reformatted code

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-analytics@154378 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-09-21 12:54:33 +00:00
parent 390136c155
commit 7c45a1d29a
1 changed files with 131 additions and 218 deletions

View File

@ -51,46 +51,39 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
}
@Deprecated
public static SortedSet<String> getQuerableKeys(
@SuppressWarnings("rawtypes") AggregatedRecord instance)
throws Exception {
public static SortedSet<String> getQuerableKeys(@SuppressWarnings("rawtypes") AggregatedRecord instance)
throws Exception {
return instance.getQuerableKeys();
}
public static SortedSet<String> getQuerableKeys(
Class<? extends AggregatedRecord<?,?>> clz)
throws Exception {
AggregatedRecord<?,?> instance = clz.newInstance();
//limit filter key for accounting storage status (used from portlet accounting for tad space)
if (clz.equals(AggregatedStorageStatusRecord.class)){
SortedSet<String> storageStatus= new TreeSet<>();
public static SortedSet<String> getQuerableKeys(Class<? extends AggregatedRecord<?, ?>> clz) throws Exception {
AggregatedRecord<?, ?> instance = clz.newInstance();
// limit filter key for accounting storage status (used from portlet
// accounting for tad space)
if (clz.equals(AggregatedStorageStatusRecord.class)) {
SortedSet<String> storageStatus = new TreeSet<>();
storageStatus.add(AggregatedStorageStatusRecord.CONSUMER_ID);
storageStatus.add(AggregatedStorageStatusRecord.DATA_SERVICEID);
return storageStatus;
} else {
return instance.getQuerableKeys();
}
else{
return instance.getQuerableKeys();
}
}
public static String getDefaultOrderingProperties(
Class<? extends AggregatedRecord<?, ?>> clz){
if(clz.isAssignableFrom(AggregatedStorageUsageRecord.class)){
public static String getDefaultOrderingProperties(Class<? extends AggregatedRecord<?, ?>> clz) {
if (clz.isAssignableFrom(AggregatedStorageUsageRecord.class)) {
return AggregatedStorageUsageRecord.DATA_VOLUME;
}
return AggregatedRecord.OPERATION_COUNT;
}
protected static JSONObject getPaddingJSONObject(
Map<Calendar, Info> unpaddedResults) throws JSONException {
protected static JSONObject getPaddingJSONObject(Map<Calendar, Info> unpaddedResults) throws JSONException {
JSONObject jsonObject = new JSONObject();
//verify data consistency
if (unpaddedResults.size()!=0){
// verify data consistency
if (unpaddedResults.size() != 0) {
Info auxInfo = new ArrayList<Info>(unpaddedResults.values()).get(0);
JSONObject auxJsonObject = auxInfo.getValue();
@SuppressWarnings("unchecked")
@ -115,8 +108,7 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
* @throws Exception
* if fails
*/
public static SortedMap<Calendar, Info> padMap(
SortedMap<Calendar, Info> unpaddedData,
public static SortedMap<Calendar, Info> padMap(SortedMap<Calendar, Info> unpaddedData,
TemporalConstraint temporalConstraint) throws Exception {
JSONObject jsonObject = getPaddingJSONObject(unpaddedData);
@ -134,124 +126,95 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
/**
* {@inheritDoc}
*/
public SortedMap<Calendar, Info> getTimeSeries(
Class<? extends AggregatedRecord<?,?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters)
throws DuplicatedKeyFilterException, KeyException, ValueException,
Exception {
public SortedMap<Calendar, Info> getTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
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 {
SortedMap<Calendar, Info> ret =
AccountingPersistenceBackendQueryFactory.getInstance()
.getTimeSeries(clz, temporalConstraint,
filters);
public SortedMap<Calendar, Info> getTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
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){
if (ret == null) {
ret = new TreeMap<>();
}
if(pad){
if (pad) {
ret = padMap(ret, temporalConstraint);
}
return ret;
}
public SortedMap<Calendar, Info> getNoContextTimeSeries(
Class<? extends AggregatedRecord<?,?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters)
throws DuplicatedKeyFilterException, KeyException, ValueException,
Exception {
public SortedMap<Calendar, Info> getNoContextTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters)
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
return this.getNoContextTimeSeries(clz, temporalConstraint, filters, false);
}
public SortedMap<Calendar, Info> getNoContextTimeSeries(
Class<? extends AggregatedRecord<?,?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters,
boolean pad) throws DuplicatedKeyFilterException, KeyException,
ValueException, Exception {
SortedMap<Calendar, Info> ret =
AccountingPersistenceBackendQueryFactory.getInstance()
.getNoContextTimeSeries(clz, temporalConstraint,
filters);
public SortedMap<Calendar, Info> getNoContextTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters, boolean pad)
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
SortedMap<Calendar, Info> ret = AccountingPersistenceBackendQueryFactory.getInstance()
.getNoContextTimeSeries(clz, temporalConstraint, filters);
if(ret==null){
if (ret == null) {
ret = new TreeMap<>();
}
if(pad){
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 {
Class<? extends AggregatedRecord<?, ?>> clz, 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){
if (orderingProperty == null) {
orderingProperty = getDefaultOrderingProperties(clz);
}
got = AccountingPersistenceBackendQueryFactory.getInstance()
.getTopValues(clz, temporalConstraint, filters, topKey,
orderingProperty);
got = AccountingPersistenceBackendQueryFactory.getInstance().getTopValues(clz, temporalConstraint, filters,
topKey, orderingProperty);
int count = got.size() > limit ? limit : got.size();
NumberedFilter firstRemovalKey = null;
for(NumberedFilter nf : got.keySet()){
if(--count>=0 || limit<=0){
if(pad){
for (NumberedFilter nf : got.keySet()) {
if (--count >= 0 || limit <= 0) {
if (pad) {
padMap(got.get(nf), temporalConstraint);
}
}else{
if(firstRemovalKey==null){
} else {
if (firstRemovalKey == null) {
firstRemovalKey = nf;
}else{
} else {
break;
}
}
}
if(firstRemovalKey!=null){
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 {
String orderingProperty = AccountingPersistenceQuery
.getDefaultOrderingProperties(clz);
Class<? extends AggregatedRecord<?, ?>> clz, 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);
return this.getTopValues(clz, temporalConstraint, filters, topKey, orderingProperty, false, 0);
}
/**
@ -259,56 +222,42 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
*/
@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 {
return this.getTopValues(clz, temporalConstraint, filters, topKey,
orderingProperty, false, 0);
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
String topKey, String orderingProperty)
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
return this.getTopValues(clz, temporalConstraint, filters, topKey, orderingProperty, false, 0);
}
public SortedSet<NumberedFilter> getNextPossibleValues(
Class<? extends AggregatedRecord<?,?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters,
String key) throws DuplicatedKeyFilterException, KeyException,
ValueException, Exception {
public SortedSet<NumberedFilter> getNextPossibleValues(Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters, String key)
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
String orderingProperty = AccountingPersistenceQuery
.getDefaultOrderingProperties(clz);
String orderingProperty = AccountingPersistenceQuery.getDefaultOrderingProperties(clz);
return this.getNextPossibleValues(clz, temporalConstraint, filters,
key, orderingProperty);
return this.getNextPossibleValues(clz, temporalConstraint, filters, 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 {
public SortedSet<NumberedFilter> getNextPossibleValues(Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters, String key, String orderingProperty)
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
return AccountingPersistenceBackendQueryFactory.getInstance()
.getNextPossibleValues(clz, temporalConstraint, filters,
key, orderingProperty);
return AccountingPersistenceBackendQueryFactory.getInstance().getNextPossibleValues(clz, temporalConstraint,
filters, key, orderingProperty);
}
@Override
public SortedSet<NumberedFilter> getNextPossibleValuesWithMap(
Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters,
String key, String orderingProperty) throws Exception {
return AccountingPersistenceBackendQueryFactory.getInstance()
.getNextPossibleValuesWithMap(clz, temporalConstraint, filters,
key, orderingProperty);
public SortedSet<NumberedFilter> getNextPossibleValuesWithMap(Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters, String key, String orderingProperty)
throws Exception {
return AccountingPersistenceBackendQueryFactory.getInstance().getNextPossibleValuesWithMap(clz,
temporalConstraint, filters, key, orderingProperty);
}
/**
* {@inheritDoc}
*/
@ -321,154 +270,121 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
* {@inheritDoc}
*/
@Override
public void prepareConnection(
AccountingPersistenceBackendQueryConfiguration configuration)
throws Exception {
public void prepareConnection(AccountingPersistenceBackendQueryConfiguration configuration) throws Exception {
throw new InvalidActivityException();
}
@Override
public SortedSet<NumberedFilter> getFilterValues(
Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters,
String key) throws Exception {
return AccountingPersistenceBackendQueryFactory.getInstance()
.getFilterValues(clz, temporalConstraint, filters,
key);
public SortedSet<NumberedFilter> getFilterValues(Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters, String key) throws Exception {
return AccountingPersistenceBackendQueryFactory.getInstance().getFilterValues(clz, temporalConstraint, filters,
key);
}
@Override
public JSONObject getUsageValue(Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, Filter applicant)
throws Exception {
return AccountingPersistenceBackendQueryFactory.getInstance()
.getUsageValue(clz, temporalConstraint, applicant);
}
public JSONObject getUsageValue(Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint,
Filter applicant) throws Exception {
return AccountingPersistenceBackendQueryFactory.getInstance().getUsageValue(clz, temporalConstraint, applicant);
}
@Override
public List<UsageValue> getUsageValueQuotaTotal( List<UsageValue> listUsage)
throws Exception {
return AccountingPersistenceBackendQueryFactory.getInstance()
.getUsageValueQuotaTotal(listUsage);
public List<UsageValue> getUsageValueQuotaTotal(List<UsageValue> listUsage) throws Exception {
return AccountingPersistenceBackendQueryFactory.getInstance().getUsageValueQuotaTotal(listUsage);
}
@Override
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(
Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters,List<String> contexts)
throws Exception {
return AccountingPersistenceBackendQueryFactory.getInstance()
.getContextTimeSeries(clz, temporalConstraint, filters, contexts);
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
List<String> contexts) throws Exception {
return AccountingPersistenceBackendQueryFactory.getInstance().getContextTimeSeries(clz, temporalConstraint,
filters, contexts);
}
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(
Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters,
List<String> contexts, boolean pad)
throws DuplicatedKeyFilterException,
Exception {
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
List<String> contexts, boolean pad) throws DuplicatedKeyFilterException, Exception {
SortedMap<Filter, SortedMap<Calendar, Info>> got;
got = AccountingPersistenceBackendQueryFactory.getInstance()
.getContextTimeSeries(clz, temporalConstraint, filters, contexts);
got = AccountingPersistenceBackendQueryFactory.getInstance().getContextTimeSeries(clz, temporalConstraint,
filters, contexts);
int count = got.size();
Filter firstRemovalKey = null;
for(Filter nf : got.keySet()){
if(--count>=0){
if(pad){
for (Filter nf : got.keySet()) {
if (--count >= 0) {
if (pad) {
padMap(got.get(nf), temporalConstraint);
}
}else{
if(firstRemovalKey==null){
} else {
if (firstRemovalKey == null) {
firstRemovalKey = nf;
}else{
} else {
break;
}
}
}
if(firstRemovalKey!=null){
if (firstRemovalKey != null) {
return got.subMap(got.firstKey(), firstRemovalKey);
}
return got;
}
public String getRecord(String recordId, String type ) throws Exception {
String record= AccountingPersistenceBackendQueryFactory.getInstance().getRecord(recordId,type);
public String getRecord(String recordId, String type) throws Exception {
String record = AccountingPersistenceBackendQueryFactory.getInstance().getRecord(recordId, type);
return record;
}
@Override
public SortedSet<String> getSpaceProvidersIds() throws Exception{
SortedSet<String> providersId= AccountingPersistenceBackendQueryFactory.getInstance().getSpaceProvidersIds();
public SortedSet<String> getSpaceProvidersIds() throws Exception {
SortedSet<String> providersId = AccountingPersistenceBackendQueryFactory.getInstance().getSpaceProvidersIds();
return providersId;
}
@Override
public SortedMap<Filter, SortedMap<Calendar, Long>> getSpaceTimeSeries(
Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters,
List<String> providersId)
throws Exception {
SortedMap<Filter, SortedMap<Calendar, Long>> spaceTimeSeries=
AccountingPersistenceBackendQueryFactory.getInstance().getSpaceTimeSeries(clz, temporalConstraint, filters, providersId);
public SortedMap<Filter, SortedMap<Calendar, Long>> getSpaceTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters, List<String> providersId) throws Exception {
SortedMap<Filter, SortedMap<Calendar, Long>> spaceTimeSeries = AccountingPersistenceBackendQueryFactory
.getInstance().getSpaceTimeSeries(clz, temporalConstraint, filters, providersId);
int count = spaceTimeSeries.size();
Filter firstRemovalKey = null;
for(Filter nf : spaceTimeSeries.keySet()){
if(--count>=0){
for (Filter nf : spaceTimeSeries.keySet()) {
if (--count >= 0) {
padMapStorage(spaceTimeSeries.get(nf), temporalConstraint);
}else{
if(firstRemovalKey==null){
} else {
if (firstRemovalKey == null) {
firstRemovalKey = nf;
}else{
} else {
break;
}
}
}
if(firstRemovalKey!=null){
if (firstRemovalKey != null) {
return spaceTimeSeries.subMap(spaceTimeSeries.firstKey(), firstRemovalKey);
}
return spaceTimeSeries;
}
public SortedMap<Calendar, Long> padMapStorage(
SortedMap<Calendar, Long> unpaddedData,
public SortedMap<Calendar, Long> padMapStorage(SortedMap<Calendar, Long> unpaddedData,
TemporalConstraint temporalConstraint) throws Exception {
SortedSet<Calendar> sequence = temporalConstraint.getCalendarSequence();
Long longValuePre = null;
for (Calendar progressTime : sequence) {
Long longValue = unpaddedData.get(progressTime);
if (longValue == null) {
unpaddedData.put(progressTime, longValuePre);
}else{
longValuePre=longValue;
} else {
longValuePre = longValue;
}
}
return unpaddedData;
}
@ -478,7 +394,4 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
return AccountingPersistenceBackendQueryFactory.getInstance().isConnectionActive();
}
}