Various fixings/improvements on scope creation and disposal

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vre-management/ResourceManager@56051 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Manuele Simi 2012-06-28 03:13:13 +00:00
parent d038a04f87
commit e92d9e1d9a
9 changed files with 110 additions and 87 deletions

View File

@ -1,49 +0,0 @@
package org.gcube.vremanagement.resourcemanager.impl.operators;
import java.util.HashSet;
import java.util.Set;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.vremanagement.resourcemanager.impl.contexts.ServiceContext;
import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedDeployedService;
import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedResource;
import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedResource.STATUS;
/**
*
* Dispose the entire scope
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public class DisposeScopeOperator extends Operator {
protected final GCUBELog logger = new GCUBELog(this, ServiceContext.getContext());
private OperatorConfig configuration;
public DisposeScopeOperator(OperatorConfig configuration) {
this.configuration = configuration;
}
@Override
public void exec() throws Exception {
//exclude from the resources to remove the Services' resources. This is because we also have the
//related Running Instances in the list, and we will eventually undeploy them (if # scopes ==1)
Set<ScopedResource> resources = new HashSet<ScopedResource>();
for (ScopedResource resource : this.configuration.scopeState.getAllResources()) {
if ((resource.getType().compareTo(ScopedDeployedService.TYPE) != 0)
&& (resource.getStatus() != STATUS.UNPUBLISHED)
&& (resource.getStatus() != STATUS.LOST)
&& (resource.getStatus() != STATUS.REMOVED)){
resources.add(resource);
this.configuration.session.addResource(resource);
}
}
configuration.scopeState.removeResources(resources);
//TODO: should we also undeploy the RM itself?
this.configuration.session.save();
}
}

View File

@ -11,7 +11,10 @@ import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.state.GCUBEWSResource;
import org.gcube.vremanagement.resourcemanager.impl.deployment.VirtualNode;
import org.gcube.vremanagement.resourcemanager.impl.deployment.VirtualNodeManager;
import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedDeployedService;
import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedResource;
import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedResource.STATUS;
import org.gcube.vremanagement.resourcemanager.impl.state.observers.Disposer;
import org.gcube.vremanagement.resourcemanager.impl.state.observers.Executor;
import org.gcube.vremanagement.resourcemanager.impl.state.observers.Publisher;
import org.gcube.vremanagement.resourcemanager.impl.state.observers.Serializer;
@ -26,7 +29,7 @@ import org.globus.wsrf.NoSuchResourceException;
public final class InstanceState extends GCUBEWSResource {
ResourceMap resources = new ResourceMap();
ScopeStateMap resources = new ScopeStateMap();
/** session id -> session map*/
static Map<String, Session> id2session = Collections.synchronizedMap(new HashMap<String, Session>());;
@ -40,10 +43,7 @@ public final class InstanceState extends GCUBEWSResource {
//nodes
state.getRawScopeState().data.put("NODES", new HashMap<String, VirtualNode>());
VirtualNodeManager.setNodes((Map<String, VirtualNode>) state.getRawScopeState().data.get("NODES"));
//register the observers
state.addObserver(new Executor());
state.addObserver(new Publisher());
state.addObserver(new Serializer());
this.registerObservers(state);
}
//let's notify the observers about the current scope states
@ -104,7 +104,7 @@ public final class InstanceState extends GCUBEWSResource {
* @throws NoSuchResourceException
*/
public ScopeState getState(GCUBEScope scope) throws NoSuchResourceException {
ScopeState state = resources.getScopeState(scope);
ScopeState state = resources.getState(scope);
if (state == null)
return resources.loadState(scope);
else
@ -113,23 +113,34 @@ public final class InstanceState extends GCUBEWSResource {
/**
* Disposes the scope
* @param report
* @throws IOException
*/
public void dispose(GCUBEScope scope) {
ScopeState scopeState = resources.getScopeState(scope);
public void disposeState(GCUBEScope scope, Session report) throws IOException {
ScopeState scopeState = resources.getState(scope);
Set<ScopedResource> allResources = new HashSet<ScopedResource>();
for (ScopedResource resource : scopeState.getAllResources()) {
allResources.add(resource);
}
if ((resource.getType().compareTo(ScopedDeployedService.TYPE) != 0)
&& (resource.getStatus() != STATUS.UNPUBLISHED)
&& (resource.getStatus() != STATUS.LOST)
&& (resource.getStatus() != STATUS.REMOVED)) {
allResources.add(resource);
report.addResource(resource);
}
}
//remove all resources
scopeState.removeResources(allResources);
//TODO: unpublish the published scope resource
//TODO: undeploy myself?
scopeState.removeResources(allResources);
report.save();
scopeState.markAsDisposed();
}
/**
* Gets the resource published in the IS for the given scope
* @param scope
* @return the resource
* @throws NoSuchResourceException
*/
public PublishedScopeResource getPublishedScopeResource(GCUBEScope scope) throws NoSuchResourceException {
return resources.getPublishedScopeResource(scope);
}
@ -141,7 +152,21 @@ public final class InstanceState extends GCUBEWSResource {
* @throws NoSuchResourceException
* @throws Exception
*/
public void create(GCUBEScope scope) throws NoSuchResourceException, Exception {
resources.createState(scope);
public void createState(GCUBEScope scope) throws NoSuchResourceException, Exception {
ScopeState state = resources.createState(scope);
this.registerObservers(state);
state.notifyObservers();
}
/**
* Registers a set of observers for the state management operations
* @param state
*/
private void registerObservers(ScopeState state) {
state.addObserver(new Executor());
state.addObserver(new Publisher());
state.addObserver(new Serializer());
state.addObserver(new Disposer());
}
}

View File

@ -34,6 +34,8 @@ public class ScopeState extends Observable {
private Session report;
private boolean isDisposed = false;
protected ScopeState() {}
protected void initialize(GCUBEScope scope, String name, boolean securityEnabled, String ... description) {
@ -326,4 +328,19 @@ public class ScopeState extends Observable {
}
/**
* @return the isDisposed
*/
public boolean isDisposed() {
return isDisposed;
}
/**
* @param isDisposed the isDisposed to set
*/
public void markAsDisposed() {
this.isDisposed = true;
this.notifyObservers();
}
}

View File

@ -17,7 +17,7 @@ import org.globus.wsrf.NoSuchResourceException;
* @author manuele simi (CNR)
*
*/
class ResourceMap {
class ScopeStateMap {
/** mapping between scopes and their actual state*/
Map<String, ScopeState> states = new HashMap<String, ScopeState>();
@ -25,9 +25,9 @@ class ResourceMap {
/** mapping between scopes and their actual published state*/
Map<String, PublishedScopeResource> published = new HashMap<String, PublishedScopeResource>();
protected GCUBELog logger = new GCUBELog(ResourceMap.class);
protected GCUBELog logger = new GCUBELog(ScopeStateMap.class);
ResourceMap() {}
ScopeStateMap() {}
/**
* Initializes the resources for all the scopes belonging the current instance
@ -97,7 +97,7 @@ class ResourceMap {
* @param scope
* @return the state or null if the state does not exist
*/
ScopeState getScopeState(GCUBEScope scope) {
ScopeState getState(GCUBEScope scope) {
return states.get(scope.getName());
}

View File

@ -0,0 +1,29 @@
package org.gcube.vremanagement.resourcemanager.impl.state.observers;
import org.gcube.vremanagement.resourcemanager.impl.state.PublishedScopeResource;
import org.gcube.vremanagement.resourcemanager.impl.state.ScopeState;
/**
* Performs scope disposal operations
* @author manuele simi (CNR)
*
*/
public class Disposer extends ScopeObserver {
@Override
protected void scopeChanged(ScopeState scopeState) {
if (scopeState.isDisposed()) {
logger.info("Disposer activated for " + scopeState.getScope().toString());
//remove the serialized state
Serializer.getSerializationFile(scopeState.getScope()).delete();
//remove the resource from the IS
try {
PublishedScopeResource.getResource(scopeState.getScope()).dismiss();
} catch (Exception e) {
logger.error("Unable to delete the resource from the IS for " + scopeState.getScope().toString(),e);
}
}
}
}

View File

@ -22,7 +22,8 @@ import org.gcube.vremanagement.resourcemanager.impl.state.ScopeState.OPERATION;
/**
*
* Performs management operations on {@link ScopedResource}s depending on their {@link STATUS}
* Performs management operations on {@link ScopedResource}s according to their
* current {@link STATUS}
*
* @author Manuele Simi (ISTI-CNR)
*

View File

@ -126,7 +126,7 @@ public class Serializer extends ScopeObserver {
private static File getSerializationFile(GCUBEScope scope) {
return ServiceContext.getContext().getPersistentFile("ResourceList_"+scope.getName(), true);
protected static File getSerializationFile(GCUBEScope scope) {
return ServiceContext.getContext().getPersistentFile("SerializedResourceList"+scope.toString().replace('/', '-'), true);
}
}

View File

@ -7,14 +7,11 @@ import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.scope.GCUBEScopeNotSupportedException;
import org.gcube.common.core.scope.GCUBEScope.MalformedScopeExpressionException;
import org.gcube.vremanagement.resourcemanager.impl.contexts.ServiceContext;
import org.gcube.vremanagement.resourcemanager.impl.operators.DisposeScopeOperator;
import org.gcube.vremanagement.resourcemanager.impl.operators.OperatorConfig;
import org.gcube.vremanagement.resourcemanager.impl.state.Session;
import org.gcube.vremanagement.resourcemanager.impl.state.PublishedScopeResource;
import org.gcube.vremanagement.resourcemanager.impl.state.PublishedScopeResource.UnknownScopeOptionException;
import org.gcube.vremanagement.resourcemanager.impl.state.Session.OPERATION;
import org.globus.wsrf.NoSuchResourceException;
import org.globus.wsrf.ResourceException;
import org.gcube.vremanagement.resourcemanager.stubs.common.InvalidScopeFaultType;
import org.gcube.vremanagement.resourcemanager.stubs.scontroller.*;
@ -52,8 +49,8 @@ public class ScopeController extends ResourceManagerPortType {
try {
Session report = new Session(UUIDGenFactory.getUUIDGen().nextUUID(), OPERATION.Dispose,scope);
this.getInstanceState().addSession(scope,report);
new DisposeScopeOperator(new OperatorConfig(report, this.getInstanceState().getState(scope), scope)).run();
this.getInstanceState().getPublishedScopeResource(scope).dismiss();
//new DisposeScopeOperator(new OperatorConfig(report, this.getInstanceState().getState(scope), scope)).run();
this.getInstanceState().disposeState(scope, report);
return report.getId();
} catch (NoSuchResourceException e) {
logger.error("No resource found for this scope", e);
@ -83,12 +80,16 @@ public class ScopeController extends ResourceManagerPortType {
}
//String map = params.getServiceMap();
try {
this.getInstanceState().create(scope);
this.getInstanceState().createState(scope);
ScopeUtils.addToInstance(scope);
} catch (Exception e) {
e.printStackTrace();
logger.error("Failed to create the scope: " + scope.toString(), e);
throw ServiceContext.getContext().getDefaultException("Unable to add this Resource Managet to the scope: " + e.getMessage(), e).toFault();
}
if (params.getOptionsParameters() != null) {
params.getOptionsParameters().setTargetScope(params.getTargetScope());
this.changeScopeOptions(params.getOptionsParameters());
}
this.changeScopeOptions(params.getOptionsParameters());
}
/**

View File

@ -8,8 +8,7 @@ import java.util.Collection;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.scope.GCUBEScopeManager.IllegalScopeException;
import org.gcube.vremanagement.resourcemanager.impl.contexts.ServiceContext;
import org.globus.wsrf.NoSuchResourceException;
import org.globus.wsrf.ResourceException;
/**
* Validates input scopes
@ -62,7 +61,7 @@ class ScopeUtils {
* @param scope the scope to add
*/
static void addToInstance(GCUBEScope scope) {
ServiceContext.getContext().getInstance().addScope(scope);
ServiceContext.getContext().addScope(scope);
}
/**
@ -70,7 +69,7 @@ class ScopeUtils {
* @param scope the scope to remove
*/
static void removeFromInstance(GCUBEScope scope) {
ServiceContext.getContext().getInstance().removeScope(scope);
ServiceContext.getContext().removeScope(scope);
}
}