Search in sources :

Example 1 with TimeBucket

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();
}
Also used : TimeBucket(com.emc.storageos.db.client.TimeSeriesMetadata.TimeBucket) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with TimeBucket

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();
}
Also used : TimeBucket(com.emc.storageos.db.client.TimeSeriesMetadata.TimeBucket) TimeSeriesMetadata(com.emc.storageos.db.client.TimeSeriesMetadata) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

TimeBucket (com.emc.storageos.db.client.TimeSeriesMetadata.TimeBucket)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 DateTime (org.joda.time.DateTime)2 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)2 TimeSeriesMetadata (com.emc.storageos.db.client.TimeSeriesMetadata)1