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 {
|
try {
|
||||||
Thread.currentThread().setContextClassLoader(EServiceHandler.class.getClassLoader());
|
Thread.currentThread().setContextClassLoader(EServiceHandler.class.getClassLoader());
|
||||||
eServiceManager.removeEService();
|
eServiceManager.updateServiceStateFacet();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Failed to update {} State", EService.NAME, e);
|
logger.error("Failed to update {} State", EService.NAME, e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -134,7 +134,7 @@ public class HostingNodeHandler extends ContainerHandler {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
//hostingNodeManager.updateStatus();
|
hostingNodeManager.updateStatus();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -155,7 +155,7 @@ public class HostingNodeHandler extends ContainerHandler {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.currentThread().setContextClassLoader(HostingNodeHandler.class.getClassLoader());
|
Thread.currentThread().setContextClassLoader(HostingNodeHandler.class.getClassLoader());
|
||||||
hostingNodeManager.updateFacets();
|
hostingNodeManager.updateStatus();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("cannot complete periodic update of {}", HostingNode.NAME, e);
|
logger.error("cannot complete periodic update of {}", HostingNode.NAME, e);
|
||||||
} finally {
|
} 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;
|
||||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
||||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
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.AvailableInAnotherContextException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lucafrosini
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @author lucafrosini
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class EServiceManager {
|
public class EServiceManager {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(HostingNodeManager.class);
|
private static Logger logger = LoggerFactory.getLogger(HostingNodeManager.class);
|
||||||
|
@ -54,7 +61,7 @@ public class EServiceManager {
|
||||||
|
|
||||||
private ResourceRegistryPublisher resourceRegistryPublisher;
|
private ResourceRegistryPublisher resourceRegistryPublisher;
|
||||||
|
|
||||||
private Activates<HostingNode, EService> activates;
|
// private Activates<HostingNode, EService> activates;
|
||||||
private EService eService;
|
private EService eService;
|
||||||
private ServiceStateFacet serviceStateFacet;
|
private ServiceStateFacet serviceStateFacet;
|
||||||
|
|
||||||
|
@ -169,29 +176,29 @@ public class EServiceManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public EService createEService() throws ResourceRegistryException {
|
public EService createEService() throws ResourceRegistryException {
|
||||||
|
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||||
|
UUID eServiceUUID = UUID.fromString(applicationContext.id());
|
||||||
try {
|
try {
|
||||||
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
|
resourceRegistryClient.exists(EService.class, eServiceUUID);
|
||||||
UUID uuid = UUID.fromString(applicationContext.id());
|
eService = resourceRegistryClient.getInstance(EService.class, eServiceUUID);
|
||||||
try {
|
} catch (NotFoundException e) {
|
||||||
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
|
|
||||||
}
|
|
||||||
eService = instantiateEService();
|
eService = instantiateEService();
|
||||||
// eService = resourceRegistryPublisher.createResource(eService);
|
createActivatesRelation(eService);
|
||||||
activates = createActivatesRelation(eService);
|
} catch (AvailableInAnotherContextException e) {
|
||||||
} catch (AvailableInAnotherContextException | AlreadyPresentException e) {
|
addToContext();
|
||||||
// resourceRegistryPublisher.delete(eService);
|
try {
|
||||||
// eService = resourceRegistryPublisher.createResource(eService);
|
eService = resourceRegistryClient.getInstance(EService.class, eServiceUUID);
|
||||||
resourceRegistryPublisher.delete(activates);
|
} catch (AvailableInAnotherContextException ex) {
|
||||||
activates = createActivatesRelation(eService);
|
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;
|
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.entities.Resource;
|
||||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
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.AvailableInAnotherContextException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
@ -323,24 +322,17 @@ public class HostingNodeManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public HostingNode createHostingNode() throws ResourceRegistryException {
|
public HostingNode createHostingNode() throws ResourceRegistryException {
|
||||||
|
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||||
|
UUID uuid = UUID.fromString(containerContext.id());
|
||||||
try {
|
try {
|
||||||
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
|
hostingNode = resourceRegistryClient.getInstance(HostingNode.class, uuid);
|
||||||
UUID uuid = UUID.fromString(containerContext.id());
|
hostingNode = updateFacets();
|
||||||
try {
|
} catch (NotFoundException e) {
|
||||||
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 = instantiateHostingNode();
|
hostingNode = instantiateHostingNode();
|
||||||
hostingNode = resourceRegistryPublisher.createResource(hostingNode);
|
hostingNode = resourceRegistryPublisher.createResource(hostingNode);
|
||||||
} catch (AvailableInAnotherContextException | AlreadyPresentException e) {
|
} catch (AvailableInAnotherContextException e) {
|
||||||
resourceRegistryPublisher.delete(hostingNode);
|
addToContext();
|
||||||
hostingNode = resourceRegistryPublisher.createResource(hostingNode);
|
hostingNode = resourceRegistryClient.getInstance(HostingNode.class, uuid);
|
||||||
}
|
}
|
||||||
return hostingNode;
|
return hostingNode;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue