git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@15886 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
55350ea099
commit
5a50b1ba0a
|
@ -7,10 +7,7 @@ import java.io.StringReader;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.rmi.RemoteException;
|
import java.rmi.RemoteException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Calendar;
|
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.UUIDGen;
|
||||||
import org.apache.axis.components.uuid.UUIDGenFactory;
|
import org.apache.axis.components.uuid.UUIDGenFactory;
|
||||||
import org.gcube.common.core.contexts.GCUBEServiceContext;
|
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.GCUBEHostingNode;
|
||||||
import org.gcube.common.core.resources.GCUBEResource;
|
import org.gcube.common.core.resources.GCUBEResource;
|
||||||
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.utils.events.GCUBEEvent;
|
import org.gcube.common.core.utils.events.GCUBEEvent;
|
||||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||||
import org.gcube.informationsystem.registry.impl.contexts.FactoryContext;
|
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.RegistryProperty;
|
||||||
import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage;
|
import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage;
|
||||||
import org.gcube.informationsystem.registry.stubs.RemoveResourceResponse;
|
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.ResourceNotAcceptedFault;
|
||||||
import org.gcube.informationsystem.registry.stubs.SchemaValidationFault;
|
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.UpdateResourceMessage;
|
||||||
import org.gcube.informationsystem.registry.stubs.UpdateResourceResponse;
|
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;
|
import static org.gcube.informationsystem.registry.impl.core.RegistryConfiguration.ResourceType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the <em>Registry Factory</em> portType
|
* 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 {
|
public class RegistryFactory extends GCUBEPortType {
|
||||||
|
@ -70,15 +61,8 @@ public class RegistryFactory extends GCUBEPortType {
|
||||||
/** Object logger */
|
/** Object logger */
|
||||||
protected final GCUBELog logger = new GCUBELog(RegistryFactory.class);
|
protected final GCUBELog logger = new GCUBELog(RegistryFactory.class);
|
||||||
|
|
||||||
enum OperationType {
|
enum OperationType {create, update, destroy};
|
||||||
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 */
|
/** the key used to label the Factory Resource */
|
||||||
public static final String NOTIFICATOR_RESOURCE_KEY = "RegistryResource";
|
public static final String NOTIFICATOR_RESOURCE_KEY = "RegistryResource";
|
||||||
|
@ -88,36 +72,10 @@ public class RegistryFactory extends GCUBEPortType {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onInitialisation() throws Exception {
|
protected void onInitialisation() throws Exception {
|
||||||
temporaryResourceLifetimeInMs = (Long) ServiceContext.getContext()
|
temporaryResourceLifetimeInMs = (Long) ServiceContext.getContext().getProperty(LIFETIME_JNDI_NAME);
|
||||||
.getProperty(LIFETIME_JNDI_NAME);
|
logger.info("Temporary resources lifetime = " + temporaryResourceLifetimeInMs);
|
||||||
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")
|
@SuppressWarnings("unchecked")
|
||||||
public UpdateResourceResponse updateResource(UpdateResourceMessage mess)
|
public UpdateResourceResponse updateResource(UpdateResourceMessage mess)
|
||||||
throws RemoteException, SchemaValidationFault,
|
throws RemoteException, SchemaValidationFault, ResourceNotAcceptedFault, GCUBEFault {
|
||||||
ResourceNotAcceptedFault, GCUBEFault {
|
|
||||||
|
|
||||||
// logSecurityInfo("updateResource");
|
|
||||||
logger.info("UpdateResource operation invoked");
|
logger.info("UpdateResource operation invoked");
|
||||||
String ID = mess.getUniqueID();
|
String ID = mess.getUniqueID();
|
||||||
String xmlProfile = mess.getXmlProfile();
|
String xmlProfile = mess.getXmlProfile();
|
||||||
|
@ -304,7 +260,6 @@ public class RegistryFactory extends GCUBEPortType {
|
||||||
try {
|
try {
|
||||||
resource = ResourceType.valueOf(mess.getType()).getResourceClass();
|
resource = ResourceType.valueOf(mess.getType()).getResourceClass();
|
||||||
resource.load(new StringReader(xmlProfile));
|
resource.load(new StringReader(xmlProfile));
|
||||||
|
|
||||||
// apply resource filter
|
// apply resource filter
|
||||||
try {
|
try {
|
||||||
if (!FilterManager.getExecutor(resource.getType()).accept(resource)) {
|
if (!FilterManager.getExecutor(resource.getType()).accept(resource)) {
|
||||||
|
@ -329,15 +284,12 @@ public class RegistryFactory extends GCUBEPortType {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
updateCounterInfo(ID, ResourceType.valueOf(mess.getType()),
|
this.updateCounterInfo(ID, ResourceType.valueOf(mess.getType()), OperationType.update, Calendar.getInstance());
|
||||||
OperationType.update, Calendar.getInstance());
|
|
||||||
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>();
|
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>();
|
||||||
event.setPayload(resource);
|
event.setPayload(resource);
|
||||||
ServiceContext.getContext().getTopicProducer().notify(
|
ServiceContext.getContext().getTopicProducer().notify(ServiceContext.RegistryTopic.UPDATE, event);
|
||||||
ServiceContext.RegistryTopic.UPDATE, event);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.warn("Error updating counting info for resource with ID "
|
logger.warn("Error while updating the counting info for resource with ID " + resource.getID(), e);
|
||||||
+ resource.getID(), e);
|
|
||||||
}
|
}
|
||||||
logger.info("Profile " + mess.getUniqueID() + " updated");
|
logger.info("Profile " + mess.getUniqueID() + " updated");
|
||||||
return new UpdateResourceResponse();
|
return new UpdateResourceResponse();
|
||||||
|
@ -481,14 +433,13 @@ public class RegistryFactory extends GCUBEPortType {
|
||||||
*
|
*
|
||||||
* @return NotifierResource resource
|
* @return NotifierResource resource
|
||||||
* @throws RemoteException
|
* @throws RemoteException
|
||||||
* Exception
|
*
|
||||||
*/
|
*/
|
||||||
private RegistryFactoryResource getResource() throws RemoteException {
|
private RegistryFactoryResource getResource() throws RemoteException {
|
||||||
Object resource = null;
|
Object resource = null;
|
||||||
try {
|
try {
|
||||||
resource = FactoryContext.getContext().getWSHome().find(
|
resource = FactoryContext.getContext().getWSHome().find(
|
||||||
FactoryContext.getContext().makeKey(
|
FactoryContext.getContext().makeKey(NOTIFICATOR_RESOURCE_KEY));
|
||||||
NOTIFICATOR_RESOURCE_KEY));
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(" Unable to access resource", e);
|
logger.error(" Unable to access resource", e);
|
||||||
}
|
}
|
||||||
|
@ -498,43 +449,8 @@ public class RegistryFactory extends GCUBEPortType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* {@inheritDoc}
|
||||||
* @param message
|
|
||||||
* UpdateScopeInProfileMessage
|
|
||||||
* @return String
|
|
||||||
* @throws GCUBEFault
|
|
||||||
* -
|
|
||||||
*/
|
*/
|
||||||
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
|
@Override
|
||||||
protected GCUBEServiceContext getServiceContext() {
|
protected GCUBEServiceContext getServiceContext() {
|
||||||
return ServiceContext.getContext();
|
return ServiceContext.getContext();
|
||||||
|
|
|
@ -16,7 +16,7 @@ import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
|
||||||
*/
|
*/
|
||||||
public class EliminatePoolingThread extends Thread {
|
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>());
|
private List<Pair> stack = Collections.synchronizedList(new LinkedList<Pair>());
|
||||||
|
|
||||||
|
@ -24,18 +24,40 @@ public class EliminatePoolingThread extends Thread {
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
boolean noErrors = true;
|
while (true) {
|
||||||
|
|
||||||
while (noErrors) {
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(sleepTime);
|
Thread.sleep(sleepTime);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
|
|
||||||
LinkedList<Pair> tmpStack = new LinkedList<Pair>();
|
|
||||||
try {
|
try {
|
||||||
long timestamp = System.currentTimeMillis();
|
|
||||||
synchronized (stack) {
|
synchronized (stack) {
|
||||||
int numRes = stack.size();
|
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) {
|
while (stack.size() > 0) {
|
||||||
Pair c = stack.remove(stack.size() - 1);
|
Pair c = stack.remove(stack.size() - 1);
|
||||||
logger.trace("checking resource for deletion " + c.resource.getID());
|
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
|
tmpStack.offer(c); // re-insert the resource in the list
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.debug("cannot destroy " + tmpStack.size() + " resources retrying in 30 seconds");
|
return tmpStack;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,50 +1,43 @@
|
||||||
package org.gcube.informationsystem.registry.impl.state;
|
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.resources.GCUBEResource;
|
||||||
import org.gcube.common.core.state.GCUBEWSResource;
|
import org.gcube.common.core.state.GCUBEWSResource;
|
||||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||||
|
import org.gcube.informationsystem.registry.impl.resources.GCUBERegisteredResource;
|
||||||
|
|
||||||
import org.globus.wsrf.ResourceException;
|
import org.globus.wsrf.ResourceException;
|
||||||
import org.w3c.dom.Document;
|
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)
|
* @author Andrea Manzi, Lucio Lelii, Manuele Simi (ISTI-CNR)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ProfileResource extends GCUBEWSResource {
|
public class ProfileResource extends GCUBEWSResource {
|
||||||
|
|
||||||
private static GCUBELog logger = new GCUBELog(ProfileResource.class
|
private static GCUBELog logger = new GCUBELog(ProfileResource.class.getName());
|
||||||
.getName());
|
|
||||||
|
|
||||||
protected GCUBEResource gCubeResource;
|
protected GCUBEResource gCubeResource;
|
||||||
|
|
||||||
protected static final String ProfileRP = "Profile";
|
protected static final String ProfileRP = "Profile";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public ProfileResource() {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected String[] getPropertyNames() {
|
protected String[] getPropertyNames() {
|
||||||
return new String[] { ProfileRP };
|
return new String[] { ProfileRP };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Initializes the resource
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
* Exception
|
|
||||||
*/
|
|
||||||
public ProfileResource() throws Exception {
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* initialize the resource
|
|
||||||
*
|
*
|
||||||
* @param params
|
* @param params
|
||||||
* Object
|
* Object
|
||||||
|
@ -53,85 +46,26 @@ public class ProfileResource extends GCUBEWSResource {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void initialise(Object... params) throws ResourceException {
|
public void initialise(Object... params) throws ResourceException {
|
||||||
GCUBEResource resource = (GCUBEResource) params[0];
|
GCUBERegisteredResource resource;
|
||||||
logger.debug("initializing resource " + resource.getID());
|
|
||||||
Document dom = null;
|
|
||||||
StringWriter writer = new StringWriter();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
resource.store(writer);
|
resource = new GCUBERegisteredResource((GCUBEResource) params[0]);
|
||||||
|
} catch (Exception e) {
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory
|
throw new ResourceException("Invalid GCUBEResource");
|
||||||
.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);
|
|
||||||
}
|
}
|
||||||
|
logger.debug("initializing resource " + resource.getID());
|
||||||
|
|
||||||
this.setProfile(dom);
|
this.setProfile(resource.getAsDOM());
|
||||||
// this.setNotificationProfile(dom);
|
// this.setNotificationProfile(dom);
|
||||||
this.setGCubeResource(resource);
|
this.setGCubeResource(resource.getSource());
|
||||||
|
|
||||||
if (hasToLive(resource))
|
if (resource.isTemporary())
|
||||||
this.setTerminationTime(null);
|
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
|
* @param profile the 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
|
|
||||||
*/
|
*/
|
||||||
public void setProfile(Document profile) {
|
public void setProfile(Document profile) {
|
||||||
this.getResourcePropertySet().get(ProfileRP).clear();
|
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() {
|
public Document getProfile() {
|
||||||
return (Document) this.getResourcePropertySet().get(ProfileRP).get(0);
|
return (Document) this.getResourcePropertySet().get(ProfileRP).get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the profile has to live or not
|
* Returns the source {@link GCUBEResource}
|
||||||
*
|
|
||||||
* @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
|
|
||||||
*
|
*
|
||||||
* @return the resource
|
* @return the resource
|
||||||
*/
|
*/
|
||||||
|
@ -179,7 +91,7 @@ public class ProfileResource extends GCUBEWSResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the resource
|
* Sets the source {@link GCUBEResource}
|
||||||
*
|
*
|
||||||
* @param resource the resource
|
* @param resource the resource
|
||||||
*/
|
*/
|
||||||
|
@ -187,66 +99,18 @@ public class ProfileResource extends GCUBEWSResource {
|
||||||
this.gCubeResource = resource;
|
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
|
* Updates the resource
|
||||||
*
|
*
|
||||||
* @param resource the resource to update
|
* @param resource
|
||||||
* @throws Exception if something goes wrong
|
* the resource to update
|
||||||
|
* @throws Exception
|
||||||
|
* if something goes wrong
|
||||||
*/
|
*/
|
||||||
public void updateResource(GCUBEResource resource) throws Exception {
|
public void updateResource(GCUBEResource resource) throws Exception {
|
||||||
|
GCUBERegisteredResource regResource = new GCUBERegisteredResource(resource);
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
this.setProfile(regResource.getAsDOM());
|
||||||
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);
|
|
||||||
this.setGCubeResource(resource);
|
this.setGCubeResource(resource);
|
||||||
// updates the notification profile too
|
|
||||||
/*
|
|
||||||
* if (this.hasToLive(resource)) this.setNotificationProfile(dom);
|
|
||||||
*/
|
|
||||||
this.store();
|
this.store();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue