Updaters for gHNs and RIs
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@36550 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
f328250842
commit
a68073786e
|
@ -11,9 +11,12 @@ import org.gcube.common.core.utils.events.GCUBEProducer;
|
|||
import org.gcube.common.core.utils.events.GCUBETopic;
|
||||
import org.gcube.common.core.utils.handlers.GCUBEScheduledHandler;
|
||||
import org.gcube.informationsystem.registry.impl.local.LocalProfileConsumerImpl;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.purging.AvailablePurgers;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.purging.GHNPurger;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.purging.RIPurger;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.remove.AvailablePurgers;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.remove.GHNPurger;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.remove.RIPurger;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.update.AvailableUpdaters;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.update.GHNUpdater;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.update.RIUpdater;
|
||||
|
||||
|
||||
|
||||
|
@ -105,6 +108,10 @@ public class ServiceContext extends GCUBEServiceContext {
|
|||
//register purgers for GCUBEResources
|
||||
AvailablePurgers.register(new GHNPurger());
|
||||
AvailablePurgers.register(new RIPurger());
|
||||
|
||||
//register updaers for GCUBEResources
|
||||
AvailableUpdaters.register(new GHNUpdater());
|
||||
AvailableUpdaters.register(new RIUpdater());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -10,8 +10,10 @@ import org.gcube.common.core.utils.logging.GCUBELog;
|
|||
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
|
||||
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext.RegistryTopic;
|
||||
import org.gcube.informationsystem.registry.impl.local.LocalNotifier;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.purging.AvailablePurgers;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.purging.Purger;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.remove.AvailablePurgers;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.remove.Purger;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.update.AvailableUpdaters;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.update.Updater;
|
||||
import org.gcube.informationsystem.registry.impl.state.Definitions.OperationType;
|
||||
import org.gcube.informationsystem.registry.impl.state.Definitions.ResourceMappings;
|
||||
|
||||
|
@ -23,6 +25,18 @@ public class LocalResourceRegistration {
|
|||
ISResourcePublisher publisher = GHNContext.getImplementation(ISResourcePublisher.class);
|
||||
publisher.register(resource, ServiceContext.getContext().getScope(), ServiceContext.getContext());
|
||||
logger.debug("Resource " + resource.getID() + " successfully created");
|
||||
logger.trace("Looking for updater for "+ resource.getType());
|
||||
Updater<?> updater = AvailableUpdaters.getPurger(resource.getType());
|
||||
if (updater != null) {
|
||||
try {
|
||||
logger.debug("Applying updater for " + resource.getType());
|
||||
updater.update(resource.getClass().cast(resource), ServiceContext.getContext().getScope());
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while updating the profiles related to the resource", e);
|
||||
}
|
||||
} else
|
||||
logger.trace("No updater found");
|
||||
|
||||
//let the notifiers know
|
||||
LocalNotifier.notifyEvent(resource, RegistryTopic.CREATE);
|
||||
StringWriter writer = new StringWriter();
|
||||
|
@ -64,6 +78,17 @@ public class LocalResourceRegistration {
|
|||
ISResourcePublisher publisher = GHNContext.getImplementation(ISResourcePublisher.class);
|
||||
publisher.register(resource, ServiceContext.getContext().getScope(), ServiceContext.getContext());
|
||||
logger.debug("Resource " + resource.getID() + " successfully updated");
|
||||
logger.trace("Looking for updater for "+ resource.getType());
|
||||
Updater<?> updater = AvailableUpdaters.getPurger(resource.getType());
|
||||
if (updater != null) {
|
||||
try {
|
||||
logger.debug("Applying updater for " + resource.getType());
|
||||
updater.update(resource.getClass().cast(resource), ServiceContext.getContext().getScope());
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while updating the profiles related to the resource", e);
|
||||
}
|
||||
} else
|
||||
logger.trace("No updater found");
|
||||
LocalNotifier.notifyEvent(resource, RegistryTopic.UPDATE);
|
||||
StringWriter writer = new StringWriter();
|
||||
resource.store(writer);
|
||||
|
|
|
@ -4,27 +4,16 @@ import java.io.BufferedReader;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.apache.axis.components.uuid.UUIDGen;
|
||||
import org.apache.axis.components.uuid.UUIDGenFactory;
|
||||
import org.gcube.common.core.contexts.GCUBEServiceContext;
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.informationsystem.publisher.ISPublisherException;
|
||||
import org.gcube.common.core.informationsystem.publisher.ISResourcePublisher;
|
||||
|
||||
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.utils.logging.GCUBELog;
|
||||
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
|
||||
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext.RegistryTopic;
|
||||
import org.gcube.informationsystem.registry.impl.local.LocalNotifier;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.purging.AvailablePurgers;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.purging.GHNPurger;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.purging.Purger;
|
||||
import org.gcube.informationsystem.registry.impl.preprocessing.filters.FilterManager;
|
||||
import org.gcube.informationsystem.registry.impl.preprocessing.filters.FilterExecutor.InvalidFilterException;
|
||||
import org.gcube.informationsystem.registry.impl.state.Definitions.OperationType;
|
||||
import org.gcube.informationsystem.registry.impl.state.Definitions.ResourceMappings;
|
||||
import org.gcube.informationsystem.registry.stubs.resourceregistration.CreateFault;
|
||||
import org.gcube.informationsystem.registry.stubs.resourceregistration.CreateMessage;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.registry.impl.postprocessing.purging;
|
||||
package org.gcube.informationsystem.registry.impl.postprocessing.remove;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.registry.impl.postprocessing.purging;
|
||||
package org.gcube.informationsystem.registry.impl.postprocessing.remove;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.HashSet;
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.registry.impl.postprocessing.purging;
|
||||
package org.gcube.informationsystem.registry.impl.postprocessing.remove;
|
||||
|
||||
import java.util.Set;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.registry.impl.postprocessing.purging;
|
||||
package org.gcube.informationsystem.registry.impl.postprocessing.remove;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
|
@ -0,0 +1,21 @@
|
|||
package org.gcube.informationsystem.registry.impl.postprocessing.update;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
|
||||
public class AvailableUpdaters {
|
||||
|
||||
private static Map<String, Updater<?>> updaters = new HashMap<String, Updater<?>>();
|
||||
private static GCUBELog logger = new GCUBELog(AvailableUpdaters.class);
|
||||
|
||||
public static void register(Updater<?> updater) {
|
||||
updaters.put(updater.getName(), updater);
|
||||
logger.debug ("Updater " + updater.getName() + " registered");
|
||||
}
|
||||
|
||||
public static Updater<?> getPurger(String updaterName) {
|
||||
return updaters.get(updaterName);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package org.gcube.informationsystem.registry.impl.postprocessing.update;
|
||||
|
||||
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.scope.GCUBEScope;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.remove.AvailablePurgers;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.remove.Purger;
|
||||
|
||||
public class GHNUpdater implements Updater<GCUBEHostingNode> {
|
||||
|
||||
protected final GCUBELog logger = new GCUBELog(GHNUpdater.class);
|
||||
|
||||
@Override
|
||||
public void update(GCUBEResource resource, GCUBEScope scope) {
|
||||
if (! (resource instanceof GCUBEHostingNode))
|
||||
return;
|
||||
GCUBEHostingNode node = (GCUBEHostingNode) resource;
|
||||
logger.trace("The gHN is currently in status " + node.getNodeDescription().getStatus().toString());
|
||||
if ((node.getNodeDescription().getStatus() == GHNContext.Status.DOWN)
|
||||
||(node.getNodeDescription().getStatus() == GHNContext.Status.FAILED)) {
|
||||
logger.trace("Looking for purger for "+ GCUBEHostingNode.TYPE);
|
||||
Purger<?> purger = AvailablePurgers.getPurger(GCUBEHostingNode.TYPE);
|
||||
if (purger != null) {
|
||||
try {
|
||||
logger.debug("Applying purger for " + GCUBEHostingNode.TYPE);
|
||||
purger.purge(node.getID(), scope);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while removing the profiles related to the resource", e);
|
||||
}
|
||||
} else
|
||||
logger.trace("No purger found");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return GCUBEHostingNode.TYPE;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package org.gcube.informationsystem.registry.impl.postprocessing.update;
|
||||
|
||||
import org.gcube.common.core.contexts.GCUBEServiceContext;
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
import org.gcube.common.core.resources.GCUBERunningInstance;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.remove.AvailablePurgers;
|
||||
import org.gcube.informationsystem.registry.impl.postprocessing.remove.Purger;
|
||||
|
||||
public class RIUpdater implements Updater<GCUBERunningInstance> {
|
||||
|
||||
protected final GCUBELog logger = new GCUBELog(RIUpdater.class);
|
||||
|
||||
@Override
|
||||
public void update(GCUBEResource resource, GCUBEScope scope) {
|
||||
if (! (resource instanceof GCUBERunningInstance))
|
||||
return;
|
||||
GCUBERunningInstance ri = (GCUBERunningInstance) resource;
|
||||
logger.trace("The Running Instance is currently in state " + ri.getDeploymentData().getState());
|
||||
if ((ri.getDeploymentData().getState().equals(GCUBEServiceContext.Status.DOWN.toString()))
|
||||
||(ri.getDeploymentData().getState().equals(GCUBEServiceContext.Status.FAILED.toString()))) {
|
||||
logger.trace("Looking for purger for "+ GCUBERunningInstance.TYPE);
|
||||
Purger<?> purger = AvailablePurgers.getPurger(GCUBERunningInstance.TYPE);
|
||||
if (purger != null) {
|
||||
try {
|
||||
logger.debug("Applying purger for " + GCUBERunningInstance.TYPE);
|
||||
purger.purge(ri.getID(), scope);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while removing the profiles related to the resource", e);
|
||||
}
|
||||
} else
|
||||
logger.trace("No purger found");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return GCUBERunningInstance.TYPE;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package org.gcube.informationsystem.registry.impl.postprocessing.update;
|
||||
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
|
||||
public interface Updater <RESOURCE extends GCUBEResource> {
|
||||
|
||||
public void update(GCUBEResource resource, GCUBEScope scope);
|
||||
|
||||
/**
|
||||
* Gets the type of resource managed by the purgerE
|
||||
* @return the type
|
||||
*/
|
||||
public String getName();
|
||||
}
|
Loading…
Reference in New Issue