forked from gCubeSystem/rmp-common-library
Moved Sweeper classes from resource-sweeper widget to rmp-common-library. This action was required to share sweeper code with other projects.
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/admin/rmp-common-library@119057 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9c995cabc4
commit
294cc8cac2
|
@ -23,5 +23,6 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="com.google.gwt.eclipse.core.GWT_CONTAINER"/>
|
||||
<classpathentry kind="output" path="war/WEB-INF/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
eclipse.preferences.version=1
|
||||
entryPointModules=
|
||||
filesCopiedToWebInfLib=
|
||||
filesCopiedToWebInfLib=gwt-servlet.jar
|
||||
gwtCompileSettings=PGd3dC1jb21waWxlLXNldHRpbmdzPjxsb2ctbGV2ZWw+SU5GTzwvbG9nLWxldmVsPjxvdXRwdXQtc3R5bGU+T0JGVVNDQVRFRDwvb3V0cHV0LXN0eWxlPjxleHRyYS1hcmdzPjwhW0NEQVRBW11dPjwvZXh0cmEtYXJncz48dm0tYXJncz48IVtDREFUQVstWG14NTEybV1dPjwvdm0tYXJncz48ZW50cnktcG9pbnQtbW9kdWxlPm9yZy5nY3ViZS5yZXNvdXJjZW1hbmFnZW1lbnQuc3VwcG9ydC5SZXNvdXJjZV9zdXBwb3J0PC9lbnRyeS1wb2ludC1tb2R1bGU+PC9nd3QtY29tcGlsZS1zZXR0aW5ncz4\=
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -11,7 +11,7 @@
|
|||
|
||||
<groupId>org.gcube.portlets.admin</groupId>
|
||||
<artifactId>rmp-common-library</artifactId>
|
||||
<version>2.4.0-SNAPSHOT</version>
|
||||
<version>2.4.1-SNAPSHOT</version>
|
||||
<name>Resource Management Library</name>
|
||||
<description>
|
||||
gCube Resource Management Library is a common library containing shared code for Information System Operations
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package org.gcube.resourcemanagement.support.server.sweeper;
|
||||
|
||||
public class QueryParameter {
|
||||
protected String name;
|
||||
protected String value;
|
||||
|
||||
public QueryParameter(String name, String value) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "QueryParameter [name=" + name + ", value=" + value + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,173 @@
|
|||
/****************************************************************************
|
||||
* This software is part of the gCube Project.
|
||||
* Site: http://www.gcube-system.org/
|
||||
****************************************************************************
|
||||
* The gCube/gCore software is licensed as Free Open Source software
|
||||
* conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
|
||||
* The software and documentation is provided by its authors/distributors
|
||||
* "as is" and no expressed or
|
||||
* implied warranty is given for its use, quality or fitness for a
|
||||
* particular case.
|
||||
****************************************************************************
|
||||
* Filename: Sweeper.java
|
||||
****************************************************************************
|
||||
* @author <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
|
||||
***************************************************************************/
|
||||
|
||||
package org.gcube.resourcemanagement.support.server.sweeper;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.gcube.common.resources.gcore.HostingNode;
|
||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.resourcemanagement.support.server.gcube.queries.QueryLoader;
|
||||
import org.gcube.resourcemanagement.support.server.gcube.queries.QueryLocation;
|
||||
import org.gcube.resourcemanagement.support.server.managers.resources.GHNManager;
|
||||
import org.gcube.resourcemanagement.support.server.managers.resources.RunningInstanceManager;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.impl.QueryTemplate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.extjs.gxt.ui.client.data.ModelData;
|
||||
|
||||
/**
|
||||
* @author Massimiliano Assante (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
public class Sweeper {
|
||||
//TODO: Make it configurable from a property file
|
||||
public static String LIVE_GHN_MAX_MINUTES = "40";
|
||||
|
||||
private static final Logger _log = LoggerFactory.getLogger(Sweeper.class);
|
||||
|
||||
|
||||
protected ArrayList<String> applyQuery(ScopeBean queryScope, QueryLocation queryPath, QueryLocation returnPath, QueryParameter... params) throws Exception {
|
||||
//set the scope
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(queryScope.toString());
|
||||
|
||||
QueryTemplate isQuery = new QueryTemplate(QueryLoader.getQuery(queryPath));
|
||||
DiscoveryClient<String> client = client();
|
||||
|
||||
if (params != null && params.length > 0) {
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
isQuery.addParameter(params[i].name, params[i].value);
|
||||
}
|
||||
}
|
||||
isQuery.addParameter("RESOURCE", QueryLoader.getQuery(returnPath));
|
||||
|
||||
List<String> results = client.submit(isQuery);
|
||||
ArrayList<String> retval = new ArrayList<String>();
|
||||
|
||||
for (String elem : results) {
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement();
|
||||
XPathHelper helper = new XPathHelper(node);
|
||||
// Removes the resources with no ID or empty
|
||||
try {
|
||||
if (helper.evaluate("//ID").get(0) != null && helper.evaluate("//ID").get(0).trim().length() > 0) {
|
||||
retval.add(elem);
|
||||
System.out.println(elem);
|
||||
} else {
|
||||
_log.debug("*** Found an invalid element with no ID");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
_log.debug("[getResourcesByType] found a resource with empty ID");
|
||||
}
|
||||
}
|
||||
ScopeProvider.instance.set(currScope);
|
||||
return retval;
|
||||
}
|
||||
/**
|
||||
* this method used to read the MAXWAIT param from the resourcemanagement.properties files, currently it reads it from the static var defined on top of this class
|
||||
* TODO: Make it configurable again from a property file
|
||||
* @param queryScope
|
||||
* @return the expired ghn list
|
||||
*/
|
||||
public ArrayList<String> getExpiredGHNs(final ScopeBean queryScope) {
|
||||
try {
|
||||
return applyQuery(
|
||||
queryScope,
|
||||
QueryLocation.SWEEPER_EXPIRED_GHN, QueryLocation.RETURN_SWEEPER_EXPIRED_GHN,
|
||||
new QueryParameter("MAXWAIT", LIVE_GHN_MAX_MINUTES));
|
||||
} catch (Exception e) {
|
||||
_log.error(e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public ArrayList<String> getDeadGHNs(ScopeBean queryScope) {
|
||||
try {
|
||||
return applyQuery(
|
||||
queryScope,
|
||||
QueryLocation.SWEEPER_DEAD_GHN, QueryLocation.RETURN_SWEEPER_DEAD_GHN);
|
||||
} catch (Exception e) {
|
||||
_log.error(e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<String> getOrphanRI(ScopeBean queryScope) {
|
||||
try {
|
||||
return applyQuery(
|
||||
queryScope,
|
||||
QueryLocation.SWEEPER_ORPHAN_RI, QueryLocation.RETURN_SWEEPER_ORPHAN_RI);
|
||||
} catch (Exception e) {
|
||||
_log.error(e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public Boolean applySweep(ScopeBean queryScope, List<ModelData> elems) {
|
||||
//set the scope
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(queryScope.toString());
|
||||
for (ModelData entry : elems) {
|
||||
try {
|
||||
System.out.println("Action->"+((Object) entry.get("Actions")).toString());
|
||||
SweeperActions action = SweeperActions.valueOf(((Object) entry.get("Actions")).toString());
|
||||
String resID = ((Object) entry.get("ID")).toString();
|
||||
|
||||
_log.info("Cleaning up " + resID + " " + action);
|
||||
|
||||
switch(action) {
|
||||
case APPLY_GHN_DELETE:
|
||||
GHNManager manager = new GHNManager(resID);
|
||||
manager.forceDelete(queryScope);
|
||||
break;
|
||||
case APPLY_GHN_MOVE_TO_UNREACHABLE:
|
||||
GHNManager ghnManager = new GHNManager(resID);
|
||||
HostingNode res = (HostingNode) ghnManager.getResource(queryScope);
|
||||
_log.trace("*** Setting HostingNode " + resID + " status to unreachable");
|
||||
res.profile().description().status("unreachable");
|
||||
HostingNode hn = ghnManager.getRegistryPublisher().update(res);
|
||||
_log.trace("*** getRegistryPublisher returned " + hn.toString());
|
||||
break;
|
||||
case APPLY_RI_DELETE:
|
||||
RunningInstanceManager riManager = new RunningInstanceManager(resID);
|
||||
_log.trace("*** The running instance " + resID + " will be deleted");
|
||||
riManager.forceDelete(queryScope);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
ScopeProvider.instance.set(currScope);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/****************************************************************************
|
||||
* This software is part of the gCube Project.
|
||||
* Site: http://www.gcube-system.org/
|
||||
****************************************************************************
|
||||
* The gCube/gCore software is licensed as Free Open Source software
|
||||
* conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
|
||||
* The software and documentation is provided by its authors/distributors
|
||||
* "as is" and no expressed or
|
||||
* implied warranty is given for its use, quality or fitness for a
|
||||
* particular case.
|
||||
****************************************************************************
|
||||
* Filename: Actions.java
|
||||
****************************************************************************
|
||||
* @author <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
|
||||
***************************************************************************/
|
||||
|
||||
package org.gcube.resourcemanagement.support.server.sweeper;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Daniele Strollo (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
public enum SweeperActions implements Serializable {
|
||||
// Declarations for getting resources to cleanup
|
||||
GET_GHN_MOVE_TO_UNREACHABLE(
|
||||
"Expired GHNs",
|
||||
"GHNs no more updated for a long time",
|
||||
"Changes the status of GHNs to unreachable"),
|
||||
GET_GHN_DELETE("Dead GHNs",
|
||||
"GHNs having status down or unreachable",
|
||||
"Removes the GHNs from the IS"),
|
||||
GET_RI_DELETE("Orphan RIs",
|
||||
"RIs related to no more available GHNs",
|
||||
"Removes the RIs from the IS"),
|
||||
|
||||
// Be sure the names are reported in xq files.
|
||||
// Declarations for applying resources cleanup
|
||||
APPLY_GHN_MOVE_TO_UNREACHABLE("Change GHN Status"),
|
||||
APPLY_GHN_DELETE("Remove Dead GHN"),
|
||||
APPLY_RI_DELETE("Remove Orphan RI");
|
||||
|
||||
private String opDescription = null;
|
||||
private String label = null;
|
||||
private String tooltip = null;
|
||||
|
||||
private SweeperActions(final String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
private SweeperActions(final String label, final String opDescription) {
|
||||
this(label);
|
||||
this.opDescription = opDescription;
|
||||
}
|
||||
|
||||
private SweeperActions(final String label, final String tooltip, final String opDescription) {
|
||||
this(label, opDescription);
|
||||
this.tooltip = tooltip;
|
||||
}
|
||||
|
||||
public String getTooltip() {
|
||||
return this.tooltip;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
public String getOperationDescription() {
|
||||
return opDescription;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue