This commit is contained in:
Manuele Simi 2008-06-09 17:26:49 +00:00
parent 9f7f345ace
commit 0f59e47e2b
3 changed files with 74 additions and 69 deletions

View File

@ -2,16 +2,18 @@ package org.gcube.informationsystem.registry.impl.contexts;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
import org.apache.axis.encoding.TypeMappingRegistry; import org.apache.axis.encoding.TypeMappingRegistry;
import org.apache.axis.encoding.ser.BeanDeserializerFactory; import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory; import org.apache.axis.encoding.ser.BeanSerializerFactory;
import org.gcube.common.core.contexts.GCUBEServiceContext; import org.gcube.common.core.contexts.GCUBEServiceContext;
import org.gcube.common.core.contexts.GHNContext; 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.ISClient;
import org.gcube.common.core.informationsystem.client.queries.GCUBERIsFromClassAndName; import org.gcube.common.core.informationsystem.client.queries.GCUBEGHNQuery;
import org.gcube.common.core.informationsystem.client.queries.GCUBEResourceXPathQuery; import org.gcube.common.core.informationsystem.client.queries.GCUBERIQuery;
import org.gcube.common.core.informationsystem.publisher.ISPublisher; import org.gcube.common.core.informationsystem.publisher.ISPublisher;
import org.gcube.common.core.informationsystem.publisher.ISPublisherException; import org.gcube.common.core.informationsystem.publisher.ISPublisherException;
import org.gcube.common.core.resources.GCUBEHostingNode; import org.gcube.common.core.resources.GCUBEHostingNode;
@ -45,9 +47,9 @@ public class ServiceContext extends GCUBEServiceContext {
protected ISClient client = null; protected ISClient client = null;
protected GCUBERIsFromClassAndName queryRI = null; protected GCUBERIQuery queryRI = null;
protected GCUBEResourceXPathQuery queryGHN = null; //protected GCUBEResourceXPathQuery queryGHN = null;
protected boolean isNotifierCodeployed = false; protected boolean isNotifierCodeployed = false;
@ -111,22 +113,14 @@ public class ServiceContext extends GCUBEServiceContext {
} }
@Override @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 //creates the single RegistryResource used to raise notifications about profiles' changes
logger.info("Creating IS-Registry notification resource..."); 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); NotificationResourceScheduler scheduler = new NotificationResourceScheduler(10, GCUBEScheduledHandler.Mode.LAZY);
scheduler.setHandled(new NotificationResource()); scheduler.setHandled(new NotificationResource());
@ -141,15 +135,14 @@ public class ServiceContext extends GCUBEServiceContext {
// Check if the Registry profile is already registered // Check if the Registry profile is already registered
try { try {
// registers the my profile // register my profile
GCUBERunningInstance RegistryRIProfile = ServiceContext.getContext().getInstance(); GCUBERunningInstance RegistryRIProfile = ServiceContext.getContext().getInstance();
this.queryRI.setEntryName("gcube/informationsystem/registry/RegistryFactory"); GCUBERIQuery query = client.getQuery(GCUBERIQuery.class);
this.queryRI.setResourceClass(this.getServiceClass()); query.addAtomicConditions(new AtomicCondition(
this.queryRI.setResourceName(this.getName()); "//Endpoint@EntryName","gcube/informationsystem/registry/RegistryFactory"),new AtomicCondition("//ServiceName", this.getName()));
if (client.execute(this.queryRI, if (this.client.execute(query, GHNContext.getContext().getDefaultScope()).size() == 0)
GHNContext.getContext().getDefaultScope()).size() == 0)
registerProfile(RegistryRIProfile, GCUBERunningInstance.TYPE); registerProfile(RegistryRIProfile, GCUBERunningInstance.TYPE);
this.checkCodeployedServices(); this.checkCodeployedServices();
} catch (Exception e) { } catch (Exception e) {
logger.error("Failed to register co-deployed services", 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); logger.error("Unable to get parse reg file", e1);
} }
//get the needed implementation classes //get the needed implementation classes
this.client = GHNContext.getImplementation(ISClient.class); //this.queryRI = this.client.getQuery(GCUBERIQuery.class);
this.queryRI = this.client.getQuery(GCUBERIsFromClassAndName.class); //this.queryGHN = this.client.getQuery(GCUBEResourceXPathQuery.class);
this.queryGHN = this.client.getQuery(GCUBEResourceXPathQuery.class); this.client = GHNContext.getImplementation(ISClient.class);
} }
/** /**
* Register the Profile * Register the Profile
* *
* @param resource * @param resource the GCUBEResource to register
* teh gCUBEResource * @param type the profile Type
* @param type
* The profile Type
* @throws Exception * @throws Exception
* @throws ISPublisherException * @throws ISPublisherException
*/ */
@ -221,30 +213,34 @@ public class ServiceContext extends GCUBEServiceContext {
// registers the local IS-Notifier profile // registers the local IS-Notifier profile
if (isNotifierCodeployed) { if (isNotifierCodeployed) {
queryRI.setEntryName("gcube/informationsystem/notifier/Notifier"); GCUBERIQuery query = client.getQuery(GCUBERIQuery.class);
queryRI.setResourceClass(ROOT_SERVICES.ISNOTIFIER.getClazz()); query.addAtomicConditions(new AtomicCondition(
queryRI.setResourceName(ROOT_SERVICES.ISNOTIFIER.getName()); "//Endpoint@EntryName","gcube/informationsystem/notifier/Notifier"),new AtomicCondition("//ServiceName", ROOT_SERVICES.ISNOTIFIER.getName()));
if (client.execute(queryRI,
GHNContext.getContext().getDefaultScope()).size() == 0) if (client.execute(query, GHNContext.getContext().getDefaultScope()).size() == 0)
registerProfile(NotifierRIProfile, GCUBERunningInstance.TYPE); registerProfile(NotifierRIProfile, GCUBERunningInstance.TYPE);
} }
// registers the local IS-IC profile // registers the local IS-IC profile
if (isICCodeployed) { if (isICCodeployed) {
queryRI.setEntryName("gcube/informationsystem/isic/ISICFactoryService"); GCUBERIQuery query = client.getQuery(GCUBERIQuery.class);
queryRI.setResourceClass(ROOT_SERVICES.ISIC.getClazz()); query.addAtomicConditions(new AtomicCondition(
queryRI.setResourceName(ROOT_SERVICES.ISIC.getName()); "//Endpoint@EntryName","gcube/informationsystem/isic/ISICFactoryService"),new AtomicCondition("//ServiceName", ROOT_SERVICES.ISIC.getName()));
if (client.execute(queryRI, GHNContext.getContext().getDefaultScope()).size() == 0)
if (client.execute(query, GHNContext.getContext().getDefaultScope()).size() == 0)
registerProfile(ISICRIProfile, GCUBERunningInstance.TYPE); registerProfile(ISICRIProfile, GCUBERunningInstance.TYPE);
} }
// registers the local GHNManager profile // registers the local GHNManager profile
//registers the GHN profile
GCUBEHostingNode ghnProfile = GHNContext.getContext().getGHN(); GCUBEHostingNode ghnProfile = GHNContext.getContext().getGHN();
String ghnName = ghnProfile.getNodeDescription().getName(); GCUBEGHNQuery node = client.getQuery(GCUBEGHNQuery.class);
queryGHN.setResourceType(GCUBEHostingNode.TYPE); node.addAtomicConditions(new AtomicCondition("/GHNDescription/Name", ghnProfile.getNodeDescription().getName()));
queryGHN.setXPath("/GHNDescription/Name/string() eq '" + ghnName + "'");
if (client.execute(queryGHN, GHNContext.getContext().getDefaultScope()).size() == 0) if (client.execute(node, GHNContext.getContext().getDefaultScope()).size() == 0)
registerProfile(ghnProfile, GCUBEHostingNode.TYPE); registerProfile(ghnProfile, GCUBEHostingNode.TYPE);
} }
/** /**

View File

@ -28,9 +28,9 @@ public class RegistryConfiguration {
/** The root service to take care at service's startup */ /** The root service to take care at service's startup */
public static enum ROOT_SERVICES { public static enum ROOT_SERVICES {
ISIC() {public String getClazz() {return "InformationSystem";} public String getName() {return "IS-IC";}}, ISIC() {public String getClazz() {return "InformationSystem";} public String getName() {return "IS-IC";}},
ISNOTIFIER() {public String getClazz() {return "InformationSystem";} public String getName() {return "IS-Notifier";}}, ISNOTIFIER() {public String getClazz() {return "InformationSystem";} public String getName() {return "IS-Notifier";}},
GHNMANAGER() {public String getClazz() {return "VREManagement";} public String getName() {return "GHNManager";}}; 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 getName();
abstract public String getClazz(); abstract public String getClazz();
} }

View File

@ -3,15 +3,16 @@ package org.gcube.informationsystem.registry.impl.util;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.util.List; import java.util.List;
import javax.xml.xpath.XPathExpressionException;
import org.gcube.common.core.contexts.GHNContext; import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.faults.GCUBEFault; import org.gcube.common.core.faults.GCUBEFault;
import org.gcube.common.core.informationsystem.ISException; import org.gcube.common.core.informationsystem.ISException;
import org.gcube.common.core.informationsystem.client.ISClient; 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.ISClient.ISMalformedQueryException;
import org.gcube.common.core.informationsystem.client.queries.GCUBERIsOnGHNQuery; import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery;
import org.gcube.common.core.informationsystem.client.queries.GCUBEResourceFromIDQuery;
import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.resources.GCUBERunningInstance; import org.gcube.common.core.resources.GCUBERunningInstance;
import org.gcube.informationsystem.registry.impl.RegistryFactory; import org.gcube.informationsystem.registry.impl.RegistryFactory;
import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage; 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) * @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 ID
* @param resourceClass * @param resourceClass
@ -46,7 +47,10 @@ public class RegistryUtil {
* @throws ISInvalidQueryException * @throws ISInvalidQueryException
* @throws ISException * @throws ISException
*/ */
public static GCUBEResource getProfileFromIS(String ID, Class<? extends GCUBEResource> resourceClass) throws ISMalformedQueryException, ISInvalidQueryException, ISException { /*public static GCUBEResource getProfileFromIS(String ID, Class<? extends GCUBEResource> resourceClass) throws ISMalformedQueryException, ISInvalidQueryException, ISException {
GCUBEGenericQuery query = client.getQuery("GCUBEResourceQuery");
GCUBEResourceFromIDQuery query =client.getQuery(GCUBEResourceFromIDQuery.class); GCUBEResourceFromIDQuery query =client.getQuery(GCUBEResourceFromIDQuery.class);
query.setResourceClass(resourceClass); query.setResourceClass(resourceClass);
query.setResourceID(ID); query.setResourceID(ID);
@ -54,7 +58,7 @@ public class RegistryUtil {
if (resource != null) return resource.get(0); if (resource != null) return resource.get(0);
else return null; else return null;
} }*/
/** /**
* Unregister all the RIs hosted on a given gHN * Unregister all the RIs hosted on a given gHN
@ -67,19 +71,24 @@ public class RegistryUtil {
* @throws GCUBEFault * @throws GCUBEFault
* @throws RemoteException * @throws RemoteException
*/ */
public static void unregisterRIRelatedToGHN(String id ,RegistryFactory service) throws ISMalformedQueryException, ISInvalidQueryException, ISException, GCUBEFault, RemoteException{ public static void unregisterRIRelatedToGHN(String id ,RegistryFactory service) throws ISMalformedQueryException, ISException, GCUBEFault, RemoteException{
RemoveResourceMessage message = null; RemoveResourceMessage message = null;
GCUBERIsOnGHNQuery query= client.getQuery(GCUBERIsOnGHNQuery.class); GCUBEGenericQuery query = client.getQuery("RIOnGHN");
query.setResourceID(id); query.addParameters(new QueryParameter("ID", GHNContext.getContext().getGHNID()));
//query to IS on order to retrieve the RI deployed on the GHN; //query to IS on order to retrieve the RI deployed on the GHN;
List<GCUBEResource> resources = client.execute(query, GHNContext.getContext().getDefaultScope()); List<XMLResult> resources = client.execute(query, GHNContext.getContext().getDefaultScope());
if (resources.size() != 0){ if (resources.size() != 0){
for (GCUBEResource resource : resources) { for (XMLResult resource : resources) {
message = new RemoveResourceMessage(); try {
message.setType(GCUBERunningInstance.TYPE); message = new RemoveResourceMessage();
message.setUniqueID(resource.getID()); message.setType(GCUBERunningInstance.TYPE);
service.removeResource(message); message.setUniqueID(resource.evaluate("/ID/text()").get(0));
service.removeResource(message);
} catch (XPathExpressionException e) {
e.printStackTrace();
}
} }