Integration with the IS-Notifier and several fixings

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@34682 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Manuele Simi 2011-02-04 23:05:47 +00:00
parent 91147638bd
commit 99ee7ae64d
7 changed files with 98 additions and 260 deletions

View File

@ -6,23 +6,6 @@
<environment name="configDir" value="@config.dir@" type="java.lang.String" <environment name="configDir" value="@config.dir@" type="java.lang.String"
override="false" /> override="false" />
<!--
GCUBEResources that are not considered temporary, i.e. they are not automatically
destroyed after the 'temporaryResourceLifetimeInMs' period
-->
<environment name="livingResourceTypes" value="GHN,RunningInstance"
type="java.lang.String" override="false" />
<!--
Lifetime for temporary resources, after this period temporary
resources are destroyed
-->
<environment name="temporaryResourceLifetimeInMs" value="480000"
type="java.lang.Long" override="false" />
<environment name="temporaryResourceSweeperIntervalInMs"
value="480000" type="java.lang.Long" override="false" />
<!-- <!--
<environment name="startScopes" value="" type="java.lang.String" <environment name="startScopes" value="" type="java.lang.String"
override="false" /> override="false" />

View File

@ -1,7 +1,6 @@
package org.gcube.informationsystem.registry.impl.contexts; package org.gcube.informationsystem.registry.impl.contexts;
import java.io.StringWriter;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -12,21 +11,13 @@ import static org.gcube.common.core.contexts.GHNContext.Mode;
import org.gcube.common.core.informationsystem.client.ISClient; import org.gcube.common.core.informationsystem.client.ISClient;
import org.gcube.common.core.informationsystem.client.queries.GCUBERIQuery; import org.gcube.common.core.informationsystem.client.queries.GCUBERIQuery;
import org.gcube.common.core.informationsystem.publisher.ISLocalPublisher; import org.gcube.common.core.informationsystem.publisher.ISLocalPublisher;
import org.gcube.common.core.informationsystem.publisher.ISLocalPublisher.LocalProfileConsumer;
import org.gcube.common.core.resources.GCUBEResource; import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.utils.events.GCUBEProducer; import org.gcube.common.core.utils.events.GCUBEProducer;
import org.gcube.common.core.utils.events.GCUBETopic; 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.common.core.utils.handlers.GCUBEScheduledHandler;
import org.gcube.informationsystem.registry.impl.local.LocalProfileConsumerImpl; import org.gcube.informationsystem.registry.impl.local.LocalProfileConsumerImpl;
import org.gcube.informationsystem.registry.impl.porttypes.RegistryFactory;
import org.gcube.informationsystem.registry.impl.porttypes.ResourceRegistration;
import org.gcube.informationsystem.registry.impl.resourcemanagement.EliminatePoolingThread; import org.gcube.informationsystem.registry.impl.resourcemanagement.EliminatePoolingThread;
import org.gcube.informationsystem.registry.impl.state.RegistryFactoryResource;
import org.gcube.informationsystem.registry.stubs.resourceregistration.CreateMessage;
import org.gcube.informationsystem.registry.stubs.resourceregistration.RemoveMessage;
import org.gcube.informationsystem.registry.stubs.resourceregistration.UpdateMessage;
/** /**
@ -68,9 +59,9 @@ public class ServiceContext extends GCUBEServiceContext {
@Override @Override
protected boolean repeat(Exception exception, int exceptionCount) { protected boolean repeat(Exception exception, int exceptionCount) {
if (exception!=null) { if (exception!=null) {
logger.warn("Failed to create the notification resource (attempt "+exceptionCount+" out of 20)",exception); ServiceContext.this.logger.warn("Failed to create the notification resource (attempt "+exceptionCount+" out of 20)",exception);
if (exceptionCount >= 20) { if (exceptionCount >= 20) {
logger.error("Max attempts reached, no more chance to register the notification resource"); ServiceContext.this.logger.error("Max attempts reached, no more chance to register the notification resource");
return false; return false;
} else } else
return true; return true;
@ -109,7 +100,6 @@ public class ServiceContext extends GCUBEServiceContext {
return topicProducer; return topicProducer;
} }
@SuppressWarnings("unchecked")
@Override @Override
protected void onReady() throws Exception { protected void onReady() throws Exception {
@ -117,36 +107,15 @@ public class ServiceContext extends GCUBEServiceContext {
if (GHNContext.getContext().getMode() == Mode.ROOT) if (GHNContext.getContext().getMode() == Mode.ROOT)
GHNContext.getContext().setMode(Mode.CONNECTED); GHNContext.getContext().setMode(Mode.CONNECTED);
//creates the single RegistryResource used to raise notifications about profiles' changes /*NotificationResourceScheduler scheduler = new NotificationResourceScheduler(20, GCUBEScheduledHandler.Mode.LAZY);
logger.info("Scheduling IS-Registry notification resource...");
for (GCUBEScope scope: ServiceContext.getContext().getInstance().getScopes().values()){
EliminatePoolingThread ept= new EliminatePoolingThread();
ServiceContext.getContext().setScope(ept, scope);
ept.start();
threadTable.put(scope.getName(), ept);
}
NotificationResourceScheduler scheduler = new NotificationResourceScheduler(20, GCUBEScheduledHandler.Mode.LAZY);
scheduler.setScheduled(new GCUBEHandler(){ scheduler.setScheduled(new GCUBEHandler(){
@Override @Override
public void run() throws Exception { public void run() throws Exception {
RegistryFactory.initialize();
try {
for (GCUBEScope scope: ServiceContext.getContext().getInstance().getScopes().values())
{
ServiceContext.getContext().setScope(scope);
RegistryFactoryResource resource = (RegistryFactoryResource) FactoryContext.getContext().getWSHome().create(FactoryContext.getContext().makeKey(RegistryFactory.NOTIFICATOR_RESOURCE_KEY));
resource.store();
}
} catch (Exception e) {
logger.error("Failed to create the resource", e);
}
} }
}); });
scheduler.run(); scheduler.run();*/
this.subscribeToLocalRegistrationEvents(); this.subscribeToLocalRegistrationEvents();
} }
@ -166,7 +135,7 @@ public class ServiceContext extends GCUBEServiceContext {
*/ */
private void subscribeToLocalRegistrationEvents() throws Exception{ private void subscribeToLocalRegistrationEvents() throws Exception{
ISLocalPublisher pub = GHNContext.getImplementation(ISLocalPublisher.class); ISLocalPublisher pub = GHNContext.getImplementation(ISLocalPublisher.class);
logger.debug("Subscribing IS-Registry to local profile events"); logger.debug("Subscribing IS-Registry for local profiles' events");
pub.subscribeLocalProfileEvents(new LocalProfileConsumerImpl()); pub.subscribeLocalProfileEvents(new LocalProfileConsumerImpl());
} }

View File

@ -0,0 +1,18 @@
package org.gcube.informationsystem.registry.impl.local;
import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.utils.events.GCUBEEvent;
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext.RegistryTopic;
public class LocalNotifier {
@SuppressWarnings("unchecked")
public static void notifyEvent(GCUBEResource resource, RegistryTopic topic){
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>();
event.setPayload(resource);
ServiceContext.getContext().getTopicProducer().notify(topic, event);
}
}

View File

@ -14,13 +14,13 @@ import org.gcube.informationsystem.registry.stubs.resourceregistration.UpdateMes
public class LocalProfileConsumerImpl extends LocalProfileConsumer { public class LocalProfileConsumerImpl extends LocalProfileConsumer {
private final static GCUBELog logger = new GCUBELog(LocalProfileConsumerImpl.class); private final GCUBELog logger = new GCUBELog(LocalProfileConsumerImpl.class);
/* (non-Javadoc) /* (non-Javadoc)
* @see org.gcube.common.core.informationsystem.publisher.ISLocalPublisher.LocalProfileConsumer#onProfileRegistered(org.gcube.common.core.resources.GCUBEResource) * @see org.gcube.common.core.informationsystem.publisher.ISLocalPublisher.LocalProfileConsumer#onProfileRegistered(org.gcube.common.core.resources.GCUBEResource)
*/ */
@Override @Override
protected void onProfileRegistered(final GCUBEResource resource, final GCUBEScope scope) { protected void onProfileRegistered(final GCUBEResource resource, final GCUBEScope scope) {
logger.debug("onProfileRegistered event received in scope " + scope ); LocalProfileConsumerImpl.this.logger.debug("onProfileRegistered event received in scope " + scope );
new Thread() { new Thread() {
@Override @Override
public void run() { public void run() {
@ -34,10 +34,10 @@ public class LocalProfileConsumerImpl extends LocalProfileConsumer {
crm.setProfile(writer.toString()); crm.setProfile(writer.toString());
crm.setType(resource.getType()); crm.setType(resource.getType());
//crm.setScopes(new String[] {scope.toString()}); //crm.setScopes(new String[] {scope.toString()});
logger.debug("Creating resource "); LocalProfileConsumerImpl.this.logger.debug("Creating resource ");
factory.create(crm); factory.create(crm);
} catch (Exception e) { } catch (Exception e) {
logger.error("cannot handle the create resource event"+e); LocalProfileConsumerImpl.this.logger.error("cannot handle the create resource event"+e);
} }
} }

View File

@ -7,33 +7,24 @@ import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.List;
import org.apache.axis.components.uuid.UUIDGen; import org.apache.axis.components.uuid.UUIDGen;
import org.apache.axis.components.uuid.UUIDGenFactory; import org.apache.axis.components.uuid.UUIDGenFactory;
import org.gcube.common.core.contexts.GCUBEServiceContext; import org.gcube.common.core.contexts.GCUBEServiceContext;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.faults.GCUBEFault; import org.gcube.common.core.faults.GCUBEFault;
import org.gcube.common.core.informationsystem.publisher.ISResourcePublisher;
import org.gcube.common.core.porttypes.GCUBEPortType; import org.gcube.common.core.porttypes.GCUBEPortType;
import org.gcube.common.core.resources.GCUBEHostingNode;
import org.gcube.common.core.resources.GCUBEResource; import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.scope.GCUBEScope; import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.state.GCUBEWSResourceKey;
import org.gcube.common.core.utils.events.GCUBEEvent;
import org.gcube.common.core.utils.logging.GCUBELog; import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.contexts.FactoryContext; import org.gcube.informationsystem.registry.impl.contexts.FactoryContext;
import org.gcube.informationsystem.registry.impl.contexts.ProfileContext; import org.gcube.informationsystem.registry.impl.contexts.ProfileContext;
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext; import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
import org.gcube.informationsystem.registry.impl.filters.FilterManager; import org.gcube.informationsystem.registry.impl.contexts.ServiceContext.RegistryTopic;
import org.gcube.informationsystem.registry.impl.filters.FilterExecutor.InvalidFilterException; import org.gcube.informationsystem.registry.impl.local.LocalNotifier;
import org.gcube.informationsystem.registry.impl.profilemanagement.GHN;
import org.gcube.informationsystem.registry.impl.resourcemanagement.Pair;
import org.gcube.informationsystem.registry.impl.state.ProfileResource; import org.gcube.informationsystem.registry.impl.state.ProfileResource;
import org.gcube.informationsystem.registry.impl.state.RegistryFactoryResource; import org.gcube.informationsystem.registry.impl.state.RegistryFactoryResource;
import org.gcube.informationsystem.registry.impl.state.Definitions.OperationType;
import org.gcube.informationsystem.registry.stubs.CreateResourceMessage; import org.gcube.informationsystem.registry.stubs.CreateResourceMessage;
import org.gcube.informationsystem.registry.stubs.ProfileAlreadyRegisteredFault; import org.gcube.informationsystem.registry.stubs.ProfileAlreadyRegisteredFault;
import org.gcube.informationsystem.registry.stubs.RegistryProperty; import org.gcube.informationsystem.registry.stubs.RegistryProperty;
@ -54,48 +45,41 @@ import static org.gcube.informationsystem.registry.impl.state.Definitions.Resour
*/ */
public class RegistryFactory extends GCUBEPortType { public class RegistryFactory extends GCUBEPortType {
/** Name of temporaryResourceLifetimeInMs JNDI environment. */
private static final String LIFETIME_JNDI_NAME = "temporaryResourceLifetimeInMs";
/** Name of Living Resource Types JNDI environment. */
private static final String LIVINGTYPES_JNDI_NAME = "livingResourceTypes";
/**
* Lifetime of temporary resources
*/
private static long temporaryResourceLifetimeInMs = 120000;
/**
* Lifetime of temporary resources
*/
private static List<String> livingResourceTypes;
/** The UUIDGen */ /** The UUIDGen */
private static final UUIDGen uuidgen = UUIDGenFactory.getUUIDGen(); private static final UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
/** Object logger */ /** Object logger */
protected final GCUBELog logger = new GCUBELog(RegistryFactory.class); protected static final GCUBELog logger = new GCUBELog(RegistryFactory.class);
enum OperationType {
create, update, destroy
};
/** the key used to label the Factory Resource */ /** the key used to label the Factory Resource */
public static final String NOTIFICATOR_RESOURCE_KEY = "RegistryResource"; public static final String NOTIFICATOR_RESOURCE_KEY = "RegistryResource";
private static Integer resourceCounter = new Integer(0); private static RegistryFactoryResource singletonResource = null;
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
protected void onInitialisation() throws Exception { protected void onInitialisation() throws Exception {
temporaryResourceLifetimeInMs = (Long) ServiceContext.getContext().getProperty(LIFETIME_JNDI_NAME);
logger.info("Temporary resources lifetime = "+ temporaryResourceLifetimeInMs); if (singletonResource != null)
return;//cannot create the state twice
logger.info("Initialising the factory state...");
try { try {
temporaryResourceLifetimeInMs = (Long) ServiceContext.getContext().getProperty(LIFETIME_JNDI_NAME); for (GCUBEScope scope: ServiceContext.getContext().getInstance().getScopes().values()){
livingResourceTypes = Arrays.asList(((String)ServiceContext.getContext().getProperty(LIVINGTYPES_JNDI_NAME)).split(",")); logger.info("Creating the notification resource " + RegistryFactory.NOTIFICATOR_RESOURCE_KEY + " within the scope " + scope.getName());
} catch (Exception e) {livingResourceTypes = new ArrayList<String>();} ServiceContext.getContext().setScope(scope);
singletonResource = (RegistryFactoryResource) FactoryContext.getContext().getWSHome().create(FactoryContext.getContext().makeKey(RegistryFactory.NOTIFICATOR_RESOURCE_KEY));
singletonResource.store();
}
} catch (Exception e) {
logger.error("Failed to create the resource", e);
throw e;
}
} }
/** /**
@ -109,7 +93,6 @@ public class RegistryFactory extends GCUBEPortType {
* @throws RemoteException * @throws RemoteException
* @throws ProfileAlreadyRegisteredFault * @throws ProfileAlreadyRegisteredFault
*/ */
@SuppressWarnings("unchecked")
public String createResource(CreateResourceMessage mess) public String createResource(CreateResourceMessage mess)
throws SchemaValidationFault, RemoteException, ProfileAlreadyRegisteredFault, ResourceNotAcceptedFault { throws SchemaValidationFault, RemoteException, ProfileAlreadyRegisteredFault, ResourceNotAcceptedFault {
@ -127,7 +110,6 @@ public class RegistryFactory extends GCUBEPortType {
try { try {
resource = ResourceType.valueOf(mess.getType()).getResourceClass(); resource = ResourceType.valueOf(mess.getType()).getResourceClass();
resource.load(new BufferedReader(new InputStreamReader( new ByteArrayInputStream(profile.getBytes("UTF-8")),"UTF-8"))); resource.load(new BufferedReader(new InputStreamReader( new ByteArrayInputStream(profile.getBytes("UTF-8")),"UTF-8")));
// the parse Profile class allows to extract from profiles // the parse Profile class allows to extract from profiles
@ -150,58 +132,16 @@ public class RegistryFactory extends GCUBEPortType {
logger.error("Error trying to load profile", ex); logger.error("Error trying to load profile", ex);
throw new SchemaValidationFault(); throw new SchemaValidationFault();
} }
// apply resource filter
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.debug("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("Creating the stateful resource N."+ ++resourceCounter + " for " + resource.getID());
GCUBEWSResourceKey key = ProfileContext.getContext().makeKey(resource.getID());
logger.trace("Resource key is " + key);
ProfileResource presource = (ProfileResource) ProfileContext.getContext().getWSHome().create(key, resource);
presource.store();
// Deleting the WSResource created if != from GHN || RI
if (! this.isLivingResource(resource))
this.scheduleForLazyDeletion(presource);
} catch (Exception ex) {
String msg = "Error creating Resource " + resource.getID();
logger.error(msg, ex);
throw new RemoteException(msg);
}
try { try {
updateCounterInfo(resource.getID(), ResourceType.valueOf( updateCounterInfo(resource.getID(), ResourceType.valueOf(
mess.getType()), OperationType.create, mess.getType()), OperationType.create,
Calendar.getInstance(), mess.getProfile()); Calendar.getInstance(), mess.getProfile());
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>(); LocalNotifier.notifyEvent(resource, RegistryTopic.CREATE);
event.setPayload(resource);
ServiceContext.getContext().getTopicProducer().notify(ServiceContext.RegistryTopic.CREATE, event);
} catch (Exception e) { } catch (Exception e) {
logger.warn("Error updating Counting info for resource with ID " + resource.getID(), e); logger.warn("Error updating Counting info for resource with ID " + resource.getID(), e);
} }
}
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
try { try {
@ -216,30 +156,6 @@ public class RegistryFactory extends GCUBEPortType {
} }
/**
* Schedules a resource for a delayed deletion
*
* @param presource the resource to delete
*/
private void scheduleForLazyDeletion(ProfileResource presource) {
long timestamp = System.currentTimeMillis() + temporaryResourceLifetimeInMs;
GCUBEScope scope = ServiceContext.getContext().getScope().getType() ==
GCUBEScope.Type.VRE ? ServiceContext.getContext().getScope().getEnclosingScope()
: ServiceContext.getContext().getScope();
Pair c = new Pair(timestamp, presource);
if (!ServiceContext.threadTable.get(scope.getName()).getStack().contains(c)) {
ServiceContext.threadTable.get(scope.getName()).getStack().add(c);
logger.trace("Adding resource to EliminatePoolingThread "+ presource.getGCubeResource().getID());
} else { // add more life to the resource by further delaying its
// deletion
int index = ServiceContext.threadTable.get(scope.getName()).getStack().indexOf(c);
ServiceContext.threadTable.get(scope.getName()).getStack().get(index).lifetime = timestamp + temporaryResourceLifetimeInMs;
}
}
/** /**
* Updates a {@link GCUBEResource} * Updates a {@link GCUBEResource}
* *
@ -249,7 +165,7 @@ public class RegistryFactory extends GCUBEPortType {
* @throws SchemaValidationException if the string serialization of the resource is not valid * @throws SchemaValidationException if the string serialization of the resource is not valid
* @throws ResourceNotAcceptedFault it the resource is rejected when evaluating the resources' filters * @throws ResourceNotAcceptedFault it the resource is rejected when evaluating the resources' filters
*/ */
@SuppressWarnings("unchecked")
public UpdateResourceResponse updateResource(UpdateResourceMessage mess) public UpdateResourceResponse updateResource(UpdateResourceMessage mess)
throws RemoteException, SchemaValidationFault, ResourceNotAcceptedFault, GCUBEFault { throws RemoteException, SchemaValidationFault, ResourceNotAcceptedFault, GCUBEFault {
@ -266,47 +182,18 @@ public class RegistryFactory extends GCUBEPortType {
logger.debug("Profile missing"); logger.debug("Profile missing");
throw new RemoteException("Error, profile missing"); throw new RemoteException("Error, profile missing");
} }
// check if the profile exist
if (!isResourceCreated(ID)) {
CreateResourceMessage input = new CreateResourceMessage();
input.setProfile(xmlProfile);
input.setType(mess.getType());
this.createResource(input);
return new UpdateResourceResponse();
}
try { try {
resource = ResourceType.valueOf(mess.getType()).getResourceClass(); resource = ResourceType.valueOf(mess.getType()).getResourceClass();
resource.load(new StringReader(xmlProfile)); resource.load(new StringReader(xmlProfile));
// apply resource filter
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 != from GHN || RI
if (! this.isLivingResource(resource))
this.scheduleForLazyDeletion(presource);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error updating profile for ID " + e); logger.error("Error updating profile for ID " + e);
throw new RemoteException(e.toString()); throw new RemoteException(e.toString());
} }
try { try {
this.updateCounterInfo(ID, ResourceType.valueOf(mess.getType()), updateCounterInfo(ID, ResourceType.valueOf(mess.getType()),
OperationType.update, Calendar.getInstance(), xmlProfile); OperationType.update, Calendar.getInstance(), xmlProfile);
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>(); LocalNotifier.notifyEvent(resource, RegistryTopic.UPDATE);
event.setPayload(resource);
ServiceContext.getContext().getTopicProducer().notify(ServiceContext.RegistryTopic.UPDATE, event);
} catch (Exception e) { } catch (Exception e) {
logger.warn("Error while updating the counting info for resource with ID " + resource.getID(), e); logger.warn("Error while updating the counting info for resource with ID " + resource.getID(), e);
} }
@ -321,7 +208,7 @@ public class RegistryFactory extends GCUBEPortType {
* @return RemoveResourceResponse * @return RemoveResourceResponse
* @throws RemoteException * @throws RemoteException
*/ */
@SuppressWarnings("unchecked")
public RemoveResourceResponse removeResource( public RemoveResourceResponse removeResource(
RemoveResourceMessage inputMessage) throws RemoteException, GCUBEFault { RemoveResourceMessage inputMessage) throws RemoteException, GCUBEFault {
@ -333,49 +220,16 @@ public class RegistryFactory extends GCUBEPortType {
throw new RemoteException("Resource ID is missing, cannot manage the resource"); throw new RemoteException("Resource ID is missing, cannot manage the resource");
} }
try { try {
logger.debug("Trying to remove the resource from the IS-IC");
ISResourcePublisher publisher = GHNContext.getImplementation(ISResourcePublisher.class);
publisher.remove(ID, type, ServiceContext.getContext().getScope(), ServiceContext.getContext());
logger.debug("Resource " + ID+ " successfully removed");
} catch (Exception e) {
logger.error("Unable to remove the resource " + ID, e);
throw new GCUBEFault();
}
// 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(); GCUBEResource resource = ResourceType.valueOf(type).getResourceClass();
resource.setID(ID); resource.setID(ID);
event.setPayload(resource); LocalNotifier.notifyEvent(resource, RegistryTopic.REMOVE);
ServiceContext.getContext().getTopicProducer().notify(ServiceContext.RegistryTopic.REMOVE, event);
updateCounterInfo(ID, ResourceType.valueOf(type),OperationType.destroy, Calendar.getInstance(), null); updateCounterInfo(ID, ResourceType.valueOf(type),OperationType.destroy, Calendar.getInstance(), null);
} catch (Exception e) { } catch (Exception e) {
logger.warn( logger.warn(
"Error updating counting info for resource with ID " "Error updating counting info for resource with ID "
+ ID, e); + ID, e);
} }
} //}
return new RemoveResourceResponse(); return new RemoveResourceResponse();
@ -420,25 +274,26 @@ public class RegistryFactory extends GCUBEPortType {
* @param updateTime the last operation Time * @param updateTime the last operation Time
* @throws Exception if the update fails * @throws Exception if the update fails
*/ */
private synchronized void updateCounterInfo(String ID, protected static synchronized void updateCounterInfo(String ID,
ResourceType resType, OperationType opType, Calendar updateTime, ResourceType resType, OperationType opType, Calendar updateTime,
String profile) throws Exception { String profile) throws Exception {
//return;
RegistryProperty property = new RegistryProperty(); RegistryProperty property = new RegistryProperty();
property.setUniqueID(ID); property.setUniqueID(ID);
property.setProfile(profile); property.setProfile(profile);
property.setOperationType(opType.name()); property.setOperationType(opType.name());
property.setChangeTime(updateTime); property.setChangeTime(updateTime);
// select the type of the resource to update // select the type of the resource to update
for (Method method : this.getResource().getClass().getDeclaredMethods()) { logger.trace("Notifying about resource " + ID +", event: " + opType);
for (Method method : getResource().getClass().getDeclaredMethods()) {
if (method.getName().contains(resType.name()) if (method.getName().contains(resType.name())
&& method.getName().contains("set")) { && method.getName().contains("set")) {
method.invoke(this.getResource(), property); method.invoke(getResource(), property);
break; break;
} }
} }
this.getResource().store(); getResource().store();
} }
/** /**
@ -448,7 +303,10 @@ public class RegistryFactory extends GCUBEPortType {
* @throws RemoteException if the stateful resource of the factory cannot be found in the home * @throws RemoteException if the stateful resource of the factory cannot be found in the home
* *
*/ */
private RegistryFactoryResource getResource() throws RemoteException { private static RegistryFactoryResource getResource() throws RemoteException {
if (singletonResource != null)
return singletonResource;
Object resource = null; Object resource = null;
try { try {
resource = FactoryContext.getContext().getWSHome().find( resource = FactoryContext.getContext().getWSHome().find(
@ -461,18 +319,6 @@ public class RegistryFactory extends GCUBEPortType {
return factoryResource; return factoryResource;
} }
/**
* Decides whether the given resource is a living resource.
*
* Living resources are those resources that are not automatically destroyed because they are updated regularly.
*
* @param resource the resource to check
* @return <tt>true</tt> if the given resource is a living resource, <tt>false</tt> otherwise
*/
private boolean isLivingResource(GCUBEResource resource) {
return (livingResourceTypes.contains(resource.getType()))? true : false;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View File

@ -4,6 +4,7 @@ import java.io.BufferedReader;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.util.Calendar;
import org.apache.axis.components.uuid.UUIDGen; import org.apache.axis.components.uuid.UUIDGen;
import org.apache.axis.components.uuid.UUIDGenFactory; import org.apache.axis.components.uuid.UUIDGenFactory;
@ -15,9 +16,12 @@ import org.gcube.common.core.resources.GCUBEHostingNode;
import org.gcube.common.core.resources.GCUBEResource; import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.utils.logging.GCUBELog; import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext; import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext.RegistryTopic;
import org.gcube.informationsystem.registry.impl.filters.FilterManager; import org.gcube.informationsystem.registry.impl.filters.FilterManager;
import org.gcube.informationsystem.registry.impl.filters.FilterExecutor.InvalidFilterException; import org.gcube.informationsystem.registry.impl.filters.FilterExecutor.InvalidFilterException;
import org.gcube.informationsystem.registry.impl.local.LocalNotifier;
import org.gcube.informationsystem.registry.impl.profilemanagement.GHN; import org.gcube.informationsystem.registry.impl.profilemanagement.GHN;
import org.gcube.informationsystem.registry.impl.state.Definitions.OperationType;
import org.gcube.informationsystem.registry.impl.state.Definitions.ResourceType; import org.gcube.informationsystem.registry.impl.state.Definitions.ResourceType;
import org.gcube.informationsystem.registry.stubs.resourceregistration.CreateFault; import org.gcube.informationsystem.registry.stubs.resourceregistration.CreateFault;
import org.gcube.informationsystem.registry.stubs.resourceregistration.CreateMessage; import org.gcube.informationsystem.registry.stubs.resourceregistration.CreateMessage;
@ -65,6 +69,11 @@ public class ResourceRegistration extends GCUBEPortType {
ISResourcePublisher publisher = GHNContext.getImplementation(ISResourcePublisher.class); ISResourcePublisher publisher = GHNContext.getImplementation(ISResourcePublisher.class);
publisher.register(resource, ServiceContext.getContext().getScope(), ServiceContext.getContext()); publisher.register(resource, ServiceContext.getContext().getScope(), ServiceContext.getContext());
logger.debug("Resource " + resource.getID() + " successfully created"); logger.debug("Resource " + resource.getID() + " successfully created");
//let the notifiers know
LocalNotifier.notifyEvent(resource, RegistryTopic.CREATE);
RegistryFactory.updateCounterInfo(resource.getID(), ResourceType.valueOf(
message.getType()), OperationType.create,
Calendar.getInstance(), message.getProfile());
} catch (Exception e) { } catch (Exception e) {
logger.error("Unable to register the resource", e); logger.error("Unable to register the resource", e);
throw new CreateFault(); throw new CreateFault();
@ -93,6 +102,9 @@ public class ResourceRegistration extends GCUBEPortType {
ISResourcePublisher publisher = GHNContext.getImplementation(ISResourcePublisher.class); ISResourcePublisher publisher = GHNContext.getImplementation(ISResourcePublisher.class);
publisher.register(resource, ServiceContext.getContext().getScope(), ServiceContext.getContext()); publisher.register(resource, ServiceContext.getContext().getScope(), ServiceContext.getContext());
logger.debug("Resource " + resource.getID() + " successfully updated"); logger.debug("Resource " + resource.getID() + " successfully updated");
LocalNotifier.notifyEvent(resource, RegistryTopic.UPDATE);
RegistryFactory.updateCounterInfo(resource.getID(), ResourceType.valueOf(message.getType()),
OperationType.update, Calendar.getInstance(), message.getXmlProfile());
} catch (Exception e) { } catch (Exception e) {
logger.error("Unable to update the resource", e); logger.error("Unable to update the resource", e);
throw new UpdateFault(); throw new UpdateFault();
@ -120,6 +132,11 @@ public class ResourceRegistration extends GCUBEPortType {
ISResourcePublisher publisher = GHNContext.getImplementation(ISResourcePublisher.class); ISResourcePublisher publisher = GHNContext.getImplementation(ISResourcePublisher.class);
publisher.remove(ID, type, ServiceContext.getContext().getScope(), ServiceContext.getContext()); publisher.remove(ID, type, ServiceContext.getContext().getScope(), ServiceContext.getContext());
logger.debug("Resource " + ID+ " successfully removed"); logger.debug("Resource " + ID+ " successfully removed");
//let the notifiers know
GCUBEResource resource = ResourceType.valueOf(type).getResourceClass();
resource.setID(ID);
LocalNotifier.notifyEvent(resource, RegistryTopic.REMOVE);
RegistryFactory.updateCounterInfo(ID, ResourceType.valueOf(type),OperationType.destroy, Calendar.getInstance(), null);
} catch (Exception e) { } catch (Exception e) {
logger.error("Unable to remove the resource " + ID, e); logger.error("Unable to remove the resource " + ID, e);
throw new UpdateFault(); throw new UpdateFault();

View File

@ -42,6 +42,11 @@ public class Definitions {
}; };
public static enum OperationType {
create, update, destroy
};
} }