Cleaning code
This commit is contained in:
parent
d3ad4f43ae
commit
e0fd599c80
|
@ -79,19 +79,6 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final InheritableThreadLocal<Properties> properties = new InheritableThreadLocal<Properties>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Properties initialValue() {
|
|
||||||
return new Properties();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
public static InheritableThreadLocal<Properties> getProperties() {
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Dimension getDimension(String key) {
|
public static Dimension getDimension(String key) {
|
||||||
Dimension dimension = dimensions.get().get(key);
|
Dimension dimension = dimensions.get().get(key);
|
||||||
if (dimension == null) {
|
if (dimension == null) {
|
||||||
|
@ -122,21 +109,8 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public static ScopeDescriptor getScopeDescriptor() {
|
|
||||||
return scopeDescriptor.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final InheritableThreadLocal<ScopeDescriptor> scopeDescriptor = new InheritableThreadLocal<ScopeDescriptor>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ScopeDescriptor initialValue() {
|
|
||||||
return new ScopeDescriptor("", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public Properties getConfigParameters() throws IOException {
|
public static Properties getConfigParameters() throws IOException {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
try {
|
try {
|
||||||
InputStream input = AccountingDashboardHarvesterPlugin.class.getClassLoader()
|
InputStream input = AccountingDashboardHarvesterPlugin.class.getClassLoader()
|
||||||
|
@ -210,9 +184,6 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
||||||
logger.debug("Harvesting from {} to {} (ReRun:{} - GetVREUsers:{} - DryRun:{})", DateUtils.format(start),
|
logger.debug("Harvesting from {} to {} (ReRun:{} - GetVREUsers:{} - DryRun:{})", DateUtils.format(start),
|
||||||
DateUtils.format(end), reRun, getVREUsers, dryRun);
|
DateUtils.format(end), reRun, getVREUsers, dryRun);
|
||||||
|
|
||||||
Properties properties = getConfigParameters();
|
|
||||||
getProperties().set(properties);
|
|
||||||
|
|
||||||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
||||||
SortedSet<String> contexts = contextAuthorization.getContexts();
|
SortedSet<String> contexts = contextAuthorization.getContexts();
|
||||||
String root = contexts.first();
|
String root = contexts.first();
|
||||||
|
@ -255,8 +226,6 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
||||||
actualScopeDescriptor = new ScopeDescriptor(scopeBean.name(), context);
|
actualScopeDescriptor = new ScopeDescriptor(scopeBean.name(), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
scopeDescriptor.set(actualScopeDescriptor);
|
|
||||||
|
|
||||||
if (scopeBean.is(Type.INFRASTRUCTURE)) {
|
if (scopeBean.is(Type.INFRASTRUCTURE)) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ public class JupyterAccessesHarvester extends BasicHarvester {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopeDescriptor scopeDescriptor = AccountingDashboardHarvesterPlugin.getScopeDescriptor();
|
ScopeDescriptor scopeDescriptor = AccountingDashboardHarvesterPlugin.getScopeDescriptor(context);
|
||||||
|
|
||||||
if (measure > 0) {
|
if (measure > 0) {
|
||||||
AccountingRecord ar = new AccountingRecord(scopeDescriptor, instant,
|
AccountingRecord ar = new AccountingRecord(scopeDescriptor, instant,
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class MethodInvocationHarvester extends BasicHarvester {
|
||||||
AggregatedServiceUsageRecord.class, temporalConstraint, filters, contexts, true);
|
AggregatedServiceUsageRecord.class, temporalConstraint, filters, contexts, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopeDescriptor scopeDescriptor = AccountingDashboardHarvesterPlugin.getScopeDescriptor();
|
ScopeDescriptor scopeDescriptor = AccountingDashboardHarvesterPlugin.getScopeDescriptor(context);
|
||||||
Dimension dimension = getDimension(HarvestedDataKey.METHOD_INVOCATIONS);
|
Dimension dimension = getDimension(HarvestedDataKey.METHOD_INVOCATIONS);
|
||||||
|
|
||||||
if(result != null) {
|
if(result != null) {
|
||||||
|
|
|
@ -115,7 +115,7 @@ public class RStudioAccessesHarvester extends BasicHarvester {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopeDescriptor scopeDescriptor = AccountingDashboardHarvesterPlugin.getScopeDescriptor();
|
ScopeDescriptor scopeDescriptor = AccountingDashboardHarvesterPlugin.getScopeDescriptor(context);
|
||||||
|
|
||||||
if (measure > 0) {
|
if (measure > 0) {
|
||||||
AccountingRecord ar = new AccountingRecord(scopeDescriptor, instant,
|
AccountingRecord ar = new AccountingRecord(scopeDescriptor, instant,
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class SocialInteractionsHarvester extends BasicHarvester {
|
||||||
|
|
||||||
getJson();
|
getJson();
|
||||||
|
|
||||||
ScopeDescriptor scopeDescriptor = AccountingDashboardHarvesterPlugin.getScopeDescriptor();
|
ScopeDescriptor scopeDescriptor = AccountingDashboardHarvesterPlugin.getScopeDescriptor(context);
|
||||||
|
|
||||||
AccountingRecord likesAR = new AccountingRecord(scopeDescriptor, instant, getDimension(HarvestedDataKey.SOCIAL_LIKES), (long) likes);
|
AccountingRecord likesAR = new AccountingRecord(scopeDescriptor, instant, getDimension(HarvestedDataKey.SOCIAL_LIKES), (long) likes);
|
||||||
logger.debug("{} : {}", likesAR.getDimension().getId(), likesAR.getMeasure());
|
logger.debug("{} : {}", likesAR.getDimension().getId(), likesAR.getMeasure());
|
||||||
|
|
|
@ -42,8 +42,6 @@ import com.google.analytics.data.v1beta.Metric;
|
||||||
import com.google.analytics.data.v1beta.Row;
|
import com.google.analytics.data.v1beta.Row;
|
||||||
import com.google.analytics.data.v1beta.RunReportRequest;
|
import com.google.analytics.data.v1beta.RunReportRequest;
|
||||||
import com.google.analytics.data.v1beta.RunReportResponse;
|
import com.google.analytics.data.v1beta.RunReportResponse;
|
||||||
import com.google.api.client.json.JsonFactory;
|
|
||||||
import com.google.api.client.json.gson.GsonFactory;
|
|
||||||
import com.google.api.gax.core.FixedCredentialsProvider;
|
import com.google.api.gax.core.FixedCredentialsProvider;
|
||||||
import com.google.auth.oauth2.ServiceAccountCredentials;
|
import com.google.auth.oauth2.ServiceAccountCredentials;
|
||||||
|
|
||||||
|
@ -52,7 +50,7 @@ public class VREAccessesHarvester extends BasicHarvester {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(VREAccessesHarvester.class);
|
private static Logger logger = LoggerFactory.getLogger(VREAccessesHarvester.class);
|
||||||
|
|
||||||
private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
|
// private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
|
||||||
|
|
||||||
private static final String SERVICE_ENDPOINT_CATEGORY = "OnlineService";
|
private static final String SERVICE_ENDPOINT_CATEGORY = "OnlineService";
|
||||||
private static final String SERVICE_ENDPOINT_NAME = "GA4AnalyticsDataService";
|
private static final String SERVICE_ENDPOINT_NAME = "GA4AnalyticsDataService";
|
||||||
|
@ -94,7 +92,7 @@ public class VREAccessesHarvester extends BasicHarvester {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopeDescriptor scopeDescriptor = AccountingDashboardHarvesterPlugin.getScopeDescriptor();
|
ScopeDescriptor scopeDescriptor = AccountingDashboardHarvesterPlugin.getScopeDescriptor(context);
|
||||||
|
|
||||||
AccountingRecord ar = new AccountingRecord(scopeDescriptor, instant, getDimension(HarvestedDataKey.ACCESSES), (long) measure);
|
AccountingRecord ar = new AccountingRecord(scopeDescriptor, instant, getDimension(HarvestedDataKey.ACCESSES), (long) measure);
|
||||||
logger.debug("{} : {}", ar.getDimension().getId(), ar.getMeasure());
|
logger.debug("{} : {}", ar.getDimension().getId(), ar.getMeasure());
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.gcube.dataharvest.harvester;
|
package org.gcube.dataharvest.harvester;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -10,7 +9,6 @@ import org.gcube.accounting.accounting.summary.access.model.update.AccountingRec
|
||||||
import org.gcube.dataharvest.AccountingDashboardHarvesterPlugin;
|
import org.gcube.dataharvest.AccountingDashboardHarvesterPlugin;
|
||||||
import org.gcube.dataharvest.datamodel.HarvestedDataKey;
|
import org.gcube.dataharvest.datamodel.HarvestedDataKey;
|
||||||
import org.gcube.social_networking.social_networking_client_library.UserClient;
|
import org.gcube.social_networking.social_networking_client_library.UserClient;
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -32,12 +30,13 @@ public class VREUsersHarvester extends BasicHarvester {
|
||||||
@Override
|
@Override
|
||||||
public List<AccountingRecord> getAccountingRecords() throws Exception {
|
public List<AccountingRecord> getAccountingRecords() throws Exception {
|
||||||
try {
|
try {
|
||||||
// String context = Utils.getCurrentContext();
|
String context = org.gcube.dataharvest.utils.Utils.getCurrentContext();
|
||||||
|
|
||||||
int measure = get();
|
int measure = get();
|
||||||
|
|
||||||
ArrayList<AccountingRecord> accountingRecords = new ArrayList<AccountingRecord>();
|
ArrayList<AccountingRecord> accountingRecords = new ArrayList<AccountingRecord>();
|
||||||
|
|
||||||
ScopeDescriptor scopeDescriptor = AccountingDashboardHarvesterPlugin.getScopeDescriptor();
|
ScopeDescriptor scopeDescriptor = AccountingDashboardHarvesterPlugin.getScopeDescriptor(context);
|
||||||
|
|
||||||
AccountingRecord ar = new AccountingRecord(scopeDescriptor, instant, getDimension(HarvestedDataKey.USERS), (long) measure);
|
AccountingRecord ar = new AccountingRecord(scopeDescriptor, instant, getDimension(HarvestedDataKey.USERS), (long) measure);
|
||||||
logger.debug("{} : {}", ar.getDimension().getId(), ar.getMeasure());
|
logger.debug("{} : {}", ar.getDimension().getId(), ar.getMeasure());
|
||||||
|
|
|
@ -77,7 +77,7 @@ public abstract class SoBigDataHarvester extends BasicHarvester {
|
||||||
* @throws ObjectNotFound
|
* @throws ObjectNotFound
|
||||||
*/
|
*/
|
||||||
protected void initMappingMaps() throws ObjectNotFound, Exception {
|
protected void initMappingMaps() throws ObjectNotFound, Exception {
|
||||||
Properties properties = AccountingDashboardHarvesterPlugin.getProperties().get();
|
Properties properties = AccountingDashboardHarvesterPlugin.getConfigParameters();
|
||||||
Set<String> keys = properties.stringPropertyNames();
|
Set<String> keys = properties.stringPropertyNames();
|
||||||
|
|
||||||
mapSystemTypeToDBEntry = new HashMap<String,String>();
|
mapSystemTypeToDBEntry = new HashMap<String,String>();
|
||||||
|
|
|
@ -109,7 +109,7 @@ public class TagMeMethodInvocationHarvester extends BasicHarvester {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopeDescriptor scopeDescriptor = AccountingDashboardHarvesterPlugin.getScopeDescriptor();
|
ScopeDescriptor scopeDescriptor = AccountingDashboardHarvesterPlugin.getScopeDescriptor(context);
|
||||||
Dimension dimension = getDimension(HarvestedDataKey.METHOD_INVOCATIONS);
|
Dimension dimension = getDimension(HarvestedDataKey.METHOD_INVOCATIONS);
|
||||||
|
|
||||||
AccountingRecord ar = new AccountingRecord(scopeDescriptor, instant, dimension, numberOfInvocation);
|
AccountingRecord ar = new AccountingRecord(scopeDescriptor, instant, dimension, numberOfInvocation);
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class ContextAuthorization {
|
||||||
|
|
||||||
public static final String CLIENT_ID = "accounting-dashboard-harvester-se-plugin";
|
public static final String CLIENT_ID = "accounting-dashboard-harvester-se-plugin";
|
||||||
|
|
||||||
protected String clientSecret = "442b9d9a-1973-46f2-99f2-9a10fae94452";
|
protected String clientSecret;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains Context full name as key and Token as Value
|
* Contains Context full name as key and Token as Value
|
||||||
|
@ -57,7 +57,7 @@ public class ContextAuthorization {
|
||||||
* Contains Properties used to generate tokens
|
* Contains Properties used to generate tokens
|
||||||
*/
|
*/
|
||||||
public ContextAuthorization() throws Exception {
|
public ContextAuthorization() throws Exception {
|
||||||
this.properties = AccountingDashboardHarvesterPlugin.getProperties().get();
|
this.properties = AccountingDashboardHarvesterPlugin.getConfigParameters();
|
||||||
this.contextToToken = new HashMap<>();
|
this.contextToToken = new HashMap<>();
|
||||||
this.tokenToContext = new HashMap<>();
|
this.tokenToContext = new HashMap<>();
|
||||||
retrieveContextsAndTokens();
|
retrieveContextsAndTokens();
|
||||||
|
@ -78,7 +78,7 @@ public class ContextAuthorization {
|
||||||
}
|
}
|
||||||
|
|
||||||
private TokenResponse getJWTAccessToken(String context) throws Exception {
|
private TokenResponse getJWTAccessToken(String context) throws Exception {
|
||||||
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(CLIENT_ID, "442b9d9a-1973-46f2-99f2-9a10fae94452", context, null);
|
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(CLIENT_ID, getClientSecret(context), context, null);
|
||||||
return tr;
|
return tr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,80 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.gcube.dataharvest.utils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.gcube.common.authorization.utils.manager.SecretManager;
|
|
||||||
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
|
||||||
import org.gcube.common.authorization.utils.secret.Secret;
|
|
||||||
import org.gcube.common.authorization.utils.secret.SecretUtility;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
|
||||||
*/
|
|
||||||
public class ContextTest {
|
|
||||||
|
|
||||||
protected static Properties properties;
|
|
||||||
protected static final String PROPERTIES_FILENAME = "token.properties";
|
|
||||||
|
|
||||||
public static final String ROOT;
|
|
||||||
public static final String VO;
|
|
||||||
public static final String VRE;
|
|
||||||
|
|
||||||
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 = "/pred4s/preprod/preVRE";
|
|
||||||
// DEFAULT_TEST_SCOPE_NAME = "/gcube/devsec/devVRE";
|
|
||||||
|
|
||||||
//ROOT = "/gcube";
|
|
||||||
ROOT = "/d4science.research-infrastructures.eu";
|
|
||||||
VO = ROOT + "/devsec";
|
|
||||||
VRE = VO + "/devVRE";
|
|
||||||
// VO = ROOT + "/devNext";
|
|
||||||
// VRE = VO + "/NextNext";
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void set(Secret secret) throws Exception {
|
|
||||||
SecretManagerProvider.instance.reset();
|
|
||||||
SecretManager secretManager = new SecretManager();
|
|
||||||
SecretManagerProvider.instance.set(secretManager);
|
|
||||||
secretManager.addSecret(secret);
|
|
||||||
secretManager.set();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setContext(String token) throws Exception {
|
|
||||||
Secret secret = getSecret(token);
|
|
||||||
set(secret);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setContextByName(String fullContextName) throws Exception {
|
|
||||||
Secret secret = getSecretByContextName(fullContextName);
|
|
||||||
set(secret);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Secret getSecret(String token) throws Exception {
|
|
||||||
Secret secret = SecretUtility.getSecretByTokenString(token);
|
|
||||||
return secret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Secret getSecretByContextName(String fullContextName) throws Exception {
|
|
||||||
String token = ContextTest.properties.getProperty(fullContextName);
|
|
||||||
return getSecret(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,129 +0,0 @@
|
||||||
package org.gcube.dataharvest.utils;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.SortedSet;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.gcube.accounting.accounting.summary.access.model.update.AccountingRecord;
|
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
|
||||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
|
||||||
import org.gcube.dataharvest.AccountingDashboardHarvesterPlugin;
|
|
||||||
import org.gcube.dataharvest.harvester.VREAccessesHarvester;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public class TestMassi extends ContextTest {
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(TestMassi.class);
|
|
||||||
|
|
||||||
public static final String ROOT = "/d4science.research-infrastructures.eu";
|
|
||||||
public TestMassi() {
|
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
try {
|
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
|
||||||
// AccountingDao dao = AccountingDao.get();
|
|
||||||
|
|
||||||
AccountingDashboardHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDashboardHarvesterPlugin();
|
|
||||||
Properties properties = accountingDataHarvesterPlugin.getConfigParameters();
|
|
||||||
AccountingDashboardHarvesterPlugin.getProperties().set(properties);
|
|
||||||
|
|
||||||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
|
||||||
SortedSet<String> contexts = contextAuthorization.getContexts();
|
|
||||||
|
|
||||||
|
|
||||||
AggregationType aggregationType = AggregationType.MONTHLY;
|
|
||||||
|
|
||||||
Calendar from = DateUtils.getStartCalendar(2023, Calendar.APRIL, 1);
|
|
||||||
|
|
||||||
Calendar runbeforeDate = DateUtils.getStartCalendar(2023, Calendar.JULY, 1);
|
|
||||||
|
|
||||||
while (from.before(runbeforeDate)) {
|
|
||||||
Date start = from.getTime();
|
|
||||||
Date end = DateUtils.getEndDateFromStartDate(aggregationType, start, 1);
|
|
||||||
|
|
||||||
logger.debug("Harvesting from {} to {}", DateUtils.format(start), DateUtils.format(end));
|
|
||||||
|
|
||||||
ArrayList<AccountingRecord> accountingRecords = new ArrayList<>();
|
|
||||||
|
|
||||||
VREAccessesHarvester vreAccessesHarvester = null;
|
|
||||||
|
|
||||||
for (String context : contexts) {
|
|
||||||
// Setting the token for the context
|
|
||||||
ContextTest.set(contextAuthorization.getSecretForContext(context));
|
|
||||||
logger.debug("Context set: {} ", context);
|
|
||||||
ScopeBean scopeBean = new ScopeBean(context);
|
|
||||||
|
|
||||||
if (vreAccessesHarvester == null) {
|
|
||||||
|
|
||||||
if (scopeBean.is(Type.INFRASTRUCTURE)) {
|
|
||||||
vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
|
||||||
} else {
|
|
||||||
// This code should be never used because the scopes
|
|
||||||
// are sorted by fullname
|
|
||||||
|
|
||||||
ScopeBean parent = scopeBean.enclosingScope();
|
|
||||||
while (!parent.is(Type.INFRASTRUCTURE)) {
|
|
||||||
parent = scopeBean.enclosingScope();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setting back token for the context
|
|
||||||
ContextTest.set(contextAuthorization.getSecretForContext(parent.toString()));
|
|
||||||
|
|
||||||
vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
|
||||||
|
|
||||||
// Setting back token for the context
|
|
||||||
ContextTest.set(contextAuthorization.getSecretForContext(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (context.startsWith(AccountingDashboardHarvesterPlugin.SO_BIG_DATA_VO)
|
|
||||||
&& start.before(DateUtils.getStartCalendar(2018, Calendar.APRIL, 1).getTime())) {
|
|
||||||
logger.info("Not Harvesting VREs Accesses for {} from {} to {}", context,
|
|
||||||
DateUtils.format(start), DateUtils.format(end));
|
|
||||||
} else {
|
|
||||||
// Collecting Google Analytics Data for VREs
|
|
||||||
// Accesses
|
|
||||||
List<AccountingRecord> harvested = vreAccessesHarvester.getAccountingRecords();
|
|
||||||
accountingRecords.addAll(harvested);
|
|
||||||
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("Error harvesting Social Interactions for {}", context, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.debug("Harvest Measures from {} to {} are {}", DateUtils.format(start), DateUtils.format(end),
|
|
||||||
accountingRecords);
|
|
||||||
ContextTest.setContextByName(ROOT);
|
|
||||||
|
|
||||||
// dao.insertRecords(accountingRecords.toArray(new
|
|
||||||
// AccountingRecord[1]));
|
|
||||||
|
|
||||||
Thread.sleep(TimeUnit.SECONDS.toMillis(10));
|
|
||||||
|
|
||||||
from.add(aggregationType.getCalendarField(), 1);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("End.");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +1,5 @@
|
||||||
package org.gcube.dataharvest.utils;
|
package org.gcube.dataharvest.utils;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||||
import org.gcube.common.authorization.utils.manager.SecretManager;
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
||||||
|
|
|
@ -14,7 +14,6 @@ import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor;
|
||||||
import org.gcube.accounting.accounting.summary.access.model.internal.Dimension;
|
import org.gcube.accounting.accounting.summary.access.model.internal.Dimension;
|
||||||
import org.gcube.accounting.accounting.summary.access.model.update.AccountingRecord;
|
import org.gcube.accounting.accounting.summary.access.model.update.AccountingRecord;
|
||||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
|
||||||
import org.gcube.dataharvest.harvester.JupyterAccessesHarvester;
|
import org.gcube.dataharvest.harvester.JupyterAccessesHarvester;
|
||||||
import org.gcube.dataharvest.utils.AggregationType;
|
import org.gcube.dataharvest.utils.AggregationType;
|
||||||
import org.gcube.dataharvest.utils.ContextAuthorization;
|
import org.gcube.dataharvest.utils.ContextAuthorization;
|
||||||
|
@ -30,39 +29,16 @@ import org.slf4j.LoggerFactory;
|
||||||
* @author Giancarlo Panichi (ISTI CNR)
|
* @author Giancarlo Panichi (ISTI CNR)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class AccountingDataHarvesterJupyterTest extends ContextTest {
|
public class AccountingDataHarvesterJupyterTest extends AccountingDataHarvesterPluginTest {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(AccountingDataHarvesterJupyterTest.class);
|
private static Logger logger = LoggerFactory.getLogger(AccountingDataHarvesterJupyterTest.class);
|
||||||
public static final String ROOT = "/d4science.research-infrastructures.eu";
|
|
||||||
// private static final String SCOPE = "/d4science.research-infrastructures.eu/D4OS/Blue-CloudLab";
|
|
||||||
|
|
||||||
protected AccountingDao getAccountingDao() throws ObjectNotFound, Exception {
|
|
||||||
AccountingDao dao = AccountingDao.get();
|
|
||||||
|
|
||||||
Set<ScopeDescriptor> scopeDescriptorSet = dao.getContexts();
|
|
||||||
Map<String, ScopeDescriptor> scopeDescriptorMap = new HashMap<>();
|
|
||||||
for (ScopeDescriptor scopeDescriptor : scopeDescriptorSet) {
|
|
||||||
scopeDescriptorMap.put(scopeDescriptor.getId(), scopeDescriptor);
|
|
||||||
}
|
|
||||||
AccountingDashboardHarvesterPlugin.scopeDescriptors.set(scopeDescriptorMap);
|
|
||||||
|
|
||||||
Set<Dimension> dimensionSet = dao.getDimensions();
|
|
||||||
Map<String, Dimension> dimensionMap = new HashMap<>();
|
|
||||||
for (Dimension dimension : dimensionSet) {
|
|
||||||
dimensionMap.put(dimension.getId(), dimension);
|
|
||||||
}
|
|
||||||
|
|
||||||
AccountingDashboardHarvesterPlugin.dimensions.set(dimensionMap);
|
|
||||||
|
|
||||||
return dao;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void testJupyterAccessesHarvester() throws Exception {
|
public void testJupyterAccessesHarvester() throws Exception {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
AccountingDao dao = getAccountingDao();
|
AccountingDao dao = getAccountingDao();
|
||||||
|
|
||||||
List<Date> starts = new ArrayList<>();
|
List<Date> starts = new ArrayList<>();
|
||||||
|
@ -74,8 +50,6 @@ public class AccountingDataHarvesterJupyterTest extends ContextTest {
|
||||||
|
|
||||||
AggregationType measureType = AggregationType.MONTHLY;
|
AggregationType measureType = AggregationType.MONTHLY;
|
||||||
|
|
||||||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
|
||||||
|
|
||||||
SortedSet<String> contexts = contextAuthorization.getContexts();
|
SortedSet<String> contexts = contextAuthorization.getContexts();
|
||||||
/*
|
/*
|
||||||
SortedSet<String> contexts = new TreeSet<>();
|
SortedSet<String> contexts = new TreeSet<>();
|
||||||
|
@ -86,31 +60,14 @@ public class AccountingDataHarvesterJupyterTest extends ContextTest {
|
||||||
|
|
||||||
List<AccountingRecord> accountingRecords = new ArrayList<>();
|
List<AccountingRecord> accountingRecords = new ArrayList<>();
|
||||||
|
|
||||||
Set<ScopeDescriptor> scopeDescriptorSet = dao.getContexts();
|
|
||||||
Map<String, ScopeDescriptor> scopeDescriptorMap = new HashMap<>();
|
|
||||||
for (ScopeDescriptor scopeDescriptor : scopeDescriptorSet) {
|
|
||||||
scopeDescriptorMap.put(scopeDescriptor.getId(), scopeDescriptor);
|
|
||||||
}
|
|
||||||
AccountingDashboardHarvesterPlugin.scopeDescriptors.set(scopeDescriptorMap);
|
|
||||||
|
|
||||||
|
|
||||||
for (Date start : starts) {
|
for (Date start : starts) {
|
||||||
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
JupyterAccessesHarvester jupyterAccessesHarvester = new JupyterAccessesHarvester(start, end);
|
JupyterAccessesHarvester jupyterAccessesHarvester = new JupyterAccessesHarvester(start, end);
|
||||||
|
|
||||||
for(String context : contexts) {
|
for(String context : contexts) {
|
||||||
ContextTest.set(contextAuthorization.getSecretForContext(context));
|
ContextTest.set(context);
|
||||||
|
|
||||||
ScopeBean scopeBean = new ScopeBean(context);
|
|
||||||
|
|
||||||
ScopeDescriptor actualScopeDescriptor = scopeDescriptorMap.get(context);
|
|
||||||
if (actualScopeDescriptor == null) {
|
|
||||||
actualScopeDescriptor = new ScopeDescriptor(scopeBean.name(), context);
|
|
||||||
}
|
|
||||||
|
|
||||||
AccountingDashboardHarvesterPlugin.scopeDescriptor.set(actualScopeDescriptor);
|
|
||||||
|
|
||||||
List<AccountingRecord> harvested = jupyterAccessesHarvester.getAccountingRecords();
|
List<AccountingRecord> harvested = jupyterAccessesHarvester.getAccountingRecords();
|
||||||
accountingRecords.addAll(harvested);
|
accountingRecords.addAll(harvested);
|
||||||
|
@ -122,8 +79,9 @@ public class AccountingDataHarvesterJupyterTest extends ContextTest {
|
||||||
|
|
||||||
logger.debug("Going to insert {}", accountingRecords);
|
logger.debug("Going to insert {}", accountingRecords);
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
|
||||||
|
// dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.error(e.getLocalizedMessage(), e);
|
logger.error(e.getLocalizedMessage(), e);
|
||||||
|
|
|
@ -5,7 +5,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -34,7 +33,6 @@ import org.gcube.dataharvest.utils.AggregationType;
|
||||||
import org.gcube.dataharvest.utils.ContextAuthorization;
|
import org.gcube.dataharvest.utils.ContextAuthorization;
|
||||||
import org.gcube.dataharvest.utils.ContextTest;
|
import org.gcube.dataharvest.utils.ContextTest;
|
||||||
import org.gcube.dataharvest.utils.DateUtils;
|
import org.gcube.dataharvest.utils.DateUtils;
|
||||||
import org.gcube.resourcemanagement.support.server.managers.context.ContextManager;
|
|
||||||
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
||||||
import org.gcube.vremanagement.executor.api.types.Scheduling;
|
import org.gcube.vremanagement.executor.api.types.Scheduling;
|
||||||
import org.gcube.vremanagement.executor.client.SmartExecutorClient;
|
import org.gcube.vremanagement.executor.client.SmartExecutorClient;
|
||||||
|
@ -56,26 +54,34 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
public static final String TAGME_VRE = "/d4science.research-infrastructures.eu/SoBigData/TagMe";
|
public static final String TAGME_VRE = "/d4science.research-infrastructures.eu/SoBigData/TagMe";
|
||||||
public static final String STOCK_ASSESMENT_VRE = "/d4science.research-infrastructures.eu/gCubeApps/StockAssessment";
|
public static final String STOCK_ASSESMENT_VRE = "/d4science.research-infrastructures.eu/gCubeApps/StockAssessment";
|
||||||
|
|
||||||
public static SortedSet<String> getContexts() throws Exception {
|
public static final String BLUE_CLOUD_LAB = "/d4science.research-infrastructures.eu/D4OS/Blue-CloudLab";
|
||||||
SortedSet<String> contexts = new TreeSet<>();
|
|
||||||
LinkedHashMap<String, ScopeBean> map = ContextManager.readContexts();
|
protected AccountingDao getAccountingDao() throws ObjectNotFound, Exception {
|
||||||
for (String scope : map.keySet()) {
|
AccountingDao dao = AccountingDao.get();
|
||||||
try {
|
|
||||||
String context = map.get(scope).toString();
|
Set<ScopeDescriptor> scopeDescriptorSet = dao.getContexts();
|
||||||
contexts.add(context);
|
Map<String, ScopeDescriptor> scopeDescriptorMap = new HashMap<>();
|
||||||
} catch (Exception e) {
|
for (ScopeDescriptor scopeDescriptor : scopeDescriptorSet) {
|
||||||
throw e;
|
scopeDescriptorMap.put(scopeDescriptor.getId(), scopeDescriptor);
|
||||||
}
|
}
|
||||||
|
AccountingDashboardHarvesterPlugin.scopeDescriptors.set(scopeDescriptorMap);
|
||||||
|
|
||||||
|
Set<Dimension> dimensionSet = dao.getDimensions();
|
||||||
|
Map<String, Dimension> dimensionMap = new HashMap<>();
|
||||||
|
for (Dimension dimension : dimensionSet) {
|
||||||
|
dimensionMap.put(dimension.getId(), dimension);
|
||||||
}
|
}
|
||||||
return contexts;
|
|
||||||
|
AccountingDashboardHarvesterPlugin.dimensions.set(dimensionMap);
|
||||||
|
|
||||||
|
return dao;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void getDimensions() {
|
public void getDimensions() {
|
||||||
try {
|
try {
|
||||||
|
ContextTest.set(ROOT);
|
||||||
ContextTest.setContextByName(ROOT);
|
|
||||||
|
|
||||||
AccountingDao dao = AccountingDao.get();
|
AccountingDao dao = AccountingDao.get();
|
||||||
|
|
||||||
|
@ -92,11 +98,11 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
//@Test
|
// @Test
|
||||||
public void launch() {
|
public void launch() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
|
|
||||||
AccountingDashboardHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDashboardHarvesterPlugin();
|
AccountingDashboardHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDashboardHarvesterPlugin();
|
||||||
|
|
||||||
|
@ -125,11 +131,11 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
@Test
|
// @Test
|
||||||
public void launchPluginOnSmartExecutor() {
|
public void launchPluginOnSmartExecutor() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
|
|
||||||
String pluginName = new AccountingDashboardHarvesterPlugin().getName();
|
String pluginName = new AccountingDashboardHarvesterPlugin().getName();
|
||||||
|
|
||||||
|
@ -182,7 +188,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
public void launchOldData() {
|
public void launchOldData() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
|
|
||||||
AccountingDashboardHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDashboardHarvesterPlugin();
|
AccountingDashboardHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDashboardHarvesterPlugin();
|
||||||
|
|
||||||
|
@ -219,14 +225,10 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
public void launchOldDataVREAccessesHarvester() {
|
public void launchOldDataVREAccessesHarvester() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
// AccountingDao dao = AccountingDao.get();
|
|
||||||
|
|
||||||
AccountingDashboardHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDashboardHarvesterPlugin();
|
AccountingDao dao = getAccountingDao();
|
||||||
Properties properties = accountingDataHarvesterPlugin.getConfigParameters();
|
|
||||||
AccountingDashboardHarvesterPlugin.getProperties().set(properties);
|
|
||||||
|
|
||||||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
|
||||||
SortedSet<String> contexts = contextAuthorization.getContexts();
|
SortedSet<String> contexts = contextAuthorization.getContexts();
|
||||||
|
|
||||||
AggregationType aggregationType = AggregationType.MONTHLY;
|
AggregationType aggregationType = AggregationType.MONTHLY;
|
||||||
|
@ -246,8 +248,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
VREAccessesHarvester vreAccessesHarvester = null;
|
VREAccessesHarvester vreAccessesHarvester = null;
|
||||||
|
|
||||||
for (String context : contexts) {
|
for (String context : contexts) {
|
||||||
// Setting the token for the context
|
ContextTest.set(context);
|
||||||
ContextTest.set(contextAuthorization.getSecretForContext(context));
|
|
||||||
|
|
||||||
ScopeBean scopeBean = new ScopeBean(context);
|
ScopeBean scopeBean = new ScopeBean(context);
|
||||||
|
|
||||||
|
@ -265,12 +266,12 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setting back token for the context
|
// Setting back token for the context
|
||||||
ContextTest.set(contextAuthorization.getSecretForContext(parent.toString()));
|
ContextTest.set(parent.toString());
|
||||||
|
|
||||||
vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
||||||
|
|
||||||
// Setting back token for the context
|
// Setting back token for the context
|
||||||
ContextTest.set(contextAuthorization.getSecretForContext(context));
|
ContextTest.set(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -294,7 +295,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
|
|
||||||
logger.debug("Harvest Measures from {} to {} are {}", DateUtils.format(start), DateUtils.format(end),
|
logger.debug("Harvest Measures from {} to {} are {}", DateUtils.format(start), DateUtils.format(end),
|
||||||
accountingRecords);
|
accountingRecords);
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
|
|
||||||
// dao.insertRecords(accountingRecords.toArray(new
|
// dao.insertRecords(accountingRecords.toArray(new
|
||||||
// AccountingRecord[1]));
|
// AccountingRecord[1]));
|
||||||
|
@ -305,7 +306,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
|
@ -315,60 +316,13 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
|
||||||
// @Test
|
|
||||||
public void testScopeBean() throws Exception {
|
|
||||||
ContextTest.setContextByName(ROOT);
|
|
||||||
SortedSet<String> contexts = getContexts();
|
|
||||||
|
|
||||||
AggregationType aggregationType = AggregationType.MONTHLY;
|
|
||||||
|
|
||||||
Date start = DateUtils.getStartCalendar(2018, Calendar.MARCH, 1).getTime();
|
|
||||||
// start = DateUtils.getPreviousPeriod(measureType).getTime();
|
|
||||||
Date end = DateUtils.getEndDateFromStartDate(aggregationType, start, 1);
|
|
||||||
|
|
||||||
logger.info("\n\n\n");
|
|
||||||
|
|
||||||
for (String context : contexts) {
|
|
||||||
ScopeBean scopeBean = new ScopeBean(context);
|
|
||||||
// logger.debug("FullName {} - Name {}", scopeBean.toString(),
|
|
||||||
// scopeBean.name());
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
if (scopeBean.is(Type.VRE)
|
|
||||||
&& start.equals(DateUtils.getPreviousPeriod(aggregationType, false).getTime())) {
|
|
||||||
logger.info("Harvesting (VRE Users) for {} from {} to {}", context, DateUtils.format(start),
|
|
||||||
DateUtils.format(end));
|
|
||||||
} else {
|
|
||||||
logger.info("--- Not Harvesting (VRE Users) for {} from {} to {}", context, DateUtils.format(start),
|
|
||||||
DateUtils.format(end));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((context.startsWith(AccountingDashboardHarvesterPlugin.SO_BIG_DATA_VO)
|
|
||||||
|| context.startsWith(AccountingDashboardHarvesterPlugin.SO_BIG_DATA_EU_VRE)
|
|
||||||
|| context.startsWith(AccountingDashboardHarvesterPlugin.SO_BIG_DATA_IT_VRE))
|
|
||||||
&& start.before(DateUtils.getStartCalendar(2018, Calendar.APRIL, 1).getTime())) {
|
|
||||||
logger.info("--- Not Harvesting (SoBigData Check) for {} from {} to {}", context,
|
|
||||||
DateUtils.format(start), DateUtils.format(end));
|
|
||||||
} else {
|
|
||||||
logger.info("Harvesting (SoBigData Check) for {} from {} to {}", context, DateUtils.format(start),
|
|
||||||
DateUtils.format(end));
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("Error harvesting Social Interactions for {}", context, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
// @Test
|
// @Test
|
||||||
public void testVREAccessesHarvester() throws Exception {
|
public void testVREAccessesHarvester() throws Exception {
|
||||||
try {
|
try {
|
||||||
// AccountingDao dao = getAccountingDao();
|
ContextTest.set(ROOT);
|
||||||
|
|
||||||
|
AccountingDao dao = getAccountingDao();
|
||||||
|
|
||||||
List<Date> starts = new ArrayList<>();
|
List<Date> starts = new ArrayList<>();
|
||||||
starts.add(DateUtils.getStartCalendar(2018, Calendar.SEPTEMBER, 1).getTime());
|
starts.add(DateUtils.getStartCalendar(2018, Calendar.SEPTEMBER, 1).getTime());
|
||||||
|
@ -389,12 +343,12 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
for (Date start : starts) {
|
for (Date start : starts) {
|
||||||
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
VREAccessesHarvester vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
VREAccessesHarvester vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
||||||
|
|
||||||
for (String contextFullname : contextFullNames) {
|
for (String contextFullname : contextFullNames) {
|
||||||
|
|
||||||
setContextByNameAndScopeDescriptor(contextFullname);
|
ContextTest.set(contextFullname);
|
||||||
|
|
||||||
List<AccountingRecord> harvested = vreAccessesHarvester.getAccountingRecords();
|
List<AccountingRecord> harvested = vreAccessesHarvester.getAccountingRecords();
|
||||||
accountingRecords.addAll(harvested);
|
accountingRecords.addAll(harvested);
|
||||||
|
@ -406,7 +360,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
|
|
||||||
logger.debug("{}", accountingRecords);
|
logger.debug("{}", accountingRecords);
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
// dao.insertRecords(accountingRecords.toArray(new
|
// dao.insertRecords(accountingRecords.toArray(new
|
||||||
// AccountingRecord[1]));
|
// AccountingRecord[1]));
|
||||||
|
|
||||||
|
@ -421,7 +375,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
public void testVREAccessesHarvesterAll() {
|
public void testVREAccessesHarvesterAll() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
|
|
||||||
AggregationType measureType = AggregationType.MONTHLY;
|
AggregationType measureType = AggregationType.MONTHLY;
|
||||||
|
|
||||||
|
@ -436,7 +390,6 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
AccountingDashboardHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDashboardHarvesterPlugin();
|
AccountingDashboardHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDashboardHarvesterPlugin();
|
||||||
accountingDataHarvesterPlugin.getConfigParameters();
|
accountingDataHarvesterPlugin.getConfigParameters();
|
||||||
|
|
||||||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
|
||||||
SortedSet<String> contexts = contextAuthorization.getContexts();
|
SortedSet<String> contexts = contextAuthorization.getContexts();
|
||||||
|
|
||||||
VREAccessesHarvester vreAccessesHarvester = null;
|
VREAccessesHarvester vreAccessesHarvester = null;
|
||||||
|
@ -445,7 +398,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
|
|
||||||
for (String context : contexts) {
|
for (String context : contexts) {
|
||||||
// Setting the token for the context
|
// Setting the token for the context
|
||||||
ContextTest.set(contextAuthorization.getSecretForContext(context));
|
ContextTest.set(context);
|
||||||
|
|
||||||
ScopeBean scopeBean = new ScopeBean(context);
|
ScopeBean scopeBean = new ScopeBean(context);
|
||||||
|
|
||||||
|
@ -462,13 +415,12 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
parent = scopeBean.enclosingScope();
|
parent = scopeBean.enclosingScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setting back token for the context
|
ContextTest.set(parent.toString());
|
||||||
ContextTest.set(contextAuthorization.getSecretForContext(parent.toString()));
|
|
||||||
|
|
||||||
vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
||||||
|
|
||||||
// Setting back token for the context
|
// Setting back token for the context
|
||||||
ContextTest.set(contextAuthorization.getSecretForContext(context));
|
ContextTest.set(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -500,14 +452,9 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
public void testSocialInteraction() {
|
public void testSocialInteraction() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
// AccountingDao dao = AccountingDao.get();
|
|
||||||
|
|
||||||
AccountingDashboardHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDashboardHarvesterPlugin();
|
AccountingDao dao = getAccountingDao();
|
||||||
Properties properties = accountingDataHarvesterPlugin.getConfigParameters();
|
|
||||||
AccountingDashboardHarvesterPlugin.getProperties().set(properties);
|
|
||||||
|
|
||||||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
|
||||||
|
|
||||||
SortedSet<String> contexts = new TreeSet<>();
|
SortedSet<String> contexts = new TreeSet<>();
|
||||||
contexts.add("/d4science.research-infrastructures.eu/D4Research");
|
contexts.add("/d4science.research-infrastructures.eu/D4Research");
|
||||||
|
@ -529,7 +476,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
|
|
||||||
for (String context : contexts) {
|
for (String context : contexts) {
|
||||||
// Setting the token for the context
|
// Setting the token for the context
|
||||||
ContextTest.set(contextAuthorization.getSecretForContext(context));
|
ContextTest.set(context);
|
||||||
try {
|
try {
|
||||||
// Collecting info on social (posts, replies and likes)
|
// Collecting info on social (posts, replies and likes)
|
||||||
logger.info("Going to harvest Social Interactions for {}", context);
|
logger.info("Going to harvest Social Interactions for {}", context);
|
||||||
|
@ -543,7 +490,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
|
|
||||||
logger.debug("Harvest Measures from {} to {} are {}", DateUtils.format(start), DateUtils.format(end),
|
logger.debug("Harvest Measures from {} to {} are {}", DateUtils.format(start), DateUtils.format(end),
|
||||||
accountingRecords);
|
accountingRecords);
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
// dao.insertRecords(accountingRecords.toArray(new
|
// dao.insertRecords(accountingRecords.toArray(new
|
||||||
// AccountingRecord[1]));
|
// AccountingRecord[1]));
|
||||||
|
|
||||||
|
@ -559,10 +506,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
// @Test
|
// @Test
|
||||||
public void testMethodInvocation() {
|
public void testMethodInvocation() {
|
||||||
try {
|
try {
|
||||||
|
ContextTest.set(STOCK_ASSESMENT_VRE);
|
||||||
ContextTest.setContextByName(ROOT);
|
|
||||||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
|
||||||
ContextTest.set(contextAuthorization.getSecretForContext(STOCK_ASSESMENT_VRE));
|
|
||||||
|
|
||||||
AggregationType measureType = AggregationType.MONTHLY;
|
AggregationType measureType = AggregationType.MONTHLY;
|
||||||
|
|
||||||
|
@ -584,7 +528,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
public void testMethodInvocationOldData() {
|
public void testMethodInvocationOldData() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
AccountingDao dao = getAccountingDao();
|
AccountingDao dao = getAccountingDao();
|
||||||
|
|
||||||
List<Date> starts = new ArrayList<>();
|
List<Date> starts = new ArrayList<>();
|
||||||
|
@ -612,16 +556,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
|
|
||||||
for (String context : contexts) {
|
for (String context : contexts) {
|
||||||
// Setting the token for the context
|
// Setting the token for the context
|
||||||
ContextTest.set(contextAuthorization.getSecretForContext(context));
|
ContextTest.set(context);
|
||||||
|
|
||||||
ScopeBean scopeBean = new ScopeBean(context);
|
|
||||||
|
|
||||||
ScopeDescriptor actualScopeDescriptor = scopeDescriptorMap.get(context);
|
|
||||||
if (actualScopeDescriptor == null) {
|
|
||||||
actualScopeDescriptor = new ScopeDescriptor(scopeBean.name(), context);
|
|
||||||
}
|
|
||||||
|
|
||||||
AccountingDashboardHarvesterPlugin.scopeDescriptor.set(actualScopeDescriptor);
|
|
||||||
|
|
||||||
List<AccountingRecord> harvested = methodInvocationHarvester.getAccountingRecords();
|
List<AccountingRecord> harvested = methodInvocationHarvester.getAccountingRecords();
|
||||||
accountingRecords.addAll(harvested);
|
accountingRecords.addAll(harvested);
|
||||||
|
@ -633,7 +568,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
|
|
||||||
logger.debug("Going to insert {}", accountingRecords);
|
logger.debug("Going to insert {}", accountingRecords);
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
// dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
// dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -641,47 +576,19 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AccountingDao getAccountingDao() throws ObjectNotFound, Exception {
|
|
||||||
AccountingDao dao = AccountingDao.get();
|
|
||||||
|
|
||||||
Set<ScopeDescriptor> scopeDescriptorSet = dao.getContexts();
|
|
||||||
Map<String, ScopeDescriptor> scopeDescriptorMap = new HashMap<>();
|
|
||||||
for (ScopeDescriptor scopeDescriptor : scopeDescriptorSet) {
|
|
||||||
scopeDescriptorMap.put(scopeDescriptor.getId(), scopeDescriptor);
|
|
||||||
}
|
|
||||||
AccountingDashboardHarvesterPlugin.scopeDescriptors.set(scopeDescriptorMap);
|
|
||||||
|
|
||||||
Set<Dimension> dimensionSet = dao.getDimensions();
|
|
||||||
Map<String, Dimension> dimensionMap = new HashMap<>();
|
|
||||||
for (Dimension dimension : dimensionSet) {
|
|
||||||
dimensionMap.put(dimension.getId(), dimension);
|
|
||||||
}
|
|
||||||
|
|
||||||
AccountingDashboardHarvesterPlugin.dimensions.set(dimensionMap);
|
|
||||||
|
|
||||||
return dao;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setContextByNameAndScopeDescriptor(String contextFullName) throws ObjectNotFound, Exception {
|
|
||||||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
|
||||||
ContextTest.set(contextAuthorization.getSecretForContext(contextFullName));
|
|
||||||
|
|
||||||
ScopeBean scopeBean = new ScopeBean(contextFullName);
|
|
||||||
ScopeDescriptor actualScopeDescriptor = AccountingDashboardHarvesterPlugin.scopeDescriptors.get()
|
|
||||||
.get(contextFullName);
|
|
||||||
if (actualScopeDescriptor == null) {
|
|
||||||
actualScopeDescriptor = new ScopeDescriptor(scopeBean.name(), contextFullName);
|
|
||||||
}
|
|
||||||
|
|
||||||
AccountingDashboardHarvesterPlugin.scopeDescriptor.set(actualScopeDescriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
// @Test
|
// @Test
|
||||||
public void testTagMeMethodInvocation() throws Exception {
|
public void testTagMeMethodInvocation() throws Exception {
|
||||||
try {
|
try {
|
||||||
// AccountingDao dao = getAccountingDao();
|
|
||||||
setContextByNameAndScopeDescriptor(TAGME_VRE);
|
ContextTest.set(ROOT);
|
||||||
|
AccountingDao dao = getAccountingDao();
|
||||||
|
|
||||||
|
ContextTest.set(TAGME_VRE);
|
||||||
|
|
||||||
List<AccountingRecord> accountingRecords = new ArrayList<>();
|
List<AccountingRecord> accountingRecords = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -705,7 +612,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
logger.debug("{}", accountingRecords);
|
logger.debug("{}", accountingRecords);
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
// dao.insertRecords(accountingRecords.toArray(new
|
// dao.insertRecords(accountingRecords.toArray(new
|
||||||
// AccountingRecord[1]));
|
// AccountingRecord[1]));
|
||||||
|
|
||||||
|
@ -719,16 +626,10 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
// @Test
|
// @Test
|
||||||
public void testGetVREUsersForSpecificVRE() {
|
public void testGetVREUsersForSpecificVRE() {
|
||||||
try {
|
try {
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
|
AccountingDao dao = getAccountingDao();
|
||||||
|
|
||||||
AccountingDashboardHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDashboardHarvesterPlugin();
|
ContextTest.set("/d4science.research-infrastructures.eu/SoBigData/SportsDataScience");
|
||||||
Properties properties = accountingDataHarvesterPlugin.getConfigParameters();
|
|
||||||
AccountingDashboardHarvesterPlugin.getProperties().set(properties);
|
|
||||||
|
|
||||||
// AccountingDao dao = AccountingDao.get();
|
|
||||||
|
|
||||||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
|
||||||
ContextTest.set(contextAuthorization.getSecretForContext("/d4science.research-infrastructures.eu/SoBigData/SportsDataScience"));
|
|
||||||
|
|
||||||
AggregationType measureType = AggregationType.MONTHLY;
|
AggregationType measureType = AggregationType.MONTHLY;
|
||||||
|
|
||||||
|
@ -740,7 +641,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
|
|
||||||
logger.info("Harvested Data from {} to {} : {}", DateUtils.format(start), DateUtils.format(end), harvested);
|
logger.info("Harvested Data from {} to {} : {}", DateUtils.format(start), DateUtils.format(end), harvested);
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
// dao.insertRecords(accountingRecords.toArray(new
|
// dao.insertRecords(accountingRecords.toArray(new
|
||||||
// AccountingRecord[1]));
|
// AccountingRecord[1]));
|
||||||
|
|
||||||
|
@ -754,7 +655,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
// @Test
|
// @Test
|
||||||
public void testFilteringGenericResource() {
|
public void testFilteringGenericResource() {
|
||||||
try {
|
try {
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
// Utils.setContext(RESOURCE_CATALOGUE);
|
// Utils.setContext(RESOURCE_CATALOGUE);
|
||||||
|
|
||||||
AggregationType measureType = AggregationType.MONTHLY;
|
AggregationType measureType = AggregationType.MONTHLY;
|
||||||
|
@ -762,10 +663,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
Date start = DateUtils.getPreviousPeriod(measureType, false).getTime();
|
Date start = DateUtils.getPreviousPeriod(measureType, false).getTime();
|
||||||
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
||||||
|
|
||||||
SortedSet<String> contexts = getContexts();
|
SortedSet<String> contexts = contextAuthorization.getContexts();
|
||||||
|
|
||||||
AccountingDashboardHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDashboardHarvesterPlugin();
|
|
||||||
accountingDataHarvesterPlugin.getConfigParameters();
|
|
||||||
|
|
||||||
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end,
|
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end,
|
||||||
contexts);
|
contexts);
|
||||||
|
@ -783,8 +681,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
public void testResourceCatalogueHarvester() {
|
public void testResourceCatalogueHarvester() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// Utils.setContext(RESOURCE_CATALOGUE);
|
ContextTest.set(ROOT);
|
||||||
ContextTest.setContextByName(ROOT);
|
|
||||||
|
|
||||||
AggregationType measureType = AggregationType.MONTHLY;
|
AggregationType measureType = AggregationType.MONTHLY;
|
||||||
|
|
||||||
|
@ -796,10 +693,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
Date start = DateUtils.getPreviousPeriod(measureType, false).getTime();
|
Date start = DateUtils.getPreviousPeriod(measureType, false).getTime();
|
||||||
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
||||||
|
|
||||||
AccountingDashboardHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDashboardHarvesterPlugin();
|
SortedSet<String> contexts = contextAuthorization.getContexts();
|
||||||
accountingDataHarvesterPlugin.getConfigParameters();
|
|
||||||
|
|
||||||
SortedSet<String> contexts = getContexts();
|
|
||||||
|
|
||||||
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end,
|
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end,
|
||||||
contexts);
|
contexts);
|
||||||
|
@ -817,8 +711,8 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
public void testCoreServicesHarvester() {
|
public void testCoreServicesHarvester() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String context = ROOT; // "/gcube";
|
String context = ROOT;
|
||||||
ContextTest.setContextByName(context);
|
ContextTest.set(context);
|
||||||
|
|
||||||
AccountingDao dao = getAccountingDao();
|
AccountingDao dao = getAccountingDao();
|
||||||
|
|
||||||
|
@ -833,7 +727,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
while (end.before(finalEnd)) {
|
while (end.before(finalEnd)) {
|
||||||
CoreServicesAccessesHarvester coreServicesHarvester = new CoreServicesAccessesHarvester(start, end);
|
CoreServicesAccessesHarvester coreServicesHarvester = new CoreServicesAccessesHarvester(start, end);
|
||||||
List<AccountingRecord> accountingRecords = coreServicesHarvester.getAccountingRecords();
|
List<AccountingRecord> accountingRecords = coreServicesHarvester.getAccountingRecords();
|
||||||
dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
// dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
||||||
|
|
||||||
logger.debug("{} -> {} Data Inserted", DateUtils.format(start), DateUtils.format(end));
|
logger.debug("{} -> {} Data Inserted", DateUtils.format(start), DateUtils.format(end));
|
||||||
logger.debug("---------------------------------------------------------------------------------------");
|
logger.debug("---------------------------------------------------------------------------------------");
|
||||||
|
@ -853,8 +747,8 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
public void testCatalogueHarvester() {
|
public void testCatalogueHarvester() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String context = ROOT; // "/gcube";
|
String context = ROOT;
|
||||||
ContextTest.setContextByName(context);
|
ContextTest.set(context);
|
||||||
|
|
||||||
AccountingDao dao = getAccountingDao();
|
AccountingDao dao = getAccountingDao();
|
||||||
|
|
||||||
|
@ -876,7 +770,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
}
|
}
|
||||||
logger.debug("{}", accountingRecords);
|
logger.debug("{}", accountingRecords);
|
||||||
|
|
||||||
dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
// dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
|
@ -890,43 +784,19 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
public void addMissingVREAccesses() {
|
public void addMissingVREAccesses() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
|
|
||||||
AccountingDashboardHarvesterPlugin adhp = new AccountingDashboardHarvesterPlugin();
|
AccountingDao dao = getAccountingDao();
|
||||||
Properties properties = adhp.getConfigParameters();
|
|
||||||
AccountingDashboardHarvesterPlugin.getProperties().set(properties);
|
|
||||||
|
|
||||||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
|
||||||
|
|
||||||
// DatabaseManager dbaseManager = new DatabaseManager();
|
|
||||||
AccountingDao dao = AccountingDao.get();
|
|
||||||
|
|
||||||
Set<ScopeDescriptor> scopeDescriptorSet = dao.getContexts();
|
|
||||||
Map<String, ScopeDescriptor> scopeDescriptorMap = new HashMap<>();
|
|
||||||
for (ScopeDescriptor scopeDescriptor : scopeDescriptorSet) {
|
|
||||||
scopeDescriptorMap.put(scopeDescriptor.getId(), scopeDescriptor);
|
|
||||||
}
|
|
||||||
AccountingDashboardHarvesterPlugin.scopeDescriptors.set(scopeDescriptorMap);
|
|
||||||
|
|
||||||
Set<Dimension> dimensionSet = dao.getDimensions();
|
|
||||||
Map<String, Dimension> dimensionMap = new HashMap<>();
|
|
||||||
for (Dimension dimension : dimensionSet) {
|
|
||||||
dimensionMap.put(dimension.getId(), dimension);
|
|
||||||
}
|
|
||||||
|
|
||||||
AccountingDashboardHarvesterPlugin.dimensions.set(dimensionMap);
|
|
||||||
|
|
||||||
// ArrayList<HarvestedData> data = new ArrayList<HarvestedData>();
|
|
||||||
ArrayList<AccountingRecord> accountingRecords = new ArrayList<AccountingRecord>();
|
ArrayList<AccountingRecord> accountingRecords = new ArrayList<AccountingRecord>();
|
||||||
|
|
||||||
String context = E_LEARNING_AREA_VRE;
|
String context = E_LEARNING_AREA_VRE;
|
||||||
|
|
||||||
// Setting the token for the context
|
// Setting the token for the context
|
||||||
ContextTest.set(contextAuthorization.getSecretForContext(context));
|
ContextTest.set(context);
|
||||||
|
|
||||||
ScopeBean scopeBean = new ScopeBean(context);
|
|
||||||
ScopeDescriptor scopeDescriptor = new ScopeDescriptor(scopeBean.name(), context);
|
|
||||||
|
|
||||||
|
ScopeDescriptor scopeDescriptor = AccountingDashboardHarvesterPlugin.getScopeDescriptor(context);
|
||||||
Dimension dimension = AccountingDashboardHarvesterPlugin.getDimension(HarvestedDataKey.ACCESSES.getKey());
|
Dimension dimension = AccountingDashboardHarvesterPlugin.getDimension(HarvestedDataKey.ACCESSES.getKey());
|
||||||
|
|
||||||
Calendar calendar = DateUtils.getStartCalendar(2018, Calendar.JULY, 1);
|
Calendar calendar = DateUtils.getStartCalendar(2018, Calendar.JULY, 1);
|
||||||
|
|
|
@ -5,22 +5,14 @@ import java.time.ZoneId;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.gcube.accounting.accounting.summary.access.AccountingDao;
|
import org.gcube.accounting.accounting.summary.access.AccountingDao;
|
||||||
import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor;
|
|
||||||
import org.gcube.accounting.accounting.summary.access.model.internal.Dimension;
|
|
||||||
import org.gcube.accounting.accounting.summary.access.model.update.AccountingRecord;
|
import org.gcube.accounting.accounting.summary.access.model.update.AccountingRecord;
|
||||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
|
||||||
import org.gcube.dataharvest.harvester.RStudioAccessesHarvester;
|
import org.gcube.dataharvest.harvester.RStudioAccessesHarvester;
|
||||||
import org.gcube.dataharvest.utils.AggregationType;
|
import org.gcube.dataharvest.utils.AggregationType;
|
||||||
import org.gcube.dataharvest.utils.ContextAuthorization;
|
|
||||||
import org.gcube.dataharvest.utils.ContextTest;
|
import org.gcube.dataharvest.utils.ContextTest;
|
||||||
import org.gcube.dataharvest.utils.DateUtils;
|
import org.gcube.dataharvest.utils.DateUtils;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
|
@ -33,39 +25,17 @@ import org.slf4j.LoggerFactory;
|
||||||
* @author Giancarlo Panichi (ISTI CNR)
|
* @author Giancarlo Panichi (ISTI CNR)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class AccountingDataHarvesterRStudioTest extends ContextTest {
|
public class AccountingDataHarvesterRStudioTest extends AccountingDataHarvesterPluginTest {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(AccountingDataHarvesterRStudioTest.class);
|
private static Logger logger = LoggerFactory.getLogger(AccountingDataHarvesterRStudioTest.class);
|
||||||
public static final String ROOT = "/d4science.research-infrastructures.eu";
|
|
||||||
// private static final String SCOPE = "/d4science.research-infrastructures.eu/D4OS/Blue-CloudLab";
|
|
||||||
|
|
||||||
protected AccountingDao getAccountingDao() throws ObjectNotFound, Exception {
|
|
||||||
AccountingDao dao = AccountingDao.get();
|
|
||||||
|
|
||||||
Set<ScopeDescriptor> scopeDescriptorSet = dao.getContexts();
|
|
||||||
Map<String, ScopeDescriptor> scopeDescriptorMap = new HashMap<>();
|
|
||||||
for (ScopeDescriptor scopeDescriptor : scopeDescriptorSet) {
|
|
||||||
scopeDescriptorMap.put(scopeDescriptor.getId(), scopeDescriptor);
|
|
||||||
}
|
|
||||||
AccountingDashboardHarvesterPlugin.scopeDescriptors.set(scopeDescriptorMap);
|
|
||||||
|
|
||||||
Set<Dimension> dimensionSet = dao.getDimensions();
|
|
||||||
Map<String, Dimension> dimensionMap = new HashMap<>();
|
|
||||||
for (Dimension dimension : dimensionSet) {
|
|
||||||
dimensionMap.put(dimension.getId(), dimension);
|
|
||||||
}
|
|
||||||
|
|
||||||
AccountingDashboardHarvesterPlugin.dimensions.set(dimensionMap);
|
|
||||||
|
|
||||||
return dao;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void testJupyterAccessesHarvester() throws Exception {
|
public void testJupyterAccessesHarvester() throws Exception {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
AccountingDao dao = getAccountingDao();
|
AccountingDao dao = getAccountingDao();
|
||||||
|
|
||||||
List<Date> starts = new ArrayList<>();
|
List<Date> starts = new ArrayList<>();
|
||||||
|
@ -78,43 +48,19 @@ public class AccountingDataHarvesterRStudioTest extends ContextTest {
|
||||||
|
|
||||||
AggregationType measureType = AggregationType.MONTHLY;
|
AggregationType measureType = AggregationType.MONTHLY;
|
||||||
|
|
||||||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
|
||||||
|
|
||||||
SortedSet<String> contexts = contextAuthorization.getContexts();
|
SortedSet<String> contexts = contextAuthorization.getContexts();
|
||||||
/*
|
|
||||||
SortedSet<String> contexts = new TreeSet<>();
|
|
||||||
contexts.add("/d4science.research-infrastructures.eu/D4OS/Blue-CloudLab");
|
|
||||||
contexts.add("/d4science.research-infrastructures.eu/D4OS/Zoo-Phytoplankton_EOV");
|
|
||||||
contexts.add("/d4science.research-infrastructures.eu/D4OS/MarineEnvironmentalIndicators");
|
|
||||||
*/
|
|
||||||
|
|
||||||
List<AccountingRecord> accountingRecords = new ArrayList<>();
|
List<AccountingRecord> accountingRecords = new ArrayList<>();
|
||||||
|
|
||||||
Set<ScopeDescriptor> scopeDescriptorSet = dao.getContexts();
|
|
||||||
Map<String, ScopeDescriptor> scopeDescriptorMap = new HashMap<>();
|
|
||||||
for (ScopeDescriptor scopeDescriptor : scopeDescriptorSet) {
|
|
||||||
scopeDescriptorMap.put(scopeDescriptor.getId(), scopeDescriptor);
|
|
||||||
}
|
|
||||||
AccountingDashboardHarvesterPlugin.scopeDescriptors.set(scopeDescriptorMap);
|
|
||||||
|
|
||||||
|
|
||||||
for (Date start : starts) {
|
for (Date start : starts) {
|
||||||
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
RStudioAccessesHarvester rstudioAccessesHarvester = new RStudioAccessesHarvester(start, end);
|
RStudioAccessesHarvester rstudioAccessesHarvester = new RStudioAccessesHarvester(start, end);
|
||||||
|
|
||||||
for(String context : contexts) {
|
for(String context : contexts) {
|
||||||
ContextTest.set(contextAuthorization.getSecretForContext(context));
|
ContextTest.set(context);
|
||||||
|
|
||||||
ScopeBean scopeBean = new ScopeBean(context);
|
|
||||||
|
|
||||||
ScopeDescriptor actualScopeDescriptor = scopeDescriptorMap.get(context);
|
|
||||||
if (actualScopeDescriptor == null) {
|
|
||||||
actualScopeDescriptor = new ScopeDescriptor(scopeBean.name(), context);
|
|
||||||
}
|
|
||||||
|
|
||||||
AccountingDashboardHarvesterPlugin.scopeDescriptor.set(actualScopeDescriptor);
|
|
||||||
|
|
||||||
List<AccountingRecord> harvested = rstudioAccessesHarvester.getAccountingRecords();
|
List<AccountingRecord> harvested = rstudioAccessesHarvester.getAccountingRecords();
|
||||||
accountingRecords.addAll(harvested);
|
accountingRecords.addAll(harvested);
|
||||||
|
@ -126,7 +72,7 @@ public class AccountingDataHarvesterRStudioTest extends ContextTest {
|
||||||
|
|
||||||
logger.debug("Going to insert {}", accountingRecords);
|
logger.debug("Going to insert {}", accountingRecords);
|
||||||
|
|
||||||
ContextTest.setContextByName(ROOT);
|
ContextTest.set(ROOT);
|
||||||
dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
|
|
@ -24,7 +24,6 @@ public class ContextAuthorizationTest extends ContextTest {
|
||||||
properties = new Properties();
|
properties = new Properties();
|
||||||
InputStream input = AccountingDashboardHarvesterPlugin.class.getClassLoader().getResourceAsStream(PROPERTY_FILENAME);
|
InputStream input = AccountingDashboardHarvesterPlugin.class.getClassLoader().getResourceAsStream(PROPERTY_FILENAME);
|
||||||
properties.load(input);
|
properties.load(input);
|
||||||
AccountingDashboardHarvesterPlugin.getProperties().set(properties);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
|
@ -35,7 +34,7 @@ public class ContextAuthorizationTest extends ContextTest {
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
logger.warn("Unable to load {} file containing configuration properties. AccountingDataHarvesterPlugin will use defaults", PROPERTY_FILENAME);
|
logger.warn("Unable to load {} file containing configuration properties. AccountingDataHarvesterPlugin will use defaults", PROPERTY_FILENAME);
|
||||||
}
|
}
|
||||||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
ContextAuthorization contextAuthorization = new ContextAuthorization(properties);
|
||||||
contextAuthorization.retrieveContextsAndTokens();
|
contextAuthorization.retrieveContextsAndTokens();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,11 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.dataharvest.utils;
|
package org.gcube.dataharvest.utils;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.gcube.common.authorization.utils.manager.SecretManager;
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
||||||
import org.gcube.common.authorization.utils.secret.Secret;
|
import org.gcube.common.authorization.utils.secret.Secret;
|
||||||
import org.gcube.common.authorization.utils.secret.SecretUtility;
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
|
@ -22,35 +19,9 @@ public class ContextTest {
|
||||||
protected static Properties properties;
|
protected static Properties properties;
|
||||||
protected static final String PROPERTIES_FILENAME = "token.properties";
|
protected static final String PROPERTIES_FILENAME = "token.properties";
|
||||||
|
|
||||||
public static final String ROOT;
|
protected static ContextAuthorization contextAuthorization;
|
||||||
public static final String VO;
|
|
||||||
public static final String VRE;
|
|
||||||
|
|
||||||
static {
|
private static void set(Secret secret) throws Exception {
|
||||||
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 = "/pred4s/preprod/preVRE";
|
|
||||||
// DEFAULT_TEST_SCOPE_NAME = "/gcube/devsec/devVRE";
|
|
||||||
|
|
||||||
//ROOT = "/gcube";
|
|
||||||
ROOT = "/d4science.research-infrastructures.eu";
|
|
||||||
VO = ROOT + "/devsec";
|
|
||||||
VRE = VO + "/devVRE";
|
|
||||||
// VO = ROOT + "/devNext";
|
|
||||||
// VRE = VO + "/NextNext";
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void set(Secret secret) throws Exception {
|
|
||||||
SecretManagerProvider.instance.reset();
|
SecretManagerProvider.instance.reset();
|
||||||
SecretManager secretManager = new SecretManager();
|
SecretManager secretManager = new SecretManager();
|
||||||
SecretManagerProvider.instance.set(secretManager);
|
SecretManagerProvider.instance.set(secretManager);
|
||||||
|
@ -58,29 +29,18 @@ public class ContextTest {
|
||||||
secretManager.set();
|
secretManager.set();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setContext(String token) throws Exception {
|
public static void set(String fullContextName) throws Exception {
|
||||||
Secret secret = getSecret(token);
|
|
||||||
set(secret);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setContextByName(String fullContextName) throws Exception {
|
|
||||||
Secret secret = getSecretByContextName(fullContextName);
|
Secret secret = getSecretByContextName(fullContextName);
|
||||||
set(secret);
|
set(secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Secret getSecret(String token) throws Exception {
|
|
||||||
Secret secret = SecretUtility.getSecretByTokenString(token);
|
|
||||||
return secret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Secret getSecretByContextName(String fullContextName) throws Exception {
|
private static Secret getSecretByContextName(String fullContextName) throws Exception {
|
||||||
String token = ContextTest.properties.getProperty(fullContextName);
|
return contextAuthorization.getSecretForContext(fullContextName);
|
||||||
return getSecret(token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() throws Exception {
|
public static void beforeClass() throws Exception {
|
||||||
setContextByName(ROOT);
|
contextAuthorization = new ContextAuthorization();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
|
|
Loading…
Reference in New Issue