diff options
author | CNlucius <lukai1@huawei.com> | 2016-09-13 11:40:12 +0800 |
---|---|---|
committer | CNlucius <lukai1@huawei.com> | 2016-09-13 11:41:53 +0800 |
commit | b731e2f1dd0972409b136aebc7b463dd72c9cfad (patch) | |
tree | 5107d7d80c19ad8076c2c97c2b5ef8d1cf3ab903 /framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent | |
parent | ee93993458266114c29271a481ef9ce7ce621b2a (diff) |
ONOSFW-171
O/S-SFC-ONOS scenario documentation
Change-Id: I51ae1cf736ea24ab6680f8edca1b2bf5dd598365
Signed-off-by: CNlucius <lukai1@huawei.com>
Diffstat (limited to 'framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent')
6 files changed, 0 insertions, 583 deletions
diff --git a/framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent/IntentMetrics.java b/framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent/IntentMetrics.java deleted file mode 100644 index 9a42e9ee..00000000 --- a/framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent/IntentMetrics.java +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * 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 org.onosproject.metrics.intent; - -import static org.slf4j.LoggerFactory.getLogger; - -import java.util.LinkedList; -import java.util.List; - -import com.google.common.collect.ImmutableList; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.apache.felix.scr.annotations.Service; -import org.onlab.metrics.EventMetric; -import org.onlab.metrics.MetricsService; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.net.intent.IntentEvent; -import org.onosproject.net.intent.IntentListener; -import org.onosproject.net.intent.IntentService; -import org.slf4j.Logger; - -/** - * ONOS Intent Metrics Application that collects intent-related metrics. - */ -@Component(immediate = true) -@Service -public class IntentMetrics implements IntentMetricsService, - IntentListener { - private static final Logger log = getLogger(IntentMetrics.class); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected IntentService intentService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected MetricsService metricsService; - - private ApplicationId appId; - - private LinkedList<IntentEvent> lastEvents = new LinkedList<>(); - private static final int LAST_EVENTS_MAX_N = 100; - - // - // Metrics - // - private static final String COMPONENT_NAME = "Intent"; - private static final String FEATURE_SUBMITTED_NAME = "Submitted"; - private static final String FEATURE_INSTALLED_NAME = "Installed"; - private static final String FEATURE_FAILED_NAME = "Failed"; - private static final String FEATURE_WITHDRAW_REQUESTED_NAME = - "WithdrawRequested"; - private static final String FEATURE_WITHDRAWN_NAME = "Withdrawn"; - private static final String FEATURE_PURGED_NAME = "Purged"; - // - // Event metrics: - // - Intent Submitted API operation - // - Intent Installed operation completion - // - Intent Failed compilation or installation - // - Intent Withdraw Requested API operation - // - Intent Withdrawn operation completion - // - Intent Purged operation completion - // - private EventMetric intentSubmittedEventMetric; - private EventMetric intentInstalledEventMetric; - private EventMetric intentFailedEventMetric; - private EventMetric intentWithdrawRequestedEventMetric; - private EventMetric intentWithdrawnEventMetric; - private EventMetric intentPurgedEventMetric; - - @Activate - protected void activate() { - appId = coreService.registerApplication("org.onosproject.metrics"); - - clear(); - registerMetrics(); - intentService.addListener(this); - log.info("Started with Application ID {}", appId.id()); - } - - @Deactivate - public void deactivate() { - intentService.removeListener(this); - removeMetrics(); - clear(); - log.info("Stopped"); - } - - @Override - public List<IntentEvent> getEvents() { - synchronized (lastEvents) { - return ImmutableList.copyOf(lastEvents); - } - } - - @Override - public EventMetric intentSubmittedEventMetric() { - return intentSubmittedEventMetric; - } - - @Override - public EventMetric intentInstalledEventMetric() { - return intentInstalledEventMetric; - } - - @Override - public EventMetric intentFailedEventMetric() { - return intentFailedEventMetric; - } - - @Override - public EventMetric intentWithdrawRequestedEventMetric() { - return intentWithdrawRequestedEventMetric; - } - - @Override - public EventMetric intentWithdrawnEventMetric() { - return intentWithdrawnEventMetric; - } - - @Override - public EventMetric intentPurgedEventMetric() { - return intentPurgedEventMetric; - } - - @Override - public void event(IntentEvent event) { - synchronized (lastEvents) { - switch (event.type()) { - case INSTALL_REQ: - intentSubmittedEventMetric.eventReceived(); - break; - case INSTALLED: - intentInstalledEventMetric.eventReceived(); - break; - case FAILED: - intentFailedEventMetric.eventReceived(); - break; - case WITHDRAW_REQ: - intentWithdrawRequestedEventMetric.eventReceived(); - break; - case WITHDRAWN: - intentWithdrawnEventMetric.eventReceived(); - break; - case PURGED: - intentPurgedEventMetric.eventReceived(); - break; - default: - break; - } - - // - // Keep only the last N events, where N = LAST_EVENTS_MAX_N - // - while (lastEvents.size() >= LAST_EVENTS_MAX_N) { - lastEvents.remove(); - } - lastEvents.add(event); - } - - log.debug("Intent Event: time = {} type = {} event = {}", - event.time(), event.type(), event); - } - - /** - * Clears the internal state. - */ - private void clear() { - synchronized (lastEvents) { - lastEvents.clear(); - } - } - - /** - * Registers the metrics. - */ - private void registerMetrics() { - intentSubmittedEventMetric = - new EventMetric(metricsService, COMPONENT_NAME, - FEATURE_SUBMITTED_NAME); - intentInstalledEventMetric = - new EventMetric(metricsService, COMPONENT_NAME, - FEATURE_INSTALLED_NAME); - intentFailedEventMetric = - new EventMetric(metricsService, COMPONENT_NAME, - FEATURE_FAILED_NAME); - intentWithdrawRequestedEventMetric = - new EventMetric(metricsService, COMPONENT_NAME, - FEATURE_WITHDRAW_REQUESTED_NAME); - intentWithdrawnEventMetric = - new EventMetric(metricsService, COMPONENT_NAME, - FEATURE_WITHDRAWN_NAME); - intentPurgedEventMetric = - new EventMetric(metricsService, COMPONENT_NAME, - FEATURE_PURGED_NAME); - - intentSubmittedEventMetric.registerMetrics(); - intentInstalledEventMetric.registerMetrics(); - intentFailedEventMetric.registerMetrics(); - intentWithdrawRequestedEventMetric.registerMetrics(); - intentWithdrawnEventMetric.registerMetrics(); - intentPurgedEventMetric.registerMetrics(); - } - - /** - * Removes the metrics. - */ - private void removeMetrics() { - intentSubmittedEventMetric.removeMetrics(); - intentInstalledEventMetric.removeMetrics(); - intentFailedEventMetric.removeMetrics(); - intentWithdrawRequestedEventMetric.removeMetrics(); - intentWithdrawnEventMetric.removeMetrics(); - intentPurgedEventMetric.removeMetrics(); - } -} diff --git a/framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent/IntentMetricsService.java b/framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent/IntentMetricsService.java deleted file mode 100644 index aa03e390..00000000 --- a/framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent/IntentMetricsService.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * 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 org.onosproject.metrics.intent; - -import java.util.List; -import org.onlab.metrics.EventMetric; -import org.onosproject.net.intent.IntentEvent; - -/** - * Service interface exported by IntentMetrics. - */ -public interface IntentMetricsService { - /** - * Gets the last saved intent events. - * - * @return the last saved intent events - */ - List<IntentEvent> getEvents(); - - /** - * Gets the Event Metric for the intent INSTALL_REQ events. - * - * @return the Event Metric for the intent INSTALL_REQ events - */ - EventMetric intentSubmittedEventMetric(); - - /** - * Gets the Event Metric for the intent INSTALLED events. - * - * @return the Event Metric for the intent INSTALLED events - */ - EventMetric intentInstalledEventMetric(); - - /** - * Gets the Event Metric for the intent FAILED events. - * - * @return the Event Metric for the intent FAILED events - */ - EventMetric intentFailedEventMetric(); - - /** - * Gets the Event Metric for the intent WITHDRAW_REQ events. - * - * @return the Event Metric for the intent WITHDRAW_REQ events - */ - EventMetric intentWithdrawRequestedEventMetric(); - - /** - * Gets the Event Metric for the intent WITHDRAWN events. - * - * @return the Event Metric for the intent WITHDRAWN events - */ - EventMetric intentWithdrawnEventMetric(); - - /** - * Gets the Event Metric for the intent PURGED events. - * - * @return the Event Metric for the intent PURGED events - */ - EventMetric intentPurgedEventMetric(); -} diff --git a/framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent/cli/IntentEventsListCommand.java b/framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent/cli/IntentEventsListCommand.java deleted file mode 100644 index 3c8457ad..00000000 --- a/framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent/cli/IntentEventsListCommand.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * 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 org.onosproject.metrics.intent.cli; - -import java.util.List; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.apache.karaf.shell.commands.Command; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.metrics.intent.IntentMetricsService; -import org.onosproject.net.intent.IntentEvent; - -/** - * Command to show the list of last intent events. - */ -@Command(scope = "onos", name = "intents-events", - description = "Lists the last intent events") -public class IntentEventsListCommand extends AbstractShellCommand { - - private static final String FORMAT_EVENT = "Event=%s"; - - @Override - protected void execute() { - IntentMetricsService service = get(IntentMetricsService.class); - - if (outputJson()) { - print("%s", json(service.getEvents())); - } else { - for (IntentEvent event : service.getEvents()) { - print(FORMAT_EVENT, event); - print(""); // Extra empty line for clarity - } - } - } - - /** - * Produces a JSON array of intent events. - * - * @param intentEvents the intent events with the data - * @return JSON array with the intent events - */ - private JsonNode json(List<IntentEvent> intentEvents) { - ObjectMapper mapper = new ObjectMapper(); - ArrayNode result = mapper.createArrayNode(); - - for (IntentEvent event : intentEvents) { - result.add(json(mapper, event)); - } - return result; - } - - /** - * Produces JSON object for a intent event. - * - * @param mapper the JSON object mapper to use - * @param intentEvent the intent event with the data - * @return JSON object for the intent event - */ - private ObjectNode json(ObjectMapper mapper, IntentEvent intentEvent) { - ObjectNode result = mapper.createObjectNode(); - - result.put("time", intentEvent.time()) - .put("type", intentEvent.type().toString()) - .put("event", intentEvent.toString()); - return result; - } -} diff --git a/framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent/cli/IntentEventsMetricsCommand.java b/framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent/cli/IntentEventsMetricsCommand.java deleted file mode 100644 index 356b9ada..00000000 --- a/framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent/cli/IntentEventsMetricsCommand.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * 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 org.onosproject.metrics.intent.cli; - -import java.io.IOException; -import java.util.concurrent.TimeUnit; - -import com.codahale.metrics.Gauge; -import com.codahale.metrics.Meter; -import com.codahale.metrics.json.MetricsModule; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.apache.karaf.shell.commands.Command; -import org.onlab.metrics.EventMetric; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.metrics.intent.IntentMetricsService; - -/** - * Command to show the intent events metrics. - */ -@Command(scope = "onos", name = "intents-events-metrics", - description = "Lists intent events metrics") -public class IntentEventsMetricsCommand extends AbstractShellCommand { - - private static final String FORMAT_GAUGE = - "Intent %s Event Timestamp (ms from epoch)=%d"; - private static final String FORMAT_METER = - "Intent %s Events count=%d rate(events/sec) mean=%f m1=%f m5=%f m15=%f"; - - @Override - protected void execute() { - IntentMetricsService service = get(IntentMetricsService.class); - - if (outputJson()) { - ObjectMapper mapper = new ObjectMapper() - .registerModule(new MetricsModule(TimeUnit.SECONDS, - TimeUnit.MILLISECONDS, - false)); - ObjectNode result = mapper.createObjectNode(); - result = json(mapper, result, "intentSubmitted", - service.intentSubmittedEventMetric()); - result = json(mapper, result, "intentInstalled", - service.intentInstalledEventMetric()); - result = json(mapper, result, "intentFailed", - service.intentFailedEventMetric()); - result = json(mapper, result, "intentWithdrawRequested", - service.intentWithdrawRequestedEventMetric()); - result = json(mapper, result, "intentWithdrawn", - service.intentWithdrawnEventMetric()); - result = json(mapper, result, "intentPurged", - service.intentPurgedEventMetric()); - print("%s", result); - } else { - printEventMetric("Submitted", - service.intentSubmittedEventMetric()); - printEventMetric("Installed", - service.intentInstalledEventMetric()); - printEventMetric("Failed", - service.intentFailedEventMetric()); - printEventMetric("Withdraw Requested", - service.intentWithdrawRequestedEventMetric()); - printEventMetric("Withdrawn", - service.intentWithdrawnEventMetric()); - printEventMetric("Purged", - service.intentPurgedEventMetric()); - } - } - - /** - * Produces JSON node for an Event Metric. - * - * @param mapper the JSON object mapper to use - * @param objectNode the JSON object node to use - * @param propertyPrefix the property prefix to use - * @param eventMetric the Event Metric with the data - * @return JSON object node for the Event Metric - */ - private ObjectNode json(ObjectMapper mapper, ObjectNode objectNode, - String propertyPrefix, EventMetric eventMetric) { - String gaugeName = propertyPrefix + "Timestamp"; - String meterName = propertyPrefix + "Rate"; - Gauge<Long> gauge = eventMetric.lastEventTimestampGauge(); - Meter meter = eventMetric.eventRateMeter(); - - objectNode.set(gaugeName, json(mapper, gauge)); - objectNode.set(meterName, json(mapper, meter)); - return objectNode; - } - - /** - * Produces JSON node for an Object. - * - * @param mapper the JSON object mapper to use - * @param object the Object with the data - * @return JSON node for the Object - */ - private JsonNode json(ObjectMapper mapper, Object object) { - // - // NOTE: The API for custom serializers is incomplete, - // hence we have to parse the JSON string to create JsonNode. - // - try { - final String objectJson = mapper.writeValueAsString(object); - JsonNode jsonNode = mapper.readTree(objectJson); - return jsonNode; - } catch (JsonProcessingException e) { - log.error("Error writing value as JSON string", e); - } catch (IOException e) { - log.error("Error writing value as JSON string", e); - } - return null; - } - - /** - * Prints an Event Metric. - * - * @param operationStr the string with the intent operation to print - * @param eventMetric the Event Metric to print - */ - private void printEventMetric(String operationStr, - EventMetric eventMetric) { - Gauge<Long> gauge = eventMetric.lastEventTimestampGauge(); - Meter meter = eventMetric.eventRateMeter(); - TimeUnit rateUnit = TimeUnit.SECONDS; - double rateFactor = rateUnit.toSeconds(1); - - // Print the Gauge - print(FORMAT_GAUGE, operationStr, gauge.getValue()); - - // Print the Meter - print(FORMAT_METER, operationStr, meter.getCount(), - meter.getMeanRate() * rateFactor, - meter.getOneMinuteRate() * rateFactor, - meter.getFiveMinuteRate() * rateFactor, - meter.getFifteenMinuteRate() * rateFactor); - } -} diff --git a/framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent/cli/package-info.java b/framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent/cli/package-info.java deleted file mode 100644 index ddc7877c..00000000 --- a/framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent/cli/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * 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. - */ - -/** - * Intent metrics command-line handlers. - */ -package org.onosproject.metrics.intent.cli; diff --git a/framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent/package-info.java b/framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent/package-info.java deleted file mode 100644 index 9a7ac66c..00000000 --- a/framework/src/onos/apps/metrics/src/main/java/org/onosproject/metrics/intent/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * 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. - */ - -/** - * ONOS Intent Metrics Application that collects intent-related metrics. - */ -package org.onosproject.metrics.intent; |