This commit is contained in:
Manuele Simi 2008-04-17 13:50:17 +00:00
parent ba50494d88
commit 1484ce8f50
5 changed files with 194 additions and 164 deletions

View File

@ -46,7 +46,7 @@
</xsd:complexType>
<xsd:complexType name="UpdateProfileMessage">
<xsd:complexType name="UpdateResourceMessage">
<xsd:sequence>
<xsd:element name="uniqueID" type="xsd:string"/>
<xsd:element name="type" type="xsd:string"/>
@ -96,7 +96,7 @@
<xsd:element name="createResourceResponse" type="xsd:string"/>
<xsd:element name="updateResource" type="tns:UpdateProfileMessage"/>
<xsd:element name="updateResource" type="tns:UpdateResourceMessage"/>
<xsd:element name="updateResourceResponse">
<xsd:complexType/>

View File

@ -42,7 +42,7 @@ import org.gcube.informationsystem.registry.stubs.RemoveScopeInProfileMessage;
import org.gcube.informationsystem.registry.stubs.SchemaValidationFault;
import org.gcube.informationsystem.registry.stubs.StartRegistration;
import org.gcube.informationsystem.registry.stubs.StartRegistrationResponse;
import org.gcube.informationsystem.registry.stubs.UpdateProfileMessage;
import org.gcube.informationsystem.registry.stubs.UpdateResourceMessage;
import org.gcube.informationsystem.registry.stubs.UpdateResourceResponse;
import org.gcube.informationsystem.registry.stubs.UpdateScopeInProfileMessage;
import org.gcube.informationsystem.registry.stubs.UpdateStateMessage;
@ -58,6 +58,25 @@ 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
};
/**
* The UUIDGen
@ -74,7 +93,7 @@ public class RegistryFactory extends GCUBEStartupPortType{
*
*
*/
public enum operationType {create,update,destroy};
public enum OperationType {create,update,destroy};
/**
* Map of registration to Notification
@ -156,24 +175,31 @@ public class RegistryFactory extends GCUBEStartupPortType{
throw new SchemaValidationFault();
}
//check if the Resource already exists
if (isResourceCreated(resource.getID())) {
logger.debug("A Resource with ID "+ resource.getID()+" is already registered");
throw new ProfileAlreadyRegisteredFault();
}
//try to create resource
try {
logger.debug("Creating the stateful resource for " + resource.getID());
ProfileContext.getContext().getWSHome().create(ProfileContext.getContext().makeKey(resource.getID()),resource);
}
catch (Exception ex) {
String msg = "Error creating Resource";
logger.error(msg,ex);
throw new RemoteException(msg);
}
try {
updateCounterInfo (resource.getID(),inputMessage.getType(),operationType.create.name(),Calendar.getInstance());
} catch (Exception e) {
logger.error("Error updating Counting info for resource with ID " + resource.getID());
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);
//throw new ProfileAlreadyRegisteredFault();
} else {
//try to create resource
try {
logger.debug("Creating the stateful resource for " + resource.getID());
ProfileContext.getContext().getWSHome().create(ProfileContext.getContext().makeKey(resource.getID()),resource);
}
catch (Exception ex) {
String msg = "Error creating Resource";
logger.error(msg,ex);
throw new RemoteException(msg);
}
try {
updateCounterInfo (resource.getID(),inputMessage.getType(), OperationType.create.name(),Calendar.getInstance());
} catch (Exception e) {
logger.error("Error updating Counting info for resource with ID " + resource.getID());
}
}
StringWriter writer = new StringWriter();
@ -183,6 +209,7 @@ public class RegistryFactory extends GCUBEStartupPortType{
} catch (Exception e) {
logger.error("Persistence failed for " + resource.getID(), e);
}
logger.info("Profile created: " + writer.toString());
return writer.toString();
}
@ -196,7 +223,7 @@ public class RegistryFactory extends GCUBEStartupPortType{
* @throws RemoteException Exception
* @throws SchemaValidationException Exception
*/
public UpdateResourceResponse updateResource(UpdateProfileMessage mess) throws RemoteException,SchemaValidationFault,GCUBEFault {
public UpdateResourceResponse updateResource(UpdateResourceMessage mess) throws RemoteException,SchemaValidationFault,GCUBEFault {
logSecurityInfo("updateResource");
logger.info("UpdateResource operation invoked");
@ -232,12 +259,12 @@ public class RegistryFactory extends GCUBEStartupPortType{
}
try {
updateCounterInfo (ID,mess.getType(),operationType.update.name(),Calendar.getInstance());
updateCounterInfo (ID,mess.getType(), OperationType.update.name(),Calendar.getInstance());
} catch (Exception e) {
logger.error("Error updating Counting info for resource with ID " + resource.getID());
e.printStackTrace();
}
logger.info("Profile updated");
logger.info("Profile updated: " + mess.getXmlProfile());
return new UpdateResourceResponse();
}
@ -305,7 +332,7 @@ public class RegistryFactory extends GCUBEStartupPortType{
}
logger.info(" Profile destroyed");
try {
updateCounterInfo(ID,type,operationType.destroy.name(),Calendar.getInstance());
updateCounterInfo(ID,type,OperationType.destroy.name(),Calendar.getInstance());
}
catch (Exception e) {
logger.error("Error updating Counting info for resource with ID " + ID);
@ -372,6 +399,7 @@ public class RegistryFactory extends GCUBEStartupPortType{
* @throws Exception Exception
*/
@SuppressWarnings("unchecked")
private synchronized void updateCounterInfo(String ID, String type, String operationType, Calendar updateTime) throws Exception{
RegistryProperty property = new RegistryProperty();
@ -428,26 +456,7 @@ public class RegistryFactory extends GCUBEStartupPortType{
return null;
}
enum ResourceType {
RunningInstance,
ExternalRunningInstance,
Service,
Collection,
CS,
CSInstance,
GHN,
gLiteSE,
gLiteCE,
gLiteSite,
gLiteService,
VRE,
Generic,
TransformationProgram,
MetadataCollection
};
public String updateScopeInProfile(UpdateScopeInProfileMessage message)throws GCUBEFault{return null;}

View File

@ -4,8 +4,6 @@ import java.util.ArrayList;
import javax.xml.namespace.QName;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.informationsystem.publisher.ISPublisher;
import org.gcube.common.core.state.GCUBEWSResource;
import org.gcube.informationsystem.registry.impl.util.RegistrationThread;
import org.gcube.informationsystem.registry.stubs.RegistryProperty;
@ -53,11 +51,6 @@ public class RegistryFactoryResource extends GCUBEWSResource {
protected static final String RunningInstanceRP="RunningInstance";
@Override
protected String[] getTopicNames() {
return RPNames;
}
protected static String[] RPNames = {
RunningInstanceRP,
ExternalRunningInstanceRP,
@ -71,11 +64,21 @@ public class RegistryFactoryResource extends GCUBEWSResource {
gLiteSiteRP,
gLiteServiceRP,
VRERP,
GenericRP,
GenericRP,
TransformationProgramRP,
MetadataCollectionRP
};
@Override
protected String[] getTopicNames() {
return RPNames;
}
@Override
protected String[] getPropertyNames() {
return RPNames;
}
/**
@ -92,9 +95,8 @@ public class RegistryFactoryResource extends GCUBEWSResource {
logger.debug("Starting RegistryFactoryService");
/* Initialize the RP's */
try {
// Topic List creation for registrationto is-Notifier
try {
//Topic List creation for registrationto is-Notifier
listQname = new ArrayList<QName>();
for (String rpName : RPNames)
listQname.add(new QName(this.getPorttypeContext().getNamespace(),rpName));
@ -110,6 +112,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
} catch (Exception e) {
logger.error("Error on Initialization of Resource",e);
throw new ResourceException("Failed to initialise the RPs and related topics");
}
}
@ -122,6 +125,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
* @param property The RI property
*
*/
@SuppressWarnings("unchecked")
public void setRunningInstance (RegistryProperty property) {
this.getResourcePropertySet().get(RunningInstanceRP).clear();
this.getResourcePropertySet().get(RunningInstanceRP).add(property);
@ -146,6 +150,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
* @param property The RegistryProperty
*
*/
@SuppressWarnings("unchecked")
public void setExternalRunningInstance (RegistryProperty property) {
this.getResourcePropertySet().get(ExternalRunningInstanceRP).clear();
this.getResourcePropertySet().get(ExternalRunningInstanceRP).add(property);
@ -172,6 +177,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
*
*/
@SuppressWarnings("unchecked")
public void setService (RegistryProperty property) {
this.getResourcePropertySet().get(ServiceRP).clear();
this.getResourcePropertySet().get(ServiceRP).add(property);
@ -197,6 +203,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
* @param property The RegistryProperty
*
*/
@SuppressWarnings("unchecked")
public void setCollection (RegistryProperty property) {
this.getResourcePropertySet().get(CollectionRP).clear();
this.getResourcePropertySet().get(CollectionRP).add(property);
@ -221,6 +228,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
* @param property The RegistryProperty
*
*/
@SuppressWarnings("unchecked")
public void setCS (RegistryProperty property) {
this.getResourcePropertySet().get(CSRP).clear();
this.getResourcePropertySet().get(CSRP).add(property);
@ -245,6 +253,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
* @param property The RegistryProperty
*
*/
@SuppressWarnings("unchecked")
public void setCSInstance (RegistryProperty property) {
this.getResourcePropertySet().get(CSInstanceRP).clear();
this.getResourcePropertySet().get(CSInstanceRP).add(property);
@ -270,6 +279,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
* @param property The RegistryProperty
*
*/
@SuppressWarnings("unchecked")
public void setGHN (RegistryProperty property) {
this.getResourcePropertySet().get(GHNRP).clear();
this.getResourcePropertySet().get(GHNRP).add(property);
@ -293,6 +303,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
* @param property The RegistryProperty
*
*/
@SuppressWarnings("unchecked")
public void setGLiteSE (RegistryProperty property) {
this.getResourcePropertySet().get(gLiteSERP).clear();
this.getResourcePropertySet().get(gLiteSERP).add(property);
@ -316,6 +327,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
* @param property The RegistryProperty
*
*/
@SuppressWarnings("unchecked")
public void setGLiteCE (RegistryProperty property) {
this.getResourcePropertySet().get(gLiteCERP).clear();
this.getResourcePropertySet().get(gLiteCERP).add(property);
@ -341,6 +353,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
* @param property The RegistryProperty
*
*/
@SuppressWarnings("unchecked")
public void setGLiteSite (RegistryProperty property) {
this.getResourcePropertySet().get(gLiteSiteRP).clear();
this.getResourcePropertySet().get(gLiteSiteRP).add(property);
@ -365,6 +378,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
* @param property The RegistryProperty
*
*/
@SuppressWarnings("unchecked")
public void setGLiteService (RegistryProperty property) {
this.getResourcePropertySet().get(gLiteServiceRP).clear();
this.getResourcePropertySet().get(gLiteServiceRP).add(property);
@ -388,6 +402,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
* @param property The RegistryProperty
*
*/
@SuppressWarnings("unchecked")
public void setVRE (RegistryProperty property) {
this.getResourcePropertySet().get(VRERP).clear();
this.getResourcePropertySet().get(VRERP).add(property);
@ -412,6 +427,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
* @param property The RegistryProperty
*
*/
@SuppressWarnings("unchecked")
public void setMetaColl (RegistryProperty property) {
this.getResourcePropertySet().get(MetadataCollectionRP).clear();
this.getResourcePropertySet().get(MetadataCollectionRP).add(property);
@ -436,6 +452,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
* @param property The RegistryProperty
*
*/
@SuppressWarnings("unchecked")
public void setTransProgram (RegistryProperty property) {
this.getResourcePropertySet().get(TransformationProgramRP).clear();
this.getResourcePropertySet().get(TransformationProgramRP).add(property);
@ -460,6 +477,7 @@ public class RegistryFactoryResource extends GCUBEWSResource {
* @param property The RegistryProperty
*
*/
@SuppressWarnings("unchecked")
public void setGenericResource (RegistryProperty property) {
this.getResourcePropertySet().get(GenericRP).clear();
this.getResourcePropertySet().get(GenericRP).add(property);

View File

@ -12,7 +12,6 @@ import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.resources.GCUBERunningInstance;
import org.gcube.informationsystem.registry.impl.core.RegistryConfiguration.ROOT_SERVICES;
/**
* IS-Registry service context
*
@ -24,6 +23,17 @@ public class ServiceContext extends GCUBEServiceContext {
public static final String JNDI_NAME = "gcube/informationsystem/registry";
protected static ServiceContext cache = new ServiceContext();
protected ISClient client = null;
protected GCUBERIsFromClassAndName queryRI = null;
protected GCUBEResourceXPathQuery queryGHN = null;
protected boolean isNotifierCodeployed = false;
protected boolean isICCodeployed = false;
private ServiceContext() {}
@ -37,122 +47,40 @@ public class ServiceContext extends GCUBEServiceContext {
@Override
protected void onReady() throws Exception {
GCUBERunningInstance RegistryRIProfile = null;
GCUBERunningInstance NotifierRIProfile = null;
GCUBERunningInstance ISICRIProfile = null;
GCUBERunningInstance GHNManagerProfile = null;
GCUBEHostingNode ghnProfile = null;
String ghnName = "";
GCUBERIsFromClassAndName queryRI = null;
GCUBEResourceXPathQuery queryGHN = null;
boolean isNotifierCodeployed = false;
boolean isICCodeployed = false;
ISClient client = null;
//GCUBERunningInstance GHNManagerProfile = null;
//creates the single RegistryResource used to raise notifications about profiles' changes
logger.info("Creating IS-Registry notification resource...");
FactoryContext.getContext().getWSHome().create(
FactoryContext.getContext().makeKey(RegistryFactory.NOTIFICATOR_RESOURCE_KEY));
logger.info("IS-Registry notification resource registered");
new Thread() {
public void run() {
try {
Thread.sleep(5000);
FactoryContext.getContext().getWSHome().create(
FactoryContext.getContext().makeKey(RegistryFactory.NOTIFICATOR_RESOURCE_KEY));
} catch (Exception e) {
ServiceContext.this.logger.error("Failed to create the notification resource", e);
}
}}.start();
// create GeneralQueryManager
try {
client = GHNContext.getImplementation(ISClient.class);
queryRI = client.getQuery(GCUBERIsFromClassAndName.class);
queryGHN = client.getQuery(GCUBEResourceXPathQuery.class);
} catch (Exception e) {
logger.error("Failed to create a QueryManger", e);
}
logger.info("IS-Registry notification resource registered");
try {
RegistryRIProfile = ServiceContext.getContext().getInstance();
} catch (Exception e) {
logger.error("Unable to get the service instance profile", e);
throw e;
}
try {
NotifierRIProfile = GHNContext.getContext().getServiceContext(
ROOT_SERVICES.ISNOTIFIER.getClazz(), ROOT_SERVICES.ISNOTIFIER.getName()).getInstance();
isNotifierCodeployed = true;
} catch (Exception e) {
logger.warn("Unable to detect if the " + ROOT_SERVICES.ISNOTIFIER.getName() + " is co-deployed");
}
try {
GHNManagerProfile = GHNContext.getContext().getServiceContext(ROOT_SERVICES.GHNMANAGER.getClazz(), ROOT_SERVICES.GHNMANAGER.getName()).getInstance();
} catch (Exception e) {
logger.warn("Unable to detect if the " + ROOT_SERVICES.GHNMANAGER.getName() + " is co-deployed");
}
try {
ISICRIProfile = GHNContext.getContext().getServiceContext( ROOT_SERVICES.ISIC.getClazz(), ROOT_SERVICES.ISIC.getName()).getInstance();
isICCodeployed = true;
} catch (Exception e) {
logger.warn("Unable to detect if the " + ROOT_SERVICES.ISIC.getName() + " is co-deployed");
}
try {
ghnProfile = GHNContext.getContext().getGHN();
ghnName = ghnProfile.getNodeDescription().getName();
} catch (Exception e) {
logger.error("Unable to get the GHN profile", e);
throw e;
}
try {
Thread.sleep(20000);
} catch (InterruptedException e1) {
logger.error("Unable to get the servce instance profile", e1);
try {Thread.sleep(20000);} catch (InterruptedException e1) {
logger.error("Unable to get the service instance profile", e1);
}
// Check if the Registry profile is already registered
try {
// registers the my profile
queryRI.setEntryName("gcube/informationsystem/registry/RegistryFactory");
queryRI.setResourceClass(this.getServiceClass());
queryRI.setResourceName(this.getName());
if (client.execute(queryRI,
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)
registerProfile(RegistryRIProfile, GCUBERunningInstance.TYPE);
// 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)
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)
registerProfile(ISICRIProfile, GCUBERunningInstance.TYPE);
}
// registers the local GHNManager profile
queryGHN.setResourceType(GCUBEHostingNode.TYPE);
queryGHN.setXPath("/GHNDescription/Name/string() eq '" + ghnName + "'");
if (client.execute(queryGHN, GHNContext.getContext().getDefaultScope()).size() == 0)
registerProfile(ghnProfile, GCUBEHostingNode.TYPE);
this.checkCodeployedServices();
} catch (Exception e) {
logger.error("Failed to register co-deployed services", e);
throw e;
@ -161,7 +89,12 @@ public class ServiceContext extends GCUBEServiceContext {
}
@Override
protected void onInitialisation() throws Exception {}
protected void onInitialisation() throws Exception {
//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);
}
/**
* Register the Profile
@ -182,4 +115,74 @@ public class ServiceContext extends GCUBEServiceContext {
}
private void checkCodeployedServices () throws Exception {
GCUBERunningInstance NotifierRIProfile = null;
GCUBERunningInstance ISICRIProfile = null;
try {
NotifierRIProfile = GHNContext.getContext().getServiceContext(
ROOT_SERVICES.ISNOTIFIER.getClazz(), ROOT_SERVICES.ISNOTIFIER.getName()).getInstance();
isNotifierCodeployed = true;
} catch (Exception e) {
logger.warn("Unable to detect if the " + ROOT_SERVICES.ISNOTIFIER.getName() + " is co-deployed");
}
/*try {
ManagerRIProfile = GHNContext.getContext().getServiceContext(ROOT_SERVICES.GHNMANAGER.getClazz(), ROOT_SERVICES.GHNMANAGER.getName()).getInstance();
} catch (Exception e) {
logger.warn("Unable to detect if the " + ROOT_SERVICES.GHNMANAGER.getName() + " is co-deployed");
}*/
try {
ISICRIProfile = GHNContext.getContext().getServiceContext( ROOT_SERVICES.ISIC.getClazz(), ROOT_SERVICES.ISIC.getName()).getInstance();
isICCodeployed = true;
} catch (Exception e) {
logger.warn("Unable to detect if the " + ROOT_SERVICES.ISIC.getName() + " is co-deployed");
}
// 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)
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)
registerProfile(ISICRIProfile, GCUBERunningInstance.TYPE);
}
// registers the local GHNManager 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)
registerProfile(ghnProfile, GCUBEHostingNode.TYPE);
}
/**
*
* @return true if the IS-Notifier service is co-deployed on the node
*/
protected boolean isNotifierCodeployed() {
return isNotifierCodeployed;
}
/**
*
* @return true if the IS-IC service is co-deployed on the node
*/
protected boolean isICCodeployed() {
return isICCodeployed;
}
}

View File

@ -11,7 +11,7 @@ import org.gcube.common.core.resources.GCUBEService;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.security.GCUBESecurityManagerImpl;
import org.gcube.informationsystem.registry.stubs.RegistryFactoryPortType;
import org.gcube.informationsystem.registry.stubs.UpdateProfileMessage;
import org.gcube.informationsystem.registry.stubs.UpdateResourceMessage;
import org.gcube.informationsystem.registry.stubs.service.RegistryFactoryServiceAddressingLocator;
import org.gridforum.jgss.ExtendedGSSCredential;
@ -38,7 +38,7 @@ public static void main (String[]args ) throws Exception {
}catch(Exception e){
e.printStackTrace();
}
UpdateProfileMessage message = new UpdateProfileMessage();
UpdateResourceMessage message = new UpdateResourceMessage();
managerSec.useCredentials(cred);