This commit is contained in:
Manuele Simi 2008-05-06 16:25:31 +00:00
parent 639cc77d80
commit 5ff9a7a309
6 changed files with 100 additions and 86 deletions

View File

@ -30,6 +30,7 @@ import org.gcube.common.core.resources.GCUBEVRE;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.state.GCUBEWSResourceKey;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.contexts.FactoryContext;
import org.gcube.informationsystem.registry.impl.contexts.ProfileContext;
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
import org.gcube.informationsystem.registry.impl.state.ProfileResource;
@ -54,6 +55,8 @@ import org.gcube.informationsystem.registry.stubs.service.RegistryServiceAddress
import org.globus.wsrf.security.SecurityManager;
import org.oasis.wsrf.lifetime.Destroy;
import static org.gcube.informationsystem.registry.impl.core.RegistryConfiguration.ResourceType;
/**
* Implementation of the <em>Registry Factory</em> portType
@ -63,24 +66,7 @@ import org.oasis.wsrf.lifetime.Destroy;
*/
public class RegistryFactory extends GCUBEStartupPortType{
public enum ResourceType {
RunningInstance,
ExternalRunningInstance,
Service,
Collection,
CS,
CSInstance,
GHN,
gLiteSE,
gLiteCE,
gLiteSite,
gLiteService,
VRE,
Generic,
TransformationProgram,
MetadataCollection
};
/**
@ -146,25 +132,25 @@ public class RegistryFactory extends GCUBEStartupPortType{
* @throws RemoteException
* @throws ProfileAlreadyRegisteredFault
*/
public String createResource(CreateResourceMessage inputMessage) throws SchemaValidationFault,RemoteException,ProfileAlreadyRegisteredFault {
public String createResource(CreateResourceMessage mess) throws SchemaValidationFault,RemoteException,ProfileAlreadyRegisteredFault {
GCUBEResource resource = null;
logger.info("CreateResource operation invoked");
logSecurityInfo("createResource");
String profile = inputMessage.getProfile();
String profile = mess.getProfile();
if (profile == null || profile.compareTo("") == 0) {
String msg = "Profile file empty";
logger.debug(msg);
throw new RemoteException(msg);
}
try {
resource = this.getResourceClass(inputMessage.getType());
resource = ResourceType.valueOf(mess.getType()).getResourceClass();
resource.load(new StringReader(profile));
//the parse Profile class allows to extract from profiles information about type/SCOPE/UniqueID
//in order to distinguish among different Resource Type
//Adding scopes to Profile
String [] scopes = inputMessage.getScopes();
String [] scopes = mess.getScopes();
if (scopes != null) {
for (String scope : scopes) {
logger.debug("Adding Scopes to Profile "+ scope);
@ -182,11 +168,11 @@ public class RegistryFactory extends GCUBEStartupPortType{
if (isResourceCreated(resource.getID())) {
// update the existing resource
logger.warn("A Resource with ID "+ resource.getID()+" is already registered");
UpdateResourceMessage mess = new UpdateResourceMessage();
mess.setUniqueID(resource.getID());
mess.setXmlProfile(inputMessage.getProfile());
mess.setType(inputMessage.getType());
this.updateResource(mess);
UpdateResourceMessage upmess = new UpdateResourceMessage();
upmess.setUniqueID(resource.getID());
upmess.setXmlProfile(mess.getProfile());
upmess.setType(mess.getType());
this.updateResource(upmess);
//throw new ProfileAlreadyRegisteredFault();
} else {
//try to create resource
@ -201,9 +187,9 @@ public class RegistryFactory extends GCUBEStartupPortType{
throw new RemoteException(msg);
}
try {
updateCounterInfo (resource.getID(),inputMessage.getType(), OperationType.create.name(),Calendar.getInstance());
updateCounterInfo (resource.getID(), ResourceType.valueOf(mess.getType()), OperationType.create, Calendar.getInstance());
} catch (Exception e) {
logger.warn("Error updating Counting info for resource with ID " + resource.getID());
logger.warn("Error updating Counting info for resource with ID " + resource.getID(), e);
}
}
@ -253,7 +239,7 @@ public class RegistryFactory extends GCUBEStartupPortType{
return new UpdateResourceResponse();
}
try {
resource = this.getResourceClass(mess.getType());
resource = ResourceType.valueOf(mess.getType()).getResourceClass();
resource.load(new StringReader(xmlProfile));
getProfileResource(ID).updateResource(resource);
}
@ -263,9 +249,9 @@ public class RegistryFactory extends GCUBEStartupPortType{
}
try {
updateCounterInfo (ID,mess.getType(), OperationType.update.name(),Calendar.getInstance());
updateCounterInfo (ID,ResourceType.valueOf(mess.getType()),OperationType.update, Calendar.getInstance());
} catch (Exception e) {
logger.warn("Error updating counting info for resource with ID " + resource.getID());
logger.warn("Error updating counting info for resource with ID " + resource.getID(), e);
}
logger.info("Profile " + mess.getUniqueID() + " updated");
return new UpdateResourceResponse();
@ -331,10 +317,10 @@ public class RegistryFactory extends GCUBEStartupPortType{
throw new RemoteException();
}
try {
updateCounterInfo(ID,type,OperationType.destroy.name(),Calendar.getInstance());
updateCounterInfo(ID, ResourceType.valueOf(type), OperationType.destroy, Calendar.getInstance());
}
catch (Exception e) {
logger.warn("Error updating counting info for resource with ID " + ID);
logger.warn("Error updating counting info for resource with ID " + ID ,e);
}
}
return new RemoveResourceResponse();
@ -383,7 +369,7 @@ public class RegistryFactory extends GCUBEStartupPortType{
/**
* Update the Registry Factory RPs
* Updates the RegistryFactoryResource RPs for notification
*
*
* @param ID resource ID
@ -394,16 +380,15 @@ public class RegistryFactory extends GCUBEStartupPortType{
*/
@SuppressWarnings("unchecked")
private synchronized void updateCounterInfo(String ID, String type, String operationType, Calendar updateTime) throws Exception{
private synchronized void updateCounterInfo(String ID, ResourceType resType, OperationType opType, Calendar updateTime) throws Exception{
RegistryProperty property = new RegistryProperty();
property.setUniqueID(ID);
property.setOperationType(operationType);
property.setOperationType(opType.name());
property.setChangeTime(updateTime);
//select the type of the resource to update
for (Method method :this.getResource().getClass().getDeclaredMethods()) {
if (method.getName().contains(type) && method.getName().contains("set")) {
if (method.getName().contains(resType.name()) && method.getName().contains("set")) {
method.invoke(this.getResource(),property);
break;
}
@ -420,37 +405,14 @@ public class RegistryFactory extends GCUBEStartupPortType{
private RegistryFactoryResource getResource() throws RemoteException {
Object resource = null;
try {
//resource = FactoryContext.getContext().getWSHome().find(FactoryContext.getContext().makeKey(NOTIFICATOR_RESOURCE_KEY));
resource = FactoryContext.getContext().getWSHome().find(FactoryContext.getContext().makeKey(NOTIFICATOR_RESOURCE_KEY));
} catch (Exception e) {
logger.error(" Unable to access resource", e);
}
RegistryFactoryResource factoryResource = (RegistryFactoryResource) resource;
return factoryResource;
}
private GCUBEResource getResourceClass(String type) throws Exception {
switch (ResourceType.valueOf(type)){
case RunningInstance:return GHNContext.getImplementation(GCUBERunningInstance.class);
case ExternalRunningInstance:return GHNContext.getImplementation(GCUBEExternalRunningInstance.class);
case Service: return GHNContext.getImplementation(GCUBEService.class);
case Collection: return GHNContext.getImplementation(GCUBECollection.class);
case CS: return GHNContext.getImplementation(GCUBECS.class);
case CSInstance: return GHNContext.getImplementation(GCUBECSInstance.class);
case GHN: return GHNContext.getImplementation(GCUBEHostingNode.class);
case VRE: return GHNContext.getImplementation(GCUBEVRE.class);
case TransformationProgram: return GHNContext.getImplementation(GCUBETransformationProgram.class);
case MetadataCollection: return GHNContext.getImplementation(GCUBEMCollection.class);
case Generic: return GHNContext.getImplementation(GCUBEGenericResource.class);
}
return null;
}
}
public String updateScopeInProfile(UpdateScopeInProfileMessage message)throws GCUBEFault{return null;}

View File

@ -1,10 +1,12 @@
package org.gcube.informationsystem.registry.impl.contexts;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.namespace.QName;
import org.apache.axis.encoding.TypeMappingRegistry;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
import org.gcube.common.core.contexts.GCUBEServiceContext;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.informationsystem.client.ISClient;
@ -21,16 +23,18 @@ import org.gcube.common.core.utils.handlers.GCUBEScheduledHandler;
import org.gcube.informationsystem.registry.impl.RegistryFactory;
import org.gcube.informationsystem.registry.impl.core.RegistryConfiguration.ROOT_SERVICES;
import org.gcube.informationsystem.registry.impl.state.RegistryFactoryResource;
import org.globus.mds.aggregator.types.AggregatorContent;
import org.globus.mds.servicegroup.client.ServiceGroupRegistrationParameters;
import org.globus.wsrf.config.ContainerConfig;
import org.globus.wsrf.encoding.ObjectDeserializer;
import org.globus.wsrf.utils.XmlUtils;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
/**
* IS-Registry service context
*
* @author Andrea Manzi, Manuele SImi (CNR)
* @author Andrea Manzi, Manuele Simi (CNR)
*
*/
public class ServiceContext extends GCUBEServiceContext {
@ -58,11 +62,11 @@ public class ServiceContext extends GCUBEServiceContext {
protected boolean repeat(Exception exception, int exceptionCount) {
if (exception!=null) {
/*logger.warn("Failed to create the notification resource (attempt "+exceptionCount+" out of 20)",exception);
logger.warn("Failed to create the notification resource (attempt "+exceptionCount+" out of 20)",exception);
if (exceptionCount >= 20) {
logger.error("Max attempts reached, no more chance to register the notification resource");
return false;
} else*/
} else
return true;
} else
return false;
@ -72,8 +76,23 @@ 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 {
public void run() throws Exception {
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));
@ -92,10 +111,7 @@ public class ServiceContext extends GCUBEServiceContext {
}
@Override
protected void onReady() throws Exception {
//GCUBERunningInstance GHNManagerProfile = null;
protected void onReady() throws Exception {
//creates the single RegistryResource used to raise notifications about profiles' changes
logger.info("Creating IS-Registry notification resource...");
@ -112,9 +128,9 @@ public class ServiceContext extends GCUBEServiceContext {
}
}}.start();*/
/*NotificationResourceScheduler scheduler = new NotificationResourceScheduler(10, GCUBEScheduledHandler.Mode.LAZY);
NotificationResourceScheduler scheduler = new NotificationResourceScheduler(10, GCUBEScheduledHandler.Mode.LAZY);
scheduler.setHandled(new NotificationResource());
scheduler.run();*/
scheduler.run();
logger.info("IS-Registry notification resource registered");

View File

@ -1,5 +1,19 @@
package org.gcube.informationsystem.registry.impl.core;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.resources.GCUBECS;
import org.gcube.common.core.resources.GCUBECSInstance;
import org.gcube.common.core.resources.GCUBECollection;
import org.gcube.common.core.resources.GCUBEExternalRunningInstance;
import org.gcube.common.core.resources.GCUBEGenericResource;
import org.gcube.common.core.resources.GCUBEHostingNode;
import org.gcube.common.core.resources.GCUBEMCollection;
import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.resources.GCUBERunningInstance;
import org.gcube.common.core.resources.GCUBEService;
import org.gcube.common.core.resources.GCUBETransformationProgram;
import org.gcube.common.core.resources.GCUBEVRE;
/**
*
* Local Configuration of the IS-Registry
@ -21,6 +35,28 @@ public class RegistryConfiguration {
abstract public String getClazz();
}
public static enum ResourceType {
RunningInstance() {public GCUBEResource getResourceClass() throws Exception {return GHNContext.getImplementation(GCUBERunningInstance.class);}},
ExternalRunningInstance() {public GCUBEResource getResourceClass() throws Exception {return GHNContext.getImplementation(GCUBEExternalRunningInstance.class);}},
Service() {public GCUBEResource getResourceClass() throws Exception {return GHNContext.getImplementation(GCUBEService.class);}},
Collection() {public GCUBEResource getResourceClass() throws Exception {return GHNContext.getImplementation(GCUBECollection.class);}},
CS() {public GCUBEResource getResourceClass() throws Exception {return GHNContext.getImplementation(GCUBECS.class);}},
CSInstance() {public GCUBEResource getResourceClass() throws Exception {return GHNContext.getImplementation(GCUBECSInstance.class);}},
GHN() {public GCUBEResource getResourceClass() throws Exception {return GHNContext.getImplementation(GCUBEHostingNode.class);}},
gLiteSE() {public GCUBEResource getResourceClass() throws Exception {return null;}},
gLiteCE() {public GCUBEResource getResourceClass() throws Exception {return null;}},
gLiteSite() {public GCUBEResource getResourceClass()throws Exception {return null;}},
gLiteService() {public GCUBEResource getResourceClass() throws Exception {return null;}},
VRE() {public GCUBEResource getResourceClass()throws Exception {return GHNContext.getImplementation(GCUBEVRE.class);}},
GenericResource() {public GCUBEResource getResourceClass() throws Exception {return GHNContext.getImplementation(GCUBEGenericResource.class);}},
TransformationProgram() {public GCUBEResource getResourceClass() throws Exception {return GHNContext.getImplementation(GCUBETransformationProgram.class);}},
MetadataCollection() {public GCUBEResource getResourceClass() throws Exception {return GHNContext.getImplementation(GCUBEMCollection.class);}};
abstract public GCUBEResource getResourceClass() throws Exception;
};
/**
*
*/

View File

@ -23,10 +23,10 @@ public class RegistryFactoryPersistenceDelegate extends GCUBEWSFilePersistenceDe
resource.setCSInstance((RegistryProperty)ois.readObject());
resource.setGHN((RegistryProperty)ois.readObject());
resource.setExternalRunningInstance((RegistryProperty)ois.readObject());
resource.setMetaColl((RegistryProperty)ois.readObject());
resource.setMetadataCollection((RegistryProperty)ois.readObject());
resource.setRunningInstance((RegistryProperty)ois.readObject());
resource.setService((RegistryProperty)ois.readObject());
resource.setTransProgram((RegistryProperty)ois.readObject());
resource.setTransformationProgram((RegistryProperty)ois.readObject());
resource.setVRE((RegistryProperty)ois.readObject());
resource.setGenericResource((RegistryProperty)ois.readObject());
SubscriptionPersistenceUtils.loadSubscriptionListeners(
@ -46,10 +46,10 @@ public class RegistryFactoryPersistenceDelegate extends GCUBEWSFilePersistenceDe
oos.writeObject(resource.getCSInstance());
oos.writeObject(resource.getGHN());
oos.writeObject(resource.getExternalRunningInstance());
oos.writeObject(resource.getMetaColl());
oos.writeObject(resource.getMetadataCollection());
oos.writeObject(resource.getRunningInstance());
oos.writeObject(resource.getService());
oos.writeObject(resource.getTransProgram());
oos.writeObject(resource.getTransformationProgram());
oos.writeObject(resource.getVRE());
oos.writeObject(resource.getGenericResource());

View File

@ -430,7 +430,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
*
*/
@SuppressWarnings("unchecked")
public void setMetaColl (RegistryProperty property) {
public void setMetadataCollection (RegistryProperty property) {
this.getResourcePropertySet().get(MetadataCollectionRP).clear();
this.getResourcePropertySet().get(MetadataCollectionRP).add(property);
//this.getPersistenceDelegate().store(this);
@ -443,7 +443,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
* @return The RegistryProperty
*
*/
public RegistryProperty getMetaColl () {
public RegistryProperty getMetadataCollection () {
return (RegistryProperty) this.getResourcePropertySet().get(MetadataCollectionRP).get(0);
}
@ -455,7 +455,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
*
*/
@SuppressWarnings("unchecked")
public void setTransProgram (RegistryProperty property) {
public void setTransformationProgram(RegistryProperty property) {
this.getResourcePropertySet().get(TransformationProgramRP).clear();
this.getResourcePropertySet().get(TransformationProgramRP).add(property);
//this.getPersistenceDelegate().store(this);
@ -468,7 +468,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
* @return The RegistryProperty
*
*/
public RegistryProperty getTransProgram () {
public RegistryProperty getTransformationProgram() {
return (RegistryProperty) this.getResourcePropertySet().get(TransformationProgramRP).get(0);
}

View File

@ -41,7 +41,7 @@ public class RegistryRemoveTest {
registryFactoryPortType =GCUBERemotePortTypeContext.getProxy(registryFactoryPortType,GCUBEScope.getScope(args[2]),managerSec);
try {
StringWriter writer =new StringWriter();
message.setType(GCUBEHostingNode.TYPE);
message.setType(GCUBERunningInstance.TYPE);
message.setUniqueID(args[1]);
registryFactoryPortType.removeResource(message);