This commit is contained in:
Lucio Lelii 2008-09-04 18:29:19 +00:00
parent 578b34406f
commit b64c8a8a59
6 changed files with 90 additions and 100 deletions

View File

@ -1,5 +1,12 @@
package org.gcube.informationsystem.registry.impl;
import java.io.StringWriter;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.axis.utils.XMLUtils;
import org.gcube.common.core.faults.GCUBEFault;
import org.gcube.informationsystem.registry.impl.contexts.ProfileContext;
@ -25,8 +32,8 @@ public class Registry {
public String getProfileAsString(GetProfileString voidType) throws GCUBEFault{
try {
return XMLUtils.DocumentToString(((ProfileResource)ProfileContext.getContext().getWSHome().find()).getProfile());
} catch (ResourceException e) {
return XMLUtils.DocumentToString(((ProfileResource)ProfileContext.getContext().getWSHome().find()).getProfile());
} catch (Exception e) {
e.printStackTrace();
throw new GCUBEFault();
}

View File

@ -11,6 +11,7 @@ import java.util.List;
import org.apache.axis.components.uuid.UUIDGen;
import org.apache.axis.components.uuid.UUIDGenFactory;
import org.apache.axis.utils.XMLUtils;
import org.gcube.common.core.contexts.GCUBEServiceContext;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.faults.GCUBEFault;
@ -138,6 +139,8 @@ public class RegistryFactory extends GCUBEStartupPortType{
logger.info("CreateResource operation invoked");
logSecurityInfo("createResource");
String profile = mess.getProfile();
if (profile == null || profile.compareTo("") == 0) {
String msg = "Profile file empty";
@ -156,6 +159,7 @@ public class RegistryFactory extends GCUBEStartupPortType{
logger.debug("Adding Scopes to Profile "+ scope);
resource.addScope(GCUBEScope.getScope(scope));
}
}
//check ID
if (resource.getID()== null || resource.getID().compareTo("")==0) {resource.setID(uuidgen.nextUUID()); }
@ -305,12 +309,9 @@ public class RegistryFactory extends GCUBEStartupPortType{
if (this.isResourceCreated(ID)){
//destroy the resource
try{
ProfileResource resource = getProfileResource(ID );
resource.removeProfile();
RegistryServiceAddressingLocator locator = new RegistryServiceAddressingLocator();
RegistryPortType portType = locator.getRegistryPortTypePort(resource.getEPR());
portType.destroy(new Destroy());
logger.info(" profile resource destroyed");
ProfileContext.getContext().getWSHome().remove(ProfileContext.getContext().makeKey(ID));
logger.info(" Resource Destroyed");
}
catch (Exception e) {
logger.error("Error removing resource for ID ", e);

View File

@ -77,52 +77,10 @@ public class ServiceContext extends GCUBEServiceContext {
}
/** Tries to create the resource */
protected class NotificationResource extends GCUBEHandler<Object> {
public NotificationResource() {
//register the aggregator content mapping in the current thread. This is because of the container
//behavior: it seems that
//this mapping is available only in the Main thread of the container, but not in the others
TypeMappingRegistry registry = ContainerConfig.getContext().getTypeMappingRegistry();
javax.xml.rpc.encoding.TypeMapping mapping = registry.createTypeMapping();
QName qname = new QName("http://mds.globus.org/aggregator/types","AggregatorContent");
mapping.register(AggregatorContent.class, qname,
new BeanSerializerFactory(AggregatorContent.class, qname),
new BeanDeserializerFactory(AggregatorContent.class,qname));
registry.register("", mapping);
}
@SuppressWarnings("unchecked")
public void run() throws Exception {
List<String> pt = GHNContext.getContext().getActivePortTypes();
if ( (pt == null) || (pt.size() < 1))
throw new Exception();
try {
// register my profile
GCUBERunningInstance RegistryRIProfile = ServiceContext.getContext().getInstance();
GCUBERIQuery query = client.getQuery(GCUBERIQuery.class);
query.addAtomicConditions(new AtomicCondition("//ServiceClass", ServiceContext.this.getServiceClass()),new AtomicCondition("//ServiceName", this.getName()));
if (ServiceContext.this.client.execute(query, GHNContext.getContext().getDefaultScope()).size() == 0)
registerProfile(RegistryRIProfile, GCUBERunningInstance.TYPE);
ServiceContext. this.checkCodeployedServices();
} catch (Exception e) {
logger.error("Failed to register co-deployed services", e);
throw e;
}
ServiceContext.getContext().setScope(ServiceContext.getContext().getInstance().getScopes().values().toArray(new GCUBEScope[0])[0]);
RegistryFactoryResource resource = (RegistryFactoryResource) FactoryContext.getContext().getWSHome().create(
FactoryContext.getContext().makeKey(RegistryFactory.NOTIFICATOR_RESOURCE_KEY));
resource.getPersistenceDelegate().store(resource );
}
}
private ServiceContext() {}
@ -144,9 +102,54 @@ public class ServiceContext extends GCUBEServiceContext {
//creates the single RegistryResource used to raise notifications about profiles' changes
logger.info("Scheduling IS-Registry notification resource...");
NotificationResourceScheduler scheduler = new NotificationResourceScheduler(10, GCUBEScheduledHandler.Mode.LAZY);
scheduler.setHandled(new NotificationResource());
scheduler.run();
NotificationResourceScheduler scheduler = new NotificationResourceScheduler(20, GCUBEScheduledHandler.Mode.LAZY);
scheduler.setHandled(new GCUBEHandler(){
public void run() throws Exception {
//TODO: to remove for gcore 0.4.0
TypeMappingRegistry registry = ContainerConfig.getContext().getTypeMappingRegistry();
javax.xml.rpc.encoding.TypeMapping mapping = registry.createTypeMapping();
QName qname = new QName("http://mds.globus.org/aggregator/types","AggregatorContent");
mapping.register(AggregatorContent.class, qname,
new BeanSerializerFactory(AggregatorContent.class, qname),
new BeanDeserializerFactory(AggregatorContent.class,qname));
registry.register("", mapping);
//-- to remove --
List<String> pt = GHNContext.getContext().getActivePortTypes();
if ( (pt == null) || (pt.size() < 1))
throw new Exception();
try {
// register my profile
GCUBERunningInstance RegistryRIProfile = ServiceContext.getContext().getInstance();
GCUBERIQuery query = ServiceContext.getContext().client.getQuery(GCUBERIQuery.class);
query.addAtomicConditions(new AtomicCondition("//ServiceClass", ServiceContext.this.getServiceClass()),new AtomicCondition("//ServiceName", this.getName()));
if (ServiceContext.getContext().client.execute(query, GHNContext.getContext().getDefaultScope()).size() == 0)
registerProfile(RegistryRIProfile, GCUBERunningInstance.TYPE);
ServiceContext.getContext().checkCodeployedServices();
} catch (Exception e) {
logger.error("Failed to register co-deployed services", e);
throw e;
}
ServiceContext.getContext().setScope(ServiceContext.getContext().getInstance().getScopes().values().toArray(new GCUBEScope[0])[0]);
RegistryFactoryResource resource = (RegistryFactoryResource) FactoryContext.getContext().getWSHome().create(
FactoryContext.getContext().makeKey(RegistryFactory.NOTIFICATOR_RESOURCE_KEY));
resource.getPersistenceDelegate().store(resource );
}
});
scheduler.run();
}
@Override

View File

@ -26,7 +26,6 @@ public class RegistryFactoryPersistenceDelegate extends GCUBEWSFilePersistenceDe
resource.setMetadataCollection((RegistryProperty)ois.readObject());
resource.setRunningInstance((RegistryProperty)ois.readObject());
resource.setService((RegistryProperty)ois.readObject());
resource.setTransformationProgram((RegistryProperty)ois.readObject());
resource.setVRE((RegistryProperty)ois.readObject());
resource.setGenericResource((RegistryProperty)ois.readObject());
SubscriptionPersistenceUtils.loadSubscriptionListeners(
@ -49,7 +48,6 @@ public class RegistryFactoryPersistenceDelegate extends GCUBEWSFilePersistenceDe
oos.writeObject(resource.getMetadataCollection());
oos.writeObject(resource.getRunningInstance());
oos.writeObject(resource.getService());
oos.writeObject(resource.getTransformationProgram());
oos.writeObject(resource.getVRE());
oos.writeObject(resource.getGenericResource());

View File

@ -9,6 +9,7 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.axis.utils.XMLUtils;
import org.gcube.common.core.informationsystem.publisher.ISPublisher;
import org.gcube.common.core.informationsystem.publisher.ISPublisherException;
import org.gcube.common.core.contexts.GHNContext;
@ -62,12 +63,14 @@ public class ProfileResource extends GCUBEWSResource {
@Override
public void initialise(Object... params) throws ResourceException {
GCUBEResource resource = (GCUBEResource) params[0];
Document dom = null;
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);
@ -76,6 +79,15 @@ public class ProfileResource extends GCUBEWSResource {
throw new ResourceException(e1);
}
/*
StringWriter sw= new StringWriter();
try {
resource.store(sw);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
*/
this.setProfile(dom);
this.setNotificationProfile(dom);
this.setGCubeResource(resource);
@ -90,7 +102,7 @@ public class ProfileResource extends GCUBEWSResource {
if (!(RegistryFactory.notificationMap.contains(this.getID()))) {
try {
publisher = GHNContext.getImplementation(ISPublisher.class);
publisher.registerToISNotification(this.getEPR(), listQname, GHNContext.getContext().getDefaultScope(), ServiceContext.getContext());
//publisher.registerToISNotification(this.getEPR(), listQname, GHNContext.getContext().getDefaultScope(), ServiceContext.getContext());
} catch (Exception e){
e.printStackTrace();
throw new ResourceException(e);
@ -191,14 +203,11 @@ public class ProfileResource extends GCUBEWSResource {
}
public void removeProfile() throws ResourceException {
this.getPersistenceDelegate().remove(this);
}
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);

View File

@ -43,9 +43,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
protected static final String VRERP="VRE";
protected static final String GenericRP="Generic";
protected static final String TransformationProgramRP="TransformationProgram";
protected static final String GenericResourceRP="GenericResource";
protected static final String MetadataCollectionRP="MetadataCollection";
@ -65,9 +63,8 @@ public class RegistryFactoryResource extends GCUBEWSResource {
gLiteSiteRP,
gLiteServiceRP,
VRERP,
GenericRP,
TransformationProgramRP,
MetadataCollectionRP
MetadataCollectionRP,
GenericResourceRP
};
@ -448,31 +445,8 @@ public class RegistryFactoryResource extends GCUBEWSResource {
}
/**
* Default Setter for the RP TransRule
*
* @param property The RegistryProperty
*
*/
@SuppressWarnings("unchecked")
public void setTransformationProgram(RegistryProperty property) {
this.getResourcePropertySet().get(TransformationProgramRP).clear();
this.getResourcePropertySet().get(TransformationProgramRP).add(property);
//this.getPersistenceDelegate().store(this);
}
/**
* Default getter for the RP TransRule
*
* @return The RegistryProperty
*
*/
public RegistryProperty getTransformationProgram() {
return (RegistryProperty) this.getResourcePropertySet().get(TransformationProgramRP).get(0);
}
/**
* Default Setter for the RP Generic
*
@ -481,8 +455,8 @@ public class RegistryFactoryResource extends GCUBEWSResource {
*/
@SuppressWarnings("unchecked")
public void setGenericResource (RegistryProperty property) {
this.getResourcePropertySet().get(GenericRP).clear();
this.getResourcePropertySet().get(GenericRP).add(property);
this.getResourcePropertySet().get(GenericResourceRP).clear();
this.getResourcePropertySet().get(GenericResourceRP).add(property);
//this.getPersistenceDelegate().store(this);
}
@ -493,7 +467,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
*
*/
public RegistryProperty getGenericResource () {
return (RegistryProperty) this.getResourcePropertySet().get(GenericRP).get(0);
return (RegistryProperty) this.getResourcePropertySet().get(GenericResourceRP).get(0);
}
@ -556,11 +530,9 @@ public class RegistryFactoryResource extends GCUBEWSResource {
this.getResourcePropertySet().get(MetadataCollectionRP).clear();
this.getResourcePropertySet().get(MetadataCollectionRP).add(property);
this.getResourcePropertySet().get(GenericRP).clear();
this.getResourcePropertySet().get(GenericRP).add(property);
this.getResourcePropertySet().get(TransformationProgramRP).clear();
this.getResourcePropertySet().get(TransformationProgramRP).add(property);
this.getResourcePropertySet().get(GenericResourceRP).clear();
this.getResourcePropertySet().get(GenericResourceRP).add(property);
}