This commit is contained in:
Manuele Simi 2008-04-15 17:28:28 +00:00
parent e7999e0104
commit e0a1165f7f
18 changed files with 2098 additions and 0 deletions

View File

@ -0,0 +1,44 @@
package org.gcube.informationsystem.registry.impl.core;
import org.gcube.common.core.contexts.GCUBEServiceContext;
import org.gcube.common.core.contexts.GCUBEStatefulPortTypeContext;
/**
* Stateful port-type context for <em>gcube/informationsystem/registry/RegistryFactory</em>
*
* @author Manuele Simi (CNR)
*
*/
public class FactoryContext extends GCUBEStatefulPortTypeContext{
static private final String PORTTYPE_NAME = "gcube/informationsystem/registry/RegistryFactory";
static FactoryContext cache = new FactoryContext();
private FactoryContext() {}
public static FactoryContext getContext() {
return cache;
}
public String getJNDIName() {
return PORTTYPE_NAME;
}
public String getNamespace() {
return "http://gcube-system.org/namespaces/informationsystem/registry";
}
public String getServiceName() {
return ServiceContext.getContext().getName();
}
@Override
public GCUBEServiceContext getServiceContext() {
return ServiceContext.getContext();
}
}

View File

@ -0,0 +1,38 @@
package org.gcube.informationsystem.registry.impl.core;
import org.gcube.common.core.contexts.GCUBEServiceContext;
import org.gcube.common.core.contexts.GCUBEStatefulPortTypeContext;
/**
* Stateful port-type context for <em>gcube/informationsystem/registry/Registry</em>
*
* @author Manuele Simi (CNR)
*
*/
public class ProfileContext extends GCUBEStatefulPortTypeContext{
static private final String PORTTYPE_NAME = "gcube/informationsystem/registry/Registry";
private ProfileContext(){}
protected static ProfileContext cache = new ProfileContext();
public static ProfileContext getContext() {
return cache;
}
public final String getJNDIName() {
return PORTTYPE_NAME;
}
public final String getNamespace() {
return "http://gcube-system.org/namespaces/informationsystem/registry";
}
public GCUBEServiceContext getServiceContext() {
return ServiceContext.getContext();
}
}

View File

@ -0,0 +1,219 @@
package org.gcube.informationsystem.registry.impl.core;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.gcube.common.core.informationsystem.publisher.ISPublisher;
import org.gcube.common.core.informationsystem.publisher.ISPublisherException;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.resources.GCUBEHostingNode;
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.state.GCUBEWSResource;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.globus.wsrf.ResourceException;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
/**
* @author Andrea Manzi
*
*/
public class ProfileResource extends GCUBEWSResource {
private static GCUBELog logger = new GCUBELog(ProfileResource.class.getName());
private ISPublisher publisher = null;
ArrayList<QName> listQname = new ArrayList<QName>();
protected static final String NotificationProfileRP="NotificationProfile";
protected GCUBEResource gCubeResource;
protected static final String ProfileRP="Profile";
@Override
protected String[] getTopicNames(){
return new String[] {NotificationProfileRP};
}
@Override
protected String[] getPropertyNames(){
return new String[] {ProfileRP};
}
/* Constructor
* @throws Exception Exception
*/
public ProfileResource() throws Exception{};
@Override
public void initialise(Object... params) throws ResourceException {
GCUBEResource resource = (GCUBEResource) params[0];
Document dom = null;
StringWriter writer =new StringWriter();
try {
resource.store(writer);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
StringReader reader = new StringReader(writer.toString().substring(writer.toString().indexOf("?>")+2, writer.toString().length()));
InputSource source = new InputSource(reader);
dom =builder.parse(source);
} catch (Exception e1) {
throw new ResourceException(e1);
}
this.setProfile(dom);
this.setNotificationProfile(dom);
this.setGCubeResource(resource);
if (hasToLive(resource)) this.setTerminationTime(null);
if (hasToLive(resource)) {
//registration of Topic To IS-Notifier
listQname.add(this.generateQName());
synchronized(RegistryFactory.notificationMap) {
if (!(RegistryFactory.notificationMap.contains(this.getID()))) {
try {
publisher = GHNContext.getImplementation(ISPublisher.class);
publisher.registerToISNotification(this.getEPR(), listQname, GHNContext.getContext().getDefaultScope(), ServiceContext.getContext());
} catch (Exception e){
e.printStackTrace();
throw new ResourceException(e);
}
RegistryFactory.notificationMap.add(this.getID());
}
}
}
}
public void setNotificationProfile(Document profile) {
this.getResourcePropertySet().get(NotificationProfileRP).clear();
this.getResourcePropertySet().get(NotificationProfileRP).add(profile);
this.getPersistenceDelegate().store(this);
}
public Document getNotificationProfile() {
return (Document)this.getResourcePropertySet().get(NotificationProfileRP).get(0);
}
public void setProfile(Document profile) {
this.getResourcePropertySet().get(ProfileRP).clear();
this.getResourcePropertySet().get(ProfileRP).add(profile);
this.getPersistenceDelegate().store(this);
}
public Document getProfile() {
return (Document)this.getResourcePropertySet().get(ProfileRP).get(0);
}
/**
* Check if the profile has to live or not
* return true/false
*/
private boolean hasToLive(GCUBEResource resource) {
if (resource.getType().compareTo(GCUBERunningInstance.TYPE)==0 ||
resource.getType().compareTo(GCUBEHostingNode.TYPE)==0 ||
resource.getType().compareTo(GCUBEService.TYPE)==0) return true;
else return false;
}
/**
* Get the Resource Qname
* @return the Resource Qname
*/
private QName generateQName() {
return QName.valueOf(NotificationProfileRP.toString()+"_"+this.getID());
}
public GCUBEResource getGCubeResource() {
return this.gCubeResource;
}
public void setGCubeResource(GCUBEResource resource) {
this.gCubeResource = resource;
}
@Override
public void remove() throws ResourceException{
super.remove();
logger.info("Resource " + this.getID()+ " is going to be removed.");
try {
publisher = GHNContext.getImplementation(ISPublisher.class);
} catch (Exception e) {
e.printStackTrace();
}
if (RegistryFactory.notificationMap.contains(this.getID()))
{
try {
publisher.unregisterFromISNotification(this.getEPR(),listQname,GHNContext.getContext().getDefaultScope(),ServiceContext.getContext());
} catch (ISPublisherException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
synchronized(RegistryFactory.notificationMap) {
RegistryFactory.notificationMap.remove(this.getID());
}
}
try {
publisher.removeWSResource(this,GHNContext.getContext().getDefaultScope());
} catch (ISPublisherException e) {
e.printStackTrace();
}
}
protected void removeProfile() throws ResourceException {
this.getPersistenceDelegate().remove(this);
}
public void updateResource(GCUBEResource resource) throws Exception{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
StringWriter writer = new StringWriter();
resource.store(writer);
StringReader reader = new StringReader(writer.toString());
InputSource source = new InputSource(reader);
Document dom = builder.parse(source);
this.setProfile(dom);
this.setGCubeResource(resource);
if (this.hasToLive(resource))
this.setNotificationProfile(dom);
}
}

View File

@ -0,0 +1,13 @@
package org.gcube.informationsystem.registry.impl.core;
import org.gcube.common.core.contexts.GCUBEStatefulPortTypeContext;
import org.gcube.common.core.state.GCUBEWSHome;
public class ProfileResourceHome extends GCUBEWSHome {
public GCUBEStatefulPortTypeContext getPortTypeContext() {
return ProfileContext.getContext();
}
}

View File

@ -0,0 +1,21 @@
package org.gcube.informationsystem.registry.impl.core;
import org.apache.axis.utils.XMLUtils;
import org.gcube.common.core.faults.GCUBEFault;
import org.gcube.informationsystem.registry.impl.core.ProfileResource;
import org.gcube.informationsystem.registry.stubs.GetProfileString;
import org.globus.wsrf.ResourceException;
public class Registry {
public String getProfileString(GetProfileString voidType) throws GCUBEFault{
try {
return XMLUtils.DocumentToString(((ProfileResource)ProfileContext.getContext().getWSHome().find()).getProfile());
} catch (ResourceException e) {
e.printStackTrace();
throw new GCUBEFault();
}
}
}

View File

@ -0,0 +1,109 @@
package org.gcube.informationsystem.registry.impl.core;
/**
*
* Local Configuration of the IS-Registry
*
* @author Andrea Manzi, Manuele Simi (CNR)
*
*/
public class RegistryConfiguration {
/** The root service to take care at service's startup */
public static enum ROOT_SERVICES {
ISIC() {String getClazz() {return "InformationSystem";} String getName() {return "IS-IC";}},
ISNOTIFIER() {String getClazz() {return "InformationSystem";} String getName() {return "IS-Notifier";}},
GHNMANAGER() {String getClazz() {return "VREManagement";} String getName() {return "GHNManager";}};
abstract String getName();
abstract String getClazz();
}
/**
*
*/
private String profilesBase = null;
/**
*
*/
private String propertiesFile = null;
/**
*
*/
private String registrationType = null;
/**
*
*/
private int registrationRemovalInterval = 140;
/**
* Constructor
*/
public RegistryConfiguration () {}
/**
* Get the profile base folder
* @return the profile base folder
*/
public String getProfilesBase() {
return profilesBase;
}
/**
* Set the profile base folder
*
* @param b the profile base folder
*/
public void setProfilesBase(String b) {
profilesBase = b;
}
/**
* The propertie file dir
* @return The propertie file dir
*/
public String getPropertiesFile() {
return propertiesFile;
}
/**
* Set the propertyFile dir
* @param file the file
*/
public void setPropertiesFile(String file) {
propertiesFile = file;
}
/**
* Get The Registration Type
* @return The registration Type
*/
public String getRegistrationType() {
return registrationType;
}
/**
* Set registration Type
* @param file the registration Type
*/
public void setRegistrationType(String type) {
registrationType = type;
}
/**
* Set the Registration time
* @param sec the interval
*/
public void setRegistrationRemovalInterval(int sec) {
registrationRemovalInterval = sec;
}
/**
* Get the registration time interval
* @return The Registration time
*/
public int getRegistrationRemovalInterval() {
return registrationRemovalInterval;
}
}

View File

@ -0,0 +1,459 @@
package org.gcube.informationsystem.registry.impl.core;
import java.io.StringReader;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import org.apache.axis.components.uuid.UUIDGen;
import org.apache.axis.components.uuid.UUIDGenFactory;
import org.gcube.common.core.contexts.GCUBEServiceContext;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.faults.GCUBEFault;
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.GCUBERunningInstance;
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.scope.GCUBEScope;
import org.gcube.common.core.state.GCUBEWSResourceKey;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.util.ProfileManager;
import org.gcube.informationsystem.registry.impl.util.RegistryUtil;
import org.gcube.informationsystem.registry.stubs.CreateResourceMessage;
import org.gcube.informationsystem.registry.stubs.ProfileAlreadyRegisteredFault;
import org.gcube.informationsystem.registry.stubs.RegistryPortType;
import org.gcube.informationsystem.registry.stubs.RegistryProperty;
import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage;
import org.gcube.informationsystem.registry.stubs.RemoveResourceResponse;
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.UpdateResourceResponse;
import org.gcube.informationsystem.registry.stubs.UpdateScopeInProfileMessage;
import org.gcube.informationsystem.registry.stubs.UpdateStateMessage;
import org.gcube.informationsystem.registry.stubs.service.RegistryServiceAddressingLocator;
import org.globus.wsrf.ResourceKey;
import org.globus.wsrf.security.SecurityManager;
import org.oasis.wsrf.lifetime.Destroy;
/**
* @author Andrea Manzi (ISTI-CNR)
*
*/
public class RegistryFactory extends GCUBEStartupPortType{
/**
* The UUIDGen
*/
private static final UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
/**
* Object logger.
* */
protected final GCUBELog logger = new GCUBELog(RegistryFactory.class);
/**
*
*
*/
public enum operationType {create,update,destroy};
/**
* Map of registration to Notification
*/
public static List<GCUBEWSResourceKey> notificationMap = Collections.synchronizedList(new ArrayList<GCUBEWSResourceKey>());
/** the key used to label the Factory Resource */
protected static final String NOTIFICATOR_RESOURCE_KEY = "RegistryResource";
@Override
protected GCUBEServiceContext getServiceContext() {
return ServiceContext.getContext();
}
/**
* Use to Load from Disk persistence profiles and registers it into the IS-IC ( in case the IS-IC is empty)
*
*
* @param start same as void
* @return void
* @throws RemoteException Exception
*/
public StartRegistrationResponse startRegistration(StartRegistration start ) throws GCUBEFault{
//start registration to broker and new profiles registration
logger.debug("Starting profile registration from disk");
try {
//loadProfiles();
} catch (Exception e) {
logger.error("Error Loading profiles");
throw new GCUBEFault(e.getMessage());
}
return new StartRegistrationResponse();
}
/**
*
* Creates a GCUBEResource
*
* @param inputMessage
* @return
* @throws SchemaValidationFault
* @throws RemoteException
* @throws ProfileAlreadyRegisteredFault
*/
public String createResource(CreateResourceMessage inputMessage) throws SchemaValidationFault,RemoteException,ProfileAlreadyRegisteredFault {
GCUBEResource resource = null;
logSecurityInfo("createResource");
logger.info("CreateResource operation invoked");
String profile = inputMessage.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.load(new StringReader(profile));
//the parse Profile class allows to extract from profiles information about type/SCOPE/UniqueID
//in order to distiguish among different Resource Type
//Adding scopes to Profile
String [] scopes = inputMessage.getScopes();
if (scopes != null) {
for (String scope : scopes) {
logger.debug("Adding Scopes to Profile "+ scope);
resource.addScope(GCUBEScope.getScope(scope));
}
}
//check ID
if (resource.getID()== null || resource.getID().compareTo("")==0) {resource.setID(uuidgen.nextUUID()); }
}
catch (Exception ex)
{
logger.error("Error trying to load profile", ex);
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());
}
StringWriter writer = new StringWriter();
try {
logger.debug("Persisting the stateful resource for " + resource.getID());
resource.store(writer);
} catch (Exception e) {
logger.error("Persistence failed for " + resource.getID(), e);
}
return writer.toString();
}
/**
* Updates Resource Profiles ( in case of an update of an ID not present it simply calls the Create resource method)
*
*
* @param mess Complex Object that contains a String representing the xml profile to update and the diligentID
* @return UpdateResourceResponse
* @throws RemoteException Exception
* @throws SchemaValidationException Exception
*/
public UpdateResourceResponse updateResource(UpdateProfileMessage mess) throws RemoteException,SchemaValidationFault,GCUBEFault {
logSecurityInfo("updateResource");
logger.info("UpdateResource operation invoked");
String ID = mess.getUniqueID();
String xmlProfile = mess.getXmlProfile();
GCUBEResource resource = null;
CreateResourceMessage input =null;
//validating input parameters
if (ID == null || ID.compareTo("") ==0) {
logger.debug(" ID missing ");
throw new RemoteException("Error, ID missing");
}
if (xmlProfile == null || xmlProfile.compareTo("") ==0) {
logger.debug("Profile missing" );
throw new RemoteException("Error, profile missing");
}
//check if the profile exist
if (!isResourceCreated(ID)) {
input = new CreateResourceMessage();
input.setProfile(xmlProfile);
input.setType(mess.getType());
this.createResource(input);
return new UpdateResourceResponse();
}
try {
resource = this.getResourceClass(mess.getType());
resource.load(new StringReader(xmlProfile));
getProfileResource(ID).updateResource(resource);
}
catch (Exception e) {
logger.error("Error updating profile for ID "+ e);
throw new RemoteException(e.toString());
}
try {
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");
return new UpdateResourceResponse();
}
/**
* Remove a Resource profile given the ID
*
*
* @param inputMessage Defined into WSDL file
* @return RemoveResourceResponse
* @throws RemoteException Exceptions
*/
public RemoveResourceResponse removeResource (RemoveResourceMessage inputMessage) throws RemoteException,GCUBEFault{
logSecurityInfo("removeResource");
logger.info("RemoveResource operation invoked");
String ID = inputMessage.getUniqueID();
String type = inputMessage.getType();
if (ID == null || ID.compareTo("") ==0) {
logger.debug("ID missing ");
throw new RemoteException("Error, ID missing");
}
//check if the UniqueID exist
if (!(isResourceCreated(ID))){
GCUBEResource resource = null;
try {
resource = RegistryUtil.getProfileFromIS(ID,this.getResourceClass(type).getClass());
} catch (Exception e1) {
logger.error("Error gettign profile from IS ");
return new RemoveResourceResponse();
}
if( resource == null) return new RemoveResourceResponse();
else {
logger.debug("Try to remove the resource from the IS-IC");
try {
new ProfileManager().removeFromISIC(ID, resource.getType(), ServiceContext.getContext().getCredentials());
} catch (Exception e) {
logger.error("Unable to remove the resource", e);
throw ServiceContext.getContext().getDefaultException("", e).toFault("Unable to remove the resource: the remote IS-IC returns an error");
}
}
return new RemoveResourceResponse();
}
try{
ProfileResource resource = getProfileResource(ID );
resource.removeProfile();
RegistryServiceAddressingLocator locator = new RegistryServiceAddressingLocator();
RegistryPortType portType = locator.getRegistryPortTypePort(resource.getEPR());
//destroy resource
portType.destroy(new Destroy());
}
catch (Exception e) {
e.printStackTrace();
logger.error("Error removing resource for ID "+ e);
throw new RemoteException();
}
try {
if (type.compareTo(GCUBEHostingNode.TYPE) == 0) {
RegistryUtil.unregisterRIRelatedToGHN(ID,this);
}
}
catch (Exception e) {
logger.error("Error removing profile related to this GHNID for ID "+ e);
e.printStackTrace();
}
logger.info(" Profile destroyed");
try {
updateCounterInfo(ID,type,operationType.destroy.name(),Calendar.getInstance());
}
catch (Exception e) {
logger.error("Error updating Counting info for resource with ID " + ID);
e.printStackTrace();
}
return new RemoveResourceResponse();
}
/**
* Log Security info
*
* @param methodName The Method Name
*/
private void logSecurityInfo(String methodName) {
logger.info("Security info for method "+ methodName );
String identity = SecurityManager.getManager().getCaller();
logger.info("The caller is: " + identity);
}
/**
* Check if the Resource has been created
*
* @param id the Resource ID
* @return the resource ( null if the resource has not been created yet
*/
protected synchronized ProfileResource getProfileResource(String id ){
ProfileResource resource = null;
ResourceKey key = ProfileContext.getContext().makeKey( id);
try {
resource = (ProfileResource) ProfileContext.getContext().getWSHome().find(key);
}
catch (Exception e ){
logger.debug("A profile with the given id has not been created yet");
return null;
}
return resource;
}
/**
*
* @param id
* @return
*/
protected synchronized boolean isResourceCreated(String id) {
if (getProfileResource(id) != null) return true; else return false;
}
/**
* Update the Registry Factory RPs
*
*
* @param ID resource ID
* @param type the resource type
* @param operationType the type of Operation performed on the Profile
* @param updateTime The last operation Time
* @throws Exception Exception
*/
private synchronized void updateCounterInfo(String ID, String type, String operationType, Calendar updateTime) throws Exception{
RegistryProperty property = new RegistryProperty();
property.setUniqueID(ID);
property.setOperationType(operationType);
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")) {
method.invoke(this.getResource(),property);
break;
}
}
this.getResource().getPersistenceDelegate().store(this.getResource());
}
/**
* return the resource
*
* @return NotifierResource
* @throws RemoteException Exception
*/
private RegistryFactoryResource getResource() throws RemoteException {
Object resource = null;
try {
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;
}
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;}
public String removeScopeInProfile(RemoveScopeInProfileMessage message)throws GCUBEFault{return null;}
public String updateState(UpdateStateMessage message)throws GCUBEFault{return null;}
}

View File

@ -0,0 +1,60 @@
package org.gcube.informationsystem.registry.impl.core;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import org.gcube.common.core.persistence.GCUBEWSFilePersistenceDelegate;
import org.gcube.informationsystem.registry.stubs.RegistryProperty;
import org.globus.wsrf.utils.SubscriptionPersistenceUtils;
public class RegistryFactoryPersistenceDelegate extends GCUBEWSFilePersistenceDelegate<RegistryFactoryResource>{
protected void onLoad(RegistryFactoryResource resource, ObjectInputStream ois) throws Exception {
super.onLoad(resource, ois);
resource.setGLiteCE((RegistryProperty)ois.readObject());
resource.setGLiteSE((RegistryProperty)ois.readObject());
resource.setGLiteService((RegistryProperty)ois.readObject());
resource.setGLiteSite((RegistryProperty)ois.readObject());
resource.setCollection((RegistryProperty)ois.readObject());
resource.setCS((RegistryProperty)ois.readObject());
resource.setCSInstance((RegistryProperty)ois.readObject());
resource.setGHN((RegistryProperty)ois.readObject());
resource.setExternalRunningInstance((RegistryProperty)ois.readObject());
resource.setMetaColl((RegistryProperty)ois.readObject());
resource.setRunningInstance((RegistryProperty)ois.readObject());
resource.setService((RegistryProperty)ois.readObject());
resource.setTransProgram((RegistryProperty)ois.readObject());
resource.setVRE((RegistryProperty)ois.readObject());
resource.setGenericResource((RegistryProperty)ois.readObject());
SubscriptionPersistenceUtils.loadSubscriptionListeners(
resource.getTopicList(), ois);
}
protected void onStore(RegistryFactoryResource resource,ObjectOutputStream oos) throws Exception {
super.onStore(resource, oos);
oos.writeObject(resource.getGLiteCE());
oos.writeObject(resource.getGLiteSE());
oos.writeObject(resource.getGLiteService());
oos.writeObject(resource.getGLiteSite());
oos.writeObject(resource.getCollection());
oos.writeObject(resource.getCS());
oos.writeObject(resource.getCSInstance());
oos.writeObject(resource.getGHN());
oos.writeObject(resource.getExternalRunningInstance());
oos.writeObject(resource.getMetaColl());
oos.writeObject(resource.getRunningInstance());
oos.writeObject(resource.getService());
oos.writeObject(resource.getTransProgram());
oos.writeObject(resource.getVRE());
oos.writeObject(resource.getGenericResource());
SubscriptionPersistenceUtils.storeSubscriptionListeners(
resource.getTopicList(), oos);
}
}

View File

@ -0,0 +1,481 @@
package org.gcube.informationsystem.registry.impl.core;
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;
import org.globus.wsrf.ResourceException;
/**
*
* The <em>RegistryFactoryResource</em> has the role to maintain WS-Topics used to notify changes each time
* a GCUBEResource profile is created/removed/updated. A single instance of this class is created within
* each instance of the IS-Registry service.
*
* @author Andrea Manzi, Manuele Simi (CNR)
*
*/
public class RegistryFactoryResource extends GCUBEWSResource {
protected static final String ExternalRunningInstanceRP="ExternalRunningInstance";
protected static final String ServiceRP="Service";
protected static final String CollectionRP="Collection";
protected static final String CSRP="CS";
protected static final String CSInstanceRP="CSInstance";
protected static final String GHNRP="GHN";
protected static final String gLiteSERP="gLiteSE";
protected static final String gLiteCERP="gLiteCE";
protected static final String gLiteSiteRP="gLiteSite";
protected static final String gLiteServiceRP="gLiteService";
protected static final String VRERP="VRE";
protected static final String GenericRP="Generic";
protected static final String TransformationProgramRP="TransformationProgram";
protected static final String MetadataCollectionRP="MetadataCollection";
protected static final String RunningInstanceRP="RunningInstance";
@Override
protected String[] getTopicNames() {
return RPNames;
}
protected static String[] RPNames = {
RunningInstanceRP,
ExternalRunningInstanceRP,
ServiceRP,
CollectionRP,
CSRP,
CSInstanceRP,
GHNRP,
gLiteSERP,
gLiteCERP,
gLiteSiteRP,
gLiteServiceRP,
VRERP,
GenericRP,
TransformationProgramRP,
MetadataCollectionRP
};
/**
*
*/
private ArrayList<QName> listQname;
/**
*
* Initializes Resource Properties.
* @throws Exception Exception
*/
protected void initialise(Object... o) throws ResourceException {
logger.debug("Starting RegistryFactoryService");
/* Initialize the RP's */
try {
// Topic List creation for registrationto is-Notifier
listQname = new ArrayList<QName>();
for (String rpName : RPNames)
listQname.add(new QName(this.getPorttypeContext().getNamespace(),rpName));
try {
RegistrationThread thread = new RegistrationThread(listQname);
Thread t = new Thread(thread);
t.start();
}catch (Exception e) {
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);
}
}
/**
* Default Setter for the RP runningInstanceRP
*
* @param property The RI property
*
*/
public void setRunningInstance (RegistryProperty property) {
this.getResourcePropertySet().get(RunningInstanceRP).clear();
this.getResourcePropertySet().get(RunningInstanceRP).add(property);
this.getPersistenceDelegate().store(this);
}
/**
* Default getter for the RP runningInstanceRP
*
* @return The RegistryProperty
*/
public RegistryProperty getRunningInstance () {
return (RegistryProperty) this.getResourcePropertySet().get(RunningInstanceRP).get(0);
}
/**
* Default Setter for the RP ExternalRunningInstanceRP
*
* @param property The RegistryProperty
*
*/
public void setExternalRunningInstance (RegistryProperty property) {
this.getResourcePropertySet().get(ExternalRunningInstanceRP).clear();
this.getResourcePropertySet().get(ExternalRunningInstanceRP).add(property);
this.getPersistenceDelegate().store(this);
}
/**
* Default getter for the RP ExternalRunningInstanceRP
*
* @return The RegistryProperty
*
*/
public RegistryProperty getExternalRunningInstance () {
return (RegistryProperty) this.getResourcePropertySet().get(ExternalRunningInstanceRP).get(0);
}
/**
* Default Setter for the RP Service
*
* @param property The RegistryProperty
*
*/
public void setService (RegistryProperty property) {
this.getResourcePropertySet().get(ServiceRP).clear();
this.getResourcePropertySet().get(ServiceRP).add(property);
this.getPersistenceDelegate().store(this);
}
/**
* Default getter for the RP Service
*
* @return The RegistryProperty
*
*/
public RegistryProperty getService () {
return (RegistryProperty) this.getResourcePropertySet().get(ServiceRP).get(0);
}
/**
* Default Setter for the RP Collection
*
* @param property The RegistryProperty
*
*/
public void setCollection (RegistryProperty property) {
this.getResourcePropertySet().get(CollectionRP).clear();
this.getResourcePropertySet().get(CollectionRP).add(property);
this.getPersistenceDelegate().store(this);
}
/**
* Default getter for the RP Collection
* @return The RegistryProperty
*
*/
public RegistryProperty getCollection () {
return (RegistryProperty) this.getResourcePropertySet().get(CollectionRP).get(0);
}
/**
* Default Setter for the RP CS
*
* @param property The RegistryProperty
*
*/
public void setCS (RegistryProperty property) {
this.getResourcePropertySet().get(CSRP).clear();
this.getResourcePropertySet().get(CSRP).add(property);
this.getPersistenceDelegate().store(this);
}
/**
* Default getter for the RP CS
*
* @return The RegistryProperty
*
*/
public RegistryProperty getCS () {
return (RegistryProperty) this.getResourcePropertySet().get(CSRP).get(0);
}
/**
* Default Setter for the RP CSInstance
*
* @param property The RegistryProperty
*
*/
public void setCSInstance (RegistryProperty property) {
this.getResourcePropertySet().get(CSInstanceRP).clear();
this.getResourcePropertySet().get(CSInstanceRP).add(property);
this.getPersistenceDelegate().store(this);
}
/**
* Default getter for the RP CSInstance
*
* @return The RegistryProperty
*
*/
public RegistryProperty getCSInstance () {
return (RegistryProperty) this.getResourcePropertySet().get(CSInstanceRP).get(0);
}
/**
* Default Setter for the RP ghn
*
* @param property The RegistryProperty
*
*/
public void setGHN (RegistryProperty property) {
this.getResourcePropertySet().get(GHNRP).clear();
this.getResourcePropertySet().get(GHNRP).add(property);
this.getPersistenceDelegate().store(this);
}
/**
* Default getter for the RP ghn
*
* @return The RegistryProperty
*/
public RegistryProperty getGHN () {
return (RegistryProperty) this.getResourcePropertySet().get(GHNRP).get(0);
}
/**
* Default Setter for the RP gLiteSE
*
* @param property The RegistryProperty
*
*/
public void setGLiteSE (RegistryProperty property) {
this.getResourcePropertySet().get(gLiteSERP).clear();
this.getResourcePropertySet().get(gLiteSERP).add(property);
this.getPersistenceDelegate().store(this);
}
/**
* Default getter for the RP gLiteSE
*
* @return The RegistryProperty
*
*/
public RegistryProperty getGLiteSE () {
return (RegistryProperty) this.getResourcePropertySet().get(gLiteSERP).get(0);
}
/**
* Default Setter for the RP gLiteCE
*
* @param property The RegistryProperty
*
*/
public void setGLiteCE (RegistryProperty property) {
this.getResourcePropertySet().get(gLiteCERP).clear();
this.getResourcePropertySet().get(gLiteCERP).add(property);
this.getPersistenceDelegate().store(this);
}
/**
* Default getter for the RP gLiteCE
* @return The RegistryProperty
*
*/
public RegistryProperty getGLiteCE () {
return (RegistryProperty) this.getResourcePropertySet().get(gLiteCERP).get(0);
}
/**
* Default Setter for the RP gLiteSite
*
* @param property The RegistryProperty
*
*/
public void setGLiteSite (RegistryProperty property) {
this.getResourcePropertySet().get(gLiteSiteRP).clear();
this.getResourcePropertySet().get(gLiteSiteRP).add(property);
this.getPersistenceDelegate().store(this);
}
/**
* Default getter for the RP gLiteSite
*
* @return The RegistryProperty
*
*/
public RegistryProperty getGLiteSite () {
return (RegistryProperty) this.getResourcePropertySet().get(gLiteSiteRP).get(0);
}
/**
* Default Setter for the RP gLiteSite
*
* @param property The RegistryProperty
*
*/
public void setGLiteService (RegistryProperty property) {
this.getResourcePropertySet().get(gLiteServiceRP).clear();
this.getResourcePropertySet().get(gLiteServiceRP).add(property);
this.getPersistenceDelegate().store(this);
}
/**
* Default getter for the RP gLiteSite
* @return The RegistryProperty
*
*/
public RegistryProperty getGLiteService () {
return (RegistryProperty) this.getResourcePropertySet().get(gLiteServiceRP).get(0);
}
/**
* Default Setter for the RP VRE
*
* @param property The RegistryProperty
*
*/
public void setVRE (RegistryProperty property) {
this.getResourcePropertySet().get(VRERP).clear();
this.getResourcePropertySet().get(VRERP).add(property);
this.getPersistenceDelegate().store(this);
}
/**
* Default getter for the RP VRE
* @return The RegistryProperty
*
*/
public RegistryProperty getVRE () {
return (RegistryProperty) this.getResourcePropertySet().get(gLiteServiceRP).get(0);
}
/**
* Default Setter for the RP MetadataColletion
*
* @param property The RegistryProperty
*
*/
public void setMetaColl (RegistryProperty property) {
this.getResourcePropertySet().get(MetadataCollectionRP).clear();
this.getResourcePropertySet().get(MetadataCollectionRP).add(property);
this.getPersistenceDelegate().store(this);
}
/**
* Default getter for the RP MetadataColletion
*
* @return The RegistryProperty
*
*/
public RegistryProperty getMetaColl () {
return (RegistryProperty) this.getResourcePropertySet().get(MetadataCollectionRP).get(0);
}
/**
* Default Setter for the RP TransRule
*
* @param property The RegistryProperty
*
*/
public void setTransProgram (RegistryProperty property) {
this.getResourcePropertySet().get(TransformationProgramRP).clear();
this.getResourcePropertySet().get(TransformationProgramRP).add(property);
this.getPersistenceDelegate().store(this);
}
/**
* Default getter for the RP TransRule
*
* @return The RegistryProperty
*
*/
public RegistryProperty getTransProgram () {
return (RegistryProperty) this.getResourcePropertySet().get(TransformationProgramRP).get(0);
}
/**
* Default Setter for the RP Generic
*
* @param property The RegistryProperty
*
*/
public void setGenericResource (RegistryProperty property) {
this.getResourcePropertySet().get(GenericRP).clear();
this.getResourcePropertySet().get(GenericRP).add(property);
this.getPersistenceDelegate().store(this);
}
/**
* Default getter for the RP Generic
*
* @return The RegistryProperty
*
*/
public RegistryProperty getGenericResource () {
return (RegistryProperty) this.getResourcePropertySet().get(GenericRP).get(0);
}
}

View File

@ -0,0 +1,11 @@
package org.gcube.informationsystem.registry.impl.core;
import org.gcube.common.core.contexts.GCUBEStatefulPortTypeContext;
import org.gcube.common.core.state.GCUBEWSHome;
public class RegistryFactoryResourceHome extends GCUBEWSHome {
public GCUBEStatefulPortTypeContext getPortTypeContext() {
return FactoryContext.getContext();
}
}

View File

@ -0,0 +1,24 @@
package org.gcube.informationsystem.registry.impl.core;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import org.gcube.common.core.persistence.GCUBEWSFilePersistenceDelegate;
import org.w3c.dom.Document;
public class RegistryPersistenceDelegate extends GCUBEWSFilePersistenceDelegate<ProfileResource> {
protected void onLoad(ProfileResource resource, ObjectInputStream ois) throws Exception {
super.onLoad(resource, ois);
resource.setProfile((Document)ois.readObject());
resource.setNotificationProfile(resource.getProfile());
}
protected void onStore(ProfileResource resource,ObjectOutputStream oos) throws Exception {
super.onStore(resource, oos);
oos.writeObject((Document)resource.getProfile());
}
}

View File

@ -0,0 +1,185 @@
package org.gcube.informationsystem.registry.impl.core;
import org.gcube.common.core.contexts.GCUBEServiceContext;
import org.gcube.common.core.contexts.GHNContext;
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.publisher.ISPublisher;
import org.gcube.common.core.informationsystem.publisher.ISPublisherException;
import org.gcube.common.core.resources.GCUBEHostingNode;
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
*
* @author Andrea Manzi, Manuele SImi (CNR)
*
*/
public class ServiceContext extends GCUBEServiceContext {
public static final String JNDI_NAME = "gcube/informationsystem/registry";
protected static ServiceContext cache = new ServiceContext();
private ServiceContext() {}
public static ServiceContext getContext() {
return cache;
}
public String getJNDIName() {
return JNDI_NAME;
}
@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;
//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");
// 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);
}
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);
}
// 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,
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);
} catch (Exception e) {
logger.error("Failed to register co-deployed services", e);
throw e;
}
}
@Override
protected void onInitialisation() throws Exception {}
/**
* Register the Profile
*
* @param resource
* teh gCUBEResource
* @param type
* The profile Type
* @throws Exception
* @throws ISPublisherException
*/
private void registerProfile(GCUBEResource resource, String type)
throws ISPublisherException, Exception {
if (GHNContext.getContext().getMode() == GHNContext.Mode.ROOT)
GHNContext.getImplementation(ISPublisher.class).registerGCUBEResource(
resource, GHNContext.getContext().getDefaultScope(),
ServiceContext.getContext());
}
}

View File

@ -0,0 +1,110 @@
package org.gcube.informationsystem.registry.impl.util;
import java.net.MalformedURLException;
import java.net.URL;
import org.diligentproject.informationservice.disic.stubs.DISICServiceLocator;
import org.diligentproject.informationservice.disic.stubs.DISICServicePortType;
import org.diligentproject.informationservice.disic.stubs.DeleteProfileParams;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.scope.GCUBEScopeNotSupportedException;
import org.gcube.common.core.scope.ServiceMap;
import org.gcube.common.core.scope.ServiceMap.ServiceType;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.core.ServiceContext;
import org.ietf.jgss.GSSCredential;
public class ProfileManager {
protected static final GCUBELog logger=new GCUBELog(ProfileManager.class);
protected static final String ISICpostfix = "ISICService";
protected URL isIcAddress;
protected String VOMapName;
public enum ResourceTypes {
Service,
CS,
CSInstance,
Collection,
RunningInstance,
ExternalRunningInstance,
DHN,
gLiteResource,
VDL,
TransformationProgram,
MetadataCollection,
GenericResource
}
public ProfileManager() throws Exception {
GCUBEScope scope = ServiceContext.getContext().getScope();
ServiceMap map;
try {
map = scope.getServiceMap();
} catch (GCUBEScopeNotSupportedException e1) {
logger.error("error retrieving service map for scope " + scope.toString(), e1);
throw new Exception(e1);
}
isIcAddress = this.getICRegistratinAddress(map);
VOMapName = scope.getName();
}
/**
* Removes from IS-IC a GCUBEResource profile ( not knowing the Resurce Type the removal has been done once for every type of GCUBE Resource
*
* @param uniqueID the uniqueID to of the GCUBEResource to remove
* @param type the type of Profile
* @throws Exception if the unregistration fails
*/
public void removeFromISIC(String uniqueID, String type, GSSCredential ... credentials) throws Exception {
logger.debug(" Removing profile from IS-IC " + isIcAddress.toString());
//check if the type has been specified
DISICServiceLocator locator_disic = new DISICServiceLocator();
DeleteProfileParams params = new DeleteProfileParams();
params.setDILIGENTResourceID(uniqueID);
if (type != null && type.compareTo("") !=0) {
params.setProfileType(type);
try {
DISICServicePortType dis_ic = locator_disic.getDISICServicePortTypePort(isIcAddress);
dis_ic.deleteProfile(params);
} catch (Exception e) {
logger.error("An error occurs while trying to remove the GCUBE Profile with ID " + uniqueID, e);
throw new Exception("Unregistration failed for the GCUBE Profile with ID " + uniqueID);
}
} else {
try {
//the typeof the resource to delete is not specified, try all the resource types
logger.debug(" trying to remove profile with UniqueID" + uniqueID);
for ( int n = 0 ; n < ResourceTypes.values().length ;n++) {
params.setProfileType(ResourceTypes.values()[n].toString());
logger.debug(" Removing profile from IS-IC " + isIcAddress.toString());
DISICServicePortType dis_ic = locator_disic.getDISICServicePortTypePort(isIcAddress);
dis_ic.deleteProfile(params);
}
} catch (Exception e) {
logger.error(" An error occurs while trying to remove the GCUBE Profile with ID "
+ uniqueID, e);
throw new Exception("Unregistration failed for the GCUBE Profile with ID " + uniqueID);
}
}
}
private URL getICRegistratinAddress(ServiceMap map) throws MalformedURLException {
String addressISIC = (String) map.getEndpoint(ServiceType.ISPublishService).getAddress().toString();
addressISIC = addressISIC.substring(0, addressISIC.lastIndexOf("/") + 1) + ISICpostfix;
return new URL(addressISIC);
}
}

View File

@ -0,0 +1,66 @@
package org.gcube.informationsystem.registry.impl.util;
import java.util.ArrayList;
import javax.xml.namespace.QName;
import org.gcube.common.core.informationsystem.publisher.ISPublisher;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.core.FactoryContext;
import org.gcube.informationsystem.registry.impl.core.ServiceContext;
/**
* Registration Thread class
* @author Andrea Manzi (ISTI-CNR)
*
*
*/
public class RegistrationThread implements Runnable{
/**
*
*/
private static GCUBELog logger = new GCUBELog(RegistrationThread.class);
/**
*
*/
private ArrayList<QName> topics;
/**
*
*/
/**
* The constructor
* @param qname an Array list of RP qname
* @throws Exception Exception
*/
public RegistrationThread ( ArrayList<QName> qname) throws Exception{
this.topics = qname;
}
/**
*
*/
public void run() {
while (true) {
try {
// This is the time interval
Thread.sleep(10000);
}
catch(InterruptedException e){
}
try {
ISPublisher publisher = GHNContext.getImplementation(ISPublisher.class);
publisher.registerToISNotification(FactoryContext.getContext().getEPR(),topics, GHNContext.getContext().getDefaultScope(), ServiceContext.getContext() );
return;
} catch (Exception e) {
e.printStackTrace();
logger.error("Error starting registration:Retrying in 10 seconds");
}
}
}
}

View File

@ -0,0 +1,88 @@
package org.gcube.informationsystem.registry.impl.util;
import java.rmi.RemoteException;
import java.util.List;
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.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.resources.GCUBERunningInstance;
import org.gcube.informationsystem.registry.impl.core.RegistryFactory;
import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage;
/**
*
*
*
* @author Andrea Manzi(ISTI_CNR)
*
*/
public class RegistryUtil {
public static ISClient client = null;
public RegistryUtil () {
try {
client = GHNContext.getImplementation(ISClient.class);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
*
*
* @param ID
* @param resourceClass
* @return
* @throws ISMalformedQueryException
* @throws ISInvalidQueryException
* @throws ISException
*/
public static GCUBEResource getProfileFromIS(String ID, Class<? extends GCUBEResource> resourceClass) throws ISMalformedQueryException, ISInvalidQueryException, ISException {
GCUBEResourceFromIDQuery query =client.getQuery(GCUBEResourceFromIDQuery.class);
query.setResourceClass(resourceClass);
query.setResourceID(ID);
List<GCUBEResource> resource = client.execute(query, GHNContext.getContext().getDefaultScope());
if (resource != null) return resource.get(0);
else return null;
}
/**
* Unregister all the RIs hosted on a given gHN
*
* @param id
* @param service
* @throws ISMalformedQueryException
* @throws ISInvalidQueryException
* @throws ISException
* @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);
//query to IS on order to retrieve the RI deployed on the GHN;
List<GCUBEResource> 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);
}
}
}
}

View File

@ -0,0 +1,52 @@
package org.gcube.informationsystem.registry.test;
import java.io.StringWriter;
import org.apache.axis.message.addressing.Address;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.gcube.common.core.contexts.GCUBERemotePortTypeContext;
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.RemoveResourceMessage;
import org.gcube.informationsystem.registry.stubs.service.RegistryFactoryServiceAddressingLocator;
import org.gridforum.jgss.ExtendedGSSCredential;
public class RegistryRemoveTest {
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]);
EndpointReferenceType factoryEPR = new EndpointReferenceType();
RegistryFactoryPortType registryFactoryPortType= null;
try {
factoryEPR.setAddress(new Address(args[0]));
registryFactoryPortType = registryLocator.getRegistryFactoryPortTypePort(factoryEPR);
}catch(Exception e){
e.printStackTrace();
}
RemoveResourceMessage message = new RemoveResourceMessage();
managerSec.useCredentials(cred);
registryFactoryPortType =GCUBERemotePortTypeContext.getProxy(registryFactoryPortType,GCUBEScope.getScope("/gcube/devsec"),managerSec);
try {
StringWriter writer =new StringWriter();
message.setType(GCUBEService.TYPE);
message.setUniqueID(args[1]);
registryFactoryPortType.removeResource(message);
} catch(Exception e) {
e.printStackTrace();
}
System.out.println("Profile with ID "+ args[1]+ "has been succesfully removed");
}
}

View File

@ -0,0 +1,58 @@
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.GCUBERemotePortTypeContext;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.resources.GCUBEService;
import org.gcube.common.core.scope.GCUBEScope;
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);
registryFactoryPortType =GCUBERemotePortTypeContext.getProxy(registryFactoryPortType,GCUBEScope.getScope("/gcube/devsec"),managerSec);
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);
}
}

View File

@ -0,0 +1,60 @@
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.GCUBERemotePortTypeContext;
import org.gcube.common.core.contexts.GHNContext;
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.service.RegistryFactoryServiceAddressingLocator;
import org.gridforum.jgss.ExtendedGSSCredential;
public class RegistryUpdateTest {
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]);
GCUBEService resource =GHNContext.getImplementation(GCUBEService.class);
EndpointReferenceType factoryEPR = new EndpointReferenceType();
resource.load(fis);
RegistryFactoryPortType registryFactoryPortType= null;
try {
factoryEPR.setAddress(new Address(args[0]));
registryFactoryPortType = registryLocator.getRegistryFactoryPortTypePort(factoryEPR);
}catch(Exception e){
e.printStackTrace();
}
UpdateProfileMessage message = new UpdateProfileMessage();
managerSec.useCredentials(cred);
registryFactoryPortType =GCUBERemotePortTypeContext.getProxy(registryFactoryPortType,GCUBEScope.getScope("/gcube/devsec"),managerSec);
try {
StringWriter writer =new StringWriter();
resource.store(writer);
message.setXmlProfile(writer.toString());
message.setUniqueID(resource.getID());
message.setType(GCUBEService.TYPE);
registryFactoryPortType.updateResource(message);
} catch(Exception e) {
e.printStackTrace();
}
System.out.println("Profile has been updated");
}
}