diff --git a/.classpath b/.classpath
index 4214a97..d497854 100644
--- a/.classpath
+++ b/.classpath
@@ -22,5 +22,10 @@
+
+
+
+
+
diff --git a/src/main/java/org/gcube/informationsystem/resource_checker/ResourceCheckerPlugin.java b/src/main/java/org/gcube/informationsystem/resource_checker/ResourceCheckerPlugin.java
index 3e09108..b9872f7 100644
--- a/src/main/java/org/gcube/informationsystem/resource_checker/ResourceCheckerPlugin.java
+++ b/src/main/java/org/gcube/informationsystem/resource_checker/ResourceCheckerPlugin.java
@@ -5,6 +5,7 @@ package org.gcube.informationsystem.resource_checker;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -13,11 +14,15 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.common.resources.gcore.HostingNode;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.Software;
+import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.resource_checker.utils.BasicFunctionalitiesMandatoryReader;
import org.gcube.informationsystem.resource_checker.utils.BasicFunctionalityBean;
@@ -29,6 +34,8 @@ import org.gcube.resources.discovery.icclient.ICFactory;
import org.gcube.vremanagement.executor.plugin.Plugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
/**
* The resource-checker-se-plugin implementation class.
@@ -40,7 +47,7 @@ public class ResourceCheckerPlugin extends Plugin resourceToIdentifierMap = new HashMap(mandatoryFunctionalities.size());
Set missingResourcesKey = new HashSet(mandatoryFunctionalities.size());
@@ -79,7 +87,7 @@ public class ResourceCheckerPlugin extends Plugin missingServices = null;
if(missingResourcesPerContext.containsKey(context))
@@ -110,7 +118,7 @@ public class ResourceCheckerPlugin extends Plugin result = null;
+ List result = null;
if(classFor.equals(ServiceEndpoint.class)){
q.addCondition("$resource/Profile/Name/text() eq '"+ service.getName() +"'");
q.addCondition("$resource/Profile/Category/text() eq '"+ service.getCategory() +"'");
- result = (List)client.submit(q);
+ result = client.submit(q);
}else if(classFor.equals(GCoreEndpoint.class)){
@@ -175,7 +184,23 @@ public class ResourceCheckerPlugin extends Plugin 0 ? result.get(0).id() : null;
+ if(result == null || result.isEmpty())
+ return null;
+ else{
+
+ String elem = (String) result.get(0);
+ Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement();
+ XPathHelper helper = new XPathHelper(node);
+
+ List currValue = null;
+ currValue = helper.evaluate("/Resource/ID/text()");
+ if (currValue != null && currValue.size() > 0) {
+ logger.debug("Id is " + currValue.get(0));
+ return currValue.get(0);
+ }
+ else throw new Exception("ID property is missing!");
+
+ }
}
/**{@inheritDoc}*/
@@ -189,14 +214,16 @@ public class ResourceCheckerPlugin extends Plugin idsMissingResources) throws IOException{
+ private void writeReport4Nagios(List idsMissingResources) throws Exception{
- // find location of nagios file and write the ids of the resources there
Properties prop = new Properties();
prop.load(getClass().getResourceAsStream(NAGIOS_PROPERTY_FILE));
String location = prop.getProperty("location");
+ logger.trace("File location for nagios is " + location);
+
File f = new File(location);
+ f.getParentFile().mkdirs();
f.delete();
f.createNewFile();
diff --git a/src/main/java/org/gcube/informationsystem/resource_checker/utils/SendNotification.java b/src/main/java/org/gcube/informationsystem/resource_checker/utils/SendNotification.java
index d1e247a..87fb3e2 100644
--- a/src/main/java/org/gcube/informationsystem/resource_checker/utils/SendNotification.java
+++ b/src/main/java/org/gcube/informationsystem/resource_checker/utils/SendNotification.java
@@ -134,10 +134,10 @@ public class SendNotification extends PluginStateNotification {
logger.warn("Something failed when trying to notify the user", e);
}
}else
- logger.error("No notification is going to be sent, because social service is missing or recipient is not specified");
+ logger.error("No notification is going to be sent because social service is missing or recipient is not specified");
break;
default:
- logger.info("No notification is going to be sent, because the status of the plugin execution is " + pluginStateEvolution.getPluginState().name());
+ logger.info("No notification is going to be sent because the status of the plugin execution is " + pluginStateEvolution.getPluginState().name());
}
}
@@ -197,13 +197,16 @@ public class SendNotification extends PluginStateNotification {
StringBuilder sb = new StringBuilder();
sb.append("Dear ");
sb.append(role).append(",").append("\n");
- sb.append("this is the report of the last running of the " + ResourceCheckerPluginDeclaration.NAME.toUpperCase() + " (" + dataStr + ").\nThe following missing resources have been found:");
+ sb.append("this is the report of the last running of the " + ResourceCheckerPluginDeclaration.NAME.toUpperCase() + " (" + dataStr + ").\nThe following missing resources have been found:\n");
Iterator>> iterator = missingResourcesPerContext.entrySet().iterator();
+
+ if(!iterator.hasNext())
+ sb.append("none.");
+
while (iterator.hasNext()) {
Map.Entry> entry = (Map.Entry>) iterator
.next();
- sb.append("\n");
List list = entry.getValue();
for (BasicFunctionalityBean basicFunctionalityBean : list) {
sb.append("- resource's name ");
@@ -213,13 +216,13 @@ public class SendNotification extends PluginStateNotification {
sb.append(" (in context " + entry.getKey() + ")");
}
if(iterator.hasNext())
- sb.append(";");
+ sb.append(";\n");
else
- sb.append(".");
+ sb.append(".\n");
}
sb.append("\n\n");
- sb.append(otherFailures + ".\n");
+ sb.append(otherFailures + "\n");
sb.append("Best,\n" + ResourceCheckerPluginDeclaration.NAME);
String message = sb.toString();
diff --git a/src/main/resources/META-INF/plugin_resources/nagios-report-location.properties b/src/main/resources/META-INF/plugin_resources/nagios-report-location.properties
index e305550..43c3e25 100644
--- a/src/main/resources/META-INF/plugin_resources/nagios-report-location.properties
+++ b/src/main/resources/META-INF/plugin_resources/nagios-report-location.properties
@@ -1 +1 @@
-location=/home/gcube/scopes_data/scopes_status
\ No newline at end of file
+location=/home/gcube/missing_resources/identifiers
\ No newline at end of file
diff --git a/src/main/resources/META-INF/services/org.gcube.vremanagement.executor.plugin.PluginDeclaration b/src/main/resources/META-INF/services/org.gcube.vremanagement.executor.plugin.PluginDeclaration
index 7473877..c30813e 100644
--- a/src/main/resources/META-INF/services/org.gcube.vremanagement.executor.plugin.PluginDeclaration
+++ b/src/main/resources/META-INF/services/org.gcube.vremanagement.executor.plugin.PluginDeclaration
@@ -1 +1 @@
-org.gcube.common.resource_checker.ResourceCheckerPluginDeclaration
\ No newline at end of file
+org.gcube.informationsystem.resource_checker.ResourceCheckerPluginDeclaration
\ No newline at end of file