EService is no more removed instead is set to down
This commit is contained in:
parent
f7e3baca07
commit
8e35e18b58
|
@ -142,7 +142,7 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
|
|||
}
|
||||
try {
|
||||
Thread.currentThread().setContextClassLoader(EServiceHandler.class.getClassLoader());
|
||||
eServiceManager.removeEService();
|
||||
eServiceManager.updateServiceStateFacet();
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to update {} State", EService.NAME, e);
|
||||
} finally {
|
||||
|
|
|
@ -134,7 +134,7 @@ public class HostingNodeHandler extends ContainerHandler {
|
|||
break;
|
||||
|
||||
default:
|
||||
//hostingNodeManager.updateStatus();
|
||||
hostingNodeManager.updateStatus();
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -155,7 +155,7 @@ public class HostingNodeHandler extends ContainerHandler {
|
|||
}
|
||||
try {
|
||||
Thread.currentThread().setContextClassLoader(HostingNodeHandler.class.getClassLoader());
|
||||
hostingNodeManager.updateFacets();
|
||||
hostingNodeManager.updateStatus();
|
||||
} catch (Exception e) {
|
||||
logger.error("cannot complete periodic update of {}", HostingNode.NAME, e);
|
||||
} finally {
|
||||
|
|
|
@ -13,7 +13,6 @@ import org.gcube.informationsystem.model.reference.properties.Header;
|
|||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
|
@ -46,6 +45,14 @@ import org.gcube.smartgears.handler.resourceregistry.ContextUtility;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author lucafrosini
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @author lucafrosini
|
||||
*
|
||||
*/
|
||||
public class EServiceManager {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(HostingNodeManager.class);
|
||||
|
@ -54,7 +61,7 @@ public class EServiceManager {
|
|||
|
||||
private ResourceRegistryPublisher resourceRegistryPublisher;
|
||||
|
||||
private Activates<HostingNode, EService> activates;
|
||||
// private Activates<HostingNode, EService> activates;
|
||||
private EService eService;
|
||||
private ServiceStateFacet serviceStateFacet;
|
||||
|
||||
|
@ -169,29 +176,29 @@ public class EServiceManager {
|
|||
}
|
||||
|
||||
public EService createEService() throws ResourceRegistryException {
|
||||
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||
UUID eServiceUUID = UUID.fromString(applicationContext.id());
|
||||
try {
|
||||
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||
UUID uuid = UUID.fromString(applicationContext.id());
|
||||
try {
|
||||
eService = resourceRegistryClient.getInstance(EService.class, uuid);
|
||||
// It is not convenient to update the node because the contexts could be changed
|
||||
// so we should remove from all contexts and then it will be added again.
|
||||
// It is more efficient to delete it.
|
||||
resourceRegistryPublisher.delete(eService);
|
||||
} catch (NotFoundException e) {
|
||||
// Fine we are going to create it again
|
||||
}
|
||||
resourceRegistryClient.exists(EService.class, eServiceUUID);
|
||||
eService = resourceRegistryClient.getInstance(EService.class, eServiceUUID);
|
||||
} catch (NotFoundException e) {
|
||||
eService = instantiateEService();
|
||||
// eService = resourceRegistryPublisher.createResource(eService);
|
||||
activates = createActivatesRelation(eService);
|
||||
} catch (AvailableInAnotherContextException | AlreadyPresentException e) {
|
||||
// resourceRegistryPublisher.delete(eService);
|
||||
// eService = resourceRegistryPublisher.createResource(eService);
|
||||
resourceRegistryPublisher.delete(activates);
|
||||
activates = createActivatesRelation(eService);
|
||||
createActivatesRelation(eService);
|
||||
} catch (AvailableInAnotherContextException e) {
|
||||
addToContext();
|
||||
try {
|
||||
eService = resourceRegistryClient.getInstance(EService.class, eServiceUUID);
|
||||
} catch (AvailableInAnotherContextException ex) {
|
||||
resourceRegistryPublisher.addResourceToCurrentContext(eService);
|
||||
// addToContext() is executed on HostingNode.
|
||||
// If the EService is still not available we need to create activates
|
||||
// relation because does not exists otherwise the EService should
|
||||
// already be in the context due to propagation constraint.
|
||||
createActivatesRelation(eService);
|
||||
}
|
||||
} catch (ResourceRegistryException e) {
|
||||
throw e;
|
||||
}
|
||||
eService = activates.getTarget();
|
||||
serviceStateFacet = eService.getFacets(ServiceStateFacet.class).get(0);
|
||||
return eService;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.gcube.informationsystem.model.reference.entities.Facet;
|
|||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
|
@ -323,24 +322,17 @@ public class HostingNodeManager {
|
|||
}
|
||||
|
||||
public HostingNode createHostingNode() throws ResourceRegistryException {
|
||||
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||
UUID uuid = UUID.fromString(containerContext.id());
|
||||
try {
|
||||
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||
UUID uuid = UUID.fromString(containerContext.id());
|
||||
try {
|
||||
hostingNode = resourceRegistryClient.getInstance(HostingNode.class, uuid);
|
||||
|
||||
// It is not convenient to update the node because the contexts could be changed
|
||||
// so we should remove from all contexts and then it will be added again.
|
||||
// It is more efficient to delete it.
|
||||
resourceRegistryPublisher.delete(hostingNode);
|
||||
} catch (NotFoundException e) {
|
||||
// Fine we are going to create it again
|
||||
}
|
||||
hostingNode = resourceRegistryClient.getInstance(HostingNode.class, uuid);
|
||||
hostingNode = updateFacets();
|
||||
} catch (NotFoundException e) {
|
||||
hostingNode = instantiateHostingNode();
|
||||
hostingNode = resourceRegistryPublisher.createResource(hostingNode);
|
||||
} catch (AvailableInAnotherContextException | AlreadyPresentException e) {
|
||||
resourceRegistryPublisher.delete(hostingNode);
|
||||
hostingNode = resourceRegistryPublisher.createResource(hostingNode);
|
||||
} catch (AvailableInAnotherContextException e) {
|
||||
addToContext();
|
||||
hostingNode = resourceRegistryClient.getInstance(HostingNode.class, uuid);
|
||||
}
|
||||
return hostingNode;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue