git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vre-management/ResourceManager@19260 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
fd37f0d003
commit
7a627ed003
|
@ -154,16 +154,12 @@
|
|||
<message name="AddResourcesInputMessage">
|
||||
<part name="request" element="tns:addResourcesParameters"/>
|
||||
</message>
|
||||
<message name="AddResourcesResponseMessage">
|
||||
<message name="ReportID">
|
||||
<part name="request" element="tns:reportID"/>
|
||||
</message>
|
||||
<message name="RemoveResourcesInputMessage">
|
||||
<part name="request" element="tns:removeResourcesParameters"/>
|
||||
</message>
|
||||
<message name="RemoveResourcesResponseMessage">
|
||||
<part name="request" element="tns:reportID"/>
|
||||
</message>
|
||||
|
||||
<message name="SendReportInputMessage">
|
||||
<part name="request" element="tns:sendReportParameters"/>
|
||||
</message>
|
||||
|
@ -196,13 +192,13 @@
|
|||
|
||||
<operation name="AddResources">
|
||||
<input message="tns:AddResourcesInputMessage"/>
|
||||
<output message="tns:AddResourcesResponseMessage"/>
|
||||
<output message="tns:ReportID"/>
|
||||
<fault name="fault" message="corefaults:GCUBEFaultMessage"/>
|
||||
</operation>
|
||||
|
||||
<operation name="RemoveResources">
|
||||
<input message="tns:RemoveResourcesInputMessage"/>
|
||||
<output message="tns:RemoveResourcesResponseMessage"/>
|
||||
<output message="tns:ReportID"/>
|
||||
<fault name="fault" message="corefaults:GCUBEFaultMessage"/>
|
||||
</operation>
|
||||
|
||||
|
@ -214,7 +210,7 @@
|
|||
|
||||
<operation name="DisposeScope">
|
||||
<input message="tns:DisposeScopeInputMessage"/>
|
||||
<output message="tns:VoidMessage"/>
|
||||
<output message="tns:ReportID"/>
|
||||
<fault name="fault" message="corefaults:GCUBEFaultMessage"/>
|
||||
</operation>
|
||||
|
||||
|
|
|
@ -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.SendReportParameters;
|
||||
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.RemoveResourcesOperator;
|
||||
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.PublishedScopeResource;
|
||||
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.globus.wsrf.NoSuchResourceException;
|
||||
import org.globus.wsrf.ResourceException;
|
||||
|
@ -56,7 +58,7 @@ public class ResourceManager extends GCUBEPortType {
|
|||
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
|
||||
* @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
|
||||
* @throws GCUBEFault if the operation fails
|
||||
|
@ -91,15 +93,10 @@ public class ResourceManager extends GCUBEPortType {
|
|||
public String removeResources(RemoveResourcesParameters resourceList) throws GCUBEFault {
|
||||
|
||||
try {
|
||||
//PublishedScopeResource resource = this.getResource().getPublishedScopeResource();
|
||||
//resource.reload();
|
||||
|
||||
GCUBEScope targetScope = this.validateOperationScope(resourceList.getTargetScope());
|
||||
ResourceReport report = new ResourceReport(UUIDGenFactory.getUUIDGen().nextUUID(), targetScope);
|
||||
this.getResource().addReport(report);
|
||||
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();
|
||||
} catch (IllegalScopeException 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!!");
|
||||
try {
|
||||
ResourceReport report = new ResourceReport(UUIDGenFactory.getUUIDGen().nextUUID(), this.getResource().getManagedScope());
|
||||
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) {
|
||||
logger.error("No resource found for this scope", e);
|
||||
throw ServiceContext.getContext().getDefaultException("No resource found for this scope", e).toFault();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
logger.error("Unable to dispose the scope: " + e.getMessage(), e);
|
||||
throw ServiceContext.getContext().getDefaultException("Unable to dispose the scope: " + e.getMessage(), e).toFault();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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.publisher.ISPublisher;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamOmitField;
|
||||
|
||||
|
||||
|
@ -37,7 +36,6 @@ import com.thoughtworks.xstream.annotations.XStreamOmitField;
|
|||
* @author Manuele Simi (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
@XStreamAlias("AnyResource")
|
||||
public final class ScopedAnyResource extends ScopedResource {
|
||||
|
||||
@XStreamOmitField
|
||||
|
@ -56,7 +54,7 @@ public final class ScopedAnyResource extends ScopedResource {
|
|||
*/
|
||||
@SuppressWarnings({ "unchecked"})
|
||||
@Override
|
||||
public void find() throws Exception {
|
||||
public void find() throws ResourceNotFound, Exception {
|
||||
ISClient client = GHNContext.getImplementation(ISClient.class);
|
||||
Class query = null;
|
||||
try {
|
||||
|
@ -71,22 +69,22 @@ public final class ScopedAnyResource extends ScopedResource {
|
|||
|
||||
ISTemplateQuery realquery = (ISTemplateQuery) client.getQuery(query);
|
||||
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))
|
||||
this.profile = profiles.get(0);
|
||||
else
|
||||
// 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) {
|
||||
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
|
||||
protected void addToScope() throws Exception {
|
||||
protected void addToScope() throws ResourceNotFound, Exception {
|
||||
this.find();
|
||||
logger.debug("Adding scope to resource's profile");
|
||||
getLogger().debug("Adding scope to resource profile");
|
||||
try {
|
||||
profile.addScope(this.getScope());
|
||||
//republish the resource
|
||||
|
@ -104,9 +102,9 @@ public final class ScopedAnyResource extends ScopedResource {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void removeFromScope() throws Exception {
|
||||
protected void removeFromScope() throws ResourceNotFound, Exception {
|
||||
this.find();
|
||||
logger.debug("Removing scope from resource's profile");
|
||||
getLogger().debug("Removing scope from resource profile");
|
||||
try {
|
||||
profile.removeScope(this.getScope());
|
||||
//republish the resource
|
||||
|
|
|
@ -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.Service;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
*
|
||||
* Models a scoped {@link GCUBEService}
|
||||
|
@ -24,7 +22,6 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|||
* @author Manuele Simi (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
@XStreamAlias("Service")
|
||||
public final class ScopedDeployedService extends ScopedResource {
|
||||
|
||||
public static final String TYPE = GCUBEService.TYPE;
|
||||
|
@ -88,7 +85,7 @@ public final class ScopedDeployedService extends ScopedResource {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void find() throws Exception {
|
||||
public void find() throws ResourceNotFound {
|
||||
//looks for the service and its deps in the Software Repository
|
||||
SoftwareRepositoryRequest request = new SoftwareRepositoryRequest();
|
||||
request.addService(this);
|
||||
|
@ -104,15 +101,15 @@ public final class ScopedDeployedService extends ScopedResource {
|
|||
}
|
||||
this.success = true;
|
||||
} catch (Exception e) {
|
||||
logger.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);
|
||||
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, new ResourceNotFound(e));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void addToScope() throws Exception {
|
||||
protected void addToScope() throws ResourceNotFound, Exception {
|
||||
if (!this.isSuccess()) {
|
||||
this.noHopeForMe(this.getErrorMessage(),new Exception());
|
||||
}
|
||||
|
@ -130,7 +127,7 @@ public final class ScopedDeployedService extends ScopedResource {
|
|||
|
||||
|
||||
@Override
|
||||
protected void removeFromScope() throws Exception {
|
||||
protected void removeFromScope() throws ResourceNotFound, Exception {
|
||||
if (!this.isSuccess()) {
|
||||
//TODO: could we undeploy static packages here?
|
||||
this.noHopeForMe(this.getErrorMessage(),new Exception());
|
||||
|
@ -155,7 +152,7 @@ public final class ScopedDeployedService extends ScopedResource {
|
|||
* @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
|
||||
List<Dependency> deps = this.getResolvedDependencies();
|
||||
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.setVersion(deps.get(i).getVersion());
|
||||
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);
|
||||
}
|
||||
node.removePackages(this.packages);
|
||||
|
@ -192,7 +189,7 @@ public final class ScopedDeployedService extends ScopedResource {
|
|||
* @param node the target GHN
|
||||
*/
|
||||
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();
|
||||
|
||||
Set<PackageInfo> packages = new HashSet<PackageInfo>();
|
||||
|
@ -205,7 +202,7 @@ public final class ScopedDeployedService extends ScopedResource {
|
|||
p.setServiceVersion(deps.get(i).getService().getVersion());
|
||||
p.setVersion(deps.get(i).getVersion());
|
||||
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);
|
||||
}
|
||||
node.addPackages(packages);
|
||||
|
|
|
@ -14,18 +14,14 @@ import org.gcube.common.vremanagement.ghnmanager.stubs.GHNManagerPortType;
|
|||
import org.gcube.common.vremanagement.ghnmanager.stubs.service.GHNManagerServiceAddressingLocator;
|
||||
import org.gcube.vremanagement.resourcemanager.impl.contexts.ServiceContext;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
* Models a scoped {@link GCUBEHostingNode}
|
||||
*
|
||||
* @author Manuele Simi (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
@XStreamAlias("GHN")
|
||||
public final class ScopedGHN extends ScopedResource {
|
||||
|
||||
|
||||
public static final String TYPE = GCUBEHostingNode.TYPE;
|
||||
|
||||
private String nodename = "";
|
||||
|
@ -36,7 +32,7 @@ public final class ScopedGHN extends ScopedResource {
|
|||
|
||||
|
||||
@Override
|
||||
protected void addToScope() throws Exception {
|
||||
protected void addToScope() throws ResourceNotFound, Exception {
|
||||
if (this.nodename.compareToIgnoreCase("") == 0)
|
||||
this.find();
|
||||
//contact the GHNManager to add the GHN to the given scope
|
||||
|
@ -58,7 +54,7 @@ public final class ScopedGHN extends ScopedResource {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void find() throws Exception {
|
||||
public void find() throws ResourceNotFound {
|
||||
try {
|
||||
ISClient client = GHNContext.getImplementation(ISClient.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.hostedOn = nodename;
|
||||
} 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
|
||||
protected void removeFromScope() throws Exception {
|
||||
protected void removeFromScope() throws ResourceNotFound, Exception {
|
||||
if (this.nodename.compareToIgnoreCase("") == 0)
|
||||
this.find();
|
||||
EndpointReferenceType endpoint = new EndpointReferenceType();
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.gcube.common.core.utils.logging.GCUBELog;
|
|||
import org.gcube.vremanagement.resourcemanager.impl.operators.Operator.ACTION;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamOmitField;
|
||||
|
||||
/**
|
||||
* An abstract model for a scoped {@link GCUBEResource}
|
||||
|
@ -20,12 +21,11 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|||
* @author Manuele Simi (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
@XStreamAlias("ScopedResource")
|
||||
public abstract class ScopedResource {
|
||||
|
||||
|
||||
/** Object logger */
|
||||
protected final GCUBELog logger=new GCUBELog(this);
|
||||
/** Object getLogger() */
|
||||
@XStreamOmitField
|
||||
protected GCUBELog logger;
|
||||
|
||||
/** the resource identifier*/
|
||||
@XStreamAlias("ResourceID")
|
||||
|
@ -36,7 +36,6 @@ public abstract class ScopedResource {
|
|||
protected String type;
|
||||
|
||||
/** where the resource is hosted on, it makes sense for RI, GHN*/
|
||||
@XStreamAlias("HostedOn")
|
||||
protected String hostedOn = "";
|
||||
|
||||
/** result of the last operation performed on the resource */
|
||||
|
@ -47,8 +46,7 @@ public abstract class ScopedResource {
|
|||
@XStreamAlias("LastOperationMessage")
|
||||
protected String errorMessage = "";
|
||||
|
||||
@XStreamAlias("Scope")
|
||||
protected GCUBEScope scope;
|
||||
protected String scope;
|
||||
|
||||
/** the last action performed on the resource*/
|
||||
protected ACTION action;
|
||||
|
@ -57,6 +55,10 @@ public abstract class ScopedResource {
|
|||
@XStreamAlias("LastModificationTime")
|
||||
protected Date lastModificationTime;
|
||||
|
||||
/** Last modification time stamp*/
|
||||
@XStreamAlias("JointTime")
|
||||
protected Date jointTime;
|
||||
|
||||
@XStreamAlias("LastStatus")
|
||||
protected STATUS status;
|
||||
|
||||
|
@ -76,7 +78,7 @@ public abstract class ScopedResource {
|
|||
public ScopedResource(String id, String type, GCUBEScope scope) {
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.scope = scope;
|
||||
this.scope = scope.toString();
|
||||
this.status = STATUS.CREATED;
|
||||
}
|
||||
|
||||
|
@ -88,10 +90,10 @@ public abstract class ScopedResource {
|
|||
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;
|
||||
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;
|
||||
default: break;
|
||||
}
|
||||
|
@ -101,15 +103,17 @@ public abstract class ScopedResource {
|
|||
/**
|
||||
* Adds the resource to the scope
|
||||
* @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
|
||||
* @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
|
||||
*/
|
||||
public GCUBEScope getScope() {
|
||||
return scope;
|
||||
return GCUBEScope.getScope(this.scope);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,6 +159,15 @@ public abstract class ScopedResource {
|
|||
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() {
|
||||
this.setLastModificationTime(Calendar.getInstance().getTime());
|
||||
}
|
||||
|
@ -177,6 +190,10 @@ public abstract class ScopedResource {
|
|||
this.hostedOn = hostedOn;
|
||||
}
|
||||
|
||||
public Date getJointTime() {
|
||||
return jointTime;
|
||||
}
|
||||
|
||||
public Date getLastModificationTime() {
|
||||
if (lastModificationTime == null)
|
||||
this.setChanged();
|
||||
|
@ -198,6 +215,7 @@ public abstract class ScopedResource {
|
|||
* @param status the status to set
|
||||
*/
|
||||
public synchronized void setStatus(STATUS status) {
|
||||
getLogger().trace(this.toString()+ ": status set to " + status);
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
|
@ -237,14 +255,14 @@ public abstract class ScopedResource {
|
|||
* Gives up the operation on the resource
|
||||
* @param message the error message to return
|
||||
* @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 {
|
||||
logger.error(this.toString() +": Unable to manage the resource " + message ,e);
|
||||
protected <E extends Exception> void noHopeForMe(String message, E e) throws E {
|
||||
getLogger().error(this.toString() +": Unable to manage the resource " + message ,e);
|
||||
this.setStatus(STATUS.LOST);
|
||||
this.success = false;
|
||||
this.setErrorMessage(message);
|
||||
throw new Exception(e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -254,10 +272,28 @@ public abstract class ScopedResource {
|
|||
public String toString() {
|
||||
return "Resource [id=" + id
|
||||
+ ", type=" + type
|
||||
+ ", lastModificationTime=" + lastModificationTime
|
||||
+ ", scope=" + scope.getName()
|
||||
+ ", timestamp=" + lastModificationTime
|
||||
+ ", scope=" + scope
|
||||
+ ", status=" + status
|
||||
+ " 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.deployment.VirtualNode;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
* Models a scoped {@link GCUBERunningInstance}
|
||||
*
|
||||
* @author Manuele Simi (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
@XStreamAlias("RunningInstance")
|
||||
public final class ScopedRunningInstance extends ScopedResource {
|
||||
|
||||
public static final String TYPE = GCUBERunningInstance.TYPE;
|
||||
|
@ -51,7 +48,7 @@ public final class ScopedRunningInstance extends ScopedResource {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void find() throws Exception {
|
||||
public void find() throws ResourceNotFound {
|
||||
|
||||
//looks for the RI to manage
|
||||
try {
|
||||
|
@ -72,7 +69,7 @@ public final class ScopedRunningInstance extends ScopedResource {
|
|||
this.hostedOnID = profile.getGHNID();
|
||||
this.scopes = profile.getScopes().values();
|
||||
} 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
|
||||
|
@ -83,7 +80,7 @@ public final class ScopedRunningInstance extends ScopedResource {
|
|||
this.hostingNode = client.execute(query, ServiceContext.getContext().getScope()).get(0).getNodeDescription().getName();
|
||||
this.hostedOn = hostingNode;
|
||||
} 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
|
||||
*/
|
||||
@Override
|
||||
protected void addToScope() throws Exception {
|
||||
protected void addToScope() throws ResourceNotFound, Exception {
|
||||
if (this.hostingNode.compareToIgnoreCase("") == 0)
|
||||
this.find();
|
||||
EndpointReferenceType endpoint = new EndpointReferenceType();
|
||||
|
@ -112,7 +109,7 @@ public final class ScopedRunningInstance extends ScopedResource {
|
|||
this.setStatus(STATUS.LOST);
|
||||
this.success = false;
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -125,11 +122,11 @@ public final class ScopedRunningInstance extends ScopedResource {
|
|||
* @throws Exception if it is not possible to remove the resource
|
||||
*/
|
||||
@Override
|
||||
protected void removeFromScope() throws Exception {
|
||||
protected void removeFromScope() throws ResourceNotFound, Exception {
|
||||
//if (this.hostingNode.compareToIgnoreCase("") == 0)
|
||||
this.find();//we always need to refresh the resource before to remove it from the scopes
|
||||
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 {
|
||||
this.undeploy();
|
||||
return;
|
||||
|
@ -162,7 +159,7 @@ public final class ScopedRunningInstance extends ScopedResource {
|
|||
*/
|
||||
private void undeploy() throws Exception {
|
||||
//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);
|
||||
}
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ public class PublishedScopeResource {
|
|||
* @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);
|
||||
}
|
||||
|
||||
|
@ -468,12 +468,12 @@ public class PublishedScopeResource {
|
|||
protected String id;
|
||||
protected String type;
|
||||
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.type = value;
|
||||
this.lastModificationTime = lastModificationTime;
|
||||
this.timestamp = timestamp;
|
||||
this.hostedOn = (hostedOn!=null && hostedOn.length>0) ? hostedOn[0] : null;
|
||||
}
|
||||
|
||||
|
@ -526,6 +526,7 @@ public class PublishedScopeResource {
|
|||
ScopedResource resource;
|
||||
try {
|
||||
resource = ScopedResourceFactory.newResource(item.id, item.type, scope);
|
||||
resource.setJointTime(item.timestamp);
|
||||
if ((item.hostedOn != null) && (item.hostedOn.compareTo("") != 0))
|
||||
resource.setHostedON(item.hostedOn);
|
||||
temp.add(resource);
|
||||
|
@ -552,7 +553,7 @@ public class PublishedScopeResource {
|
|||
serializer.startTag(PublishedScopeResource.NS, "ResourceType").text(item.type).endTag(PublishedScopeResource.NS, "ResourceType");
|
||||
if ((item.hostedOn != null) && (item.hostedOn.compareTo("") != 0))
|
||||
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, RESOURCES_ELEMENT);
|
||||
|
|
|
@ -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.types.MultiKeysMap;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
*
|
||||
* The scope state.
|
||||
|
@ -22,21 +20,17 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|||
* @author Manuele Simi (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
@XStreamAlias("RawScopeState")
|
||||
public class RawScopeState {
|
||||
|
||||
/** the scope this state belongs to*/
|
||||
@XStreamAlias("Scope")
|
||||
protected GCUBEScope scope;
|
||||
protected String scope;
|
||||
|
||||
/** the list of resources */
|
||||
@XStreamAlias("Resources")
|
||||
protected MultiKeysMap<String, String, ScopedResource> resources;
|
||||
|
||||
//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
|
||||
/** any data belonging the state worthy to be serialized*/
|
||||
@XStreamAlias("Data")
|
||||
protected Map<String, Object> data;
|
||||
|
||||
protected RawScopeState () {}
|
||||
|
@ -48,14 +42,14 @@ public class RawScopeState {
|
|||
protected void initialize(final GCUBEScope scope) {
|
||||
resources = new MultiKeysMap<String, String, ScopedResource>();
|
||||
data = new HashMap<String, Object>();
|
||||
this.scope = scope;
|
||||
this.scope = scope.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the scope this state belongs to
|
||||
*/
|
||||
public GCUBEScope getScope() {
|
||||
return scope;
|
||||
return GCUBEScope.getScope(this.scope);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -174,7 +174,7 @@ public class ScopeState extends Observable {
|
|||
* @return the scope
|
||||
*/
|
||||
public GCUBEScope getScope() {
|
||||
return rawState.scope;
|
||||
return rawState.getScope();
|
||||
}
|
||||
|
||||
public void notifyObservers(Object whatschanged) {
|
||||
|
|
|
@ -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.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.state.ScopeState;
|
||||
import org.gcube.vremanagement.resourcemanager.impl.state.ScopeState.OPERATION;
|
||||
|
@ -39,6 +40,9 @@ public class Executor extends ScopeObserver {
|
|||
try {
|
||||
resource.doAction(ACTION.ADD);
|
||||
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) {
|
||||
resource.setStatus(STATUS.LOST);
|
||||
}
|
||||
|
@ -50,9 +54,12 @@ public class Executor extends ScopeObserver {
|
|||
try {
|
||||
resource.doAction(ACTION.REMOVE);
|
||||
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) {
|
||||
//can't cope with this exception and don't know what to do
|
||||
resource.setStatus(STATUS.LOST);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,14 +4,23 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
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.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.ScopeState;
|
||||
|
||||
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 {
|
||||
|
||||
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
|
||||
* @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 {
|
||||
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);
|
||||
stream.toXML(scopeState.getRawScopeState(), fs);
|
||||
fs.close();
|
||||
|
@ -58,8 +75,13 @@ public class Serializer extends ScopeObserver {
|
|||
throw new IOException();
|
||||
|
||||
//try to load the local list of resources
|
||||
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);
|
||||
|
||||
RawScopeState state = (RawScopeState) stream.fromXML(new FileInputStream((persistentList)));
|
||||
|
||||
//a bit of sanity checks....
|
||||
|
@ -69,4 +91,30 @@ public class Serializer extends ScopeObserver {
|
|||
//inject the 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);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue