git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@15059 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
8d7c4115f6
commit
15772e3d89
27
build.xml
27
build.xml
|
@ -3,7 +3,7 @@
|
|||
|
||||
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
|
||||
in the configuration directory of the service (or else using the -D flag on the command line).
|
||||
|
@ -24,10 +24,7 @@ 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
|
||||
should be optimised for remote builds in ETICS. If it is omitted, this buildfile will optimise build structures and procedures
|
||||
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.
|
||||
|
||||
|
||||
-->
|
||||
|
||||
<project default="deployService" name="GCUBE Service Buildfile">
|
||||
|
@ -86,10 +83,9 @@ full.stubs: (optional) Set to 'false', it excludes auxiliary stub code plac
|
|||
</if>
|
||||
|
||||
|
||||
<property name="full.stubs" value="true"/>
|
||||
<property name="stubs.package" value="${package}.${stubs.dir.name}"/>
|
||||
<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"/>
|
||||
|
||||
<!-- temporary build locations -->
|
||||
|
@ -395,8 +391,7 @@ full.stubs: (optional) Set to 'false', it excludes auxiliary stub code plac
|
|||
</target>
|
||||
|
||||
<target name="buildService" depends="processWSDLs" description="compiles service implementation">
|
||||
<javac srcdir="${source.dir}" destdir="${build.class.dir}" debug="${java.debug}" deprecation="${java.deprecation}"
|
||||
excludes="org/gcube/common/vremanagement/deployer/stubs/**">
|
||||
<javac srcdir="${source.dir}" destdir="${build.class.dir}" debug="${java.debug}" deprecation="${java.deprecation}">
|
||||
<classpath>
|
||||
<fileset dir="${lib.location}">
|
||||
<include name="**/*.jar" />
|
||||
|
@ -434,14 +429,12 @@ full.stubs: (optional) Set to 'false', it excludes auxiliary stub code plac
|
|||
<!-- Stub Build tasks -->
|
||||
|
||||
<target name="buildStubs" depends="processWSDLs,generateStubs" description="build service stubs">
|
||||
<if name="full.stubs" value="true">
|
||||
<if name="stubs.dir.present">
|
||||
<copy toDir="${build.stubs.src.dir}/${package.dir}/${stubs.dir.name}" overwrite="true">
|
||||
<fileset dir="${stubs.dir}" casesensitive="yes">
|
||||
<exclude name="**/*.class" />
|
||||
</fileset>
|
||||
</copy>
|
||||
</if>
|
||||
<if name="stubs.dir.present">
|
||||
<copy toDir="${build.stubs.src.dir}/${package.dir}/${stubs.dir.name}" overwrite="true">
|
||||
<fileset dir="${stubs.dir}" casesensitive="yes">
|
||||
<exclude name="**/*.class" />
|
||||
</fileset>
|
||||
</copy>
|
||||
</if>
|
||||
<javac srcdir="${build.stubs.src.dir}" destdir="${build.stubs.class.dir}" debug="${java.debug}" deprecation="${java.deprecation}" description="compile stub classes">
|
||||
<include name="**/*.java" />
|
||||
|
|
|
@ -7,6 +7,13 @@
|
|||
<Class>InformationSystem</Class>
|
||||
<Name>IS-Registry</Name>
|
||||
<Version>1.0.0</Version>
|
||||
<Dependencies>
|
||||
<Dependency>
|
||||
<Class>InformationSystem</Class>
|
||||
<Name>IS-Collector</Name>
|
||||
<Version>1.00.00</Version>
|
||||
</Dependency>
|
||||
</Dependencies>
|
||||
<Packages>
|
||||
<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>
|
||||
|
|
|
@ -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.filters.FilterManager;
|
||||
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.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.ProfileAlreadyRegisteredFault;
|
||||
import org.gcube.informationsystem.registry.stubs.RegistryProperty;
|
||||
|
@ -46,478 +46,498 @@ import org.gcube.informationsystem.registry.stubs.UpdateResourceMessage;
|
|||
import org.gcube.informationsystem.registry.stubs.UpdateResourceResponse;
|
||||
import org.gcube.informationsystem.registry.stubs.UpdateScopeInProfileMessage;
|
||||
import org.gcube.informationsystem.registry.stubs.UpdateStateMessage;
|
||||
import org.globus.wsrf.security.SecurityManager;
|
||||
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
|
||||
*
|
||||
* @author Andrea Manzi, Manuele Simi (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
public class RegistryFactory extends GCUBEPortType {
|
||||
|
||||
/**Name of temporaryResourceLifetimeInMs JNDI environment.*/
|
||||
private static final String LIFETIME_JNDI_NAME = "temporaryResourceLifetimeInMs";
|
||||
|
||||
/**
|
||||
* Lifetime of temporary resources
|
||||
*/
|
||||
private static long temporaryResourceLifetimeInMs= 120000;
|
||||
|
||||
|
||||
/**The UUIDGen */
|
||||
private static final UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
|
||||
/** Name of temporaryResourceLifetimeInMs JNDI environment. */
|
||||
private static final String LIFETIME_JNDI_NAME = "temporaryResourceLifetimeInMs";
|
||||
|
||||
/**Object logger*/
|
||||
protected final GCUBELog logger = new GCUBELog(RegistryFactory.class);
|
||||
|
||||
enum OperationType {create,update,destroy};
|
||||
/**
|
||||
* Lifetime of temporary resources
|
||||
*/
|
||||
private static long temporaryResourceLifetimeInMs = 120000;
|
||||
|
||||
/**
|
||||
* Map of registration to Notification
|
||||
*/
|
||||
public static final List<GCUBEWSResourceKey> notificationMap = Collections.synchronizedList(new ArrayList<GCUBEWSResourceKey>());
|
||||
/** The UUIDGen */
|
||||
private static final UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
|
||||
|
||||
/** the key used to label the Factory Resource */
|
||||
public static final String NOTIFICATOR_RESOURCE_KEY = "RegistryResource";
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void onInitialisation() throws Exception {
|
||||
temporaryResourceLifetimeInMs = (Long)ServiceContext.getContext().getProperty(LIFETIME_JNDI_NAME);
|
||||
logger.info("Temporary resources lifetime = " + temporaryResourceLifetimeInMs);
|
||||
/** Object logger */
|
||||
protected final GCUBELog logger = new GCUBELog(RegistryFactory.class);
|
||||
|
||||
enum OperationType {
|
||||
create, update, destroy
|
||||
};
|
||||
|
||||
/**
|
||||
* Map of registration to Notification
|
||||
*/
|
||||
public static final List<GCUBEWSResourceKey> notificationMap = Collections
|
||||
.synchronizedList(new ArrayList<GCUBEWSResourceKey>());
|
||||
|
||||
/** the key used to label the Factory Resource */
|
||||
public static final String NOTIFICATOR_RESOURCE_KEY = "RegistryResource";
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void onInitialisation() throws Exception {
|
||||
temporaryResourceLifetimeInMs = (Long) ServiceContext.getContext()
|
||||
.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)
|
||||
*
|
||||
*
|
||||
* @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());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
return new StartRegistrationResponse();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Creates a new GCUBEResource's profile manager
|
||||
*
|
||||
* @param inputMessage
|
||||
* @return the profile as string
|
||||
* @throws SchemaValidationFault
|
||||
* @throws RemoteException
|
||||
* @throws ProfileAlreadyRegisteredFault
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public String createResource(CreateResourceMessage mess) throws SchemaValidationFault, RemoteException,
|
||||
ProfileAlreadyRegisteredFault, ResourceNotAcceptedFault {
|
||||
|
||||
GCUBEResource resource = null;
|
||||
|
||||
logger.info("CreateResource operation invoked");
|
||||
// logSecurityInfo("createResource");
|
||||
|
||||
String profile = mess.getProfile();
|
||||
if (profile == null || profile.compareTo("") == 0) {
|
||||
String msg = "Profile file is empty";
|
||||
logger.debug(msg);
|
||||
throw new RemoteException(msg);
|
||||
}
|
||||
|
||||
try {
|
||||
resource = ResourceType.valueOf(mess.getType()).getResourceClass();
|
||||
|
||||
/**
|
||||
*
|
||||
* Creates a new GCUBEResource's profile manager
|
||||
*
|
||||
* @param inputMessage
|
||||
* @return the profile as string
|
||||
* @throws SchemaValidationFault
|
||||
* @throws RemoteException
|
||||
* @throws ProfileAlreadyRegisteredFault
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public String createResource(CreateResourceMessage mess) throws SchemaValidationFault,RemoteException,ProfileAlreadyRegisteredFault,ResourceNotAcceptedFault {
|
||||
GCUBEResource resource=null;
|
||||
|
||||
logger.info("CreateResource operation invoked");
|
||||
//logSecurityInfo("createResource");
|
||||
|
||||
|
||||
|
||||
String profile = mess.getProfile();
|
||||
if (profile == null || profile.compareTo("") == 0) {
|
||||
String msg = "Profile file is empty";
|
||||
logger.debug(msg);
|
||||
throw new RemoteException(msg);
|
||||
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
|
||||
// in order to distinguish among different Resource Type
|
||||
// Adding scopes to Profile
|
||||
String[] scopes = mess.getScopes();
|
||||
if (scopes != null) {
|
||||
for (String scope : scopes) {
|
||||
logger.debug(resource.getID()
|
||||
+ " Adding Scopes to Profile " + scope);
|
||||
resource.addScope(GCUBEScope.getScope(scope));
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
resource=ResourceType.valueOf(mess.getType()).getResourceClass();
|
||||
|
||||
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
|
||||
//in order to distinguish among different Resource Type
|
||||
//Adding scopes to Profile
|
||||
String [] scopes = mess.getScopes();
|
||||
if (scopes != null) {
|
||||
for (String scope : scopes) {
|
||||
logger.debug(resource.getID()+" 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();
|
||||
}
|
||||
//apply resource filter
|
||||
try {
|
||||
if (! FilterManager.getExecutor(resource.getType()).accept(resource)) {
|
||||
logger.warn("Resource "+ resource.getID()+" NOT accepted ");
|
||||
throw new ResourceNotAcceptedFault();
|
||||
}
|
||||
logger.trace("Resource "+ resource.getID()+" accepted ");
|
||||
} catch (InvalidFilterException e) {
|
||||
logger.warn("Invalid filter selected, the resource " + resource.getID()+" CANNOT be filtered ");
|
||||
}
|
||||
|
||||
//check if the Resource already exists
|
||||
if (isResourceCreated(resource.getID())) {
|
||||
// update the existing resource
|
||||
logger.warn("A Resource with ID "+ resource.getID()+" is already registered");
|
||||
UpdateResourceMessage upmess = new UpdateResourceMessage();
|
||||
upmess.setUniqueID(resource.getID());
|
||||
upmess.setXmlProfile(mess.getProfile());
|
||||
upmess.setType(mess.getType());
|
||||
this.updateResource(upmess);
|
||||
//throw new ProfileAlreadyRegisteredFault();
|
||||
} else {
|
||||
//try to create resource
|
||||
try {
|
||||
logger.debug(resource.getID()+" Creating the stateful resource for " + resource.getID());
|
||||
|
||||
ProfileResource presource = (ProfileResource) ProfileContext.getContext().getWSHome().create(ProfileContext.getContext().makeKey(resource.getID()),resource);
|
||||
presource.store();
|
||||
|
||||
//Deleting the WSResource created
|
||||
long timestamp;
|
||||
if (resource.getType().compareTo(GCUBEHostingNode.TYPE)!=0){
|
||||
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);
|
||||
if(!ServiceContext.threadTable.get(tmpScope.getName()).getStack().contains(c)){
|
||||
ServiceContext.threadTable.get(tmpScope.getName()).getStack().add(c);
|
||||
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);
|
||||
}
|
||||
try {
|
||||
updateCounterInfo (resource.getID(), ResourceType.valueOf(mess.getType()), OperationType.create, Calendar.getInstance());
|
||||
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>();
|
||||
event.setPayload(resource);
|
||||
ServiceContext.getContext().getTopicProducer().notify(ServiceContext.RegistryTopic.CREATE, event);
|
||||
} catch (Exception e) {
|
||||
logger.warn("Error updating Counting info for resource with ID " + resource.getID(), e);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
logger.info("Profile " + resource.getID() + " created ");
|
||||
return writer.toString();
|
||||
|
||||
}
|
||||
// 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();
|
||||
}
|
||||
// apply resource filter
|
||||
try {
|
||||
if (!FilterManager.getExecutor(resource.getType()).accept(resource)) {
|
||||
logger.warn("Resource " + resource.getID() + " NOT accepted ");
|
||||
throw new ResourceNotAcceptedFault();
|
||||
}
|
||||
logger.trace("Resource " + resource.getID() + " accepted ");
|
||||
} catch (InvalidFilterException e) {
|
||||
logger.warn("Invalid filter selected, the resource "
|
||||
+ resource.getID() + " CANNOT be filtered ");
|
||||
}
|
||||
|
||||
// check if the Resource already exists
|
||||
if (isResourceCreated(resource.getID())) {
|
||||
// update the existing resource
|
||||
logger.warn("A Resource with ID " + resource.getID()
|
||||
+ " is already registered");
|
||||
UpdateResourceMessage upmess = new UpdateResourceMessage();
|
||||
upmess.setUniqueID(resource.getID());
|
||||
upmess.setXmlProfile(mess.getProfile());
|
||||
upmess.setType(mess.getType());
|
||||
this.updateResource(upmess);
|
||||
// throw new ProfileAlreadyRegisteredFault();
|
||||
} else {
|
||||
// try to create resource
|
||||
try {
|
||||
logger.debug(resource.getID() + " Creating the stateful resource for " + resource.getID());
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return UpdateResourceResponse
|
||||
* @throws RemoteException Exception
|
||||
* @throws SchemaValidationException Exception
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public UpdateResourceResponse updateResource(UpdateResourceMessage mess)
|
||||
throws RemoteException, SchemaValidationFault, ResourceNotAcceptedFault, GCUBEFault {
|
||||
ProfileResource presource = (ProfileResource) ProfileContext.getContext().getWSHome().create(ProfileContext.getContext()
|
||||
.makeKey(resource.getID()), resource);
|
||||
presource.store();
|
||||
|
||||
//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 = ResourceType.valueOf(mess.getType()).getResourceClass();
|
||||
resource.load(new StringReader(xmlProfile));
|
||||
|
||||
//apply resource filter
|
||||
try {
|
||||
if (! FilterManager.getExecutor(resource.getType()).accept(resource)) {
|
||||
logger.warn("Resource "+ resource.getID()+" NOT accepted ");
|
||||
throw new ResourceNotAcceptedFault();
|
||||
}
|
||||
logger.trace("Resource "+ resource.getID()+" accepted ");
|
||||
} catch (InvalidFilterException e) {
|
||||
logger.warn("Invalid filter selected, the resource " + resource.getID()+" CANNOT be filtered ");
|
||||
}
|
||||
|
||||
ProfileResource pr= getProfileResource(ID);
|
||||
pr.updateResource(resource);
|
||||
|
||||
//Deleting the WSResource created
|
||||
long timestamp;
|
||||
if (resource.getType().compareTo(GCUBEHostingNode.TYPE)!=0){
|
||||
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, pr);
|
||||
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());
|
||||
}
|
||||
|
||||
try {
|
||||
updateCounterInfo (ID,ResourceType.valueOf(mess.getType()),OperationType.update, Calendar.getInstance());
|
||||
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>();
|
||||
event.setPayload(resource);
|
||||
ServiceContext.getContext().getTopicProducer().notify(ServiceContext.RegistryTopic.UPDATE, event);
|
||||
} catch (Exception e) {
|
||||
logger.warn("Error updating counting info for resource with ID " + resource.getID(), e);
|
||||
}
|
||||
logger.info("Profile " + mess.getUniqueID() + " updated");
|
||||
return new UpdateResourceResponse();
|
||||
// Deleting the WSResource created if != from GHN
|
||||
if (resource.getType().compareTo(GCUBEHostingNode.TYPE) != 0)
|
||||
this.scheduleForLazyDeletion(presource);
|
||||
|
||||
} catch (Exception ex) {
|
||||
String msg = "Error creating Resource " + resource.getID();
|
||||
logger.error(msg, ex);
|
||||
throw new RemoteException(msg);
|
||||
}
|
||||
try {
|
||||
updateCounterInfo(resource.getID(), ResourceType.valueOf(mess.getType()), OperationType.create, Calendar.getInstance());
|
||||
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>();
|
||||
event.setPayload(resource);
|
||||
ServiceContext.getContext().getTopicProducer().notify(
|
||||
ServiceContext.RegistryTopic.CREATE, event);
|
||||
} catch (Exception e) {
|
||||
logger.warn("Error updating Counting info for resource with ID " + resource.getID(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a Resource profile identified by the given the resource ID
|
||||
*
|
||||
*
|
||||
* @param inputMessage Defined into WSDL file
|
||||
* @return RemoveResourceResponse
|
||||
* @throws RemoteException Exceptions
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
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.warn("Resource ID is missing");
|
||||
throw new RemoteException("Resource ID is missing");
|
||||
}
|
||||
//check if the UniqueID exist
|
||||
|
||||
/*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("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) {
|
||||
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");
|
||||
}
|
||||
//}
|
||||
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);
|
||||
}
|
||||
|
||||
logger.info("Profile " + resource.getID() + " created ");
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a resource for a delayed deletion
|
||||
*
|
||||
* @param presource the resource to delete
|
||||
*/
|
||||
private void scheduleForLazyDeletion(ProfileResource presource) {
|
||||
|
||||
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);
|
||||
System.out.println("error removing RI related to GHN");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (this.isResourceCreated(ID)){
|
||||
//destroy the resource
|
||||
try{
|
||||
|
||||
ProfileContext.getContext().getWSHome().remove(ProfileContext.getContext().makeKey(ID));
|
||||
|
||||
logger.info(" Resource Destroyed");
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Error removing resource for ID ", e);
|
||||
throw new RemoteException();
|
||||
}
|
||||
try {
|
||||
|
||||
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>();
|
||||
GCUBEResource resource =ResourceType.valueOf(type).getResourceClass();
|
||||
resource.setID(ID);
|
||||
event.setPayload(resource);
|
||||
ServiceContext.getContext().getTopicProducer().notify(ServiceContext.RegistryTopic.REMOVE, event);
|
||||
|
||||
updateCounterInfo(ID, ResourceType.valueOf(type), OperationType.destroy, Calendar.getInstance());
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.warn("Error updating counting info for resource with ID " + ID ,e);
|
||||
}
|
||||
}
|
||||
|
||||
return new RemoveResourceResponse();
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @param id the Resource ID
|
||||
* @return the resource ( null if the resource has not been created yet
|
||||
*/
|
||||
protected synchronized ProfileResource getProfileResource(String id ){
|
||||
try {
|
||||
return (ProfileResource) ProfileContext.getContext().getWSHome().find(ProfileContext.getContext().makeKey(id));
|
||||
}
|
||||
catch (Exception e ){
|
||||
logger.debug("A profile with the given id "+ id+" has not been created yet");
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
protected synchronized boolean isResourceCreated(String id) {
|
||||
if (getProfileResource(id) != null) return true; else return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Updates the RegistryFactoryResource RPs for notification
|
||||
*
|
||||
*
|
||||
* @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, ResourceType resType, OperationType opType, Calendar updateTime) throws Exception{
|
||||
|
||||
RegistryProperty property = new RegistryProperty();
|
||||
property.setUniqueID(ID);
|
||||
property.setOperationType(opType.name());
|
||||
property.setChangeTime(updateTime);
|
||||
//select the type of the resource to update
|
||||
for (Method method :this.getResource().getClass().getDeclaredMethods()) {
|
||||
if (method.getName().contains(resType.name()) && method.getName().contains("set")) {
|
||||
method.invoke(this.getResource(),property);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
this.getResource().store();
|
||||
}
|
||||
/**
|
||||
* return the resource
|
||||
*
|
||||
* @return NotifierResource resource
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message UpdateScopeInProfileMessage
|
||||
* @return String
|
||||
* @throws GCUBEFault -
|
||||
*/
|
||||
public String updateScopeInProfile(UpdateScopeInProfileMessage message)throws GCUBEFault{return null;}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message RemoveScopeInProfileMessage
|
||||
* @return String
|
||||
* @throws GCUBEFault -
|
||||
*/
|
||||
public String removeScopeInProfile(RemoveScopeInProfileMessage message)throws GCUBEFault{return null;}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message UpdateStateMessage
|
||||
* @return
|
||||
* @throws GCUBEFault -
|
||||
*/
|
||||
public String updateState(UpdateStateMessage message)throws GCUBEFault{return null;}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return UpdateResourceResponse
|
||||
* @throws RemoteException
|
||||
* Exception
|
||||
* @throws SchemaValidationException
|
||||
* Exception
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public UpdateResourceResponse updateResource(UpdateResourceMessage mess)
|
||||
throws RemoteException, SchemaValidationFault,
|
||||
ResourceNotAcceptedFault, GCUBEFault {
|
||||
|
||||
@Override
|
||||
protected GCUBEServiceContext getServiceContext() {
|
||||
return ServiceContext.getContext();
|
||||
// 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 = ResourceType.valueOf(mess.getType()).getResourceClass();
|
||||
resource.load(new StringReader(xmlProfile));
|
||||
|
||||
// apply resource filter
|
||||
try {
|
||||
if (!FilterManager.getExecutor(resource.getType()).accept(resource)) {
|
||||
logger.warn("Resource " + resource.getID() + " NOT accepted ");
|
||||
throw new ResourceNotAcceptedFault();
|
||||
}
|
||||
logger.trace("Resource " + resource.getID() + " accepted ");
|
||||
} catch (InvalidFilterException e) {
|
||||
logger.warn("Invalid filter selected, the resource " + resource.getID() + " CANNOT be filtered ");
|
||||
}
|
||||
|
||||
ProfileResource presource = getProfileResource(ID);
|
||||
presource.updateResource(resource);
|
||||
|
||||
// Deleting the WSResource created
|
||||
if (resource.getType().compareTo(GCUBEHostingNode.TYPE) != 0)
|
||||
this.scheduleForLazyDeletion(presource);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error updating profile for ID " + e);
|
||||
throw new RemoteException(e.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
updateCounterInfo(ID, ResourceType.valueOf(mess.getType()),
|
||||
OperationType.update, Calendar.getInstance());
|
||||
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>();
|
||||
event.setPayload(resource);
|
||||
ServiceContext.getContext().getTopicProducer().notify(
|
||||
ServiceContext.RegistryTopic.UPDATE, event);
|
||||
} catch (Exception e) {
|
||||
logger.warn("Error updating counting info for resource with ID "
|
||||
+ resource.getID(), e);
|
||||
}
|
||||
logger.info("Profile " + mess.getUniqueID() + " updated");
|
||||
return new UpdateResourceResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a Resource profile identified by the given the resource ID
|
||||
*
|
||||
* @param inputMessage defined into WSDL file
|
||||
* @return RemoveResourceResponse
|
||||
* @throws RemoteException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public RemoveResourceResponse removeResource(RemoveResourceMessage inputMessage) throws RemoteException, GCUBEFault {
|
||||
//logSecurityInfo("removeResource");
|
||||
|
||||
String ID = inputMessage.getUniqueID();
|
||||
String type = inputMessage.getType();
|
||||
logger.info("RemoveResource operation invoked on resource ID=" + ID + ", type=" + type);
|
||||
if (ID == null || ID.compareTo("") == 0) {
|
||||
logger.warn("Resource ID is missing, cannot manage the resource");
|
||||
throw new RemoteException("Resource ID is missing, cannot manage the resource");
|
||||
}
|
||||
|
||||
try {
|
||||
logger.debug("Trying to remove the resource from the IS-IC");
|
||||
new ProfileManager().removeFromISIC(ID, type, ServiceContext.getContext().getScope(), ServiceContext.getContext());
|
||||
logger.info("Resource removed from the IS-IC");
|
||||
} 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 returned an error");
|
||||
}
|
||||
// if the resource is a GHN, remove also the related RIs
|
||||
try {
|
||||
if (type.compareTo(GCUBEHostingNode.TYPE) == 0) {
|
||||
logger.debug("Removing the related RIs");
|
||||
GHN ghn = new GHN(ID);
|
||||
ghn.unregisterHostedRIs(this);
|
||||
logger.debug("Related RIs removed");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while removing RI profiles related to the GHN", e);
|
||||
}
|
||||
|
||||
if (this.isResourceCreated(ID)) {
|
||||
// destroy the resource
|
||||
try {
|
||||
logger.debug("Destroying the local stateful Resoruce");
|
||||
ProfileContext.getContext().getWSHome().remove(ProfileContext.getContext().makeKey(ID));
|
||||
logger.info(" Resource Destroyed");
|
||||
} catch (Exception e) {
|
||||
logger.error("Error removing resource for ID ", e);
|
||||
throw new RemoteException();
|
||||
}
|
||||
try {
|
||||
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>();
|
||||
GCUBEResource resource = ResourceType.valueOf(type).getResourceClass();
|
||||
resource.setID(ID);
|
||||
event.setPayload(resource);
|
||||
ServiceContext.getContext().getTopicProducer().notify(ServiceContext.RegistryTopic.REMOVE, event);
|
||||
updateCounterInfo(ID, ResourceType.valueOf(type),OperationType.destroy, Calendar.getInstance());
|
||||
} catch (Exception e) {
|
||||
logger.warn("Error updating counting info for resource with ID " + ID, e);
|
||||
}
|
||||
}
|
||||
|
||||
return new RemoveResourceResponse();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks 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) {
|
||||
try {
|
||||
return (ProfileResource) ProfileContext.getContext().getWSHome()
|
||||
.find(ProfileContext.getContext().makeKey(id));
|
||||
} catch (Exception e) {
|
||||
logger.debug("A profile with the given id " + id
|
||||
+ " has not been created yet");
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
protected synchronized boolean isResourceCreated(String id) {
|
||||
if (getProfileResource(id) != null)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the RegistryFactoryResource RPs for notification
|
||||
*
|
||||
*
|
||||
* @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,
|
||||
ResourceType resType, OperationType opType, Calendar updateTime)
|
||||
throws Exception {
|
||||
|
||||
RegistryProperty property = new RegistryProperty();
|
||||
property.setUniqueID(ID);
|
||||
property.setOperationType(opType.name());
|
||||
property.setChangeTime(updateTime);
|
||||
// select the type of the resource to update
|
||||
for (Method method : this.getResource().getClass().getDeclaredMethods()) {
|
||||
if (method.getName().contains(resType.name())
|
||||
&& method.getName().contains("set")) {
|
||||
method.invoke(this.getResource(), property);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
this.getResource().store();
|
||||
}
|
||||
|
||||
/**
|
||||
* return the resource
|
||||
*
|
||||
* @return NotifierResource resource
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
* UpdateScopeInProfileMessage
|
||||
* @return String
|
||||
* @throws GCUBEFault
|
||||
* -
|
||||
*/
|
||||
public String updateScopeInProfile(UpdateScopeInProfileMessage message)
|
||||
throws GCUBEFault {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
* RemoveScopeInProfileMessage
|
||||
* @return String
|
||||
* @throws GCUBEFault
|
||||
* -
|
||||
*/
|
||||
public String removeScopeInProfile(RemoveScopeInProfileMessage message)
|
||||
throws GCUBEFault {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
* UpdateStateMessage
|
||||
* @return
|
||||
* @throws GCUBEFault
|
||||
* -
|
||||
*/
|
||||
public String updateState(UpdateStateMessage message) throws GCUBEFault {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GCUBEServiceContext getServiceContext() {
|
||||
return ServiceContext.getContext();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,10 @@ package org.gcube.informationsystem.registry.impl.contexts;
|
|||
|
||||
|
||||
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.GHNContext;
|
||||
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.GCUBEScheduledHandler;
|
||||
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.util.EliminatePoolingThread;
|
||||
import org.gcube.informationsystem.registry.stubs.CreateResourceMessage;
|
||||
import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage;
|
||||
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 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();
|
||||
|
||||
|
|
|
@ -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) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -3,23 +3,17 @@ package org.gcube.informationsystem.registry.impl.state;
|
|||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
|
||||
|
||||
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.state.GCUBEWSResource;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
|
||||
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
|
||||
import org.globus.wsrf.ResourceException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
|
||||
/**
|
||||
* Stateful resource wrapping a {@link GCUBEResource}
|
||||
*
|
||||
|
@ -28,239 +22,232 @@ import org.xml.sax.InputSource;
|
|||
*/
|
||||
public class ProfileResource extends GCUBEWSResource {
|
||||
|
||||
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 static final String ProfileRP="Profile";
|
||||
|
||||
@Override
|
||||
protected String[] getPropertyNames(){
|
||||
return new String[] {ProfileRP};
|
||||
}
|
||||
private static GCUBELog logger = new GCUBELog(ProfileResource.class
|
||||
.getName());
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @throws Exception Exception
|
||||
*/
|
||||
public ProfileResource() throws Exception{};
|
||||
protected GCUBEResource gCubeResource;
|
||||
|
||||
|
||||
/**
|
||||
* initialize the resource
|
||||
* @param params Object
|
||||
* @throws ResourceException if resource is missing
|
||||
*/
|
||||
@Override
|
||||
public void initialise(Object... params) throws ResourceException {
|
||||
GCUBEResource resource = (GCUBEResource) params[0];
|
||||
logger.debug("initializing resource "+resource.getID());
|
||||
Document dom = null;
|
||||
StringWriter writer =new StringWriter();
|
||||
|
||||
try {
|
||||
resource.store(writer);
|
||||
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
|
||||
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(new SimpleTopic(this.generateQName()));
|
||||
synchronized(RegistryFactory.notificationMap) {
|
||||
if (!(RegistryFactory.notificationMap.contains(this.getID()))) {
|
||||
try {
|
||||
notifier = GHNContext.getImplementation(ISNotifier.class);
|
||||
notifier.registerISNotification(this.getEPR(), listQname, ServiceContext.getContext());
|
||||
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
throw new ResourceException(e);
|
||||
}
|
||||
|
||||
RegistryFactory.notificationMap.add(this.getID());
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
protected static final String ProfileRP = "Profile";
|
||||
|
||||
/**
|
||||
* set notification Profile
|
||||
*
|
||||
* @param profile Document
|
||||
*/
|
||||
/*public void setNotificationProfile(Document profile) {
|
||||
this.getResourcePropertySet().get(NotificationProfileRP).clear();
|
||||
this.getResourcePropertySet().get(NotificationProfileRP).add(profile);
|
||||
//this.getPersistenceDelegate().store(this);
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
* get notification Profile
|
||||
*
|
||||
* @return Document profile
|
||||
*/
|
||||
/*public Document getNotificationProfile() {
|
||||
return (Document)this.getResourcePropertySet().get(NotificationProfileRP).get(0);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* set Profile
|
||||
*
|
||||
* @param profile Document
|
||||
*/
|
||||
public void setProfile(Document profile) {
|
||||
this.getResourcePropertySet().get(ProfileRP).clear();
|
||||
this.getResourcePropertySet().get(ProfileRP).add(profile);
|
||||
}
|
||||
|
||||
/**
|
||||
* get Profile
|
||||
*
|
||||
* @return Document profile
|
||||
*/
|
||||
public Document getProfile() {
|
||||
return (Document)this.getResourcePropertySet().get(ProfileRP).get(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the profile has to live or not
|
||||
*
|
||||
* @param GCUBEReosurce resource
|
||||
* @return true/false
|
||||
*/
|
||||
private boolean hasToLive(GCUBEResource resource) {
|
||||
if (resource.getType().compareTo(GCUBEHostingNode.TYPE)==0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Resource QName
|
||||
* @return the Resource QName
|
||||
*/
|
||||
//private QName generateQName() {
|
||||
// return new QName(ProfileContext.getContext().getNamespace(), NotificationProfileRP+this.getID().getValue());
|
||||
//}
|
||||
|
||||
/**
|
||||
* returns the Resource
|
||||
*
|
||||
* @return resource GCUBEReosurce
|
||||
*/
|
||||
public GCUBEResource getGCubeResource() {
|
||||
return this.gCubeResource;
|
||||
}
|
||||
@Override
|
||||
protected String[] getPropertyNames() {
|
||||
return new String[] { ProfileRP };
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the resource
|
||||
* @param resource GCUBEReosurce
|
||||
* Constructor
|
||||
*
|
||||
* @throws Exception
|
||||
* Exception
|
||||
*/
|
||||
public void setGCubeResource(GCUBEResource resource) {
|
||||
this.gCubeResource = resource;
|
||||
}
|
||||
|
||||
|
||||
/** {@inheritDoc}*/
|
||||
@Override
|
||||
public void onRemove() throws ResourceException{
|
||||
super.onRemove();
|
||||
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 {
|
||||
notifier = GHNContext.getImplementation(ISNotifier.class);
|
||||
notifier.unregisterISNotification(this.getEPR(),listQname,ServiceContext.getContext());
|
||||
} catch (ISPublisherException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public ProfileResource() throws Exception {
|
||||
};
|
||||
|
||||
synchronized(RegistryFactory.notificationMap) {
|
||||
RegistryFactory.notificationMap.remove(this.getID());
|
||||
}
|
||||
}*/
|
||||
|
||||
try {
|
||||
publisher.removeWSResource(this,ServiceContext.getContext().getScope());
|
||||
//System.out.println(" "+this.getResourcePropertySet().getScope().get(0));
|
||||
} catch (ISPublisherException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
/**
|
||||
* initialize the resource
|
||||
*
|
||||
* @param params
|
||||
* Object
|
||||
* @throws ResourceException
|
||||
* if resource is missing
|
||||
*/
|
||||
@Override
|
||||
public void initialise(Object... params) throws ResourceException {
|
||||
GCUBEResource resource = (GCUBEResource) params[0];
|
||||
logger.debug("initializing resource " + resource.getID());
|
||||
Document dom = null;
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
try {
|
||||
resource.store(writer);
|
||||
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory
|
||||
.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* updates the resource
|
||||
|
||||
this.setProfile(dom);
|
||||
// this.setNotificationProfile(dom);
|
||||
this.setGCubeResource(resource);
|
||||
|
||||
if (hasToLive(resource))
|
||||
this.setTerminationTime(null);
|
||||
|
||||
/*
|
||||
* if (hasToLive(resource)) { //registration of Topic To IS-Notifier
|
||||
*
|
||||
* @param resource the resource to update
|
||||
* @throws Exception if something goes wrong
|
||||
* listQname.add(new SimpleTopic(this.generateQName()));
|
||||
* synchronized(RegistryFactory.notificationMap) { if
|
||||
* (!(RegistryFactory.notificationMap.contains(this.getID()))) { try {
|
||||
* notifier = GHNContext.getImplementation(ISNotifier.class);
|
||||
* notifier.registerISNotification(this.getEPR(), listQname,
|
||||
* ServiceContext.getContext());
|
||||
*
|
||||
* } catch (Exception e){ e.printStackTrace(); throw new
|
||||
* ResourceException(e); }
|
||||
*
|
||||
* RegistryFactory.notificationMap.add(this.getID()); } } }
|
||||
*/
|
||||
}
|
||||
|
||||
public void updateResource(GCUBEResource resource) throws Exception{
|
||||
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
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);
|
||||
// updates the notification profile too
|
||||
/*if (this.hasToLive(resource))
|
||||
this.setNotificationProfile(dom);
|
||||
*/
|
||||
this.store();
|
||||
}
|
||||
/**
|
||||
* set notification Profile
|
||||
*
|
||||
* @param profile
|
||||
* Document
|
||||
*/
|
||||
/*
|
||||
* public void setNotificationProfile(Document profile) {
|
||||
* this.getResourcePropertySet().get(NotificationProfileRP).clear();
|
||||
* this.getResourcePropertySet().get(NotificationProfileRP).add(profile);
|
||||
* //this.getPersistenceDelegate().store(this); }
|
||||
*/
|
||||
|
||||
/**
|
||||
* get notification Profile
|
||||
*
|
||||
* @return Document profile
|
||||
*/
|
||||
/*
|
||||
* public Document getNotificationProfile() { return
|
||||
* (Document)this.getResourcePropertySet
|
||||
* ().get(NotificationProfileRP).get(0); }
|
||||
*/
|
||||
|
||||
/**
|
||||
* set Profile
|
||||
*
|
||||
* @param profile
|
||||
* Document
|
||||
*/
|
||||
public void setProfile(Document profile) {
|
||||
this.getResourcePropertySet().get(ProfileRP).clear();
|
||||
this.getResourcePropertySet().get(ProfileRP).add(profile);
|
||||
}
|
||||
|
||||
/**
|
||||
* get Profile
|
||||
*
|
||||
* @return Document profile
|
||||
*/
|
||||
public Document getProfile() {
|
||||
return (Document) this.getResourcePropertySet().get(ProfileRP).get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the profile has to live or not
|
||||
*
|
||||
* @param resource the resource
|
||||
* @return true/false
|
||||
*/
|
||||
private boolean hasToLive(GCUBEResource resource) {
|
||||
if (resource.getType().compareTo(GCUBEHostingNode.TYPE) == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Resource QName
|
||||
*
|
||||
* @return the Resource QName
|
||||
*/
|
||||
// private QName generateQName() {
|
||||
// return new QName(ProfileContext.getContext().getNamespace(),
|
||||
// NotificationProfileRP+this.getID().getValue());
|
||||
// }
|
||||
/**
|
||||
* Returns the Resource
|
||||
*
|
||||
* @return the resource
|
||||
*/
|
||||
public GCUBEResource getGCubeResource() {
|
||||
return this.gCubeResource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the resource
|
||||
*
|
||||
* @param resource the resource
|
||||
*/
|
||||
public void setGCubeResource(GCUBEResource resource) {
|
||||
this.gCubeResource = resource;
|
||||
}
|
||||
|
||||
// /** {@inheritDoc}*/
|
||||
// @Override
|
||||
// public void onRemove() throws ResourceException{
|
||||
// super.onRemove();
|
||||
// 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 {
|
||||
// notifier = GHNContext.getImplementation(ISNotifier.class);
|
||||
// notifier.unregisterISNotification(this.getEPR(),listQname,ServiceContext.getContext());
|
||||
// } catch (ISPublisherException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// synchronized(RegistryFactory.notificationMap) {
|
||||
// RegistryFactory.notificationMap.remove(this.getID());
|
||||
// }
|
||||
// }*/
|
||||
//
|
||||
// try {
|
||||
// publisher.removeWSResource(this,ServiceContext.getContext().getScope());
|
||||
// //System.out.println(" "+this.getResourcePropertySet().getScope().get(0));
|
||||
// } catch (ISPublisherException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* Updates the resource
|
||||
*
|
||||
* @param resource the resource to update
|
||||
* @throws Exception if something goes wrong
|
||||
*/
|
||||
public void updateResource(GCUBEResource resource) throws Exception {
|
||||
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
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);
|
||||
// updates the notification profile too
|
||||
/*
|
||||
* if (this.hasToLive(resource)) this.setNotificationProfile(dom);
|
||||
*/
|
||||
this.store();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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");
|
||||
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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) {}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
java -cp ./lib/org.gcube.informationsystem.registry.stubs.jar:$CLASSPATH org/gcube/informationsystem/registry/stubs/testsuite/RegistryRegistrationTest $1 $2 $3 $4
|
|
@ -1 +0,0 @@
|
|||
java -cp ./lib/org.gcube.informationsystem.registry.jar:$CLASSPATH org/gcube/informationsystem/registry/stubs/testsuite/RegistryRemoveTest $1 $2 $3 $4
|
Loading…
Reference in New Issue