public void sumFromPeriodType(Period period, String type) { if (period == null || type == null) { throw new IllegalArgumentException("args can't be null"); } long timeSecs = (period.getEndingMs() - period.getBeginningMs()) / 1000; // TODO: the strings here should be in an enum or something. same with events? // Autoboxing should work because we prevented nulls everywhere if (type.equalsIgnoreCase("m1.small")) { this.m1SmallNum = this.m1SmallNum + 1; this.m1SmallTimeSecs = this.m1SmallTimeSecs + timeSecs; } else if (type.equalsIgnoreCase("c1.medium")) { this.c1MediumNum = this.c1MediumNum + 1; this.c1MediumTimeSecs = this.c1MediumTimeSecs + timeSecs; } else if (type.equalsIgnoreCase("m1.large")) { this.m1LargeNum = this.m1LargeNum + 1; this.m1LargeTimeSecs = this.m1LargeTimeSecs + timeSecs; } else if (type.equalsIgnoreCase("m1.xlarge")) { this.m1XLargeNum = this.m1XLargeNum + 1; this.m1XLargeTimeSecs = this.m1XLargeTimeSecs + timeSecs; } else if (type.equalsIgnoreCase("c1.xlarge")) { this.c1XLargeNum = this.c1XLargeNum + 1; this.c1XLargeTimeSecs = this.c1XLargeTimeSecs + timeSecs; } else { throw new RuntimeException("Unrecognized type:" + type); } }
public GenerateReportResponseType generateReport(final GenerateReportType request) throws EucalyptusCloudException { final GenerateReportResponseType reply = request.getReply(); reply.getResponseMetadata().setRequestId(reply.getCorrelationId()); checkAuthorized(); final Period period = Period.defaultPeriod(); long startTime = period.getBeginningMs(); long endTime = period.getEndingMs(); if (request.getStartDate() != null) { startTime = parseDate(request.getStartDate()); } if (request.getEndDate() != null) { endTime = parseDate(request.getEndDate()); } final String reportData; try { reportData = ReportGenerationFacade.generateReport( Objects.firstNonNull(request.getType(), "instance"), Objects.firstNonNull(request.getFormat(), "html"), units(request), startTime, endTime); } catch (final ReportGenerationArgumentException e) { throw new ReportingException( HttpResponseStatus.BAD_REQUEST, ReportingException.BAD_REQUEST, "Bad request: Invalid start or end date"); } catch (final Exception e) { logger.error(e, e); throw new ReportingException( HttpResponseStatus.INTERNAL_SERVER_ERROR, ReportingException.INTERNAL_SERVER_ERROR, "Error generating report"); } reply.setResult(new GenerateReportResultType(reportData)); return reply; }