|
|
|
@ -1,10 +1,21 @@
|
|
|
|
|
package org.gcube.portlets.admin.systemservicedefinition.is;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
|
|
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
|
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
|
|
|
|
import org.gcube.common.resources.gcore.ScopeGroup;
|
|
|
|
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
|
|
|
|
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
|
|
|
|
import org.gcube.common.resources.gcore.ServiceEndpoint.Profile;
|
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
|
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
|
|
|
|
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
|
|
|
|
import org.gcube.informationsystem.publisher.ScopedPublisher;
|
|
|
|
|
import org.gcube.portlets.admin.systemservicedefinition.definition.DefinitionItem;
|
|
|
|
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
|
|
|
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
|
|
|
|
import org.gcube.resources.discovery.icclient.ICFactory;
|
|
|
|
@ -15,7 +26,8 @@ public class InformationSystemUtils {
|
|
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(InformationSystemUtils.class);
|
|
|
|
|
|
|
|
|
|
public static void retrieveSSD(String category, String scope, String token) throws Exception {
|
|
|
|
|
public static ArrayList<DefinitionItem> retrieveSSD(String category, String scope, String token) throws Exception {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
logger.debug("Retrieve System Services Definition on IS");
|
|
|
|
|
|
|
|
|
@ -26,9 +38,8 @@ public class InformationSystemUtils {
|
|
|
|
|
throw new Exception("Invalid token: " + scope);
|
|
|
|
|
|
|
|
|
|
ScopeProvider.instance.set(scope);
|
|
|
|
|
SecurityTokenProvider.instance.set(token);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// AccessTokenProvider.instance.set(token);
|
|
|
|
|
// SecurityTokenProvider.instance.set(token);
|
|
|
|
|
|
|
|
|
|
SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class);
|
|
|
|
|
query.addCondition("$resource/Profile/Category/text() eq '" + category + "'");
|
|
|
|
@ -38,41 +49,25 @@ public class InformationSystemUtils {
|
|
|
|
|
|
|
|
|
|
logger.debug("Retrieved: " + resources);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* String serviceAddress = null; ArrayList<ServiceInfoData> serviceProperties =
|
|
|
|
|
* new ArrayList<>();
|
|
|
|
|
*
|
|
|
|
|
* if (accessPointList != null && !accessPointList.isEmpty()) { for (int i = 0;
|
|
|
|
|
* i < accessPointList.size(); i++) { AccessPoint accessPoint =
|
|
|
|
|
* accessPointList.get(i); if (accessPoint != null) { if (i == 0) { if
|
|
|
|
|
* (accessPoint.address() != null && !accessPoint.address().isEmpty()) { String
|
|
|
|
|
* accessPointAddress = accessPoint.address(); int wpsWebProcessingServiceIndex
|
|
|
|
|
* = accessPointAddress .indexOf(Constants.WPSWebProcessingService); if
|
|
|
|
|
* (wpsWebProcessingServiceIndex > 0) { serviceAddress =
|
|
|
|
|
* accessPointAddress.substring(0, wpsWebProcessingServiceIndex); } } }
|
|
|
|
|
*
|
|
|
|
|
* String categoryDescription; if (accessPoint.description() == null &&
|
|
|
|
|
* accessPoint.description().isEmpty()) { categoryDescription =
|
|
|
|
|
* Constants.DATA_MINER_DEFAULT_SERVICE_INFO_CATEGORY; } else {
|
|
|
|
|
* categoryDescription = accessPoint.description(); }
|
|
|
|
|
*
|
|
|
|
|
* if (accessPoint.properties() != null && !accessPoint.propertyMap().isEmpty())
|
|
|
|
|
* { for (String key : accessPoint.propertyMap().keySet()) { Property property =
|
|
|
|
|
* accessPoint.propertyMap().get(key); if (property != null && property.name()
|
|
|
|
|
* != null && !property.name().isEmpty()) { if (property.name().contains(":")) {
|
|
|
|
|
* String[] propertyWithCategory = property.name().split(":"); if
|
|
|
|
|
* (propertyWithCategory.length >= 2) { serviceProperties.add(new
|
|
|
|
|
* ServiceInfoData(propertyWithCategory[1], property.value(),
|
|
|
|
|
* propertyWithCategory[0])); } else { serviceProperties.add(new
|
|
|
|
|
* ServiceInfoData(property.name(), property.value(), categoryDescription)); } }
|
|
|
|
|
* else { serviceProperties.add(new ServiceInfoData(property.name(),
|
|
|
|
|
* property.value(), categoryDescription)); } }
|
|
|
|
|
*
|
|
|
|
|
* } } } } } ServiceInfo serviceInfo = new ServiceInfo(serviceAddress,
|
|
|
|
|
* serviceProperties);
|
|
|
|
|
*
|
|
|
|
|
* logger.debug("DataMiner Service Info: " + serviceInfo); return serviceInfo;
|
|
|
|
|
*/
|
|
|
|
|
ArrayList<DefinitionItem> ssdList = new ArrayList<DefinitionItem>();
|
|
|
|
|
|
|
|
|
|
for (ServiceEndpoint se : resources) {
|
|
|
|
|
DefinitionItem definitionItem = new DefinitionItem();
|
|
|
|
|
definitionItem.setClientId(se.profile().name());
|
|
|
|
|
definitionItem.setDescription(se.profile().description());
|
|
|
|
|
for (AccessPoint accessPoint : se.profile().accessPoints()) {
|
|
|
|
|
definitionItem.setUsername(accessPoint.username());
|
|
|
|
|
String decryptedSecret = StringEncrypter.getEncrypter().decrypt(accessPoint.password());
|
|
|
|
|
|
|
|
|
|
definitionItem.setSecret(decryptedSecret);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
ssdList.add(definitionItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.debug("SSDList: {}", ssdList);
|
|
|
|
|
return ssdList;
|
|
|
|
|
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
logger.error("Error in discovery System Services Endpoint in scope: " + scope);
|
|
|
|
|
logger.error(e.getLocalizedMessage(), e);
|
|
|
|
@ -80,4 +75,71 @@ public class InformationSystemUtils {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void publishSSD(DefinitionItem definitionItem, String category, String scope, String token)
|
|
|
|
|
throws Exception {
|
|
|
|
|
if (definitionItem == null)
|
|
|
|
|
throw new Exception("Invalid definition: " + definitionItem);
|
|
|
|
|
|
|
|
|
|
if (category == null || category.isEmpty())
|
|
|
|
|
throw new Exception("Invalid category: " + category);
|
|
|
|
|
|
|
|
|
|
if (scope == null || scope.isEmpty())
|
|
|
|
|
throw new Exception("Invalid scope: " + scope);
|
|
|
|
|
|
|
|
|
|
if (token == null || token.isEmpty())
|
|
|
|
|
throw new Exception("Invalid token: " + token);
|
|
|
|
|
|
|
|
|
|
ServiceEndpoint toPublish = new ServiceEndpoint();
|
|
|
|
|
|
|
|
|
|
/*List<String> scopes = new ArrayList<String>();
|
|
|
|
|
scopes.add(scope);
|
|
|
|
|
Collection<String> col = toPublish.scopes().asCollection();
|
|
|
|
|
col.addAll(scopes);*/
|
|
|
|
|
|
|
|
|
|
toPublish.newProfile();
|
|
|
|
|
toPublish.profile().description(definitionItem.getDescription());
|
|
|
|
|
toPublish.profile().name(definitionItem.getClientId());
|
|
|
|
|
toPublish.profile().category(category);
|
|
|
|
|
//toPublish.profile().version("1.0.0");
|
|
|
|
|
|
|
|
|
|
AccessPoint accessPoint = new AccessPoint();
|
|
|
|
|
//String encryptedPassword = StringEncrypter.getEncrypter().encrypt(definitionItem.getSecret());
|
|
|
|
|
accessPoint.credentials(definitionItem.getSecret(), definitionItem.getUsername());
|
|
|
|
|
accessPoint.description("Keycloak client credentials");
|
|
|
|
|
accessPoint.address("accounts.dev.d4science.org");
|
|
|
|
|
accessPoint.name(definitionItem.getClientId());
|
|
|
|
|
toPublish.profile().accessPoints().add(accessPoint);
|
|
|
|
|
|
|
|
|
|
toPublish.profile().newPlatform().name("d4science");
|
|
|
|
|
toPublish.profile().platform().version((short) 0);
|
|
|
|
|
toPublish.profile().platform().minorVersion((short) 0);
|
|
|
|
|
toPublish.profile().platform().revisionVersion((short) 0);
|
|
|
|
|
toPublish.profile().platform().buildVersion((short) 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toPublish.profile().newRuntime().hostedOn("d4science.org");
|
|
|
|
|
toPublish.profile().runtime().status("READY");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.debug("Request publish: {}", toPublish);
|
|
|
|
|
try {
|
|
|
|
|
ScopeProvider.instance.set(scope);
|
|
|
|
|
// AccessTokenProvider.instance.set(token);
|
|
|
|
|
// SecurityTokenProvider.instance.set(token);
|
|
|
|
|
|
|
|
|
|
RegistryPublisher publisher = RegistryPublisherFactory.create();
|
|
|
|
|
|
|
|
|
|
String id = publisher.create(toPublish).id();
|
|
|
|
|
logger.debug("Created new RR sent, Got from publisher: id=" + id);
|
|
|
|
|
|
|
|
|
|
// ScopedPublisher sp=RegistryPublisherFactory.scopedPublisher();
|
|
|
|
|
// toPublish = sp.create(toPublish,scopes);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("Error publishing the ssd on IS: {}", e.getLocalizedMessage(), e);
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
logger.debug("Published on IS");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|