git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-analytics@129510 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a6bb27420e
commit
6413cd9cf6
|
@ -20,6 +20,7 @@
|
|||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
|
|
13
.project
13
.project
|
@ -5,6 +5,11 @@
|
|||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
|
@ -15,9 +20,17 @@
|
|||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
|
|
|
@ -20,7 +20,8 @@ public class NoUsableAccountingPersistenceQueryFound extends Exception {
|
|||
* call to {@link #initCause}.
|
||||
*/
|
||||
public NoUsableAccountingPersistenceQueryFound() {
|
||||
super();
|
||||
super("No Usable Accounting Persistence Query Found");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,6 +5,7 @@ package org.gcube.accounting.analytics.persistence;
|
|||
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.SortedSet;
|
||||
|
||||
|
@ -16,6 +17,7 @@ import org.gcube.accounting.analytics.exception.DuplicatedKeyFilterException;
|
|||
import org.gcube.accounting.analytics.exception.KeyException;
|
||||
import org.gcube.accounting.analytics.exception.ValueException;
|
||||
import org.gcube.documentstore.records.AggregatedRecord;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
|
@ -26,7 +28,7 @@ public interface AccountingPersistenceBackendQuery {
|
|||
|
||||
public void prepareConnection(
|
||||
AccountingPersistenceBackendQueryConfiguration configuration)
|
||||
throws Exception;
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* Query the persistence obtaining a Map where the date is the key and the
|
||||
|
@ -53,9 +55,12 @@ public interface AccountingPersistenceBackendQuery {
|
|||
*/
|
||||
public SortedMap<Calendar, Info> getTimeSeries(
|
||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
||||
Exception;
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
||||
Exception;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return a SortedMap containing the TimeSeries for top values for a certain
|
||||
|
@ -85,11 +90,11 @@ public interface AccountingPersistenceBackendQuery {
|
|||
* @throws Exception
|
||||
*/
|
||||
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>>
|
||||
getTopValues(Class<? extends AggregatedRecord<?,?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String topKey, String orderingProperty)
|
||||
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
||||
Exception;
|
||||
getTopValues(Class<? extends AggregatedRecord<?,?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String topKey, String orderingProperty)
|
||||
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
||||
Exception;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -106,10 +111,10 @@ public interface AccountingPersistenceBackendQuery {
|
|||
*/
|
||||
public SortedSet<NumberedFilter> getNextPossibleValues(
|
||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String key, String orderingProperty) throws
|
||||
DuplicatedKeyFilterException, KeyException, ValueException,
|
||||
Exception;
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String key, String orderingProperty) throws
|
||||
DuplicatedKeyFilterException, KeyException, ValueException,
|
||||
Exception;
|
||||
|
||||
/**
|
||||
* Close the connection to persistence
|
||||
|
@ -119,4 +124,48 @@ public interface AccountingPersistenceBackendQuery {
|
|||
*/
|
||||
public void close() throws Exception;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return a sortedSet filter value
|
||||
*
|
||||
*
|
||||
* @param clz
|
||||
* @param temporalConstraint
|
||||
* @param filters
|
||||
* @param key
|
||||
* @param orderingProperty
|
||||
* @return
|
||||
* @throws DuplicatedKeyFilterException
|
||||
* @throws KeyException
|
||||
* @throws ValueException
|
||||
* @throws Exception
|
||||
*/
|
||||
public SortedSet<NumberedFilter> getFilterValues(
|
||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String key) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Return a JsonObject with value
|
||||
* e.g.for StorageUsageRecord {"dataVolume":1860328,"operationCount":4115}
|
||||
* e.g. for ServiceUsageRcord {"operationCount":1651624}
|
||||
*
|
||||
* @param clz
|
||||
* the Usage Record Class of interest
|
||||
* @param temporalConstraint
|
||||
* the TemporalConstraint (interval and aggregation)
|
||||
* @param applicant
|
||||
* the type field and value
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public JSONObject getUsageValue(Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, Filter applicant)
|
||||
throws Exception;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -46,8 +46,9 @@ public abstract class AccountingPersistenceBackendQueryFactory {
|
|||
try {
|
||||
ServiceLoader<AccountingPersistenceBackendQuery> serviceLoader = ServiceLoader.load(AccountingPersistenceBackendQuery.class);
|
||||
for (AccountingPersistenceBackendQuery found : serviceLoader) {
|
||||
Class<? extends AccountingPersistenceBackendQuery> foundClass = found.getClass();
|
||||
Class<? extends AccountingPersistenceBackendQuery> foundClass=null;
|
||||
try {
|
||||
foundClass = found.getClass();
|
||||
String foundClassName = foundClass.getSimpleName();
|
||||
logger.debug("Testing {}", foundClassName);
|
||||
AccountingPersistenceBackendQueryConfiguration configuration = new AccountingPersistenceBackendQueryConfiguration(foundClass);
|
||||
|
@ -55,14 +56,17 @@ public abstract class AccountingPersistenceBackendQueryFactory {
|
|||
accountingPersistenceQuery = found;
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
logger.debug(String.format("%s not initialized correctly. It will not be used", foundClass.getSimpleName()));
|
||||
logger.error(String.format("%s not initialized correctly. It will not be used", foundClass.getSimpleName()));
|
||||
|
||||
}
|
||||
}
|
||||
} catch(Exception e){
|
||||
throw new NoUsableAccountingPersistenceQueryFound();
|
||||
logger.error(String.format("service loader or not initialized correctly."));
|
||||
throw new NoUsableAccountingPersistenceQueryFound(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
if(accountingPersistenceQuery==null){
|
||||
logger.error(String.format("accountingPersistenceQuery null"));
|
||||
throw new NoUsableAccountingPersistenceQueryFound();
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import javax.activity.InvalidActivityException;
|
||||
|
@ -37,7 +38,7 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
|||
private static final AccountingPersistenceQuery accountingPersistenceQuery;
|
||||
|
||||
public static final int DEFAULT_LIMIT_RESULT_NUMBER = 5;
|
||||
|
||||
|
||||
private AccountingPersistenceQuery() {
|
||||
}
|
||||
|
||||
|
@ -51,7 +52,7 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
|||
|
||||
public static SortedSet<String> getQuerableKeys(
|
||||
@SuppressWarnings("rawtypes") AggregatedRecord instance)
|
||||
throws Exception {
|
||||
throws Exception {
|
||||
SortedSet<String> properties = new TreeSet<>(
|
||||
instance.getRequiredFields());
|
||||
|
||||
|
@ -67,11 +68,11 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
|||
|
||||
public static SortedSet<String> getQuerableKeys(
|
||||
Class<? extends AggregatedRecord<?,?>> clz)
|
||||
throws Exception {
|
||||
throws Exception {
|
||||
AggregatedRecord<?,?> instance = clz.newInstance();
|
||||
return getQuerableKeys(instance);
|
||||
}
|
||||
|
||||
|
||||
public static String getDefaultOrderingProperties(
|
||||
Class<? extends AggregatedRecord<?, ?>> clz){
|
||||
if(clz.isAssignableFrom(AggregatedStorageUsageRecord.class)){
|
||||
|
@ -79,23 +80,26 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
|||
}
|
||||
return AggregatedRecord.OPERATION_COUNT;
|
||||
}
|
||||
|
||||
|
||||
protected static JSONObject getPaddingJSONObject(
|
||||
Map<Calendar, Info> unpaddedResults) throws JSONException {
|
||||
Info auxInfo = new ArrayList<Info>(unpaddedResults.values()).get(0);
|
||||
JSONObject auxJsonObject = auxInfo.getValue();
|
||||
@SuppressWarnings("unchecked")
|
||||
Iterator<String> keys = auxJsonObject.keys();
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
jsonObject.put(key, 0);
|
||||
//verify data consistency
|
||||
if (unpaddedResults.size()!=0){
|
||||
Info auxInfo = new ArrayList<Info>(unpaddedResults.values()).get(0);
|
||||
JSONObject auxJsonObject = auxInfo.getValue();
|
||||
@SuppressWarnings("unchecked")
|
||||
Iterator<String> keys = auxJsonObject.keys();
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
jsonObject.put(key, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pad the data
|
||||
*
|
||||
|
@ -111,7 +115,7 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
|||
public static SortedMap<Calendar, Info> padMap(
|
||||
SortedMap<Calendar, Info> unpaddedData,
|
||||
TemporalConstraint temporalConstraint) throws Exception {
|
||||
|
||||
|
||||
JSONObject jsonObject = getPaddingJSONObject(unpaddedData);
|
||||
SortedSet<Calendar> sequence = temporalConstraint.getCalendarSequence();
|
||||
for (Calendar progressTime : sequence) {
|
||||
|
@ -123,58 +127,66 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
|||
}
|
||||
return unpaddedData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public SortedMap<Calendar, Info> getTimeSeries(
|
||||
Class<? extends AggregatedRecord<?,?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
||||
Exception {
|
||||
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
||||
Exception {
|
||||
|
||||
return this.getTimeSeries(clz, temporalConstraint, filters, false);
|
||||
}
|
||||
|
||||
|
||||
public SortedMap<Calendar, Info> getTimeSeries(
|
||||
Class<? extends AggregatedRecord<?,?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
boolean pad) throws DuplicatedKeyFilterException, KeyException,
|
||||
ValueException, Exception {
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
boolean pad) throws DuplicatedKeyFilterException, KeyException,
|
||||
ValueException, Exception {
|
||||
SortedMap<Calendar, Info> ret =
|
||||
AccountingPersistenceBackendQueryFactory.getInstance()
|
||||
.getTimeSeries(clz, temporalConstraint,
|
||||
filters);
|
||||
|
||||
|
||||
if(ret==null){
|
||||
ret = new TreeMap<>();
|
||||
}
|
||||
|
||||
|
||||
if(pad){
|
||||
ret = padMap(ret, temporalConstraint);
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
|
||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String topKey, String orderingProperty, boolean pad, int limit)
|
||||
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
||||
Exception {
|
||||
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String topKey, String orderingProperty, boolean pad, int limit)
|
||||
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
||||
Exception {
|
||||
|
||||
|
||||
|
||||
|
||||
SortedMap<NumberedFilter, SortedMap<Calendar, Info>> got;
|
||||
|
||||
|
||||
if(orderingProperty==null){
|
||||
orderingProperty = getDefaultOrderingProperties(clz);
|
||||
}
|
||||
|
||||
|
||||
got = AccountingPersistenceBackendQueryFactory.getInstance()
|
||||
.getTopValues(clz, temporalConstraint, filters, topKey,
|
||||
orderingProperty);
|
||||
|
||||
orderingProperty);
|
||||
|
||||
|
||||
int count = got.size() > limit ? limit : got.size();
|
||||
|
||||
|
||||
NumberedFilter firstRemovalKey = null;
|
||||
|
||||
|
||||
for(NumberedFilter nf : got.keySet()){
|
||||
if(--count>=0 || limit<=0){
|
||||
if(pad){
|
||||
|
@ -188,70 +200,73 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(firstRemovalKey!=null){
|
||||
return got.subMap(got.firstKey(), firstRemovalKey);
|
||||
}
|
||||
|
||||
|
||||
return got;
|
||||
}
|
||||
|
||||
|
||||
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
|
||||
Class<? extends AggregatedRecord<?,?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String topKey) throws DuplicatedKeyFilterException,
|
||||
KeyException, ValueException, Exception {
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String topKey) throws DuplicatedKeyFilterException,
|
||||
KeyException, ValueException, Exception {
|
||||
String orderingProperty = AccountingPersistenceQuery
|
||||
.getDefaultOrderingProperties(clz);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return this.getTopValues(clz, temporalConstraint, filters, topKey,
|
||||
orderingProperty, false, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
|
||||
Class<? extends AggregatedRecord<?,?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String topKey, String orderingProperty) throws
|
||||
DuplicatedKeyFilterException, KeyException, ValueException,
|
||||
Exception {
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String topKey, String orderingProperty) throws
|
||||
DuplicatedKeyFilterException, KeyException, ValueException,
|
||||
Exception {
|
||||
return this.getTopValues(clz, temporalConstraint, filters, topKey,
|
||||
orderingProperty, false, 0);
|
||||
orderingProperty, false, 0);
|
||||
}
|
||||
|
||||
public SortedSet<NumberedFilter> getNextPossibleValues(
|
||||
Class<? extends AggregatedRecord<?,?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String key) throws DuplicatedKeyFilterException, KeyException,
|
||||
ValueException, Exception {
|
||||
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String key) throws DuplicatedKeyFilterException, KeyException,
|
||||
ValueException, Exception {
|
||||
|
||||
String orderingProperty = AccountingPersistenceQuery
|
||||
.getDefaultOrderingProperties(clz);
|
||||
|
||||
|
||||
return this.getNextPossibleValues(clz, temporalConstraint, filters,
|
||||
key, orderingProperty);
|
||||
key, orderingProperty);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public SortedSet<NumberedFilter> getNextPossibleValues(
|
||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String key, String orderingProperty) throws
|
||||
DuplicatedKeyFilterException, KeyException, ValueException,
|
||||
Exception {
|
||||
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String key, String orderingProperty) throws
|
||||
DuplicatedKeyFilterException, KeyException, ValueException,
|
||||
Exception {
|
||||
|
||||
return AccountingPersistenceBackendQueryFactory.getInstance()
|
||||
.getNextPossibleValues(clz, temporalConstraint, filters,
|
||||
key, orderingProperty);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -266,8 +281,27 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
|||
@Override
|
||||
public void prepareConnection(
|
||||
AccountingPersistenceBackendQueryConfiguration configuration)
|
||||
throws Exception {
|
||||
throws Exception {
|
||||
throw new InvalidActivityException();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SortedSet<NumberedFilter> getFilterValues(
|
||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String key) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
return AccountingPersistenceBackendQueryFactory.getInstance()
|
||||
.getFilterValues(clz, temporalConstraint, filters,
|
||||
key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getUsageValue(Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, Filter applicant)
|
||||
throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue