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 { public void addToContext() throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
HostingNode hostingNode = applicationContext.container().properties() HostingNode hostingNode = applicationContext.container().properties()
.lookup(Constants.HOSTING_NODE_MANAGER_PROPERTY).value(HostingNodeManager.class).getHostingNode(); .lookup(Constants.HOSTING_NODE_MANAGER_PROPERTY).value(HostingNodeManager.class).getHostingNode();
boolean added = resourceRegistryPublisher.addResourceToCurrentContext(hostingNode); try {
if (added) { resourceRegistryPublisher.addResourceToCurrentContext(hostingNode);
logger.info("{} successfully added to current context ({})", eService, logger.info("{} successfully added to current context ({})", eService, ContextUtility.getCurrentContextName());
ContextUtility.getCurrentContextName()); } catch (Exception e) {
} else { logger.error("Unable to add {} to current context ({})", eService, ContextUtility.getCurrentContextName(), e);
logger.error("Unable to add {} to current context ({})", eService, ContextUtility.getCurrentContextName());
} }
} }
public void removeFromContext() public void removeFromContext()
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
boolean removed = false; try {
removed = resourceRegistryPublisher.removeResourceFromCurrentContext(eService); resourceRegistryPublisher.removeResourceFromCurrentContext(eService);
if (removed) {
logger.info("{} successfully removed from current context ({})", eService, logger.info("{} successfully removed from current context ({})", eService,
ContextUtility.getCurrentContextName()); ContextUtility.getCurrentContextName());
} else { } catch (Exception e) {
logger.error("Unable to remove {} from current context ({})", eService, logger.error("Unable to remove {} from current context ({})", eService,
ContextUtility.getCurrentContextName()); ContextUtility.getCurrentContextName(), e);
} }
} }
public void removeFromContext(UUID contextUUID) public void removeFromContext(UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
boolean removed = false;
String contextFullName = ContextCache.getInstance().getContextFullNameByUUID(contextUUID); String contextFullName = ContextCache.getInstance().getContextFullNameByUUID(contextUUID);
removed = resourceRegistryPublisher.removeResourceFromContext(eService, contextUUID); try {
if (removed) { resourceRegistryPublisher.removeResourceFromContext(eService, contextUUID);
logger.info("{} successfully removed from context ({})", eService, contextFullName); logger.info("{} successfully removed from context ({})", eService, contextFullName);
} else { } catch (Exception e) {
logger.error("Unable to remove {} from current context ({})", eService, contextFullName); logger.error("Unable to remove {} from current context ({})", eService, contextFullName, e);
} }
} }

View File

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