Fixed add/remove to/from context return

This commit is contained in:
Luca Frosini 2021-07-07 10:20:32 +02:00
parent 676e90dcc9
commit 122cdb8288
2 changed files with 33 additions and 41 deletions

View File

@ -81,37 +81,34 @@ public class EServiceManager {
public void addToContext() throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
HostingNode hostingNode = applicationContext.container().properties()
.lookup(Constants.HOSTING_NODE_MANAGER_PROPERTY).value(HostingNodeManager.class).getHostingNode();
boolean added = resourceRegistryPublisher.addResourceToCurrentContext(hostingNode);
if (added) {
logger.info("{} successfully added to current context ({})", eService,
ContextUtility.getCurrentContextName());
} else {
logger.error("Unable to add {} to current context ({})", eService, ContextUtility.getCurrentContextName());
try {
resourceRegistryPublisher.addResourceToCurrentContext(hostingNode);
logger.info("{} successfully added to current context ({})", eService, ContextUtility.getCurrentContextName());
} catch (Exception e) {
logger.error("Unable to add {} to current context ({})", eService, ContextUtility.getCurrentContextName(), e);
}
}
public void removeFromContext()
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
boolean removed = false;
removed = resourceRegistryPublisher.removeResourceFromCurrentContext(eService);
if (removed) {
try {
resourceRegistryPublisher.removeResourceFromCurrentContext(eService);
logger.info("{} successfully removed from current context ({})", eService,
ContextUtility.getCurrentContextName());
} else {
} catch (Exception e) {
logger.error("Unable to remove {} from current context ({})", eService,
ContextUtility.getCurrentContextName());
ContextUtility.getCurrentContextName(), e);
}
}
public void removeFromContext(UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
boolean removed = false;
String contextFullName = ContextCache.getInstance().getContextFullNameByUUID(contextUUID);
removed = resourceRegistryPublisher.removeResourceFromContext(eService, contextUUID);
if (removed) {
try {
resourceRegistryPublisher.removeResourceFromContext(eService, contextUUID);
logger.info("{} successfully removed from context ({})", eService, contextFullName);
} else {
logger.error("Unable to remove {} from current context ({})", eService, contextFullName);
} catch (Exception e) {
logger.error("Unable to remove {} from current context ({})", eService, contextFullName, e);
}
}
@ -188,7 +185,7 @@ public class EServiceManager {
return eService;
}
public EService createEService() throws ResourceRegistryException {
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
UUID eServiceUUID = UUID.fromString(applicationContext.id());
@ -196,13 +193,13 @@ public class EServiceManager {
ResourceRegistryClientFactory.includeContextsInInstanceHeader(true);
eService = resourceRegistryClient.getInstance(EService.class, eServiceUUID);
stateFacet = eService.getFacets(StateFacet.class).get(0);
if(stateFacet==null) {
if (stateFacet == null) {
stateFacet = new StateFacetImpl();
String state = getState();
stateFacet.setValue(state);
eService.addFacet(stateFacet);
resourceRegistryPublisher.update(eService);
}else{
} else {
updateServiceStateFacet();
}
} catch (NotFoundException e) {
@ -222,13 +219,13 @@ public class EServiceManager {
createActivatesRelation(eService);
}
stateFacet = eService.getFacets(StateFacet.class).get(0);
if(stateFacet==null) {
if (stateFacet == null) {
stateFacet = new StateFacetImpl();
String state = getState();
stateFacet.setValue(state);
eService.addFacet(stateFacet);
resourceRegistryPublisher.update(eService);
}else{
} else {
updateServiceStateFacet();
}
} catch (ResourceRegistryException e) {
@ -279,7 +276,7 @@ public class EServiceManager {
updateServiceStateFacet();
}
}
public Set<UUID> getContextsUUID() throws Exception {
return resourceRegistryPublisher.getResourceContexts(eService);
}

View File

@ -100,38 +100,33 @@ public class HostingNodeManager {
}
public void addToContext() throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
boolean added = resourceRegistryPublisher.addResourceToCurrentContext(hostingNode);
if (added) {
logger.info("{} successfully added to current context ({})", hostingNode,
ContextUtility.getCurrentContextName());
} else {
logger.error("Unable to add {} to current context ({})", hostingNode,
ContextUtility.getCurrentContextName());
try {
resourceRegistryPublisher.addResourceToCurrentContext(hostingNode);
logger.info("{} successfully added to current context ({})", hostingNode, ContextUtility.getCurrentContextName());
} catch (Exception e) {
logger.error("Unable to add {} to current context ({})", hostingNode, ContextUtility.getCurrentContextName(), e);
}
}
public void removeFromContext()
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
boolean removed = false;
removed = resourceRegistryPublisher.removeResourceFromCurrentContext(hostingNode);
if (removed) {
try {
resourceRegistryPublisher.removeResourceFromCurrentContext(hostingNode);
logger.info("{} successfully removed from current context ({})", hostingNode,
ContextUtility.getCurrentContextName());
} else {
logger.error("Unable to remove {} from current context ({})", hostingNode,
ContextUtility.getCurrentContextName());
} catch (Exception e) {
logger.error("Unable to remove {} from current context ({})", hostingNode, ContextUtility.getCurrentContextName(), e);
}
}
public void removeFromContext(UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
boolean removed = false;
String contextFullName = ContextCache.getInstance().getContextFullNameByUUID(contextUUID);
removed = resourceRegistryPublisher.removeResourceFromContext(hostingNode, contextUUID);
if (removed) {
try {
resourceRegistryPublisher.removeResourceFromContext(hostingNode, contextUUID);
logger.info("{} successfully removed from context ({})", hostingNode, contextFullName);
} else {
logger.error("Unable to remove {} from current context ({})", hostingNode, contextFullName);
} catch (Exception e) {
logger.error("Unable to remove {} from current context ({})", hostingNode, contextFullName, e);
}
}