Code redesign
Refs #11756: Refactor DataHArvesterPlugin to support scheduled execution from smart-executor Task-Url: https://support.d4science.org/issues/11756 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-dashboard-harvester-se-plugin@167599 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d5cdc30748
commit
bad93fa5f7
|
@ -27,7 +27,7 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
|
|
|
@ -1,8 +1,2 @@
|
||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
|
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
org.eclipse.jdt.core.compiler.source=1.8
|
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -119,7 +119,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.portlets.admin</groupId>
|
<groupId>org.gcube.portlets.admin</groupId>
|
||||||
<artifactId>rmp-common-library</artifactId>
|
<artifactId>rmp-common-library</artifactId>
|
||||||
<version>[2.7.1-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
<version>[2.7.2-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -2,8 +2,6 @@ package org.gcube.dataharvest.utils;
|
||||||
|
|
||||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
@ -16,7 +14,7 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
import org.gcube.common.scope.impl.ScopeBean;
|
||||||
import org.gcube.dataharvest.AccountingDataHarvesterPlugin;
|
import org.gcube.dataharvest.AccountingDataHarvesterPlugin;
|
||||||
import org.gcube.resourcemanagement.support.server.managers.scope.ScopeManager;
|
import org.gcube.resourcemanagement.support.server.managers.context.ContextManager;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -27,9 +25,6 @@ public class ContextAuthorization {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(ContextAuthorization.class);
|
private static Logger logger = LoggerFactory.getLogger(ContextAuthorization.class);
|
||||||
|
|
||||||
public static final String VO_FILE = "VO_FILE";
|
|
||||||
public static final String DEFAULT_VO_FILENAME = "scopedata.xml";
|
|
||||||
|
|
||||||
public static final String USERNAME = "USERNAME";
|
public static final String USERNAME = "USERNAME";
|
||||||
public static final String DEFAULT_USERNAME = "luca.frosini";
|
public static final String DEFAULT_USERNAME = "luca.frosini";
|
||||||
|
|
||||||
|
@ -55,22 +50,6 @@ public class ContextAuthorization {
|
||||||
retrieveContextsAndTokens();
|
retrieveContextsAndTokens();
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getVOFile() {
|
|
||||||
try {
|
|
||||||
String voFileName = AccountingDataHarvesterPlugin.getProperties().get().getProperty(VO_FILE,
|
|
||||||
DEFAULT_VO_FILENAME);
|
|
||||||
URL url = ContextAuthorization.class.getClassLoader().getResource(voFileName);
|
|
||||||
File voFile = new File(url.toURI());
|
|
||||||
logger.trace("VO file is {}", voFile);
|
|
||||||
if(!voFile.exists()) {
|
|
||||||
throw new Exception("No VO file found. Unable to continue without it");
|
|
||||||
}
|
|
||||||
return voFile;
|
|
||||||
} catch(Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void retrieveContextsAndTokens() throws Exception {
|
protected void retrieveContextsAndTokens() throws Exception {
|
||||||
|
|
||||||
String initialToken = SecurityTokenProvider.instance.get();
|
String initialToken = SecurityTokenProvider.instance.get();
|
||||||
|
@ -79,11 +58,10 @@ public class ContextAuthorization {
|
||||||
|
|
||||||
Properties properties = AccountingDataHarvesterPlugin.getProperties().get();
|
Properties properties = AccountingDataHarvesterPlugin.getProperties().get();
|
||||||
|
|
||||||
LinkedHashMap<String,ScopeBean> map = ScopeManager.readScopes(getVOFile().getAbsolutePath());
|
LinkedHashMap<String,ScopeBean> map = ContextManager.readContexts();
|
||||||
for(String scope : map.keySet()) {
|
for(String scope : map.keySet()) {
|
||||||
try {
|
try {
|
||||||
String context = map.get(scope).toString();
|
String context = map.get(scope).toString();
|
||||||
System.out.println("Going to generate Token for Context " + context);
|
|
||||||
logger.info("Going to generate Token for Context {}", context);
|
logger.info("Going to generate Token for Context {}", context);
|
||||||
UserInfo userInfo = new UserInfo(properties.getProperty(USERNAME, DEFAULT_USERNAME),
|
UserInfo userInfo = new UserInfo(properties.getProperty(USERNAME, DEFAULT_USERNAME),
|
||||||
new ArrayList<>());
|
new ArrayList<>());
|
||||||
|
|
|
@ -27,17 +27,6 @@ public class ContextAuthorizationTest extends ContextTest {
|
||||||
AccountingDataHarvesterPlugin.getProperties().set(properties);
|
AccountingDataHarvesterPlugin.getProperties().set(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetVOFile() throws Exception {
|
|
||||||
try {
|
|
||||||
getConfigParameters();
|
|
||||||
}catch (Exception e) {
|
|
||||||
logger.warn("Unable to load {} file containing configuration properties. AccountingDataHarvesterPlugin will use defaults", PROPERTY_FILENAME);
|
|
||||||
}
|
|
||||||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
|
||||||
contextAuthorization.getVOFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRetrieveContextsAndTokens() throws Exception {
|
public void testRetrieveContextsAndTokens() throws Exception {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue