Added explicit invocation of addEserviceToContext

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/resource-registry-handlers@148246 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-05-02 15:55:29 +00:00
parent 2f56c934df
commit 7453f3239d
1 changed files with 18 additions and 12 deletions

View File

@ -335,6 +335,23 @@ public class EServiceManager extends ApplicationLifecycleHandler {
try {
eService = resourceRegistryPublisher.createResource(EService.class,
eService);
} catch (ResourceAlreadyPresentException e) {
ResourceRegistryClient registryClient = ResourceRegistryClientFactory.create();
eService = registryClient.getInstance(EService.class, eService.getHeader().getUUID());
String state = applicationContext.lifecycle().state().remoteForm().toLowerCase();
logger.debug("Moving app {} to {}", applicationContext.name(), state);
createOrUpdateServiceStateFacet(eService, state);
} catch (ResourceAvailableInAnotherContextException e) {
// Adding the HostingNode I also add the EService thanks to propagationConstraint
String token = SecurityTokenProvider.instance.get();
// If hosts was not created we need to add eService and HostingNode, otherwise
// addHostingnode is sufficient. Because we cannot be sure of it we invoke both
addToContext(eService, token);
addHostingNodeToCurrentContext();
ResourceRegistryClient registryClient = ResourceRegistryClientFactory.create();
eService = registryClient.getInstance(EService.class, eService.getHeader().getUUID());
}
try {
createHostsRelation(eService, resourceRegistryPublisher);
} catch (Exception ex) {
@ -345,18 +362,7 @@ public class EServiceManager extends ApplicationLifecycleHandler {
logger.error(error, ex);
throw new ResourceRegistryException(error, ex);
}
} catch (ResourceAlreadyPresentException e) {
ResourceRegistryClient registryClient = ResourceRegistryClientFactory.create();
eService = registryClient.getInstance(EService.class, eService.getHeader().getUUID());
String state = applicationContext.lifecycle().state().remoteForm().toLowerCase();
logger.debug("Moving app {} to {}", applicationContext.name(), state);
createOrUpdateServiceStateFacet(eService, state);
} catch (ResourceAvailableInAnotherContextException e) {
// Adding the HostingNode I also add the EService thanks to propagationConstraint
addHostingNodeToCurrentContext();
ResourceRegistryClient registryClient = ResourceRegistryClientFactory.create();
eService = registryClient.getInstance(EService.class, eService.getHeader().getUUID());
}
return eService;
}
@ -540,6 +546,7 @@ public class EServiceManager extends ApplicationLifecycleHandler {
Thread.currentThread().setContextClassLoader(contextCL);
}
}
*/
private void addToContext(EService eService, String token) {
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
@ -574,7 +581,6 @@ public class EServiceManager extends ApplicationLifecycleHandler {
Thread.currentThread().setContextClassLoader(contextCL);
}
}
*/
@SuppressWarnings("unchecked")