Implementing code to remove the resource from no more available contexts
at startup
This commit is contained in:
parent
a77172d7f1
commit
754ab7ec86
|
@ -1,5 +1,9 @@
|
||||||
package org.gcube.smartgears.handler.resourceregistry;
|
package org.gcube.smartgears.handler.resourceregistry;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.gcube.common.authorization.client.proxy.AuthorizationProxy;
|
import org.gcube.common.authorization.client.proxy.AuthorizationProxy;
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
@ -47,4 +51,15 @@ public class ContextUtility {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SortedSet<String> getContextFullNamesFromTokens(Set<String> tokens){
|
||||||
|
SortedSet<String> contextFullNames = new TreeSet<>();
|
||||||
|
for(String token : tokens) {
|
||||||
|
String contextFullName = getContextName(token);
|
||||||
|
contextFullNames.add(contextFullName);
|
||||||
|
}
|
||||||
|
return contextFullNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,12 +80,12 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
|
||||||
try {
|
try {
|
||||||
Thread.currentThread().setContextClassLoader(EServiceHandler.class.getClassLoader());
|
Thread.currentThread().setContextClassLoader(EServiceHandler.class.getClassLoader());
|
||||||
boolean create = true;
|
boolean create = true;
|
||||||
|
eServiceManager = new EServiceManager(applicationContext);
|
||||||
Set<String> startTokens = applicationContext.configuration().startTokens();
|
Set<String> startTokens = applicationContext.configuration().startTokens();
|
||||||
for (String token : startTokens) {
|
for (String token : startTokens) {
|
||||||
ContextUtility.setContextFromToken(token);
|
ContextUtility.setContextFromToken(token);
|
||||||
try {
|
try {
|
||||||
if (create) {
|
if (create) {
|
||||||
eServiceManager = new EServiceManager(applicationContext);
|
|
||||||
eServiceManager.createEService();
|
eServiceManager.createEService();
|
||||||
applicationContext.properties()
|
applicationContext.properties()
|
||||||
.add(new Property(Constants.ESERVICE_MANAGER_PROPERTY, eServiceManager));
|
.add(new Property(Constants.ESERVICE_MANAGER_PROPERTY, eServiceManager));
|
||||||
|
|
|
@ -86,12 +86,12 @@ public class HostingNodeHandler extends ContainerHandler {
|
||||||
try {
|
try {
|
||||||
Thread.currentThread().setContextClassLoader(HostingNodeHandler.class.getClassLoader());
|
Thread.currentThread().setContextClassLoader(HostingNodeHandler.class.getClassLoader());
|
||||||
boolean create = true;
|
boolean create = true;
|
||||||
|
hostingNodeManager = new HostingNodeManager(containerContext);
|
||||||
List<String> startTokens = containerContext.configuration().startTokens();
|
List<String> startTokens = containerContext.configuration().startTokens();
|
||||||
for (String token : startTokens) {
|
for (String token : startTokens) {
|
||||||
ContextUtility.setContextFromToken(token);
|
ContextUtility.setContextFromToken(token);
|
||||||
try {
|
try {
|
||||||
if (create) {
|
if (create) {
|
||||||
hostingNodeManager = new HostingNodeManager(containerContext);
|
|
||||||
hostingNodeManager.createHostingNode();
|
hostingNodeManager.createHostingNode();
|
||||||
containerContext.properties()
|
containerContext.properties()
|
||||||
.add(new Property(Constants.HOSTING_NODE_MANAGER_PROPERTY, hostingNodeManager));
|
.add(new Property(Constants.HOSTING_NODE_MANAGER_PROPERTY, hostingNodeManager));
|
||||||
|
|
|
@ -3,6 +3,8 @@ package org.gcube.smartgears.handler.resourceregistry.resourcemanager;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.servlet.ServletRegistration;
|
import javax.servlet.ServletRegistration;
|
||||||
|
@ -13,6 +15,7 @@ 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.contexts.ContextCache;
|
||||||
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;
|
||||||
|
@ -178,8 +181,9 @@ public class EServiceManager {
|
||||||
public EService createEService() throws ResourceRegistryException {
|
public EService createEService() throws ResourceRegistryException {
|
||||||
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
|
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||||
UUID eServiceUUID = UUID.fromString(applicationContext.id());
|
UUID eServiceUUID = UUID.fromString(applicationContext.id());
|
||||||
|
Set<UUID> contexts;
|
||||||
try {
|
try {
|
||||||
resourceRegistryClient.exists(EService.class, eServiceUUID);
|
ResourceRegistryClientFactory.includeContextsInInstanceHeader(true);
|
||||||
eService = resourceRegistryClient.getInstance(EService.class, eServiceUUID);
|
eService = resourceRegistryClient.getInstance(EService.class, eServiceUUID);
|
||||||
serviceStateFacet = eService.getFacets(ServiceStateFacet.class).get(0);
|
serviceStateFacet = eService.getFacets(ServiceStateFacet.class).get(0);
|
||||||
if(serviceStateFacet==null) {
|
if(serviceStateFacet==null) {
|
||||||
|
@ -194,6 +198,7 @@ public class EServiceManager {
|
||||||
} catch (NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
eService = instantiateEService();
|
eService = instantiateEService();
|
||||||
createActivatesRelation(eService);
|
createActivatesRelation(eService);
|
||||||
|
|
||||||
} catch (AvailableInAnotherContextException e) {
|
} catch (AvailableInAnotherContextException e) {
|
||||||
addToContext();
|
addToContext();
|
||||||
try {
|
try {
|
||||||
|
@ -219,6 +224,16 @@ public class EServiceManager {
|
||||||
} catch (ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Remove contexts not present in start contexts
|
||||||
|
Set<String> startTokens = applicationContext.configuration().startTokens();
|
||||||
|
Set<String> contextFullNames = ContextUtility.getContextFullNamesFromTokens(startTokens);
|
||||||
|
ContextCache contextCache = ContextCache.getInstance();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, UUID> contextFullNameToUUID = contextCache.getContextFullNameToUUIDAssociation();
|
||||||
|
|
||||||
return eService;
|
return eService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
@ -334,6 +335,10 @@ public class HostingNodeManager {
|
||||||
addToContext();
|
addToContext();
|
||||||
hostingNode = resourceRegistryClient.getInstance(HostingNode.class, uuid);
|
hostingNode = resourceRegistryClient.getInstance(HostingNode.class, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Remove contexts not present in start contexts
|
||||||
|
List<String> startTokens = containerContext.configuration().startTokens();
|
||||||
|
|
||||||
return hostingNode;
|
return hostingNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue