2018-05-11 17:50:37 +02:00
|
|
|
package org.gcube.dataharvest;
|
|
|
|
|
2018-05-17 12:52:17 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
2018-05-18 12:00:10 +02:00
|
|
|
import java.util.ArrayList;
|
2018-06-14 16:19:25 +02:00
|
|
|
import java.util.Calendar;
|
2018-05-16 15:08:25 +02:00
|
|
|
import java.util.Date;
|
2018-09-04 11:13:16 +02:00
|
|
|
import java.util.HashMap;
|
2018-05-11 17:50:37 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2018-05-17 12:52:17 +02:00
|
|
|
import java.util.Properties;
|
2018-09-04 11:13:16 +02:00
|
|
|
import java.util.Set;
|
2018-05-18 12:00:10 +02:00
|
|
|
import java.util.SortedSet;
|
2018-05-11 17:50:37 +02:00
|
|
|
|
2018-09-04 11:13:16 +02:00
|
|
|
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;
|
2018-05-29 11:08:24 +02:00
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
2018-06-13 19:39:01 +02:00
|
|
|
import org.gcube.common.scope.impl.ScopeBean;
|
|
|
|
import org.gcube.common.scope.impl.ScopeBean.Type;
|
2018-06-14 14:50:42 +02:00
|
|
|
import org.gcube.dataharvest.harvester.MethodInvocationHarvester;
|
|
|
|
import org.gcube.dataharvest.harvester.SocialInteractionsHarvester;
|
2018-06-14 14:34:11 +02:00
|
|
|
import org.gcube.dataharvest.harvester.VREAccessesHarvester;
|
2018-06-14 14:50:42 +02:00
|
|
|
import org.gcube.dataharvest.harvester.VREUsersHarvester;
|
|
|
|
import org.gcube.dataharvest.harvester.sobigdata.DataMethodDownloadHarvester;
|
|
|
|
import org.gcube.dataharvest.harvester.sobigdata.ResourceCatalogueHarvester;
|
|
|
|
import org.gcube.dataharvest.harvester.sobigdata.TagMeMethodInvocationHarvester;
|
2018-09-04 11:13:16 +02:00
|
|
|
import org.gcube.dataharvest.utils.AggregationType;
|
2018-05-17 12:52:17 +02:00
|
|
|
import org.gcube.dataharvest.utils.ContextAuthorization;
|
2018-05-17 16:04:22 +02:00
|
|
|
import org.gcube.dataharvest.utils.DateUtils;
|
2018-05-18 12:00:10 +02:00
|
|
|
import org.gcube.dataharvest.utils.Utils;
|
2018-05-16 15:08:25 +02:00
|
|
|
import org.gcube.vremanagement.executor.plugin.Plugin;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2018-05-11 17:50:37 +02:00
|
|
|
|
2018-05-18 14:17:54 +02:00
|
|
|
/**
|
|
|
|
* @author Eric Perrone (ISTI - CNR)
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*/
|
2018-05-11 17:50:37 +02:00
|
|
|
public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDeclaration> {
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-11 17:50:37 +02:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(AccountingDataHarvesterPlugin.class);
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-17 12:52:17 +02:00
|
|
|
private static final String PROPERTY_FILENAME = "config.properties";
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-17 16:04:22 +02:00
|
|
|
public static final String START_DATE_INPUT_PARAMETER = "startDate";
|
|
|
|
public static final String MEASURE_TYPE_INPUT_PARAMETER = "measureType";
|
|
|
|
public static final String RERUN_INPUT_PARAMETER = "reRun";
|
2018-06-04 16:35:32 +02:00
|
|
|
public static final String GET_VRE_USERS_INPUT_PARAMETER = "getVREUsers";
|
2018-05-17 16:04:22 +02:00
|
|
|
public static final String DRY_RUN_INPUT_PARAMETER = "dryRun";
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-06-14 16:19:25 +02:00
|
|
|
public static final String SO_BIG_DATA_VO = "/d4science.research-infrastructures.eu/SoBigData";
|
2018-06-14 16:22:19 +02:00
|
|
|
public static final String SO_BIG_DATA_EU_VRE = "/d4science.research-infrastructures.eu/gCubeApps/SoBigData.eu";
|
|
|
|
public static final String SO_BIG_DATA_IT_VRE = "/d4science.research-infrastructures.eu/gCubeApps/SoBigData.it";
|
2018-05-28 12:00:15 +02:00
|
|
|
public static final String SO_BIG_DATA_CATALOGUE_CONTEXT = "/d4science.research-infrastructures.eu/SoBigData/ResourceCatalogue";
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-18 16:36:05 +02:00
|
|
|
public static final String TAGME_CONTEXT = "/d4science.research-infrastructures.eu/SoBigData/TagMe";
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-09-04 11:13:16 +02:00
|
|
|
public static final String TO_BE_SET = "TO BE SET";
|
|
|
|
|
2018-05-17 16:04:22 +02:00
|
|
|
protected Date start;
|
|
|
|
protected Date end;
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-18 12:00:10 +02:00
|
|
|
public AccountingDataHarvesterPlugin(DataHarvestPluginDeclaration pluginDeclaration) {
|
|
|
|
super(pluginDeclaration);
|
|
|
|
}
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-17 16:04:22 +02:00
|
|
|
private static final InheritableThreadLocal<Properties> properties = new InheritableThreadLocal<Properties>() {
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-17 16:04:22 +02:00
|
|
|
@Override
|
|
|
|
protected Properties initialValue() {
|
|
|
|
return new Properties();
|
|
|
|
}
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-17 16:04:22 +02:00
|
|
|
};
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-09-04 11:13:16 +02:00
|
|
|
|
2018-05-17 16:04:22 +02:00
|
|
|
public static InheritableThreadLocal<Properties> getProperties() {
|
|
|
|
return properties;
|
|
|
|
}
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-09-04 11:13:16 +02:00
|
|
|
public static Dimension getDimension(String key) {
|
|
|
|
Dimension dimension = dimensions.get().get(key);
|
|
|
|
if(dimension == null) {
|
|
|
|
dimension = new Dimension(key, key, null, key);
|
|
|
|
}
|
|
|
|
return dimension;
|
|
|
|
}
|
|
|
|
|
2018-11-12 16:30:20 +01:00
|
|
|
protected static final InheritableThreadLocal<Map<String, Dimension>> dimensions = new InheritableThreadLocal<Map<String, Dimension>>() {
|
2018-09-04 11:13:16 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Map<String, Dimension> initialValue() {
|
|
|
|
return new HashMap<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
public static ScopeDescriptor getScopeDescriptor(String context) {
|
|
|
|
return scopeDescriptors.get().get(context);
|
|
|
|
}
|
|
|
|
|
2018-11-12 16:30:20 +01:00
|
|
|
protected static final InheritableThreadLocal<Map<String, ScopeDescriptor>> scopeDescriptors = new InheritableThreadLocal<Map<String, ScopeDescriptor>>() {
|
2018-09-04 11:13:16 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Map<String, ScopeDescriptor> initialValue() {
|
|
|
|
return new HashMap<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
public static ScopeDescriptor getScopeDescriptor() {
|
|
|
|
return scopeDescriptor.get();
|
|
|
|
}
|
|
|
|
|
2019-05-03 14:22:11 +02:00
|
|
|
public static final InheritableThreadLocal<ScopeDescriptor> scopeDescriptor = new InheritableThreadLocal<ScopeDescriptor>() {
|
2018-09-04 11:13:16 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected ScopeDescriptor initialValue() {
|
|
|
|
return new ScopeDescriptor("","");
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-29 13:05:55 +02:00
|
|
|
public Properties getConfigParameters() throws IOException {
|
|
|
|
Properties properties = new Properties();
|
2018-05-17 16:04:22 +02:00
|
|
|
try {
|
|
|
|
InputStream input = AccountingDataHarvesterPlugin.class.getClassLoader()
|
|
|
|
.getResourceAsStream(PROPERTY_FILENAME);
|
|
|
|
properties.load(input);
|
2018-05-29 13:05:55 +02:00
|
|
|
return properties;
|
2018-05-17 16:04:22 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
logger.warn(
|
|
|
|
"Unable to load {} file containing configuration properties. AccountingDataHarvesterPlugin will use defaults",
|
|
|
|
PROPERTY_FILENAME);
|
|
|
|
}
|
2018-05-29 13:05:55 +02:00
|
|
|
return properties;
|
2018-05-17 16:04:22 +02:00
|
|
|
}
|
2018-06-13 14:43:36 +02:00
|
|
|
|
2018-05-11 17:50:37 +02:00
|
|
|
/** {@inheritDoc} */
|
|
|
|
@Override
|
2018-05-17 16:04:22 +02:00
|
|
|
public void launch(Map<String,Object> inputs) throws Exception {
|
|
|
|
logger.debug("{} is starting", this.getClass().getSimpleName());
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-17 16:04:22 +02:00
|
|
|
if(inputs == null || inputs.isEmpty()) {
|
|
|
|
throw new IllegalArgumentException("The can only be launched providing valid input parameters");
|
2018-05-17 12:52:17 +02:00
|
|
|
}
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-17 16:04:22 +02:00
|
|
|
if(!inputs.containsKey(MEASURE_TYPE_INPUT_PARAMETER)) {
|
|
|
|
throw new IllegalArgumentException("Please set required parameter '" + MEASURE_TYPE_INPUT_PARAMETER + "'");
|
|
|
|
}
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-06-14 18:17:22 +02:00
|
|
|
AggregationType aggregationType = AggregationType.valueOf((String) inputs.get(MEASURE_TYPE_INPUT_PARAMETER));
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-17 16:04:22 +02:00
|
|
|
boolean reRun = true;
|
|
|
|
if(inputs.containsKey(RERUN_INPUT_PARAMETER)) {
|
|
|
|
try {
|
|
|
|
reRun = (boolean) inputs.get(RERUN_INPUT_PARAMETER);
|
2018-06-14 16:22:19 +02:00
|
|
|
} catch(Exception e) {
|
2018-05-17 16:04:22 +02:00
|
|
|
throw new IllegalArgumentException("'" + RERUN_INPUT_PARAMETER + "' must be a boolean");
|
|
|
|
}
|
2018-05-11 17:50:37 +02:00
|
|
|
}
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-06-04 16:35:32 +02:00
|
|
|
boolean getVREUsers = true;
|
|
|
|
if(inputs.containsKey(GET_VRE_USERS_INPUT_PARAMETER)) {
|
|
|
|
try {
|
|
|
|
reRun = (boolean) inputs.get(GET_VRE_USERS_INPUT_PARAMETER);
|
2018-06-14 16:22:19 +02:00
|
|
|
} catch(Exception e) {
|
2018-06-04 16:35:32 +02:00
|
|
|
throw new IllegalArgumentException("'" + GET_VRE_USERS_INPUT_PARAMETER + "' must be a boolean");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 16:04:22 +02:00
|
|
|
boolean dryRun = true;
|
|
|
|
if(inputs.containsKey(DRY_RUN_INPUT_PARAMETER)) {
|
|
|
|
try {
|
|
|
|
dryRun = (boolean) inputs.get(DRY_RUN_INPUT_PARAMETER);
|
2018-06-14 16:22:19 +02:00
|
|
|
} catch(Exception e) {
|
2018-05-17 16:04:22 +02:00
|
|
|
throw new IllegalArgumentException("'" + DRY_RUN_INPUT_PARAMETER + "' must be a boolean");
|
|
|
|
}
|
2018-05-11 17:50:37 +02:00
|
|
|
}
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-17 16:04:22 +02:00
|
|
|
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 {
|
2018-06-14 18:17:22 +02:00
|
|
|
start = DateUtils.getPreviousPeriod(aggregationType).getTime();
|
2018-05-11 17:50:37 +02:00
|
|
|
}
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-06-14 18:17:22 +02:00
|
|
|
end = DateUtils.getEndDateFromStartDate(aggregationType, start, 1);
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-07-05 18:25:05 +02:00
|
|
|
logger.debug("Harvesting from {} to {} (ReRun:{} - GetVREUsers:{} - DryRun:{})",
|
|
|
|
DateUtils.format(start), DateUtils.format(end), reRun, getVREUsers, dryRun);
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-29 13:05:55 +02:00
|
|
|
Properties properties = getConfigParameters();
|
|
|
|
getProperties().set(properties);
|
|
|
|
|
2018-06-13 19:39:01 +02:00
|
|
|
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-09-04 11:13:16 +02:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
scopeDescriptors.set(scopeDescriptorMap);
|
|
|
|
|
|
|
|
|
|
|
|
Set<Dimension> dimensionSet = dao.getDimensions();
|
|
|
|
Map<String,Dimension> dimensionMap = new HashMap<>();
|
|
|
|
for(Dimension dimension : dimensionSet) {
|
|
|
|
dimensionMap.put(dimension.getId(), dimension);
|
|
|
|
}
|
|
|
|
|
|
|
|
dimensions.set(dimensionMap);
|
|
|
|
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-18 12:00:10 +02:00
|
|
|
SortedSet<String> contexts = contextAuthorization.getContexts();
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-09-04 11:13:16 +02:00
|
|
|
// ArrayList<HarvestedData> data = new ArrayList<HarvestedData>();
|
|
|
|
ArrayList<AccountingRecord> accountingRecords = new ArrayList<AccountingRecord>();
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-29 11:08:24 +02:00
|
|
|
String initialToken = SecurityTokenProvider.instance.get();
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-06-14 14:34:11 +02:00
|
|
|
VREAccessesHarvester vreAccessesHarvester = null;
|
2018-05-29 11:08:24 +02:00
|
|
|
|
2018-05-18 12:00:10 +02:00
|
|
|
for(String context : contexts) {
|
|
|
|
// Setting the token for the context
|
|
|
|
Utils.setContext(contextAuthorization.getTokenForContext(context));
|
2018-06-13 19:39:01 +02:00
|
|
|
|
|
|
|
ScopeBean scopeBean = new ScopeBean(context);
|
|
|
|
|
2018-09-04 11:13:16 +02:00
|
|
|
ScopeDescriptor actualScopeDescriptor = scopeDescriptorMap.get(context);
|
|
|
|
if(actualScopeDescriptor==null) {
|
|
|
|
actualScopeDescriptor = new ScopeDescriptor(scopeBean.name(), context);
|
|
|
|
}
|
|
|
|
|
|
|
|
scopeDescriptor.set(actualScopeDescriptor);
|
|
|
|
|
|
|
|
|
2018-06-14 14:34:11 +02:00
|
|
|
if(vreAccessesHarvester == null) {
|
2018-06-13 19:39:01 +02:00
|
|
|
|
|
|
|
if(scopeBean.is(Type.INFRASTRUCTURE)) {
|
2018-06-14 14:34:11 +02:00
|
|
|
vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
2018-06-14 16:22:19 +02:00
|
|
|
} else {
|
2018-06-13 19:39:01 +02:00
|
|
|
// 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();
|
|
|
|
}
|
2018-06-14 14:34:11 +02:00
|
|
|
|
2018-06-13 19:39:01 +02:00
|
|
|
// Setting back token for the context
|
|
|
|
Utils.setContext(contextAuthorization.getTokenForContext(parent.toString()));
|
|
|
|
|
2018-06-14 14:34:11 +02:00
|
|
|
vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
2018-06-13 19:39:01 +02:00
|
|
|
|
|
|
|
// Setting back token for the context
|
|
|
|
Utils.setContext(contextAuthorization.getTokenForContext(context));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-06-14 14:34:11 +02:00
|
|
|
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-06-14 18:17:22 +02:00
|
|
|
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),
|
|
|
|
DateUtils.format(end));
|
|
|
|
} else {
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-21 12:18:06 +02:00
|
|
|
try {
|
2018-06-14 18:17:22 +02:00
|
|
|
// Collecting Google Analytics Data for VREs Accesses
|
2018-07-05 18:25:05 +02:00
|
|
|
logger.info("Going to harvest VRE Accesses for {}", context);
|
2018-09-04 11:13:16 +02:00
|
|
|
|
|
|
|
List<AccountingRecord> harvested = vreAccessesHarvester.getAccountingRecords();
|
|
|
|
accountingRecords.addAll(harvested);
|
|
|
|
|
|
|
|
/*
|
2018-06-14 18:17:22 +02:00
|
|
|
List<HarvestedData> harvested = vreAccessesHarvester.getData();
|
2018-05-21 12:18:06 +02:00
|
|
|
data.addAll(harvested);
|
2018-09-04 11:13:16 +02:00
|
|
|
*/
|
2018-05-21 12:18:06 +02:00
|
|
|
} catch(Exception e) {
|
2018-07-05 18:25:05 +02:00
|
|
|
logger.error("Error harvesting VRE Accesses for {}", context, e);
|
2018-05-21 12:18:06 +02:00
|
|
|
}
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-18 16:36:05 +02:00
|
|
|
try {
|
2018-06-14 18:17:22 +02:00
|
|
|
// Collecting info on social (posts, replies and likes)
|
2018-07-05 18:25:05 +02:00
|
|
|
logger.info("Going to harvest Social Interactions for {}", context);
|
2018-06-14 18:17:22 +02:00
|
|
|
SocialInteractionsHarvester socialHarvester = new SocialInteractionsHarvester(start, end);
|
2018-09-04 11:13:16 +02:00
|
|
|
|
|
|
|
List<AccountingRecord> harvested = socialHarvester.getAccountingRecords();
|
|
|
|
accountingRecords.addAll(harvested);
|
|
|
|
|
|
|
|
/*
|
2018-06-14 18:17:22 +02:00
|
|
|
List<HarvestedData> harvested = socialHarvester.getData();
|
2018-05-18 16:36:05 +02:00
|
|
|
data.addAll(harvested);
|
2018-09-04 11:13:16 +02:00
|
|
|
*/
|
2018-05-18 16:36:05 +02:00
|
|
|
} catch(Exception e) {
|
2018-06-14 18:17:22 +02:00
|
|
|
logger.error("Error harvesting Social Interactions for {}", context, e);
|
2018-05-18 16:36:05 +02:00
|
|
|
}
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-18 18:33:28 +02:00
|
|
|
try {
|
2018-06-14 18:17:22 +02:00
|
|
|
// 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)
|
2018-06-18 14:42:59 +02:00
|
|
|
// The VREUsers can be only Harvested for the last month
|
2018-06-14 18:17:22 +02:00
|
|
|
if(scopeBean.is(Type.VRE) && start.equals(DateUtils.getPreviousPeriod(aggregationType).getTime())) {
|
2018-07-05 18:25:05 +02:00
|
|
|
logger.info("Going to harvest Context Users for {}", context);
|
2018-06-14 18:17:22 +02:00
|
|
|
VREUsersHarvester vreUsersHarvester = new VREUsersHarvester(start, end);
|
2018-09-04 11:13:16 +02:00
|
|
|
|
|
|
|
List<AccountingRecord> harvested = vreUsersHarvester.getAccountingRecords();
|
|
|
|
accountingRecords.addAll(harvested);
|
|
|
|
|
|
|
|
/*
|
2018-06-14 18:17:22 +02:00
|
|
|
List<HarvestedData> harvested = vreUsersHarvester.getData();
|
|
|
|
data.addAll(harvested);
|
2018-09-04 11:13:16 +02:00
|
|
|
*/
|
2018-06-14 18:17:22 +02:00
|
|
|
}
|
|
|
|
}
|
2018-05-18 18:33:28 +02:00
|
|
|
} catch(Exception e) {
|
2018-06-14 18:17:22 +02:00
|
|
|
logger.error("Error harvesting Context Users for {}", context, e);
|
2018-05-18 18:33:28 +02:00
|
|
|
}
|
2018-06-14 18:17:22 +02:00
|
|
|
|
|
|
|
if(context.startsWith(SO_BIG_DATA_CATALOGUE_CONTEXT)) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Collecting info on Resource Catalogue (Dataset, Application, Deliverables, Methods)
|
2018-07-05 18:25:05 +02:00
|
|
|
logger.info("Going to harvest Resource Catalogue Information for {}", context);
|
2018-06-14 18:17:22 +02:00
|
|
|
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end,
|
|
|
|
contexts);
|
2018-09-04 11:13:16 +02:00
|
|
|
|
|
|
|
List<AccountingRecord> harvested = resourceCatalogueHarvester.getAccountingRecords();
|
|
|
|
accountingRecords.addAll(harvested);
|
|
|
|
|
|
|
|
/*
|
2018-06-14 18:17:22 +02:00
|
|
|
List<HarvestedData> harvested = resourceCatalogueHarvester.getData();
|
|
|
|
data.addAll(harvested);
|
2018-09-04 11:13:16 +02:00
|
|
|
*/
|
|
|
|
|
2018-06-14 18:17:22 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("Error harvesting Resource Catalogue Information for {}", context, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Collecting info on Data/Method download
|
2018-07-05 18:25:05 +02:00
|
|
|
logger.info("Going to harvest Data Method Download for {}", context);
|
2018-06-14 18:17:22 +02:00
|
|
|
DataMethodDownloadHarvester dataMethodDownloadHarvester = new DataMethodDownloadHarvester(start,
|
|
|
|
end, contexts);
|
2018-09-04 11:13:16 +02:00
|
|
|
|
|
|
|
List<AccountingRecord> harvested = dataMethodDownloadHarvester.getAccountingRecords();
|
|
|
|
accountingRecords.addAll(harvested);
|
|
|
|
|
|
|
|
/*
|
2018-06-14 18:17:22 +02:00
|
|
|
List<HarvestedData> harvested = dataMethodDownloadHarvester.getData();
|
|
|
|
data.addAll(harvested);
|
2018-09-04 11:13:16 +02:00
|
|
|
*/
|
|
|
|
|
2018-06-14 18:17:22 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("Error harvesting Data Method Download for {}", context, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(context.startsWith(TAGME_CONTEXT)) {
|
|
|
|
try {
|
|
|
|
// Collecting info on method invocation
|
2018-07-05 18:25:05 +02:00
|
|
|
logger.info("Going to harvest Method Invocations for {}", context);
|
2018-06-14 18:17:22 +02:00
|
|
|
TagMeMethodInvocationHarvester tagMeMethodInvocationHarvester = new TagMeMethodInvocationHarvester(
|
|
|
|
start, end);
|
2018-09-04 11:13:16 +02:00
|
|
|
|
|
|
|
List<AccountingRecord> harvested = tagMeMethodInvocationHarvester.getAccountingRecords();
|
|
|
|
accountingRecords.addAll(harvested);
|
|
|
|
|
|
|
|
/*
|
2018-06-14 18:17:22 +02:00
|
|
|
List<HarvestedData> harvested = tagMeMethodInvocationHarvester.getData();
|
|
|
|
data.addAll(harvested);
|
2018-09-04 11:13:16 +02:00
|
|
|
*/
|
|
|
|
|
2018-06-14 18:17:22 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("Error harvesting Method Invocations for {}", context, e);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
// Collecting info on method invocation
|
2018-07-05 18:25:05 +02:00
|
|
|
logger.info("Going to harvest Method Invocations for {}", context);
|
2018-06-14 18:17:22 +02:00
|
|
|
MethodInvocationHarvester methodInvocationHarvester = new MethodInvocationHarvester(start, end);
|
2018-09-04 11:13:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
List<AccountingRecord> harvested = methodInvocationHarvester.getAccountingRecords();
|
|
|
|
accountingRecords.addAll(harvested);
|
|
|
|
|
|
|
|
/*
|
2018-06-14 18:17:22 +02:00
|
|
|
List<HarvestedData> harvested = methodInvocationHarvester.getData();
|
|
|
|
data.addAll(harvested);
|
2018-09-04 11:13:16 +02:00
|
|
|
*/
|
2018-06-14 18:17:22 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
logger.error("Error harvesting Method Invocations for {}", context, e);
|
|
|
|
}
|
2018-05-18 16:36:05 +02:00
|
|
|
}
|
2018-05-16 15:08:25 +02:00
|
|
|
}
|
2018-05-11 17:50:37 +02:00
|
|
|
}
|
2018-05-29 11:08:24 +02:00
|
|
|
|
|
|
|
Utils.setContext(initialToken);
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-09-04 11:13:16 +02:00
|
|
|
logger.debug("Harvest Measures from {} to {} are {}", DateUtils.format(start), DateUtils.format(end), accountingRecords);
|
2018-05-18 12:00:10 +02:00
|
|
|
if(!dryRun) {
|
2018-09-04 11:13:16 +02:00
|
|
|
dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
|
|
|
//dbaseManager.insertMonthlyData(start, end, data, reRun);
|
|
|
|
}else {
|
|
|
|
logger.debug("Harvested measures are {}", accountingRecords);
|
2018-05-18 12:00:10 +02:00
|
|
|
}
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-11 17:50:37 +02:00
|
|
|
}
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-11 17:50:37 +02:00
|
|
|
/** {@inheritDoc} */
|
|
|
|
@Override
|
|
|
|
protected void onStop() throws Exception {
|
2018-05-17 16:04:22 +02:00
|
|
|
logger.debug("{} is stopping", this.getClass().getSimpleName());
|
2018-05-11 17:50:37 +02:00
|
|
|
}
|
2018-06-14 16:22:19 +02:00
|
|
|
|
2018-05-11 17:50:37 +02:00
|
|
|
}
|