New Timer for long sessions, NodeList initialization starting from rawscope fixed

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vre-management/ResourceManager@59210 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Manuele Simi 2012-09-28 14:11:49 +00:00
parent 9c8462d5e8
commit 934f8b8ae8
5 changed files with 82 additions and 10 deletions

View File

@ -74,7 +74,7 @@ public class ServiceContext extends GCUBEServiceContext {
@Override
protected boolean repeat(Exception exception, int exceptionCount) {
if (exception!=null) {
logger.warn("Failed to create the vre manager resource (attempt "+exceptionCount+" out of 20)",exception);
logger.warn("Failed to create the ResourceManager resource (attempt "+exceptionCount+" out of 20)",exception);
if (exceptionCount >= 20) {
logger.error("Max attempts reached, no more chance to register the ResourceManager resource, the service startup failed");
ServiceContext.getContext().setStatus(GCUBEServiceContext.Status.FAILED);

View File

@ -93,7 +93,7 @@ public class DeploySoftwareOperator extends Operator {
Thread.sleep(5000);
} catch (InterruptedException e) {}
//checking if the session is closed and we need to send feedback
if ((tsession.isReportClosed()
if ((tsession.isSessionClosed()
&& ((tsession.getOperation()==OPERATION.AddResources)
|| (tsession.getOperation()==OPERATION.UpdateResources)
|| (tsession.getOperation()==OPERATION.Create)))) {
@ -114,7 +114,8 @@ public class DeploySoftwareOperator extends Operator {
if(softwareToUndeploy.size() > 0)
this.configuration.scopeState.removeResources(softwareToUndeploy);
this.configuration.session.save();
this.configuration.session.save();
this.configuration.session.startChecker();
}
/**

View File

@ -14,6 +14,8 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.utils.logging.GCUBELog;
@ -76,6 +78,12 @@ public class Session implements Serializable {
private String deploymentPlan;
private Timer timer;
boolean forcedToBeClosed = false;
String sessionErrorMessage = "";
/** internally used by {@link Session#loadAsString(String)}*/
private Session () {}
@ -89,7 +97,8 @@ public class Session implements Serializable {
if ((scope == null)|| (scope[0] == null))
this.scope = ServiceContext.getContext().getInstance().getScopes().values().iterator().next();
else
this.scope = scope[0];
this.scope = scope[0];
timer = new Timer("SessionTimer"+id);
}
/**
@ -123,7 +132,12 @@ public class Session implements Serializable {
serializer.startDocument("UTF-8", true);
serializer.startTag(NS,"ResourceReport");
serializer.startTag(NS,"ID").text(this.id).endTag(NS, "ID");
serializer.startTag(NS,"Status").text(this.isReportClosed()?"CLOSED" :"OPEN").endTag(NS, "Status");
if (this.forcedToBeClosed) {
serializer.startTag(NS,"Status").text("CLOSED").endTag(NS, "Status");
serializer.startTag(NS,"SessionError").text(this.sessionErrorMessage).endTag(NS, "SessionError");
} else {
serializer.startTag(NS,"Status").text(this.isSessionClosed()?"CLOSED" :"OPEN").endTag(NS, "Status");
}
serializer.startTag(NS,"Operation").text(this.operation.toString()).endTag(NS, "Operation");
serializer.startTag(NS,"LastUpdate").text(ProfileDate.toXMLDateAndTime(this.lastUpdate.getTime())).endTag(NS,"LastUpdate");
serializer.startTag(NS,"TargetScope").text(this.scope.toString()).endTag(NS,"TargetScope");
@ -415,7 +429,7 @@ public class Session implements Serializable {
* Checks whether the report is closed or no
* @return true if the report is closed, false otherwise
*/
public boolean isReportClosed() {
public boolean isSessionClosed() {
for ( ScopedResource resource : this.resources) {
if ((resource.getStatus() == STATUS.ADDREQUESTED) || (resource.getStatus() == STATUS.REMOVEREQUESTED))
@ -464,5 +478,54 @@ public class Session implements Serializable {
throw new IOException("No Deployment Plan is available");
return this.deploymentPlan;
}
/**
* Starts the session checker
*/
public void startChecker() {
logger.debug("Starting the Session Checker");
try {
this.timer.schedule(new SessionChecker(), 600000);
} catch (Exception e) {logger.warn("Session Checker was not started (timer already cancelled)");}
}
class SessionChecker extends TimerTask {
@Override
public void run() {
Session.this.logger.debug("Session Checker woke up");
//check if there is nothing to do
if (Session.this.isSessionClosed()) {try {this.cancel(); return;} catch (Exception e) {}}
for ( ScopedResource resource : Session.this.resources) {
if ((resource.getStatus() == STATUS.ADDREQUESTED)
|| (resource.getStatus() == STATUS.REMOVEREQUESTED)) {
//the resource has not been managed
resource.setStatus(STATUS.LOST);
resource.setErrorMessage("The resource was not managed properly in a reasonable time (10 mins)");
}
}
for (ScopedDeployedSoftware service : Session.this.services) {
String reportHostName = service.getTargetNodeName();
if (service.isSuccess() && (Session.this.brokerWasSuccessful)) {
//check the availability of the report and its status
if (! node2report.keySet().contains(reportHostName)) {
Session.this.forcedToBeClosed = true;
Session.this.sessionErrorMessage = "Node " + reportHostName + " did not send any report on time";
Session.this.logger.debug("Session Checker forced the session to close:" + Session.this.sessionErrorMessage);;
} else if (node2report.get(reportHostName).getStatus().compareToIgnoreCase("CLOSED") != 0){
Session.this.forcedToBeClosed = true;
Session.this.sessionErrorMessage = "Report from node " + reportHostName + " was not closed on time";
Session.this.logger.debug("Session Checker forced the session to close:" + Session.this.sessionErrorMessage);;
}
}
}
try {
logger.debug("Cancelling the Session Checker");
this.cancel();
} catch (Exception e) {}
}
}
}

View File

@ -217,10 +217,15 @@ public class GCUBEPackage {
builder.append(this.getName());
builder.append('-');
builder.append(this.getVersion());
builder.append('-');
builder.append(this.getPackageName());
builder.append('-');
builder.append(this.getPackageVersion());
//the following two may be null in case of service deployments
if (this.getPackageName() != null) {
builder.append('-');
builder.append(this.getPackageName());
}
if (this.getPackageVersion() != null) {
builder.append('-');
builder.append(this.getPackageVersion());
}
return builder.toString();
}

View File

@ -313,6 +313,9 @@ public final class ScopeState extends Observable {
*/
public void setRawScopeState(RawScopeState state) {
this.rawState = state;
this.nodes = new VirtualNodeList(state.getScope());
this.nodes.loadFromState(this.rawState);
this.lastOperationPerformed = OPERATION.CREATED;
}