2018-06-25 16:08:42 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.vremanagement.executor;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
2020-09-30 13:57:09 +02:00
|
|
|
import java.util.Map;
|
2018-06-25 16:08:42 +02:00
|
|
|
|
|
|
|
import org.gcube.common.resources.gcore.Resource;
|
|
|
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
|
|
|
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
|
|
|
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
|
|
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
|
|
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
|
|
|
import org.gcube.resources.discovery.icclient.ICFactory;
|
2020-09-30 13:57:09 +02:00
|
|
|
import org.gcube.vremanagement.executor.plugin.Plugin;
|
|
|
|
import org.gcube.vremanagement.executor.pluginmanager.PluginManager;
|
|
|
|
import org.junit.Test;
|
2018-06-25 16:08:42 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class SmartExecutorInizializatorTest {
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(SmartExecutorInizializatorTest.class);
|
|
|
|
|
2020-09-30 13:57:09 +02:00
|
|
|
@Test
|
|
|
|
public void getAvailablePlugin() {
|
2020-10-14 11:25:52 +02:00
|
|
|
PluginManager pluginManager = PluginManager.getInstance();
|
|
|
|
Map<String, Class<? extends Plugin>> availablePlugins = pluginManager.getAvailablePlugins();
|
2020-09-30 13:57:09 +02:00
|
|
|
for(String pluginName : availablePlugins.keySet()) {
|
|
|
|
logger.debug("Plugin {}, Class {}", pluginName, availablePlugins.get(pluginName).getSimpleName());
|
2018-06-25 16:08:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static void unPublishResource(Resource resource) throws Exception {
|
|
|
|
//StringWriter stringWriter = new StringWriter();
|
|
|
|
//Resources.marshal(resource, stringWriter);
|
|
|
|
|
|
|
|
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
|
|
|
|
|
|
|
|
String id = resource.id();
|
2020-09-30 13:57:09 +02:00
|
|
|
logger.debug("Trying to remove {} with ID {} from {}", resource.getClass().getSimpleName(), id, ContextTest.getCurrentContext());
|
2018-06-25 16:08:42 +02:00
|
|
|
|
|
|
|
registryPublisher.remove(resource);
|
|
|
|
|
|
|
|
logger.debug("{} with ID {} removed successfully", resource.getClass().getSimpleName(), id);
|
|
|
|
}
|
|
|
|
|
2019-09-24 14:59:25 +02:00
|
|
|
// @Test
|
2018-06-25 16:08:42 +02:00
|
|
|
public void removeOldInstances() throws Exception{
|
|
|
|
try {
|
2019-09-24 14:59:25 +02:00
|
|
|
//ContextTest.setContextByName("/d4science.research-infrastructures.eu");
|
2018-06-25 16:08:42 +02:00
|
|
|
|
|
|
|
SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class)
|
|
|
|
.addCondition(String.format("$resource/Profile/Category/text() eq '%s'", "VREManagement"))
|
|
|
|
.addCondition(String.format("$resource/Profile/Name/text() eq '%s'", "SmartExecutor"))
|
|
|
|
.addCondition(String.format("$resource/Profile/AccessPoint/Interface/Endpoint/@EntryName eq '%s'", "SmartGenericWorker"));
|
|
|
|
|
|
|
|
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
|
|
|
|
List<ServiceEndpoint> serviceEndpoints = client.submit(query);
|
|
|
|
|
|
|
|
for (ServiceEndpoint serviceEndpoint : serviceEndpoints) {
|
|
|
|
try {
|
|
|
|
logger.debug("Trying to unpublish the old ServiceEndpoint with ID {} ({}) from scope {}",
|
2020-12-02 11:22:48 +01:00
|
|
|
serviceEndpoint.id(), serviceEndpoint.profile().runtime().hostedOn(), ContextUtility.getCurrentContext());
|
2018-06-25 16:08:42 +02:00
|
|
|
// unPublishResource(serviceEndpoint);
|
|
|
|
} catch(Exception e){
|
|
|
|
logger.debug("Exception tryng to unpublish the old ServiceEndpoint with ID {} ({}) from scope {}",
|
2020-12-02 11:22:48 +01:00
|
|
|
serviceEndpoint.id(), serviceEndpoint.profile().runtime().hostedOn(), ContextUtility.getCurrentContext(), e);
|
2018-06-25 16:08:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}catch(Exception e){
|
|
|
|
logger.debug("An Exception occur while checking and/or unpublishing old ServiceEndpoint", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|