This commit is contained in:
Manuele Simi 2010-04-30 00:51:53 +00:00
parent fd37f0d003
commit 7a627ed003
13 changed files with 197 additions and 108 deletions

View File

@ -154,16 +154,12 @@
<message name="AddResourcesInputMessage"> <message name="AddResourcesInputMessage">
<part name="request" element="tns:addResourcesParameters"/> <part name="request" element="tns:addResourcesParameters"/>
</message> </message>
<message name="AddResourcesResponseMessage"> <message name="ReportID">
<part name="request" element="tns:reportID"/> <part name="request" element="tns:reportID"/>
</message> </message>
<message name="RemoveResourcesInputMessage"> <message name="RemoveResourcesInputMessage">
<part name="request" element="tns:removeResourcesParameters"/> <part name="request" element="tns:removeResourcesParameters"/>
</message> </message>
<message name="RemoveResourcesResponseMessage">
<part name="request" element="tns:reportID"/>
</message>
<message name="SendReportInputMessage"> <message name="SendReportInputMessage">
<part name="request" element="tns:sendReportParameters"/> <part name="request" element="tns:sendReportParameters"/>
</message> </message>
@ -196,13 +192,13 @@
<operation name="AddResources"> <operation name="AddResources">
<input message="tns:AddResourcesInputMessage"/> <input message="tns:AddResourcesInputMessage"/>
<output message="tns:AddResourcesResponseMessage"/> <output message="tns:ReportID"/>
<fault name="fault" message="corefaults:GCUBEFaultMessage"/> <fault name="fault" message="corefaults:GCUBEFaultMessage"/>
</operation> </operation>
<operation name="RemoveResources"> <operation name="RemoveResources">
<input message="tns:RemoveResourcesInputMessage"/> <input message="tns:RemoveResourcesInputMessage"/>
<output message="tns:RemoveResourcesResponseMessage"/> <output message="tns:ReportID"/>
<fault name="fault" message="corefaults:GCUBEFaultMessage"/> <fault name="fault" message="corefaults:GCUBEFaultMessage"/>
</operation> </operation>
@ -214,7 +210,7 @@
<operation name="DisposeScope"> <operation name="DisposeScope">
<input message="tns:DisposeScopeInputMessage"/> <input message="tns:DisposeScopeInputMessage"/>
<output message="tns:VoidMessage"/> <output message="tns:ReportID"/>
<fault name="fault" message="corefaults:GCUBEFaultMessage"/> <fault name="fault" message="corefaults:GCUBEFaultMessage"/>
</operation> </operation>

View File

@ -23,6 +23,7 @@ import org.gcube.vremanagement.resourcemanager.stubs.resourcemanager.RemoveResou
import org.gcube.vremanagement.resourcemanager.stubs.resourcemanager.ScopeOption; import org.gcube.vremanagement.resourcemanager.stubs.resourcemanager.ScopeOption;
import org.gcube.vremanagement.resourcemanager.stubs.resourcemanager.SendReportParameters; import org.gcube.vremanagement.resourcemanager.stubs.resourcemanager.SendReportParameters;
import org.gcube.vremanagement.resourcemanager.impl.operators.AddResourcesOperator; import org.gcube.vremanagement.resourcemanager.impl.operators.AddResourcesOperator;
import org.gcube.vremanagement.resourcemanager.impl.operators.DisposeScopeOperator;
import org.gcube.vremanagement.resourcemanager.impl.operators.OperatorConfig; import org.gcube.vremanagement.resourcemanager.impl.operators.OperatorConfig;
import org.gcube.vremanagement.resourcemanager.impl.operators.RemoveResourcesOperator; import org.gcube.vremanagement.resourcemanager.impl.operators.RemoveResourcesOperator;
import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedResource; import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedResource;
@ -30,6 +31,7 @@ import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedRunningInsta
import org.gcube.vremanagement.resourcemanager.impl.state.ResourceReport; import org.gcube.vremanagement.resourcemanager.impl.state.ResourceReport;
import org.gcube.vremanagement.resourcemanager.impl.state.PublishedScopeResource; import org.gcube.vremanagement.resourcemanager.impl.state.PublishedScopeResource;
import org.gcube.vremanagement.resourcemanager.impl.state.InstanceState; import org.gcube.vremanagement.resourcemanager.impl.state.InstanceState;
import org.gcube.vremanagement.resourcemanager.impl.state.ScopeState;
import org.gcube.vremanagement.resourcemanager.impl.state.PublishedScopeResource.UnknownScopeOptionException; import org.gcube.vremanagement.resourcemanager.impl.state.PublishedScopeResource.UnknownScopeOptionException;
import org.globus.wsrf.NoSuchResourceException; import org.globus.wsrf.NoSuchResourceException;
import org.globus.wsrf.ResourceException; import org.globus.wsrf.ResourceException;
@ -56,7 +58,7 @@ public class ResourceManager extends GCUBEPortType {
return ServiceContext.getContext(); return ServiceContext.getContext();
} }
/** /**
* Adds a new group of {@link GCUBEResource} to the PublishedScopeResource * Adds a new group of {@link ScopedResource}s to the managed Scope
* *
* @param resourcesList the resources to join * @param resourcesList the resources to join
* @return the ID assigned to the operation, it can be used to retrieve the resource report by invoking the {@link ResourceManager#getReport(String)} operation * @return the ID assigned to the operation, it can be used to retrieve the resource report by invoking the {@link ResourceManager#getReport(String)} operation
@ -83,7 +85,7 @@ public class ResourceManager extends GCUBEPortType {
} }
/** /**
* Removes a group of {@link GCUBEResource} from the PublishedScopeResource * Removes a group of {@link ScopedResource}s from the managed Scope
* *
* @param resourcesList the resources to remove from the PublishedScopeResource * @param resourcesList the resources to remove from the PublishedScopeResource
* @throws GCUBEFault if the operation fails * @throws GCUBEFault if the operation fails
@ -91,15 +93,10 @@ public class ResourceManager extends GCUBEPortType {
public String removeResources(RemoveResourcesParameters resourceList) throws GCUBEFault { public String removeResources(RemoveResourcesParameters resourceList) throws GCUBEFault {
try { try {
//PublishedScopeResource resource = this.getResource().getPublishedScopeResource();
//resource.reload();
GCUBEScope targetScope = this.validateOperationScope(resourceList.getTargetScope()); GCUBEScope targetScope = this.validateOperationScope(resourceList.getTargetScope());
ResourceReport report = new ResourceReport(UUIDGenFactory.getUUIDGen().nextUUID(), targetScope); ResourceReport report = new ResourceReport(UUIDGenFactory.getUUIDGen().nextUUID(), targetScope);
this.getResource().addReport(report); this.getResource().addReport(report);
new RemoveResourcesOperator(new OperatorConfig(report, this.getResource().getResourceList(), targetScope),resourceList).run(); new RemoveResourcesOperator(new OperatorConfig(report, this.getResource().getResourceList(), targetScope),resourceList).run();
//resource.publish();
//returns the report ID, it can be used to invoke the getReport operation
return report.getId(); return report.getId();
} catch (IllegalScopeException ise){ } catch (IllegalScopeException ise){
logger.error("The target scope (" + resourceList.getTargetScope() + ") is not valid or null or not joined to this instance", ise); logger.error("The target scope (" + resourceList.getTargetScope() + ") is not valid or null or not joined to this instance", ise);
@ -110,18 +107,25 @@ public class ResourceManager extends GCUBEPortType {
} }
} }
public void disposeScope(DisposeScopeParameters params) throws GCUBEFault { /**
* Disposes the managed Scope
* @param params
* @return
* @throws GCUBEFault
*/
public String disposeScope(DisposeScopeParameters params) throws GCUBEFault {
logger.info("Dispose Scope invoked... the entire scope is going to be thrown away!!"); logger.info("Dispose Scope invoked... the entire scope is going to be thrown away!!");
try { try {
ResourceReport report = new ResourceReport(UUIDGenFactory.getUUIDGen().nextUUID(), this.getResource().getManagedScope()); ResourceReport report = new ResourceReport(UUIDGenFactory.getUUIDGen().nextUUID(), this.getResource().getManagedScope());
this.getResource().addReport(report); this.getResource().addReport(report);
//new RemoveResourcesOperator(new OperatorConfig(report, this.getResource().getResourceList(), this.getResource().getManagedScope()),resourceList).run(); new DisposeScopeOperator(new OperatorConfig(report, this.getResource().getResourceList(), this.getResource().getManagedScope())).run();
return report.getId();
} catch (NoSuchResourceException e) { } catch (NoSuchResourceException e) {
logger.error("No resource found for this scope", e); logger.error("No resource found for this scope", e);
throw ServiceContext.getContext().getDefaultException("No resource found for this scope", e).toFault(); throw ServiceContext.getContext().getDefaultException("No resource found for this scope", e).toFault();
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block logger.error("Unable to dispose the scope: " + e.getMessage(), e);
e.printStackTrace(); throw ServiceContext.getContext().getDefaultException("Unable to dispose the scope: " + e.getMessage(), e).toFault();
} }
} }

View File

@ -0,0 +1,15 @@
package org.gcube.vremanagement.resourcemanager.impl.operators;
public class DisposeScopeOperator extends Operator {
public DisposeScopeOperator(OperatorConfig operatorConfig) {
// TODO Auto-generated constructor stub
}
@Override
public void exec() throws Exception {
// TODO Auto-generated method stub
}
}

View File

@ -26,7 +26,6 @@ import org.gcube.common.core.informationsystem.client.queries.GCUBEMCollectionQu
import org.gcube.common.core.informationsystem.client.queries.GCUBEServiceQuery; import org.gcube.common.core.informationsystem.client.queries.GCUBEServiceQuery;
import org.gcube.common.core.informationsystem.publisher.ISPublisher; import org.gcube.common.core.informationsystem.publisher.ISPublisher;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamOmitField; import com.thoughtworks.xstream.annotations.XStreamOmitField;
@ -37,7 +36,6 @@ import com.thoughtworks.xstream.annotations.XStreamOmitField;
* @author Manuele Simi (ISTI-CNR) * @author Manuele Simi (ISTI-CNR)
* *
*/ */
@XStreamAlias("AnyResource")
public final class ScopedAnyResource extends ScopedResource { public final class ScopedAnyResource extends ScopedResource {
@XStreamOmitField @XStreamOmitField
@ -56,7 +54,7 @@ public final class ScopedAnyResource extends ScopedResource {
*/ */
@SuppressWarnings({ "unchecked"}) @SuppressWarnings({ "unchecked"})
@Override @Override
public void find() throws Exception { public void find() throws ResourceNotFound, Exception {
ISClient client = GHNContext.getImplementation(ISClient.class); ISClient client = GHNContext.getImplementation(ISClient.class);
Class query = null; Class query = null;
try { try {
@ -71,22 +69,22 @@ public final class ScopedAnyResource extends ScopedResource {
ISTemplateQuery realquery = (ISTemplateQuery) client.getQuery(query); ISTemplateQuery realquery = (ISTemplateQuery) client.getQuery(query);
realquery.addAtomicConditions(new AtomicCondition("//ID",this.id)); realquery.addAtomicConditions(new AtomicCondition("//ID",this.id));
List <GCUBEResource> profiles = client.execute(realquery, this.scope); List <GCUBEResource> profiles = client.execute(realquery, GCUBEScope.getScope(this.scope));
if ((profiles != null) && (profiles.size() > 0)) if ((profiles != null) && (profiles.size() > 0))
this.profile = profiles.get(0); this.profile = profiles.get(0);
else else
// obviously, in the case of adding, the resource is not in the current scope, therefore we look upstairs (the enclosing scope) // obviously, in the case of adding, the resource is not in the current scope, therefore we look upstairs (the enclosing scope)
this.profile = (GCUBEResource) client.execute(realquery, this.scope.getEnclosingScope()).get(0); this.profile = (GCUBEResource) client.execute(realquery, GCUBEScope.getScope(this.scope).getEnclosingScope()).get(0);
} catch (Exception e) { } catch (Exception e) {
this.noHopeForMe("unable to find the target resource (ID=" + id + "). Possible cause: " + e.getMessage(), e); this.noHopeForMe("unable to find the target resource (ID=" + id + "). Possible cause: " + e.getMessage(), new ResourceNotFound(e));
} }
} }
@Override @Override
protected void addToScope() throws Exception { protected void addToScope() throws ResourceNotFound, Exception {
this.find(); this.find();
logger.debug("Adding scope to resource's profile"); getLogger().debug("Adding scope to resource profile");
try { try {
profile.addScope(this.getScope()); profile.addScope(this.getScope());
//republish the resource //republish the resource
@ -104,9 +102,9 @@ public final class ScopedAnyResource extends ScopedResource {
} }
@Override @Override
protected void removeFromScope() throws Exception { protected void removeFromScope() throws ResourceNotFound, Exception {
this.find(); this.find();
logger.debug("Removing scope from resource's profile"); getLogger().debug("Removing scope from resource profile");
try { try {
profile.removeScope(this.getScope()); profile.removeScope(this.getScope());
//republish the resource //republish the resource

View File

@ -15,8 +15,6 @@ import org.gcube.vremanagement.resourcemanager.impl.deployment.VirtualNode;
import org.gcube.vremanagement.resourcemanager.impl.deployment.resources.Dependency; import org.gcube.vremanagement.resourcemanager.impl.deployment.resources.Dependency;
import org.gcube.vremanagement.resourcemanager.impl.deployment.resources.Service; import org.gcube.vremanagement.resourcemanager.impl.deployment.resources.Service;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/** /**
* *
* Models a scoped {@link GCUBEService} * Models a scoped {@link GCUBEService}
@ -24,7 +22,6 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
* @author Manuele Simi (ISTI-CNR) * @author Manuele Simi (ISTI-CNR)
* *
*/ */
@XStreamAlias("Service")
public final class ScopedDeployedService extends ScopedResource { public final class ScopedDeployedService extends ScopedResource {
public static final String TYPE = GCUBEService.TYPE; public static final String TYPE = GCUBEService.TYPE;
@ -88,7 +85,7 @@ public final class ScopedDeployedService extends ScopedResource {
} }
@Override @Override
public void find() throws Exception { public void find() throws ResourceNotFound {
//looks for the service and its deps in the Software Repository //looks for the service and its deps in the Software Repository
SoftwareRepositoryRequest request = new SoftwareRepositoryRequest(); SoftwareRepositoryRequest request = new SoftwareRepositoryRequest();
request.addService(this); request.addService(this);
@ -104,15 +101,15 @@ public final class ScopedDeployedService extends ScopedResource {
} }
this.success = true; this.success = true;
} catch (Exception e) { } catch (Exception e) {
logger.error("Unable to resolve the list of deps for " + this.service, e); getLogger().error("Unable to resolve the list of deps for " + this.service, e);
this.noHopeForMe("Unable to resolve the list of dependencies for " + this.service,e); this.noHopeForMe("Unable to resolve the list of dependencies for " + this.service, new ResourceNotFound(e));
} }
} }
@Override @Override
protected void addToScope() throws Exception { protected void addToScope() throws ResourceNotFound, Exception {
if (!this.isSuccess()) { if (!this.isSuccess()) {
this.noHopeForMe(this.getErrorMessage(),new Exception()); this.noHopeForMe(this.getErrorMessage(),new Exception());
} }
@ -130,7 +127,7 @@ public final class ScopedDeployedService extends ScopedResource {
@Override @Override
protected void removeFromScope() throws Exception { protected void removeFromScope() throws ResourceNotFound, Exception {
if (!this.isSuccess()) { if (!this.isSuccess()) {
//TODO: could we undeploy static packages here? //TODO: could we undeploy static packages here?
this.noHopeForMe(this.getErrorMessage(),new Exception()); this.noHopeForMe(this.getErrorMessage(),new Exception());
@ -155,7 +152,7 @@ public final class ScopedDeployedService extends ScopedResource {
* @throws Exception * @throws Exception
*/ */
private void undeploy(VirtualNode node) throws Exception { private void undeploy(VirtualNode node) throws Exception {
logger.info("Undeploying service "+ this.service+ " from GHN " + this.ghnID); getLogger().info("Undeploying service "+ this.service+ " from GHN " + this.ghnID);
//prepare the input list of packagesToAdd for that GHN //prepare the input list of packagesToAdd for that GHN
List<Dependency> deps = this.getResolvedDependencies(); List<Dependency> deps = this.getResolvedDependencies();
for (int i = 0; i < deps.size(); i++) { for (int i = 0; i < deps.size(); i++) {
@ -165,7 +162,7 @@ public final class ScopedDeployedService extends ScopedResource {
p.setServiceVersion(deps.get(i).getService().getVersion()); p.setServiceVersion(deps.get(i).getService().getVersion());
p.setVersion(deps.get(i).getVersion()); p.setVersion(deps.get(i).getVersion());
p.setName(deps.get(i).getName()); p.setName(deps.get(i).getName());
logger.trace("Adding Package to deployment request: " + deps.get(i)); getLogger().trace("Adding Package to deployment request: " + deps.get(i));
this.packages.add(p); this.packages.add(p);
} }
node.removePackages(this.packages); node.removePackages(this.packages);
@ -192,7 +189,7 @@ public final class ScopedDeployedService extends ScopedResource {
* @param node the target GHN * @param node the target GHN
*/ */
public void setTargetGHN(VirtualNode node) { public void setTargetGHN(VirtualNode node) {
logger.info("Using GHN " + node.getID() + " for " + this); getLogger().info("Using GHN " + node.getID() + " for " + this);
this.ghnID = node.getID(); this.ghnID = node.getID();
Set<PackageInfo> packages = new HashSet<PackageInfo>(); Set<PackageInfo> packages = new HashSet<PackageInfo>();
@ -205,7 +202,7 @@ public final class ScopedDeployedService extends ScopedResource {
p.setServiceVersion(deps.get(i).getService().getVersion()); p.setServiceVersion(deps.get(i).getService().getVersion());
p.setVersion(deps.get(i).getVersion()); p.setVersion(deps.get(i).getVersion());
p.setName(deps.get(i).getName()); //packageName p.setName(deps.get(i).getName()); //packageName
logger.trace("Adding Package to deployment request: " + deps.get(i)); getLogger().trace("Adding Package to deployment request: " + deps.get(i));
packages.add(p); packages.add(p);
} }
node.addPackages(packages); node.addPackages(packages);

View File

@ -14,18 +14,14 @@ import org.gcube.common.vremanagement.ghnmanager.stubs.GHNManagerPortType;
import org.gcube.common.vremanagement.ghnmanager.stubs.service.GHNManagerServiceAddressingLocator; import org.gcube.common.vremanagement.ghnmanager.stubs.service.GHNManagerServiceAddressingLocator;
import org.gcube.vremanagement.resourcemanager.impl.contexts.ServiceContext; import org.gcube.vremanagement.resourcemanager.impl.contexts.ServiceContext;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/** /**
* Models a scoped {@link GCUBEHostingNode} * Models a scoped {@link GCUBEHostingNode}
* *
* @author Manuele Simi (ISTI-CNR) * @author Manuele Simi (ISTI-CNR)
* *
*/ */
@XStreamAlias("GHN")
public final class ScopedGHN extends ScopedResource { public final class ScopedGHN extends ScopedResource {
public static final String TYPE = GCUBEHostingNode.TYPE; public static final String TYPE = GCUBEHostingNode.TYPE;
private String nodename = ""; private String nodename = "";
@ -36,7 +32,7 @@ public final class ScopedGHN extends ScopedResource {
@Override @Override
protected void addToScope() throws Exception { protected void addToScope() throws ResourceNotFound, Exception {
if (this.nodename.compareToIgnoreCase("") == 0) if (this.nodename.compareToIgnoreCase("") == 0)
this.find(); this.find();
//contact the GHNManager to add the GHN to the given scope //contact the GHNManager to add the GHN to the given scope
@ -58,7 +54,7 @@ public final class ScopedGHN extends ScopedResource {
} }
@Override @Override
public void find() throws Exception { public void find() throws ResourceNotFound {
try { try {
ISClient client = GHNContext.getImplementation(ISClient.class); ISClient client = GHNContext.getImplementation(ISClient.class);
GCUBEGHNQuery query = client.getQuery(GCUBEGHNQuery.class); GCUBEGHNQuery query = client.getQuery(GCUBEGHNQuery.class);
@ -66,13 +62,13 @@ public final class ScopedGHN extends ScopedResource {
this.nodename = client.execute(query, ServiceContext.getContext().getScope().getEnclosingScope()).get(0).getNodeDescription().getName(); this.nodename = client.execute(query, ServiceContext.getContext().getScope().getEnclosingScope()).get(0).getNodeDescription().getName();
this.hostedOn = nodename; this.hostedOn = nodename;
} catch (Exception e) { } catch (Exception e) {
this.noHopeForMe("unable to find the target GHN (ID=" + this.id + ")", e); this.noHopeForMe("unable to find the target GHN (ID=" + this.id + ")", new ResourceNotFound(e));
} }
} }
@Override @Override
protected void removeFromScope() throws Exception { protected void removeFromScope() throws ResourceNotFound, Exception {
if (this.nodename.compareToIgnoreCase("") == 0) if (this.nodename.compareToIgnoreCase("") == 0)
this.find(); this.find();
EndpointReferenceType endpoint = new EndpointReferenceType(); EndpointReferenceType endpoint = new EndpointReferenceType();

View File

@ -13,6 +13,7 @@ import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.vremanagement.resourcemanager.impl.operators.Operator.ACTION; import org.gcube.vremanagement.resourcemanager.impl.operators.Operator.ACTION;
import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
/** /**
* An abstract model for a scoped {@link GCUBEResource} * An abstract model for a scoped {@link GCUBEResource}
@ -20,12 +21,11 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
* @author Manuele Simi (ISTI-CNR) * @author Manuele Simi (ISTI-CNR)
* *
*/ */
@XStreamAlias("ScopedResource")
public abstract class ScopedResource { public abstract class ScopedResource {
/** Object getLogger() */
/** Object logger */ @XStreamOmitField
protected final GCUBELog logger=new GCUBELog(this); protected GCUBELog logger;
/** the resource identifier*/ /** the resource identifier*/
@XStreamAlias("ResourceID") @XStreamAlias("ResourceID")
@ -36,7 +36,6 @@ public abstract class ScopedResource {
protected String type; protected String type;
/** where the resource is hosted on, it makes sense for RI, GHN*/ /** where the resource is hosted on, it makes sense for RI, GHN*/
@XStreamAlias("HostedOn")
protected String hostedOn = ""; protected String hostedOn = "";
/** result of the last operation performed on the resource */ /** result of the last operation performed on the resource */
@ -47,8 +46,7 @@ public abstract class ScopedResource {
@XStreamAlias("LastOperationMessage") @XStreamAlias("LastOperationMessage")
protected String errorMessage = ""; protected String errorMessage = "";
@XStreamAlias("Scope") protected String scope;
protected GCUBEScope scope;
/** the last action performed on the resource*/ /** the last action performed on the resource*/
protected ACTION action; protected ACTION action;
@ -57,6 +55,10 @@ public abstract class ScopedResource {
@XStreamAlias("LastModificationTime") @XStreamAlias("LastModificationTime")
protected Date lastModificationTime; protected Date lastModificationTime;
/** Last modification time stamp*/
@XStreamAlias("JointTime")
protected Date jointTime;
@XStreamAlias("LastStatus") @XStreamAlias("LastStatus")
protected STATUS status; protected STATUS status;
@ -76,7 +78,7 @@ public abstract class ScopedResource {
public ScopedResource(String id, String type, GCUBEScope scope) { public ScopedResource(String id, String type, GCUBEScope scope) {
this.id = id; this.id = id;
this.type = type; this.type = type;
this.scope = scope; this.scope = scope.toString();
this.status = STATUS.CREATED; this.status = STATUS.CREATED;
} }
@ -88,10 +90,10 @@ public abstract class ScopedResource {
public abstract void find() throws Exception;; public abstract void find() throws Exception;;
public synchronized void doAction(ACTION action) throws Exception { public synchronized void doAction(ACTION action) throws ResourceNotFound, Exception {
this.action = action; this.action = action;
switch (action) { switch (action) {
case ADD: this.addToScope(); this.success= true; break; case ADD: this.addToScope(); this.setJointTime(Calendar.getInstance().getTime()); this.success= true; break;
case REMOVE: this.removeFromScope(); this.success= true; break; case REMOVE: this.removeFromScope(); this.success= true; break;
default: break; default: break;
} }
@ -101,15 +103,17 @@ public abstract class ScopedResource {
/** /**
* Adds the resource to the scope * Adds the resource to the scope
* @throws Exception if the operation fails * @throws Exception if the operation fails
* @throws ResourceNotFound if the resource does not exist in the infrastructure
*/ */
protected abstract void addToScope() throws Exception; protected abstract void addToScope() throws ResourceNotFound, Exception;
/** /**
* Removes the resource from the scope * Removes the resource from the scope
* @throws Exception if the operation fails * @throws Exception if the operation fails
* @throws ResourceNotFound if the resource does not exist in the infrastructure
*/ */
protected abstract void removeFromScope() throws Exception; protected abstract void removeFromScope() throws ResourceNotFound, Exception;
/** /**
@ -130,7 +134,7 @@ public abstract class ScopedResource {
* @return the scope * @return the scope
*/ */
public GCUBEScope getScope() { public GCUBEScope getScope() {
return scope; return GCUBEScope.getScope(this.scope);
} }
/** /**
@ -155,6 +159,15 @@ public abstract class ScopedResource {
this.errorMessage = errorMessage; this.errorMessage = errorMessage;
} }
/**
* Updates the time the resource joined the scope
* @param time the new joint time
*/
public void setJointTime(Date time) {
this.jointTime = time;
}
private void setChanged() { private void setChanged() {
this.setLastModificationTime(Calendar.getInstance().getTime()); this.setLastModificationTime(Calendar.getInstance().getTime());
} }
@ -177,6 +190,10 @@ public abstract class ScopedResource {
this.hostedOn = hostedOn; this.hostedOn = hostedOn;
} }
public Date getJointTime() {
return jointTime;
}
public Date getLastModificationTime() { public Date getLastModificationTime() {
if (lastModificationTime == null) if (lastModificationTime == null)
this.setChanged(); this.setChanged();
@ -198,6 +215,7 @@ public abstract class ScopedResource {
* @param status the status to set * @param status the status to set
*/ */
public synchronized void setStatus(STATUS status) { public synchronized void setStatus(STATUS status) {
getLogger().trace(this.toString()+ ": status set to " + status);
this.status = status; this.status = status;
} }
@ -237,14 +255,14 @@ public abstract class ScopedResource {
* Gives up the operation on the resource * Gives up the operation on the resource
* @param message the error message to return * @param message the error message to return
* @param e the exception that generates the hopeless * @param e the exception that generates the hopeless
* @throws Exception the exception returned to the operation caller * @throws E the source exception
*/ */
protected void noHopeForMe(String message, Throwable e) throws Exception { protected <E extends Exception> void noHopeForMe(String message, E e) throws E {
logger.error(this.toString() +": Unable to manage the resource " + message ,e); getLogger().error(this.toString() +": Unable to manage the resource " + message ,e);
this.setStatus(STATUS.LOST); this.setStatus(STATUS.LOST);
this.success = false; this.success = false;
this.setErrorMessage(message); this.setErrorMessage(message);
throw new Exception(e); throw e;
} }
/** /**
@ -254,10 +272,28 @@ public abstract class ScopedResource {
public String toString() { public String toString() {
return "Resource [id=" + id return "Resource [id=" + id
+ ", type=" + type + ", type=" + type
+ ", lastModificationTime=" + lastModificationTime + ", timestamp=" + lastModificationTime
+ ", scope=" + scope.getName() + ", scope=" + scope
+ ", status=" + status + ", status=" + status
+ " hostedOn=" + hostedOn + "]"; + " hostedOn=" + hostedOn + "]";
} }
protected GCUBELog getLogger() {
if (this.logger == null)
logger=new GCUBELog(this);
return logger;
}
/** Unable to find the resource in the infrastructure*/
public class ResourceNotFound extends Exception {
public ResourceNotFound(String message) {super(message);}
public ResourceNotFound(Exception e) {
super(e);
}
private static final long serialVersionUID = -6111206113583291172L;
}
} }

View File

@ -20,15 +20,12 @@ import org.gcube.common.vremanagement.ghnmanager.stubs.service.GHNManagerService
import org.gcube.vremanagement.resourcemanager.impl.contexts.ServiceContext; import org.gcube.vremanagement.resourcemanager.impl.contexts.ServiceContext;
import org.gcube.vremanagement.resourcemanager.impl.deployment.VirtualNode; import org.gcube.vremanagement.resourcemanager.impl.deployment.VirtualNode;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/** /**
* Models a scoped {@link GCUBERunningInstance} * Models a scoped {@link GCUBERunningInstance}
* *
* @author Manuele Simi (ISTI-CNR) * @author Manuele Simi (ISTI-CNR)
* *
*/ */
@XStreamAlias("RunningInstance")
public final class ScopedRunningInstance extends ScopedResource { public final class ScopedRunningInstance extends ScopedResource {
public static final String TYPE = GCUBERunningInstance.TYPE; public static final String TYPE = GCUBERunningInstance.TYPE;
@ -51,7 +48,7 @@ public final class ScopedRunningInstance extends ScopedResource {
} }
@Override @Override
public void find() throws Exception { public void find() throws ResourceNotFound {
//looks for the RI to manage //looks for the RI to manage
try { try {
@ -72,7 +69,7 @@ public final class ScopedRunningInstance extends ScopedResource {
this.hostedOnID = profile.getGHNID(); this.hostedOnID = profile.getGHNID();
this.scopes = profile.getScopes().values(); this.scopes = profile.getScopes().values();
} catch (Exception e) { } catch (Exception e) {
this.noHopeForMe("unable to find the target RI (ID=" + id + ")", e); this.noHopeForMe("unable to find the target RI (ID=" + id + ")", new ResourceNotFound(e));
} }
//looks for the GHN to contact //looks for the GHN to contact
@ -83,7 +80,7 @@ public final class ScopedRunningInstance extends ScopedResource {
this.hostingNode = client.execute(query, ServiceContext.getContext().getScope()).get(0).getNodeDescription().getName(); this.hostingNode = client.execute(query, ServiceContext.getContext().getScope()).get(0).getNodeDescription().getName();
this.hostedOn = hostingNode; this.hostedOn = hostingNode;
} catch (Exception e) { } catch (Exception e) {
this.noHopeForMe("unable to find the hosting GHN (ID=" + this.hostedOnID + ")", e); this.noHopeForMe("unable to find the hosting GHN (ID=" + this.hostedOnID + ")", new ResourceNotFound(e));
} }
} }
@ -94,7 +91,7 @@ public final class ScopedRunningInstance extends ScopedResource {
* @throws Exception if it is not possible to add the resource * @throws Exception if it is not possible to add the resource
*/ */
@Override @Override
protected void addToScope() throws Exception { protected void addToScope() throws ResourceNotFound, Exception {
if (this.hostingNode.compareToIgnoreCase("") == 0) if (this.hostingNode.compareToIgnoreCase("") == 0)
this.find(); this.find();
EndpointReferenceType endpoint = new EndpointReferenceType(); EndpointReferenceType endpoint = new EndpointReferenceType();
@ -112,7 +109,7 @@ public final class ScopedRunningInstance extends ScopedResource {
this.setStatus(STATUS.LOST); this.setStatus(STATUS.LOST);
this.success = false; this.success = false;
this.setErrorMessage("Failed to add RunningInstance to scope " + scope.toString()); this.setErrorMessage("Failed to add RunningInstance to scope " + scope.toString());
logger.error("Failed to add RunningInstance to scope " + scope.toString(), e); getLogger().error("Failed to add RunningInstance to scope " + scope.toString(), e);
throw new Exception("Failed to add RunningInstance to scope " + scope.toString()); throw new Exception("Failed to add RunningInstance to scope " + scope.toString());
} }
@ -125,11 +122,11 @@ public final class ScopedRunningInstance extends ScopedResource {
* @throws Exception if it is not possible to remove the resource * @throws Exception if it is not possible to remove the resource
*/ */
@Override @Override
protected void removeFromScope() throws Exception { protected void removeFromScope() throws ResourceNotFound, Exception {
//if (this.hostingNode.compareToIgnoreCase("") == 0) //if (this.hostingNode.compareToIgnoreCase("") == 0)
this.find();//we always need to refresh the resource before to remove it from the scopes this.find();//we always need to refresh the resource before to remove it from the scopes
if (this.scopes.size() == 1) { if (this.scopes.size() == 1) {
logger.info("RI ("+this.getId()+") is only in this scope: it is going to be undeployed"); getLogger().info("RI ("+this.getId()+") is only in this scope: it is going to be undeployed");
try { try {
this.undeploy(); this.undeploy();
return; return;
@ -162,7 +159,7 @@ public final class ScopedRunningInstance extends ScopedResource {
*/ */
private void undeploy() throws Exception { private void undeploy() throws Exception {
//retrieving the related Service //retrieving the related Service
ScopedDeployedService service = (ScopedDeployedService)ScopedResourceFactory.newResource(this.sourceService.serviceID, GCUBEService.TYPE, scope); ScopedDeployedService service = (ScopedDeployedService)ScopedResourceFactory.newResource(this.sourceService.serviceID, GCUBEService.TYPE, GCUBEScope.getScope(scope));
service.removeFromScope(this.hostedOnID); service.removeFromScope(this.hostedOnID);
} }

View File

@ -101,7 +101,7 @@ public class PublishedScopeResource {
* @throws Exception * @throws Exception
*/ */
public void addResource(ScopedResource resource) throws Exception { public void addResource(ScopedResource resource) throws Exception {
this.publishedResourceList.add(resource.getId(), resource.getType(),resource.getLastModificationTime(), resource.getHostedOn()); this.publishedResourceList.add(resource.getId(), resource.getType(),resource.getJointTime(), resource.getHostedOn());
resource.setStatus(STATUS.PUBLISHED); resource.setStatus(STATUS.PUBLISHED);
} }
@ -468,12 +468,12 @@ public class PublishedScopeResource {
protected String id; protected String id;
protected String type; protected String type;
protected String hostedOn; protected String hostedOn;
protected Date lastModificationTime; protected Date timestamp;
protected Item(String id, String value, Date lastModificationTime, String ... hostedOn) { protected Item(String id, String value, Date timestamp, String ... hostedOn) {
this.id = id; this.id = id;
this.type = value; this.type = value;
this.lastModificationTime = lastModificationTime; this.timestamp = timestamp;
this.hostedOn = (hostedOn!=null && hostedOn.length>0) ? hostedOn[0] : null; this.hostedOn = (hostedOn!=null && hostedOn.length>0) ? hostedOn[0] : null;
} }
@ -526,6 +526,7 @@ public class PublishedScopeResource {
ScopedResource resource; ScopedResource resource;
try { try {
resource = ScopedResourceFactory.newResource(item.id, item.type, scope); resource = ScopedResourceFactory.newResource(item.id, item.type, scope);
resource.setJointTime(item.timestamp);
if ((item.hostedOn != null) && (item.hostedOn.compareTo("") != 0)) if ((item.hostedOn != null) && (item.hostedOn.compareTo("") != 0))
resource.setHostedON(item.hostedOn); resource.setHostedON(item.hostedOn);
temp.add(resource); temp.add(resource);
@ -552,7 +553,7 @@ public class PublishedScopeResource {
serializer.startTag(PublishedScopeResource.NS, "ResourceType").text(item.type).endTag(PublishedScopeResource.NS, "ResourceType"); serializer.startTag(PublishedScopeResource.NS, "ResourceType").text(item.type).endTag(PublishedScopeResource.NS, "ResourceType");
if ((item.hostedOn != null) && (item.hostedOn.compareTo("") != 0)) if ((item.hostedOn != null) && (item.hostedOn.compareTo("") != 0))
serializer.startTag(PublishedScopeResource.NS, "HostedOn").text(item.hostedOn).endTag(PublishedScopeResource.NS, "HostedOn"); serializer.startTag(PublishedScopeResource.NS, "HostedOn").text(item.hostedOn).endTag(PublishedScopeResource.NS, "HostedOn");
serializer.startTag(PublishedScopeResource.NS, "JointTime").text(ProfileDate.toXMLDateAndTime(item.lastModificationTime)).endTag(PublishedScopeResource.NS, "JointTime"); serializer.startTag(PublishedScopeResource.NS, "JointTime").text(ProfileDate.toXMLDateAndTime(item.timestamp)).endTag(PublishedScopeResource.NS, "JointTime");
serializer.endTag(PublishedScopeResource.NS, RESOURCE_ELEMENT); serializer.endTag(PublishedScopeResource.NS, RESOURCE_ELEMENT);
} }
serializer.endTag(PublishedScopeResource.NS, RESOURCES_ELEMENT); serializer.endTag(PublishedScopeResource.NS, RESOURCES_ELEMENT);

View File

@ -7,8 +7,6 @@ import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedResource; import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedResource;
import org.gcube.vremanagement.resourcemanager.impl.resources.types.MultiKeysMap; import org.gcube.vremanagement.resourcemanager.impl.resources.types.MultiKeysMap;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/** /**
* *
* The scope state. * The scope state.
@ -22,21 +20,17 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
* @author Manuele Simi (ISTI-CNR) * @author Manuele Simi (ISTI-CNR)
* *
*/ */
@XStreamAlias("RawScopeState")
public class RawScopeState { public class RawScopeState {
/** the scope this state belongs to*/ /** the scope this state belongs to*/
@XStreamAlias("Scope") protected String scope;
protected GCUBEScope scope;
/** the list of resources */ /** the list of resources */
@XStreamAlias("Resources")
protected MultiKeysMap<String, String, ScopedResource> resources; protected MultiKeysMap<String, String, ScopedResource> resources;
//Open structure for information to store. By using it, we will avoid to broke XSTREAM serialization //Open structure for information to store. By using it, we will avoid to broke XSTREAM serialization
//when we need to add more information to the class //when we need to add more information to the class
/** any data belonging the state worthy to be serialized*/ /** any data belonging the state worthy to be serialized*/
@XStreamAlias("Data")
protected Map<String, Object> data; protected Map<String, Object> data;
protected RawScopeState () {} protected RawScopeState () {}
@ -48,14 +42,14 @@ public class RawScopeState {
protected void initialize(final GCUBEScope scope) { protected void initialize(final GCUBEScope scope) {
resources = new MultiKeysMap<String, String, ScopedResource>(); resources = new MultiKeysMap<String, String, ScopedResource>();
data = new HashMap<String, Object>(); data = new HashMap<String, Object>();
this.scope = scope; this.scope = scope.toString();
} }
/** /**
* @return the scope this state belongs to * @return the scope this state belongs to
*/ */
public GCUBEScope getScope() { public GCUBEScope getScope() {
return scope; return GCUBEScope.getScope(this.scope);
} }

View File

@ -174,7 +174,7 @@ public class ScopeState extends Observable {
* @return the scope * @return the scope
*/ */
public GCUBEScope getScope() { public GCUBEScope getScope() {
return rawState.scope; return rawState.getScope();
} }
public void notifyObservers(Object whatschanged) { public void notifyObservers(Object whatschanged) {

View File

@ -2,6 +2,7 @@ package org.gcube.vremanagement.resourcemanager.impl.state.observers;
import org.gcube.vremanagement.resourcemanager.impl.operators.Operator.ACTION; import org.gcube.vremanagement.resourcemanager.impl.operators.Operator.ACTION;
import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedResource; import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedResource;
import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedResource.ResourceNotFound;
import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedResource.STATUS; import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedResource.STATUS;
import org.gcube.vremanagement.resourcemanager.impl.state.ScopeState; import org.gcube.vremanagement.resourcemanager.impl.state.ScopeState;
import org.gcube.vremanagement.resourcemanager.impl.state.ScopeState.OPERATION; import org.gcube.vremanagement.resourcemanager.impl.state.ScopeState.OPERATION;
@ -39,6 +40,9 @@ public class Executor extends ScopeObserver {
try { try {
resource.doAction(ACTION.ADD); resource.doAction(ACTION.ADD);
resource.setStatus(STATUS.ADDED); resource.setStatus(STATUS.ADDED);
} catch (ResourceNotFound e) {
//the resource does not exist..it will be removed from the internal state
resource.setStatus(STATUS.REMOVED);
} catch (Exception e) { } catch (Exception e) {
resource.setStatus(STATUS.LOST); resource.setStatus(STATUS.LOST);
} }
@ -50,9 +54,12 @@ public class Executor extends ScopeObserver {
try { try {
resource.doAction(ACTION.REMOVE); resource.doAction(ACTION.REMOVE);
resource.setStatus(STATUS.REMOVED); resource.setStatus(STATUS.REMOVED);
} catch (ResourceNotFound e) {
//tolerate this exception... anyway it will be removed from the internal state
resource.setStatus(STATUS.REMOVED);
} catch (Exception e) { } catch (Exception e) {
//can't cope with this exception and don't know what to do
resource.setStatus(STATUS.LOST); resource.setStatus(STATUS.LOST);
} }
} }
} }

View File

@ -4,14 +4,23 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Map;
import org.gcube.common.core.scope.GCUBEScope; import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.vremanagement.resourcemanager.impl.contexts.ServiceContext; import org.gcube.vremanagement.resourcemanager.impl.contexts.ServiceContext;
import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedAnyResource;
import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedDeployedService;
import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedGHN;
import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedResource; import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedResource;
import org.gcube.vremanagement.resourcemanager.impl.resources.ScopedRunningInstance;
import org.gcube.vremanagement.resourcemanager.impl.resources.types.MultiKeysMap;
import org.gcube.vremanagement.resourcemanager.impl.state.RawScopeState; import org.gcube.vremanagement.resourcemanager.impl.state.RawScopeState;
import org.gcube.vremanagement.resourcemanager.impl.state.ScopeState; import org.gcube.vremanagement.resourcemanager.impl.state.ScopeState;
import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.QNameMap;
import com.thoughtworks.xstream.io.xml.StaxDriver;
import javax.xml.namespace.QName;
/** /**
* *
@ -22,7 +31,9 @@ import com.thoughtworks.xstream.XStream;
*/ */
public class Serializer extends ScopeObserver { public class Serializer extends ScopeObserver {
final public static File persistentList = ServiceContext.getContext().getPersistentFile("ScopedResourceList.xml", true); public final static File persistentList = ServiceContext.getContext().getPersistentFile("ScopedResourceList.xml", true);
private final static String namespace = "http://gcube-system.org/namespaces/resourcemanager/manager/xsd/state";
/** /**
* Serializes the notified list on the file system * Serializes the notified list on the file system
* @param scopeState the list to serialize * @param scopeState the list to serialize
@ -40,8 +51,14 @@ public class Serializer extends ScopeObserver {
} }
public synchronized static void store(final ScopeState scopeState) throws IOException { public synchronized static void store(final ScopeState scopeState) throws IOException {
XStream stream = new XStream();
stream.processAnnotations(RawScopeState.class); QNameMap qmap = new QNameMap();
qmap.registerMapping(new QName(namespace, ""), RawScopeState.class);
StaxDriver driver = new StaxDriver(qmap);
driver.setRepairingNamespace(false);
XStream stream = new XStream(driver);
prepareStream(stream);
FileOutputStream fs = new FileOutputStream(persistentList); FileOutputStream fs = new FileOutputStream(persistentList);
stream.toXML(scopeState.getRawScopeState(), fs); stream.toXML(scopeState.getRawScopeState(), fs);
fs.close(); fs.close();
@ -58,8 +75,13 @@ public class Serializer extends ScopeObserver {
throw new IOException(); throw new IOException();
//try to load the local list of resources //try to load the local list of resources
XStream stream = new XStream(); QNameMap qmap = new QNameMap();
stream.processAnnotations(RawScopeState.class); qmap.registerMapping(new QName(namespace, ""), RawScopeState.class);
StaxDriver driver = new StaxDriver(qmap);
driver.setRepairingNamespace(false);
XStream stream = new XStream(driver);
prepareStream(stream);
RawScopeState state = (RawScopeState) stream.fromXML(new FileInputStream((persistentList))); RawScopeState state = (RawScopeState) stream.fromXML(new FileInputStream((persistentList)));
//a bit of sanity checks.... //a bit of sanity checks....
@ -69,4 +91,30 @@ public class Serializer extends ScopeObserver {
//inject the state //inject the state
scopeState.setRawScopeState(state); scopeState.setRawScopeState(state);
} }
private static void prepareStream(XStream stream) {
stream.processAnnotations(RawScopeState.class);
stream.alias(RawScopeState.class.getSimpleName(), RawScopeState.class);
stream.processAnnotations(ScopedResource.class);
stream.alias(ScopedResource.class.getSimpleName(), ScopedResource.class);
stream.alias(ScopedGHN.class.getSimpleName(), ScopedGHN.class);
stream.processAnnotations(ScopedGHN.class);
stream.alias(ScopedRunningInstance.class.getSimpleName(), ScopedRunningInstance.class);
stream.processAnnotations(ScopedRunningInstance.class);
stream.alias(ScopedDeployedService.class.getSimpleName(), ScopedDeployedService.class);
stream.processAnnotations(ScopedDeployedService.class);
stream.alias(ScopedAnyResource.class.getSimpleName(), ScopedAnyResource.class);
stream.processAnnotations(ScopedAnyResource.class);
stream.alias("ResourceList", MultiKeysMap.class);
stream.alias("ResourceData", Map.class);
stream.alias("Scope", GCUBEScope.class);
stream.alias("ScopeType", GCUBEScope.Type.class);
}
} }