Code redesign
Refs #11756: Refactor DataHArvesterPlugin to support scheduled execution from smart-executor Task-Url: https://support.d4science.org/issues/11756 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-dashboard-harvester-se-plugin@167798 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
0d0aaf1b21
commit
67ae816424
|
@ -56,29 +56,31 @@ public class DataMethodDownloadHarvester extends SoBigDataHarvester {
|
|||
@Override
|
||||
public List<HarvestedData> getData() throws Exception {
|
||||
String defaultContext = Utils.getCurrentContext();
|
||||
logger.debug("The context is: "+defaultContext);
|
||||
logger.debug("The context is {}", defaultContext);
|
||||
|
||||
try {
|
||||
|
||||
String vreName = getVRENameToHL(defaultContext);
|
||||
logger.debug("Getting VRE Name to HL from context/scope returns: "+vreName);
|
||||
logger.debug("Getting VRE Name to HL from context/scope returns {} ", vreName);
|
||||
|
||||
String user = vreName + "-Manager";
|
||||
logger.debug("Using user '"+user+"' to getHome from HL");
|
||||
logger.debug("Using user '{}' to getHome from HL", user);
|
||||
|
||||
//ISTANCING HL AND GETTING HOME FOR VRE MANAGER
|
||||
//Getting HL instance and home for VRE MANAGER
|
||||
HomeManager manager = HomeLibrary.getHomeManagerFactory().getHomeManager();
|
||||
@SuppressWarnings("deprecation")
|
||||
Home home = manager.getHome(user);
|
||||
JCRWorkspace ws = (JCRWorkspace) home.getWorkspace();
|
||||
//
|
||||
String path = "/Workspace/MySpecialFolders/" + vreName;
|
||||
logger.debug("Getting item by Path: "+path);
|
||||
JCRWorkspaceItem item = (JCRWorkspaceItem) ws.getItemByPath(path);
|
||||
//
|
||||
logger.info("Analyzing " + defaultContext + " in the period [" + start.toString() + " to " + end.toString() +"] starting from root: "+item.getName());
|
||||
|
||||
HarvestedData defaultHarvesteData = new HarvestedData(HarvestedDataKey.DATA_METHOD_DOWNLOAD, defaultContext, count);
|
||||
String path = "/Workspace/MySpecialFolders/" + vreName;
|
||||
logger.debug("Getting item by Path {}", path);
|
||||
JCRWorkspaceItem item = (JCRWorkspaceItem) ws.getItemByPath(path);
|
||||
|
||||
logger.debug("Analyzing {} in the period [{} to {}] starting from root {}", defaultContext,
|
||||
DateUtils.format(start), DateUtils.format(end), item.getName());
|
||||
|
||||
HarvestedData defaultHarvesteData = new HarvestedData(HarvestedDataKey.DATA_METHOD_DOWNLOAD, defaultContext,
|
||||
count);
|
||||
|
||||
List<HarvestedData> data = new ArrayList<HarvestedData>();
|
||||
for(WorkspaceItem children : item.getChildren()) {
|
||||
|
@ -86,22 +88,24 @@ public class DataMethodDownloadHarvester extends SoBigDataHarvester {
|
|||
HarvestedData harvestedData;
|
||||
//Getting statistics for folder
|
||||
if(children.isFolder()) {
|
||||
logger.info("Getting statistics for folder: "+children.getName());
|
||||
logger.debug("Getting statistics for folder {}", children.getName());
|
||||
getStats(children, start, end);
|
||||
|
||||
String normalizedName = children.getName().replaceAll("[^A-Za-z0-9]", "");
|
||||
String scope = mapWsFolderNameToVRE.get(normalizedName);
|
||||
//Checking if it is a VRE name to right accouning...
|
||||
//Checking if it is a VRE name to right accounting...
|
||||
if(scope != null && !scope.isEmpty()) {
|
||||
logger.info("Found scope '" + scope + "' matching with normalized VRE name: "+normalizedName);
|
||||
logger.debug("Found context '{}' matching with normalized VRE name {} ", scope, normalizedName);
|
||||
harvestedData = new HarvestedData(HarvestedDataKey.DATA_METHOD_DOWNLOAD, scope, count);
|
||||
data.add(harvestedData);
|
||||
logger.info("Added data: "+harvestedData);
|
||||
logger.debug("Added data {}", harvestedData);
|
||||
} else {
|
||||
logger.info("No scope found matching the folder name: "+normalizedName +", accounting its stats in the default context: "+defaultContext);
|
||||
logger.debug(
|
||||
"No scope found matching the folder name {}, accounting its stats in the default context {}",
|
||||
normalizedName, defaultContext);
|
||||
//INCREASING THE DEFAULT CONTEXT COUNTER...
|
||||
defaultHarvesteData.setMeasure(defaultHarvesteData.getMeasure() + count);
|
||||
logger.info("Increased default context stats: "+defaultHarvesteData);
|
||||
logger.trace("Increased default context stats {}", defaultHarvesteData);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -110,7 +114,8 @@ public class DataMethodDownloadHarvester extends SoBigDataHarvester {
|
|||
//ADDING DEFAULT ACCOUNTING
|
||||
data.add(defaultHarvesteData);
|
||||
|
||||
logger.info("In the period [from {} to {} ] returning workspace accouting data {}", DateUtils.format(start), DateUtils.format(end), data);
|
||||
logger.debug("In the period [from {} to {} ] returning workspace accouting data {}", DateUtils.format(start),
|
||||
DateUtils.format(end), data);
|
||||
|
||||
return data;
|
||||
|
||||
|
@ -120,7 +125,6 @@ public class DataMethodDownloadHarvester extends SoBigDataHarvester {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the stats.
|
||||
*
|
||||
|
@ -147,7 +151,8 @@ public class DataMethodDownloadHarvester extends SoBigDataHarvester {
|
|||
case UPDATE:
|
||||
case READ:
|
||||
Calendar calendar = entry.getDate();
|
||||
if(calendar.after(DateUtils.dateToCalendar(start)) && calendar.before(DateUtils.dateToCalendar(end))) {
|
||||
if(calendar.after(DateUtils.dateToCalendar(start))
|
||||
&& calendar.before(DateUtils.dateToCalendar(end))) {
|
||||
count++;
|
||||
}
|
||||
|
||||
|
@ -159,13 +164,11 @@ public class DataMethodDownloadHarvester extends SoBigDataHarvester {
|
|||
|
||||
}
|
||||
} catch(Exception e) {
|
||||
logger.error("DataMethodDownloadHarvester: " + e.getLocalizedMessage());
|
||||
throw new InternalErrorException(e.getLocalizedMessage());
|
||||
throw new InternalErrorException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the VRE name to HL.
|
||||
*
|
||||
|
|
|
@ -73,7 +73,7 @@ public class ResourceCatalogueHarvester extends SoBigDataHarvester {
|
|||
//EXECUTING THE QUERY IN THE PERIOD
|
||||
String queryResult = executeQueryFor(solrParameters, start, end, "groups");
|
||||
HarvestedDataKey insertDBKey = HarvestedDataKey.valueOf(mapSystemTypeToDBEntry.get(systemType));
|
||||
logger.info("Creating statistics for type {} using db key {}", systemType, insertDBKey);
|
||||
logger.debug("Creating statistics for type {} using db key {}", systemType, insertDBKey);
|
||||
data.addAll(buildListOfHarvestedData(queryResult, insertDBKey));
|
||||
}
|
||||
|
||||
|
@ -95,9 +95,7 @@ public class ResourceCatalogueHarvester extends SoBigDataHarvester {
|
|||
JSONObject responseHeader = jsonObject.getJSONObject("responseHeader");
|
||||
int status = responseHeader.getInt("status");
|
||||
if(status != 0) {
|
||||
String err = "Query Deliverable in error: status " + status;
|
||||
logger.error(err);
|
||||
throw new Exception(err);
|
||||
throw new Exception("Query Deliverable in error: status " + status);
|
||||
}
|
||||
|
||||
JSONObject response = jsonObject.getJSONObject("response");
|
||||
|
@ -139,7 +137,7 @@ public class ResourceCatalogueHarvester extends SoBigDataHarvester {
|
|||
logger.debug("Document without groups, accounting it in the catalogue context");
|
||||
catalogueContextCount++;
|
||||
} catch (Exception e) {
|
||||
logger.error("Skipping parsing error", e);
|
||||
logger.warn("Skipping parsing error", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,7 +156,7 @@ public class ResourceCatalogueHarvester extends SoBigDataHarvester {
|
|||
data.add(new HarvestedData(harvestKey, mapCatalogueGroupToVRE.get(key), counter.get(key)));
|
||||
}
|
||||
|
||||
logger.info("For {} in the period [from {} to {}] returning accouting data :", harvestKey, DateUtils.format(start), DateUtils.format(end), data);
|
||||
logger.debug("For {} in the period [from {} to {}] returning accouting data :", harvestKey, DateUtils.format(start), DateUtils.format(end), data);
|
||||
|
||||
return data;
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
}
|
||||
|
||||
|
||||
// @Test
|
||||
@Test
|
||||
public void launch() {
|
||||
try {
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
inputs.put(AccountingDataHarvesterPlugin.MEASURE_TYPE_INPUT_PARAMETER, measureType.name());
|
||||
inputs.put(AccountingDataHarvesterPlugin.RERUN_INPUT_PARAMETER, true);
|
||||
inputs.put(AccountingDataHarvesterPlugin.DRY_RUN_INPUT_PARAMETER, true);
|
||||
inputs.put(AccountingDataHarvesterPlugin.DRY_RUN_INPUT_PARAMETER, false);
|
||||
|
||||
/*
|
||||
Calendar from = DateUtils.getStartCalendar(2018, Calendar.APRIL, 1);
|
||||
|
|
Loading…
Reference in New Issue