From 7a67f5f10dab58faa6eeb0c34be3fa81e54a4336 Mon Sep 17 00:00:00 2001 From: Vaclav Demcak Date: Thu, 3 Jul 2014 09:21:48 +0200 Subject: [PATCH] Bug 542 - Plugin internal stats * refactoring for internal statistics * add internal statistic confSubsystem module * add MXBean for statistic's report Change-Id: I2574d16bb087538dc0f85963717a0160c5729112 Signed-off-by: Vaclav Demcak --- .../initial/42-openflow-protocol-impl.xml | 18 +++ .../openflow/md/core/MDController.java | 2 +- .../md/core/NotificationPopListener.java | 2 +- .../md/core/RpcListeningExecutorService.java | 2 +- .../md/core/SwitchConnectionHandlerImpl.java | 2 +- .../md/core/sal/OFRpcTaskContext.java | 2 +- .../openflow/md/core/sal/OFRpcTaskUtil.java | 2 +- .../md/core/sal/OpenflowPluginProvider.java | 38 ++++--- .../md/core/session/SessionManager.java | 2 +- .../md/core/session/SessionManagerOFImpl.java | 2 +- .../md/queue/QueueProcessorLightImpl.java | 3 +- .../md/queue/TicketProcessorFactory.java | 1 + .../md/queue/TicketProcessorFactoryImpl.java | 1 + .../MessageCountCommandProvider.java | 3 +- .../MessageCountDumper.java | 2 +- .../MessageObservatory.java | 3 +- .../md/queue => statistics}/MessageSpy.java | 2 +- .../MessageSpyCounterImpl.java | 7 +- .../impl/rev140326/MsgSpyServiceModule.java | 107 ++++++++++++++++++ .../rev140326/MsgSpyServiceModuleFactory.java | 13 +++ .../main/yang/openflow-plugin-cfg-impl.yang | 68 ++++++++++- .../md/core/ConnectionConductorImplTest.java | 2 +- 22 files changed, 247 insertions(+), 37 deletions(-) rename openflowplugin/src/main/java/org/opendaylight/openflowplugin/{openflow/md/core/cmd => statistics}/MessageCountCommandProvider.java (94%) rename openflowplugin/src/main/java/org/opendaylight/openflowplugin/{openflow/md/queue => statistics}/MessageCountDumper.java (89%) rename openflowplugin/src/main/java/org/opendaylight/openflowplugin/{openflow/md/queue => statistics}/MessageObservatory.java (88%) rename openflowplugin/src/main/java/org/opendaylight/openflowplugin/{openflow/md/queue => statistics}/MessageSpy.java (97%) rename openflowplugin/src/main/java/org/opendaylight/openflowplugin/{openflow/md/queue => statistics}/MessageSpyCounterImpl.java (96%) create mode 100644 openflowplugin/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/common/config/impl/rev140326/MsgSpyServiceModule.java create mode 100644 openflowplugin/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/common/config/impl/rev140326/MsgSpyServiceModuleFactory.java diff --git a/distribution/base/src/main/resources/configuration/initial/42-openflow-protocol-impl.xml b/distribution/base/src/main/resources/configuration/initial/42-openflow-protocol-impl.xml index 7c92145181..76dfde8d9d 100644 --- a/distribution/base/src/main/resources/configuration/initial/42-openflow-protocol-impl.xml +++ b/distribution/base/src/main/resources/configuration/initial/42-openflow-protocol-impl.xml @@ -57,6 +57,16 @@ and is available at http://www.eclipse.org/legal/epl-v10.html binding-osgi-broker + + + msgspy:msg-spy-service-impl + msg-spy-service-impl + + + opfprov:openflow-provider + openflow-provider + + @@ -79,6 +89,14 @@ and is available at http://www.eclipse.org/legal/epl-v10.html /modules/module[type='openflow-provider-impl'][name='openflow-provider-impl'] + + + msgspy:msg-spy-service + + msg-spy-service + /modules/module[type='msg-spy-service-impl'][name='msg-spy-service-impl'] + + diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/MDController.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/MDController.java index 2d3fae434c..bb333de44e 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/MDController.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/MDController.java @@ -42,9 +42,9 @@ import org.opendaylight.openflowplugin.openflow.md.core.translator.PacketInTrans import org.opendaylight.openflowplugin.openflow.md.core.translator.PacketInV10Translator; import org.opendaylight.openflowplugin.openflow.md.core.translator.PortStatusMessageToNodeConnectorUpdatedTranslator; import org.opendaylight.openflowplugin.openflow.md.lldp.LLDPSpeakerPopListener; -import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpy; import org.opendaylight.openflowplugin.openflow.md.queue.PopListener; import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil; +import org.opendaylight.openflowplugin.statistics.MessageSpy; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeErrorNotification; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SwitchFlowRemoved; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdate; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/NotificationPopListener.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/NotificationPopListener.java index bd7462d994..c543d3129d 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/NotificationPopListener.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/NotificationPopListener.java @@ -8,8 +8,8 @@ package org.opendaylight.openflowplugin.openflow.md.core; import org.opendaylight.controller.sal.binding.api.NotificationProviderService; -import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpy; import org.opendaylight.openflowplugin.openflow.md.queue.PopListener; +import org.opendaylight.openflowplugin.statistics.MessageSpy; import org.opendaylight.yangtools.yang.binding.Notification; /** diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/RpcListeningExecutorService.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/RpcListeningExecutorService.java index 23c561c23d..ba142ff324 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/RpcListeningExecutorService.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/RpcListeningExecutorService.java @@ -16,7 +16,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTask; -import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpy; +import org.opendaylight.openflowplugin.statistics.MessageSpy; import org.opendaylight.yangtools.yang.binding.DataContainer; import com.google.common.util.concurrent.ListenableFuture; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/SwitchConnectionHandlerImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/SwitchConnectionHandlerImpl.java index ecb9757f85..fbb0018a84 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/SwitchConnectionHandlerImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/SwitchConnectionHandlerImpl.java @@ -15,8 +15,8 @@ import java.util.concurrent.TimeUnit; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler; import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil; -import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpy; import org.opendaylight.openflowplugin.openflow.md.queue.QueueProcessorLightImpl; +import org.opendaylight.openflowplugin.statistics.MessageSpy; import org.opendaylight.yangtools.yang.binding.DataContainer; /** diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskContext.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskContext.java index ed59fe9222..179fb5c7cf 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskContext.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskContext.java @@ -12,7 +12,7 @@ import java.util.concurrent.TimeUnit; import org.opendaylight.controller.sal.binding.api.NotificationProviderService; import org.opendaylight.openflowplugin.openflow.md.core.session.IMessageDispatchService; import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext; -import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpy; +import org.opendaylight.openflowplugin.statistics.MessageSpy; import org.opendaylight.yangtools.yang.binding.DataContainer; import com.google.common.util.concurrent.ListeningExecutorService; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskUtil.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskUtil.java index f919202878..c43db8b1e8 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskUtil.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskUtil.java @@ -19,7 +19,7 @@ import org.opendaylight.openflowplugin.openflow.md.core.MessageFactory; import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher; import org.opendaylight.openflowplugin.openflow.md.core.session.IMessageDispatchService; import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext; -import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpy; +import org.opendaylight.openflowplugin.statistics.MessageSpy; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput; import org.opendaylight.yangtools.yang.binding.DataContainer; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OpenflowPluginProvider.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OpenflowPluginProvider.java index d16877bdd4..7ef15a4e88 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OpenflowPluginProvider.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OpenflowPluginProvider.java @@ -16,9 +16,10 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderCo import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider; import org.opendaylight.openflowplugin.openflow.md.core.MDController; -import org.opendaylight.openflowplugin.openflow.md.core.cmd.MessageCountCommandProvider; -import org.opendaylight.openflowplugin.openflow.md.queue.MessageObservatory; -import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpyCounterImpl; +import org.opendaylight.openflowplugin.statistics.MessageCountCommandProvider; +import org.opendaylight.openflowplugin.statistics.MessageCountDumper; +import org.opendaylight.openflowplugin.statistics.MessageObservatory; +import org.opendaylight.openflowplugin.statistics.MessageSpyCounterImpl; import org.opendaylight.yangtools.yang.binding.DataContainer; import org.opendaylight.yangtools.yang.binding.RpcService; import org.osgi.framework.BundleContext; @@ -29,9 +30,9 @@ import org.slf4j.LoggerFactory; * OFPlugin provider implementation */ public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseable { - + private static Logger LOG = LoggerFactory.getLogger(OpenflowPluginProvider.class); - + private BindingAwareBroker broker; private BundleContext context; @@ -39,13 +40,13 @@ public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseab private Collection switchConnectionProviders; private MDController mdController; - + private MessageCountCommandProvider messageCountCommandProvider; private MessageObservatory messageCountProvider; - + private SalRegistrationManager registrationManager; - + /** * @param switchConnectionProvider */ @@ -61,10 +62,10 @@ public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseab } /** - * dependencymanager requirement + * dependencymanager requirement * @param context - * - * @deprecated we should stop relying on osgi to provide cli interface for messageCounter + * + * @deprecated we should stop relying on osgi to provide cli interface for messageCounter */ @Deprecated public void setContext(BundleContext context) { @@ -74,7 +75,6 @@ public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseab @Override public void onSessionInitiated(ProviderContext session) { LOG.debug("onSessionInitiated"); - messageCountProvider = new MessageSpyCounterImpl(); registrationManager = new SalRegistrationManager(); registrationManager.onSessionInitiated(session); mdController = new MDController(); @@ -85,7 +85,7 @@ public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseab messageCountCommandProvider = new MessageCountCommandProvider(context, messageCountProvider); messageCountCommandProvider.onSessionInitiated(session); } - + @Override public void close() { LOG.debug("close"); @@ -120,7 +120,7 @@ public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseab } /** - * dependencymanager requirement + * dependencymanager requirement * @param broker */ public void setBroker(BindingAwareBroker broker) { @@ -128,7 +128,7 @@ public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseab } /** - * dependencymanager requirement + * dependencymanager requirement * @param brokerArg */ public void unsetBroker(BindingAwareBroker brokerArg) { @@ -141,14 +141,18 @@ public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseab } return false; } - + /** * register providers for md-sal */ public void registerProvider() { - //FIXME: is it needed + // TODO : create normal init + messageCountProvider = new MessageSpyCounterImpl(); if(hasAllDependencies()) { this.broker.registerProvider(this,context); } } + public MessageCountDumper getMessageCountDumper() { + return messageCountProvider; + } } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionManager.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionManager.java index f5553cb891..0bfcc9478d 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionManager.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionManager.java @@ -19,8 +19,8 @@ import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor; import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator; import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher; import org.opendaylight.openflowplugin.openflow.md.core.TranslatorKey; -import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpy; import org.opendaylight.openflowplugin.openflow.md.queue.PopListener; +import org.opendaylight.openflowplugin.statistics.MessageSpy; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.binding.DataContainer; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionManagerOFImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionManagerOFImpl.java index a314018d77..a9ce909503 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionManagerOFImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionManagerOFImpl.java @@ -21,8 +21,8 @@ import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor; import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator; import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher; import org.opendaylight.openflowplugin.openflow.md.core.TranslatorKey; -import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpy; import org.opendaylight.openflowplugin.openflow.md.queue.PopListener; +import org.opendaylight.openflowplugin.statistics.MessageSpy; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.concepts.util.ListenerRegistry; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/QueueProcessorLightImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/QueueProcessorLightImpl.java index ad62f014b1..c6d5922bc4 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/QueueProcessorLightImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/QueueProcessorLightImpl.java @@ -23,7 +23,8 @@ import java.util.concurrent.TimeUnit; import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator; import org.opendaylight.openflowplugin.openflow.md.core.ThreadPoolLoggingExecutor; import org.opendaylight.openflowplugin.openflow.md.core.TranslatorKey; -import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpy.STATISTIC_GROUP; +import org.opendaylight.openflowplugin.statistics.MessageSpy; +import org.opendaylight.openflowplugin.statistics.MessageSpy.STATISTIC_GROUP; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yangtools.yang.binding.DataContainer; import org.opendaylight.yangtools.yang.binding.DataObject; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/TicketProcessorFactory.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/TicketProcessorFactory.java index 17d7539343..4c9baade5a 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/TicketProcessorFactory.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/TicketProcessorFactory.java @@ -13,6 +13,7 @@ import java.util.Map; import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator; import org.opendaylight.openflowplugin.openflow.md.core.TranslatorKey; +import org.opendaylight.openflowplugin.statistics.MessageSpy; import org.opendaylight.yangtools.yang.binding.DataContainer; import org.opendaylight.yangtools.yang.binding.DataObject; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/TicketProcessorFactoryImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/TicketProcessorFactoryImpl.java index 720c016617..871853689b 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/TicketProcessorFactoryImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/TicketProcessorFactoryImpl.java @@ -16,6 +16,7 @@ import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor; import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator; import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher; import org.opendaylight.openflowplugin.openflow.md.core.TranslatorKey; +import org.opendaylight.openflowplugin.statistics.MessageSpy; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yangtools.yang.binding.DataContainer; import org.opendaylight.yangtools.yang.binding.DataObject; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/cmd/MessageCountCommandProvider.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/statistics/MessageCountCommandProvider.java similarity index 94% rename from openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/cmd/MessageCountCommandProvider.java rename to openflowplugin/src/main/java/org/opendaylight/openflowplugin/statistics/MessageCountCommandProvider.java index 242348a659..2cd5ec8081 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/cmd/MessageCountCommandProvider.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/statistics/MessageCountCommandProvider.java @@ -6,12 +6,11 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.openflow.md.core.cmd; +package org.opendaylight.openflowplugin.statistics; import org.eclipse.osgi.framework.console.CommandInterpreter; import org.eclipse.osgi.framework.console.CommandProvider; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; -import org.opendaylight.openflowplugin.openflow.md.queue.MessageCountDumper; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; import org.slf4j.Logger; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageCountDumper.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/statistics/MessageCountDumper.java similarity index 89% rename from openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageCountDumper.java rename to openflowplugin/src/main/java/org/opendaylight/openflowplugin/statistics/MessageCountDumper.java index ff5969876c..4f02509ebb 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageCountDumper.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/statistics/MessageCountDumper.java @@ -6,7 +6,7 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.openflow.md.queue; +package org.opendaylight.openflowplugin.statistics; import java.util.List; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageObservatory.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/statistics/MessageObservatory.java similarity index 88% rename from openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageObservatory.java rename to openflowplugin/src/main/java/org/opendaylight/openflowplugin/statistics/MessageObservatory.java index d5fe858022..921a3efe7d 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageObservatory.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/statistics/MessageObservatory.java @@ -6,7 +6,8 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.openflow.md.queue; +package org.opendaylight.openflowplugin.statistics; + /** * @param diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageSpy.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/statistics/MessageSpy.java similarity index 97% rename from openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageSpy.java rename to openflowplugin/src/main/java/org/opendaylight/openflowplugin/statistics/MessageSpy.java index 40a271757b..d05ede8b0f 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageSpy.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/statistics/MessageSpy.java @@ -6,7 +6,7 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.openflow.md.queue; +package org.opendaylight.openflowplugin.statistics; /** diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageSpyCounterImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/statistics/MessageSpyCounterImpl.java similarity index 96% rename from openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageSpyCounterImpl.java rename to openflowplugin/src/main/java/org/opendaylight/openflowplugin/statistics/MessageSpyCounterImpl.java index 6890f169ca..024ab7f02c 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageSpyCounterImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/statistics/MessageSpyCounterImpl.java @@ -6,7 +6,7 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.openflow.md.queue; +package org.opendaylight.openflowplugin.statistics; import java.util.ArrayList; import java.util.List; @@ -23,10 +23,9 @@ import org.slf4j.LoggerFactory; /** * message counter (by type) */ -public class MessageSpyCounterImpl implements MessageObservatory { +public class MessageSpyCounterImpl implements MessageObservatory { - private static final Logger LOG = LoggerFactory - .getLogger(MessageSpyCounterImpl.class); + private static final Logger LOG = LoggerFactory.getLogger(MessageSpyCounterImpl.class); private static final class MessageCounters { private static final AtomicLongFieldUpdater UPDATER = AtomicLongFieldUpdater.newUpdater(MessageCounters.class, "current"); diff --git a/openflowplugin/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/common/config/impl/rev140326/MsgSpyServiceModule.java b/openflowplugin/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/common/config/impl/rev140326/MsgSpyServiceModule.java new file mode 100644 index 0000000000..9d0acbac11 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/common/config/impl/rev140326/MsgSpyServiceModule.java @@ -0,0 +1,107 @@ +package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.common.config.impl.rev140326; + +import java.text.SimpleDateFormat; +import java.util.List; + +import org.opendaylight.openflowplugin.openflow.md.core.sal.OpenflowPluginProvider; +import org.opendaylight.openflowplugin.statistics.MessageCountDumper; +import org.opendaylight.openflowplugin.statistics.MessageObservatory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Strings; + +/** + * MsgSpyServiceModul implements and register own MsgSpyServiceRuntimeMXBean + * which is linked to {@link MessageObservatory} from {@link OpenflowPluginProvider} + * + * @author Vaclav Demcak + * + */ +public class MsgSpyServiceModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.common.config.impl.rev140326.AbstractMsgSpyServiceModule { + private static final Logger log = LoggerFactory.getLogger(MsgSpyServiceModule.class); + + private static final SimpleDateFormat ft = new SimpleDateFormat ("E yyyy.MM.dd 'at' hh:mm:ss a zzz"); + + public MsgSpyServiceModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, + final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + + super(identifier, dependencyResolver); + } + + public MsgSpyServiceModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, + final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, + final MsgSpyServiceModule oldModule, final java.lang.AutoCloseable oldInstance) { + + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + /* OpenflowPluginProvider provides MessageCountDumper implementation, so it can not be null */ + if (getOpenflowPluginProviderDependency() == null) { + throw new IllegalStateException("OpenflowPluginProvider is not accessible!"); + } + } + + @Override + public java.lang.AutoCloseable createInstance() { + final MessageCountDumper msg = getOpenflowPluginProviderDependency().getMessageCountDumper(); + + /* Internal MXBean implementation -> make statMsg from dumpMessageCounst only yet */ + final MsgSpyServiceRuntimeMXBean msgSpyBean = new MsgSpyServiceRuntimeMXBean() { + + @Override + public String makeMsgStatistics() { + if (msg == null) { + return "Message Spy Count Dumper is not avaliable."; + } + List statList = msg.dumpMessageCounts(); + + StringBuilder strBuilder = new StringBuilder(ft.format(System.currentTimeMillis())); + for (String stat : statList) { + strBuilder.append("\n").append(stat).append(Strings.repeat(" ", (100 -stat.length()))); + } + return strBuilder.toString(); + } + + @Override + public String getMsgStatistics() { + return makeMsgStatistics(); + } + }; + + /* MXBean registration */ + final MsgSpyServiceRuntimeRegistration runtimeReg = + getRootRuntimeBeanRegistratorWrapper().register(msgSpyBean); + + /* Internal MsgSpyService implementation */ + final class AutoClosableMsgSpyService implements MessageCountDumper, AutoCloseable { + + @Override + public void close() { + if (runtimeReg != null) { + try { + runtimeReg.close(); + } + catch (Exception e) { + String errMsg = "Error by stop MsgSpyService."; + log.error(errMsg, e); + throw new IllegalStateException(errMsg, e); + } + } + log.info(" Msg Stat Service consumer (instance {} turn down.)", this); + } + + @Override + public List dumpMessageCounts() { + return msg.dumpMessageCounts(); + } + } + + AutoCloseable ret = new AutoClosableMsgSpyService(); + log.info("MsgStatService (instance {}) initialized.", ret); + return ret; + } + +} diff --git a/openflowplugin/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/common/config/impl/rev140326/MsgSpyServiceModuleFactory.java b/openflowplugin/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/common/config/impl/rev140326/MsgSpyServiceModuleFactory.java new file mode 100644 index 0000000000..91c5a29721 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/common/config/impl/rev140326/MsgSpyServiceModuleFactory.java @@ -0,0 +1,13 @@ +/* +* Generated file +* +* Generated from: yang module name: openflow-provider-impl yang module local name: msg-spy-service-impl +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Fri Jul 04 09:53:32 CEST 2014 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.common.config.impl.rev140326; +public class MsgSpyServiceModuleFactory extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.common.config.impl.rev140326.AbstractMsgSpyServiceModuleFactory { + +} diff --git a/openflowplugin/src/main/yang/openflow-plugin-cfg-impl.yang b/openflowplugin/src/main/yang/openflow-plugin-cfg-impl.yang index 36827b731e..4d9780b2f2 100644 --- a/openflowplugin/src/main/yang/openflow-plugin-cfg-impl.yang +++ b/openflowplugin/src/main/yang/openflow-plugin-cfg-impl.yang @@ -4,6 +4,7 @@ module openflow-provider-impl { prefix "ofplugin-cfg-impl"; import config {prefix config; revision-date 2013-04-05;} + import rpc-context { prefix rpcx; revision-date 2013-06-17; } import openflow-provider {prefix openflow-provider;} import openflow-switch-connection-provider {prefix openflow-switch-connection-provider;revision-date 2014-03-28;} import opendaylight-md-sal-binding { prefix md-sal-binding; revision-date 2013-10-28;} @@ -23,6 +24,21 @@ module openflow-provider-impl { config:java-name-prefix ConfigurableOpenFlowProvider; } + identity msg-spy-service { + description + "MessageCountDumperServiceInterface as a MsgSpyService interface identity"; + base config:service-type; + config:java-class "org.opendaylight.openflowplugin.statistics.MessageCountDumper"; + } + + identity msg-spy-service-impl { + description + "This is the definition of MsgSpyService implementation module identity."; + base config:module-type; + config:provided-service msg-spy-service; + config:java-name-prefix MsgSpyService; + } + augment "/config:modules/config:module/config:configuration" { case openflow-provider-impl { when "/config:modules/config:module/config:type = 'openflow-provider-impl'"; @@ -44,5 +60,55 @@ module openflow-provider-impl { } } } + + case msg-spy-service-impl { + when "/config:modules/config:module/config:type = 'msg-spy-service-impl'"; + + container openflow-plugin-provider { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity openflow-provider:openflow-provider; + } + } + } + } + } + + augment "/config:modules/config:module/config:state" { + case msg-spy-service-impl { + when "/config:modules/config:module/config:type = 'msg-spy-service-impl'"; + + description + "MXBean designed for Message Statistic providing to JConsole."; + + leaf msgStatistics { + type string; + } + + rpcx:rpc-context-instance "make-msg-statistics-rpc"; + } + } + + identity make-msg-statistics-rpc; + + rpc make-msg-statistics { + + description + "Shortcut JMX call to getMsgStatistics."; + + input { + uses rpcx:rpc-context-ref { + refine context-instance { + rpcx:rpc-context-instance make-msg-statistics-rpc; + } + } + } + + output { + leaf result { + type string; + } + } } -} \ No newline at end of file +} diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImplTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImplTest.java index 2ded7ad0e8..af73158a3b 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImplTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImplTest.java @@ -33,9 +33,9 @@ import org.opendaylight.openflowplugin.openflow.md.core.plan.ConnectionAdapterSt import org.opendaylight.openflowplugin.openflow.md.core.plan.EventFactory; import org.opendaylight.openflowplugin.openflow.md.core.plan.SwitchTestEvent; import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext; -import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpy; import org.opendaylight.openflowplugin.openflow.md.queue.PopListener; import org.opendaylight.openflowplugin.openflow.md.queue.QueueProcessorLightImpl; +import org.opendaylight.openflowplugin.statistics.MessageSpy; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; -- 2.36.6