diff --git a/.classpath b/.classpath index c7d03c1..a9540ac 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -45,5 +45,5 @@ - + diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index e6d61c1..1a07e40 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -4,10 +4,7 @@ - - uses - - + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml b/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml deleted file mode 100644 index cc81385..0000000 --- a/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml index a7b456a..735eb31 100644 --- a/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -3,6 +3,5 @@ - diff --git a/pom.xml b/pom.xml index 6b48068..6eda59b 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ 4.0.0 org.gcube.portlets.admin accounting-manager - 1.1.0-SNAPSHOT + 1.2.0-SNAPSHOT war @@ -225,7 +225,7 @@ org.gcube.accounting accounting-analytics - [1.1.0-SNAPSHOT,2.0.0-SNAPSHOT) + [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT) @@ -240,7 +240,7 @@ org.gcube.accounting accounting-analytics-persistence-couchdb - [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) + [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT) diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/AccountingManagerServiceImpl.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/AccountingManagerServiceImpl.java index 8dc0af4..ba94672 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/AccountingManagerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/AccountingManagerServiceImpl.java @@ -9,7 +9,6 @@ import org.gcube.application.framework.core.session.ASLSession; import org.gcube.portlets.admin.accountingmanager.client.rpc.AccountingManagerService; import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCaller; import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCallerInterface; -import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCallerTester; import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue; @@ -89,7 +88,7 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet try { HttpSession session = this.getThreadLocalRequest().getSession(); SessionUtil.getAslSession(session); - AccountingCallerInterface accountingCaller = new AccountingCallerTester(); + AccountingCallerInterface accountingCaller = new AccountingCaller(); SeriesResponse seriesResponse = accountingCaller.getSeries( accountingType, seriesRequest); @@ -117,7 +116,7 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet HttpSession session = this.getThreadLocalRequest().getSession(); SessionUtil.getAslSession(session); - AccountingCallerInterface accountingCaller = new AccountingCallerTester(); + AccountingCallerInterface accountingCaller = new AccountingCaller(); ArrayList filterKeys = accountingCaller.getFilterKeys(accountingType); return filterKeys; @@ -145,7 +144,7 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet HttpSession session = this.getThreadLocalRequest().getSession(); SessionUtil.getAslSession(session); - AccountingCallerInterface accountingCaller = new AccountingCallerTester(); + AccountingCallerInterface accountingCaller = new AccountingCaller(); ArrayList filterValues = accountingCaller.getFilterValues(filterValuesRequest); return filterValues; diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/SessionUtil.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/SessionUtil.java index 564ae05..70023e4 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/SessionUtil.java @@ -8,7 +8,6 @@ import javax.servlet.http.HttpSession; import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.SessionManager; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; -import org.gcube.portlets.admin.accountingmanager.shared.Constants; import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerSessionExpiredException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,9 +29,9 @@ public class SessionUtil { ASLSession session; if (username == null) { logger.warn("no user found in session, use test user"); - /*throw new AccountingManagerSessionExpiredException("Session Expired!");*/ - + throw new AccountingManagerSessionExpiredException("Session Expired!"); + /* // Remove comment for Test username = Constants.DEFAULT_USER; String scope = Constants.DEFAULT_SCOPE; @@ -41,7 +40,7 @@ public class SessionUtil { session = SessionManager.getInstance().getASLSession( httpSession.getId(), username); session.setScope(scope); - + */ } else { session = SessionManager.getInstance().getASLSession( httpSession.getId(), username); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCaller.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCaller.java index dd3e91b..5df335a 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCaller.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCaller.java @@ -82,7 +82,7 @@ public class AccountingCaller implements AccountingCallerInterface { return accountingCommandBasic.execute(); case Top: AccountingQueryTop accountingQueryTop = (AccountingQueryTop) query; - AccountingCommandTop accountingCommandTop=new AccountingCommandTop(accountingQueryTop,accountingType, seriesRequest); + AccountingCommandTop accountingCommandTop=new AccountingCommandTop(accountingQueryTop,accountingType); return accountingCommandTop.execute(); default: throw new AccountingManagerServiceException( diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandBasic.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandBasic.java index 1d38826..552b84c 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandBasic.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandBasic.java @@ -1,9 +1,13 @@ package org.gcube.portlets.admin.accountingmanager.server.amservice.command; +import java.util.ArrayList; +import java.util.Calendar; import java.util.List; +import java.util.SortedMap; import org.gcube.accounting.analytics.Info; -import org.gcube.accounting.analytics.ResourceRecordQuery; +import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery; +import org.gcube.accounting.analytics.persistence.AccountingPersistenceQueryFactory; import org.gcube.portlets.admin.accountingmanager.server.amservice.query.AccountingQueryBasic; import org.gcube.portlets.admin.accountingmanager.server.amservice.response.SeriesResponse4JobBasic; import org.gcube.portlets.admin.accountingmanager.server.amservice.response.SeriesResponse4PortletBasic; @@ -39,14 +43,19 @@ public class AccountingCommandBasic implements AccountingCommand @Override public SeriesResponse execute() throws AccountingManagerServiceException { try { - ResourceRecordQuery rrq = new ResourceRecordQuery(); + AccountingPersistenceQuery apq = AccountingPersistenceQueryFactory.getInstance(); - List infos = rrq.getInfo(accountingQueryBasic.getType(), - accountingQueryBasic.getTemporalConstraint(), accountingQueryBasic.getFilters(), true); - if (infos == null) { + SortedMap sm = apq.getTimeSeries( + accountingQueryBasic.getType(), + accountingQueryBasic.getTemporalConstraint(), + accountingQueryBasic.getFilters(), true); + + if (sm == null || sm.values()==null) { throw new AccountingManagerServiceException( - "Error retrieving list of info: list is null!"); + "Error retrieving info: sorted map is null!"); } + + List infos = new ArrayList<>(sm.values()); logger.debug("Retrieved Infos"); logger.debug("Infos: " + infos); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandGetFilterKeys.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandGetFilterKeys.java index 28ce69e..8b02364 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandGetFilterKeys.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandGetFilterKeys.java @@ -1,9 +1,9 @@ package org.gcube.portlets.admin.accountingmanager.server.amservice.command; import java.util.ArrayList; -import java.util.List; +import java.util.SortedSet; -import org.gcube.accounting.analytics.ResourceRecordQuery; +import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery; import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord; @@ -38,22 +38,21 @@ public class AccountingCommandGetFilterKeys implements AccountingCommand(); } ArrayList filterKeys = new ArrayList(); - List keys; + SortedSet keys; - ResourceRecordQuery rrq = new ResourceRecordQuery(); switch (accountingType) { case JOB: - keys = rrq.getKeys(AggregatedJobUsageRecord.class); + keys = AccountingPersistenceQuery.getQuerableKeys(AggregatedJobUsageRecord.class); break; case PORTLET: // keys=rrq.getKeys(AggregatedPortletUsageRecord.class); return filterKeys; case SERVICE: - keys = rrq.getKeys(AggregatedServiceUsageRecord.class); + keys = AccountingPersistenceQuery.getQuerableKeys(AggregatedServiceUsageRecord.class); break; case STORAGE: - keys = rrq.getKeys(AggregatedStorageUsageRecord.class); + keys =AccountingPersistenceQuery.getQuerableKeys(AggregatedStorageUsageRecord.class); break; case TASK: // keys=rrq.getKeys(AggregatedTaskUsageRecord.class); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandGetFilterValues.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandGetFilterValues.java index 21b0745..94869dd 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandGetFilterValues.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandGetFilterValues.java @@ -1,9 +1,16 @@ package org.gcube.portlets.admin.accountingmanager.server.amservice.command; import java.util.ArrayList; +import java.util.GregorianCalendar; import java.util.List; +import java.util.Set; -import org.gcube.accounting.analytics.ResourceRecordQuery; +import org.gcube.accounting.analytics.Filter; +import org.gcube.accounting.analytics.NumberedFilter; +import org.gcube.accounting.analytics.TemporalConstraint; +import org.gcube.accounting.analytics.TemporalConstraint.AggregationMode; +import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery; +import org.gcube.accounting.analytics.persistence.AccountingPersistenceQueryFactory; import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord; @@ -15,23 +22,26 @@ import org.slf4j.LoggerFactory; /** * - * @author Giancarlo Panichi - * email: g.panichi@isti.cnr.it + * @author Giancarlo Panichi email: g.panichi@isti.cnr.it * */ -public class AccountingCommandGetFilterValues implements AccountingCommand> { - private static final Logger logger = LoggerFactory.getLogger(AccountingCommandGetFilterValues.class); - +public class AccountingCommandGetFilterValues implements + AccountingCommand> { + private static final Logger logger = LoggerFactory + .getLogger(AccountingCommandGetFilterValues.class); + private FilterValuesRequest filterValuesRequest; - - public AccountingCommandGetFilterValues(FilterValuesRequest filterValuesRequest){ - this.filterValuesRequest=filterValuesRequest; - + + public AccountingCommandGetFilterValues( + FilterValuesRequest filterValuesRequest) { + this.filterValuesRequest = filterValuesRequest; + } - - + @Override - public ArrayList execute() throws AccountingManagerServiceException { + public ArrayList execute() + throws AccountingManagerServiceException { try { logger.debug("getFilterValue(): [FilterValueRequest=" + filterValuesRequest + "]"); @@ -42,30 +52,45 @@ public class AccountingCommandGetFilterValues implements AccountingCommand filteValues = new ArrayList(); - List values; + + + Set values; - ResourceRecordQuery rrq = new ResourceRecordQuery(); + AccountingPersistenceQuery apq = AccountingPersistenceQueryFactory + .getInstance(); + + + + GregorianCalendar startDate = new GregorianCalendar(); + GregorianCalendar endDate = new GregorianCalendar(); + endDate.add(GregorianCalendar.YEAR, -3); + + TemporalConstraint tc = new TemporalConstraint( + startDate.getTimeInMillis(), endDate.getTimeInMillis(), + AggregationMode.YEARLY); + + List filters = new ArrayList<>(); + Filter filterForValue = new Filter(filterValuesRequest + .getFilterKey().getKey(), null); + filters.add(filterForValue); switch (filterValuesRequest.getAccountingType()) { case JOB: - values = rrq.getPossibleValuesForKey( - AggregatedJobUsageRecord.class, filterValuesRequest - .getFilterKey().getKey()); - return filteValues; + values = apq.getNextPossibleValues( + AggregatedJobUsageRecord.class, tc, filters); + break; case PORTLET: // values = rrq.getPossibleValuesForKey( // AggregatedPortletUsageRecord.class, filterValuesRequest // .getFilterKey().getKey()); return filteValues; case SERVICE: - values = rrq.getPossibleValuesForKey( - AggregatedServiceUsageRecord.class, filterValuesRequest - .getFilterKey().getKey()); + values = apq.getNextPossibleValues( + AggregatedServiceUsageRecord.class, tc, filters); break; case STORAGE: - values = rrq.getPossibleValuesForKey( - AggregatedStorageUsageRecord.class, filterValuesRequest - .getFilterKey().getKey()); + values = apq.getNextPossibleValues( + AggregatedStorageUsageRecord.class, tc, filters); break; case TASK: // values = rrq.getPossibleValuesForKey( @@ -75,9 +100,12 @@ public class AccountingCommandGetFilterValues implements AccountingCommandg.panichi@isti.cnr.it + * @author Giancarlo Panichi email: g.panichi@isti.cnr.it * */ public class AccountingCommandTop implements AccountingCommand { - private static final Logger logger = LoggerFactory.getLogger(AccountingCommandTop.class); - + private static final Logger logger = LoggerFactory + .getLogger(AccountingCommandTop.class); + private AccountingQueryTop accountingQueryTop; private AccountingType accountingType; - private SeriesRequest seriesRequest; - public AccountingCommandTop(AccountingQueryTop accountingQueryTop, AccountingType accountingType, SeriesRequest seriesRequest){ - this.accountingQueryTop=accountingQueryTop; - this.accountingType=accountingType; - this.seriesRequest=seriesRequest; + + public AccountingCommandTop(AccountingQueryTop accountingQueryTop, + AccountingType accountingType) { + this.accountingQueryTop = accountingQueryTop; + this.accountingType = accountingType; } - - + @Override public SeriesResponse execute() throws AccountingManagerServiceException { try { - ResourceRecordQuery rrq = new ResourceRecordQuery(); - - /* - List infos = rrq.getInfo(accountingQueryBasic.getType(), - accountingQueryBasic.getTemporalConstraint(), accountingQueryBasic.getFilters(), true); - if (infos == null) { + AccountingPersistenceQuery apq = AccountingPersistenceQueryFactory + .getInstance(); + + ArrayList filters = new ArrayList<>( + accountingQueryTop.getFilters()); + Filter filterKey = new Filter(accountingQueryTop.getFilterKey() + .getKey(), null); + + filters.add(filterKey); + + SortedMap> topSM = apq + .getTopValues(accountingQueryTop.getType(), + accountingQueryTop.getTemporalConstraint(), + filters, null, true, + accountingQueryTop.getTopNumber()); + + if (topSM == null) { throw new AccountingManagerServiceException( - "Error retrieving list of info: list is null!"); + "Error retrieving info for top: sorted map is null!"); } - logger.debug("Retrieved Infos"); - logger.debug("Infos: " + infos); - */ - - /*SeriesResponseBuilder seriesResponseBuilder = getSeriesResponseBuilder( - accountingType, infos); + + + SeriesResponseBuilder seriesResponseBuilder = getSeriesResponseBuilder( + accountingType, topSM); SeriesResponseDirector seriesResponseDirector = new SeriesResponseDirector(); seriesResponseDirector @@ -75,18 +84,18 @@ public class AccountingCommandTop implements AccountingCommand { } logger.debug("SeriesResponse Created: " + seriesResponse); return seriesResponse; - */ - return null; + } catch (Throwable e) { - logger.error("Error in AccountingCommandTop(): " + e.getLocalizedMessage()); + logger.error("Error in AccountingCommandTop(): " + + e.getLocalizedMessage()); e.printStackTrace(); throw new AccountingManagerServiceException("No data available!"); } } - + private SeriesResponseBuilder getSeriesResponseBuilder( - AccountingType accountingType, List infos) + AccountingType accountingType, SortedMap> topSM) throws AccountingManagerServiceException { if (accountingType == null) { throw new AccountingManagerServiceException( @@ -95,21 +104,20 @@ public class AccountingCommandTop implements AccountingCommand { switch (accountingType) { case JOB: - return new SeriesResponse4JobTop(infos); + return new SeriesResponse4JobTop(topSM); case PORTLET: - return new SeriesResponse4PortletTop(infos); + return new SeriesResponse4PortletTop(topSM); case SERVICE: - return new SeriesResponse4ServiceTop(infos); + return new SeriesResponse4ServiceTop(topSM); case STORAGE: - return new SeriesResponse4StorageTop(infos); + return new SeriesResponse4StorageTop(topSM); case TASK: - return new SeriesResponse4TaskTop(infos); + return new SeriesResponse4TaskTop(topSM); default: throw new AccountingManagerServiceException( "Error request type is unknow!"); } } - } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQueryBasic.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQueryBasic.java index 019d49e..8591595 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQueryBasic.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQueryBasic.java @@ -15,14 +15,13 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.ChartType; * href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it * */ -@SuppressWarnings("rawtypes") public class AccountingQueryBasic extends AccountingQuery { - private Class type; + private Class> type; private TemporalConstraint temporalConstraint; private ArrayList filters; - public AccountingQueryBasic(Class type, + public AccountingQueryBasic(Class> type, TemporalConstraint temporalConstraint, ArrayList filters) { super(); chartType=ChartType.Basic; @@ -31,11 +30,11 @@ public class AccountingQueryBasic extends AccountingQuery { this.filters = filters; } - public Class getType() { + public Class> getType() { return type; } - public void setType(Class type) { + public void setType(Class> type) { this.type = type; } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQueryTop.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQueryTop.java index 488b098..b92ff15 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQueryTop.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQueryTop.java @@ -14,15 +14,14 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey; * href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it * */ -@SuppressWarnings("rawtypes") public class AccountingQueryTop extends AccountingQuery { - private Class type; + private Class> type; private FilterKey filterKey; private Integer topNumber; private TemporalConstraint temporalConstraint; private ArrayList filters; - public AccountingQueryTop(Class type, + public AccountingQueryTop(Class> type, FilterKey filterKey, Integer topNumber, TemporalConstraint temporalConstraint, ArrayList filters) { super(); @@ -34,11 +33,11 @@ public class AccountingQueryTop extends AccountingQuery { this.topNumber = topNumber; } - public Class getType() { + public Class> getType() { return type; } - public void setType(Class type) { + public void setType(Class> type) { this.type = type; } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4JobTop.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4JobTop.java index 8682c32..f4a5b98 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4JobTop.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4JobTop.java @@ -1,20 +1,24 @@ package org.gcube.portlets.admin.accountingmanager.server.amservice.response; import java.util.ArrayList; -import java.util.List; +import java.util.Calendar; +import java.util.SortedMap; import org.gcube.accounting.analytics.Info; +import org.gcube.accounting.analytics.NumberedFilter; import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord; +import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesJob; -import org.gcube.portlets.admin.accountingmanager.shared.data.response.job.SeriesJobBasic; import org.gcube.portlets.admin.accountingmanager.shared.data.response.job.SeriesJobData; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.job.SeriesJobDataTop; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.job.SeriesJobTop; import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Series Response 4 Job Basic + * Top Series Response 4 Job * * @author "Giancarlo Panichi" email: g.panichi@isti.cnr.it @@ -23,44 +27,61 @@ import org.slf4j.LoggerFactory; public class SeriesResponse4JobTop extends SeriesResponseBuilder { protected static Logger logger = LoggerFactory .getLogger(SeriesResponse4JobTop.class); - private List infos; + private SortedMap> topSM; - public SeriesResponse4JobTop(List infos) { - this.infos=infos; + public SeriesResponse4JobTop( + SortedMap> topSM) { + this.topSM = topSM; } @Override public void buildSeriesResponse() throws AccountingManagerServiceException { try { - if(infos.size()<=0){ + if (topSM == null || topSM.isEmpty()) { logger.error("Error creating series for job accounting: No data available!"); - throw new AccountingManagerServiceException("No data available!"); - } - - ArrayList series=new ArrayList(); - for (Info info : infos) { - JSONObject jso = info.getValue(); - //Long duration = jso.getLong(AggregatedJobUsageRecord.DURATION); - Long operationCount = jso - .getLong(AggregatedJobUsageRecord.OPERATION_COUNT); - //Long maxInvocationTime = jso.getLong(AggregatedServiceUsageRecord.MAX_INVOCATION_TIME); - //Long minInvocationTime = jso.getLong(AggregatedServiceUsageRecord.MIN_INVOCATION_TIME); - - series.add(new SeriesJobData(info.getCalendar().getTime(), - operationCount, operationCount, operationCount, - operationCount)); - + throw new AccountingManagerServiceException( + "No data available!"); } - SeriesJobBasic seriesJobBasic=new SeriesJobBasic(series); - - SeriesJob seriesJob = new SeriesJob(seriesJobBasic); + ArrayList seriesJobDataTopList = new ArrayList<>(); + + for (NumberedFilter topValue : topSM.keySet()) { + + ArrayList series = new ArrayList<>(); + SortedMap infos = topSM.get(topValue); + for (Info info : infos.values()) { + JSONObject jso = info.getValue(); + // Long duration = + // jso.getLong(AggregatedJobUsageRecord.DURATION); + Long operationCount = jso + .getLong(AggregatedJobUsageRecord.OPERATION_COUNT); + // Long maxInvocationTime = + // jso.getLong(AggregatedJobUsageRecord.MAX_INVOCATION_TIME); + // Long minInvocationTime = + // jso.getLong(AggregatedJobUsageRecord.MIN_INVOCATION_TIME); + + series.add(new SeriesJobData(info.getCalendar().getTime(), + operationCount, operationCount, operationCount, + operationCount)); + } + SeriesJobDataTop seriesJobDataTop = new SeriesJobDataTop( + new FilterValue(topValue.getValue()), series); + seriesJobDataTopList.add(seriesJobDataTop); + + } + + SeriesJobTop seriesJobTop = new SeriesJobTop(seriesJobDataTopList); + SeriesJob seriesJob = new SeriesJob(seriesJobTop); seriesResponseSpec.setSr(seriesJob); + } catch (Throwable e) { - logger.error("Error creating series for job accounting basic chart: "+e.getLocalizedMessage()); + logger.error("Error creating series for job accounting top chart: " + + e.getLocalizedMessage()); e.printStackTrace(); - throw new AccountingManagerServiceException("Error creating series for job accounting basic chart: "+e.getLocalizedMessage()); + throw new AccountingManagerServiceException( + "Error creating series for job accounting top chart: " + + e.getLocalizedMessage()); } } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4PortletTop.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4PortletTop.java index 5e59b01..41aa4a8 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4PortletTop.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4PortletTop.java @@ -1,15 +1,24 @@ package org.gcube.portlets.admin.accountingmanager.server.amservice.response; -import java.util.List; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.SortedMap; import org.gcube.accounting.analytics.Info; -import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse; +import org.gcube.accounting.analytics.NumberedFilter; +import org.gcube.accounting.datamodel.aggregation.AggregatedPortletUsageRecord; +import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesPortlet; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.portlet.SeriesPortletData; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.portlet.SeriesPortletDataTop; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.portlet.SeriesPortletTop; import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Series Response 4 Portlet Basic + * Top Series Response 4 Portlet * * @author "Giancarlo Panichi" email: g.panichi@isti.cnr.it @@ -19,25 +28,59 @@ public class SeriesResponse4PortletTop extends SeriesResponseBuilder { protected static Logger logger = LoggerFactory .getLogger(SeriesResponse4PortletTop.class); - private List infos; + private SortedMap> topSM; - public SeriesResponse4PortletTop(List infos) { - this.infos=infos; + public SeriesResponse4PortletTop(SortedMap> topSM) { + this.topSM=topSM; } @Override public void buildSeriesResponse() throws AccountingManagerServiceException { - if(infos.size()<=0){ - logger.error("Error creating series for portlet accounting: No data available!"); - throw new AccountingManagerServiceException("No data available!"); + try { + if (topSM == null || topSM.isEmpty()) { + logger.error("Error creating series for portlet accounting: No data available!"); + throw new AccountingManagerServiceException( + "No data available!"); + } + + ArrayList seriesPortletDataTopList = new ArrayList<>(); + + for (NumberedFilter topValue : topSM.keySet()) { + + ArrayList series = new ArrayList<>(); + SortedMap infos = topSM.get(topValue); + for (Info info : infos.values()) { + JSONObject jso = info.getValue(); + // Long duration = + // jso.getLong(AggregatedPortletUsageRecord.DURATION); + Long operationCount = jso + .getLong(AggregatedPortletUsageRecord.OPERATION_COUNT); + // Long maxInvocationTime = + // jso.getLong(AggregatedPortletUsageRecord.MAX_INVOCATION_TIME); + // Long minInvocationTime = + // jso.getLong(AggregatedPortletUsageRecord.MIN_INVOCATION_TIME); + + series.add(new SeriesPortletData(info.getCalendar().getTime(), + operationCount)); + } + SeriesPortletDataTop seriesPortletDataTop = new SeriesPortletDataTop( + new FilterValue(topValue.getValue()), series); + seriesPortletDataTopList.add(seriesPortletDataTop); + + } + + SeriesPortletTop seriesPortletTop = new SeriesPortletTop(seriesPortletDataTopList); + SeriesPortlet seriesPortlet = new SeriesPortlet(seriesPortletTop); + + seriesResponseSpec.setSr(seriesPortlet); + + } catch (Throwable e) { + logger.error("Error creating series for portlet accounting top chart: " + + e.getLocalizedMessage()); + e.printStackTrace(); + throw new AccountingManagerServiceException( + "Error creating series for portlet accounting top chart: " + + e.getLocalizedMessage()); } - - //SeriesPortletBasic seriesPortletBasic=new SeriesPortletBasic(series); - //SeriesPortlet seriesPortlet = new SeriesPortlet(seriesPortletBasic); - - SeriesResponse seriesResponse = new SeriesResponse(); - - seriesResponseSpec.setSr(seriesResponse); - } } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4ServiceTop.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4ServiceTop.java index 3fc4a9d..2e6b1d6 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4ServiceTop.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4ServiceTop.java @@ -1,20 +1,24 @@ package org.gcube.portlets.admin.accountingmanager.server.amservice.response; import java.util.ArrayList; -import java.util.List; +import java.util.Calendar; +import java.util.SortedMap; import org.gcube.accounting.analytics.Info; +import org.gcube.accounting.analytics.NumberedFilter; import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord; +import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesService; -import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceBasic; import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceData; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceDataTop; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceTop; import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Series Response 4 Service Basic + * Top Series Response 4 Service * * @author "Giancarlo Panichi" email: g.panichi@isti.cnr.it @@ -23,42 +27,63 @@ import org.slf4j.LoggerFactory; public class SeriesResponse4ServiceTop extends SeriesResponseBuilder { protected static Logger logger = LoggerFactory .getLogger(SeriesResponse4ServiceTop.class); - private List infos; + private SortedMap> topSM; - public SeriesResponse4ServiceTop(List infos) { - this.infos=infos; + public SeriesResponse4ServiceTop( + SortedMap> topSM) { + this.topSM = topSM; } @Override public void buildSeriesResponse() throws AccountingManagerServiceException { try { - if(infos.size()<=0){ + if (topSM == null || topSM.isEmpty()) { logger.error("Error creating series for service accounting: No data available!"); - throw new AccountingManagerServiceException("No data available!"); - } - - ArrayList series=new ArrayList(); - for (Info info : infos) { - JSONObject jso = info.getValue(); - Long duration = jso.getLong(AggregatedServiceUsageRecord.DURATION); - Long operationCount = jso - .getLong(AggregatedServiceUsageRecord.OPERATION_COUNT); - Long maxInvocationTime = jso.getLong(AggregatedServiceUsageRecord.MAX_INVOCATION_TIME); - Long minInvocationTime = jso.getLong(AggregatedServiceUsageRecord.MIN_INVOCATION_TIME); - - series.add(new SeriesServiceData(info.getCalendar().getTime(), operationCount, duration, maxInvocationTime, minInvocationTime)); - + throw new AccountingManagerServiceException( + "No data available!"); } - SeriesServiceBasic seriesServiceBasic=new SeriesServiceBasic(series); - - SeriesService seriesService = new SeriesService(seriesServiceBasic); + ArrayList seriesServiceDataTopList = new ArrayList<>(); + + for (NumberedFilter topValue : topSM.keySet()) { + + ArrayList series = new ArrayList<>(); + SortedMap infos = topSM.get(topValue); + for (Info info : infos.values()) { + JSONObject jso = info.getValue(); + Long duration = jso + .getLong(AggregatedServiceUsageRecord.DURATION); + Long operationCount = jso + .getLong(AggregatedServiceUsageRecord.OPERATION_COUNT); + Long maxInvocationTime = jso + .getLong(AggregatedServiceUsageRecord.MAX_INVOCATION_TIME); + Long minInvocationTime = jso + .getLong(AggregatedServiceUsageRecord.MIN_INVOCATION_TIME); + + series.add(new SeriesServiceData(info.getCalendar() + .getTime(), operationCount, duration, + maxInvocationTime, minInvocationTime)); + + } + SeriesServiceDataTop seriesServiceDataTop = new SeriesServiceDataTop( + new FilterValue(topValue.getValue()), series); + seriesServiceDataTopList.add(seriesServiceDataTop); + + } + + SeriesServiceTop seriesServiceTop = new SeriesServiceTop( + seriesServiceDataTopList); + SeriesService seriesService = new SeriesService(seriesServiceTop); seriesResponseSpec.setSr(seriesService); + } catch (Throwable e) { - logger.error("Error creating series for service accounting chart basic: "+e.getLocalizedMessage()); + logger.error("Error creating series for service accounting top chart: " + + e.getLocalizedMessage()); e.printStackTrace(); - throw new AccountingManagerServiceException("Error creating series for service accounting chart basic: "+e.getLocalizedMessage()); + throw new AccountingManagerServiceException( + "Error creating series for service accounting top chart: " + + e.getLocalizedMessage()); } } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4StorageTop.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4StorageTop.java index a500472..9d9783a 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4StorageTop.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4StorageTop.java @@ -1,9 +1,11 @@ package org.gcube.portlets.admin.accountingmanager.server.amservice.response; import java.util.ArrayList; -import java.util.List; +import java.util.Calendar; +import java.util.SortedMap; import org.gcube.accounting.analytics.Info; +import org.gcube.accounting.analytics.NumberedFilter; import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage; @@ -16,8 +18,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Series Response 4 Storage Top - * + * Top Series Response 4 Storage + * * @author "Giancarlo Panichi" email: g.panichi@isti.cnr.it * @@ -25,33 +27,40 @@ import org.slf4j.LoggerFactory; public class SeriesResponse4StorageTop extends SeriesResponseBuilder { protected static Logger logger = LoggerFactory .getLogger(SeriesResponse4StorageTop.class); - private List infos; + private SortedMap> topSM; - public SeriesResponse4StorageTop(List infos) { - this.infos = infos; + public SeriesResponse4StorageTop(SortedMap> topSM) { + this.topSM=topSM; } @Override public void buildSeriesResponse() throws AccountingManagerServiceException { try { - if(infos.size()<=0){ + if(topSM==null||topSM.isEmpty()){ logger.error("Error creating series for storage accounting: No data available!"); throw new AccountingManagerServiceException("No data available!"); } - - ArrayList series=new ArrayList(); - for (Info info : infos) { - JSONObject jso = info.getValue(); - Long dataVolume = jso.getLong(AggregatedStorageUsageRecord.DATA_VOLUME); - Long operationCount = jso - .getLong(AggregatedStorageUsageRecord.OPERATION_COUNT); - series.add(new SeriesStorageData(info.getCalendar().getTime(), dataVolume, operationCount)); - - } - + ArrayList seriesStorageDataTopList=new ArrayList<>(); - SeriesStorageDataTop seriesStorageDataTop=new SeriesStorageDataTop(new FilterValue("giancarlo.panichi"), series); - seriesStorageDataTopList.add(seriesStorageDataTop); + + for(NumberedFilter topValue:topSM.keySet()){ + + ArrayList series=new ArrayList<>(); + SortedMap infos=topSM.get(topValue); + for (Info info : infos.values()) { + JSONObject jso = info.getValue(); + Long dataVolume = jso.getLong(AggregatedStorageUsageRecord.DATA_VOLUME); + Long operationCount = jso + .getLong(AggregatedStorageUsageRecord.OPERATION_COUNT); + series.add(new SeriesStorageData(info.getCalendar().getTime(), dataVolume, operationCount)); + + } + SeriesStorageDataTop seriesStorageDataTop=new SeriesStorageDataTop( + new FilterValue(topValue.getValue()), series); + seriesStorageDataTopList.add(seriesStorageDataTop); + + } + SeriesStorageTop seriesStorageTop=new SeriesStorageTop(seriesStorageDataTopList); SeriesStorage seriesStorage = new SeriesStorage(seriesStorageTop); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4TaskTop.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4TaskTop.java index 562c45a..6c08197 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4TaskTop.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4TaskTop.java @@ -1,15 +1,24 @@ package org.gcube.portlets.admin.accountingmanager.server.amservice.response; -import java.util.List; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.SortedMap; import org.gcube.accounting.analytics.Info; -import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse; +import org.gcube.accounting.analytics.NumberedFilter; +import org.gcube.accounting.datamodel.aggregation.AggregatedTaskUsageRecord; +import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesTask; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.task.SeriesTaskData; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.task.SeriesTaskDataTop; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.task.SeriesTaskTop; import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Series Response 4 Task Basic + * Top Series Response 4 Task * * @author "Giancarlo Panichi" email: g.panichi@isti.cnr.it @@ -18,25 +27,59 @@ import org.slf4j.LoggerFactory; public class SeriesResponse4TaskTop extends SeriesResponseBuilder { protected static Logger logger = LoggerFactory .getLogger(SeriesResponse4TaskTop.class); - private List infos; + private SortedMap> topSM; - public SeriesResponse4TaskTop(List infos) { - this.infos=infos; + public SeriesResponse4TaskTop(SortedMap> topSM) { + this.topSM=topSM; } @Override public void buildSeriesResponse() throws AccountingManagerServiceException { - if(infos.size()<=0){ - logger.error("Error creating series for task accounting: No data available!"); - throw new AccountingManagerServiceException("No data available!"); + try { + if (topSM == null || topSM.isEmpty()) { + logger.error("Error creating series for task accounting: No data available!"); + throw new AccountingManagerServiceException( + "No data available!"); + } + + ArrayList seriesTaskDataTopList = new ArrayList<>(); + + for (NumberedFilter topValue : topSM.keySet()) { + + ArrayList series = new ArrayList<>(); + SortedMap infos = topSM.get(topValue); + for (Info info : infos.values()) { + JSONObject jso = info.getValue(); + // Long duration = + // jso.getLong(AggregatedTaskUsageRecord.DURATION); + Long operationCount = jso + .getLong(AggregatedTaskUsageRecord.OPERATION_COUNT); + // Long maxInvocationTime = + // jso.getLong(AggregatedTaskUsageRecord.MAX_INVOCATION_TIME); + // Long minInvocationTime = + // jso.getLong(AggregatedTaskUsageRecord.MIN_INVOCATION_TIME); + + series.add(new SeriesTaskData(info.getCalendar().getTime(), + operationCount)); + } + SeriesTaskDataTop seriesTaskDataTop = new SeriesTaskDataTop( + new FilterValue(topValue.getValue()), series); + seriesTaskDataTopList.add(seriesTaskDataTop); + + } + + SeriesTaskTop seriesTaskTop = new SeriesTaskTop(seriesTaskDataTopList); + SeriesTask seriesTask = new SeriesTask(seriesTaskTop); + + seriesResponseSpec.setSr(seriesTask); + + } catch (Throwable e) { + logger.error("Error creating series for portlet accounting top chart: " + + e.getLocalizedMessage()); + e.printStackTrace(); + throw new AccountingManagerServiceException( + "Error creating series for portlet accounting top chart: " + + e.getLocalizedMessage()); } - - //SeriesTaskBasic seriesTaskBasic=new SeriesTaskBasic(series); - //SeriesTask seriesTask = new SeriesTask(seriesTaskBasic); - - SeriesResponse seriesResponse = new SeriesResponse(); - - seriesResponseSpec.setSr(seriesResponse); - } }