improvements related to ticket #9031
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-checker-se-plugin@150528 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
949f9c7cbd
commit
4996ba14fe
|
@ -1,5 +1,12 @@
|
|||
<ReleaseNotes>
|
||||
<Changeset component="org.gcube.information-system.resource-checker-se-plugin.1-0-0" date="2017-04-29">
|
||||
<Change>First Release</Change>
|
||||
<Changeset
|
||||
component="org.gcube.information-system.resource-checker-se-plugin.1-1-0"
|
||||
date="2017-06-29">
|
||||
<Change>Added check for HomeLibraryWebApp GCoreEP</Change>
|
||||
</Changeset>
|
||||
<Changeset
|
||||
component="org.gcube.information-system.resource-checker-se-plugin.1-0-0"
|
||||
date="2017-04-29">
|
||||
<Change>First Release</Change>
|
||||
</Changeset>
|
||||
</ReleaseNotes>
|
2
pom.xml
2
pom.xml
|
@ -9,7 +9,7 @@
|
|||
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>resource-checker-se-plugin</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>Resource Checker Smart Executor Plugin</name>
|
||||
<description>Resource Checker Smart Executor Plugin</description>
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.resource_checker;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
|
@ -10,8 +7,10 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -26,10 +25,13 @@ 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.common.scope.impl.ScopeBean;
|
||||
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
||||
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
||||
import org.gcube.informationsystem.resource_checker.beans.BasicFunctionalityBean;
|
||||
import org.gcube.informationsystem.resource_checker.beans.ContextLevel;
|
||||
import org.gcube.informationsystem.resource_checker.beans.OperationLevel;
|
||||
import org.gcube.informationsystem.resource_checker.utils.BasicFunctionalitiesMandatoryReader;
|
||||
import org.gcube.informationsystem.resource_checker.utils.BasicFunctionalityBean;
|
||||
import org.gcube.informationsystem.resource_checker.utils.RetrieveContextsList;
|
||||
import org.gcube.informationsystem.resource_checker.utils.SendNotification;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
|
@ -53,12 +55,11 @@ public class ResourceCheckerPlugin extends Plugin<ResourceCheckerPluginDeclarati
|
|||
public static final String ROLE_TO_NOTIFY = "role";
|
||||
private static final String NAGIOS_PROPERTY_FILE = "/META-INF/plugin_resources/nagios-report-location.properties";
|
||||
private static final Logger logger = LoggerFactory.getLogger(ResourceCheckerPlugin.class);
|
||||
private static final DiscoveryClient client = ICFactory.client();
|
||||
|
||||
public ResourceCheckerPlugin(ResourceCheckerPluginDeclaration pluginDeclaration){
|
||||
|
||||
super(pluginDeclaration);
|
||||
logger.info("Constructor invoked");
|
||||
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
|
@ -80,45 +81,47 @@ public class ResourceCheckerPlugin extends Plugin<ResourceCheckerPluginDeclarati
|
|||
Map<String, List<BasicFunctionalityBean>> missingResourcesPerContext = new HashMap<String, List<BasicFunctionalityBean>>(contexts.size());
|
||||
|
||||
String otherFailures = INITIAL_ERRORS_STATEMENT;
|
||||
DiscoveryClient client = ICFactory.client();
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
|
||||
Map<String, String> resourceToIdentifierMap = new HashMap<String, String>(mandatoryFunctionalities.size());
|
||||
Set<String> missingResourcesKey = new HashSet<String>(mandatoryFunctionalities.size());
|
||||
// write nagios report
|
||||
Set<String> missingResourceIds = new HashSet<String>(mandatoryFunctionalities.size());
|
||||
Map<String, BasicFunctionalityBean> idToResource = new HashMap<String, BasicFunctionalityBean>(mandatoryFunctionalities.size());
|
||||
|
||||
boolean missingToReadArePresent = false;
|
||||
|
||||
// loop over contexts and resources
|
||||
for (String context : contexts) {
|
||||
// switch context
|
||||
ScopeProvider.instance.set(context);
|
||||
for (BasicFunctionalityBean service : mandatoryFunctionalities) {
|
||||
|
||||
// check if this resource should be checked in this scope
|
||||
ScopeBean sb = new ScopeBean(context);
|
||||
ContextLevel contextDepth = service.getCtxLevel();
|
||||
|
||||
if(contextDepth.equals(ContextLevel.VO) && sb.type().equals(ScopeBean.Type.VRE)){
|
||||
logger.info("Resource " + service + " doesn't need to be checked in a VRE context (" + context + ")");
|
||||
continue;
|
||||
}
|
||||
try{
|
||||
|
||||
String resourceId = null;
|
||||
String resourceKey = service.getName() + ":" + service.getCategory();
|
||||
if((resourceId = isServicePresent(service, client, docBuilder)) == null){
|
||||
|
||||
List<BasicFunctionalityBean> missingServices = null;
|
||||
if(missingResourcesPerContext.containsKey(context))
|
||||
missingServices = missingResourcesPerContext.get(context);
|
||||
else
|
||||
missingServices = new ArrayList<BasicFunctionalityBean>();
|
||||
|
||||
// add among missing resources
|
||||
missingResourcesKey.add(resourceKey);
|
||||
|
||||
missingServices.add(service);
|
||||
missingResourcesPerContext.put(context, missingServices);
|
||||
|
||||
if((resourceId = isServicePresent(service, client, docBuilder)) != null){
|
||||
service.setResourceId(resourceId);
|
||||
idToResource.put(resourceId, service);
|
||||
}else{
|
||||
resourceToIdentifierMap.put(resourceKey, resourceId);
|
||||
List<BasicFunctionalityBean> missingServices = missingResourcesPerContext.containsKey(context) ?
|
||||
missingResourcesPerContext.get(context) : new ArrayList<BasicFunctionalityBean>();
|
||||
missingServices.add(service);
|
||||
missingResourcesPerContext.put(context, missingServices);
|
||||
|
||||
if(service.getOpLevel().equals(OperationLevel.ALERT_READD))
|
||||
missingToReadArePresent = true;
|
||||
}
|
||||
|
||||
Thread.sleep(1000 * SECONDS2WAIT);
|
||||
|
||||
}catch(Exception e){
|
||||
if(!(e instanceof InterruptedException)){
|
||||
logger.warn("An error arose when checking for resource " + service + " into context " + context);
|
||||
otherFailures += "\nAn error arose while checking for resource with name/category "
|
||||
+ service.getName() + "/" + service.getCategory() + " into context " + context + "(stack trace is : " + e.getMessage() + ")";
|
||||
+ service.getName() + "/" + service.getCategory() + " and type " + service.getType().getCanonicalName() + " into context " + context + "(stack trace is : " + e.getMessage() + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,24 +132,30 @@ public class ResourceCheckerPlugin extends Plugin<ResourceCheckerPluginDeclarati
|
|||
else
|
||||
otherFailures += "\n";
|
||||
|
||||
// write nagios report
|
||||
List<String> identifiers = new ArrayList<String>(mandatoryFunctionalities.size());
|
||||
for (String key : missingResourcesKey) {
|
||||
identifiers.add(resourceToIdentifierMap.get(key));
|
||||
}
|
||||
// evaluate missing resources from the map
|
||||
evaluateMissingIds(missingResourceIds, missingResourcesPerContext);
|
||||
|
||||
writeReport4Nagios(identifiers);
|
||||
// update the file used by nagios
|
||||
writeReport4Nagios(missingResourceIds);
|
||||
|
||||
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);
|
||||
otherFailures = "\nThe above resources have been readded in the scopes they were missing!.";
|
||||
}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(!missingResourceIds.isEmpty() && missingToReadArePresent){
|
||||
logger.info("Going to perform add and alert or just alert of missing resources");
|
||||
otherFailures = "Re-add operation on some resources has been executed. This is the result:";
|
||||
for(String resId: missingResourceIds){
|
||||
|
||||
// check if it must be readded or just alert is needed
|
||||
if(idToResource.get(resId).getOpLevel().equals(OperationLevel.ALERT)){
|
||||
logger.info("Resource " + idToResource.get(resId) + " doesn't need to be readded into the scopes it is missing");
|
||||
continue;
|
||||
}
|
||||
|
||||
try{
|
||||
readdResource(contexts, resId, idToResource.get(resId));
|
||||
otherFailures += "\n- resource with identifier " + resId + " has been readded in the scopes it was missing;";
|
||||
}catch(Exception e){
|
||||
otherFailures += "\n- while trying to re-add the resource with the following identifier " + resId + " there was this error: " + e.getMessage() +";";
|
||||
logger.error("While readding a resource this error arose", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,7 +163,8 @@ public class ResourceCheckerPlugin extends Plugin<ResourceCheckerPluginDeclarati
|
|||
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);
|
||||
logger.info("Plugin's execution ended.");
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("The following error arose during the execution of the plugin", e);
|
||||
}finally{
|
||||
|
@ -163,6 +173,26 @@ public class ResourceCheckerPlugin extends Plugin<ResourceCheckerPluginDeclarati
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the ids of the missing resources
|
||||
* @param missingResourceIds
|
||||
* @param missingResourcesPerContext
|
||||
*/
|
||||
private void evaluateMissingIds(Set<String> missingResourceIds,
|
||||
Map<String, List<BasicFunctionalityBean>> missingResourcesPerContext) {
|
||||
|
||||
Iterator<Entry<String, List<BasicFunctionalityBean>>> iterator = missingResourcesPerContext.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<java.lang.String, java.util.List<org.gcube.informationsystem.resource_checker.beans.BasicFunctionalityBean>> entry = (Map.Entry<java.lang.String, java.util.List<org.gcube.informationsystem.resource_checker.beans.BasicFunctionalityBean>>) iterator
|
||||
.next();
|
||||
List<BasicFunctionalityBean> missingResources = entry.getValue();
|
||||
for (BasicFunctionalityBean basicFunctionalityBean : missingResources) {
|
||||
missingResourceIds.add(basicFunctionalityBean.getResourceId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given resource is present or is missing.
|
||||
* @param service
|
||||
|
@ -185,9 +215,9 @@ public class ResourceCheckerPlugin extends Plugin<ResourceCheckerPluginDeclarati
|
|||
|
||||
}else if(classFor.equals(GCoreEndpoint.class)){
|
||||
|
||||
// TODO
|
||||
logger.error("There is no implementation yet to check for GCoreEndpoint");
|
||||
throw new Exception("There is no implementation yet to check for GCoreEndpoint");
|
||||
q.addCondition("$resource/Profile/ServiceName/text() eq '"+ service.getName() +"'");
|
||||
q.addCondition("$resource/Profile/ServiceClass/text() eq '"+ service.getCategory() +"'");
|
||||
result = client.submit(q);
|
||||
|
||||
}else if(classFor.equals(GenericResource.class)){
|
||||
|
||||
|
@ -225,7 +255,8 @@ public class ResourceCheckerPlugin extends Plugin<ResourceCheckerPluginDeclarati
|
|||
logger.debug("Id is " + currValue.get(0));
|
||||
return currValue.get(0);
|
||||
}
|
||||
else throw new Exception("ID property is missing!");
|
||||
else
|
||||
throw new Exception("ID property is missing!");
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -234,7 +265,7 @@ public class ResourceCheckerPlugin extends Plugin<ResourceCheckerPluginDeclarati
|
|||
* Write a report for nagios
|
||||
* @throws IOException
|
||||
*/
|
||||
private void writeReport4Nagios(List<String> idsMissingResources) throws Exception{
|
||||
private void writeReport4Nagios(Set<String> idsMissingResources) throws Exception{
|
||||
|
||||
try{
|
||||
Properties prop = new Properties();
|
||||
|
@ -251,7 +282,7 @@ public class ResourceCheckerPlugin extends Plugin<ResourceCheckerPluginDeclarati
|
|||
FileWriter writer = new FileWriter(f, false);
|
||||
|
||||
if (idsMissingResources == null || idsMissingResources.isEmpty()) {
|
||||
writer.write("none");
|
||||
writer.write("none\n");
|
||||
}else{
|
||||
for (String idMissing : idsMissingResources) {
|
||||
writer.write(idMissing + "\n");
|
||||
|
@ -265,52 +296,39 @@ public class ResourceCheckerPlugin extends Plugin<ResourceCheckerPluginDeclarati
|
|||
|
||||
|
||||
/**
|
||||
* Add the missing ids.
|
||||
* Add the missing resources back.
|
||||
* @param voScopes
|
||||
* @param resourceIds
|
||||
* @param idToResource
|
||||
* @param resourceType
|
||||
*/
|
||||
private <T extends Resource> void accessPointQuery(List<String> voScopes, List<String> resourceIds, Class<T> resourceType){
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends Resource> void readdResource(List<String> allScopes, String resourceId, BasicFunctionalityBean service){
|
||||
|
||||
String currentScope = voScopes.get(0);
|
||||
HashSet<String> scopeSet = new HashSet<String>();
|
||||
logger.info("Adding back resource with id " + resourceId + "("+ service + ") to scopes " + allScopes);
|
||||
|
||||
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();
|
||||
String currentScope = allScopes.get(0); // infrastructure root
|
||||
ScopeProvider.instance.set(currentScope);
|
||||
|
||||
scopeSet.addAll(voScopes);
|
||||
SimpleQuery query = ICFactory.queryFor(service.getType());
|
||||
DiscoveryClient<T> client = ICFactory.clientFor(service.getType());
|
||||
query.addCondition("$resource/ID/text() = '"+resourceId+"'");
|
||||
T resource = client.submit(query).get(0);
|
||||
|
||||
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);
|
||||
}
|
||||
resource.scopes().asCollection().retainAll(Collections.emptyList()); // remove all scopes
|
||||
resource.scopes().asCollection().addAll(allScopes); // add them all again
|
||||
|
||||
for (String resourceId : resourceIds){
|
||||
RegistryPublisher pub = RegistryPublisherFactory.create();
|
||||
pub.vosUpdate(resource);
|
||||
|
||||
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();
|
||||
logger.debug("onStop() invoked");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class ResourceCheckerPluginDeclaration implements PluginDeclaration {
|
|||
*/
|
||||
public static final String NAME = "resource-checker-se-plugin";
|
||||
public static final String DESCRIPTION = "The resource-checker-plugin has the role to check the existence of some resources in all Infrastructure's contexts.";
|
||||
public static final String VERSION = "1.0.0";
|
||||
public static final String VERSION = "1.1.0";
|
||||
|
||||
/**{@inheritDoc}*/
|
||||
@Override
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.resource_checker.utils;
|
||||
package org.gcube.informationsystem.resource_checker.beans;
|
||||
|
||||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||
import org.gcube.common.resources.gcore.GenericResource;
|
||||
|
@ -8,7 +8,9 @@ import org.gcube.common.resources.gcore.Resource.Type;
|
|||
import org.gcube.common.resources.gcore.Software;
|
||||
|
||||
/**
|
||||
* A basic functionality bean with name, category and type
|
||||
* A basic functionality bean with name, category and type.
|
||||
* Resource Identifier will be discovered at run time. It is supposed that the same resource
|
||||
* is published in all contexts (so the identifier is the same).
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
|
@ -16,14 +18,17 @@ public class BasicFunctionalityBean {
|
|||
|
||||
private String category;
|
||||
private String name;
|
||||
private Class type; // service endpoint only for now
|
||||
private Class type;
|
||||
private String resourceId;
|
||||
private OperationLevel opLevel = OperationLevel.ALERT_READD;
|
||||
private ContextLevel ctxLevel = ContextLevel.ALL;
|
||||
|
||||
/**
|
||||
* @param category
|
||||
* @param name
|
||||
* @param type
|
||||
*/
|
||||
public BasicFunctionalityBean(String category, String name, String type) {
|
||||
public BasicFunctionalityBean(String category, String name, String type, String opLevel, String ctxLevel) {
|
||||
super();
|
||||
this.category = category;
|
||||
this.name = name;
|
||||
|
@ -34,9 +39,6 @@ public class BasicFunctionalityBean {
|
|||
Type extractedType = Type.valueOf(type);
|
||||
|
||||
switch(extractedType){
|
||||
case ENDPOINT:
|
||||
this.type = ServiceEndpoint.class;
|
||||
break;
|
||||
case GCOREENDPOINT:
|
||||
this.type = GCoreEndpoint.class;
|
||||
break;
|
||||
|
@ -49,10 +51,18 @@ public class BasicFunctionalityBean {
|
|||
case SOFTWARE:
|
||||
this.type = Software.class;
|
||||
break;
|
||||
case ENDPOINT:
|
||||
default:
|
||||
this.type = ServiceEndpoint.class;
|
||||
}
|
||||
}
|
||||
|
||||
if(opLevel != null)
|
||||
this.opLevel = OperationLevel.valueOf(opLevel);
|
||||
|
||||
if(ctxLevel != null)
|
||||
this.ctxLevel = ContextLevel.valueOf(ctxLevel);
|
||||
|
||||
}
|
||||
public String getCategory() {
|
||||
return category;
|
||||
|
@ -72,10 +82,29 @@ public class BasicFunctionalityBean {
|
|||
public void Class(Class type) {
|
||||
this.type = type;
|
||||
}
|
||||
public String getResourceId() {
|
||||
return resourceId;
|
||||
}
|
||||
public void setResourceId(String resourceId) {
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
public OperationLevel getOpLevel() {
|
||||
return opLevel;
|
||||
}
|
||||
public void setOpLevel(OperationLevel opLevel) {
|
||||
this.opLevel = opLevel;
|
||||
}
|
||||
public ContextLevel getCtxLevel() {
|
||||
return ctxLevel;
|
||||
}
|
||||
public void setCtxLevel(ContextLevel ctxLevel) {
|
||||
this.ctxLevel = ctxLevel;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BasicFunctionalityBean [category=" + category + ", name="
|
||||
+ name + ", type=" + type + "]";
|
||||
+ name + ", type=" + type + ", resourceId=" + resourceId
|
||||
+ ", opLevel=" + opLevel + ", ctxLevel=" + ctxLevel + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package org.gcube.informationsystem.resource_checker.beans;
|
||||
|
||||
/**
|
||||
* Evaluate at which level the resource must be checked.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public enum ContextLevel {
|
||||
|
||||
VO, // check only at VO level (and root vo)
|
||||
ALL // check at all levels
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package org.gcube.informationsystem.resource_checker.beans;
|
||||
|
||||
/**
|
||||
* Enumerators for the actions to be taken wrt missing resources: ALERT only or ALERT and READD
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public enum OperationLevel {
|
||||
|
||||
ALERT_READD, // alert and readd the resource
|
||||
ALERT // just alert it is missing
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.gcube.informationsystem.resource_checker.beans.BasicFunctionalityBean;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -23,6 +24,8 @@ public class BasicFunctionalitiesMandatoryReader {
|
|||
private static final String SERVICE_NAME_KEY = "ServiceNames";
|
||||
private static final String CATEGORY_NAME_KEY = "CategoryNames";
|
||||
private static final String TYPES = "Types";
|
||||
private static final String CONTEXTS = "Contexts";
|
||||
private static final String OPERATIONS = "Operations";
|
||||
private static final String SEPARATOR = ",";
|
||||
|
||||
public BasicFunctionalitiesMandatoryReader() throws Exception{
|
||||
|
@ -42,17 +45,27 @@ public class BasicFunctionalitiesMandatoryReader {
|
|||
String serviceNames = prop.getProperty(SERVICE_NAME_KEY);
|
||||
String serviceCategories = prop.getProperty(CATEGORY_NAME_KEY);
|
||||
String types = prop.getProperty(TYPES);
|
||||
String contexts = prop.getProperty(CONTEXTS);
|
||||
String operations = prop.getProperty(OPERATIONS);
|
||||
|
||||
if(serviceNames == null || serviceCategories == null)
|
||||
throw new Exception("Service names or categories are missing in file " + FILE_PROPRETIES_LOCATION_PATH);
|
||||
|
||||
String[] serviceNamesSplitted = serviceNames.split(SEPARATOR);
|
||||
String[] serviceCategoriesSplitted = serviceCategories.split(SEPARATOR);
|
||||
|
||||
String[] typesSplitted = null;
|
||||
String[] contextsSplitted = null;
|
||||
String[] operationsSplitted = null;
|
||||
|
||||
if(types != null)
|
||||
typesSplitted = types.split(SEPARATOR);
|
||||
|
||||
if(contexts != null)
|
||||
contextsSplitted = contexts.split(SEPARATOR);
|
||||
|
||||
if(operations != null)
|
||||
operationsSplitted = operations.split(SEPARATOR);
|
||||
|
||||
// build the java objects
|
||||
if(serviceNamesSplitted.length != serviceCategoriesSplitted.length)
|
||||
throw new Exception("The file at " + FILE_PROPRETIES_LOCATION_PATH + " seems to be malformed (service names and categories number do not match)!");
|
||||
|
@ -60,10 +73,21 @@ public class BasicFunctionalitiesMandatoryReader {
|
|||
if(typesSplitted != null && serviceNamesSplitted.length != typesSplitted.length)
|
||||
throw new Exception("The file at " + FILE_PROPRETIES_LOCATION_PATH + " seems to be malformed (types lenght doesn't match the other properties)!");
|
||||
|
||||
if(contextsSplitted != null && serviceNamesSplitted.length != contextsSplitted.length)
|
||||
throw new Exception("The file at " + FILE_PROPRETIES_LOCATION_PATH + " seems to be malformed (contexts lenght doesn't match the other properties)!");
|
||||
|
||||
if(operationsSplitted != null && serviceNamesSplitted.length != operationsSplitted.length)
|
||||
throw new Exception("The file at " + FILE_PROPRETIES_LOCATION_PATH + " seems to be malformed (operations lenght doesn't match the other properties)!");
|
||||
|
||||
// Build the objects
|
||||
mandatoryFunctionalities = new ArrayList<BasicFunctionalityBean>();
|
||||
for (int i = 0; i < serviceCategoriesSplitted.length; i++) {
|
||||
mandatoryFunctionalities.add(new BasicFunctionalityBean(serviceCategoriesSplitted[i], serviceNamesSplitted[i], typesSplitted != null ? typesSplitted[i] : null));
|
||||
mandatoryFunctionalities.add(new BasicFunctionalityBean(
|
||||
serviceCategoriesSplitted[i],
|
||||
serviceNamesSplitted[i],
|
||||
typesSplitted != null ? typesSplitted[i] : null,
|
||||
operationsSplitted != null ? operationsSplitted[i] : null,
|
||||
contextsSplitted != null ? contextsSplitted[i] : null ));
|
||||
}
|
||||
|
||||
logger.info("Built list is " + mandatoryFunctionalities);
|
||||
|
|
|
@ -48,7 +48,7 @@ public class RetrieveContextsList {
|
|||
SimpleQuery queryVRE = ICFactory.queryFor(GenericResource.class);
|
||||
queryVRE.addCondition("$resource/Profile/SecondaryType/text() = 'VRE'");
|
||||
queryVRE.setResult("$resource/Profile/Body/Scope/string()");
|
||||
|
||||
String currentScope = ScopeProvider.instance.get();
|
||||
DiscoveryClient vREScopeClient = ICFactory.client();
|
||||
|
||||
List<String> vres = new ArrayList<String>();
|
||||
|
@ -61,6 +61,7 @@ public class RetrieveContextsList {
|
|||
}
|
||||
|
||||
voContexts.addAll(vres);
|
||||
ScopeProvider.instance.set(currentScope);
|
||||
|
||||
logger.info("List of all contexts is " + voContexts);
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.informationsystem.resource_checker.ResourceCheckerPluginDeclaration;
|
||||
import org.gcube.informationsystem.resource_checker.beans.BasicFunctionalityBean;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
|
||||
|
@ -205,11 +206,13 @@ public class SendNotification extends PluginStateNotification {
|
|||
sb.append("none.");
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<java.lang.String, java.util.List<org.gcube.informationsystem.resource_checker.utils.BasicFunctionalityBean>> entry = (Map.Entry<java.lang.String, java.util.List<org.gcube.informationsystem.resource_checker.utils.BasicFunctionalityBean>>) iterator
|
||||
Map.Entry<java.lang.String, java.util.List<org.gcube.informationsystem.resource_checker.beans.BasicFunctionalityBean>> entry = (Map.Entry<java.lang.String, java.util.List<org.gcube.informationsystem.resource_checker.beans.BasicFunctionalityBean>>) iterator
|
||||
.next();
|
||||
List<BasicFunctionalityBean> list = entry.getValue();
|
||||
for (BasicFunctionalityBean basicFunctionalityBean : list) {
|
||||
sb.append("- resource's name ");
|
||||
sb.append("- resource's id is ");
|
||||
sb.append(basicFunctionalityBean.getResourceId());
|
||||
sb.append(", resource's name ");
|
||||
sb.append(basicFunctionalityBean.getName());
|
||||
sb.append(" and resource's class/category ");
|
||||
sb.append(basicFunctionalityBean.getCategory());
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
#Resources to fetch are reported here. It can be read as follows
|
||||
# Resources to fetch are reported here. It can be read as follows
|
||||
# check for resource having (ServiceName = ServiceNames[i], CategoryName = CategoryNames[i])
|
||||
# where i stands for the i-th position
|
||||
ServiceNames=HTTP-URI-Resolver,Persistence,StorageManager
|
||||
CategoryNames=Service,Accounting,DataStorage
|
||||
# For Types look at org.gcube.informationsystem.resource_checker.beans.BasicFunctionalityBean
|
||||
# For Contexts: ALL means it has to check a resource in all contexts, VO just in ROOT VO and VOs
|
||||
# For Operations: ALERT_READD means the service is readded and alert is sent, or only alert is sent (ALERT)
|
||||
ServiceNames=HTTP-URI-Resolver,Persistence,StorageManager,HomeLibraryWebapp
|
||||
CategoryNames=Service,Accounting,DataStorage,DataAccess
|
||||
Types=ENDPOINT,ENDPOINT,ENDPOINT,GCOREENDPOINT
|
||||
Contexts=ALL,ALL,ALL,VO
|
||||
Operations=ALERT_READD,ALERT_READD,ALERT_READD,ALERT
|
Loading…
Reference in New Issue