InstanceState and ScopeStates initialized from the ResourceHome

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vre-management/ResourceManager@56118 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Manuele Simi 2012-07-02 15:29:06 +00:00
parent b736edc373
commit f0daf0311e
10 changed files with 90 additions and 50 deletions

View File

@ -69,7 +69,7 @@
<dependency>
<groupId>org.gcube.resourcemanagement</groupId>
<artifactId>deployer-stubs</artifactId>
<version>[2.3.0-SNAPSHOT,2.4.0-SNAPSHOT)</version>
<version>[2.4.0-SNAPSHOT,2.5.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>

View File

@ -6,7 +6,7 @@ import org.gcube.common.core.contexts.GCUBEServiceContext;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.utils.handlers.GCUBEHandler;
import org.gcube.common.core.utils.handlers.GCUBEScheduledHandler;
import org.gcube.vremanagement.resourcemanager.porttypes.ResourceBinder;
import static org.gcube.vremanagement.resourcemanager.impl.contexts.StatefulPortTypeContext.*;
/**
* ResourceManager service context implementation
@ -19,7 +19,17 @@ public class ServiceContext extends GCUBEServiceContext {
static ServiceContext cache = new ServiceContext();
public static String getReportingPTName() {
return "gcube/vremanagement/resourcemanager/reporting";
}
public static String getResourceBinderPTName() {
return "gcube/vremanagement/resourcemanager/binder";
}
public static String getScopeControllerPTName() {
return "gcube/vremanagement/resourcemanager/scopecontroller";
}
/**
* Gets the current service context
@ -78,17 +88,16 @@ public class ServiceContext extends GCUBEServiceContext {
}
/** Tries to create the resource in all the instance scopes*/
/** Create the instance state in all the instance scopes*/
protected class HState extends GCUBEHandler<Object> {
public HState() {}
public void run() throws Exception {
GCUBEScope scope = ServiceContext.getContext().getInstance().getScopes().values().iterator().next();
logger.trace("Adding ResourceManager resource to " + scope);
ServiceContext.getContext().setScope(scope);
StatefulPortTypeContext.getContext().getWSHome().create(StatefulPortTypeContext.getContext().makeKey(ResourceBinder.SINGLETON_RESOURCE_KEY));
for (GCUBEScope scope : ServiceContext.getContext().getInstance().getScopes().values()) {
ServiceContext.getContext().setScope(scope);//set the scope in the current thread
StatefulPortTypeContext.getContext().getWSHome().create(StatefulPortTypeContext.getContext().makeKey(SINGLETON_RESOURCE_KEY));
}
}
}

View File

@ -10,13 +10,16 @@ import org.gcube.common.core.contexts.GCUBEStatefulPortTypeContext;
*/
public class StatefulPortTypeContext extends GCUBEStatefulPortTypeContext {
/** Singleton resource name*/
public static final String SINGLETON_RESOURCE_KEY = "ManagerState";
static StatefulPortTypeContext cache = new StatefulPortTypeContext();
@Override
public String getJNDIName() {
return "gcube/vremanagement/ResourceManager";
}
@Override
public String getNamespace() {
return "http://gcube-system.org/namespaces/vremanagement/resourcemanager";

View File

@ -68,7 +68,7 @@ public final class SoftwareGatewayRequest {
}
/**
* Sends the request to the appropriate SR
* Sends the request to the appropriate SG
*
* @throws Exception
*/
@ -82,20 +82,22 @@ public final class SoftwareGatewayRequest {
inner: for (GCUBEScope scope : eprs.keySet()) {
for (EndpointReferenceType epr : eprs.get(scope)) {
try {
logger.trace("Trying Service Repository located at "+ epr);
logger.trace("Trying Service Gateway located at "+ epr);
AccessServiceAddressingLocator locator = new AccessServiceAddressingLocator();
AccessPortType pt = locator.getAccessPortTypePort(epr);
String report = GCUBERemotePortTypeContext.getProxy(pt, scope, TIMEOUT, ServiceContext.getContext()).getDependencies(packageCoordinates);
service2package.add(parseDependenciesReport(service, report));
break inner;//no need for looping on the other instances, we just need that one satisfies the request
} catch (Exception e) {
logger.warn("Unable to check deps for " + packageCoordinates.getServiceName() + " from Service Repository in " + scope + ": "+ e.getMessage(), e);
logger.warn("Unable to check deps for " + packageCoordinates.getServiceName() + " from Service Gateway in " + scope + ": "+ e.getMessage(), e);
}
}
// if we are here, no SR instance was able to resolve the dependencies
// if we are here, no SG instance was able to resolve the dependencies
//ResolvedService s = new ResolvedService(service);
service.setErrorMessage("Unable to check deps for this service in any of the Service Repository instance in scope");
service2package.add(service);
service.setErrorMessage("Unable to check deps for this service in any of the Service Gateway instances in scope");
//service.setStatus();
service2package.add(service);
throw new Exception("Unable to check deps for this service in any of the Service Gateway instances in scope");
}
}
return service2package;

View File

@ -182,7 +182,7 @@ public class VirtualNode {
return;
}
EndpointReferenceType callbackEPR = ServiceContext.getContext().getInstance().getAccessPoint().getEndpoint(StatefulPortTypeContext.getContext().getJNDIName());
EndpointReferenceType callbackEPR = ServiceContext.getContext().getInstance().getAccessPoint().getEndpoint(ServiceContext.getReportingPTName());
UndeployParameters params = new UndeployParameters();
params.set_package(this.packagesToRemove.toArray(new PackageInfo[0]));
params.setTargetScope(new String[] {scope.toString()});

View File

@ -29,37 +29,34 @@ import org.globus.wsrf.NoSuchResourceException;
public final class InstanceState extends GCUBEWSResource {
ScopeStateMap resources = new ScopeStateMap();
static ScopeStateMap resources = new ScopeStateMap();
/** session id -> session map*/
static Map<String, Session> id2session = Collections.synchronizedMap(new HashMap<String, Session>());;
@SuppressWarnings("unchecked")
@Override
protected void initialise(Object... params) throws Exception {
resources.initializeScopes();
this.reuseState(this.getScope());
}
@SuppressWarnings("unchecked")
protected void reuseState(GCUBEScope scope) throws Exception {
//initialize the scope states
for (ScopeState state : resources.getAllStates()) {
//nodes
state.getRawScopeState().data.put("NODES", new HashMap<String, VirtualNode>());
VirtualNodeManager.setNodes((Map<String, VirtualNode>) state.getRawScopeState().data.get("NODES"));
this.registerObservers(state);
}
//let's notify the observers about the current scope states
resources.initializeScope(scope);
ScopeState state = resources.getState(scope);
//nodes
state.getRawScopeState().data.put("NODES", new HashMap<String, VirtualNode>());
VirtualNodeManager.setNodes((Map<String, VirtualNode>) state.getRawScopeState().data.get("NODES"));
this.registerObservers(state);
//notify the observers about the initialization
new Thread() {
/* (non-Javadoc)
* @see java.lang.Thread#run()
*/
@Override
public void run() {
for (ScopeState state : resources.getAllStates())
state.notifyObservers();
resources.getState(InstanceState.this.getScope()).notifyObservers();
}
}.start();
}
/**
* Gets the {@link Session}

View File

@ -2,7 +2,9 @@ package org.gcube.vremanagement.resourcemanager.impl.state;
import org.gcube.common.core.contexts.GCUBEStatefulPortTypeContext;
import org.gcube.common.core.state.GCUBEWSHome;
import org.gcube.common.core.state.GCUBEWSResource;
import org.gcube.vremanagement.resourcemanager.impl.contexts.StatefulPortTypeContext;
import org.globus.wsrf.ResourceException;
/**
*
@ -18,4 +20,19 @@ public class ResourceManagerHome extends GCUBEWSHome {
return StatefulPortTypeContext.getContext();
}
/* (non-Javadoc)
* @see org.gcube.common.core.state.GCUBEWSHome#onReuse(org.gcube.common.core.state.GCUBEWSResource)
*/
@Override
protected void onReuse(GCUBEWSResource resource) throws ResourceException {
super.onReuse(resource);
try {
((InstanceState) resource).reuseState(resource.getServiceContext().getScope());
} catch (Exception e) {
throw new ResourceException("unable to reuse resource in scope " + resource.getServiceContext().getScope().toString());
}
}
}

View File

@ -2,13 +2,13 @@ package org.gcube.vremanagement.resourcemanager.impl.state;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
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.vremanagement.resourcemanager.impl.contexts.ServiceContext;
import org.gcube.vremanagement.resourcemanager.impl.state.observers.Serializer;
import org.globus.wsrf.NoSuchResourceException;
@ -27,18 +27,19 @@ class ScopeStateMap {
ScopeStateMap() {}
/**
* Initializes the resources for all the scopes belonging the current instance
* @throws Exception if any of the initializations fails
* Initializes the scope state
* @throws Exception if initialization fails
*/
void initializeScopes() throws Exception {
Collection<GCUBEScope> scopes = ServiceContext.getContext().getInstance().getScopes().values();
for (GCUBEScope scope : scopes) {
try {
states.put(scope, this.loadState(scope));
} catch (Exception e) {
states.put(scope, this.createState(scope));
}
void initializeScope(GCUBEScope scope) throws Exception {
logger.debug("initialising scope " + scope.toString());
try {
states.put(scope, this.loadState(scope));
logger.debug("scope state " + scope.toString() + " created from a previously serialized state");
} catch (Exception e) {
states.put(scope, this.createState(scope));
logger.debug("scope state " + scope.toString() + " created from scratch");
}
}
/**
@ -86,7 +87,7 @@ class ScopeStateMap {
* @return the states
*/
Collection<ScopeState> getAllStates() {
return states.values();
return Collections.unmodifiableCollection(states.values());
}
/**

View File

@ -6,6 +6,7 @@ import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.vremanagement.resourcemanager.impl.contexts.ServiceContext;
import org.gcube.vremanagement.resourcemanager.impl.contexts.StatefulPortTypeContext;
import static org.gcube.vremanagement.resourcemanager.impl.contexts.StatefulPortTypeContext.*;
import org.gcube.vremanagement.resourcemanager.impl.state.InstanceState;
import org.globus.wsrf.NoSuchResourceException;
import org.globus.wsrf.ResourceException;
@ -17,9 +18,6 @@ import org.globus.wsrf.ResourceException;
*/
abstract class ResourceManagerPortType extends GCUBEPortType {
/** Singleton resource name*/
public static final String SINGLETON_RESOURCE_KEY = "VREManagerState";
/**
* Object logger.
*/

View File

@ -0,0 +1,13 @@
######################################
# Sample VRE creation - properties file
######################################
targetScope=/gcube/devsec/devVRE
callerScope=/gcube/devsec
#Scope properties
creator=CN=Manuele Simi, L=NMIS-ISTI, OU=Personal Certificate, O=INFN, C=IT
designer=CN=Manuele Simi, L=NMIS-ISTI, OU=Personal Certificate, O=INFN, C=IT
securityenabled=false