com.vmware.photon.controller.model.monitoring.ResourceAggregateMetricService Maven / Gradle / Ivy
/*
* Copyright (c) 2015-2016 VMware, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, without warranties or
* conditions of any kind, EITHER EXPRESS OR IMPLIED. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.vmware.photon.controller.model.monitoring;
import com.vmware.photon.controller.model.UriPaths;
import com.vmware.xenon.common.FactoryService;
import com.vmware.xenon.common.Operation;
import com.vmware.xenon.common.ServiceDocument;
import com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption;
import com.vmware.xenon.common.ServiceStats.TimeSeriesStats.TimeBin;
import com.vmware.xenon.common.StatefulService;
import com.vmware.xenon.common.Utils;
/**
* This class is used to store aggregated metric values
*/
public class ResourceAggregateMetricService extends StatefulService {
public static final String FACTORY_LINK = UriPaths.MONITORING + "/aggregate-metrics";
public static FactoryService createFactory() {
return FactoryService.createIdempotent(ResourceAggregateMetricService.class);
}
public ResourceAggregateMetricService() {
super(ResourceAggregateMetric.class);
super.toggleOption(ServiceOption.PERSISTENCE, true);
super.toggleOption(ServiceOption.ON_DEMAND_LOAD, true);
}
/**
* Service state to store aggregate metric values. The timeBin field
* is used to store the various metric aggregations and currentIntervalTimeStampMicrosUtc
* is the timestamp to which the metric values correspond
*/
public static class ResourceAggregateMetric extends ServiceDocument {
public static final int VERSION_RETENTION_LIMIT = Integer.getInteger(
UriPaths.PROPERTY_PREFIX + ResourceAggregateMetric.class.getSimpleName()
+ ".VERSION_RETENTION_LIMIT", 50000);
public static final String FIELD_NAME_TIMESTAMP = "currentIntervalTimeStampMicrosUtc";
public static final String FIELD_NAME_TIMEBIN = "timeBin";
@Documentation(description = "TimeBin for the current interval")
@UsageOption(option = PropertyUsageOption.REQUIRED)
public TimeBin timeBin;
@Documentation(description = "The timestamp for the current interval")
@UsageOption(option = PropertyUsageOption.REQUIRED)
public Long currentIntervalTimeStampMicrosUtc;
}
@Override
public void handleStart(Operation start) {
try {
processInput(start);
start.complete();
} catch (Throwable t) {
start.fail(t);
}
}
@Override
public void handlePut(Operation put) {
try {
ResourceAggregateMetric returnState = processInput(put);
setState(put, returnState);
put.complete();
} catch (Throwable t) {
put.fail(t);
}
}
private ResourceAggregateMetric processInput(Operation op) {
if (!op.hasBody()) {
throw (new IllegalArgumentException("body is required"));
}
ResourceAggregateMetric state = op.getBody(ResourceAggregateMetric.class);
Utils.validateState(getStateDescription(), state);
return state;
}
@Override
public ServiceDocument getDocumentTemplate() {
ServiceDocument serviceDocument = super.getDocumentTemplate();
serviceDocument.documentDescription.versionRetentionLimit = ResourceAggregateMetric.VERSION_RETENTION_LIMIT;
return serviceDocument;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy