use of com.emc.storageos.db.client.TimeSeriesMetadata.TimeBucket in project coprhd-controller by CoprHD.
the class MeteringService method getStats.
/**
* Retrieves the bulk metering stats for all resources in a specified time bucket (minute or hour).
*
* @param time_bucket required Time bucket for retrieval of stats. Acceptable formats are: yyyy-MM-dd'T'HH for hour bucket,
* yyyy-MM-dd'T'HH:mm for minute bucket
* @brief List metering statistics for time period
* @return - Output stream of stats or an error status.
*/
@GET
@Path("/stats")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.SYSTEM_ADMIN })
public Response getStats(@QueryParam("time_bucket") final String timeBucketParam, @Context HttpHeaders header) {
_logger.debug("getStats: timebucket: {}", timeBucketParam);
MediaType mediaType = MediaType.APPLICATION_XML_TYPE;
List<MediaType> mTypes = header.getAcceptableMediaTypes();
if (mTypes != null) {
for (MediaType media : mTypes) {
if (media.equals(MediaType.APPLICATION_JSON_TYPE) || media.equals(MediaType.APPLICATION_XML_TYPE)) {
mediaType = media;
break;
}
}
}
DateTimeFormatter dfHourFormat = DateTimeFormat.forPattern(HOUR_BUCKET_TIME_FORMAT).withZoneUTC();
DateTimeFormatter dfMinuteFormat = DateTimeFormat.forPattern(MINUTE_BUCKET_TIME_FORMAT).withZoneUTC();
DateTime timeBucket = null;
TimeBucket granularity = TimeBucket.HOUR;
try {
// we reduce the length by 2 here to account for single quote in yyyy-MM-dd'T'HH format
if ((null != timeBucketParam) && (timeBucketParam.length() == HOUR_BUCKET_TIME_FORMAT.length() - 2)) {
timeBucket = dfHourFormat.parseDateTime(timeBucketParam);
granularity = TimeSeriesMetadata.TimeBucket.HOUR;
} else if ((null != timeBucketParam) && (timeBucketParam.length() == MINUTE_BUCKET_TIME_FORMAT.length() - 2)) {
timeBucket = dfMinuteFormat.parseDateTime(timeBucketParam);
granularity = TimeSeriesMetadata.TimeBucket.MINUTE;
} else {
throw APIException.badRequests.invalidTimeBucket(timeBucketParam);
}
} catch (final IllegalArgumentException e) {
throw APIException.badRequests.invalidTimeBucket(timeBucketParam, e);
}
if (timeBucket == null) {
throw APIException.badRequests.invalidTimeBucket(timeBucketParam);
}
return Response.ok(getStreamData(timeBucket, granularity, mediaType), mediaType).build();
}
use of com.emc.storageos.db.client.TimeSeriesMetadata.TimeBucket in project coprhd-controller by CoprHD.
the class MonitoringService method getEvents.
/**
* Retrieves the bulk events and alerts in a specified time bucket (minute or hour).
*
* @param time_bucket required Time bucket for retrieval of events. Acceptable formats are: yyyy-MM-dd'T'HH for hour bucket,
* yyyy-MM-dd'T'HH:mm for minute bucket
* @brief List events and alerts for time period
* @return Output stream of events or an error status.
*/
@GET
@Path("/events")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.SYSTEM_ADMIN })
public Response getEvents(@QueryParam("time_bucket") final String timeBucketParam, @Context HttpHeaders header) {
_logger.debug("getEvents: timebucket: {}", timeBucketParam);
MediaType mType = MediaType.APPLICATION_XML_TYPE;
List<MediaType> mTypes = header.getAcceptableMediaTypes();
if (mTypes != null) {
for (MediaType media : mTypes) {
if (media.equals(MediaType.APPLICATION_JSON_TYPE) || media.equals(MediaType.APPLICATION_XML_TYPE)) {
mType = media;
break;
}
}
}
// try two time formats which are supported
DateTimeFormatter hourBucketFormat = DateTimeFormat.forPattern(HOUR_BUCKET_TIME_FORMAT).withZoneUTC();
DateTimeFormatter minuteBucketFormat = DateTimeFormat.forPattern(MINUTE_BUCKET_TIME_FORMAT).withZoneUTC();
DateTime timeBucket = null;
TimeSeriesMetadata.TimeBucket timeBucketGran = TimeSeriesMetadata.TimeBucket.HOUR;
try {
// we reduce the length by 2 here to account for single quote in yyyy-MM-dd'T'HH format
if ((null != timeBucketParam) && (timeBucketParam.length() == HOUR_BUCKET_TIME_FORMAT.length() - 2)) {
timeBucket = hourBucketFormat.parseDateTime(timeBucketParam);
timeBucketGran = TimeSeriesMetadata.TimeBucket.HOUR;
} else if ((null != timeBucketParam) && (timeBucketParam.length() == MINUTE_BUCKET_TIME_FORMAT.length() - 2)) {
timeBucket = minuteBucketFormat.parseDateTime(timeBucketParam);
timeBucketGran = TimeSeriesMetadata.TimeBucket.MINUTE;
} else {
throw APIException.badRequests.invalidTimeBucket(timeBucketParam);
}
} catch (final IllegalArgumentException e) {
throw APIException.badRequests.invalidTimeBucket(timeBucketParam, e);
}
if (timeBucket == null) {
throw APIException.badRequests.invalidTimeBucket(timeBucketParam);
}
return Response.ok(getStreamOutput(timeBucket, timeBucketGran, mType), mType).build();
}
Aggregations