diff --git a/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/contexts/ServiceContext.java b/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/contexts/ServiceContext.java index 44d9d22..8780a8f 100644 --- a/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/contexts/ServiceContext.java +++ b/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/contexts/ServiceContext.java @@ -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); diff --git a/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/operators/DeploySoftwareOperator.java b/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/operators/DeploySoftwareOperator.java index 6a347b6..cfd88f7 100644 --- a/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/operators/DeploySoftwareOperator.java +++ b/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/operators/DeploySoftwareOperator.java @@ -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(); } /** diff --git a/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/reporting/Session.java b/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/reporting/Session.java index 16ee6b9..688f714 100644 --- a/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/reporting/Session.java +++ b/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/reporting/Session.java @@ -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) {} + } + + } } diff --git a/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/resources/software/GCUBEPackage.java b/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/resources/software/GCUBEPackage.java index b719580..3037e2d 100644 --- a/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/resources/software/GCUBEPackage.java +++ b/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/resources/software/GCUBEPackage.java @@ -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(); } diff --git a/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/state/ScopeState.java b/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/state/ScopeState.java index 3d08ca3..21e3b9e 100644 --- a/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/state/ScopeState.java +++ b/resource-manager-service/src/main/java/org/gcube/vremanagement/resourcemanager/impl/state/ScopeState.java @@ -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; }