From 0f59e47e2bc5ab77f4af820fc3bdae0c4122113c Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Jun 2008 17:26:49 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@1494 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../impl/contexts/ServiceContext.java | 92 +++++++++---------- .../impl/core/RegistryConfiguration.java | 6 +- .../registry/impl/util/RegistryUtil.java | 45 +++++---- 3 files changed, 74 insertions(+), 69 deletions(-) diff --git a/src/org/gcube/informationsystem/registry/impl/contexts/ServiceContext.java b/src/org/gcube/informationsystem/registry/impl/contexts/ServiceContext.java index 39a1bde..f91b85a 100644 --- a/src/org/gcube/informationsystem/registry/impl/contexts/ServiceContext.java +++ b/src/org/gcube/informationsystem/registry/impl/contexts/ServiceContext.java @@ -2,16 +2,18 @@ package org.gcube.informationsystem.registry.impl.contexts; import java.io.ByteArrayInputStream; - 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 static org.gcube.common.core.contexts.GHNContext.Mode; + +import org.gcube.common.core.informationsystem.client.AtomicCondition; import org.gcube.common.core.informationsystem.client.ISClient; -import org.gcube.common.core.informationsystem.client.queries.GCUBERIsFromClassAndName; -import org.gcube.common.core.informationsystem.client.queries.GCUBEResourceXPathQuery; +import org.gcube.common.core.informationsystem.client.queries.GCUBEGHNQuery; +import org.gcube.common.core.informationsystem.client.queries.GCUBERIQuery; import org.gcube.common.core.informationsystem.publisher.ISPublisher; import org.gcube.common.core.informationsystem.publisher.ISPublisherException; import org.gcube.common.core.resources.GCUBEHostingNode; @@ -45,9 +47,9 @@ public class ServiceContext extends GCUBEServiceContext { protected ISClient client = null; - protected GCUBERIsFromClassAndName queryRI = null; + protected GCUBERIQuery queryRI = null; - protected GCUBEResourceXPathQuery queryGHN = null; + //protected GCUBEResourceXPathQuery queryGHN = null; protected boolean isNotifierCodeployed = false; @@ -111,22 +113,14 @@ public class ServiceContext extends GCUBEServiceContext { } @Override - protected void onReady() throws Exception { + protected void onReady() throws Exception { + + //switch to the production mode if needed + if (GHNContext.getContext().getMode() == Mode.ROOT) + GHNContext.getContext().setMode(Mode.PRODUCTION); //creates the single RegistryResource used to raise notifications about profiles' changes logger.info("Creating IS-Registry notification resource..."); - /*new Thread() { - public void run() { - try { - Thread.sleep(5000); - 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 ); - } catch (Exception e) { - ServiceContext.this.logger.error("Failed to create the notification resource", e); - } - }}.start();*/ NotificationResourceScheduler scheduler = new NotificationResourceScheduler(10, GCUBEScheduledHandler.Mode.LAZY); scheduler.setHandled(new NotificationResource()); @@ -141,15 +135,14 @@ public class ServiceContext extends GCUBEServiceContext { // Check if the Registry profile is already registered try { - // registers the my profile - GCUBERunningInstance RegistryRIProfile = ServiceContext.getContext().getInstance(); - this.queryRI.setEntryName("gcube/informationsystem/registry/RegistryFactory"); - this.queryRI.setResourceClass(this.getServiceClass()); - this.queryRI.setResourceName(this.getName()); - if (client.execute(this.queryRI, - GHNContext.getContext().getDefaultScope()).size() == 0) + // register my profile + GCUBERunningInstance RegistryRIProfile = ServiceContext.getContext().getInstance(); + GCUBERIQuery query = client.getQuery(GCUBERIQuery.class); + query.addAtomicConditions(new AtomicCondition( + "//Endpoint@EntryName","gcube/informationsystem/registry/RegistryFactory"),new AtomicCondition("//ServiceName", this.getName())); + if (this.client.execute(query, GHNContext.getContext().getDefaultScope()).size() == 0) registerProfile(RegistryRIProfile, GCUBERunningInstance.TYPE); - + this.checkCodeployedServices(); } catch (Exception e) { logger.error("Failed to register co-deployed services", e); @@ -167,19 +160,18 @@ public class ServiceContext extends GCUBEServiceContext { logger.error("Unable to get parse reg file", e1); } - //get the needed implementation classes - this.client = GHNContext.getImplementation(ISClient.class); - this.queryRI = this.client.getQuery(GCUBERIsFromClassAndName.class); - this.queryGHN = this.client.getQuery(GCUBEResourceXPathQuery.class); + //get the needed implementation classes + //this.queryRI = this.client.getQuery(GCUBERIQuery.class); + //this.queryGHN = this.client.getQuery(GCUBEResourceXPathQuery.class); + this.client = GHNContext.getImplementation(ISClient.class); + } /** * Register the Profile * - * @param resource - * teh gCUBEResource - * @param type - * The profile Type + * @param resource the GCUBEResource to register + * @param type the profile Type * @throws Exception * @throws ISPublisherException */ @@ -221,30 +213,34 @@ public class ServiceContext extends GCUBEServiceContext { // registers the local IS-Notifier profile if (isNotifierCodeployed) { - queryRI.setEntryName("gcube/informationsystem/notifier/Notifier"); - queryRI.setResourceClass(ROOT_SERVICES.ISNOTIFIER.getClazz()); - queryRI.setResourceName(ROOT_SERVICES.ISNOTIFIER.getName()); - if (client.execute(queryRI, - GHNContext.getContext().getDefaultScope()).size() == 0) + GCUBERIQuery query = client.getQuery(GCUBERIQuery.class); + query.addAtomicConditions(new AtomicCondition( + "//Endpoint@EntryName","gcube/informationsystem/notifier/Notifier"),new AtomicCondition("//ServiceName", ROOT_SERVICES.ISNOTIFIER.getName())); + + if (client.execute(query, GHNContext.getContext().getDefaultScope()).size() == 0) registerProfile(NotifierRIProfile, GCUBERunningInstance.TYPE); } // registers the local IS-IC profile if (isICCodeployed) { - queryRI.setEntryName("gcube/informationsystem/isic/ISICFactoryService"); - queryRI.setResourceClass(ROOT_SERVICES.ISIC.getClazz()); - queryRI.setResourceName(ROOT_SERVICES.ISIC.getName()); - if (client.execute(queryRI, GHNContext.getContext().getDefaultScope()).size() == 0) + GCUBERIQuery query = client.getQuery(GCUBERIQuery.class); + query.addAtomicConditions(new AtomicCondition( + "//Endpoint@EntryName","gcube/informationsystem/isic/ISICFactoryService"),new AtomicCondition("//ServiceName", ROOT_SERVICES.ISIC.getName())); + + if (client.execute(query, GHNContext.getContext().getDefaultScope()).size() == 0) registerProfile(ISICRIProfile, GCUBERunningInstance.TYPE); } // registers the local GHNManager profile + + + //registers the GHN profile GCUBEHostingNode ghnProfile = GHNContext.getContext().getGHN(); - String ghnName = ghnProfile.getNodeDescription().getName(); - queryGHN.setResourceType(GCUBEHostingNode.TYPE); - queryGHN.setXPath("/GHNDescription/Name/string() eq '" + ghnName + "'"); - if (client.execute(queryGHN, GHNContext.getContext().getDefaultScope()).size() == 0) + GCUBEGHNQuery node = client.getQuery(GCUBEGHNQuery.class); + node.addAtomicConditions(new AtomicCondition("/GHNDescription/Name", ghnProfile.getNodeDescription().getName())); + + if (client.execute(node, GHNContext.getContext().getDefaultScope()).size() == 0) registerProfile(ghnProfile, GCUBEHostingNode.TYPE); - + } /** diff --git a/src/org/gcube/informationsystem/registry/impl/core/RegistryConfiguration.java b/src/org/gcube/informationsystem/registry/impl/core/RegistryConfiguration.java index 94557e6..28611cb 100644 --- a/src/org/gcube/informationsystem/registry/impl/core/RegistryConfiguration.java +++ b/src/org/gcube/informationsystem/registry/impl/core/RegistryConfiguration.java @@ -28,9 +28,9 @@ public class RegistryConfiguration { /** The root service to take care at service's startup */ public static enum ROOT_SERVICES { ISIC() {public String getClazz() {return "InformationSystem";} public String getName() {return "IS-IC";}}, - ISNOTIFIER() {public String getClazz() {return "InformationSystem";} public String getName() {return "IS-Notifier";}}, - GHNMANAGER() {public String getClazz() {return "VREManagement";} public String getName() {return "GHNManager";}}; - + ISNOTIFIER() {public String getClazz() {return "InformationSystem";} public String getName() {return "IS-Notifier";}}, + GHNMANAGER() {public String getClazz() {return "VREManagement";} public String getName() {return "GHNManager";}}, + DEPLOYER() {public String getClazz() {return "VREManagement";} public String getName() {return "Deployer";}}; abstract public String getName(); abstract public String getClazz(); } diff --git a/src/org/gcube/informationsystem/registry/impl/util/RegistryUtil.java b/src/org/gcube/informationsystem/registry/impl/util/RegistryUtil.java index 88db5ea..8f3f3ab 100644 --- a/src/org/gcube/informationsystem/registry/impl/util/RegistryUtil.java +++ b/src/org/gcube/informationsystem/registry/impl/util/RegistryUtil.java @@ -3,15 +3,16 @@ package org.gcube.informationsystem.registry.impl.util; import java.rmi.RemoteException; import java.util.List; +import javax.xml.xpath.XPathExpressionException; + import org.gcube.common.core.contexts.GHNContext; import org.gcube.common.core.faults.GCUBEFault; import org.gcube.common.core.informationsystem.ISException; import org.gcube.common.core.informationsystem.client.ISClient; -import org.gcube.common.core.informationsystem.client.ISClient.ISInvalidQueryException; +import org.gcube.common.core.informationsystem.client.QueryParameter; +import org.gcube.common.core.informationsystem.client.XMLResult; import org.gcube.common.core.informationsystem.client.ISClient.ISMalformedQueryException; -import org.gcube.common.core.informationsystem.client.queries.GCUBERIsOnGHNQuery; -import org.gcube.common.core.informationsystem.client.queries.GCUBEResourceFromIDQuery; -import org.gcube.common.core.resources.GCUBEResource; +import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery; import org.gcube.common.core.resources.GCUBERunningInstance; import org.gcube.informationsystem.registry.impl.RegistryFactory; import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage; @@ -19,7 +20,7 @@ import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage; /** * - * + * Helper class for IS-registry * * @author Andrea Manzi(ISTI_CNR) * @@ -37,7 +38,7 @@ public class RegistryUtil { } /** - * + * Queries the IS to find a GCUBEResource given its ID * * @param ID * @param resourceClass @@ -46,7 +47,10 @@ public class RegistryUtil { * @throws ISInvalidQueryException * @throws ISException */ - public static GCUBEResource getProfileFromIS(String ID, Class resourceClass) throws ISMalformedQueryException, ISInvalidQueryException, ISException { + /*public static GCUBEResource getProfileFromIS(String ID, Class resourceClass) throws ISMalformedQueryException, ISInvalidQueryException, ISException { + + GCUBEGenericQuery query = client.getQuery("GCUBEResourceQuery"); + GCUBEResourceFromIDQuery query =client.getQuery(GCUBEResourceFromIDQuery.class); query.setResourceClass(resourceClass); query.setResourceID(ID); @@ -54,7 +58,7 @@ public class RegistryUtil { if (resource != null) return resource.get(0); else return null; - } + }*/ /** * Unregister all the RIs hosted on a given gHN @@ -67,19 +71,24 @@ public class RegistryUtil { * @throws GCUBEFault * @throws RemoteException */ - public static void unregisterRIRelatedToGHN(String id ,RegistryFactory service) throws ISMalformedQueryException, ISInvalidQueryException, ISException, GCUBEFault, RemoteException{ - RemoveResourceMessage message = null; - GCUBERIsOnGHNQuery query= client.getQuery(GCUBERIsOnGHNQuery.class); - query.setResourceID(id); + public static void unregisterRIRelatedToGHN(String id ,RegistryFactory service) throws ISMalformedQueryException, ISException, GCUBEFault, RemoteException{ + RemoveResourceMessage message = null; + GCUBEGenericQuery query = client.getQuery("RIOnGHN"); + query.addParameters(new QueryParameter("ID", GHNContext.getContext().getGHNID())); + //query to IS on order to retrieve the RI deployed on the GHN; - List resources = client.execute(query, GHNContext.getContext().getDefaultScope()); + List resources = client.execute(query, GHNContext.getContext().getDefaultScope()); if (resources.size() != 0){ - for (GCUBEResource resource : resources) { - message = new RemoveResourceMessage(); - message.setType(GCUBERunningInstance.TYPE); - message.setUniqueID(resource.getID()); - service.removeResource(message); + for (XMLResult resource : resources) { + try { + message = new RemoveResourceMessage(); + message.setType(GCUBERunningInstance.TYPE); + message.setUniqueID(resource.evaluate("/ID/text()").get(0)); + service.removeResource(message); + } catch (XPathExpressionException e) { + e.printStackTrace(); + } }