Ignord webapp directory
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor@122830 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
5b64ccf438
commit
3ba5c03967
|
@ -4,6 +4,7 @@ import java.util.UUID;
|
|||
|
||||
import javax.jws.WebService;
|
||||
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||
import org.gcube.vremanagement.executor.api.SmartExecutor;
|
||||
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
||||
|
@ -31,6 +32,7 @@ portName = "SmartExecutorPort",
|
|||
serviceName = SmartExecutor.WEB_SERVICE_SERVICE_NAME,
|
||||
targetNamespace = SmartExecutor.TARGET_NAMESPACE,
|
||||
endpointInterface = "org.gcube.vremanagement.executor.api.SmartExecutor" )
|
||||
@ManagedBy(SmartExecutorInitializator.class)
|
||||
public class SmartExecutorImpl implements SmartExecutor {
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,19 +4,11 @@
|
|||
package org.gcube.vremanagement.executor;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.common.resources.gcore.Resources;
|
||||
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;
|
||||
|
@ -25,17 +17,14 @@ import org.gcube.common.resources.gcore.ServiceEndpoint.Runtime;
|
|||
import org.gcube.common.resources.gcore.common.Platform;
|
||||
import org.gcube.common.resources.gcore.utils.Group;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.informationsystem.publisher.AdvancedScopedPublisher;
|
||||
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
||||
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
||||
import org.gcube.informationsystem.publisher.ScopedPublisher;
|
||||
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.gcube.resources.discovery.icclient.ICFactory;
|
||||
import org.gcube.smartgears.ApplicationManager;
|
||||
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||
import org.gcube.smartgears.handlers.application.ApplicationLifecycleEvent;
|
||||
import org.gcube.smartgears.handlers.application.ApplicationLifecycleHandler;
|
||||
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector;
|
||||
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory;
|
||||
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
|
||||
|
@ -48,8 +37,7 @@ import org.slf4j.LoggerFactory;
|
|||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
@XmlRootElement(name = "plugin-registration-handler")
|
||||
public class SmartExecutorInitializator extends ApplicationLifecycleHandler {
|
||||
public class SmartExecutorInitializator implements ApplicationManager {
|
||||
|
||||
/**
|
||||
* Logger
|
||||
|
@ -95,15 +83,17 @@ public class SmartExecutorInitializator extends ApplicationLifecycleHandler {
|
|||
* @throws RegistryNotFoundException if the Registry is not found so the
|
||||
* resource has not be published
|
||||
*/
|
||||
private static void publishScopedResource(Resource resource, List<String> scopes) throws RegistryNotFoundException, Exception {
|
||||
private static void publishScopedResource(Resource resource) throws Exception {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
Resources.marshal(resource, stringWriter);
|
||||
|
||||
ScopedPublisher scopedPublisher = RegistryPublisherFactory.scopedPublisher();
|
||||
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
|
||||
|
||||
try {
|
||||
logger.debug("Trying to publish to {}:\n{}", scopes, stringWriter);
|
||||
scopedPublisher.create(resource, scopes);
|
||||
} catch (RegistryNotFoundException e) {
|
||||
String scope = ScopeProvider.instance.get();
|
||||
logger.debug("Trying to publish to {}:\n{}", scope, stringWriter);
|
||||
registryPublisher.create(resource);
|
||||
} catch (Exception e) {
|
||||
logger.error("The resource was not published", e);
|
||||
throw e;
|
||||
}
|
||||
|
@ -115,18 +105,16 @@ public class SmartExecutorInitializator extends ApplicationLifecycleHandler {
|
|||
* @throws RegistryNotFoundException if the Registry is not found so the
|
||||
* resource has not be published
|
||||
*/
|
||||
private static void unPublishScopedResource(Resource resource) throws RegistryNotFoundException, Exception {
|
||||
private static void unPublishScopedResource(Resource resource) throws Exception {
|
||||
//StringWriter stringWriter = new StringWriter();
|
||||
//Resources.marshal(resource, stringWriter);
|
||||
|
||||
ScopedPublisher scopedPublisher = RegistryPublisherFactory.scopedPublisher();
|
||||
AdvancedScopedPublisher advancedScopedPublisher = new AdvancedScopedPublisher(scopedPublisher);
|
||||
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
|
||||
|
||||
String id = resource.id();
|
||||
logger.debug("Trying to remove {} with ID {} from {}", resource.getClass().getSimpleName(), id, ScopeProvider.instance.get());
|
||||
|
||||
//scopedPublisher.remove(resource, scopes);
|
||||
advancedScopedPublisher.forceRemove(resource);
|
||||
registryPublisher.remove(resource);
|
||||
|
||||
logger.debug("{} with ID {} removed successfully", resource.getClass().getSimpleName(), id);
|
||||
}
|
||||
|
@ -241,6 +229,7 @@ public class SmartExecutorInitializator extends ApplicationLifecycleHandler {
|
|||
return serviceEndpoint;
|
||||
}
|
||||
|
||||
/*
|
||||
public static List<String> getScopes(ApplicationContext applicationContext){
|
||||
Collection<String> scopes;
|
||||
|
||||
|
@ -262,8 +251,9 @@ public class SmartExecutorInitializator extends ApplicationLifecycleHandler {
|
|||
|
||||
return new ArrayList<String>(scopes);
|
||||
}
|
||||
*/
|
||||
|
||||
private void cleanServiceEndpoints(String scope){
|
||||
private void cleanServiceEndpoints(){
|
||||
try {
|
||||
SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class)
|
||||
.addCondition(String.format("$resource/Profile/Category/text() eq '%s'", SmartExecutorImpl.ctx.configuration().serviceClass()))
|
||||
|
@ -274,6 +264,8 @@ public class SmartExecutorInitializator extends ApplicationLifecycleHandler {
|
|||
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
|
||||
List<ServiceEndpoint> serviceEndpoints = client.submit(query);
|
||||
|
||||
String scope = ScopeProvider.instance.get();
|
||||
|
||||
for (ServiceEndpoint serviceEndpoint : serviceEndpoints) {
|
||||
try {
|
||||
logger.debug("Trying to unpublish the old ServiceEndpoint with ID {} from scope {}",
|
||||
|
@ -297,37 +289,30 @@ public class SmartExecutorInitializator extends ApplicationLifecycleHandler {
|
|||
* Furthermore create/connect to DB
|
||||
*/
|
||||
@Override
|
||||
public void onStart(ApplicationLifecycleEvent.Start applicationLifecycleEventStart) {
|
||||
public void onInit() {
|
||||
logger.trace(
|
||||
"\n-------------------------------------------------------\n"
|
||||
+ "Smart Executor is Starting\n"
|
||||
+ "-------------------------------------------------------");
|
||||
|
||||
SmartExecutorImpl.ctx = applicationLifecycleEventStart.context();
|
||||
|
||||
ServiceEndpoint serviceEndpoint = createServiceEndpoint();
|
||||
|
||||
// Checking if there are old unpublished ServiceEndpoints related to
|
||||
// this vHN and trying to unpublish them
|
||||
List<String> scopes = getScopes(SmartExecutorImpl.ctx);
|
||||
cleanServiceEndpoints();
|
||||
|
||||
for(String scope : scopes){
|
||||
ScopeProvider.instance.set(scope);
|
||||
cleanServiceEndpoints(scope);
|
||||
try {
|
||||
SmartExecutorPersistenceFactory.getPersistenceConnector();
|
||||
} catch (Exception e) {
|
||||
String scope = ScopeProvider.instance.get();
|
||||
logger.error("Unable to isntantiate {} for scope {}",
|
||||
SmartExecutorPersistenceConnector.class.getSimpleName(), scope, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO set task that are still on running state on DB to have a clear
|
||||
// room
|
||||
|
||||
try {
|
||||
publishScopedResource(serviceEndpoint, scopes);
|
||||
publishScopedResource(serviceEndpoint);
|
||||
} catch (RegistryNotFoundException e) {
|
||||
logger.error("Unable to Create ServiceEndpoint. the Service will be aborted", e);
|
||||
return;
|
||||
|
@ -343,7 +328,6 @@ public class SmartExecutorInitializator extends ApplicationLifecycleHandler {
|
|||
|
||||
// TODO Launch initializer thread
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -353,7 +337,7 @@ public class SmartExecutorInitializator extends ApplicationLifecycleHandler {
|
|||
* Furthermore close the connection to DB.
|
||||
*/
|
||||
@Override
|
||||
public void onStop(ApplicationLifecycleEvent.Stop applicationLifecycleEventStop) {
|
||||
public void onShutdown(){
|
||||
logger.trace(
|
||||
"\n-------------------------------------------------------\n"
|
||||
+ "Smart Executor is Stopping\n"
|
||||
|
@ -361,18 +345,16 @@ public class SmartExecutorInitializator extends ApplicationLifecycleHandler {
|
|||
|
||||
SmartExecutorScheduler.getInstance().stopAll();
|
||||
|
||||
List<String> scopes = getScopes(SmartExecutorImpl.ctx);
|
||||
|
||||
for(String scope : scopes){
|
||||
ScopeProvider.instance.set(scope);
|
||||
cleanServiceEndpoints(scope);
|
||||
|
||||
String scope = ScopeProvider.instance.get();
|
||||
cleanServiceEndpoints();
|
||||
try {
|
||||
SmartExecutorPersistenceFactory.getPersistenceConnector().close();
|
||||
} catch (Exception e) {
|
||||
logger.error("Unable to correctly close {} for scope {}",
|
||||
SmartExecutorPersistenceConnector.class.getSimpleName(), scope, e);
|
||||
}
|
||||
}
|
||||
|
||||
logger.trace(
|
||||
"\n-------------------------------------------------------\n"
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
org.gcube.vremanagement.executor.SmartExecutorInitializator
|
Loading…
Reference in New Issue