Added logic to exclude harvesting in some cases
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-dashboard-harvester-se-plugin@169213 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
13c74dc4f9
commit
56d97e228b
|
@ -35,41 +35,44 @@ import org.slf4j.LoggerFactory;
|
|||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDeclaration> {
|
||||
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(AccountingDataHarvesterPlugin.class);
|
||||
|
||||
|
||||
private static final String PROPERTY_FILENAME = "config.properties";
|
||||
|
||||
|
||||
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";
|
||||
public static final String GET_VRE_USERS_INPUT_PARAMETER = "getVREUsers";
|
||||
public static final String DRY_RUN_INPUT_PARAMETER = "dryRun";
|
||||
|
||||
|
||||
public static final String SO_BIG_DATA_VO = "/d4science.research-infrastructures.eu/SoBigData";
|
||||
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";
|
||||
public static final String SO_BIG_DATA_CATALOGUE_CONTEXT = "/d4science.research-infrastructures.eu/SoBigData/ResourceCatalogue";
|
||||
|
||||
public static final String TAGME_CONTEXT = "/d4science.research-infrastructures.eu/SoBigData/TagMe";
|
||||
|
||||
|
||||
protected Date start;
|
||||
protected Date end;
|
||||
|
||||
|
||||
public AccountingDataHarvesterPlugin(DataHarvestPluginDeclaration pluginDeclaration) {
|
||||
super(pluginDeclaration);
|
||||
}
|
||||
|
||||
|
||||
private static final InheritableThreadLocal<Properties> properties = new InheritableThreadLocal<Properties>() {
|
||||
|
||||
|
||||
@Override
|
||||
protected Properties initialValue() {
|
||||
return new Properties();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
public static InheritableThreadLocal<Properties> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
||||
public Properties getConfigParameters() throws IOException {
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
|
@ -89,70 +92,68 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
|||
@Override
|
||||
public void launch(Map<String,Object> inputs) throws Exception {
|
||||
logger.debug("{} is starting", this.getClass().getSimpleName());
|
||||
|
||||
|
||||
if(inputs == null || inputs.isEmpty()) {
|
||||
throw new IllegalArgumentException("The can only be launched providing valid input parameters");
|
||||
}
|
||||
|
||||
|
||||
if(!inputs.containsKey(MEASURE_TYPE_INPUT_PARAMETER)) {
|
||||
throw new IllegalArgumentException("Please set required parameter '" + MEASURE_TYPE_INPUT_PARAMETER + "'");
|
||||
}
|
||||
|
||||
|
||||
MeasureType measureType = MeasureType.valueOf((String) inputs.get(MEASURE_TYPE_INPUT_PARAMETER));
|
||||
|
||||
|
||||
boolean reRun = true;
|
||||
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)) {
|
||||
try {
|
||||
reRun = (boolean) inputs.get(GET_VRE_USERS_INPUT_PARAMETER);
|
||||
}catch (Exception e) {
|
||||
} 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)) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 {
|
||||
start = DateUtils.getPreviousPeriod(measureType).getTime();
|
||||
}
|
||||
|
||||
|
||||
end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
||||
|
||||
logger.debug("Harvesting from {} to {}", DateUtils.format(start),
|
||||
DateUtils.format(end));
|
||||
|
||||
|
||||
logger.debug("Harvesting from {} to {}", DateUtils.format(start), DateUtils.format(end));
|
||||
|
||||
Properties properties = getConfigParameters();
|
||||
getProperties().set(properties);
|
||||
|
||||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
||||
|
||||
|
||||
DatabaseManager dbaseManager = new DatabaseManager();
|
||||
|
||||
|
||||
SortedSet<String> contexts = contextAuthorization.getContexts();
|
||||
|
||||
|
||||
ArrayList<HarvestedData> data = new ArrayList<HarvestedData>();
|
||||
|
||||
|
||||
String initialToken = SecurityTokenProvider.instance.get();
|
||||
|
||||
|
||||
VREAccessesHarvester vreAccessesHarvester = null;
|
||||
|
||||
for(String context : contexts) {
|
||||
|
@ -165,7 +166,7 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
|||
|
||||
if(scopeBean.is(Type.INFRASTRUCTURE)) {
|
||||
vreAccessesHarvester = new VREAccessesHarvester(start, end);
|
||||
}else {
|
||||
} else {
|
||||
// This code should be never used because the scopes are sorted by fullname
|
||||
|
||||
ScopeBean parent = scopeBean.enclosingScope();
|
||||
|
@ -184,10 +185,12 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
|||
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
if(context.startsWith(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));
|
||||
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 VREs Accesses for {} from {} to {}", context, DateUtils.format(start),
|
||||
DateUtils.format(end));
|
||||
} else {
|
||||
// Collecting Google Analytics Data for VREs Accesses
|
||||
List<HarvestedData> harvested = vreAccessesHarvester.getData();
|
||||
|
@ -197,7 +200,6 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
|||
logger.error("Error harvesting Social Interactions for {}", context, e);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
// Collecting info on social (posts, replies and likes)
|
||||
SocialInteractionsHarvester socialHarvester = new SocialInteractionsHarvester(start, end);
|
||||
|
@ -206,7 +208,7 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
|||
} catch(Exception e) {
|
||||
logger.error("Error harvesting Social Interactions for {}", context, e);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
// Collecting info on VRE users
|
||||
if(getVREUsers) {
|
||||
|
@ -221,40 +223,42 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
|||
} catch(Exception e) {
|
||||
logger.error("Error harvesting Context Users for {}", context, e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(context.startsWith(SO_BIG_DATA_CATALOGUE_CONTEXT)) {
|
||||
|
||||
|
||||
try {
|
||||
// Collecting info on Resource Catalogue (Dataset, Application, Deliverables, Methods)
|
||||
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end, contexts);
|
||||
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end,
|
||||
contexts);
|
||||
List<HarvestedData> harvested = resourceCatalogueHarvester.getData();
|
||||
data.addAll(harvested);
|
||||
} catch(Exception e) {
|
||||
logger.error("Error harvesting Resource Catalogue Information for {}", context, e);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
// Collecting info on Data/Method download
|
||||
DataMethodDownloadHarvester dataMethodDownloadHarvester = new DataMethodDownloadHarvester(start, end, contexts);
|
||||
DataMethodDownloadHarvester dataMethodDownloadHarvester = new DataMethodDownloadHarvester(start,
|
||||
end, contexts);
|
||||
List<HarvestedData> harvested = dataMethodDownloadHarvester.getData();
|
||||
data.addAll(harvested);
|
||||
} catch(Exception e) {
|
||||
logger.error("Error harvesting Data Method Download for {}", context, e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(context.startsWith(TAGME_CONTEXT)) {
|
||||
try {
|
||||
// Collecting info on method invocation
|
||||
TagMeMethodInvocationHarvester tagMeMethodInvocationHarvester = new TagMeMethodInvocationHarvester(start, end);
|
||||
TagMeMethodInvocationHarvester tagMeMethodInvocationHarvester = new TagMeMethodInvocationHarvester(
|
||||
start, end);
|
||||
List<HarvestedData> harvested = tagMeMethodInvocationHarvester.getData();
|
||||
data.addAll(harvested);
|
||||
} catch(Exception e) {
|
||||
logger.error("Error harvesting Method Invocations for {}", context, e);
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
try {
|
||||
// Collecting info on method invocation
|
||||
MethodInvocationHarvester methodInvocationHarvester = new MethodInvocationHarvester(start, end);
|
||||
|
@ -268,18 +272,18 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
|||
}
|
||||
|
||||
Utils.setContext(initialToken);
|
||||
|
||||
|
||||
logger.debug("Harvest Measures from {} to {} are {}", DateUtils.format(start), DateUtils.format(end), data);
|
||||
if(!dryRun) {
|
||||
dbaseManager.insertMonthlyData(start, end, data, reRun);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected void onStop() throws Exception {
|
||||
logger.debug("{} is stopping", this.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue