63 lines
2.2 KiB
Java
63 lines
2.2 KiB
Java
package org.gcube.portlets.admin.accountingmanager.server.amservice.response;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.gcube.accounting.analytics.Info;
|
|
import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord;
|
|
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesJob;
|
|
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesJobData;
|
|
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
|
|
*
|
|
* @author "Giancarlo Panichi" email: <a
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
*
|
|
*/
|
|
public class SeriesResponse4Job extends SeriesResponseBuilder {
|
|
protected static Logger logger = LoggerFactory
|
|
.getLogger(SeriesResponse4Job.class);
|
|
private List<Info> infos;
|
|
|
|
public SeriesResponse4Job(List<Info> infos) {
|
|
this.infos=infos;
|
|
}
|
|
|
|
@Override
|
|
public void buildSeriesResponse() throws AccountingManagerServiceException {
|
|
try {
|
|
if(infos.size()<=0){
|
|
logger.error("Error creating series for job accounting: No data available!");
|
|
throw new AccountingManagerServiceException("No data available!");
|
|
}
|
|
|
|
ArrayList<SeriesJobData> series=new ArrayList<SeriesJobData>();
|
|
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));
|
|
|
|
}
|
|
|
|
SeriesJob seriesService = new SeriesJob(series);
|
|
|
|
seriesResponseSpec.setSr(seriesService);
|
|
} catch (Throwable e) {
|
|
logger.error("Error creating series for job accounting: "+e.getLocalizedMessage());
|
|
e.printStackTrace();
|
|
throw new AccountingManagerServiceException("Error creating series for job accounting: "+e.getLocalizedMessage());
|
|
}
|
|
|
|
}
|
|
}
|