Implementing code to remove the resource from no more available contexts

at startup
This commit is contained in:
Luca Frosini 2020-11-10 15:52:46 +01:00
parent a77172d7f1
commit 754ab7ec86
5 changed files with 38 additions and 3 deletions

View File

@ -1,5 +1,9 @@
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.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
@ -46,5 +50,16 @@ public class ContextUtility {
return null;
}
}
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;
}
}

View File

@ -80,12 +80,12 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
try {
Thread.currentThread().setContextClassLoader(EServiceHandler.class.getClassLoader());
boolean create = true;
eServiceManager = new EServiceManager(applicationContext);
Set<String> startTokens = applicationContext.configuration().startTokens();
for (String token : startTokens) {
ContextUtility.setContextFromToken(token);
try {
if (create) {
eServiceManager = new EServiceManager(applicationContext);
eServiceManager.createEService();
applicationContext.properties()
.add(new Property(Constants.ESERVICE_MANAGER_PROPERTY, eServiceManager));

View File

@ -86,12 +86,12 @@ public class HostingNodeHandler extends ContainerHandler {
try {
Thread.currentThread().setContextClassLoader(HostingNodeHandler.class.getClassLoader());
boolean create = true;
hostingNodeManager = new HostingNodeManager(containerContext);
List<String> startTokens = containerContext.configuration().startTokens();
for (String token : startTokens) {
ContextUtility.setContextFromToken(token);
try {
if (create) {
hostingNodeManager = new HostingNodeManager(containerContext);
hostingNodeManager.createHostingNode();
containerContext.properties()
.add(new Property(Constants.HOSTING_NODE_MANAGER_PROPERTY, hostingNodeManager));

View File

@ -3,6 +3,8 @@ package org.gcube.smartgears.handler.resourceregistry.resourcemanager;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
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.AddConstraint;
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.NotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
@ -178,8 +181,9 @@ public class EServiceManager {
public EService createEService() throws ResourceRegistryException {
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
UUID eServiceUUID = UUID.fromString(applicationContext.id());
Set<UUID> contexts;
try {
resourceRegistryClient.exists(EService.class, eServiceUUID);
ResourceRegistryClientFactory.includeContextsInInstanceHeader(true);
eService = resourceRegistryClient.getInstance(EService.class, eServiceUUID);
serviceStateFacet = eService.getFacets(ServiceStateFacet.class).get(0);
if(serviceStateFacet==null) {
@ -194,6 +198,7 @@ public class EServiceManager {
} catch (NotFoundException e) {
eService = instantiateEService();
createActivatesRelation(eService);
} catch (AvailableInAnotherContextException e) {
addToContext();
try {
@ -219,6 +224,16 @@ public class EServiceManager {
} catch (ResourceRegistryException 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;
}

View File

@ -15,6 +15,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -334,6 +335,10 @@ public class HostingNodeManager {
addToContext();
hostingNode = resourceRegistryClient.getInstance(HostingNode.class, uuid);
}
// TODO Remove contexts not present in start contexts
List<String> startTokens = containerContext.configuration().startTokens();
return hostingNode;
}