Fixed dependencies and added test to launch the plugin
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-checker-se-plugin@179105 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
4996ba14fe
commit
e2aa2bb5b7
31
pom.xml
31
pom.xml
|
@ -60,12 +60,6 @@
|
|||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>[4.0.0,)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
|
@ -83,6 +77,31 @@
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.vremanagement</groupId>
|
||||
<artifactId>smart-executor-client</artifactId>
|
||||
<version>1.7.0-SNAPSHOT</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.0.13</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -1 +1 @@
|
|||
location=/home/gcube/missing_resources/identifiers
|
||||
location=/home/lucafrosini/missing_resources/identifiers
|
|
@ -0,0 +1,86 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.resource_checker;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.gcube.common.authorization.client.Constants;
|
||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||
import org.gcube.common.authorization.library.provider.ClientInfo;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.authorization.library.utils.Caller;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
public class ContextTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
|
||||
|
||||
protected static Properties properties;
|
||||
protected static final String PROPERTIES_FILENAME = "token.properties";
|
||||
|
||||
public static final String DEFAULT_TEST_SCOPE_NAME;
|
||||
|
||||
static {
|
||||
properties = new Properties();
|
||||
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
|
||||
|
||||
try {
|
||||
// load the properties file
|
||||
properties.load(input);
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
//DEFAULT_TEST_SCOPE_NAME = "/d4science.research-infrastructures.eu";
|
||||
//DEFAULT_TEST_SCOPE_NAME = "/pred4s";
|
||||
DEFAULT_TEST_SCOPE_NAME = "/gcube";
|
||||
}
|
||||
|
||||
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
|
||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||
String context = authorizationEntry.getContext();
|
||||
logger.info("Context of token {} is {}", token, context);
|
||||
return context;
|
||||
}
|
||||
|
||||
public static void setContextByName(String fullContextName) throws ObjectNotFound, Exception {
|
||||
String token = ContextTest.properties.getProperty(fullContextName);
|
||||
setContext(token);
|
||||
}
|
||||
|
||||
public static void setContext(String token) throws ObjectNotFound, Exception {
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||
ClientInfo clientInfo = authorizationEntry.getClientInfo();
|
||||
logger.debug("User : {} - Type : {}", clientInfo.getId(), clientInfo.getType().name());
|
||||
String qualifier = authorizationEntry.getQualifier();
|
||||
Caller caller = new Caller(clientInfo, qualifier);
|
||||
AuthorizationProvider.instance.set(caller);
|
||||
ScopeProvider.instance.set(getCurrentScope(token));
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
setContextByName(DEFAULT_TEST_SCOPE_NAME);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
||||
}
|
|
@ -3,22 +3,64 @@ package org.gcube.informationsystem.resource_checker;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.informationsystem.resource_checker.ResourceCheckerPlugin;
|
||||
import org.gcube.informationsystem.resource_checker.utils.SendNotification;
|
||||
import org.gcube.vremanagement.executor.api.rest.SmartExecutor;
|
||||
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
||||
import org.gcube.vremanagement.executor.api.types.Scheduling;
|
||||
import org.gcube.vremanagement.executor.client.SmartExecutorClientFactory;
|
||||
import org.gcube.vremanagement.executor.json.SEMapper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.quartz.CronExpression;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class TestResourceChecker{
|
||||
public class TestResourceChecker extends ContextTest {
|
||||
|
||||
//@Test
|
||||
private static Logger logger = LoggerFactory.getLogger(TestResourceChecker.class);
|
||||
|
||||
@Test
|
||||
public void launchPlugin() throws Exception{
|
||||
|
||||
// ScopeProvider.instance.set(....);
|
||||
// SecurityTokenProvider.instance.set(....);
|
||||
// ContextTest.setContextByName("/d4science.research-infrastructures.eu");
|
||||
|
||||
ContextTest.setContextByName("/gcube");
|
||||
|
||||
ResourceCheckerPlugin checker = new ResourceCheckerPlugin(null);
|
||||
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||
inputs.put(SendNotification.RECIPIENT_KEY, null);
|
||||
inputs.put(ResourceCheckerPlugin.ROLE_TO_NOTIFY, null);
|
||||
inputs.put(ResourceCheckerPlugin.ROLE_TO_NOTIFY, "Administrator");
|
||||
checker.launch(inputs);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchRemotely() throws Exception{
|
||||
ContextTest.setContextByName("/d4science.research-infrastructures.eu");
|
||||
|
||||
SmartExecutor smartExecutor = SmartExecutorClientFactory.create(ResourceCheckerPluginDeclaration.NAME);
|
||||
Assert.assertNotNull(smartExecutor);
|
||||
|
||||
try {
|
||||
|
||||
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||
inputs.put(SendNotification.RECIPIENT_KEY, null);
|
||||
inputs.put(ResourceCheckerPlugin.ROLE_TO_NOTIFY, "Administrator");
|
||||
|
||||
LaunchParameter launchParameter = new LaunchParameter(ResourceCheckerPluginDeclaration.NAME, inputs);
|
||||
|
||||
// Every day at 8:00
|
||||
CronExpression cronExpression = new CronExpression("0 0 8 1/1 * ? *");
|
||||
Scheduling scheduling = new Scheduling(cronExpression, true);
|
||||
scheduling.setGlobal(false);
|
||||
|
||||
launchParameter.setScheduling(scheduling);
|
||||
|
||||
String uuidString = smartExecutor.launch(SEMapper.marshal(launchParameter));
|
||||
logger.debug("Launched with UUID : {}", uuidString);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while launching {}", e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
<infrastructures>
|
||||
|
||||
<infrastructure>
|
||||
<name>d4science</name>
|
||||
<vos>
|
||||
<vo>
|
||||
<name>d4science</name>
|
||||
<src>ServiceMap_d4science.research-infrastructures.eu.xml</src>
|
||||
<scope>/d4science.research-infrastructures.eu</scope>
|
||||
</vo>
|
||||
<vo>
|
||||
<name>d4science/D4Research</name>
|
||||
<src>ServiceMap_D4Research.xml</src>
|
||||
<scope>/d4science.research-infrastructures.eu/D4Research</scope>
|
||||
</vo>
|
||||
<vo>
|
||||
<name>d4science/FARM</name>
|
||||
<src>ServiceMap_FARM.xml</src>
|
||||
<scope>/d4science.research-infrastructures.eu/FARM</scope>
|
||||
</vo>
|
||||
<vo>
|
||||
<name>d4science/gCubeApps</name>
|
||||
<src>ServiceMap_gCubeApps.xml</src>
|
||||
<scope>/d4science.research-infrastructures.eu/gCubeApps</scope>
|
||||
</vo>
|
||||
<vo>
|
||||
<name>d4science/OpenAIRE</name>
|
||||
<src>ServiceMap_OpenAIRE.xml</src>
|
||||
<scope>/d4science.research-infrastructures.eu/OpenAIRE</scope>
|
||||
</vo>
|
||||
<vo>
|
||||
<name>d4science/SmartArea</name>
|
||||
<src>ServiceMap_SmartArea.xml</src>
|
||||
<scope>/d4science.research-infrastructures.eu/SmartArea</scope>
|
||||
</vo>
|
||||
<vo>
|
||||
<name>d4science/SoBigData</name>
|
||||
<src>ServiceMap_SoBigData.xml</src>
|
||||
<scope>/d4science.research-infrastructures.eu/SoBigData</scope>
|
||||
</vo>
|
||||
</vos>
|
||||
</infrastructure>
|
||||
|
||||
<infrastructure>
|
||||
<name>gcube</name>
|
||||
<vos>
|
||||
<vo>
|
||||
<name>gcube</name>
|
||||
<src>ServiceMap_gcube.xml</src>
|
||||
<scope>/gcube</scope>
|
||||
</vo>
|
||||
<vo>
|
||||
<name>gcube/devsec</name>
|
||||
<src>ServiceMap_devsec.xml</src>
|
||||
<scope>/gcube/devsec</scope>
|
||||
</vo>
|
||||
<vo>
|
||||
<name>gcube/devNext</name>
|
||||
<src>ServiceMap_devNext.xml</src>
|
||||
<scope>/gcube/devNext</scope>
|
||||
</vo>
|
||||
<vo>
|
||||
<name>gcube/preprod</name>
|
||||
<src>ServiceMap_preprod.xml</src>
|
||||
<scope>/gcube/preprod</scope>
|
||||
</vo>
|
||||
</vos>
|
||||
</infrastructure>
|
||||
|
||||
</infrastructures>
|
|
@ -0,0 +1 @@
|
|||
location=/home/gcube/missing_resources/identifiers
|
|
@ -0,0 +1,11 @@
|
|||
# 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
|
||||
# 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
|
|
@ -0,0 +1 @@
|
|||
org.gcube.informationsystem.resource_checker.ResourceCheckerPluginDeclaration
|
|
@ -0,0 +1,16 @@
|
|||
<configuration>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
||||
<logger name="org.gcube" level="TRACE" />
|
||||
|
||||
<root level="WARN">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
Loading…
Reference in New Issue