This commit is contained in:
Manuele Simi 2009-09-04 18:14:23 +00:00
parent 8d7c4115f6
commit 15772e3d89
19 changed files with 1090 additions and 1266 deletions

View File

@ -3,7 +3,7 @@
Version 0.5 Version 0.5
INPUT PROPERTIES REQUIRED INPUT PROPERTIES
This buildfile assumes that the following properties have or may have been defined in a "build.properties" file This buildfile assumes that the following properties have or may have been defined in a "build.properties" file
in the configuration directory of the service (or else using the -D flag on the command line). in the configuration directory of the service (or else using the -D flag on the command line).
@ -24,9 +24,6 @@ package.<n>: (optional) The package name of the stubs generated from WSDL and/
etics.build: (optional) Set to 'true', it indicates that build structures and procedures etics.build: (optional) Set to 'true', it indicates that build structures and procedures
should be optimised for remote builds in ETICS. If it is omitted, this buildfile will optimise build structures and procedures should be optimised for remote builds in ETICS. If it is omitted, this buildfile will optimise build structures and procedures
for local builds. for local builds.
full.stubs: (optional) Set to 'false', it excludes auxiliary stub code placed under ${package}/stubs when building the stub distribution.
It is intended to simplify realignment of auxiliary and standard stub in IDE environments in case the latter change in non backwards-compatible ways.
After re-alignment, the property is typically left to its default of 'true' to restore a joint build of all stub code.
--> -->
@ -86,10 +83,9 @@ full.stubs: (optional) Set to 'false', it excludes auxiliary stub code plac
</if> </if>
<property name="full.stubs" value="true"/>
<property name="stubs.package" value="${package}.${stubs.dir.name}"/> <property name="stubs.package" value="${package}.${stubs.dir.name}"/>
<property name="stubs.dir.name" value="stubs" /> <!-- auxiliary stub classes --> <property name="stubs.dir.name" value="stubs" /> <!-- auxiliary stub classes -->
<property name="stubs.dir" value="${source.dir}/${package.dir}/${stubs.dir.name}" /> <property name="stubs.dir" value="${source.dir}/${package.dir}${stubs.dir.name}" />
<available file="${stubs.dir}" property="stubs.dir.present"/> <available file="${stubs.dir}" property="stubs.dir.present"/>
<!-- temporary build locations --> <!-- temporary build locations -->
@ -395,8 +391,7 @@ full.stubs: (optional) Set to 'false', it excludes auxiliary stub code plac
</target> </target>
<target name="buildService" depends="processWSDLs" description="compiles service implementation"> <target name="buildService" depends="processWSDLs" description="compiles service implementation">
<javac srcdir="${source.dir}" destdir="${build.class.dir}" debug="${java.debug}" deprecation="${java.deprecation}" <javac srcdir="${source.dir}" destdir="${build.class.dir}" debug="${java.debug}" deprecation="${java.deprecation}">
excludes="org/gcube/common/vremanagement/deployer/stubs/**">
<classpath> <classpath>
<fileset dir="${lib.location}"> <fileset dir="${lib.location}">
<include name="**/*.jar" /> <include name="**/*.jar" />
@ -434,7 +429,6 @@ full.stubs: (optional) Set to 'false', it excludes auxiliary stub code plac
<!-- Stub Build tasks --> <!-- Stub Build tasks -->
<target name="buildStubs" depends="processWSDLs,generateStubs" description="build service stubs"> <target name="buildStubs" depends="processWSDLs,generateStubs" description="build service stubs">
<if name="full.stubs" value="true">
<if name="stubs.dir.present"> <if name="stubs.dir.present">
<copy toDir="${build.stubs.src.dir}/${package.dir}/${stubs.dir.name}" overwrite="true"> <copy toDir="${build.stubs.src.dir}/${package.dir}/${stubs.dir.name}" overwrite="true">
<fileset dir="${stubs.dir}" casesensitive="yes"> <fileset dir="${stubs.dir}" casesensitive="yes">
@ -442,7 +436,6 @@ full.stubs: (optional) Set to 'false', it excludes auxiliary stub code plac
</fileset> </fileset>
</copy> </copy>
</if> </if>
</if>
<javac srcdir="${build.stubs.src.dir}" destdir="${build.stubs.class.dir}" debug="${java.debug}" deprecation="${java.deprecation}" description="compile stub classes"> <javac srcdir="${build.stubs.src.dir}" destdir="${build.stubs.class.dir}" debug="${java.debug}" deprecation="${java.deprecation}" description="compile stub classes">
<include name="**/*.java" /> <include name="**/*.java" />
<classpath> <classpath>

View File

@ -7,6 +7,13 @@
<Class>InformationSystem</Class> <Class>InformationSystem</Class>
<Name>IS-Registry</Name> <Name>IS-Registry</Name>
<Version>1.0.0</Version> <Version>1.0.0</Version>
<Dependencies>
<Dependency>
<Class>InformationSystem</Class>
<Name>IS-Collector</Name>
<Version>1.00.00</Version>
</Dependency>
</Dependencies>
<Packages> <Packages>
<Main> <Main>
<Description>IS-Registry: validate, register and unregister GCUBE resources to/from the IS. It also publishes Topics for notifications about GCUBE resource events</Description> <Description>IS-Registry: validate, register and unregister GCUBE resources to/from the IS. It also publishes Topics for notifications about GCUBE resource events</Description>

View File

@ -27,11 +27,11 @@ import org.gcube.informationsystem.registry.impl.contexts.ProfileContext;
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext; import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
import org.gcube.informationsystem.registry.impl.filters.FilterManager; import org.gcube.informationsystem.registry.impl.filters.FilterManager;
import org.gcube.informationsystem.registry.impl.filters.FilterExecutor.InvalidFilterException; import org.gcube.informationsystem.registry.impl.filters.FilterExecutor.InvalidFilterException;
import org.gcube.informationsystem.registry.impl.profilemanagement.ProfileManager;
import org.gcube.informationsystem.registry.impl.profilemanagement.GHN;
import org.gcube.informationsystem.registry.impl.resourcemanagement.Pair;
import org.gcube.informationsystem.registry.impl.state.ProfileResource; import org.gcube.informationsystem.registry.impl.state.ProfileResource;
import org.gcube.informationsystem.registry.impl.state.RegistryFactoryResource; import org.gcube.informationsystem.registry.impl.state.RegistryFactoryResource;
import org.gcube.informationsystem.registry.impl.util.Couple;
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.CreateResourceMessage;
import org.gcube.informationsystem.registry.stubs.ProfileAlreadyRegisteredFault; import org.gcube.informationsystem.registry.stubs.ProfileAlreadyRegisteredFault;
import org.gcube.informationsystem.registry.stubs.RegistryProperty; import org.gcube.informationsystem.registry.stubs.RegistryProperty;
@ -46,10 +46,8 @@ import org.gcube.informationsystem.registry.stubs.UpdateResourceMessage;
import org.gcube.informationsystem.registry.stubs.UpdateResourceResponse; import org.gcube.informationsystem.registry.stubs.UpdateResourceResponse;
import org.gcube.informationsystem.registry.stubs.UpdateScopeInProfileMessage; import org.gcube.informationsystem.registry.stubs.UpdateScopeInProfileMessage;
import org.gcube.informationsystem.registry.stubs.UpdateStateMessage; import org.gcube.informationsystem.registry.stubs.UpdateStateMessage;
import org.globus.wsrf.security.SecurityManager;
import static org.gcube.informationsystem.registry.impl.core.RegistryConfiguration.ResourceType; import static org.gcube.informationsystem.registry.impl.core.RegistryConfiguration.ResourceType;
/** /**
* Implementation of the <em>Registry Factory</em> portType * Implementation of the <em>Registry Factory</em> portType
* *
@ -58,27 +56,29 @@ import static org.gcube.informationsystem.registry.impl.core.RegistryConfigurati
*/ */
public class RegistryFactory extends GCUBEPortType { public class RegistryFactory extends GCUBEPortType {
/**Name of temporaryResourceLifetimeInMs JNDI environment.*/ /** Name of temporaryResourceLifetimeInMs JNDI environment. */
private static final String LIFETIME_JNDI_NAME = "temporaryResourceLifetimeInMs"; private static final String LIFETIME_JNDI_NAME = "temporaryResourceLifetimeInMs";
/** /**
* Lifetime of temporary resources * Lifetime of temporary resources
*/ */
private static long temporaryResourceLifetimeInMs= 120000; private static long temporaryResourceLifetimeInMs = 120000;
/** The UUIDGen */
/**The UUIDGen */
private static final UUIDGen uuidgen = UUIDGenFactory.getUUIDGen(); private static final UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
/**Object logger*/ /** Object logger */
protected final GCUBELog logger = new GCUBELog(RegistryFactory.class); protected final GCUBELog logger = new GCUBELog(RegistryFactory.class);
enum OperationType {create,update,destroy}; enum OperationType {
create, update, destroy
};
/** /**
* Map of registration to Notification * Map of registration to Notification
*/ */
public static final List<GCUBEWSResourceKey> notificationMap = Collections.synchronizedList(new ArrayList<GCUBEWSResourceKey>()); public static final List<GCUBEWSResourceKey> notificationMap = Collections
.synchronizedList(new ArrayList<GCUBEWSResourceKey>());
/** the key used to label the Factory Resource */ /** the key used to label the Factory Resource */
public static final String NOTIFICATOR_RESOURCE_KEY = "RegistryResource"; public static final String NOTIFICATOR_RESOURCE_KEY = "RegistryResource";
@ -88,23 +88,29 @@ public class RegistryFactory extends GCUBEPortType {
*/ */
@Override @Override
protected void onInitialisation() throws Exception { protected void onInitialisation() throws Exception {
temporaryResourceLifetimeInMs = (Long)ServiceContext.getContext().getProperty(LIFETIME_JNDI_NAME); temporaryResourceLifetimeInMs = (Long) ServiceContext.getContext()
logger.info("Temporary resources lifetime = " + temporaryResourceLifetimeInMs); .getProperty(LIFETIME_JNDI_NAME);
logger.info("Temporary resources lifetime = "
+ temporaryResourceLifetimeInMs);
} }
/** /**
* Use to Load from Disk persistence profiles and registers it into the IS-IC ( in case the IS-IC is empty) * 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 * @param start
* same as void
* @return void * @return void
* @throws RemoteException Exception * @throws RemoteException
* Exception
*/ */
public StartRegistrationResponse startRegistration(StartRegistration start ) throws GCUBEFault{ public StartRegistrationResponse startRegistration(StartRegistration start)
//start registration to broker and new profiles registration throws GCUBEFault {
// start registration to broker and new profiles registration
logger.debug("Starting profile registration from disk"); logger.debug("Starting profile registration from disk");
try { try {
//loadProfiles(); // loadProfiles();
} catch (Exception e) { } catch (Exception e) {
logger.error("Error Loading profiles"); logger.error("Error Loading profiles");
throw new GCUBEFault(e.getMessage()); throw new GCUBEFault(e.getMessage());
@ -113,7 +119,6 @@ public class RegistryFactory extends GCUBEPortType {
} }
/** /**
* *
* Creates a new GCUBEResource's profile manager * Creates a new GCUBEResource's profile manager
@ -125,13 +130,13 @@ public class RegistryFactory extends GCUBEPortType {
* @throws ProfileAlreadyRegisteredFault * @throws ProfileAlreadyRegisteredFault
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public String createResource(CreateResourceMessage mess) throws SchemaValidationFault,RemoteException,ProfileAlreadyRegisteredFault,ResourceNotAcceptedFault { public String createResource(CreateResourceMessage mess) throws SchemaValidationFault, RemoteException,
GCUBEResource resource=null; ProfileAlreadyRegisteredFault, ResourceNotAcceptedFault {
GCUBEResource resource = null;
logger.info("CreateResource operation invoked"); logger.info("CreateResource operation invoked");
//logSecurityInfo("createResource"); // logSecurityInfo("createResource");
String profile = mess.getProfile(); String profile = mess.getProfile();
if (profile == null || profile.compareTo("") == 0) { if (profile == null || profile.compareTo("") == 0) {
@ -140,86 +145,80 @@ public class RegistryFactory extends GCUBEPortType {
throw new RemoteException(msg); throw new RemoteException(msg);
} }
try { try {
resource=ResourceType.valueOf(mess.getType()).getResourceClass(); resource = ResourceType.valueOf(mess.getType()).getResourceClass();
resource.load(new BufferedReader(new InputStreamReader(new ByteArrayInputStream(profile.getBytes("UTF-8")), "UTF-8"))); resource.load(new BufferedReader(new InputStreamReader(new ByteArrayInputStream(profile.getBytes("UTF-8")), "UTF-8")));
//the parse Profile class allows to extract from profiles information about type/SCOPE/UniqueID // the parse Profile class allows to extract from profiles
//in order to distinguish among different Resource Type // information about type/SCOPE/UniqueID
//Adding scopes to Profile // in order to distinguish among different Resource Type
String [] scopes = mess.getScopes(); // Adding scopes to Profile
String[] scopes = mess.getScopes();
if (scopes != null) { if (scopes != null) {
for (String scope : scopes) { for (String scope : scopes) {
logger.debug(resource.getID()+" Adding Scopes to Profile "+ scope); logger.debug(resource.getID()
+ " Adding Scopes to Profile " + scope);
resource.addScope(GCUBEScope.getScope(scope)); resource.addScope(GCUBEScope.getScope(scope));
} }
} }
//check ID // check ID
if (resource.getID()== null || resource.getID().compareTo("")==0) {resource.setID(uuidgen.nextUUID()); } if (resource.getID() == null || resource.getID().compareTo("") == 0) {
resource.setID(uuidgen.nextUUID());
} }
catch (Exception ex) {
} catch (Exception ex) {
logger.error("Error trying to load profile", ex); logger.error("Error trying to load profile", ex);
throw new SchemaValidationFault(); throw new SchemaValidationFault();
} }
//apply resource filter // apply resource filter
try { try {
if (! FilterManager.getExecutor(resource.getType()).accept(resource)) { if (!FilterManager.getExecutor(resource.getType()).accept(resource)) {
logger.warn("Resource "+ resource.getID()+" NOT accepted "); logger.warn("Resource " + resource.getID() + " NOT accepted ");
throw new ResourceNotAcceptedFault(); throw new ResourceNotAcceptedFault();
} }
logger.trace("Resource "+ resource.getID()+" accepted "); logger.trace("Resource " + resource.getID() + " accepted ");
} catch (InvalidFilterException e) { } catch (InvalidFilterException e) {
logger.warn("Invalid filter selected, the resource " + resource.getID()+" CANNOT be filtered "); logger.warn("Invalid filter selected, the resource "
+ resource.getID() + " CANNOT be filtered ");
} }
//check if the Resource already exists // check if the Resource already exists
if (isResourceCreated(resource.getID())) { if (isResourceCreated(resource.getID())) {
// update the existing resource // update the existing resource
logger.warn("A Resource with ID "+ resource.getID()+" is already registered"); logger.warn("A Resource with ID " + resource.getID()
+ " is already registered");
UpdateResourceMessage upmess = new UpdateResourceMessage(); UpdateResourceMessage upmess = new UpdateResourceMessage();
upmess.setUniqueID(resource.getID()); upmess.setUniqueID(resource.getID());
upmess.setXmlProfile(mess.getProfile()); upmess.setXmlProfile(mess.getProfile());
upmess.setType(mess.getType()); upmess.setType(mess.getType());
this.updateResource(upmess); this.updateResource(upmess);
//throw new ProfileAlreadyRegisteredFault(); // throw new ProfileAlreadyRegisteredFault();
} else { } else {
//try to create resource // try to create resource
try { try {
logger.debug(resource.getID()+" Creating the stateful resource for " + resource.getID()); logger.debug(resource.getID() + " Creating the stateful resource for " + resource.getID());
ProfileResource presource = (ProfileResource) ProfileContext.getContext().getWSHome().create(ProfileContext.getContext().makeKey(resource.getID()),resource); ProfileResource presource = (ProfileResource) ProfileContext.getContext().getWSHome().create(ProfileContext.getContext()
.makeKey(resource.getID()), resource);
presource.store(); presource.store();
//Deleting the WSResource created // Deleting the WSResource created if != from GHN
long timestamp; if (resource.getType().compareTo(GCUBEHostingNode.TYPE) != 0)
if (resource.getType().compareTo(GCUBEHostingNode.TYPE)!=0){ this.scheduleForLazyDeletion(presource);
GCUBEScope tmpScope= ServiceContext.getContext().getScope().getType() == GCUBEScope.Type.VRE ? ServiceContext.getContext().getScope().getEnclosingScope() : ServiceContext.getContext().getScope();
timestamp=System.currentTimeMillis()+temporaryResourceLifetimeInMs;
Couple c= new Couple(timestamp, presource); } catch (Exception ex) {
if(!ServiceContext.threadTable.get(tmpScope.getName()).getStack().contains(c)){ String msg = "Error creating Resource " + resource.getID();
ServiceContext.threadTable.get(tmpScope.getName()).getStack().add(c); logger.error(msg, ex);
logger.trace("Adding resource to EliminatePoolingThread "+presource.getGCubeResource().getID());
}else{
int index= ServiceContext.threadTable.get(tmpScope.getName()).getStack().indexOf(c);
ServiceContext.threadTable.get(tmpScope.getName()).getStack().get(index).timestamp=timestamp+temporaryResourceLifetimeInMs;
}
}
}
catch (Exception ex) {
String msg = "Error creating Resource "+resource.getID();
logger.error(msg,ex);
throw new RemoteException(msg); throw new RemoteException(msg);
} }
try { try {
updateCounterInfo (resource.getID(), ResourceType.valueOf(mess.getType()), OperationType.create, Calendar.getInstance()); updateCounterInfo(resource.getID(), ResourceType.valueOf(mess.getType()), OperationType.create, Calendar.getInstance());
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>(); GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>();
event.setPayload(resource); event.setPayload(resource);
ServiceContext.getContext().getTopicProducer().notify(ServiceContext.RegistryTopic.CREATE, event); ServiceContext.getContext().getTopicProducer().notify(
ServiceContext.RegistryTopic.CREATE, event);
} catch (Exception e) { } catch (Exception e) {
logger.warn("Error updating Counting info for resource with ID " + resource.getID(), e); logger.warn("Error updating Counting info for resource with ID " + resource.getID(), e);
} }
@ -227,47 +226,74 @@ public class RegistryFactory extends GCUBEPortType {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
try { try {
logger.debug("Persisting the stateful resource for " + resource.getID()); logger.debug("Persisting the stateful resource for "
+ resource.getID());
resource.store(writer); resource.store(writer);
} catch (Exception e) { } catch (Exception e) {
logger.error("Persistence failed for " + resource.getID(), e); logger.error("Persistence failed for " + resource.getID(), e);
} }
logger.info("Profile " + resource.getID() + " created "); logger.info("Profile " + resource.getID() + " created ");
return writer.toString(); return writer.toString();
} }
/**
* Schedules a resource for a delayed deletion
*
* @param presource the resource to delete
*/
private void scheduleForLazyDeletion(ProfileResource presource) {
long timestamp = System.currentTimeMillis() + temporaryResourceLifetimeInMs;
GCUBEScope scope = ServiceContext.getContext().getScope().getType() == GCUBEScope.Type.VRE ? ServiceContext
.getContext().getScope().getEnclosingScope(): ServiceContext.getContext().getScope();
Pair c = new Pair(timestamp, presource);
if (!ServiceContext.threadTable.get(scope.getName()).getStack().contains(c)) {
ServiceContext.threadTable.get(scope.getName()).getStack().add(c);
logger.trace("Adding resource to EliminatePoolingThread " + presource.getGCubeResource().getID());
} else { //add more life to the resource by further delaying its deletion
int index = ServiceContext.threadTable.get(scope.getName()).getStack().indexOf(c);
ServiceContext.threadTable.get(scope.getName()).getStack().get(index).lifetime = timestamp+ temporaryResourceLifetimeInMs;
}
}
/** /**
* Updates Resource Profiles (in case of an update of an ID not present it invokes calls the Create resource operation) * Updates Resource Profiles (in case of an update of an ID not present it
* invokes calls the Create resource operation)
* *
* @param mess Complex Object that contains a String representing the XML profile to update and the diligentID * @param mess
* Complex Object that contains a String representing the XML
* profile to update and the diligentID
* @return UpdateResourceResponse * @return UpdateResourceResponse
* @throws RemoteException Exception * @throws RemoteException
* @throws SchemaValidationException Exception * Exception
* @throws SchemaValidationException
* Exception
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public UpdateResourceResponse updateResource(UpdateResourceMessage mess) public UpdateResourceResponse updateResource(UpdateResourceMessage mess)
throws RemoteException, SchemaValidationFault, ResourceNotAcceptedFault, GCUBEFault { throws RemoteException, SchemaValidationFault,
ResourceNotAcceptedFault, GCUBEFault {
//logSecurityInfo("updateResource"); // logSecurityInfo("updateResource");
logger.info("UpdateResource operation invoked"); logger.info("UpdateResource operation invoked");
String ID = mess.getUniqueID(); String ID = mess.getUniqueID();
String xmlProfile = mess.getXmlProfile(); String xmlProfile = mess.getXmlProfile();
GCUBEResource resource = null; GCUBEResource resource = null;
CreateResourceMessage input =null; CreateResourceMessage input = null;
//validating input parameters // validating input parameters
if (ID == null || ID.compareTo("") ==0) { if (ID == null || ID.compareTo("") == 0) {
logger.debug(" ID missing "); logger.debug(" ID missing ");
throw new RemoteException("Error, ID missing"); throw new RemoteException("Error, ID missing");
} }
if (xmlProfile == null || xmlProfile.compareTo("") ==0) { if (xmlProfile == null || xmlProfile.compareTo("") == 0) {
logger.debug("Profile missing" ); logger.debug("Profile missing");
throw new RemoteException("Error, profile missing"); throw new RemoteException("Error, profile missing");
} }
//check if the profile exist // check if the profile exist
if (!isResourceCreated(ID)) { if (!isResourceCreated(ID)) {
input = new CreateResourceMessage(); input = new CreateResourceMessage();
input.setProfile(xmlProfile); input.setProfile(xmlProfile);
@ -279,47 +305,39 @@ public class RegistryFactory extends GCUBEPortType {
resource = ResourceType.valueOf(mess.getType()).getResourceClass(); resource = ResourceType.valueOf(mess.getType()).getResourceClass();
resource.load(new StringReader(xmlProfile)); resource.load(new StringReader(xmlProfile));
//apply resource filter // apply resource filter
try { try {
if (! FilterManager.getExecutor(resource.getType()).accept(resource)) { if (!FilterManager.getExecutor(resource.getType()).accept(resource)) {
logger.warn("Resource "+ resource.getID()+" NOT accepted "); logger.warn("Resource " + resource.getID() + " NOT accepted ");
throw new ResourceNotAcceptedFault(); throw new ResourceNotAcceptedFault();
} }
logger.trace("Resource "+ resource.getID()+" accepted "); logger.trace("Resource " + resource.getID() + " accepted ");
} catch (InvalidFilterException e) { } catch (InvalidFilterException e) {
logger.warn("Invalid filter selected, the resource " + resource.getID()+" CANNOT be filtered "); logger.warn("Invalid filter selected, the resource " + resource.getID() + " CANNOT be filtered ");
} }
ProfileResource pr= getProfileResource(ID); ProfileResource presource = getProfileResource(ID);
pr.updateResource(resource); presource.updateResource(resource);
//Deleting the WSResource created // Deleting the WSResource created
long timestamp; if (resource.getType().compareTo(GCUBEHostingNode.TYPE) != 0)
if (resource.getType().compareTo(GCUBEHostingNode.TYPE)!=0){ this.scheduleForLazyDeletion(presource);
GCUBEScope tmpScope= ServiceContext.getContext().getScope().getType() == GCUBEScope.Type.VRE ? ServiceContext.getContext().getScope().getEnclosingScope() : ServiceContext.getContext().getScope();
timestamp=System.currentTimeMillis()+temporaryResourceLifetimeInMs; } catch (Exception e) {
Couple c= new Couple(timestamp, pr); logger.error("Error updating profile for ID " + e);
if(!ServiceContext.threadTable.get(tmpScope.getName()).getStack().contains(c)){
ServiceContext.threadTable.get(tmpScope.getName()).getStack().add(c);
logger.trace("Adding resource to EliminatePoolingThread "+pr.getGCubeResource().getID());
}else{
int index= ServiceContext.threadTable.get(tmpScope.getName()).getStack().indexOf(c);
ServiceContext.threadTable.get(tmpScope.getName()).getStack().get(index).timestamp=timestamp+temporaryResourceLifetimeInMs;
}
}
}
catch (Exception e) {
logger.error("Error updating profile for ID "+ e);
throw new RemoteException(e.toString()); throw new RemoteException(e.toString());
} }
try { try {
updateCounterInfo (ID,ResourceType.valueOf(mess.getType()),OperationType.update, Calendar.getInstance()); updateCounterInfo(ID, ResourceType.valueOf(mess.getType()),
OperationType.update, Calendar.getInstance());
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>(); GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>();
event.setPayload(resource); event.setPayload(resource);
ServiceContext.getContext().getTopicProducer().notify(ServiceContext.RegistryTopic.UPDATE, event); ServiceContext.getContext().getTopicProducer().notify(
ServiceContext.RegistryTopic.UPDATE, event);
} catch (Exception e) { } catch (Exception e) {
logger.warn("Error updating counting info for resource with ID " + resource.getID(), e); logger.warn("Error updating counting info for resource with ID "
+ resource.getID(), e);
} }
logger.info("Profile " + mess.getUniqueID() + " updated"); logger.info("Profile " + mess.getUniqueID() + " updated");
return new UpdateResourceResponse(); return new UpdateResourceResponse();
@ -328,75 +346,61 @@ public class RegistryFactory extends GCUBEPortType {
/** /**
* Removes a Resource profile identified by the given the resource ID * Removes a Resource profile identified by the given the resource ID
* *
* * @param inputMessage defined into WSDL file
* @param inputMessage Defined into WSDL file
* @return RemoveResourceResponse * @return RemoveResourceResponse
* @throws RemoteException Exceptions * @throws RemoteException
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public RemoveResourceResponse removeResource (RemoveResourceMessage inputMessage) throws RemoteException,GCUBEFault{ public RemoveResourceResponse removeResource(RemoveResourceMessage inputMessage) throws RemoteException, GCUBEFault {
logSecurityInfo("removeResource"); //logSecurityInfo("removeResource");
logger.info("RemoveResource operation invoked");
String ID = inputMessage.getUniqueID(); String ID = inputMessage.getUniqueID();
String type = inputMessage.getType(); String type = inputMessage.getType();
if (ID == null || ID.compareTo("") ==0) { logger.info("RemoveResource operation invoked on resource ID=" + ID + ", type=" + type);
logger.warn("Resource ID is missing"); if (ID == null || ID.compareTo("") == 0) {
throw new RemoteException("Resource ID is missing"); logger.warn("Resource ID is missing, cannot manage the resource");
throw new RemoteException("Resource ID is missing, cannot manage the resource");
} }
//check if the UniqueID exist
/*GCUBEResource resource = null;
try { try {
resource = RegistryUtil.getProfileFromIS(ID,this.getResourceClass(type).getClass()); logger.debug("Trying to remove the resource from the IS-IC");
} catch (Exception e1) { new ProfileManager().removeFromISIC(ID, type, ServiceContext.getContext().getScope(), ServiceContext.getContext());
logger.error("Error gettign profile from IS "); logger.info("Resource removed from the IS-IC");
return new RemoveResourceResponse();
}*/
//if( resource == null) return new RemoveResourceResponse();
//else {
logger.debug("trying to remove the resource from the IS-IC");
try {
new ProfileManager().removeFromISIC(ID, type, ServiceContext.getContext().getCredentials());
logger.debug("resource removed");
} catch (Exception e) { } catch (Exception e) {
logger.error("Unable to remove the resource", 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"); throw ServiceContext.getContext().getDefaultException("", e).toFault( "Unable to remove the resource: the remote IS-IC returned an error");
} }
//} // if the resource is a GHN, remove also the related RIs
try { try {
if (type.compareTo(GCUBEHostingNode.TYPE) == 0) if (type.compareTo(GCUBEHostingNode.TYPE) == 0) {
RegistryUtil.unregisterRIRelatedToGHN(ID,this); logger.debug("Removing the related RIs");
GHN ghn = new GHN(ID);
ghn.unregisterHostedRIs(this);
logger.debug("Related RIs removed");
}
} catch (Exception e) { } catch (Exception e) {
logger.error("Error removing profile related to this GHNID for ID ", e); logger.error("Error while removing RI profiles related to the GHN", e);
System.out.println("error removing RI related to GHN");
e.printStackTrace();
} }
if (this.isResourceCreated(ID)){ if (this.isResourceCreated(ID)) {
//destroy the resource // destroy the resource
try{ try {
logger.debug("Destroying the local stateful Resoruce");
ProfileContext.getContext().getWSHome().remove(ProfileContext.getContext().makeKey(ID)); ProfileContext.getContext().getWSHome().remove(ProfileContext.getContext().makeKey(ID));
logger.info(" Resource Destroyed"); logger.info(" Resource Destroyed");
} } catch (Exception e) {
catch (Exception e) {
logger.error("Error removing resource for ID ", e); logger.error("Error removing resource for ID ", e);
throw new RemoteException(); throw new RemoteException();
} }
try { try {
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>(); GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>();
GCUBEResource resource =ResourceType.valueOf(type).getResourceClass(); GCUBEResource resource = ResourceType.valueOf(type).getResourceClass();
resource.setID(ID); resource.setID(ID);
event.setPayload(resource); event.setPayload(resource);
ServiceContext.getContext().getTopicProducer().notify(ServiceContext.RegistryTopic.REMOVE, event); ServiceContext.getContext().getTopicProducer().notify(ServiceContext.RegistryTopic.REMOVE, event);
updateCounterInfo(ID, ResourceType.valueOf(type),OperationType.destroy, Calendar.getInstance());
updateCounterInfo(ID, ResourceType.valueOf(type), OperationType.destroy, Calendar.getInstance()); } catch (Exception e) {
} logger.warn("Error updating counting info for resource with ID " + ID, e);
catch (Exception e) {
logger.warn("Error updating counting info for resource with ID " + ID ,e);
} }
} }
@ -405,30 +409,20 @@ public class RegistryFactory extends GCUBEPortType {
} }
/**
* 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);
}
/** /**
* Checks if the Resource has been created * Checks if the Resource has been created
* *
* @param id the Resource ID * @param id
* the Resource ID
* @return the resource ( null if the resource has not been created yet * @return the resource ( null if the resource has not been created yet
*/ */
protected synchronized ProfileResource getProfileResource(String id ){ protected synchronized ProfileResource getProfileResource(String id) {
try { try {
return (ProfileResource) ProfileContext.getContext().getWSHome().find(ProfileContext.getContext().makeKey(id)); return (ProfileResource) ProfileContext.getContext().getWSHome()
} .find(ProfileContext.getContext().makeKey(id));
catch (Exception e ){ } catch (Exception e) {
logger.debug("A profile with the given id "+ id+" has not been created yet"); logger.debug("A profile with the given id " + id
+ " has not been created yet");
} }
return null; return null;
@ -440,48 +434,61 @@ public class RegistryFactory extends GCUBEPortType {
* @return * @return
*/ */
protected synchronized boolean isResourceCreated(String id) { protected synchronized boolean isResourceCreated(String id) {
if (getProfileResource(id) != null) return true; else return false; if (getProfileResource(id) != null)
return true;
else
return false;
} }
/** /**
* Updates the RegistryFactoryResource RPs for notification * Updates the RegistryFactoryResource RPs for notification
* *
* *
* @param ID resource ID * @param ID
* @param type the resource type * resource ID
* @param operationType the type of Operation performed on the Profile * @param type
* @param updateTime The last operation Time * the resource type
* @throws Exception Exception * @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, ResourceType resType, OperationType opType, Calendar updateTime) throws Exception{ private synchronized void updateCounterInfo(String ID,
ResourceType resType, OperationType opType, Calendar updateTime)
throws Exception {
RegistryProperty property = new RegistryProperty(); RegistryProperty property = new RegistryProperty();
property.setUniqueID(ID); property.setUniqueID(ID);
property.setOperationType(opType.name()); property.setOperationType(opType.name());
property.setChangeTime(updateTime); property.setChangeTime(updateTime);
//select the type of the resource to update // select the type of the resource to update
for (Method method :this.getResource().getClass().getDeclaredMethods()) { for (Method method : this.getResource().getClass().getDeclaredMethods()) {
if (method.getName().contains(resType.name()) && method.getName().contains("set")) { if (method.getName().contains(resType.name())
method.invoke(this.getResource(),property); && method.getName().contains("set")) {
method.invoke(this.getResource(), property);
break; break;
} }
} }
this.getResource().store(); this.getResource().store();
} }
/** /**
* return the resource * return the resource
* *
* @return NotifierResource resource * @return NotifierResource resource
* @throws RemoteException Exception * @throws RemoteException
* Exception
*/ */
private RegistryFactoryResource getResource() throws RemoteException { private RegistryFactoryResource getResource() throws RemoteException {
Object resource = null; Object resource = null;
try { try {
resource = FactoryContext.getContext().getWSHome().find(FactoryContext.getContext().makeKey(NOTIFICATOR_RESOURCE_KEY)); resource = FactoryContext.getContext().getWSHome().find(
FactoryContext.getContext().makeKey(
NOTIFICATOR_RESOURCE_KEY));
} catch (Exception e) { } catch (Exception e) {
logger.error(" Unable to access resource", e); logger.error(" Unable to access resource", e);
} }
@ -492,28 +499,41 @@ public class RegistryFactory extends GCUBEPortType {
/** /**
* *
* @param message UpdateScopeInProfileMessage * @param message
* UpdateScopeInProfileMessage
* @return String * @return String
* @throws GCUBEFault - * @throws GCUBEFault
* -
*/ */
public String updateScopeInProfile(UpdateScopeInProfileMessage message)throws GCUBEFault{return null;} public String updateScopeInProfile(UpdateScopeInProfileMessage message)
throws GCUBEFault {
return null;
}
/** /**
* *
* @param message RemoveScopeInProfileMessage * @param message
* RemoveScopeInProfileMessage
* @return String * @return String
* @throws GCUBEFault - * @throws GCUBEFault
* -
*/ */
public String removeScopeInProfile(RemoveScopeInProfileMessage message)throws GCUBEFault{return null;} public String removeScopeInProfile(RemoveScopeInProfileMessage message)
throws GCUBEFault {
return null;
}
/** /**
* *
* @param message UpdateStateMessage * @param message
* UpdateStateMessage
* @return * @return
* @throws GCUBEFault - * @throws GCUBEFault
* -
*/ */
public String updateState(UpdateStateMessage message)throws GCUBEFault{return null;} public String updateState(UpdateStateMessage message) throws GCUBEFault {
return null;
}
@Override @Override
protected GCUBEServiceContext getServiceContext() { protected GCUBEServiceContext getServiceContext() {

View File

@ -2,7 +2,10 @@ package org.gcube.informationsystem.registry.impl.contexts;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.Hashtable; import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
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 static org.gcube.common.core.contexts.GHNContext.Mode;
@ -17,8 +20,8 @@ import org.gcube.common.core.utils.events.GCUBETopic;
import org.gcube.common.core.utils.handlers.GCUBEHandler; import org.gcube.common.core.utils.handlers.GCUBEHandler;
import org.gcube.common.core.utils.handlers.GCUBEScheduledHandler; import org.gcube.common.core.utils.handlers.GCUBEScheduledHandler;
import org.gcube.informationsystem.registry.impl.RegistryFactory; import org.gcube.informationsystem.registry.impl.RegistryFactory;
import org.gcube.informationsystem.registry.impl.resourcemanagement.EliminatePoolingThread;
import org.gcube.informationsystem.registry.impl.state.RegistryFactoryResource; import org.gcube.informationsystem.registry.impl.state.RegistryFactoryResource;
import org.gcube.informationsystem.registry.impl.util.EliminatePoolingThread;
import org.gcube.informationsystem.registry.stubs.CreateResourceMessage; import org.gcube.informationsystem.registry.stubs.CreateResourceMessage;
import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage; import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage;
import org.gcube.informationsystem.registry.stubs.UpdateResourceMessage; import org.gcube.informationsystem.registry.stubs.UpdateResourceMessage;
@ -34,7 +37,7 @@ public class ServiceContext extends GCUBEServiceContext {
public static final String JNDI_NAME = "gcube/informationsystem/registry"; public static final String JNDI_NAME = "gcube/informationsystem/registry";
public static Hashtable<String, EliminatePoolingThread> threadTable= new Hashtable<String, EliminatePoolingThread>(); public static Map<String, EliminatePoolingThread> threadTable = Collections.synchronizedMap(new HashMap<String, EliminatePoolingThread>());
protected static final ServiceContext cache = new ServiceContext(); protected static final ServiceContext cache = new ServiceContext();

View File

@ -0,0 +1,72 @@
package org.gcube.informationsystem.registry.impl.profilemanagement;
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.QueryParameter;
import org.gcube.common.core.informationsystem.client.XMLResult;
import org.gcube.common.core.informationsystem.client.ISClient.ISMalformedQueryException;
import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery;
import org.gcube.common.core.resources.GCUBERunningInstance;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.RegistryFactory;
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage;
/**
*
* GHN profile management
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public class GHN {
public static ISClient client = null;
protected static final GCUBELog logger = new GCUBELog(GHN.class);
private String id = null;
public GHN(String id) {
this.id = id;
}
/**
* Unregisters all the RIs hosted on the gHN
*
* @param service
* @throws ISMalformedQueryException
* @throws ISInvalidQueryException
* @throws ISException
* @throws GCUBEFault
* @throws RemoteException
*/
public void unregisterHostedRIs(RegistryFactory service) throws Exception {
if (client == null)
client = GHNContext.getImplementation(ISClient.class);
RemoveResourceMessage message = null;
GCUBEGenericQuery query = client.getQuery("RIOnGHN");
query.addParameters(new QueryParameter("ID", this.id));
// query to IS on order to retrieve the RI deployed on the GHN;
List<XMLResult> resources = client.execute(query, ServiceContext.getContext().getScope());
if (resources.size() != 0) {
for (XMLResult resource : resources) {
try {
message = new RemoveResourceMessage();
message.setType(GCUBERunningInstance.TYPE);
message.setUniqueID(resource.evaluate("/Resource/ID/text()").get(0));
service.removeResource(message);
} catch (RemoteException rme) {
}
}
}
}
}

View File

@ -0,0 +1,154 @@
package org.gcube.informationsystem.registry.impl.profilemanagement;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;
import org.apache.axis.message.addressing.AttributedURI;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.gcube.common.core.contexts.GCUBERemotePortTypeContext;
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.security.GCUBEServiceSecurityManager;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.collector.stubs.DeleteProfileParams;
import org.gcube.informationsystem.collector.stubs.XMLCollectionAccessPortType;
import org.gcube.informationsystem.collector.stubs.service.XMLCollectionAccessServiceLocator;
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
public class ProfileManager {
protected static final GCUBELog logger = new GCUBELog(ProfileManager.class);
protected Set<EndpointReferenceType> ICEprs = new HashSet<EndpointReferenceType>();
protected String VOMapName;
public enum ResourceTypes {
Service, CS, CSInstance, Collection, RunningInstance, ExternalRunningInstance, GHN, gLiteResource, 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);
}
this.getSinks(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, GCUBEScope scope,
GCUBEServiceSecurityManager manager) throws Exception {
for (EndpointReferenceType sink : this.ICEprs) {
String isIcAddress = sink.getAddress().toString();
// check if the type has been specified
DeleteProfileParams params = new DeleteProfileParams();
params.setID(uniqueID);
if (type != null && type.compareTo("") != 0) {
try {
logger.debug("Removing profile from sink " + isIcAddress);
params.setProfileType(type);
XMLCollectionAccessPortType port = new XMLCollectionAccessServiceLocator().getXMLCollectionAccessPortTypePort(new URL(isIcAddress));
port = GCUBERemotePortTypeContext.getProxy(port, scope, manager);
port.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 type of the resource to delete is not specified, try
// all the resource types
logger.debug(" trying to remove profile with UniqueID" + uniqueID);
XMLCollectionAccessPortType port = new XMLCollectionAccessServiceLocator().getXMLCollectionAccessPortTypePort(new URL(isIcAddress));
port = GCUBERemotePortTypeContext.getProxy(port, scope, manager);
for (int n = 0; n < ResourceTypes.values().length; n++) {
params.setProfileType(ResourceTypes.values()[n].toString());
logger.debug("Removing profile from sink " + isIcAddress.toString());
port.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);
}
}
}
}
/**
* Queries the IS to find a GCUBEResource given its ID
*
* @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 {
GCUBEGenericQuery query = client.getQuery("GCUBEResourceQuery");
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;
}*/
private void getSinks(final ServiceMap map) throws Exception {
Set<EndpointReferenceType> tmpEPRs = new HashSet<EndpointReferenceType>();
// get the list of IC where to register the RPs
if (map.getEndpoints(ServiceType.ISICProfileQueryPT) != null)
tmpEPRs.addAll(map.getEndpoints(ServiceType.ISICProfileQueryPT));
if (map.getEndpoints(ServiceType.ISICAllQueryPT) != null)
tmpEPRs.addAll(map.getEndpoints(ServiceType.ISICAllQueryPT));
//TODO: temporary patch, to remove when XMLDocumentAccess will be available in the servicemap (gcore >= 0.5.1)
for (EndpointReferenceType epr : tmpEPRs) {
EndpointReferenceType newepr = new EndpointReferenceType();
String path = epr.getAddress().toString();
newepr.setAddress(new AttributedURI(path.replace("XQueryAccess", "XMLCollectionAccess")));
this.ICEprs.add(newepr);
}
if (this.ICEprs.size() == 0)
throw new Exception("No sink available in the Service Map");
}
}

View File

@ -0,0 +1,76 @@
package org.gcube.informationsystem.registry.impl.resourcemanagement;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.contexts.ProfileContext;
/**
*
* Manages the asynchronous deletion of temporary resources
*
* @author Lucio Lelii, Manuele Simi (ISTI-CNR)
*
*/
public class EliminatePoolingThread extends Thread {
private final long sleepTime = 60000;
private List<Pair> stack = Collections.synchronizedList(new LinkedList<Pair>());
private static GCUBELog logger = new GCUBELog(EliminatePoolingThread.class.getName());
@SuppressWarnings("static-access")
public void run() {
boolean noErrors = true;
while (noErrors) {
try {
this.sleep(sleepTime);
} catch (InterruptedException e) {
}
LinkedList<Pair> tmpStack = new LinkedList<Pair>();
try {
long timestamp = System.currentTimeMillis();
synchronized (stack) {
int numRes = stack.size();
while (stack.size() > 0) {
Pair c = stack.remove(stack.size() - 1);
logger.trace("checking resource for deletion " + c.resource.getID());
logger.trace("timenstamp now: " + timestamp + ", resource lifetime: " + c.lifetime);
if ((timestamp >= c.lifetime)) {
try {
logger.debug("temporary resource " + c.resource.getID() + " is going to be deleted");
ProfileContext.getContext().getWSHome().remove(c.resource.getID());
} catch (Exception e) {
logger.error(e);
tmpStack.offer(c);//re-insert the resource in the list
}
} else {
tmpStack.offer(c); //re-insert the resource in the list
}
}
logger.debug("cannot destroy " + tmpStack.size() + " resources retrying in 30 seconds");
logger.debug("destroyed " + (numRes - tmpStack.size()) + " resources ");
stack.addAll(tmpStack);
} //end synchronized block
} catch (Exception e) {
logger.error("Cannot continue with thread Excecution " + e);
noErrors = false;
}
}
}
public synchronized List<Pair> getStack() {
return this.stack;
}
}

View File

@ -0,0 +1,28 @@
package org.gcube.informationsystem.registry.impl.resourcemanagement;
import org.gcube.informationsystem.registry.impl.state.ProfileResource;
/**
*
* Maintain a {@link ProfileResource} and related lifetime association
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public class Pair {
public long lifetime;
public ProfileResource resource;
public Pair(long lifetime, ProfileResource resource){
this.lifetime = lifetime;
this.resource = resource;
}
public boolean equals(Object o){
Pair objectCouple = (Pair) o;
return objectCouple.resource.equals(this.resource);
}
}

View File

@ -0,0 +1,58 @@
package org.gcube.informationsystem.registry.impl.resourcemanagement;
import java.util.List;
import org.gcube.common.core.informationsystem.notifier.ISNotifier;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.contexts.FactoryContext;
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
import org.globus.wsrf.Topic;
/**
* Registration Thread class
*
* @author Andrea Manzi (ISTI-CNR)
*
*
*/
public class RegistrationThread implements Runnable {
private static GCUBELog logger = new GCUBELog(RegistrationThread.class);
private List<? extends Topic> topics;
/**
* The constructor
*
* @param qname
* an Array list of RP qname
* @throws Exception
* Exception
*/
public RegistrationThread(List<? extends Topic> topics) throws Exception {
this.topics = topics;
}
public void run() {
while (true) {
try {
// This is the time interval
Thread.sleep(10000);
} catch (InterruptedException e) {}
try {
ISNotifier notifier = GHNContext.getImplementation(ISNotifier.class);
notifier.registerISNotification(FactoryContext.getContext().getEPR(), topics, ServiceContext.getContext(),
ServiceContext.getContext().getInstance().getScopes().values().toArray(new GCUBEScope[0]));
return;
} catch (Exception e) {
logger.error("Error starting registration: Retrying in 10 seconds");
}
}
}
}

View File

@ -3,23 +3,17 @@ package org.gcube.informationsystem.registry.impl.state;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; 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.GCUBEHostingNode;
import org.gcube.common.core.resources.GCUBEResource; import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.state.GCUBEWSResource; import org.gcube.common.core.state.GCUBEWSResource;
import org.gcube.common.core.utils.logging.GCUBELog; import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
import org.globus.wsrf.ResourceException; import org.globus.wsrf.ResourceException;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
/** /**
* Stateful resource wrapping a {@link GCUBEResource} * Stateful resource wrapping a {@link GCUBEResource}
* *
@ -28,119 +22,116 @@ import org.xml.sax.InputSource;
*/ */
public class ProfileResource extends GCUBEWSResource { public class ProfileResource extends GCUBEWSResource {
private static GCUBELog logger = new GCUBELog(ProfileResource.class.getName()); private static GCUBELog logger = new GCUBELog(ProfileResource.class
.getName());
private ISPublisher publisher = null;
//private ISNotifier notifier= null;
//protected static final String NotificationProfileRP="NotificationProfile";
protected GCUBEResource gCubeResource; protected GCUBEResource gCubeResource;
protected static final String ProfileRP="Profile"; protected static final String ProfileRP = "Profile";
@Override @Override
protected String[] getPropertyNames(){ protected String[] getPropertyNames() {
return new String[] {ProfileRP}; return new String[] { ProfileRP };
} }
/** /**
* Constructor * Constructor
* @throws Exception Exception *
* @throws Exception
* Exception
*/ */
public ProfileResource() throws Exception{}; public ProfileResource() throws Exception {
};
/** /**
* initialize the resource * initialize the resource
* @param params Object *
* @throws ResourceException if resource is missing * @param params
* Object
* @throws ResourceException
* if resource is missing
*/ */
@Override @Override
public void initialise(Object... params) throws ResourceException { public void initialise(Object... params) throws ResourceException {
GCUBEResource resource = (GCUBEResource) params[0]; GCUBEResource resource = (GCUBEResource) params[0];
logger.debug("initializing resource "+resource.getID()); logger.debug("initializing resource " + resource.getID());
Document dom = null; Document dom = null;
StringWriter writer =new StringWriter(); StringWriter writer = new StringWriter();
try { try {
resource.store(writer); resource.store(writer);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setNamespaceAware(true); factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder(); DocumentBuilder builder = factory.newDocumentBuilder();
StringReader reader = new StringReader(writer.toString().substring(writer.toString().indexOf("?>")+2, writer.toString().length())); StringReader reader = new StringReader(writer.toString().substring(
writer.toString().indexOf("?>") + 2,
writer.toString().length()));
InputSource source = new InputSource(reader); InputSource source = new InputSource(reader);
dom =builder.parse(source); dom = builder.parse(source);
} catch (Exception e1) { } catch (Exception e1) {
throw new ResourceException(e1); throw new ResourceException(e1);
} }
this.setProfile(dom); this.setProfile(dom);
//this.setNotificationProfile(dom); // this.setNotificationProfile(dom);
this.setGCubeResource(resource); this.setGCubeResource(resource);
if (hasToLive(resource))
this.setTerminationTime(null);
if (hasToLive(resource)) this.setTerminationTime(null);
/* /*
if (hasToLive(resource)) { * if (hasToLive(resource)) { //registration of Topic To IS-Notifier
//registration of Topic To IS-Notifier *
* listQname.add(new SimpleTopic(this.generateQName()));
listQname.add(new SimpleTopic(this.generateQName())); * synchronized(RegistryFactory.notificationMap) { if
synchronized(RegistryFactory.notificationMap) { * (!(RegistryFactory.notificationMap.contains(this.getID()))) { try {
if (!(RegistryFactory.notificationMap.contains(this.getID()))) { * notifier = GHNContext.getImplementation(ISNotifier.class);
try { * notifier.registerISNotification(this.getEPR(), listQname,
notifier = GHNContext.getImplementation(ISNotifier.class); * ServiceContext.getContext());
notifier.registerISNotification(this.getEPR(), listQname, ServiceContext.getContext()); *
* } catch (Exception e){ e.printStackTrace(); throw new
} catch (Exception e){ * ResourceException(e); }
e.printStackTrace(); *
throw new ResourceException(e); * RegistryFactory.notificationMap.add(this.getID()); } } }
}
RegistryFactory.notificationMap.add(this.getID());
}
}
}
*/ */
} }
/** /**
* set notification Profile * set notification Profile
* *
* @param profile Document * @param profile
* Document
*/
/*
* public void setNotificationProfile(Document profile) {
* this.getResourcePropertySet().get(NotificationProfileRP).clear();
* this.getResourcePropertySet().get(NotificationProfileRP).add(profile);
* //this.getPersistenceDelegate().store(this); }
*/ */
/*public void setNotificationProfile(Document profile) {
this.getResourcePropertySet().get(NotificationProfileRP).clear();
this.getResourcePropertySet().get(NotificationProfileRP).add(profile);
//this.getPersistenceDelegate().store(this);
}*/
/** /**
* get notification Profile * get notification Profile
* *
* @return Document profile * @return Document profile
*/ */
/*public Document getNotificationProfile() { /*
return (Document)this.getResourcePropertySet().get(NotificationProfileRP).get(0); * public Document getNotificationProfile() { return
} * (Document)this.getResourcePropertySet
* ().get(NotificationProfileRP).get(0); }
*/ */
/** /**
* set Profile * set Profile
* *
* @param profile Document * @param profile
* Document
*/ */
public void setProfile(Document profile) { public void setProfile(Document profile) {
this.getResourcePropertySet().get(ProfileRP).clear(); this.getResourcePropertySet().get(ProfileRP).clear();
@ -153,19 +144,17 @@ public class ProfileResource extends GCUBEWSResource {
* @return Document profile * @return Document profile
*/ */
public Document getProfile() { public Document getProfile() {
return (Document)this.getResourcePropertySet().get(ProfileRP).get(0); return (Document) this.getResourcePropertySet().get(ProfileRP).get(0);
} }
/** /**
* Checks if the profile has to live or not * Checks if the profile has to live or not
* *
* @param GCUBEReosurce resource * @param resource the resource
* @return true/false * @return true/false
*/ */
private boolean hasToLive(GCUBEResource resource) { private boolean hasToLive(GCUBEResource resource) {
if (resource.getType().compareTo(GCUBEHostingNode.TYPE)==0) if (resource.getType().compareTo(GCUBEHostingNode.TYPE) == 0)
return true; return true;
else else
return false; return false;
@ -173,77 +162,76 @@ public class ProfileResource extends GCUBEWSResource {
/** /**
* Gets the Resource QName * Gets the Resource QName
*
* @return the Resource QName * @return the Resource QName
*/ */
//private QName generateQName() { // private QName generateQName() {
// return new QName(ProfileContext.getContext().getNamespace(), NotificationProfileRP+this.getID().getValue()); // return new QName(ProfileContext.getContext().getNamespace(),
//} // NotificationProfileRP+this.getID().getValue());
// }
/** /**
* returns the Resource * Returns the Resource
* *
* @return resource GCUBEReosurce * @return the resource
*/ */
public GCUBEResource getGCubeResource() { public GCUBEResource getGCubeResource() {
return this.gCubeResource; return this.gCubeResource;
} }
/** /**
* sets the resource * Sets the resource
* @param resource GCUBEReosurce *
* @param resource the resource
*/ */
public void setGCubeResource(GCUBEResource resource) { public void setGCubeResource(GCUBEResource resource) {
this.gCubeResource = resource; this.gCubeResource = resource;
} }
// /** {@inheritDoc}*/
/** {@inheritDoc}*/ // @Override
@Override // public void onRemove() throws ResourceException{
public void onRemove() throws ResourceException{ // super.onRemove();
super.onRemove(); // logger.info("Resource " + this.getID()+ " is going to be removed.");
logger.info("Resource " + this.getID()+ " is going to be removed."); //
// try {
try { // publisher = GHNContext.getImplementation(ISPublisher.class);
publisher = GHNContext.getImplementation(ISPublisher.class); // } catch (Exception e) {
} catch (Exception e) { // e.printStackTrace();
e.printStackTrace(); // }
} //
// /*
/* // if (RegistryFactory.notificationMap.contains(this.getID()))
if (RegistryFactory.notificationMap.contains(this.getID())) // {
{ // try {
try { // notifier = GHNContext.getImplementation(ISNotifier.class);
notifier = GHNContext.getImplementation(ISNotifier.class); // notifier.unregisterISNotification(this.getEPR(),listQname,ServiceContext.getContext());
notifier.unregisterISNotification(this.getEPR(),listQname,ServiceContext.getContext()); // } catch (ISPublisherException e) {
} catch (ISPublisherException e) { // e.printStackTrace();
e.printStackTrace(); // } catch (Exception e) {
} catch (Exception e) { // e.printStackTrace();
e.printStackTrace(); // }
} //
// synchronized(RegistryFactory.notificationMap) {
synchronized(RegistryFactory.notificationMap) { // RegistryFactory.notificationMap.remove(this.getID());
RegistryFactory.notificationMap.remove(this.getID()); // }
} // }*/
}*/ //
// try {
try { // publisher.removeWSResource(this,ServiceContext.getContext().getScope());
publisher.removeWSResource(this,ServiceContext.getContext().getScope()); // //System.out.println(" "+this.getResourcePropertySet().getScope().get(0));
//System.out.println(" "+this.getResourcePropertySet().getScope().get(0)); // } catch (ISPublisherException e) {
} catch (ISPublisherException e) { // e.printStackTrace();
e.printStackTrace(); // }
} //
// }
}
/** /**
* updates the resource * Updates the resource
* *
* @param resource the resource to update * @param resource the resource to update
* @throws Exception if something goes wrong * @throws Exception if something goes wrong
*/ */
public void updateResource(GCUBEResource resource) throws Exception {
public void updateResource(GCUBEResource resource) throws Exception{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true); factory.setNamespaceAware(true);
@ -256,11 +244,10 @@ public class ProfileResource extends GCUBEWSResource {
this.setProfile(dom); this.setProfile(dom);
this.setGCubeResource(resource); this.setGCubeResource(resource);
// updates the notification profile too // updates the notification profile too
/*if (this.hasToLive(resource)) /*
this.setNotificationProfile(dom); * if (this.hasToLive(resource)) this.setNotificationProfile(dom);
*/ */
this.store(); this.store();
} }
} }

View File

@ -1,26 +0,0 @@
package org.gcube.informationsystem.registry.impl.util;
import org.gcube.informationsystem.registry.impl.state.ProfileResource;
/**
* couple
* @author lucio
*
*/
public class Couple{
public long timestamp;
public ProfileResource resource;
public Couple(long timestamp, ProfileResource resource){
this.timestamp=timestamp;
this.resource= resource;
}
public boolean equals(Object o){
Couple objectCouple= (Couple) o;
return objectCouple.resource.equals(this.resource);
}
}

View File

@ -1,69 +0,0 @@
package org.gcube.informationsystem.registry.impl.util;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.RegistryFactory;
import org.gcube.informationsystem.registry.impl.contexts.ProfileContext;
public class EliminatePoolingThread extends Thread {
private final long sleepTime= 60000;
private List<Couple> stack = Collections.synchronizedList(new LinkedList<Couple>());
private static GCUBELog logger = new GCUBELog(RegistryFactory.class.getName());
@SuppressWarnings("static-access")
public void run(){
boolean noErrors= true;
while(noErrors){
try {
this.sleep(sleepTime);
} catch (InterruptedException e) {}
LinkedList<Couple> tmpStack = new LinkedList<Couple>();
try {
long timestamp= System.currentTimeMillis();
synchronized (stack) {
int numRes= stack.size();
while (stack.size()>0){
Couple c=stack.remove(stack.size()-1);
logger.trace("trying to delete "+c.resource.getID() );
logger.trace("timenstamp now: "+timestamp+" resource timestamp: "+c.timestamp);
if ( (timestamp>=c.timestamp))
try {
ProfileContext.getContext().getWSHome().remove(c.resource.getID());
}catch(Exception e){e.printStackTrace();tmpStack.offer(c);}
else tmpStack.offer(c);
}
logger.debug("cannot destroy "+tmpStack.size()+" resources retrying in 30 seconds");
logger.debug("destroyed "+(numRes-tmpStack.size())+" resources ");
stack.addAll(tmpStack);
}
} catch (Exception e) {
logger.error("Cannot continue with thread Excecution "+e);
e.printStackTrace();
noErrors=false;
}
}
}
public synchronized List<Couple> getStack(){
return this.stack;
}
}

View File

@ -1,124 +0,0 @@
package org.gcube.informationsystem.registry.impl.util;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;
import org.apache.axis.message.addressing.EndpointReferenceType;
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.contexts.ServiceContext;
import org.ietf.jgss.GSSCredential;
public class ProfileManager {
protected static final GCUBELog logger=new GCUBELog(ProfileManager.class);
protected static final String ISICpostfix = "DISICService";
//protected URL isIcAddress;
protected Set<EndpointReferenceType> ICEprs = new HashSet<EndpointReferenceType>();
protected String VOMapName;
public enum ResourceTypes {
Service,
CS,
CSInstance,
Collection,
RunningInstance,
ExternalRunningInstance,
GHN,
gLiteResource,
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);
}
this.getSinks(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 {
for (EndpointReferenceType sink : this.ICEprs) {
String isIcAddress = sink.getAddress().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) {
try {
logger.debug(" Removing profile from sink " + isIcAddress);
params.setProfileType(type);
DISICServicePortType dis_ic = locator_disic.getDISICServicePortTypePort(new URL(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 type of 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 sink " + isIcAddress.toString());
DISICServicePortType dis_ic = locator_disic.getDISICServicePortTypePort(new URL(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 void getSinks(ServiceMap map) throws Exception {
/*
String addressISIC = (String) map.getEndpoint(ServiceType.ISPublishService).getAddress().toString();
addressISIC = addressISIC.substring(0, addressISIC.lastIndexOf("/") + 1) + ISICpostfix;
return new URL(addressISIC);*/
//get the list of IC where to register the RPs
if (map.getEndpoints(ServiceType.ISICProfileQueryPT) != null)
this.ICEprs.addAll(map.getEndpoints(ServiceType.ISICProfileQueryPT));
if (map.getEndpoints(ServiceType.ISICAllQueryPT) != null)
this.ICEprs.addAll(map.getEndpoints(ServiceType.ISICAllQueryPT));
if (this.ICEprs.size() == 0)
throw new Exception("No sink available in the Service Map");
}
}

View File

@ -1,66 +0,0 @@
package org.gcube.informationsystem.registry.impl.util;
import java.util.List;
import org.gcube.common.core.informationsystem.notifier.ISNotifier;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.contexts.FactoryContext;
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
import org.globus.wsrf.Topic;
/**
* Registration Thread class
* @author Andrea Manzi (ISTI-CNR)
*
*
*/
public class RegistrationThread implements Runnable{
/**
*
*/
private static GCUBELog logger = new GCUBELog(RegistrationThread.class);
/**
*
*/
private List<? extends Topic> topics;
/**
*
*/
/**
* The constructor
* @param qname an Array list of RP qname
* @throws Exception Exception
*/
public RegistrationThread ( List<? extends Topic> topics) throws Exception{
this.topics = topics;
}
/**
*
*/
public void run() {
while (true) {
try {
// This is the time interval
Thread.sleep(10000);
}
catch(InterruptedException e){
}
try {
ISNotifier notifier = GHNContext.getImplementation(ISNotifier.class);
notifier.registerISNotification(FactoryContext.getContext().getEPR(),topics, ServiceContext.getContext(), ServiceContext.getContext().getInstance().getScopes().values().toArray(new GCUBEScope[0]));
return;
} catch (Exception e) {
e.printStackTrace();
logger.error("Error starting registration:Retrying in 10 seconds");
}
}
}
}

View File

@ -1,87 +0,0 @@
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.QueryParameter;
import org.gcube.common.core.informationsystem.client.XMLResult;
import org.gcube.common.core.informationsystem.client.ISClient.ISMalformedQueryException;
import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery;
import org.gcube.common.core.resources.GCUBERunningInstance;
import org.gcube.informationsystem.registry.impl.RegistryFactory;
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage;
/**
*
* Helper class for IS-registry
*
* @author Andrea Manzi(ISTI_CNR)
*
*/
public class RegistryUtil {
public static ISClient client = null;
/**
* Queries the IS to find a GCUBEResource given its ID
*
* @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 {
GCUBEGenericQuery query = client.getQuery("GCUBEResourceQuery");
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 Exception{
if (client==null) client = GHNContext.getImplementation(ISClient.class);
RemoveResourceMessage message = null;
GCUBEGenericQuery query = client.getQuery("RIOnGHN");
query.addParameters(new QueryParameter("ID", id));
//query to IS on order to retrieve the RI deployed on the GHN;
List<XMLResult> resources = client.execute(query, ServiceContext.getContext().getScope());
if (resources.size() != 0){
for (XMLResult resource : resources) {
try {
message = new RemoveResourceMessage();
message.setType(GCUBERunningInstance.TYPE);
message.setUniqueID(resource.evaluate("/Resource/ID/text()").get(0));
service.removeResource(message);
} catch (RemoteException rme) {}
}
}
}
}

View File

@ -1,148 +0,0 @@
package org.gcube.informationsystem.registry.stubs.testsuite;
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.GCUBEGenericResource;
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.scope.GCUBEScope;
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;
/**
* {@link GCUBEResource} registration tester
*
* @author Manuele Simi (CNR-ISTI)
*
*/
public class RegistryRegistrationTest {
/**
*
* @param args
* parameters:
* <ul>
* <li>factory URI
* <li>resource file
* <li>resource type
* <li>caller scope
*
* @throws Exception
* if the registration fails
*/
public static void main(String[] args) throws Exception {
if (args.length != 4) {
printUsage();
}
for (String param : args) System.out.println("param "+ param);
// get the scope and the factory URI
GCUBEScope scope = GCUBEScope.getScope(args[2]);
EndpointReferenceType factoryEPR = new EndpointReferenceType();
try {
factoryEPR.setAddress(new Address(args[0]));
} catch (Exception e) {
e.printStackTrace();
Runtime.getRuntime().exit(1);
}
RegistryFactoryServiceAddressingLocator registryLocator = new RegistryFactoryServiceAddressingLocator();
GCUBESecurityManagerImpl managerSec = new GCUBESecurityManagerImpl() {
public boolean isSecurityEnabled() {
return false;
}
};
// load the resource
GCUBEResource resource = getResource(args[3], new FileReader(args[1]));
RegistryFactoryPortType registryFactoryPortType = null;
try {
registryFactoryPortType = registryLocator
.getRegistryFactoryPortTypePort(factoryEPR);
} catch (Exception e) {
e.printStackTrace();
Runtime.getRuntime().exit(1);
}
CreateResourceMessage message = new CreateResourceMessage();
registryFactoryPortType = GCUBERemotePortTypeContext.getProxy(
registryFactoryPortType, scope, managerSec);
try {
StringWriter writer = new StringWriter();
resource.store(writer);
message.setProfile(writer.toString());
message.setType(resource.getType());
System.out.println(registryFactoryPortType.createResource(message));
} catch (Exception e) {
e.printStackTrace();
Runtime.getRuntime().exit(1);
}
}
/**
* Loads the specific GCUBEResource class
*
* @param type
* the resource type
* @param file
* the file representation of the profile
* @return the resource class
* @throws Exception
* if the loading fails
*/
static GCUBEResource getResource(String type, FileReader file)
throws Exception {
if (type.compareTo("Service") == 0) {
GCUBEService service = GHNContext
.getImplementation(GCUBEService.class);
service.load(file);
return (GCUBEResource) service;
} else if (type.compareTo("RunningInstance") == 0) {
GCUBERunningInstance instance = GHNContext
.getImplementation(GCUBERunningInstance.class);
instance.load(file);
return (GCUBEResource) instance;
} else if (type.compareTo("GHN") == 0) {
GCUBEHostingNode node = GHNContext
.getImplementation(GCUBEHostingNode.class);
node.load(file);
return (GCUBEResource) node;
} else if (type.compareTo("GenericResource") == 0) {
GCUBEGenericResource generic = GHNContext
.getImplementation(GCUBEGenericResource.class);
generic.load(file);
return (GCUBEResource) generic;
}
throw new Exception(type + " is an invalid resource type");
}
/**
* Prints tester usage syntax
*/
static void printUsage() {
System.out
.println("RegistryRegistrationTest <factory URI> <resource file> <resource type> <caller scope>");
System.out
.println("allowed types are: RunningInstance/Service/GHN/GenericResource");
System.exit(1);
}
}

View File

@ -1,52 +0,0 @@
package org.gcube.informationsystem.registry.stubs.testsuite;
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.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;
public class RegistryRemoveTest {
public static void main(String[] args) throws Exception {
RegistryFactoryServiceAddressingLocator registryLocator = new RegistryFactoryServiceAddressingLocator();
GCUBESecurityManagerImpl managerSec = new GCUBESecurityManagerImpl() {
public boolean isSecurityEnabled() {
return true;
}
};
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(args[2]),
managerSec);
try {
message.setType(args[3]);
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

@ -1 +0,0 @@
java -cp ./lib/org.gcube.informationsystem.registry.stubs.jar:$CLASSPATH org/gcube/informationsystem/registry/stubs/testsuite/RegistryRegistrationTest $1 $2 $3 $4

View File

@ -1 +0,0 @@
java -cp ./lib/org.gcube.informationsystem.registry.jar:$CLASSPATH org/gcube/informationsystem/registry/stubs/testsuite/RegistryRemoveTest $1 $2 $3 $4