diff --git a/pom.xml b/pom.xml index aba0b86..5414c49 100644 --- a/pom.xml +++ b/pom.xml @@ -34,12 +34,22 @@ UTF-8 UTF-8 + + + + org.gcube.distribution + maven-portal-bom + LATEST + pom + import + + + com.google.gwt gwt-user - ${gwtVersion} provided @@ -53,7 +63,11 @@ org.gcube.resources.discovery ic-client - 1.0.1-SNAPSHOT + + + org.gcube.core + common-scope-maps + [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) org.gcube.resourcemanagement @@ -73,18 +87,15 @@ org.gcube.resourcemanagement ghnmanager-stubs - [1.5.0-SNAPSHOT, 2.0.0-SNAPSHOT) log4j log4j - 1.2.16 com.thoughtworks.xstream xstream - 1.3.1 provided diff --git a/src/main/java/org/gcube/resourcemanagement/support/client/views/ResourceTypeDecorator.java b/src/main/java/org/gcube/resourcemanagement/support/client/views/ResourceTypeDecorator.java index 485e9bb..34c0b87 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/client/views/ResourceTypeDecorator.java +++ b/src/main/java/org/gcube/resourcemanagement/support/client/views/ResourceTypeDecorator.java @@ -55,11 +55,11 @@ public enum ResourceTypeDecorator { /**************************************** * Models for SWEEPER ***************************************/ - Sweeper_GHN("gCube Hosting Node", "ghn-icon",""), - Sweeper_RI("Running Instance", "runninginstance-icon",""), - Sweeper_RI_Orphan("Orphan Running Instance", "orphan-runninginstance-icon",""), - Sweeper_GHN_Expired("Expired gHN", "expired-ghn-icon",""), - Sweeper_GHN_Dead("Dead gHN", "dead-ghn-icon",""); + Sweeper_GHN("gCube Hosting Node", "ghn-icon","Hosting Node"), + Sweeper_RI("Running Instance", "runninginstance-icon", "GCore Endpoint"), + Sweeper_RI_Orphan("Orphan Running Instance", "orphan-runninginstance-icon", "Orphan GCore Endpoint"), + Sweeper_GHN_Expired("Expired gHN", "expired-ghn-icon", "Expired Nodes"), + Sweeper_GHN_Dead("Dead gHN", "dead-ghn-icon", "Unreachable Nodes"); private String fwsName = null; diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/QueryLocation.java b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/QueryLocation.java index bd68a9c..0dcd817 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/QueryLocation.java +++ b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/QueryLocation.java @@ -64,8 +64,13 @@ public enum QueryLocation { // Queries for sweeper SWEEPER_EXPIRED_GHN("sweeper/expiredGhns.xq"), + RETURN_SWEEPER_EXPIRED_GHN("sweeper/RETURN_expiredGhns.xq"), + SWEEPER_DEAD_GHN("sweeper/deadGhns.xq"), + RETURN_SWEEPER_DEAD_GHN("sweeper/RETURN_deadGhns.xq"), + SWEEPER_ORPHAN_RI("sweeper/orphanRI.xq"), + RETURN_SWEEPER_ORPHAN_RI("sweeper/RETURN_orphanRI.xq"), // Used to build the gwt model representation inside dialogs. // see getResourceModels inside ISClientRequester. diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/RETURN_deadGhns.xq b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/RETURN_deadGhns.xq new file mode 100644 index 0000000..8388ec3 --- /dev/null +++ b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/RETURN_deadGhns.xq @@ -0,0 +1,14 @@ + + {$GHNs/ID} + {$GHNs/Profile/GHNDescription/Name} + {$GHNs/Profile/GHNDescription/Status} + {$GHNs/Profile/GHNDescription/Type} + {$GHNs/Profile/Site/Location} + {$GHNs/Profile/Site/Domain} + {$GHNs/Profile/GHNDescription/NetworkAdapter/@IPAddress/string()} + {$scopes} + {count($RIinstalled)} + {$GHNs/Profile/GHNDescription/LastUpdate} + {$totalminutes} + APPLY_GHN_DELETE + \ No newline at end of file diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/RETURN_expiredGhns.xq b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/RETURN_expiredGhns.xq new file mode 100644 index 0000000..93edbd0 --- /dev/null +++ b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/RETURN_expiredGhns.xq @@ -0,0 +1,13 @@ + + {$GHNs/ID} + {$GHNs/Profile/GHNDescription/Name} + {$GHNs/Profile/GHNDescription/Status} + {$GHNs/Profile/GHNDescription/Type} + {$GHNs/Profile/Site/Location} + {$GHNs/Profile/Site/Domain} + {$GHNs/Profile/GHNDescription/NetworkAdapter/@IPAddress/string()} + {$scopes} + {count($RIinstalled)} + {$GHNs/Profile/GHNDescription/LastUpdate} + APPLY_GHN_MOVE_TO_UNREACHABLE + \ No newline at end of file diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/RETURN_orphanRI.xq b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/RETURN_orphanRI.xq new file mode 100644 index 0000000..3f1ff75 --- /dev/null +++ b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/RETURN_orphanRI.xq @@ -0,0 +1,9 @@ + + {$ri//Resource/ID/string()} + {$ri/Profile/DeploymentData/Status/string()} + {$ri/Profile/DeploymentData/ActivationTime/@value/string()} + {$ri/Profile/GHN/@UniqueID/string()} + {$ri/Profile/ServiceClass/string()} + {$ri/Profile/ServiceName/string()} + APPLY_RI_DELETE + \ No newline at end of file diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/deadGhns.xq b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/deadGhns.xq index 86d266e..6cbf401 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/deadGhns.xq +++ b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/deadGhns.xq @@ -10,20 +10,4 @@ let $RIinstalled := $RIs[Profile/GHN/string(@UniqueID)=$GHNs/ID] let $scopes := string-join( $GHNs/Scopes//Scope/text(), ';') where ($GHNs/Profile/GHNDescription/Status/string() eq 'down' or $GHNs/Profile/GHNDescription/Status/string() eq 'unreachable') return - - {$GHNs/ID} - {$GHNs/Profile/GHNDescription/Name} - {$GHNs/Profile/GHNDescription/Status} - {$GHNs/Profile/GHNDescription/Type} - {$GHNs/Profile/Site/Location} - {$GHNs/Profile/Site/Domain} - {$GHNs/Profile/GHNDescription/NetworkAdapter/@IPAddress/string()} - - {$scopes} - {count($RIinstalled)} - {$GHNs/Profile/GHNDescription/LastUpdate} - {$totalminutes} - - \ No newline at end of file + \ No newline at end of file diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/expiredGhns.xq b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/expiredGhns.xq index 327987b..ff9b32c 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/expiredGhns.xq +++ b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/expiredGhns.xq @@ -9,19 +9,4 @@ let $RIinstalled := $RIs[Profile/GHN/string(@UniqueID)=$GHNs/ID] let $scopes := string-join( $GHNs/Scopes//Scope/text(), ';') where $GHNs/Profile/GHNDescription/Status/string() != 'down' and $GHNs/Profile/GHNDescription/Status/string() != 'unreachable' return - - {$GHNs/ID} - {$GHNs/Profile/GHNDescription/Name} - {$GHNs/Profile/GHNDescription/Status} - {$GHNs/Profile/GHNDescription/Type} - {$GHNs/Profile/Site/Location} - {$GHNs/Profile/Site/Domain} - {$GHNs/Profile/GHNDescription/NetworkAdapter/@IPAddress/string()} - - {$scopes} - {count($RIinstalled)} - {$GHNs/Profile/GHNDescription/LastUpdate} - - \ No newline at end of file + \ No newline at end of file diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/orphanRI.xq b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/orphanRI.xq index ebac355..83f3f40 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/orphanRI.xq +++ b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/sweeper/orphanRI.xq @@ -4,16 +4,4 @@ for $ri in $ris let $counter := index-of(($ghns//ID/string()), $ri/Profile/GHN/@UniqueID/string()) where empty($counter) return - - {$ri//Resource/ID/string()} - {$ri/Profile/DeploymentData/Status/string()} - {$ri/Profile/DeploymentData/ActivationTime/@value/string()} - {$ri/Profile/GHN/@UniqueID/string()} - {$ri/Profile/ServiceClass/string()} - {$ri/Profile/ServiceName/string()} - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/AbstractResourceManager.java b/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/AbstractResourceManager.java index 95d065d..43ec3be 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/AbstractResourceManager.java +++ b/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/AbstractResourceManager.java @@ -26,6 +26,7 @@ import org.gcube.common.resources.gcore.Resource; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean.Type; +import org.gcube.informationsystem.publisher.AdvancedPublisher; import org.gcube.informationsystem.publisher.RegistryPublisher; import org.gcube.informationsystem.publisher.RegistryPublisherFactory; import org.gcube.resourcemanagement.support.server.exceptions.AbstractResourceException; @@ -175,7 +176,7 @@ public abstract class AbstractResourceManager { * @throws ResourceParameterException if the parameters are invalid */ public final RMBinderLibrary getResourceManager(String scope) throws AbstractResourceException { - + ScopeBean bscope = new ScopeBean(scope); if (bscope.is(Type.VRE)) { scope = bscope.enclosingScope().toString(); @@ -202,7 +203,7 @@ public abstract class AbstractResourceManager { scope = bscope.enclosingScope().toString(); } ScopeProvider.instance.set(scope); - + ServerConsole.info(LOG_PREFIX, "Getting Resource Manager in scope [" + scope.toString() + "]"); RMReportingLibrary rml = Proxies.reportingService().build(); if (rml == null) { // no managers found @@ -232,7 +233,7 @@ public abstract class AbstractResourceManager { targetScope.toString() + "]"); String curr = ScopeProvider.instance.get(); ScopeProvider.instance.set(targetScope.toString()); - + AddResourcesParameters addParam = new AddResourcesParameters(); ResourceItem toAdd = new ResourceItem(); toAdd.setId(this.getID()); @@ -261,7 +262,7 @@ public abstract class AbstractResourceManager { targetScope.toString() + "]... reportID: " + reportID); RMReportingLibrary pt = this.getReportResourceManager(scope.toString()); - + String toReturn = pt.getReport(reportID); ScopeProvider.instance.set(curr); return toReturn; @@ -286,7 +287,7 @@ public abstract class AbstractResourceManager { checker.validate(sourceScope != null, new ResourceParameterException("Invalid parameter sourceScope. null not allowed.")); checker.validate(targetScope != null, new ResourceParameterException("Invalid parameter targetScope. null not allowed.")); checker.validate(this.getID() != null, new ResourceOperationException("Invalid resource ID. null not allowed.")); - + String curr = ScopeProvider.instance.get(); ScopeProvider.instance.set(sourceScope.toString()); ReportBuilder report = new ReportBuilder(); @@ -319,7 +320,7 @@ public abstract class AbstractResourceManager { targetScope.toString() + " the remote report ID is: " + this.bindToScope(targetScope.toString()), true)); - + String toReturn = report.getXML(); ScopeProvider.instance.set(curr); return toReturn; @@ -407,9 +408,9 @@ public abstract class AbstractResourceManager { protected final String getXMLDescription(final ScopeBean scope) throws AbstractResourceException { Assertion checker = new Assertion(); checker.validate(this.getID() != null, new ResourceAccessException("Cannot execute on resources with no ID.")); - + ScopeProvider.instance.set(scope.toString()); - + // Phase 1. retrieve the resource to copy Query query = new QueryBox("for $resource in collection('/db/Profiles/" + this.getType().name() + "')//Resource " + "where ( $resource/ID/string() eq '" + @@ -423,7 +424,7 @@ public abstract class AbstractResourceManager { if (results == null || results.isEmpty()) throw new ResourceAccessException("Cannot retrieve the IS profile for resource: " + this.getID() + " in scope: " + scope.toString()); - + return results.get(0).toString(); } @@ -475,10 +476,10 @@ public abstract class AbstractResourceManager { Assertion checker = new Assertion(); checker.validate(scope != null, new ResourceParameterException("Invalid parameter scope. null not allowed.")); checker.validate(this.getID() != null, new ResourceOperationException("Invalid ID. null not allowed.")); - + ScopeProvider.instance.set(scope.toString()); String retval = this.basicRemoveFromScope(scope); - + return retval; } @@ -503,14 +504,20 @@ public abstract class AbstractResourceManager { * @param scope where the resource is bound * @throws AbstractResourceException */ - public final void forceDelete(final ScopeBean scope) throws AbstractResourceException { - ServerConsole.trace(LOG_PREFIX, "[DELETE] [DELETE-BRANCH] deleting resource since no more scopes remained"); - Resource resStub = this.getResource(scope); - try { - this.getRegistryPublisher().remove(resStub); - } catch (Exception e) { - ServerConsole.error(LOG_PREFIX, e); - } + public final void forceDelete(ScopeBean scope) throws AbstractResourceException { + ServerConsole.trace(LOG_PREFIX, "[FORCE DELETE] [DELETE-BRANCH] deleting resource from scope " + scope); + String currScope = ScopeProvider.instance.get(); + + Resource toDelete = this.getResource(scope); + + while (scope.enclosingScope() != null) + scope = scope.enclosingScope(); + + ScopeProvider.instance.set(scope.toString()); + AdvancedPublisher advancedPublisher = new AdvancedPublisher(this.getRegistryPublisher()); + advancedPublisher.forceRemove(toDelete); + ServerConsole.trace(LOG_PREFIX, "[FORCE DELETE] [DELETE-BRANCH] deleted resource from scope " + scope); + ScopeProvider.instance.set(currScope); } /** @@ -528,8 +535,8 @@ public abstract class AbstractResourceManager { checker.validate(this.getID() != null, new ResourceOperationException("Invalid ID. null not allowed.")); System.out.println("DELETING TYPE: "+ this.getType()); - ScopeProvider.instance.set(scope.toString()); - + String currScope = ScopeProvider.instance.get(); + ScopeProvider.instance.set(scope.toString()); Resource resStub = this.getResource(scope); List boundedScopes = this.validateScopes(resStub.scopes().toArray(new String[0])); @@ -545,8 +552,9 @@ public abstract class AbstractResourceManager { try { this.getRegistryPublisher().remove(resStub); } catch (Exception e) { - + ScopeProvider.instance.set(currScope); } + ScopeProvider.instance.set(currScope); } } diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/GHNManager.java b/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/GHNManager.java index 2c0fad5..0f94d78 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/GHNManager.java +++ b/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/GHNManager.java @@ -131,7 +131,7 @@ public class GHNManager extends AbstractResourceManager { } return this.addToExistingScope(sourceScope, targetScope); } - + /** *

* Required information: diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/utils/persistence/PersistentItem.java b/src/main/java/org/gcube/resourcemanagement/support/server/utils/persistence/PersistentItem.java index 46cd3f2..89bcb47 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/utils/persistence/PersistentItem.java +++ b/src/main/java/org/gcube/resourcemanagement/support/server/utils/persistence/PersistentItem.java @@ -129,7 +129,7 @@ implements PersistenceHandler { while ((currLine = reader.readLine()) != null) { xml.append(currLine); } - + reader.close(); return (T) this.getSerializer().fromXML(xml.toString()); } catch (Exception e) { ServerConsole.error(LOG_PREFIX, e);