Fixing project to migrate monthly aggregated accounting records in a
dedicated bucket #12803
This commit is contained in:
parent
06faf22fbf
commit
b26baa781a
|
@ -0,0 +1,3 @@
|
||||||
|
/org.eclipse.core.resources.prefs
|
||||||
|
/org.eclipse.jdt.core.prefs
|
||||||
|
/org.eclipse.m2e.core.prefs
|
|
@ -6,7 +6,7 @@ import java.util.Date;
|
||||||
|
|
||||||
import org.gcube.accounting.aggregator.aggregation.AggregationType;
|
import org.gcube.accounting.aggregator.aggregation.AggregationType;
|
||||||
import org.gcube.accounting.aggregator.directory.WorkSpaceDirectoryStructure;
|
import org.gcube.accounting.aggregator.directory.WorkSpaceDirectoryStructure;
|
||||||
import org.gcube.accounting.aggregator.plugin.ScopedTest;
|
import org.gcube.accounting.aggregator.plugin.ContextTest;
|
||||||
import org.gcube.accounting.aggregator.utility.Constant;
|
import org.gcube.accounting.aggregator.utility.Constant;
|
||||||
import org.gcube.accounting.aggregator.utility.Utility;
|
import org.gcube.accounting.aggregator.utility.Utility;
|
||||||
import org.gcube.accounting.aggregator.workspace.WorkSpaceManagement;
|
import org.gcube.accounting.aggregator.workspace.WorkSpaceManagement;
|
||||||
|
@ -14,7 +14,7 @@ import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class WorkSpaceDirectoryStructureTest extends ScopedTest {
|
public class WorkSpaceDirectoryStructureTest extends ContextTest {
|
||||||
|
|
||||||
public static Logger logger = LoggerFactory.getLogger(WorkSpaceDirectoryStructureTest.class);
|
public static Logger logger = LoggerFactory.getLogger(WorkSpaceDirectoryStructureTest.class);
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,16 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
public class AccountingAggregatorPluginTest extends ScopedTest {
|
public class AccountingAggregatorPluginTest extends ContextTest {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(AccountingAggregatorPluginTest.class);
|
private static Logger logger = LoggerFactory.getLogger(AccountingAggregatorPluginTest.class);
|
||||||
|
|
||||||
|
private static final String ROOT_PROD = "/d4science.research-infrastructures.eu";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aggregate() throws Exception {
|
public void aggregate() throws Exception {
|
||||||
//setContext(ROOT);
|
ContextTest.setContextByName(PARENT_DEFAULT_TEST_SCOPE);
|
||||||
|
// ContextTest.setContextByName(ROOT_PROD);
|
||||||
|
|
||||||
Map<String, Object> inputs = new HashMap<String, Object>();
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
@ -41,20 +44,26 @@ public class AccountingAggregatorPluginTest extends ScopedTest {
|
||||||
inputs.put(AccountingAggregatorPlugin.FORCE_RERUN, false);
|
inputs.put(AccountingAggregatorPlugin.FORCE_RERUN, false);
|
||||||
inputs.put(AccountingAggregatorPlugin.FORCE_RESTART, true);
|
inputs.put(AccountingAggregatorPlugin.FORCE_RESTART, true);
|
||||||
|
|
||||||
Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2017, Calendar.OCTOBER, 1);
|
Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2016, Calendar.OCTOBER, 1);
|
||||||
String aggregationStartDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationStartCalendar.getTime());
|
String aggregationStartDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationStartCalendar.getTime());
|
||||||
logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
||||||
inputs.put(AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
||||||
|
|
||||||
|
/*
|
||||||
Calendar aggregationEndCalendar = Utility.getAggregationStartCalendar(2017, Calendar.DECEMBER, 31);
|
Calendar aggregationEndCalendar = Utility.getAggregationStartCalendar(2017, Calendar.DECEMBER, 31);
|
||||||
String aggregationEndDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationEndCalendar.getTime());
|
String aggregationEndDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationEndCalendar.getTime());
|
||||||
logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationEndDate);
|
logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationEndDate);
|
||||||
inputs.put(AccountingAggregatorPlugin.AGGREGATION_END_DATE_INPUT_PARAMETER, aggregationEndDate);
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_END_DATE_INPUT_PARAMETER, aggregationEndDate);
|
||||||
|
*/
|
||||||
|
|
||||||
AccountingAggregatorPlugin plugin = new AccountingAggregatorPlugin(null);
|
AccountingAggregatorPlugin plugin = new AccountingAggregatorPlugin(null);
|
||||||
logger.debug("Going to launch {} with inputs {}", AccountingAggregatorPluginDeclaration.NAME, inputs);
|
logger.debug("Going to launch {} with inputs {}", AccountingAggregatorPluginDeclaration.NAME, inputs);
|
||||||
|
|
||||||
plugin.launch(inputs);
|
while(aggregationStartCalendar.get(Calendar.YEAR)!=2018) {
|
||||||
|
aggregationStartCalendar.add(Calendar.MONTH, 1);
|
||||||
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
||||||
|
plugin.launch(inputs);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +79,9 @@ public class AccountingAggregatorPluginTest extends ScopedTest {
|
||||||
|
|
||||||
// @Test
|
// @Test
|
||||||
public void testRecovery() throws Exception {
|
public void testRecovery() throws Exception {
|
||||||
setContext(ROOT);
|
ContextTest.setContextByName(PARENT_DEFAULT_TEST_SCOPE);
|
||||||
|
// ContextTest.setContextByName(ROOT_PROD);
|
||||||
|
|
||||||
Map<String, Object> inputs = new HashMap<String, Object>();
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||||
|
|
||||||
inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.RECOVERY.name());
|
inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.RECOVERY.name());
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.accounting.aggregator.plugin;
|
||||||
|
|
||||||
|
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 PARENT_DEFAULT_TEST_SCOPE;
|
||||||
|
public static final String DEFAULT_TEST_SCOPE;
|
||||||
|
public static final String ALTERNATIVE_TEST_SCOPE;
|
||||||
|
|
||||||
|
public static final String DEFAULT_TEST_SCOPE_ANOTHER_USER;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PARENT_DEFAULT_TEST_SCOPE = "/pred4s"
|
||||||
|
// DEFAULT_TEST_SCOPE_NAME = PARENT_DEFAULT_TEST_SCOPE + "/preprod";
|
||||||
|
// ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE_NAME + "/preVRE";
|
||||||
|
|
||||||
|
|
||||||
|
PARENT_DEFAULT_TEST_SCOPE = "/gcube";
|
||||||
|
DEFAULT_TEST_SCOPE = PARENT_DEFAULT_TEST_SCOPE + "/devNext";
|
||||||
|
ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE + "/NextNext";
|
||||||
|
|
||||||
|
DEFAULT_TEST_SCOPE_ANOTHER_USER = "lucio.lelii_" + DEFAULT_TEST_SCOPE;
|
||||||
|
|
||||||
|
try {
|
||||||
|
setContextByName(DEFAULT_TEST_SCOPE);
|
||||||
|
} catch(Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
private 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void afterClass() throws Exception {
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -16,7 +16,7 @@ import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class CouchBaseConnectorTest extends ScopedTest {
|
public class CouchBaseConnectorTest extends ContextTest {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(AccountingAggregatorPluginTest.class);
|
private static Logger logger = LoggerFactory.getLogger(AccountingAggregatorPluginTest.class);
|
||||||
|
|
||||||
|
|
|
@ -1,98 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.gcube.accounting.aggregator.plugin;
|
|
||||||
|
|
||||||
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.SecurityTokenProvider;
|
|
||||||
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 ScopedTest {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ScopedTest.class);
|
|
||||||
|
|
||||||
protected static final String PROPERTIES_FILENAME = "token.properties";
|
|
||||||
|
|
||||||
private static final String GCUBE_DEVNEXT_VARNAME = "GCUBE_DEVNEXT";
|
|
||||||
public static final String GCUBE_DEVNEXT;
|
|
||||||
|
|
||||||
private static final String GCUBE_DEVNEXT_NEXTNEXT_VARNAME = "GCUBE_DEVNEXT_NEXTNEXT";
|
|
||||||
public static final String GCUBE_DEVNEXT_NEXTNEXT;
|
|
||||||
|
|
||||||
public static final String GCUBE_DEVSEC_VARNAME = "GCUBE_DEVSEC";
|
|
||||||
public static final String GCUBE_DEVSEC;
|
|
||||||
|
|
||||||
public static final String GCUBE_DEVSEC_DEVVRE_VARNAME = "GCUBE_DEVSEC_DEVVRE";
|
|
||||||
public static final String GCUBE_DEVSEC_DEVVRE;
|
|
||||||
|
|
||||||
public static final String GCUBE_VARNAME = "GCUBE";
|
|
||||||
public static final String GCUBE;
|
|
||||||
|
|
||||||
public static final String DEFAULT_TEST_SCOPE;
|
|
||||||
|
|
||||||
public static final String ROOT_VARNAME = "ROOT";
|
|
||||||
public static final String ROOT;
|
|
||||||
|
|
||||||
static {
|
|
||||||
Properties properties = new Properties();
|
|
||||||
InputStream input = ScopedTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// load the properties file
|
|
||||||
properties.load(input);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
GCUBE = properties.getProperty(GCUBE_VARNAME);
|
|
||||||
|
|
||||||
GCUBE_DEVNEXT = properties.getProperty(GCUBE_DEVNEXT_VARNAME);
|
|
||||||
GCUBE_DEVNEXT_NEXTNEXT = properties.getProperty(GCUBE_DEVNEXT_NEXTNEXT_VARNAME);
|
|
||||||
|
|
||||||
GCUBE_DEVSEC = properties.getProperty(GCUBE_DEVSEC_VARNAME);
|
|
||||||
GCUBE_DEVSEC_DEVVRE = properties.getProperty(GCUBE_DEVSEC_DEVVRE_VARNAME);
|
|
||||||
|
|
||||||
ROOT = properties.getProperty(ROOT_VARNAME);
|
|
||||||
|
|
||||||
DEFAULT_TEST_SCOPE = GCUBE_DEVSEC;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 setContext(String token) throws ObjectNotFound, Exception{
|
|
||||||
SecurityTokenProvider.instance.set(token);
|
|
||||||
ScopeProvider.instance.set(getCurrentScope(token));
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void beforeClass() throws Exception{
|
|
||||||
setContext(DEFAULT_TEST_SCOPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterClass
|
|
||||||
public static void afterClass() throws Exception{
|
|
||||||
SecurityTokenProvider.instance.reset();
|
|
||||||
ScopeProvider.instance.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -3,8 +3,7 @@ package org.gcube.accounting.aggregator.workspace;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.accounting.aggregator.plugin.ScopedTest;
|
import org.gcube.accounting.aggregator.plugin.ContextTest;
|
||||||
import org.gcube.accounting.aggregator.workspace.WorkSpaceManagement;
|
|
||||||
import org.gcube.common.resources.gcore.GCoreEndpoint.Profile;
|
import org.gcube.common.resources.gcore.GCoreEndpoint.Profile;
|
||||||
import org.gcube.common.resources.gcore.GCoreEndpoint.Profile.Endpoint;
|
import org.gcube.common.resources.gcore.GCoreEndpoint.Profile.Endpoint;
|
||||||
import org.gcube.common.resources.gcore.utils.Group;
|
import org.gcube.common.resources.gcore.utils.Group;
|
||||||
|
@ -12,7 +11,7 @@ import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class WorkSpaceManagementTest extends ScopedTest {
|
public class WorkSpaceManagementTest extends ContextTest {
|
||||||
|
|
||||||
public static Logger logger = LoggerFactory.getLogger(WorkSpaceManagementTest.class);
|
public static Logger logger = LoggerFactory.getLogger(WorkSpaceManagementTest.class);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
/devNext.gcubekey
|
||||||
|
/devsec.gcubekey
|
||||||
|
/gcube.gcubekey
|
||||||
|
/preprod.gcubekey
|
||||||
|
/token.properties
|
Loading…
Reference in New Issue