diff --git a/pom.xml b/pom.xml
index b7b8c9b..bf2e7f7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -77,6 +77,12 @@
1.1.1
compile
+
+ registry-publisher
+ org.gcube.resources
+ provided
+
+
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 b9872f7..264d5ff 100644
--- a/src/main/java/org/gcube/informationsystem/resource_checker/ResourceCheckerPlugin.java
+++ b/src/main/java/org/gcube/informationsystem/resource_checker/ResourceCheckerPlugin.java
@@ -7,6 +7,7 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -20,10 +21,13 @@ 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.Resource;
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.publisher.RegistryPublisher;
+import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
import org.gcube.informationsystem.resource_checker.utils.BasicFunctionalitiesMandatoryReader;
import org.gcube.informationsystem.resource_checker.utils.BasicFunctionalityBean;
import org.gcube.informationsystem.resource_checker.utils.RetrieveContextsList;
@@ -127,13 +131,27 @@ public class ResourceCheckerPlugin extends Plugin vosContexts = new ArrayList();
+ RetrieveContextsList.loadVOs(vosContexts);
+ accessPointQuery(vosContexts, identifiers , ServiceEndpoint.class);
+ }catch(Exception e){
+ otherFailures = "\n\nMoreover, while trying to re-add the following identifiers " + identifiers + " there was this error " + e.getMessage();
+ logger.error("While readding the resources this error arose", e);
+ }
+ }
+
// if there are missing resources, notify administrators via mail
if(!missingResourcesPerContext.isEmpty() || !otherFailures.equals(INITIAL_ERRORS_STATEMENT + "none.\n"))
SendNotification.sendMessage(missingResourcesPerContext, otherFailures, (String)inputs.get(ROLE_TO_NOTIFY));
logger.info("Plugin's execution ended. Map of not available services per scope is the following: \n" + missingResourcesPerContext);
+
}
/**
@@ -203,6 +221,82 @@ public class ResourceCheckerPlugin extends Plugin idsMissingResources) throws Exception{
+
+ try{
+ 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();
+
+ FileWriter writer = new FileWriter(f, false);
+
+ if (idsMissingResources == null || idsMissingResources.isEmpty()) {
+ writer.write("none");
+ }else{
+ for (String idMissing : idsMissingResources) {
+ writer.write(idMissing + "\n");
+ }
+ }
+ writer.close();
+ }catch(Exception e){
+ logger.error("Failed to write the report file for nagios", e);
+ }
+ }
+
+
+ /**
+ * Add the missing ids.
+ * @param voScopes
+ * @param resourceIds
+ * @param resourceType
+ */
+ private void accessPointQuery(List voScopes, List resourceIds, Class resourceType){
+
+ String currentScope = voScopes.get(0);
+ HashSet scopeSet = new HashSet();
+
+ SimpleQuery queryVRE = ICFactory.queryFor(GenericResource.class);
+ queryVRE.addCondition("$resource/Profile/SecondaryType/text() = 'VRE'");
+ queryVRE.setResult("$resource/Profile/Body/Scope/string()");
+ DiscoveryClient vREScopeClient = ICFactory.client();
+
+ scopeSet.addAll(voScopes);
+
+ for (String scope: voScopes){
+ ScopeProvider.instance.set(scope);
+ List vresscope = vREScopeClient.submit(queryVRE);
+ System.out.println("found "+vresscope.size()+ " vres in "+scope);
+ scopeSet.addAll(vresscope);
+ }
+
+ for (String resourceId : resourceIds){
+
+ ScopeProvider.instance.set(currentScope);
+ SimpleQuery query = ICFactory.queryFor(resourceType);
+ DiscoveryClient client = ICFactory.clientFor(resourceType);
+ query.addCondition("$resource/ID/text() = '"+resourceId+"'");
+ T resource = client.submit(query).get(0);
+
+ resource.scopes().asCollection().retainAll(Collections.emptyList());
+ resource.scopes().asCollection().addAll(scopeSet);
+
+ RegistryPublisher pub = RegistryPublisherFactory.create();
+ pub.vosUpdate(resource);
+ }
+
+ }
+
/**{@inheritDoc}*/
@Override
protected void onStop() throws Exception {
@@ -210,32 +304,4 @@ public class ResourceCheckerPlugin extends Plugin idsMissingResources) throws Exception{
-
- 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();
-
- FileWriter writer = new FileWriter(f, false);
-
- if (idsMissingResources == null || idsMissingResources.isEmpty()) {
- writer.write("none");
- }else{
- for (String idMissing : idsMissingResources) {
- writer.write(idMissing + "\n");
- }
- }
- writer.close();
- }
}
diff --git a/src/main/java/org/gcube/informationsystem/resource_checker/utils/RetrieveContextsList.java b/src/main/java/org/gcube/informationsystem/resource_checker/utils/RetrieveContextsList.java
index dc7574d..537dc93 100644
--- a/src/main/java/org/gcube/informationsystem/resource_checker/utils/RetrieveContextsList.java
+++ b/src/main/java/org/gcube/informationsystem/resource_checker/utils/RetrieveContextsList.java
@@ -66,7 +66,7 @@ public class RetrieveContextsList {
}
- private static void loadVOs(List contexts) throws ParserConfigurationException, SAXException, IOException {
+ public static void loadVOs(List contexts) throws ParserConfigurationException, SAXException, IOException {
String infrastructureRoot = "/" + ScopeProvider.instance.get().split("/")[1];
logger.debug("Infrastructure root is " + infrastructureRoot);