This commit is contained in:
Manuele Simi 2009-10-13 23:03:22 +00:00
parent 55350ea099
commit 5a50b1ba0a
7 changed files with 390 additions and 518 deletions

View File

@ -7,10 +7,7 @@ import java.io.StringReader;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import org.apache.axis.components.uuid.UUIDGen;
import org.apache.axis.components.uuid.UUIDGenFactory;
import org.gcube.common.core.contexts.GCUBEServiceContext;
@ -19,7 +16,6 @@ import org.gcube.common.core.porttypes.GCUBEPortType;
import org.gcube.common.core.resources.GCUBEHostingNode;
import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.state.GCUBEWSResourceKey;
import org.gcube.common.core.utils.events.GCUBEEvent;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.contexts.FactoryContext;
@ -37,21 +33,16 @@ import org.gcube.informationsystem.registry.stubs.ProfileAlreadyRegisteredFault;
import org.gcube.informationsystem.registry.stubs.RegistryProperty;
import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage;
import org.gcube.informationsystem.registry.stubs.RemoveResourceResponse;
import org.gcube.informationsystem.registry.stubs.RemoveScopeInProfileMessage;
import org.gcube.informationsystem.registry.stubs.ResourceNotAcceptedFault;
import org.gcube.informationsystem.registry.stubs.SchemaValidationFault;
import org.gcube.informationsystem.registry.stubs.StartRegistration;
import org.gcube.informationsystem.registry.stubs.StartRegistrationResponse;
import org.gcube.informationsystem.registry.stubs.UpdateResourceMessage;
import org.gcube.informationsystem.registry.stubs.UpdateResourceResponse;
import org.gcube.informationsystem.registry.stubs.UpdateScopeInProfileMessage;
import org.gcube.informationsystem.registry.stubs.UpdateStateMessage;
import static org.gcube.informationsystem.registry.impl.core.RegistryConfiguration.ResourceType;
/**
* Implementation of the <em>Registry Factory</em> portType
*
* @author Andrea Manzi, Manuele Simi (ISTI-CNR)
* @author Lucio Lelii, Manuele Simi (ISTI-CNR)
*
*/
public class RegistryFactory extends GCUBEPortType {
@ -70,15 +61,8 @@ public class RegistryFactory extends GCUBEPortType {
/** Object logger */
protected final GCUBELog logger = new GCUBELog(RegistryFactory.class);
enum OperationType {
create, update, destroy
};
enum OperationType {create, update, destroy};
/**
* Map of registration to Notification
*/
public static final List<GCUBEWSResourceKey> notificationMap = Collections
.synchronizedList(new ArrayList<GCUBEWSResourceKey>());
/** the key used to label the Factory Resource */
public static final String NOTIFICATOR_RESOURCE_KEY = "RegistryResource";
@ -88,36 +72,10 @@ public class RegistryFactory extends GCUBEPortType {
*/
@Override
protected void onInitialisation() throws Exception {
temporaryResourceLifetimeInMs = (Long) ServiceContext.getContext()
.getProperty(LIFETIME_JNDI_NAME);
logger.info("Temporary resources lifetime = "
+ temporaryResourceLifetimeInMs);
temporaryResourceLifetimeInMs = (Long) ServiceContext.getContext().getProperty(LIFETIME_JNDI_NAME);
logger.info("Temporary resources lifetime = " + temporaryResourceLifetimeInMs);
}
/**
* Use to Load from Disk persistence profiles and registers it into the
* IS-IC ( in case the IS-IC is empty)
*
*
* @param start
* same as void
* @return void
* @throws RemoteException
* Exception
*/
public StartRegistrationResponse startRegistration(StartRegistration start)
throws GCUBEFault {
// start registration to broker and new profiles registration
logger.debug("Starting profile registration from disk");
try {
// loadProfiles();
} catch (Exception e) {
logger.error("Error Loading profiles");
throw new GCUBEFault(e.getMessage());
}
return new StartRegistrationResponse();
}
/**
*
@ -275,10 +233,8 @@ public class RegistryFactory extends GCUBEPortType {
*/
@SuppressWarnings("unchecked")
public UpdateResourceResponse updateResource(UpdateResourceMessage mess)
throws RemoteException, SchemaValidationFault,
ResourceNotAcceptedFault, GCUBEFault {
throws RemoteException, SchemaValidationFault, ResourceNotAcceptedFault, GCUBEFault {
// logSecurityInfo("updateResource");
logger.info("UpdateResource operation invoked");
String ID = mess.getUniqueID();
String xmlProfile = mess.getXmlProfile();
@ -304,7 +260,6 @@ public class RegistryFactory extends GCUBEPortType {
try {
resource = ResourceType.valueOf(mess.getType()).getResourceClass();
resource.load(new StringReader(xmlProfile));
// apply resource filter
try {
if (!FilterManager.getExecutor(resource.getType()).accept(resource)) {
@ -329,15 +284,12 @@ public class RegistryFactory extends GCUBEPortType {
}
try {
updateCounterInfo(ID, ResourceType.valueOf(mess.getType()),
OperationType.update, Calendar.getInstance());
this.updateCounterInfo(ID, ResourceType.valueOf(mess.getType()), OperationType.update, Calendar.getInstance());
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>();
event.setPayload(resource);
ServiceContext.getContext().getTopicProducer().notify(
ServiceContext.RegistryTopic.UPDATE, event);
ServiceContext.getContext().getTopicProducer().notify(ServiceContext.RegistryTopic.UPDATE, event);
} catch (Exception e) {
logger.warn("Error updating counting info for resource with ID "
+ resource.getID(), e);
logger.warn("Error while updating the counting info for resource with ID " + resource.getID(), e);
}
logger.info("Profile " + mess.getUniqueID() + " updated");
return new UpdateResourceResponse();
@ -481,14 +433,13 @@ public class RegistryFactory extends GCUBEPortType {
*
* @return NotifierResource resource
* @throws RemoteException
* Exception
*
*/
private RegistryFactoryResource getResource() throws RemoteException {
Object resource = null;
try {
resource = FactoryContext.getContext().getWSHome().find(
FactoryContext.getContext().makeKey(
NOTIFICATOR_RESOURCE_KEY));
FactoryContext.getContext().makeKey(NOTIFICATOR_RESOURCE_KEY));
} catch (Exception e) {
logger.error(" Unable to access resource", e);
}
@ -498,43 +449,8 @@ public class RegistryFactory extends GCUBEPortType {
}
/**
*
* @param message
* UpdateScopeInProfileMessage
* @return String
* @throws GCUBEFault
* -
* {@inheritDoc}
*/
public String updateScopeInProfile(UpdateScopeInProfileMessage message)
throws GCUBEFault {
return null;
}
/**
*
* @param message
* RemoveScopeInProfileMessage
* @return String
* @throws GCUBEFault
* -
*/
public String removeScopeInProfile(RemoveScopeInProfileMessage message)
throws GCUBEFault {
return null;
}
/**
*
* @param message
* UpdateStateMessage
* @return
* @throws GCUBEFault
* -
*/
public String updateState(UpdateStateMessage message) throws GCUBEFault {
return null;
}
@Override
protected GCUBEServiceContext getServiceContext() {
return ServiceContext.getContext();

View File

@ -16,7 +16,7 @@ import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
*/
public class EliminatePoolingThread extends Thread {
private final long sleepTime = (Long) ServiceContext.getContext().getProperty("temporaryResourceSweeperIntervalInMs");;
private final long sleepTime = (Long) ServiceContext.getContext().getProperty("temporaryResourceSweeperIntervalInMs");
private List<Pair> stack = Collections.synchronizedList(new LinkedList<Pair>());
@ -24,18 +24,40 @@ public class EliminatePoolingThread extends Thread {
public void run() {
boolean noErrors = true;
while (noErrors) {
while (true) {
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {}
LinkedList<Pair> tmpStack = new LinkedList<Pair>();
try {
long timestamp = System.currentTimeMillis();
synchronized (stack) {
int numRes = stack.size();
LinkedList<Pair> undeletedResources = this.checkResources();
logger.debug("cannot destroy " + undeletedResources.size() + " resources, retrying later");
logger.debug("destroyed " + (numRes - undeletedResources.size()) + " resources ");
stack.addAll(undeletedResources);
} // end synchronized block
} catch (Exception e) {
logger.error("Cannot continue with thread Excecution " + e);
break;
}
}
}
public synchronized List<Pair> getStack() {
return this.stack;
}
/**
* Checks and deletes expired temporary resources
* @return the list of still living resources
*/
private LinkedList<Pair> checkResources() {
LinkedList<Pair> tmpStack = new LinkedList<Pair>();
long timestamp = System.currentTimeMillis();
while (stack.size() > 0) {
Pair c = stack.remove(stack.size() - 1);
logger.trace("checking resource for deletion " + c.resource.getID());
@ -52,21 +74,7 @@ public class EliminatePoolingThread extends Thread {
tmpStack.offer(c); // re-insert the resource in the list
}
}
logger.debug("cannot destroy " + tmpStack.size() + " resources retrying in 30 seconds");
logger.debug("destroyed " + (numRes - tmpStack.size()) + " resources ");
stack.addAll(tmpStack);
} // end synchronized block
} catch (Exception e) {
logger.error("Cannot continue with thread Excecution " + e);
noErrors = false;
}
}
}
public synchronized List<Pair> getStack() {
return this.stack;
return tmpStack;
}
}

View File

@ -0,0 +1,84 @@
package org.gcube.informationsystem.registry.impl.resources;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.gcube.common.core.resources.GCUBEHostingNode;
import org.gcube.common.core.resources.GCUBEResource;
/**
* A to-be-registered {@link GCUBEResource} passed to the ISRegistry
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public class GCUBERegisteredResource {
protected GCUBEResource resource;
Document dom = null;
public GCUBERegisteredResource (GCUBEResource resource) throws Exception {
this.resource = resource;
this.parse();
}
public String getID() {
return this.resource.getID();
}
/**
* States if the resource is a temporary resource, i.e. must be destroyed after its registration
* @return
*/
public boolean isTemporary() {
if (resource.getType().compareTo(GCUBEHostingNode.TYPE) == 0)
return false;
else
return true;
}
private void parse() throws Exception {
StringWriter writer = new StringWriter();
try {
resource.store(writer);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
StringReader reader = new StringReader(writer.toString().substring(writer.toString().indexOf("?>") + 2, writer.toString().length()));
InputSource source = new InputSource(reader);
this.dom = builder.parse(source);
} catch (Exception e1) {
throw new Exception("Unable to parse the resource");
}
}
/**
* @return the XML Document representation of the resouce
*/
public Document getAsDOM() {
return this.dom;
}
/**
* @return the source resource
*/
public GCUBEResource getSource() {
return this.resource;
}
}

View File

@ -1,50 +1,43 @@
package org.gcube.informationsystem.registry.impl.state;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.gcube.common.core.resources.GCUBEHostingNode;
import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.state.GCUBEWSResource;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.resources.GCUBERegisteredResource;
import org.globus.wsrf.ResourceException;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
/**
* Stateful resource wrapping a {@link GCUBEResource}
* Profile Stateful resource
*
* @author Andrea Manzi, Lucio Lelii, Manuele Simi (ISTI-CNR)
*
*/
public class ProfileResource extends GCUBEWSResource {
private static GCUBELog logger = new GCUBELog(ProfileResource.class
.getName());
private static GCUBELog logger = new GCUBELog(ProfileResource.class.getName());
protected GCUBEResource gCubeResource;
protected static final String ProfileRP = "Profile";
/**
* Constructor
*
*/
public ProfileResource() {};
/**
* {@inheritDoc}
*/
@Override
protected String[] getPropertyNames() {
return new String[] { ProfileRP };
}
/**
* Constructor
*
* @throws Exception
* Exception
*/
public ProfileResource() throws Exception {
};
/**
* initialize the resource
* Initializes the resource
*
* @param params
* Object
@ -53,85 +46,26 @@ public class ProfileResource extends GCUBEWSResource {
*/
@Override
public void initialise(Object... params) throws ResourceException {
GCUBEResource resource = (GCUBEResource) params[0];
logger.debug("initializing resource " + resource.getID());
Document dom = null;
StringWriter writer = new StringWriter();
GCUBERegisteredResource resource;
try {
resource.store(writer);
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
StringReader reader = new StringReader(writer.toString().substring(
writer.toString().indexOf("?>") + 2,
writer.toString().length()));
InputSource source = new InputSource(reader);
dom = builder.parse(source);
} catch (Exception e1) {
throw new ResourceException(e1);
resource = new GCUBERegisteredResource((GCUBEResource) params[0]);
} catch (Exception e) {
throw new ResourceException("Invalid GCUBEResource");
}
logger.debug("initializing resource " + resource.getID());
this.setProfile(dom);
this.setProfile(resource.getAsDOM());
// this.setNotificationProfile(dom);
this.setGCubeResource(resource);
this.setGCubeResource(resource.getSource());
if (hasToLive(resource))
if (resource.isTemporary())
this.setTerminationTime(null);
/*
* if (hasToLive(resource)) { //registration of Topic To IS-Notifier
*
* listQname.add(new SimpleTopic(this.generateQName()));
* synchronized(RegistryFactory.notificationMap) { if
* (!(RegistryFactory.notificationMap.contains(this.getID()))) { try {
* notifier = GHNContext.getImplementation(ISNotifier.class);
* notifier.registerISNotification(this.getEPR(), listQname,
* ServiceContext.getContext());
*
* } catch (Exception e){ e.printStackTrace(); throw new
* ResourceException(e); }
*
* RegistryFactory.notificationMap.add(this.getID()); } } }
*/
}
/**
* set notification Profile
* Sets Profile
*
* @param profile
* Document
*/
/*
* public void setNotificationProfile(Document profile) {
* this.getResourcePropertySet().get(NotificationProfileRP).clear();
* this.getResourcePropertySet().get(NotificationProfileRP).add(profile);
* //this.getPersistenceDelegate().store(this); }
*/
/**
* get notification Profile
*
* @return Document profile
*/
/*
* public Document getNotificationProfile() { return
* (Document)this.getResourcePropertySet
* ().get(NotificationProfileRP).get(0); }
*/
/**
* set Profile
*
* @param profile
* Document
* @param profile the profile
*/
public void setProfile(Document profile) {
this.getResourcePropertySet().get(ProfileRP).clear();
@ -139,38 +73,16 @@ public class ProfileResource extends GCUBEWSResource {
}
/**
* get Profile
* Gets Profile
*
* @return Document profile
* @return the profile
*/
public Document getProfile() {
return (Document) this.getResourcePropertySet().get(ProfileRP).get(0);
}
/**
* Checks if the profile has to live or not
*
* @param resource the resource
* @return true/false
*/
private boolean hasToLive(GCUBEResource resource) {
if (resource.getType().compareTo(GCUBEHostingNode.TYPE) == 0)
return true;
else
return false;
}
/**
* Gets the Resource QName
*
* @return the Resource QName
*/
// private QName generateQName() {
// return new QName(ProfileContext.getContext().getNamespace(),
// NotificationProfileRP+this.getID().getValue());
// }
/**
* Returns the Resource
* Returns the source {@link GCUBEResource}
*
* @return the resource
*/
@ -179,7 +91,7 @@ public class ProfileResource extends GCUBEWSResource {
}
/**
* Sets the resource
* Sets the source {@link GCUBEResource}
*
* @param resource the resource
*/
@ -187,66 +99,18 @@ public class ProfileResource extends GCUBEWSResource {
this.gCubeResource = resource;
}
// /** {@inheritDoc}*/
// @Override
// public void onRemove() throws ResourceException{
// super.onRemove();
// logger.info("Resource " + this.getID()+ " is going to be removed.");
//
// try {
// publisher = GHNContext.getImplementation(ISPublisher.class);
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// /*
// if (RegistryFactory.notificationMap.contains(this.getID()))
// {
// try {
// notifier = GHNContext.getImplementation(ISNotifier.class);
// notifier.unregisterISNotification(this.getEPR(),listQname,ServiceContext.getContext());
// } catch (ISPublisherException e) {
// e.printStackTrace();
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// synchronized(RegistryFactory.notificationMap) {
// RegistryFactory.notificationMap.remove(this.getID());
// }
// }*/
//
// try {
// publisher.removeWSResource(this,ServiceContext.getContext().getScope());
// //System.out.println(" "+this.getResourcePropertySet().getScope().get(0));
// } catch (ISPublisherException e) {
// e.printStackTrace();
// }
//
// }
/**
* Updates the resource
*
* @param resource the resource to update
* @throws Exception if something goes wrong
* @param resource
* the resource to update
* @throws Exception
* if something goes wrong
*/
public void updateResource(GCUBEResource resource) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
StringWriter writer = new StringWriter();
resource.store(writer);
StringReader reader = new StringReader(writer.toString());
InputSource source = new InputSource(reader);
Document dom = builder.parse(source);
this.setProfile(dom);
GCUBERegisteredResource regResource = new GCUBERegisteredResource(resource);
this.setProfile(regResource.getAsDOM());
this.setGCubeResource(resource);
// updates the notification profile too
/*
* if (this.hasToLive(resource)) this.setNotificationProfile(dom);
*/
this.store();
}