git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@7001 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e1fc80d8bb
commit
7f0a5355d8
|
@ -16,6 +16,7 @@ import org.apache.axis.components.uuid.UUIDGenFactory;
|
||||||
import org.gcube.common.core.faults.GCUBEFault;
|
import org.gcube.common.core.faults.GCUBEFault;
|
||||||
import org.gcube.common.core.resources.GCUBEHostingNode;
|
import org.gcube.common.core.resources.GCUBEHostingNode;
|
||||||
import org.gcube.common.core.resources.GCUBEResource;
|
import org.gcube.common.core.resources.GCUBEResource;
|
||||||
|
import org.gcube.common.core.resources.service.Package.GHNRequirement;
|
||||||
import org.gcube.common.core.scope.GCUBEScope;
|
import org.gcube.common.core.scope.GCUBEScope;
|
||||||
import org.gcube.common.core.state.GCUBEWSResourceKey;
|
import org.gcube.common.core.state.GCUBEWSResourceKey;
|
||||||
import org.gcube.common.core.utils.events.GCUBEEvent;
|
import org.gcube.common.core.utils.events.GCUBEEvent;
|
||||||
|
@ -25,6 +26,7 @@ import org.gcube.informationsystem.registry.impl.contexts.ProfileContext;
|
||||||
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
|
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
|
||||||
import org.gcube.informationsystem.registry.impl.state.ProfileResource;
|
import org.gcube.informationsystem.registry.impl.state.ProfileResource;
|
||||||
import org.gcube.informationsystem.registry.impl.state.RegistryFactoryResource;
|
import org.gcube.informationsystem.registry.impl.state.RegistryFactoryResource;
|
||||||
|
import org.gcube.informationsystem.registry.impl.util.EliminatePoolingThread;
|
||||||
import org.gcube.informationsystem.registry.impl.util.ProfileManager;
|
import org.gcube.informationsystem.registry.impl.util.ProfileManager;
|
||||||
import org.gcube.informationsystem.registry.impl.util.RegistryUtil;
|
import org.gcube.informationsystem.registry.impl.util.RegistryUtil;
|
||||||
import org.gcube.informationsystem.registry.stubs.CreateResourceMessage;
|
import org.gcube.informationsystem.registry.stubs.CreateResourceMessage;
|
||||||
|
@ -170,6 +172,8 @@ public class RegistryFactory{
|
||||||
logger.debug(resource.getID()+" Creating the stateful resource for " + resource.getID());
|
logger.debug(resource.getID()+" Creating the stateful resource for " + resource.getID());
|
||||||
ProfileResource presource = (ProfileResource) ProfileContext.getContext().getWSHome().create(ProfileContext.getContext().makeKey(resource.getID()),resource);
|
ProfileResource presource = (ProfileResource) ProfileContext.getContext().getWSHome().create(ProfileContext.getContext().makeKey(resource.getID()),resource);
|
||||||
presource.getPersistenceDelegate().store(presource);
|
presource.getPersistenceDelegate().store(presource);
|
||||||
|
if (resource.getType().compareTo(GCUBEHostingNode.TYPE)!=0)
|
||||||
|
EliminatePoolingThread.getStack().add(presource);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
String msg = "Error creating Resource";
|
String msg = "Error creating Resource";
|
||||||
|
@ -193,6 +197,9 @@ public class RegistryFactory{
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Persistence failed for " + resource.getID(), e);
|
logger.error("Persistence failed for " + resource.getID(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logger.info("Profile " + resource.getID() + " created ");
|
logger.info("Profile " + resource.getID() + " created ");
|
||||||
return writer.toString();
|
return writer.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ public class ServiceContext extends GCUBEServiceContext {
|
||||||
|
|
||||||
protected class NotificationResourceScheduler extends GCUBEScheduledHandler {
|
protected class NotificationResourceScheduler extends GCUBEScheduledHandler {
|
||||||
|
|
||||||
|
|
||||||
public NotificationResourceScheduler(long interval, Mode mode) {
|
public NotificationResourceScheduler(long interval, Mode mode) {
|
||||||
super(interval, mode);
|
super(interval, mode);
|
||||||
}
|
}
|
||||||
|
@ -72,9 +73,6 @@ public class ServiceContext extends GCUBEServiceContext {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private ServiceContext() {}
|
private ServiceContext() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -105,6 +103,7 @@ public class ServiceContext extends GCUBEServiceContext {
|
||||||
@Override
|
@Override
|
||||||
protected void onReady() throws Exception {
|
protected void onReady() throws Exception {
|
||||||
|
|
||||||
|
|
||||||
//switch to the production mode if needed
|
//switch to the production mode if needed
|
||||||
if (GHNContext.getContext().getMode() == Mode.ROOT)
|
if (GHNContext.getContext().getMode() == Mode.ROOT)
|
||||||
GHNContext.getContext().setMode(Mode.CONNECTED);
|
GHNContext.getContext().setMode(Mode.CONNECTED);
|
||||||
|
|
|
@ -27,6 +27,8 @@ import org.gcube.informationsystem.registry.impl.contexts.ProfileContext;
|
||||||
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
|
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
|
||||||
import org.globus.wsrf.ResourceException;
|
import org.globus.wsrf.ResourceException;
|
||||||
import org.globus.wsrf.impl.SimpleTopic;
|
import org.globus.wsrf.impl.SimpleTopic;
|
||||||
|
import org.oasis.wsrf.properties.GetMultipleResourcePropertiesResponse;
|
||||||
|
import org.oasis.wsrf.properties.GetMultipleResourceProperties_Element;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
package org.gcube.informationsystem.registry.impl.util;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
import org.gcube.common.core.contexts.GHNContext;
|
||||||
|
import org.gcube.common.core.informationsystem.client.ISClient;
|
||||||
|
import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery;
|
||||||
|
import org.gcube.common.core.scope.GCUBEScope;
|
||||||
|
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||||
|
import org.gcube.informationsystem.registry.impl.state.ProfileResource;
|
||||||
|
|
||||||
|
public class EliminatePoolingThread extends Thread {
|
||||||
|
|
||||||
|
private static List<ProfileResource> stack = Collections.synchronizedList(new LinkedList<ProfileResource>());
|
||||||
|
|
||||||
|
private static GCUBELog logger = new GCUBELog(EliminatePoolingThread.class.getName());
|
||||||
|
|
||||||
|
public void run(){
|
||||||
|
boolean noErrors= true;
|
||||||
|
while(noErrors){
|
||||||
|
try {
|
||||||
|
this.sleep(30000);
|
||||||
|
} catch (InterruptedException e) {}
|
||||||
|
|
||||||
|
LinkedList<ProfileResource> tmpStack = new LinkedList<ProfileResource>();
|
||||||
|
|
||||||
|
ISClient client;
|
||||||
|
GCUBEGenericQuery query;
|
||||||
|
try {
|
||||||
|
client = GHNContext.getImplementation(ISClient.class);
|
||||||
|
query = client.getQuery(GCUBEGenericQuery.class);
|
||||||
|
|
||||||
|
ProfileResource p;
|
||||||
|
synchronized (stack) {
|
||||||
|
int numRes= stack.size();
|
||||||
|
while ((p=stack.remove(stack.size()-1))!=null){
|
||||||
|
query.setExpression("declare namespace is = 'http://gcube-system.org/namespaces/informationsystem/registry';for $result in collection(\"/db/Profile\")//Document/Data/is:Profile/Resource where $result/ID/string() eq '"+p.getID().getValue()+"' return true");
|
||||||
|
if (client.execute(query, GCUBEScope.getScope(p.getResourcePropertySet().getScope().get(0))).size()>0) p.remove();
|
||||||
|
else tmpStack.offer(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("cannot destroy "+tmpStack.size()+" resources retrying in 30 seconds");
|
||||||
|
logger.debug("destroyed "+(numRes-tmpStack.size())+" resources ");
|
||||||
|
stack.addAll(tmpStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Cannot continue with thread Excecution "+e);
|
||||||
|
noErrors=false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static synchronized List<ProfileResource> getStack(){
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue