added code to republish missing resources from their identifiers
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-checker-se-plugin@147107 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
65e66445a1
commit
7f7cbb4b45
6
pom.xml
6
pom.xml
|
@ -77,6 +77,12 @@
|
||||||
<version>1.1.1</version>
|
<version>1.1.1</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<artifactId>registry-publisher</artifactId>
|
||||||
|
<groupId>org.gcube.resources</groupId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
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.GCoreEndpoint;
|
||||||
import org.gcube.common.resources.gcore.GenericResource;
|
import org.gcube.common.resources.gcore.GenericResource;
|
||||||
import org.gcube.common.resources.gcore.HostingNode;
|
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.ServiceEndpoint;
|
||||||
import org.gcube.common.resources.gcore.Software;
|
import org.gcube.common.resources.gcore.Software;
|
||||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
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.BasicFunctionalitiesMandatoryReader;
|
||||||
import org.gcube.informationsystem.resource_checker.utils.BasicFunctionalityBean;
|
import org.gcube.informationsystem.resource_checker.utils.BasicFunctionalityBean;
|
||||||
import org.gcube.informationsystem.resource_checker.utils.RetrieveContextsList;
|
import org.gcube.informationsystem.resource_checker.utils.RetrieveContextsList;
|
||||||
|
@ -127,13 +131,27 @@ public class ResourceCheckerPlugin extends Plugin<ResourceCheckerPluginDeclarati
|
||||||
for (String key : missingResourcesKey) {
|
for (String key : missingResourcesKey) {
|
||||||
identifiers.add(resourceToIdentifierMap.get(key));
|
identifiers.add(resourceToIdentifierMap.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
writeReport4Nagios(identifiers);
|
writeReport4Nagios(identifiers);
|
||||||
|
|
||||||
|
if(!identifiers.isEmpty()){
|
||||||
|
try{
|
||||||
|
logger.info("Going to execute code to re-add them");
|
||||||
|
List<String> vosContexts = new ArrayList<String>();
|
||||||
|
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 there are missing resources, notify administrators via mail
|
||||||
if(!missingResourcesPerContext.isEmpty() || !otherFailures.equals(INITIAL_ERRORS_STATEMENT + "none.\n"))
|
if(!missingResourcesPerContext.isEmpty() || !otherFailures.equals(INITIAL_ERRORS_STATEMENT + "none.\n"))
|
||||||
SendNotification.sendMessage(missingResourcesPerContext, otherFailures, (String)inputs.get(ROLE_TO_NOTIFY));
|
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);
|
logger.info("Plugin's execution ended. Map of not available services per scope is the following: \n" + missingResourcesPerContext);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -203,19 +221,13 @@ public class ResourceCheckerPlugin extends Plugin<ResourceCheckerPluginDeclarati
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**{@inheritDoc}*/
|
|
||||||
@Override
|
|
||||||
protected void onStop() throws Exception {
|
|
||||||
logger.debug("onStop() invoked");
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a report for nagios
|
* Write a report for nagios
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private void writeReport4Nagios(List<String> idsMissingResources) throws Exception{
|
private void writeReport4Nagios(List<String> idsMissingResources) throws Exception{
|
||||||
|
|
||||||
|
try{
|
||||||
Properties prop = new Properties();
|
Properties prop = new Properties();
|
||||||
prop.load(getClass().getResourceAsStream(NAGIOS_PROPERTY_FILE));
|
prop.load(getClass().getResourceAsStream(NAGIOS_PROPERTY_FILE));
|
||||||
String location = prop.getProperty("location");
|
String location = prop.getProperty("location");
|
||||||
|
@ -237,5 +249,59 @@ public class ResourceCheckerPlugin extends Plugin<ResourceCheckerPluginDeclarati
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writer.close();
|
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 <T extends Resource> void accessPointQuery(List<String> voScopes, List<String> resourceIds, Class<T> resourceType){
|
||||||
|
|
||||||
|
String currentScope = voScopes.get(0);
|
||||||
|
HashSet<String> scopeSet = new HashSet<String>();
|
||||||
|
|
||||||
|
SimpleQuery queryVRE = ICFactory.queryFor(GenericResource.class);
|
||||||
|
queryVRE.addCondition("$resource/Profile/SecondaryType/text() = 'VRE'");
|
||||||
|
queryVRE.setResult("$resource/Profile/Body/Scope/string()");
|
||||||
|
DiscoveryClient<String> vREScopeClient = ICFactory.client();
|
||||||
|
|
||||||
|
scopeSet.addAll(voScopes);
|
||||||
|
|
||||||
|
for (String scope: voScopes){
|
||||||
|
ScopeProvider.instance.set(scope);
|
||||||
|
List<String> 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<T> 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 {
|
||||||
|
logger.debug("onStop() invoked");
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class RetrieveContextsList {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadVOs(List<String> contexts) throws ParserConfigurationException, SAXException, IOException {
|
public static void loadVOs(List<String> contexts) throws ParserConfigurationException, SAXException, IOException {
|
||||||
|
|
||||||
String infrastructureRoot = "/" + ScopeProvider.instance.get().split("/")[1];
|
String infrastructureRoot = "/" + ScopeProvider.instance.get().split("/")[1];
|
||||||
logger.debug("Infrastructure root is " + infrastructureRoot);
|
logger.debug("Infrastructure root is " + infrastructureRoot);
|
||||||
|
|
Loading…
Reference in New Issue