Merge pull request 'feature/21031' (#1) from feature/21031 into master
Reviewed-on: #1
This commit is contained in:
commit
81d792162d
|
@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
## [v2.0.0-SNAPSHOT]
|
||||
|
||||
- Added Jupyter Harvester [#21031]
|
||||
- Switched accounting JSON management to gcube-jackson [#19115]
|
||||
- Switched smart-executor JSON management to gcube-jackson [#19647]
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.gcube.common.scope.impl.ScopeBean;
|
|||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
||||
import org.gcube.dataharvest.harvester.CatalogueAccessesHarvester;
|
||||
import org.gcube.dataharvest.harvester.CoreServicesAccessesHarvester;
|
||||
import org.gcube.dataharvest.harvester.JupyterAccessesHarvester;
|
||||
import org.gcube.dataharvest.harvester.MethodInvocationHarvester;
|
||||
import org.gcube.dataharvest.harvester.SocialInteractionsHarvester;
|
||||
import org.gcube.dataharvest.harvester.VREAccessesHarvester;
|
||||
|
@ -53,10 +54,11 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
|||
public static final String DRY_RUN_INPUT_PARAMETER = "dryRun";
|
||||
|
||||
/**
|
||||
* Allows partial harvesting of data of the current period.
|
||||
* This means that in MONTHLY aggregation type the current month is harvested instead of the previous month which
|
||||
* is done when the month is completed.
|
||||
* This allow the portlet to display monthly data in the current moth even the data is partial (till the current day).
|
||||
* Allows partial harvesting of data of the current period. This means that
|
||||
* in MONTHLY aggregation type the current month is harvested instead of the
|
||||
* previous month which is done when the month is completed. This allow the
|
||||
* portlet to display monthly data in the current moth even the data is
|
||||
* partial (till the current day).
|
||||
*/
|
||||
public static final String PARTIAL_HARVESTING = "partialHarvesting";
|
||||
|
||||
|
@ -85,14 +87,13 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
|||
|
||||
};
|
||||
|
||||
|
||||
public static InheritableThreadLocal<Properties> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public static Dimension getDimension(String key) {
|
||||
Dimension dimension = dimensions.get().get(key);
|
||||
if(dimension == null) {
|
||||
if (dimension == null) {
|
||||
dimension = new Dimension(key, key, null, key);
|
||||
}
|
||||
return dimension;
|
||||
|
@ -107,12 +108,11 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
|||
|
||||
};
|
||||
|
||||
|
||||
public static ScopeDescriptor getScopeDescriptor(String context) {
|
||||
return scopeDescriptors.get().get(context);
|
||||
}
|
||||
|
||||
protected static final InheritableThreadLocal<Map<String, ScopeDescriptor>> scopeDescriptors = new InheritableThreadLocal<Map<String, ScopeDescriptor>>() {
|
||||
public static final InheritableThreadLocal<Map<String, ScopeDescriptor>> scopeDescriptors = new InheritableThreadLocal<Map<String, ScopeDescriptor>>() {
|
||||
|
||||
@Override
|
||||
protected Map<String, ScopeDescriptor> initialValue() {
|
||||
|
@ -129,7 +129,7 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
|||
|
||||
@Override
|
||||
protected ScopeDescriptor initialValue() {
|
||||
return new ScopeDescriptor("","");
|
||||
return new ScopeDescriptor("", "");
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -141,7 +141,7 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
|||
.getResourceAsStream(PROPERTY_FILENAME);
|
||||
properties.load(input);
|
||||
return properties;
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.warn(
|
||||
"Unable to load {} file containing configuration properties. AccountingDataHarvesterPlugin will use defaults",
|
||||
PROPERTY_FILENAME);
|
||||
|
@ -151,52 +151,52 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void launch(Map<String,Object> inputs) throws Exception {
|
||||
public void launch(Map<String, Object> inputs) throws Exception {
|
||||
logger.debug("{} is starting", this.getClass().getSimpleName());
|
||||
|
||||
if(inputs == null || inputs.isEmpty()) {
|
||||
if (inputs == null || inputs.isEmpty()) {
|
||||
throw new IllegalArgumentException("The can only be launched providing valid input parameters");
|
||||
}
|
||||
|
||||
if(!inputs.containsKey(MEASURE_TYPE_INPUT_PARAMETER)) {
|
||||
if (!inputs.containsKey(MEASURE_TYPE_INPUT_PARAMETER)) {
|
||||
throw new IllegalArgumentException("Please set required parameter '" + MEASURE_TYPE_INPUT_PARAMETER + "'");
|
||||
}
|
||||
|
||||
AggregationType aggregationType = AggregationType.valueOf((String) inputs.get(MEASURE_TYPE_INPUT_PARAMETER));
|
||||
|
||||
boolean reRun = true;
|
||||
if(inputs.containsKey(RERUN_INPUT_PARAMETER)) {
|
||||
if (inputs.containsKey(RERUN_INPUT_PARAMETER)) {
|
||||
try {
|
||||
reRun = (boolean) inputs.get(RERUN_INPUT_PARAMETER);
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("'" + RERUN_INPUT_PARAMETER + "' must be a boolean");
|
||||
}
|
||||
}
|
||||
|
||||
boolean getVREUsers = true;
|
||||
if(inputs.containsKey(GET_VRE_USERS_INPUT_PARAMETER)) {
|
||||
if (inputs.containsKey(GET_VRE_USERS_INPUT_PARAMETER)) {
|
||||
try {
|
||||
reRun = (boolean) inputs.get(GET_VRE_USERS_INPUT_PARAMETER);
|
||||
} catch(Exception e) {
|
||||
getVREUsers = (boolean) inputs.get(GET_VRE_USERS_INPUT_PARAMETER);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("'" + GET_VRE_USERS_INPUT_PARAMETER + "' must be a boolean");
|
||||
}
|
||||
}
|
||||
|
||||
boolean dryRun = true;
|
||||
if(inputs.containsKey(DRY_RUN_INPUT_PARAMETER)) {
|
||||
if (inputs.containsKey(DRY_RUN_INPUT_PARAMETER)) {
|
||||
try {
|
||||
dryRun = (boolean) inputs.get(DRY_RUN_INPUT_PARAMETER);
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("'" + DRY_RUN_INPUT_PARAMETER + "' must be a boolean");
|
||||
}
|
||||
}
|
||||
|
||||
boolean partialHarvesting = false;
|
||||
if(inputs.containsKey(PARTIAL_HARVESTING)) {
|
||||
if (inputs.containsKey(PARTIAL_HARVESTING)) {
|
||||
partialHarvesting = (boolean) inputs.get(PARTIAL_HARVESTING);
|
||||
}
|
||||
|
||||
if(inputs.containsKey(START_DATE_INPUT_PARAMETER)) {
|
||||
if (inputs.containsKey(START_DATE_INPUT_PARAMETER)) {
|
||||
String startDateString = (String) inputs.get(START_DATE_INPUT_PARAMETER);
|
||||
start = DateUtils.UTC_DATE_FORMAT.parse(startDateString + " " + DateUtils.UTC);
|
||||
} else {
|
||||
|
@ -205,8 +205,8 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
|||
|
||||
end = DateUtils.getEndDateFromStartDate(aggregationType, start, 1, partialHarvesting);
|
||||
|
||||
logger.debug("Harvesting from {} to {} (ReRun:{} - GetVREUsers:{} - DryRun:{})",
|
||||
DateUtils.format(start), DateUtils.format(end), reRun, getVREUsers, dryRun);
|
||||
logger.debug("Harvesting from {} to {} (ReRun:{} - GetVREUsers:{} - DryRun:{})", DateUtils.format(start),
|
||||
DateUtils.format(end), reRun, getVREUsers, dryRun);
|
||||
|
||||
Properties properties = getConfigParameters();
|
||||
getProperties().set(properties);
|
||||
|
@ -221,16 +221,15 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
|||
AccountingDao dao = AccountingDao.get();
|
||||
|
||||
Set<ScopeDescriptor> scopeDescriptorSet = dao.getContexts();
|
||||
Map<String,ScopeDescriptor> scopeDescriptorMap = new HashMap<>();
|
||||
for(ScopeDescriptor scopeDescriptor : scopeDescriptorSet) {
|
||||
Map<String, ScopeDescriptor> scopeDescriptorMap = new HashMap<>();
|
||||
for (ScopeDescriptor scopeDescriptor : scopeDescriptorSet) {
|
||||
scopeDescriptorMap.put(scopeDescriptor.getId(), scopeDescriptor);
|
||||
}
|
||||
scopeDescriptors.set(scopeDescriptorMap);
|
||||
|
||||
|
||||
Set<Dimension> dimensionSet = dao.getDimensions();
|
||||
Map<String,Dimension> dimensionMap = new HashMap<>();
|
||||
for(Dimension dimension : dimensionSet) {
|
||||
Map<String, Dimension> dimensionMap = new HashMap<>();
|
||||
for (Dimension dimension : dimensionSet) {
|
||||
dimensionMap.put(dimension.getId(), dimension);
|
||||
}
|
||||
|
||||
|
@ -241,21 +240,22 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
|||
String initialToken = SecurityTokenProvider.instance.get();
|
||||
|
||||
VREAccessesHarvester vreAccessesHarvester = null;
|
||||
JupyterAccessesHarvester jupyterAccessesHarvester = null;
|
||||
|
||||
for(String context : contexts) {
|
||||
for (String context : contexts) {
|
||||
// Setting the token for the context
|
||||
Utils.setContext(contextAuthorization.getTokenForContext(context));
|
||||
|
||||
ScopeBean scopeBean = new ScopeBean(context);
|
||||
|
||||
ScopeDescriptor actualScopeDescriptor = scopeDescriptorMap.get(context);
|
||||
if(actualScopeDescriptor==null) {
|
||||
if (actualScopeDescriptor == null) {
|
||||
actualScopeDescriptor = new ScopeDescriptor(scopeBean.name(), context);
|
||||
}
|
||||
|
||||
scopeDescriptor.set(actualScopeDescriptor);
|
||||
|
||||
if(scopeBean.is(Type.INFRASTRUCTURE)) {
|
||||
if (scopeBean.is(Type.INFRASTRUCTURE)) {
|
||||
try {
|
||||
|
||||
CatalogueAccessesHarvester catalogueHarvester = new CatalogueAccessesHarvester(start, end);
|
||||
|
@ -266,21 +266,22 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
|||
List<AccountingRecord> records = coreServicesHarvester.getAccountingRecords();
|
||||
accountingRecords.addAll(records);
|
||||
|
||||
}catch (Exception e) {
|
||||
logger.error("Error harvesting {} for {}", CatalogueAccessesHarvester.class.getSimpleName(), context, e);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error harvesting {} for {}", CatalogueAccessesHarvester.class.getSimpleName(),
|
||||
context, e);
|
||||
}
|
||||
}
|
||||
|
||||
if (vreAccessesHarvester == null) {
|
||||
|
||||
if(vreAccessesHarvester == null) {
|
||||
|
||||
if(scopeBean.is(Type.INFRASTRUCTURE)) {
|
||||
if (scopeBean.is(Type.INFRASTRUCTURE)) {
|
||||
vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
||||
} else {
|
||||
// This code should be never used because the scopes are sorted by fullname
|
||||
// This code should be never used because the scopes are
|
||||
// sorted by fullname
|
||||
|
||||
ScopeBean parent = scopeBean.enclosingScope();
|
||||
while(!parent.is(Type.INFRASTRUCTURE)) {
|
||||
while (!parent.is(Type.INFRASTRUCTURE)) {
|
||||
parent = scopeBean.enclosingScope();
|
||||
}
|
||||
|
||||
|
@ -295,8 +296,31 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
|||
|
||||
}
|
||||
|
||||
if (jupyterAccessesHarvester == null) {
|
||||
|
||||
if((context.startsWith(SO_BIG_DATA_VO) || context.startsWith(SO_BIG_DATA_EU_VRE)
|
||||
if (scopeBean.is(Type.INFRASTRUCTURE)) {
|
||||
jupyterAccessesHarvester = new JupyterAccessesHarvester(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
|
||||
Utils.setContext(contextAuthorization.getTokenForContext(parent.toString()));
|
||||
|
||||
jupyterAccessesHarvester = new JupyterAccessesHarvester(start, end);
|
||||
|
||||
// Setting back token for the context
|
||||
Utils.setContext(contextAuthorization.getTokenForContext(context));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ((context.startsWith(SO_BIG_DATA_VO) || context.startsWith(SO_BIG_DATA_EU_VRE)
|
||||
|| context.startsWith(SO_BIG_DATA_IT_VRE))
|
||||
&& start.before(DateUtils.getStartCalendar(2018, Calendar.APRIL, 1).getTime())) {
|
||||
logger.info("Not Harvesting for {} from {} to {}", context, DateUtils.format(start),
|
||||
|
@ -311,10 +335,26 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
|||
accountingRecords.addAll(harvested);
|
||||
|
||||
/*
|
||||
List<HarvestedData> harvested = vreAccessesHarvester.getData();
|
||||
data.addAll(harvested);
|
||||
* List<HarvestedData> harvested =
|
||||
* vreAccessesHarvester.getData(); data.addAll(harvested);
|
||||
*/
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("Error harvesting VRE Accesses for {}", context, e);
|
||||
}
|
||||
|
||||
try {
|
||||
// Collecting Google Analytics Data for Jupyters Accesses
|
||||
logger.info("Going to harvest Jupyter Accesses for {}", context);
|
||||
|
||||
List<AccountingRecord> harvested = jupyterAccessesHarvester.getAccountingRecords();
|
||||
accountingRecords.addAll(harvested);
|
||||
|
||||
/*
|
||||
* List<HarvestedData> harvested =
|
||||
* jupyterAccessesHarvester.getData();
|
||||
* data.addAll(harvested);
|
||||
*/
|
||||
} catch (Exception e) {
|
||||
logger.error("Error harvesting VRE Accesses for {}", context, e);
|
||||
}
|
||||
|
||||
|
@ -327,19 +367,21 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
|||
accountingRecords.addAll(harvested);
|
||||
|
||||
/*
|
||||
List<HarvestedData> harvested = socialHarvester.getData();
|
||||
data.addAll(harvested);
|
||||
* List<HarvestedData> harvested =
|
||||
* socialHarvester.getData(); data.addAll(harvested);
|
||||
*/
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("Error harvesting Social Interactions for {}", context, e);
|
||||
}
|
||||
|
||||
try {
|
||||
// Collecting info on VRE users
|
||||
if(getVREUsers) {
|
||||
// Harvesting Users only for VREs (not for VO and ROOT which is the sum of the children contexts)
|
||||
if (getVREUsers) {
|
||||
// Harvesting Users only for VREs (not for VO and ROOT
|
||||
// which is the sum of the children contexts)
|
||||
// The VREUsers can be only Harvested for the last month
|
||||
if(scopeBean.is(Type.VRE) && start.equals(DateUtils.getPreviousPeriod(aggregationType, partialHarvesting).getTime())) {
|
||||
if (scopeBean.is(Type.VRE) && start
|
||||
.equals(DateUtils.getPreviousPeriod(aggregationType, partialHarvesting).getTime())) {
|
||||
logger.info("Going to harvest Context Users for {}", context);
|
||||
VREUsersHarvester vreUsersHarvester = new VREUsersHarvester(start, end);
|
||||
|
||||
|
@ -347,32 +389,35 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
|||
accountingRecords.addAll(harvested);
|
||||
|
||||
/*
|
||||
List<HarvestedData> harvested = vreUsersHarvester.getData();
|
||||
data.addAll(harvested);
|
||||
* List<HarvestedData> harvested =
|
||||
* vreUsersHarvester.getData();
|
||||
* data.addAll(harvested);
|
||||
*/
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("Error harvesting Context Users for {}", context, e);
|
||||
}
|
||||
|
||||
if(context.startsWith(SO_BIG_DATA_CATALOGUE_CONTEXT)) {
|
||||
if (context.startsWith(SO_BIG_DATA_CATALOGUE_CONTEXT)) {
|
||||
|
||||
try {
|
||||
// Collecting info on Resource Catalogue (Dataset, Application, Deliverables, Methods)
|
||||
// Collecting info on Resource Catalogue (Dataset,
|
||||
// Application, Deliverables, Methods)
|
||||
logger.info("Going to harvest Resource Catalogue Information for {}", context);
|
||||
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end,
|
||||
contexts);
|
||||
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start,
|
||||
end, contexts);
|
||||
|
||||
List<AccountingRecord> harvested = resourceCatalogueHarvester.getAccountingRecords();
|
||||
accountingRecords.addAll(harvested);
|
||||
|
||||
/*
|
||||
List<HarvestedData> harvested = resourceCatalogueHarvester.getData();
|
||||
data.addAll(harvested);
|
||||
* List<HarvestedData> harvested =
|
||||
* resourceCatalogueHarvester.getData();
|
||||
* data.addAll(harvested);
|
||||
*/
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("Error harvesting Resource Catalogue Information for {}", context, e);
|
||||
}
|
||||
|
||||
|
@ -385,13 +430,13 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
|||
List<AccountingRecord> harvested = dataMethodDownloadHarvester.getAccountingRecords();
|
||||
accountingRecords.addAll(harvested);
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("Error harvesting Data Method Download for {}", context, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(context.startsWith(TAGME_CONTEXT)) {
|
||||
if (context.startsWith(TAGME_CONTEXT)) {
|
||||
try {
|
||||
// Collecting info on method invocation
|
||||
logger.info("Going to harvest Method Invocations for {}", context);
|
||||
|
@ -402,11 +447,12 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
|||
accountingRecords.addAll(harvested);
|
||||
|
||||
/*
|
||||
List<HarvestedData> harvested = tagMeMethodInvocationHarvester.getData();
|
||||
data.addAll(harvested);
|
||||
* List<HarvestedData> harvested =
|
||||
* tagMeMethodInvocationHarvester.getData();
|
||||
* data.addAll(harvested);
|
||||
*/
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("Error harvesting Method Invocations for {}", context, e);
|
||||
}
|
||||
} else {
|
||||
|
@ -415,15 +461,15 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
|||
logger.info("Going to harvest Method Invocations for {}", context);
|
||||
MethodInvocationHarvester methodInvocationHarvester = new MethodInvocationHarvester(start, end);
|
||||
|
||||
|
||||
List<AccountingRecord> harvested = methodInvocationHarvester.getAccountingRecords();
|
||||
accountingRecords.addAll(harvested);
|
||||
|
||||
/*
|
||||
List<HarvestedData> harvested = methodInvocationHarvester.getData();
|
||||
data.addAll(harvested);
|
||||
* List<HarvestedData> harvested =
|
||||
* methodInvocationHarvester.getData();
|
||||
* data.addAll(harvested);
|
||||
*/
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("Error harvesting Method Invocations for {}", context, e);
|
||||
}
|
||||
}
|
||||
|
@ -432,11 +478,11 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
|
|||
|
||||
Utils.setContext(initialToken);
|
||||
|
||||
logger.debug("Harvest Measures from {} to {} are {}", DateUtils.format(start), DateUtils.format(end), accountingRecords);
|
||||
if(!dryRun) {
|
||||
logger.debug("Harvest Measures from {} to {} are {}", DateUtils.format(start), DateUtils.format(end),
|
||||
accountingRecords);
|
||||
if (!dryRun) {
|
||||
dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
||||
//dbaseManager.insertMonthlyData(start, end, data, reRun);
|
||||
}else {
|
||||
} else {
|
||||
logger.debug("Harvested measures are {}", accountingRecords);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ public enum HarvestedDataKey {
|
|||
MESSAGES_ACCESSES("Messages Accesses"),
|
||||
NOTIFICATIONS_ACCESSES("Notifications Accesses"),
|
||||
PROFILE_ACCESSES("Profile Accesses"),
|
||||
JUPYTER_ACCESSES("Jupyter Accesses"),
|
||||
|
||||
CATALOGUE_ACCESSES("Catalogue Accesses"),
|
||||
CATALOGUE_DATASET_LIST_ACCESSES("Item List"),
|
||||
|
|
|
@ -0,0 +1,407 @@
|
|||
package org.gcube.dataharvest.harvester;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor;
|
||||
import org.gcube.accounting.accounting.summary.access.model.update.AccountingRecord;
|
||||
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
||||
import org.gcube.common.resources.gcore.utils.Group;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.dataharvest.AccountingDashboardHarvesterPlugin;
|
||||
import org.gcube.dataharvest.datamodel.AnalyticsReportCredentials;
|
||||
import org.gcube.dataharvest.datamodel.HarvestedDataKey;
|
||||
import org.gcube.dataharvest.datamodel.VREAccessesReportRow;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder;
|
||||
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
|
||||
import com.google.api.client.googleapis.util.Utils;
|
||||
import com.google.api.client.http.HttpTransport;
|
||||
import com.google.api.client.json.JsonFactory;
|
||||
import com.google.api.client.json.gson.GsonFactory;
|
||||
import com.google.api.client.util.PemReader;
|
||||
import com.google.api.client.util.PemReader.Section;
|
||||
import com.google.api.client.util.SecurityUtils;
|
||||
import com.google.api.services.analyticsreporting.v4.AnalyticsReporting;
|
||||
import com.google.api.services.analyticsreporting.v4.AnalyticsReportingScopes;
|
||||
import com.google.api.services.analyticsreporting.v4.model.DateRange;
|
||||
import com.google.api.services.analyticsreporting.v4.model.DateRangeValues;
|
||||
import com.google.api.services.analyticsreporting.v4.model.GetReportsRequest;
|
||||
import com.google.api.services.analyticsreporting.v4.model.GetReportsResponse;
|
||||
import com.google.api.services.analyticsreporting.v4.model.Metric;
|
||||
import com.google.api.services.analyticsreporting.v4.model.Report;
|
||||
import com.google.api.services.analyticsreporting.v4.model.ReportRequest;
|
||||
import com.google.api.services.analyticsreporting.v4.model.ReportRow;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Giancarlo Panichi (ISTI CNR)
|
||||
*
|
||||
*/
|
||||
public class JupyterAccessesHarvester extends BasicHarvester {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(JupyterAccessesHarvester.class);
|
||||
|
||||
private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
|
||||
|
||||
private static final String SERVICE_ENDPOINT_CATEGORY = "OnlineService";
|
||||
private static final String SERVICE_ENDPOINT_NAME = "BigGAnalyticsReportService";
|
||||
private static final String AP_VIEWS_PROPERTY = "views";
|
||||
private static final String AP_CLIENT_PROPERTY = "clientId";
|
||||
private static final String AP_PRIVATEKEY_PROPERTY = "privateKeyId";
|
||||
private static final String APPLICATION_NAME = "Analytics Reporting";
|
||||
|
||||
private List<VREAccessesReportRow> vreAccesses;
|
||||
|
||||
public JupyterAccessesHarvester(Date start, Date end) throws Exception {
|
||||
super(start, end);
|
||||
logger.debug("JupyerAccessHArvester: {}, {}", start, end);
|
||||
vreAccesses = getAllAccesses(start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AccountingRecord> getAccountingRecords() throws Exception {
|
||||
try {
|
||||
String context = org.gcube.dataharvest.utils.Utils.getCurrentContext();
|
||||
|
||||
ArrayList<AccountingRecord> accountingRecords = new ArrayList<AccountingRecord>();
|
||||
|
||||
int measure = 0;
|
||||
|
||||
ScopeBean scopeBean = new ScopeBean(context);
|
||||
String lowerCasedContext = scopeBean.name().toLowerCase();
|
||||
logger.debug("JupyerAccessHArvester lowerCasedContext: {}", lowerCasedContext);
|
||||
for (VREAccessesReportRow row : vreAccesses) {
|
||||
String pagePath = row.getPagePath().toLowerCase();
|
||||
if (pagePath != null && !pagePath.isEmpty()) {
|
||||
if (pagePath.contains(lowerCasedContext)) {
|
||||
if (!pagePath.contains("catalogue")) {
|
||||
if (pagePath.contains("jupyter") || pagePath.contains("jupiter")) {
|
||||
logger.trace("Matched jupyter or jupiter ({}) : {}", lowerCasedContext, pagePath);
|
||||
measure += row.getVisitNumber();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScopeDescriptor scopeDescriptor = AccountingDashboardHarvesterPlugin.getScopeDescriptor();
|
||||
|
||||
AccountingRecord ar = new AccountingRecord(scopeDescriptor, instant,
|
||||
getDimension(HarvestedDataKey.JUPYTER_ACCESSES), (long) measure);
|
||||
logger.debug("{} : {}", ar.getDimension().getId(), ar.getMeasure());
|
||||
accountingRecords.add(ar);
|
||||
|
||||
return accountingRecords;
|
||||
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a list of {@link VREAccessesReportRow} objects containing the
|
||||
* pagePath and the visit number e.g. VREAccessesReportRow
|
||||
* [pagePath=/group/agroclimaticmodelling/add-new-users,
|
||||
* visitNumber=1] VREAccessesReportRow
|
||||
* [pagePath=/group/agroclimaticmodelling/administration,
|
||||
* visitNumber=2] VREAccessesReportRow
|
||||
* [pagePath=/group/agroclimaticmodelling/agroclimaticmodelling,
|
||||
* visitNumber=39]
|
||||
*/
|
||||
private static List<VREAccessesReportRow> getAllAccesses(Date start, Date end) throws Exception {
|
||||
DateRange dateRange = getDateRangeForAnalytics(start, end);
|
||||
logger.trace("Getting accesses in this time range {}", dateRange.toPrettyString());
|
||||
|
||||
AnalyticsReportCredentials credentialsFromD4S = getAuthorisedApplicationInfoFromIs();
|
||||
AnalyticsReporting service = initializeAnalyticsReporting(credentialsFromD4S);
|
||||
HashMap<String, List<GetReportsResponse>> responses = getReportResponses(service,
|
||||
credentialsFromD4S.getViewIds(), dateRange);
|
||||
List<VREAccessesReportRow> totalAccesses = new ArrayList<>();
|
||||
|
||||
for (String view : responses.keySet()) {
|
||||
List<VREAccessesReportRow> viewReport = parseResponse(view, responses.get(view));
|
||||
logger.trace("Got {} entries from view id={}", viewReport.size(), view);
|
||||
totalAccesses.addAll(viewReport);
|
||||
}
|
||||
logger.trace("Merged in {} total entries from all views", totalAccesses.size());
|
||||
return totalAccesses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes an Analytics Reporting API V4 service object.
|
||||
*
|
||||
* @return An authorized Analytics Reporting API V4 service object.
|
||||
* @throws IOException
|
||||
* @throws GeneralSecurityException
|
||||
*/
|
||||
private static AnalyticsReporting initializeAnalyticsReporting(AnalyticsReportCredentials cred)
|
||||
throws GeneralSecurityException, IOException {
|
||||
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
|
||||
GoogleCredential credential = fromD4SServiceEndpoint(cred).createScoped(AnalyticsReportingScopes.all());
|
||||
|
||||
// Construct the Analytics Reporting service object.
|
||||
return new AnalyticsReporting.Builder(httpTransport, JSON_FACTORY, credential)
|
||||
.setApplicationName(APPLICATION_NAME).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries the Analytics Reporting API V4.
|
||||
*
|
||||
* @param service
|
||||
* An authorized Analytics Reporting API V4 service object.
|
||||
* @return GetReportResponse The Analytics Reporting API V4 response.
|
||||
* @throws IOException
|
||||
*/
|
||||
private static HashMap<String, List<GetReportsResponse>> getReportResponses(AnalyticsReporting service,
|
||||
List<String> viewIDs, DateRange dateRange) throws IOException {
|
||||
|
||||
HashMap<String, List<GetReportsResponse>> reports = new HashMap<>();
|
||||
|
||||
// Create the Metrics object.
|
||||
Metric sessions = new Metric().setExpression("ga:pageviews").setAlias("pages");
|
||||
com.google.api.services.analyticsreporting.v4.model.Dimension pageTitle = new com.google.api.services.analyticsreporting.v4.model.Dimension()
|
||||
.setName("ga:pagePath");
|
||||
|
||||
for (String view : viewIDs) {
|
||||
List<GetReportsResponse> gReportResponses = new ArrayList<>();
|
||||
logger.info("Getting data from Google Analytics for viewid: " + view);
|
||||
boolean iterateMorePages = true;
|
||||
String nextPageToken = null;
|
||||
while (iterateMorePages) {
|
||||
// Create the ReportRequest object.
|
||||
ReportRequest request = new ReportRequest().setViewId(view.trim())
|
||||
.setDateRanges(Arrays.asList(dateRange)).setMetrics(Arrays.asList(sessions))
|
||||
.setDimensions(Arrays.asList(pageTitle));
|
||||
request.setPageSize(1000);
|
||||
request.setPageToken(nextPageToken);
|
||||
ArrayList<ReportRequest> requests = new ArrayList<ReportRequest>();
|
||||
requests.add(request);
|
||||
// Create the GetReportsRequest object.
|
||||
GetReportsRequest getReport = new GetReportsRequest().setReportRequests(requests);
|
||||
// Call the batchGet method.
|
||||
GetReportsResponse response = service.reports().batchGet(getReport).execute();
|
||||
nextPageToken = response.getReports().get(0).getNextPageToken();
|
||||
iterateMorePages = (nextPageToken != null);
|
||||
logger.debug("got nextPageToken: " + nextPageToken);
|
||||
gReportResponses.add(response);
|
||||
}
|
||||
reports.put(view, gReportResponses);
|
||||
}
|
||||
// Return the response.
|
||||
return reports;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses and prints the Analytics Reporting API V4 response.
|
||||
*
|
||||
* @param response
|
||||
* An Analytics Reporting API V4 response.
|
||||
*/
|
||||
/**
|
||||
* Parses and prints the Analytics Reporting API V4 response.
|
||||
*
|
||||
* @param response
|
||||
* An Analytics Reporting API V4 response.
|
||||
*/
|
||||
private static List<VREAccessesReportRow> parseResponse(String viewId, List<GetReportsResponse> responses) {
|
||||
logger.debug("parsing Response for " + viewId);
|
||||
|
||||
List<VREAccessesReportRow> toReturn = new ArrayList<>();
|
||||
for (GetReportsResponse response : responses) {
|
||||
for (Report report : response.getReports()) {
|
||||
List<ReportRow> rows = report.getData().getRows();
|
||||
if (rows == null) {
|
||||
logger.warn("No data found for " + viewId);
|
||||
} else {
|
||||
for (ReportRow row : rows) {
|
||||
String dimension = row.getDimensions().get(0);
|
||||
DateRangeValues metric = row.getMetrics().get(0);
|
||||
VREAccessesReportRow var = new VREAccessesReportRow();
|
||||
boolean validEntry = false;
|
||||
String pagePath = dimension;
|
||||
if (pagePath.startsWith("/group") || pagePath.startsWith("/web")) {
|
||||
var.setPagePath(dimension);
|
||||
validEntry = true;
|
||||
}
|
||||
if (validEntry) {
|
||||
var.setVisitNumber(Integer.parseInt(metric.getValues().get(0)));
|
||||
toReturn.add(var);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
private static GoogleCredential fromD4SServiceEndpoint(AnalyticsReportCredentials cred) throws IOException {
|
||||
|
||||
String clientId = cred.getClientId();
|
||||
String clientEmail = cred.getClientEmail();
|
||||
String privateKeyPem = cred.getPrivateKeyPem();
|
||||
String privateKeyId = cred.getPrivateKeyId();
|
||||
String tokenUri = cred.getTokenUri();
|
||||
String projectId = cred.getProjectId();
|
||||
|
||||
if (clientId == null || clientEmail == null || privateKeyPem == null || privateKeyId == null) {
|
||||
throw new IOException("Error reading service account credential from stream, "
|
||||
+ "expecting 'client_id', 'client_email', 'private_key' and 'private_key_id'.");
|
||||
}
|
||||
|
||||
PrivateKey privateKey = privateKeyFromPkcs8(privateKeyPem);
|
||||
|
||||
Collection<String> emptyScopes = Collections.emptyList();
|
||||
|
||||
Builder credentialBuilder = new GoogleCredential.Builder().setTransport(Utils.getDefaultTransport())
|
||||
.setJsonFactory(Utils.getDefaultJsonFactory()).setServiceAccountId(clientEmail)
|
||||
.setServiceAccountScopes(emptyScopes).setServiceAccountPrivateKey(privateKey)
|
||||
.setServiceAccountPrivateKeyId(privateKeyId);
|
||||
|
||||
if (tokenUri != null) {
|
||||
credentialBuilder.setTokenServerEncodedUrl(tokenUri);
|
||||
}
|
||||
|
||||
if (projectId != null) {
|
||||
credentialBuilder.setServiceAccountProjectId(projectId);
|
||||
}
|
||||
|
||||
// Don't do a refresh at this point, as it will always fail before the
|
||||
// scopes are added.
|
||||
return credentialBuilder.build();
|
||||
}
|
||||
|
||||
private static PrivateKey privateKeyFromPkcs8(String privateKeyPem) throws IOException {
|
||||
Reader reader = new StringReader(privateKeyPem);
|
||||
Section section = PemReader.readFirstSectionAndClose(reader, "PRIVATE KEY");
|
||||
if (section == null) {
|
||||
throw new IOException("Invalid PKCS8 data.");
|
||||
}
|
||||
byte[] bytes = section.getBase64DecodedBytes();
|
||||
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(bytes);
|
||||
Exception unexpectedException = null;
|
||||
try {
|
||||
KeyFactory keyFactory = SecurityUtils.getRsaKeyFactory();
|
||||
PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
|
||||
return privateKey;
|
||||
} catch (NoSuchAlgorithmException exception) {
|
||||
unexpectedException = exception;
|
||||
} catch (InvalidKeySpecException exception) {
|
||||
unexpectedException = exception;
|
||||
}
|
||||
throw new IOException("Unexpected exception reading PKCS data", unexpectedException);
|
||||
}
|
||||
|
||||
private static List<ServiceEndpoint> getAnalyticsReportingConfigurationFromIS(String infrastructureScope)
|
||||
throws Exception {
|
||||
String scope = infrastructureScope;
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(scope);
|
||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||
query.addCondition("$resource/Profile/Category/text() eq '" + SERVICE_ENDPOINT_CATEGORY + "'");
|
||||
query.addCondition("$resource/Profile/Name/text() eq '" + SERVICE_ENDPOINT_NAME + "'");
|
||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||
List<ServiceEndpoint> toReturn = client.submit(query);
|
||||
ScopeProvider.instance.set(currScope);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* l
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private static AnalyticsReportCredentials getAuthorisedApplicationInfoFromIs() throws Exception {
|
||||
AnalyticsReportCredentials reportCredentials = new AnalyticsReportCredentials();
|
||||
|
||||
String context = org.gcube.dataharvest.utils.Utils.getCurrentContext();
|
||||
try {
|
||||
List<ServiceEndpoint> list = getAnalyticsReportingConfigurationFromIS(context);
|
||||
if (list.size() > 1) {
|
||||
logger.error("Too many Service Endpoints having name " + SERVICE_ENDPOINT_NAME
|
||||
+ " in this scope having Category " + SERVICE_ENDPOINT_CATEGORY);
|
||||
} else if (list.size() == 0) {
|
||||
logger.warn("There is no Service Endpoint having name " + SERVICE_ENDPOINT_NAME + " and Category "
|
||||
+ SERVICE_ENDPOINT_CATEGORY + " in this context: " + context);
|
||||
} else {
|
||||
|
||||
for (ServiceEndpoint res : list) {
|
||||
reportCredentials.setTokenUri(res.profile().runtime().hostedOn());
|
||||
Group<AccessPoint> apGroup = res.profile().accessPoints();
|
||||
AccessPoint[] accessPoints = (AccessPoint[]) apGroup.toArray(new AccessPoint[apGroup.size()]);
|
||||
AccessPoint found = accessPoints[0];
|
||||
reportCredentials.setClientEmail(found.address());
|
||||
reportCredentials.setProjectId(found.username());
|
||||
reportCredentials.setPrivateKeyPem(StringEncrypter.getEncrypter().decrypt(found.password()));
|
||||
for (Property prop : found.properties()) {
|
||||
if (prop.name().compareTo(AP_VIEWS_PROPERTY) == 0) {
|
||||
String decryptedValue = StringEncrypter.getEncrypter().decrypt(prop.value());
|
||||
String[] views = decryptedValue.split(";");
|
||||
reportCredentials.setViewIds(Arrays.asList(views));
|
||||
}
|
||||
if (prop.name().compareTo(AP_CLIENT_PROPERTY) == 0) {
|
||||
String decryptedValue = StringEncrypter.getEncrypter().decrypt(prop.value());
|
||||
reportCredentials.setClientId(decryptedValue);
|
||||
}
|
||||
if (prop.name().compareTo(AP_PRIVATEKEY_PROPERTY) == 0) {
|
||||
String decryptedValue = StringEncrypter.getEncrypter().decrypt(prop.value());
|
||||
reportCredentials.setPrivateKeyId(decryptedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return reportCredentials;
|
||||
}
|
||||
|
||||
private static LocalDate asLocalDate(Date date) {
|
||||
return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDate();
|
||||
}
|
||||
|
||||
private static DateRange getDateRangeForAnalytics(Date start, Date end) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); // required
|
||||
// by
|
||||
// Analytics
|
||||
String startDate = asLocalDate(start).format(formatter);
|
||||
String endDate = asLocalDate(end).format(formatter);
|
||||
DateRange dateRange = new DateRange();// date format `yyyy-MM-dd`
|
||||
dateRange.setStartDate(startDate);
|
||||
dateRange.setEndDate(endDate);
|
||||
return dateRange;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
package org.gcube.dataharvest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
|
||||
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.common.authorization.client.exceptions.ObjectNotFound;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.dataharvest.harvester.JupyterAccessesHarvester;
|
||||
import org.gcube.dataharvest.utils.AggregationType;
|
||||
import org.gcube.dataharvest.utils.ContextAuthorization;
|
||||
import org.gcube.dataharvest.utils.ContextTest;
|
||||
import org.gcube.dataharvest.utils.DateUtils;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Giancarlo Panichi (ISTI CNR)
|
||||
*
|
||||
*/
|
||||
public class AccountingDataHarvesterJupyterTest extends ContextTest {
|
||||
|
||||
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
|
||||
@Test
|
||||
public void testJupyterAccessesHarvester() throws Exception {
|
||||
try {
|
||||
|
||||
ContextTest.setContextByName(ROOT);
|
||||
AccountingDao dao = getAccountingDao();
|
||||
|
||||
List<Date> starts = new ArrayList<>();
|
||||
starts.add(DateUtils.getStartCalendar(2021, Calendar.JANUARY, 1).getTime());
|
||||
starts.add(DateUtils.getStartCalendar(2021, Calendar.FEBRUARY, 1).getTime());
|
||||
starts.add(DateUtils.getStartCalendar(2021, Calendar.MARCH, 1).getTime());
|
||||
starts.add(DateUtils.getStartCalendar(2021, Calendar.APRIL, 1).getTime());
|
||||
starts.add(DateUtils.getStartCalendar(2021, Calendar.MAY, 1).getTime());
|
||||
|
||||
AggregationType measureType = AggregationType.MONTHLY;
|
||||
|
||||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
||||
|
||||
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<>();
|
||||
|
||||
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) {
|
||||
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
|
||||
|
||||
ContextTest.setContextByName(ROOT);
|
||||
JupyterAccessesHarvester jupyterAccessesHarvester = new JupyterAccessesHarvester(start, end);
|
||||
|
||||
for(String context : contexts) {
|
||||
ContextTest.setContext(contextAuthorization.getTokenForContext(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();
|
||||
accountingRecords.addAll(harvested);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// logger.debug("{}", accountingRecords);
|
||||
|
||||
logger.debug("Going to insert {}", accountingRecords);
|
||||
|
||||
ContextTest.setContextByName(ROOT);
|
||||
dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -41,6 +41,7 @@ import org.gcube.vremanagement.executor.api.types.Scheduling;
|
|||
import org.gcube.vremanagement.executor.client.SmartExecutorClient;
|
||||
import org.gcube.vremanagement.executor.client.SmartExecutorClientFactory;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.quartz.CronExpression;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -58,19 +59,20 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
public static SortedSet<String> getContexts() throws Exception {
|
||||
SortedSet<String> contexts = new TreeSet<>();
|
||||
LinkedHashMap<String,ScopeBean> map = ContextManager.readContexts();
|
||||
for(String scope : map.keySet()) {
|
||||
LinkedHashMap<String, ScopeBean> map = ContextManager.readContexts();
|
||||
for (String scope : map.keySet()) {
|
||||
try {
|
||||
String context = map.get(scope).toString();
|
||||
contexts.add(context);
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return contexts;
|
||||
}
|
||||
|
||||
// @Test
|
||||
@Ignore
|
||||
@Test
|
||||
public void getDimensions() {
|
||||
try {
|
||||
|
||||
|
@ -79,17 +81,18 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
AccountingDao dao = AccountingDao.get();
|
||||
|
||||
Set<Dimension> dimensionSet = dao.getDimensions();
|
||||
for(Dimension d : dimensionSet) {
|
||||
for (Dimension d : dimensionSet) {
|
||||
logger.debug("{} - {} - {} - {}", d.getId(), d.getGroup(), d.getAggregatedMeasure(), d.getLabel());
|
||||
}
|
||||
|
||||
logger.info("End.");
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
|
||||
//@Ignore
|
||||
@Test
|
||||
public void launch() {
|
||||
try {
|
||||
|
@ -98,33 +101,32 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
AccountingDashboardHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDashboardHarvesterPlugin();
|
||||
|
||||
Map<String,Object> inputs = new HashMap<>();
|
||||
Map<String, Object> inputs = new HashMap<>();
|
||||
|
||||
AggregationType aggregationType = AggregationType.MONTHLY;
|
||||
|
||||
inputs.put(AccountingDashboardHarvesterPlugin.MEASURE_TYPE_INPUT_PARAMETER, aggregationType.name());
|
||||
inputs.put(AccountingDashboardHarvesterPlugin.GET_VRE_USERS_INPUT_PARAMETER, true);
|
||||
inputs.put(AccountingDashboardHarvesterPlugin.RERUN_INPUT_PARAMETER, true);
|
||||
inputs.put(AccountingDashboardHarvesterPlugin.DRY_RUN_INPUT_PARAMETER, false);
|
||||
inputs.put(AccountingDashboardHarvesterPlugin.PARTIAL_HARVESTING, false);
|
||||
inputs.put(AccountingDashboardHarvesterPlugin.DRY_RUN_INPUT_PARAMETER, true);
|
||||
inputs.put(AccountingDashboardHarvesterPlugin.PARTIAL_HARVESTING, true);
|
||||
|
||||
/*
|
||||
Calendar from = DateUtils.getStartCalendar(2020, Calendar.MAY, 1);
|
||||
Calendar from = DateUtils.getStartCalendar(2021, Calendar.JANUARY, 1);
|
||||
String fromDate = DateUtils.LAUNCH_DATE_FORMAT.format(from.getTime());
|
||||
logger.trace("{} is {}", AccountingDashboardHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
|
||||
inputs.put(AccountingDashboardHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
|
||||
*/
|
||||
|
||||
accountingDataHarvesterPlugin.launch(inputs);
|
||||
|
||||
logger.info("End.");
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
|
||||
// @Test
|
||||
@Ignore
|
||||
@Test
|
||||
public void launchPluginOnSmartExecutor() {
|
||||
try {
|
||||
|
||||
|
@ -135,7 +137,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
SmartExecutorClient smartExecutor = SmartExecutorClientFactory.getClient(pluginName);
|
||||
Assert.assertNotNull(smartExecutor);
|
||||
|
||||
Map<String,Object> inputs = new HashMap<>();
|
||||
Map<String, Object> inputs = new HashMap<>();
|
||||
|
||||
AggregationType aggregationType = AggregationType.MONTHLY;
|
||||
|
||||
|
@ -146,14 +148,17 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
inputs.put(AccountingDashboardHarvesterPlugin.PARTIAL_HARVESTING, false);
|
||||
|
||||
/*
|
||||
Calendar from = DateUtils.getStartCalendar(2016, Calendar.SEPTEMBER, 1);
|
||||
String fromDate = DateUtils.LAUNCH_DATE_FORMAT.format(from.getTime());
|
||||
logger.trace("{} is {}", AccountingDataHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
|
||||
inputs.put(AccountingDataHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
|
||||
* Calendar from = DateUtils.getStartCalendar(2016, Calendar.SEPTEMBER, 1);
|
||||
* String fromDate = DateUtils.LAUNCH_DATE_FORMAT.format(from.getTime());
|
||||
* logger.trace("{} is {}",
|
||||
* AccountingDataHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
|
||||
* inputs.put(AccountingDataHarvesterPlugin. START_DATE_INPUT_PARAMETER,
|
||||
* fromDate);
|
||||
*/
|
||||
|
||||
// 3rd of the month for MONTHLY Harvesting at 10:00
|
||||
// CronExpression cronExpression = new CronExpression("0 0 10 3 1/1 ? *");
|
||||
// CronExpression cronExpression = new CronExpression("0 0 10 3 1/1
|
||||
// ? *");
|
||||
|
||||
// Every day at 10:00 for partial harvesting
|
||||
CronExpression cronExpression = new CronExpression("0 0 10 3 1/1 ? *");
|
||||
|
@ -161,18 +166,20 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
Scheduling scheduling = new Scheduling(cronExpression);
|
||||
scheduling.setGlobal(false);
|
||||
LaunchParameter launchParameter = new LaunchParameter(pluginName, inputs, scheduling);
|
||||
//LaunchParameter launchParameter = new LaunchParameter(pluginName, inputs);
|
||||
// LaunchParameter launchParameter = new LaunchParameter(pluginName,
|
||||
// inputs);
|
||||
|
||||
smartExecutor.launch(launchParameter);
|
||||
|
||||
logger.info("End.");
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
|
||||
// @Test
|
||||
//@Ignore
|
||||
@Test
|
||||
public void launchOldData() {
|
||||
try {
|
||||
|
||||
|
@ -180,7 +187,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
AccountingDashboardHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDashboardHarvesterPlugin();
|
||||
|
||||
Map<String,Object> inputs = new HashMap<>();
|
||||
Map<String, Object> inputs = new HashMap<>();
|
||||
|
||||
AggregationType aggregationType = AggregationType.MONTHLY;
|
||||
|
||||
|
@ -193,7 +200,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
Calendar runbeforeDate = DateUtils.getStartCalendar(2018, Calendar.JUNE, 1);
|
||||
|
||||
while(from.before(runbeforeDate)) {
|
||||
while (from.before(runbeforeDate)) {
|
||||
String fromDate = DateUtils.LAUNCH_DATE_FORMAT.format(from.getTime());
|
||||
logger.trace("{} is {}", AccountingDashboardHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
|
||||
inputs.put(AccountingDashboardHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
|
||||
|
@ -203,11 +210,12 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
logger.info("End.");
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
// @Test
|
||||
public void launchOldDataVREAccessesHarvester() {
|
||||
try {
|
||||
|
@ -228,7 +236,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
Calendar runbeforeDate = DateUtils.getStartCalendar(2018, Calendar.JUNE, 1);
|
||||
|
||||
while(from.before(runbeforeDate)) {
|
||||
while (from.before(runbeforeDate)) {
|
||||
Date start = from.getTime();
|
||||
Date end = DateUtils.getEndDateFromStartDate(aggregationType, start, 1, false);
|
||||
|
||||
|
@ -238,21 +246,22 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
VREAccessesHarvester vreAccessesHarvester = null;
|
||||
|
||||
for(String context : contexts) {
|
||||
for (String context : contexts) {
|
||||
// Setting the token for the context
|
||||
ContextTest.setContext(contextAuthorization.getTokenForContext(context));
|
||||
|
||||
ScopeBean scopeBean = new ScopeBean(context);
|
||||
|
||||
if(vreAccessesHarvester == null) {
|
||||
if (vreAccessesHarvester == null) {
|
||||
|
||||
if(scopeBean.is(Type.INFRASTRUCTURE)) {
|
||||
if (scopeBean.is(Type.INFRASTRUCTURE)) {
|
||||
vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
||||
} else {
|
||||
// This code should be never used because the scopes are sorted by fullname
|
||||
// This code should be never used because the scopes
|
||||
// are sorted by fullname
|
||||
|
||||
ScopeBean parent = scopeBean.enclosingScope();
|
||||
while(!parent.is(Type.INFRASTRUCTURE)) {
|
||||
while (!parent.is(Type.INFRASTRUCTURE)) {
|
||||
parent = scopeBean.enclosingScope();
|
||||
}
|
||||
|
||||
|
@ -268,17 +277,18 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
}
|
||||
|
||||
try {
|
||||
if(context.startsWith(AccountingDashboardHarvesterPlugin.SO_BIG_DATA_VO)
|
||||
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
|
||||
// Collecting Google Analytics Data for VREs
|
||||
// Accesses
|
||||
List<AccountingRecord> harvested = vreAccessesHarvester.getAccountingRecords();
|
||||
accountingRecords.addAll(harvested);
|
||||
|
||||
}
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("Error harvesting Social Interactions for {}", context, e);
|
||||
}
|
||||
}
|
||||
|
@ -287,7 +297,8 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
accountingRecords);
|
||||
ContextTest.setContextByName(ROOT);
|
||||
|
||||
// dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
||||
// dao.insertRecords(accountingRecords.toArray(new
|
||||
// AccountingRecord[1]));
|
||||
|
||||
Thread.sleep(TimeUnit.SECONDS.toMillis(10));
|
||||
|
||||
|
@ -297,7 +308,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
ContextTest.setContextByName(ROOT);
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
|
||||
|
@ -305,6 +316,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
}
|
||||
|
||||
@Ignore
|
||||
// @Test
|
||||
public void testScopeBean() throws Exception {
|
||||
ContextTest.setContextByName(ROOT);
|
||||
|
@ -318,13 +330,15 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
logger.info("\n\n\n");
|
||||
|
||||
for(String context : contexts) {
|
||||
for (String context : contexts) {
|
||||
ScopeBean scopeBean = new ScopeBean(context);
|
||||
// logger.debug("FullName {} - Name {}", scopeBean.toString(), scopeBean.name());
|
||||
// logger.debug("FullName {} - Name {}", scopeBean.toString(),
|
||||
// scopeBean.name());
|
||||
|
||||
try {
|
||||
|
||||
if(scopeBean.is(Type.VRE) && start.equals(DateUtils.getPreviousPeriod(aggregationType, false).getTime())) {
|
||||
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 {
|
||||
|
@ -332,7 +346,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
DateUtils.format(end));
|
||||
}
|
||||
|
||||
if((context.startsWith(AccountingDashboardHarvesterPlugin.SO_BIG_DATA_VO)
|
||||
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())) {
|
||||
|
@ -343,7 +357,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
DateUtils.format(end));
|
||||
}
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("Error harvesting Social Interactions for {}", context, e);
|
||||
}
|
||||
|
||||
|
@ -351,7 +365,8 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
}
|
||||
|
||||
// @Test
|
||||
@Ignore
|
||||
@Test
|
||||
public void testVREAccessesHarvester() throws Exception {
|
||||
try {
|
||||
// AccountingDao dao = getAccountingDao();
|
||||
|
@ -367,18 +382,18 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
AggregationType measureType = AggregationType.MONTHLY;
|
||||
|
||||
String[] contextFullNames = new String[] {"/d4science.research-infrastructures.eu/FARM/GRSF",
|
||||
"/d4science.research-infrastructures.eu/FARM/GRSF_Admin"};
|
||||
String[] contextFullNames = new String[] { "/d4science.research-infrastructures.eu/FARM/GRSF",
|
||||
"/d4science.research-infrastructures.eu/FARM/GRSF_Admin" };
|
||||
|
||||
List<AccountingRecord> accountingRecords = new ArrayList<>();
|
||||
|
||||
for(Date start : starts) {
|
||||
for (Date start : starts) {
|
||||
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
|
||||
|
||||
ContextTest.setContextByName(ROOT);
|
||||
VREAccessesHarvester vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
||||
|
||||
for(String contextFullname : contextFullNames) {
|
||||
for (String contextFullname : contextFullNames) {
|
||||
|
||||
setContextByNameAndScopeDescriptor(contextFullname);
|
||||
|
||||
|
@ -393,14 +408,16 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
logger.debug("{}", accountingRecords);
|
||||
|
||||
ContextTest.setContextByName(ROOT);
|
||||
// dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
||||
// dao.insertRecords(accountingRecords.toArray(new
|
||||
// AccountingRecord[1]));
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
// @Test
|
||||
public void testVREAccessesHarvesterAll() {
|
||||
try {
|
||||
|
@ -409,8 +426,10 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
AggregationType measureType = AggregationType.MONTHLY;
|
||||
|
||||
// Date start = DateUtils.getStartCalendar(2015, Calendar.FEBRUARY, 1).getTime();
|
||||
// Date end = DateUtils.getStartCalendar(2019, Calendar.FEBRUARY, 1).getTime();
|
||||
// Date start = DateUtils.getStartCalendar(2015, Calendar.FEBRUARY,
|
||||
// 1).getTime();
|
||||
// Date end = DateUtils.getStartCalendar(2019, Calendar.FEBRUARY,
|
||||
// 1).getTime();
|
||||
|
||||
Date start = DateUtils.getPreviousPeriod(measureType, false).getTime();
|
||||
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
|
||||
|
@ -425,21 +444,22 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
ArrayList<AccountingRecord> accountingRecords = new ArrayList<>();
|
||||
|
||||
for(String context : contexts) {
|
||||
for (String context : contexts) {
|
||||
// Setting the token for the context
|
||||
ContextTest.setContext(contextAuthorization.getTokenForContext(context));
|
||||
|
||||
ScopeBean scopeBean = new ScopeBean(context);
|
||||
|
||||
if(vreAccessesHarvester == null) {
|
||||
if (vreAccessesHarvester == null) {
|
||||
|
||||
if(scopeBean.is(Type.INFRASTRUCTURE)) {
|
||||
if (scopeBean.is(Type.INFRASTRUCTURE)) {
|
||||
vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
||||
} else {
|
||||
// This code should be never used because the scopes are sorted by fullname
|
||||
// This code should be never used because the scopes are
|
||||
// sorted by fullname
|
||||
|
||||
ScopeBean parent = scopeBean.enclosingScope();
|
||||
while(!parent.is(Type.INFRASTRUCTURE)) {
|
||||
while (!parent.is(Type.INFRASTRUCTURE)) {
|
||||
parent = scopeBean.enclosingScope();
|
||||
}
|
||||
|
||||
|
@ -455,7 +475,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
}
|
||||
|
||||
try {
|
||||
if(context.startsWith(AccountingDashboardHarvesterPlugin.SO_BIG_DATA_VO)
|
||||
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));
|
||||
|
@ -464,18 +484,19 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
List<AccountingRecord> harvested = vreAccessesHarvester.getAccountingRecords();
|
||||
accountingRecords.addAll(harvested);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("Error harvesting Social Interactions for {}", context, e);
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("{}", accountingRecords);
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
// @Test
|
||||
public void testSocialInteraction() {
|
||||
try {
|
||||
|
@ -507,7 +528,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
ArrayList<AccountingRecord> accountingRecords = new ArrayList<>();
|
||||
|
||||
for(String context : contexts) {
|
||||
for (String context : contexts) {
|
||||
// Setting the token for the context
|
||||
ContextTest.setContext(contextAuthorization.getTokenForContext(context));
|
||||
try {
|
||||
|
@ -516,7 +537,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
SocialInteractionsHarvester socialHarvester = new SocialInteractionsHarvester(start, end);
|
||||
List<AccountingRecord> harvested = socialHarvester.getAccountingRecords();
|
||||
accountingRecords.addAll(harvested);
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("Error harvesting Social Interactions for {}", context, e);
|
||||
}
|
||||
}
|
||||
|
@ -524,9 +545,10 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
logger.debug("Harvest Measures from {} to {} are {}", DateUtils.format(start), DateUtils.format(end),
|
||||
accountingRecords);
|
||||
ContextTest.setContextByName(ROOT);
|
||||
// dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
||||
// dao.insertRecords(accountingRecords.toArray(new
|
||||
// AccountingRecord[1]));
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
|
||||
|
@ -534,6 +556,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
}
|
||||
|
||||
@Ignore
|
||||
// @Test
|
||||
public void testMethodInvocation() {
|
||||
try {
|
||||
|
@ -554,7 +577,52 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
logger.debug("{}", accountingRecords);
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodInvocationOldData() {
|
||||
try {
|
||||
|
||||
ContextTest.setContextByName(ROOT);
|
||||
AccountingDao dao = getAccountingDao();
|
||||
|
||||
List<Date> starts = new ArrayList<>();
|
||||
starts.add(DateUtils.getStartCalendar(2021, Calendar.APRIL, 1).getTime());
|
||||
|
||||
AggregationType measureType = AggregationType.MONTHLY;
|
||||
|
||||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
||||
SortedSet<String> contexts = contextAuthorization.getContexts();
|
||||
|
||||
List<AccountingRecord> accountingRecords = new ArrayList<>();
|
||||
|
||||
for (Date start : starts) {
|
||||
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
|
||||
|
||||
MethodInvocationHarvester methodInvocationHarvester = new MethodInvocationHarvester(start, end);
|
||||
|
||||
for (String context : contexts) {
|
||||
// Setting the token for the context
|
||||
ContextTest.setContext(contextAuthorization.getTokenForContext(context));
|
||||
|
||||
|
||||
List<AccountingRecord> harvested = methodInvocationHarvester.getAccountingRecords();
|
||||
accountingRecords.addAll(harvested);
|
||||
|
||||
logger.debug("{} - {}", context, harvested);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Going to insert {}", accountingRecords);
|
||||
|
||||
ContextTest.setContextByName(ROOT);
|
||||
dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
|
@ -563,15 +631,15 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
AccountingDao dao = AccountingDao.get();
|
||||
|
||||
Set<ScopeDescriptor> scopeDescriptorSet = dao.getContexts();
|
||||
Map<String,ScopeDescriptor> scopeDescriptorMap = new HashMap<>();
|
||||
for(ScopeDescriptor scopeDescriptor : scopeDescriptorSet) {
|
||||
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) {
|
||||
Map<String, Dimension> dimensionMap = new HashMap<>();
|
||||
for (Dimension dimension : dimensionSet) {
|
||||
dimensionMap.put(dimension.getId(), dimension);
|
||||
}
|
||||
|
||||
|
@ -589,13 +657,14 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
ScopeBean scopeBean = new ScopeBean(contextFullName);
|
||||
ScopeDescriptor actualScopeDescriptor = AccountingDashboardHarvesterPlugin.scopeDescriptors.get()
|
||||
.get(contextFullName);
|
||||
if(actualScopeDescriptor == null) {
|
||||
if (actualScopeDescriptor == null) {
|
||||
actualScopeDescriptor = new ScopeDescriptor(scopeBean.name(), contextFullName);
|
||||
}
|
||||
|
||||
AccountingDashboardHarvesterPlugin.scopeDescriptor.set(actualScopeDescriptor);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
// @Test
|
||||
public void testTagMeMethodInvocation() throws Exception {
|
||||
try {
|
||||
|
@ -613,7 +682,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
starts.add(DateUtils.getStartCalendar(2019, Calendar.FEBRUARY, 1).getTime());
|
||||
starts.add(DateUtils.getStartCalendar(2019, Calendar.MARCH, 1).getTime());
|
||||
|
||||
for(Date start : starts) {
|
||||
for (Date start : starts) {
|
||||
|
||||
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
|
||||
|
||||
|
@ -625,14 +694,16 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
}
|
||||
|
||||
ContextTest.setContextByName(ROOT);
|
||||
// dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
||||
// dao.insertRecords(accountingRecords.toArray(new
|
||||
// AccountingRecord[1]));
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
// @Test
|
||||
public void testGetVREUsersForSpecificVRE() {
|
||||
try {
|
||||
|
@ -659,19 +730,21 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
logger.info("Harvested Data from {} to {} : {}", DateUtils.format(start), DateUtils.format(end), harvested);
|
||||
|
||||
ContextTest.setContextByName(ROOT);
|
||||
// dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
||||
// dao.insertRecords(accountingRecords.toArray(new
|
||||
// AccountingRecord[1]));
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Ignore
|
||||
// @Test
|
||||
public void testFilteringGenericResource() {
|
||||
try {
|
||||
ContextTest.setContextByName(ROOT);
|
||||
//Utils.setContext(RESOURCE_CATALOGUE);
|
||||
// Utils.setContext(RESOURCE_CATALOGUE);
|
||||
|
||||
AggregationType measureType = AggregationType.MONTHLY;
|
||||
|
||||
|
@ -688,23 +761,26 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
SortedSet<String> validContexts = resourceCatalogueHarvester.getValidContexts(contexts, SO_BIG_VO + "/");
|
||||
logger.info("Valid Contexts {}", validContexts);
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Ignore
|
||||
// @Test
|
||||
public void testResourceCatalogueHarvester() {
|
||||
try {
|
||||
|
||||
//Utils.setContext(RESOURCE_CATALOGUE);
|
||||
// Utils.setContext(RESOURCE_CATALOGUE);
|
||||
ContextTest.setContextByName(ROOT);
|
||||
|
||||
AggregationType measureType = AggregationType.MONTHLY;
|
||||
|
||||
// Date start = DateUtils.getStartCalendar(2015, Calendar.FEBRUARY, 1).getTime();
|
||||
// Date end = DateUtils.getStartCalendar(2019, Calendar.FEBRUARY, 1).getTime();
|
||||
// Date start = DateUtils.getStartCalendar(2015, Calendar.FEBRUARY,
|
||||
// 1).getTime();
|
||||
// Date end = DateUtils.getStartCalendar(2019, Calendar.FEBRUARY,
|
||||
// 1).getTime();
|
||||
|
||||
Date start = DateUtils.getPreviousPeriod(measureType, false).getTime();
|
||||
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
|
||||
|
@ -720,16 +796,17 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
logger.debug("{}", data);
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testCoreServicesHarvester() {
|
||||
try {
|
||||
|
||||
String context = ROOT; //"/gcube";
|
||||
String context = ROOT; // "/gcube";
|
||||
ContextTest.setContextByName(context);
|
||||
|
||||
AccountingDao dao = getAccountingDao();
|
||||
|
@ -742,7 +819,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
ScopeBean scopeBean = new ScopeBean(context);
|
||||
logger.debug("FullName {} - Name {}", scopeBean.toString(), scopeBean.name());
|
||||
|
||||
while(end.before(finalEnd)) {
|
||||
while (end.before(finalEnd)) {
|
||||
CoreServicesAccessesHarvester coreServicesHarvester = new CoreServicesAccessesHarvester(start, end);
|
||||
List<AccountingRecord> accountingRecords = coreServicesHarvester.getAccountingRecords();
|
||||
dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
||||
|
@ -755,18 +832,17 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
end = DateUtils.getEndDateFromStartDate(AggregationType.MONTHLY, start, 1, false);
|
||||
}
|
||||
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testCatalogueHarvester() {
|
||||
try {
|
||||
|
||||
String context = ROOT; //"/gcube";
|
||||
String context = ROOT; // "/gcube";
|
||||
ContextTest.setContextByName(context);
|
||||
|
||||
AccountingDao dao = getAccountingDao();
|
||||
|
@ -775,8 +851,8 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
Date end = DateUtils.getStartCalendar(2020, Calendar.FEBRUARY, 1).getTime();
|
||||
|
||||
/*
|
||||
* Date start = DateUtils.getPreviousPeriod(measureType, false).getTime();
|
||||
* Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
|
||||
* Date start = DateUtils.getPreviousPeriod(measureType, false).getTime(); Date
|
||||
* end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
|
||||
*/
|
||||
|
||||
ScopeBean scopeBean = new ScopeBean(context);
|
||||
|
@ -791,23 +867,25 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Ignore
|
||||
// @Test
|
||||
public void testDataMethodDownloadHarvester() {
|
||||
try {
|
||||
|
||||
//Utils.setContext(RESOURCE_CATALOGUE);
|
||||
// Utils.setContext(RESOURCE_CATALOGUE);
|
||||
ContextTest.setContextByName(ROOT);
|
||||
|
||||
AggregationType measureType = AggregationType.MONTHLY;
|
||||
|
||||
// Date start = DateUtils.getStartCalendar(2015, Calendar.FEBRUARY, 1).getTime();
|
||||
// Date end = DateUtils.getStartCalendar(2019, Calendar.FEBRUARY, 1).getTime();
|
||||
// Date start = DateUtils.getStartCalendar(2015, Calendar.FEBRUARY,
|
||||
// 1).getTime();
|
||||
// Date end = DateUtils.getStartCalendar(2019, Calendar.FEBRUARY,
|
||||
// 1).getTime();
|
||||
|
||||
Date start = DateUtils.getPreviousPeriod(measureType, false).getTime();
|
||||
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
|
||||
|
@ -818,13 +896,13 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
||||
SortedSet<String> contexts = contextAuthorization.getContexts();
|
||||
|
||||
for(String context : contexts) {
|
||||
for (String context : contexts) {
|
||||
ScopeBean scopeBean = new ScopeBean(context);
|
||||
logger.debug("FullName {} - Name {}", scopeBean.toString(), scopeBean.name());
|
||||
|
||||
if(context.startsWith(AccountingDashboardHarvesterPlugin.SO_BIG_DATA_VO)) {
|
||||
if(scopeBean.is(Type.VRE)) {
|
||||
if(context.startsWith(TAGME_VRE)) {
|
||||
if (context.startsWith(AccountingDashboardHarvesterPlugin.SO_BIG_DATA_VO)) {
|
||||
if (scopeBean.is(Type.VRE)) {
|
||||
if (context.startsWith(TAGME_VRE)) {
|
||||
continue;
|
||||
}
|
||||
ContextTest.setContext(contextAuthorization.getTokenForContext(context));
|
||||
|
@ -837,13 +915,14 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
}
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static final String E_LEARNING_AREA_VRE = "/d4science.research-infrastructures.eu/SoBigData/E-Learning_Area";
|
||||
|
||||
@Ignore
|
||||
// @Test
|
||||
public void addMissingVREAccesses() {
|
||||
try {
|
||||
|
@ -860,15 +939,15 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
AccountingDao dao = AccountingDao.get();
|
||||
|
||||
Set<ScopeDescriptor> scopeDescriptorSet = dao.getContexts();
|
||||
Map<String,ScopeDescriptor> scopeDescriptorMap = new HashMap<>();
|
||||
for(ScopeDescriptor scopeDescriptor : scopeDescriptorSet) {
|
||||
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) {
|
||||
Map<String, Dimension> dimensionMap = new HashMap<>();
|
||||
for (Dimension dimension : dimensionSet) {
|
||||
dimensionMap.put(dimension.getId(), dimension);
|
||||
}
|
||||
|
||||
|
@ -890,13 +969,13 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
Calendar calendar = DateUtils.getStartCalendar(2018, Calendar.JULY, 1);
|
||||
calendar.set(Calendar.DAY_OF_MONTH, 15);
|
||||
|
||||
Map<Integer,Integer> monthValues = new HashMap<>();
|
||||
Map<Integer, Integer> monthValues = new HashMap<>();
|
||||
monthValues.put(Calendar.JULY, 54);
|
||||
monthValues.put(Calendar.AUGUST, 23);
|
||||
monthValues.put(Calendar.SEPTEMBER, 127);
|
||||
monthValues.put(Calendar.OCTOBER, 192);
|
||||
|
||||
for(Integer month : monthValues.keySet()) {
|
||||
for (Integer month : monthValues.keySet()) {
|
||||
calendar.set(Calendar.MONTH, month);
|
||||
Instant instant = calendar.toInstant();
|
||||
|
||||
|
@ -909,7 +988,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
logger.trace("{}", accountingRecords);
|
||||
dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.dataharvest.harvester.sobigdata;
|
|||
import java.util.List;
|
||||
|
||||
import org.gcube.dataharvest.utils.ContextTest;
|
||||
import org.junit.Ignore;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -10,6 +11,7 @@ public class SoBigDataHarvesterTest extends ContextTest {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(SoBigDataHarvesterTest.class);
|
||||
|
||||
@Ignore
|
||||
// @Test
|
||||
public void testGroupList() throws Exception {
|
||||
// ContextTest.setContextByName("/d4science.research-infrastructures.eu/D4Research/AGINFRAplusDev");
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.io.InputStream;
|
|||
import java.util.Properties;
|
||||
|
||||
import org.gcube.dataharvest.AccountingDashboardHarvesterPlugin;
|
||||
import org.junit.Ignore;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -26,6 +27,7 @@ public class ContextAuthorizationTest extends ContextTest {
|
|||
AccountingDashboardHarvesterPlugin.getProperties().set(properties);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
// @Test
|
||||
public void testRetrieveContextsAndTokens() throws Exception {
|
||||
try {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/*.gcubekey
|
||||
/*.key
|
||||
/*.properties
|
||||
/howto.txt
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
groupId=org.gcube.accounting
|
||||
artifactId=accounting-dashboard-harvester-se-plugin
|
||||
version=2.0.0-SNAPSHOT
|
||||
description=Accounting Dashboard Harvester Smart Executor Plugin.
|
Loading…
Reference in New Issue