From 058fb3af465d4eca61e10de5bc70270c428ddfa2 Mon Sep 17 00:00:00 2001 From: Andrea Manzi Date: Thu, 20 Mar 2008 18:19:36 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@38 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../registry/impl/core/ProfileResource.java | 10 ++- .../registry/impl/core/RegistryFactory.java | 64 +++++++++++++++++-- .../impl/core/RegistryFactoryResource.java | 3 + .../registry/test/RegistryTest.java | 59 +++++++++++++++++ 4 files changed, 128 insertions(+), 8 deletions(-) create mode 100644 org/gcube/informationsystem/registry/test/RegistryTest.java diff --git a/org/gcube/informationsystem/registry/impl/core/ProfileResource.java b/org/gcube/informationsystem/registry/impl/core/ProfileResource.java index 8654630..a3995e0 100644 --- a/org/gcube/informationsystem/registry/impl/core/ProfileResource.java +++ b/org/gcube/informationsystem/registry/impl/core/ProfileResource.java @@ -87,6 +87,14 @@ public class ProfileResource extends GCUBEWSResource { } } } + //Resource Registration + try { + GHNContext.getImplementation(ISPublisher.class).registerWSResource(this,GHNContext.getContext().getDefaultScope()); + } catch (ISPublisherException e) { + throw new ResourceException(e); + } catch (Exception e) { + throw new ResourceException(e); + } } @@ -169,7 +177,7 @@ public class ProfileResource extends GCUBEWSResource { } try { - publisher.removeWSResource(this); + publisher.removeWSResource(this,GHNContext.getContext().getDefaultScope()); } catch (ISPublisherException e) { e.printStackTrace(); } diff --git a/org/gcube/informationsystem/registry/impl/core/RegistryFactory.java b/org/gcube/informationsystem/registry/impl/core/RegistryFactory.java index 8a55238..875acc0 100644 --- a/org/gcube/informationsystem/registry/impl/core/RegistryFactory.java +++ b/org/gcube/informationsystem/registry/impl/core/RegistryFactory.java @@ -14,8 +14,18 @@ import org.gcube.common.core.is.ISException; import org.gcube.common.core.is.client.ISClient.ISInvalidQueryException; import org.gcube.common.core.is.client.ISClient.ISMalformedQueryException; import org.gcube.common.core.porttypes.GCUBEStartupPortType; +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.GCUBEService; +import org.gcube.common.core.resources.GCUBETransformationProgram; +import org.gcube.common.core.resources.GCUBEVRE; +import org.gcube.common.core.resources.impl.kxml.KGCUBEResource; import org.gcube.common.core.scope.GCUBEScope; import org.gcube.common.core.utils.logging.GCUBELog; import org.gcube.common.is.publisher.impl.GCUBEPublisher; @@ -103,7 +113,8 @@ public class RegistryFactory extends GCUBEStartupPortType{ public String createResource(CreateResourceMessage inputMessage) throws SchemaValidationFault,RemoteException,ProfileAlreadyRegisteredFault { - GCUBEResource resource = null; + + GCUBEResource resource = null; logSecurityInfo("createResource"); String profile = inputMessage.getProfile(); @@ -114,10 +125,10 @@ public class RegistryFactory extends GCUBEStartupPortType{ throw new RemoteException(msg); } - try { - resource.load ( new StringReader(profile)); - resource.getType(); + + resource = this.getResourceClass(inputMessage.getType()); + resource.load(new StringReader(profile)); //the parse Profile class allows to extract from profiles information about type/DL/UniqueID //in order to distiguish among different Resource Type @@ -137,7 +148,7 @@ public class RegistryFactory extends GCUBEStartupPortType{ } catch (Exception ex) { - logger.error("Error trying to loading profile"); + logger.error("Error trying to load profile"); ex.printStackTrace(); throw new SchemaValidationFault(); } @@ -223,7 +234,8 @@ public class RegistryFactory extends GCUBEStartupPortType{ } try { - resource.load(new StringReader(xmlProfile)); + resource = this.getResourceClass(mess.getType()); + resource.load(new StringReader(xmlProfile)); } catch (Exception e) { @@ -456,7 +468,7 @@ public class RegistryFactory extends GCUBEStartupPortType{ private RegistryFactoryResource getResource() throws RemoteException { Object resource = null; try { - resource = FactoryContext.getContext().getWSHome().find(FactoryContext.getContext().makeKey("FactoryResource")); + resource = FactoryContext.getContext().getWSHome().find(FactoryContext.getContext().makeKey("RegistryResource")); //resource= ResourceContext.getResourceContext().getResource(); } catch (Exception e) { logger.error(" Unable to access resource", e); @@ -466,6 +478,44 @@ public class RegistryFactory extends GCUBEStartupPortType{ return factoryResource; } + private GCUBEResource getResourceClass(String type) throws Exception { + + + switch (ResourceType.valueOf(type)){ + 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(GCUBECollection.class); + case Generic: return GHNContext.getImplementation(GCUBEGenericResource.class); + } + return null; + + } + + enum ResourceType { + ExternalRunningInstance, + Service, + Collection, + CS, + CSInstance, + GHN, + gLiteSE, + gLiteCE, + gLiteSite, + gLiteService, + VRE, + Generic, + TransformationProgram, + MetadataCollection + + }; + + public String updateScopeInProfile(UpdateScopeInProfileMessage message)throws GCUBEFault{return null;} public String removeScopeInProfile(RemoveScopeInProfileMessage message)throws GCUBEFault{return null;} diff --git a/org/gcube/informationsystem/registry/impl/core/RegistryFactoryResource.java b/org/gcube/informationsystem/registry/impl/core/RegistryFactoryResource.java index 00d22a7..1008740 100644 --- a/org/gcube/informationsystem/registry/impl/core/RegistryFactoryResource.java +++ b/org/gcube/informationsystem/registry/impl/core/RegistryFactoryResource.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import javax.xml.namespace.QName; +import org.gcube.common.core.contexts.GHNContext; +import org.gcube.common.core.is.publisher.ISPublisher; import org.gcube.common.core.state.GCUBEWSResource; import org.gcube.informationsystem.registry.impl.util.RegistrationThread; import org.gcube.informationsystem.registry.stubs.RegistryProperty; @@ -100,6 +102,7 @@ public class RegistryFactoryResource extends GCUBEWSResource { e.printStackTrace(); logger.error("Error on Registration Thread",e); } + GHNContext.getImplementation(ISPublisher.class).registerWSResource(this,GHNContext.getContext().getDefaultScope()); } catch (Exception e) { logger.error("Error on Initialization of Resource",e); diff --git a/org/gcube/informationsystem/registry/test/RegistryTest.java b/org/gcube/informationsystem/registry/test/RegistryTest.java new file mode 100644 index 0000000..79a02eb --- /dev/null +++ b/org/gcube/informationsystem/registry/test/RegistryTest.java @@ -0,0 +1,59 @@ +package org.gcube.informationsystem.registry.test; + +import java.io.FileReader; +import java.io.StringWriter; + +import org.apache.axis.message.addressing.Address; +import org.apache.axis.message.addressing.EndpointReferenceType; +import org.gcube.common.core.contexts.GHNContext; +import org.gcube.common.core.resources.GCUBEService; +import org.gcube.common.core.security.GCUBESecurityManager; +import org.gcube.common.core.security.GCUBESecurityManagerImpl; +import org.gcube.informationsystem.registry.stubs.CreateResourceMessage; +import org.gcube.informationsystem.registry.stubs.RegistryFactoryPortType; +import org.gcube.informationsystem.registry.stubs.service.RegistryFactoryServiceAddressingLocator; +import org.gridforum.jgss.ExtendedGSSCredential; + +public class RegistryTest { + + public static void main (String[]args ) throws Exception { + + RegistryFactoryServiceAddressingLocator registryLocator = new RegistryFactoryServiceAddressingLocator(); + + GCUBESecurityManagerImpl managerSec = new GCUBESecurityManagerImpl() { public boolean isSecurityEnabled() {return true;}}; + + ExtendedGSSCredential cred =org.diligentproject.dvos.authentication.util.ProxyUtil.loadProxyCredentials(args[2]); + + FileReader fis = new FileReader (args[1]); +// GHNContext.getImplementation(GCUBEService.class); + GCUBEService resource =GHNContext.getImplementation(GCUBEService.class); + EndpointReferenceType factoryEPR = new EndpointReferenceType(); + resource.load(fis); + //resource.store(fir); + + + + RegistryFactoryPortType registryFactoryPortType= null; + try { + factoryEPR.setAddress(new Address(args[0])); + registryFactoryPortType = registryLocator.getRegistryFactoryPortTypePort(factoryEPR); + }catch(Exception e){ + e.printStackTrace(); + } + CreateResourceMessage message = new CreateResourceMessage(); + String profile =""; + managerSec.useCredentials(cred); + managerSec.setSecurity(registryFactoryPortType, GCUBESecurityManager.AuthMode.INTEGRITY, GCUBESecurityManager.DelegationMode.NONE); + try { + StringWriter writer =new StringWriter(); + resource.store(writer); + message.setProfile(writer.toString()); + message.setType(resource.getType()); + profile =registryFactoryPortType.createResource(message); + + } catch(Exception e) { + e.printStackTrace(); + } + System.out.println(profile); + } +}