From: Shweta Chaturvedi Date: Mon, 21 Jan 2019 12:14:40 +0000 (+0530) Subject: OPNFLWPLUG-1064: Openflow diagstatus: Merge all X-Git-Tag: release/sodium~55 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=58d7c6cf3e627228df8253e9c20666162200d44d;p=openflowplugin.git OPNFLWPLUG-1064: Openflow diagstatus: Merge all the 3 openflow services into one "OPENFLOW" Change-Id: I6d192ca72153f48892d8ee14c6e0d10f41c40dfc Signed-off-by: Shweta Chaturvedi --- diff --git a/openflowjava/openflow-protocol-api/pom.xml b/openflowjava/openflow-protocol-api/pom.xml index 96595d9982..1215163f7d 100644 --- a/openflowjava/openflow-protocol-api/pom.xml +++ b/openflowjava/openflow-protocol-api/pom.xml @@ -54,5 +54,11 @@ org.mockito mockito-core + + org.opendaylight.infrautils + diagstatus-api + ${infrautils.version} + compile + diff --git a/openflowjava/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/OpenflowDiagStatusProvider.java b/openflowjava/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/OpenflowDiagStatusProvider.java new file mode 100644 index 0000000000..dfb2c45377 --- /dev/null +++ b/openflowjava/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/OpenflowDiagStatusProvider.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2019 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.api.connection; + +import org.opendaylight.infrautils.diagstatus.ServiceState; + +public interface OpenflowDiagStatusProvider { + + void reportStatus(ServiceState serviceState); + + void reportStatus(String diagStatusService, Throwable throwable); + + void reportStatus(String diagStatusIdentifier, ServiceState serviceState, String description); + + void reportStatus(String diagStatusIdentifier, ServiceState serviceState); +} + + diff --git a/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OpenflowDiagStatusProviderImpl.java b/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OpenflowDiagStatusProviderImpl.java new file mode 100644 index 0000000000..9c877711f5 --- /dev/null +++ b/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OpenflowDiagStatusProviderImpl.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2019 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.core; + +import static org.opendaylight.infrautils.diagstatus.ServiceState.ERROR; +import static org.opendaylight.infrautils.diagstatus.ServiceState.OPERATIONAL; +import static org.opendaylight.infrautils.diagstatus.ServiceState.STARTING; + +import java.util.HashMap; +import java.util.Map; +import javax.inject.Inject; +import javax.inject.Singleton; +import org.apache.aries.blueprint.annotation.service.Reference; +import org.apache.aries.blueprint.annotation.service.Service; +import org.opendaylight.infrautils.diagstatus.DiagStatusService; +import org.opendaylight.infrautils.diagstatus.ServiceDescriptor; +import org.opendaylight.infrautils.diagstatus.ServiceState; +import org.opendaylight.openflowjava.protocol.api.connection.OpenflowDiagStatusProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Singleton +@Service(classes = OpenflowDiagStatusProvider.class) +public class OpenflowDiagStatusProviderImpl implements OpenflowDiagStatusProvider { + private static final Logger LOG = LoggerFactory.getLogger(OpenflowDiagStatusProviderImpl.class); + private static final String OPENFLOW_SERVICE = "OPENFLOW"; + private static final String OPENFLOW_SERVER_6633 = "OPENFLOW_SERVER_6633"; + private static final String OPENFLOW_SERVER_6653 = "OPENFLOW_SERVER_6653"; + private static final String OPENFLOW_SERVICE_AGGREGATE = OPENFLOW_SERVICE; + + private final DiagStatusService diagStatusService; + private volatile Map statusMap = new HashMap() {{ + put(OPENFLOW_SERVICE, STARTING); + put(OPENFLOW_SERVER_6633, STARTING); + put(OPENFLOW_SERVER_6653, STARTING); + } + }; + + @Inject + public OpenflowDiagStatusProviderImpl(final @Reference DiagStatusService diagStatusService) { + this.diagStatusService = diagStatusService; + diagStatusService.register(OPENFLOW_SERVICE_AGGREGATE); + } + + @Override + public void reportStatus(final ServiceState serviceState) { + LOG.debug("reporting status as {} for {}", serviceState,OPENFLOW_SERVICE_AGGREGATE); + diagStatusService.report(new ServiceDescriptor(OPENFLOW_SERVICE_AGGREGATE, serviceState)); + } + + @Override + public void reportStatus(final String diagStatusIdentifier, final Throwable throwable) { + LOG.debug("Reporting error for {} as {}", diagStatusIdentifier, throwable.toString()); + statusMap.replace(diagStatusIdentifier, ERROR); + diagStatusService.report(new ServiceDescriptor(OPENFLOW_SERVICE_AGGREGATE, throwable)); + } + + @Override + public void reportStatus(final String diagStatusIdentifier, final ServiceState serviceState, + final String description) { + LOG.debug("Reporting status {} for {} and desc {}", serviceState, diagStatusIdentifier, description); + diagStatusService.report(new ServiceDescriptor(OPENFLOW_SERVICE_AGGREGATE, serviceState, description)); + } + + @Override + public void reportStatus(final String diagStatusIdentifier, final ServiceState serviceState) { + statusMap.replace(diagStatusIdentifier, serviceState); + LOG.info("The report status is {} for {}", serviceState, diagStatusIdentifier); + reportStatus(); + } + + public void reportStatus() { + boolean state = statusMap.values().stream().allMatch(serviceState -> serviceState.equals(OPERATIONAL)); + if (state) { + reportStatus(OPERATIONAL); + } + } +} \ No newline at end of file diff --git a/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderFactoryImpl.java b/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderFactoryImpl.java index 319c5b9622..63357e1d67 100644 --- a/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderFactoryImpl.java +++ b/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderFactoryImpl.java @@ -11,12 +11,10 @@ import com.google.common.base.MoreObjects; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.List; -import javax.inject.Inject; import javax.inject.Singleton; -import org.apache.aries.blueprint.annotation.service.Reference; import org.apache.aries.blueprint.annotation.service.Service; -import org.opendaylight.infrautils.diagstatus.DiagStatusService; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration; +import org.opendaylight.openflowjava.protocol.api.connection.OpenflowDiagStatusProvider; import org.opendaylight.openflowjava.protocol.api.connection.ThreadConfiguration; import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration; import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider; @@ -35,16 +33,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow @Service(classes = SwitchConnectionProviderFactory.class) public class SwitchConnectionProviderFactoryImpl implements SwitchConnectionProviderFactory { - private final DiagStatusService diagStatusService; - - @Inject - public SwitchConnectionProviderFactoryImpl(@Reference DiagStatusService diagStatusService) { - this.diagStatusService = diagStatusService; - } - @Override - public SwitchConnectionProvider newInstance(SwitchConnectionConfig config) { - return new SwitchConnectionProviderImpl(new ConnectionConfigurationImpl(config), diagStatusService); + public SwitchConnectionProvider newInstance(SwitchConnectionConfig config, + OpenflowDiagStatusProvider openflowPluginDiagStatusProvider) { + return new SwitchConnectionProviderImpl(new ConnectionConfigurationImpl(config), + openflowPluginDiagStatusProvider); } private static InetAddress getInetAddress(final IpAddress address) throws UnknownHostException { diff --git a/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java b/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java index 40adc5716b..b0f5381074 100755 --- a/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java +++ b/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java @@ -17,11 +17,10 @@ import com.google.common.util.concurrent.MoreExecutors; import io.netty.channel.EventLoopGroup; import io.netty.channel.epoll.Epoll; import org.checkerframework.checker.nullness.qual.Nullable; -import org.opendaylight.infrautils.diagstatus.DiagStatusService; -import org.opendaylight.infrautils.diagstatus.ServiceDescriptor; import org.opendaylight.infrautils.diagstatus.ServiceState; import org.opendaylight.infrautils.utils.concurrent.Executors; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration; +import org.opendaylight.openflowjava.protocol.api.connection.OpenflowDiagStatusProvider; import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler; import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; @@ -80,23 +79,19 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, C private final DeserializerRegistry deserializerRegistry; private final DeserializationFactory deserializationFactory; private final ListeningExecutorService listeningExecutorService; - private final DiagStatusService diagStatusService; private final String diagStatusIdentifier; private final String threadName; private TcpConnectionInitializer connectionInitializer; + private OpenflowDiagStatusProvider openflowDiagStatusProvider; public SwitchConnectionProviderImpl( - @Nullable ConnectionConfiguration connConfig, DiagStatusService diagStatusService) { + @Nullable ConnectionConfiguration connConfig, OpenflowDiagStatusProvider openflowDiagStatusProvider) { this.connConfig = connConfig; String connectionSuffix = createConnectionSuffix(connConfig); - - this.diagStatusService = diagStatusService; this.diagStatusIdentifier = OPENFLOW_JAVA_SERVICE_NAME_PREFIX + connectionSuffix; - diagStatusService.register(diagStatusIdentifier); - + this.openflowDiagStatusProvider = openflowDiagStatusProvider; this.threadName = THREAD_NAME_PREFIX + connectionSuffix; this.listeningExecutorService = Executors.newListeningSingleThreadExecutor(threadName, LOG); - serializerRegistry = new SerializerRegistryImpl(); if (connConfig != null) { serializerRegistry.setGroupAddModConfig(connConfig.isGroupAddModEnabled()); @@ -150,13 +145,13 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, C @Override public void onFailure(Throwable throwable) { - diagStatusService.report(new ServiceDescriptor(diagStatusIdentifier, throwable)); + openflowDiagStatusProvider.reportStatus(diagStatusIdentifier, throwable); } @Override public void onSuccess(@Nullable Object nullResult) { - diagStatusService.report(new ServiceDescriptor( - diagStatusIdentifier, ServiceState.ERROR, threadName + " terminated")); + openflowDiagStatusProvider.reportStatus(diagStatusIdentifier, ServiceState.ERROR, + threadName + " terminated"); } } , MoreExecutors.directExecutor()); return serverFacade.getIsOnlineFuture(); @@ -177,25 +172,23 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, C factory.setUseBarrier(connConfig.useBarrier()); factory.setChannelOutboundQueueSize(connConfig.getChannelOutboundQueueSize()); final TransportProtocol transportProtocol = (TransportProtocol) connConfig.getTransferProtocol(); - // Check if Epoll native transport is available. // TODO : Add option to disable Epoll. boolean isEpollEnabled = Epoll.isAvailable(); if (TransportProtocol.TCP.equals(transportProtocol) || TransportProtocol.TLS.equals(transportProtocol)) { - server = new TcpHandler(connConfig.getAddress(), connConfig.getPort(), () -> diagStatusService - .report(new ServiceDescriptor(diagStatusIdentifier, ServiceState.OPERATIONAL))); + server = new TcpHandler(connConfig.getAddress(), connConfig.getPort(), () -> + openflowDiagStatusProvider.reportStatus(diagStatusIdentifier, ServiceState.OPERATIONAL)); final TcpChannelInitializer channelInitializer = factory.createPublishingChannelInitializer(); ((TcpHandler) server).setChannelInitializer(channelInitializer); ((TcpHandler) server).initiateEventLoopGroups(connConfig.getThreadConfiguration(), isEpollEnabled); - final EventLoopGroup workerGroupFromTcpHandler = ((TcpHandler) server).getWorkerGroup(); connectionInitializer = new TcpConnectionInitializer(workerGroupFromTcpHandler, isEpollEnabled); connectionInitializer.setChannelInitializer(channelInitializer); connectionInitializer.run(); } else if (TransportProtocol.UDP.equals(transportProtocol)) { - server = new UdpHandler(connConfig.getAddress(), connConfig.getPort(), () -> diagStatusService - .report(new ServiceDescriptor(diagStatusIdentifier, ServiceState.OPERATIONAL))); + server = new UdpHandler(connConfig.getAddress(), connConfig.getPort(), () -> + openflowDiagStatusProvider.reportStatus(diagStatusIdentifier, ServiceState.OPERATIONAL)); ((UdpHandler) server).initiateEventLoopGroups(connConfig.getThreadConfiguration(), isEpollEnabled); ((UdpHandler) server).setChannelInitializer(factory.createUdpChannelInitializer()); } else { diff --git a/openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImpl02Test.java b/openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImpl02Test.java index e43e93b3ff..fcfc1a461f 100755 --- a/openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImpl02Test.java +++ b/openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImpl02Test.java @@ -15,7 +15,7 @@ import org.junit.Assert; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.opendaylight.infrautils.diagstatus.DiagStatusService; +import org.opendaylight.openflowjava.protocol.api.connection.OpenflowDiagStatusProvider; import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler; import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration; import org.opendaylight.openflowjava.protocol.api.connection.TlsConfigurationImpl; @@ -59,7 +59,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * @author michal.polkorab */ public class SwitchConnectionProviderImpl02Test { - @Mock DiagStatusService diagStatusService; @Mock SwitchConnectionHandler handler; @Mock OFGeneralSerializer serializer; @Mock OFGeneralDeserializer deserializer; @@ -72,6 +71,7 @@ public class SwitchConnectionProviderImpl02Test { @Mock OFSerializer serializerMultipartRequestExpCase; @Mock OFSerializer serializerMeterBandExpCase; @Mock ConnectionConfigurationImpl config; + @Mock OpenflowDiagStatusProvider openflowPluginDiagStatusProvider; private static final int CHANNEL_OUTBOUND_QUEUE_SIZE = 1024; private static final int SWITCH_IDLE_TIMEOUT = 2000; private TlsConfiguration tlsConfiguration; @@ -88,7 +88,7 @@ public class SwitchConnectionProviderImpl02Test { if (protocol != null) { createConfig(protocol); } - provider = new SwitchConnectionProviderImpl(config, diagStatusService); + provider = new SwitchConnectionProviderImpl(config,openflowPluginDiagStatusProvider); } private void createConfig(final TransportProtocol protocol) throws UnknownHostException { diff --git a/openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImplTest.java b/openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImplTest.java index 4ebdd96983..ca6bc3e50e 100644 --- a/openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImplTest.java +++ b/openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImplTest.java @@ -19,7 +19,7 @@ import org.junit.Assert; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.opendaylight.infrautils.diagstatus.DiagStatusService; +import org.opendaylight.openflowjava.protocol.api.connection.OpenflowDiagStatusProvider; import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler; import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration; import org.opendaylight.openflowjava.protocol.api.connection.TlsConfigurationImpl; @@ -38,7 +38,7 @@ import org.slf4j.LoggerFactory; public class SwitchConnectionProviderImplTest { @Mock SwitchConnectionHandler handler; - @Mock DiagStatusService diagStatusService; + @Mock OpenflowDiagStatusProvider openflowPluginDiagStatusProvider; private static final int SWITCH_IDLE_TIMEOUT = 2000; private static final int WAIT_TIMEOUT = 2000; @@ -51,13 +51,14 @@ public class SwitchConnectionProviderImplTest { * Creates new {@link SwitchConnectionProvider} instance for each test. * @param protocol communication protocol */ + public void startUp(final TransportProtocol protocol) throws UnknownHostException { MockitoAnnotations.initMocks(this); config = null; if (protocol != null) { createConfig(protocol); } - provider = new SwitchConnectionProviderImpl(config, diagStatusService); + provider = new SwitchConnectionProviderImpl(config, openflowPluginDiagStatusProvider); } private void createConfig(final TransportProtocol protocol) throws UnknownHostException { diff --git a/openflowjava/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/it/integration/IntegrationTest.java b/openflowjava/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/it/integration/IntegrationTest.java index 92c9d64bc9..63bd44a6f6 100644 --- a/openflowjava/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/it/integration/IntegrationTest.java +++ b/openflowjava/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/it/integration/IntegrationTest.java @@ -18,7 +18,7 @@ import java.util.concurrent.TimeoutException; import org.junit.After; import org.junit.Test; import org.mockito.Mockito; -import org.opendaylight.infrautils.diagstatus.DiagStatusService; +import org.opendaylight.openflowjava.protocol.api.connection.OpenflowDiagStatusProvider; import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration; import org.opendaylight.openflowjava.protocol.api.connection.TlsConfigurationImpl; import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent; @@ -88,7 +88,8 @@ public class IntegrationTest { connConfig.setTransferProtocol(protocol); mockPlugin = new MockPlugin(); - switchConnectionProvider = new SwitchConnectionProviderImpl(connConfig, Mockito.mock(DiagStatusService.class)); + switchConnectionProvider = new SwitchConnectionProviderImpl(connConfig, + Mockito.mock(OpenflowDiagStatusProvider.class)); switchConnectionProvider.setSwitchConnectionHandler(mockPlugin); switchConnectionProvider.startup().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); if (protocol.equals(TransportProtocol.TCP) || protocol.equals(TransportProtocol.TLS)) { diff --git a/openflowjava/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProviderFactory.java b/openflowjava/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProviderFactory.java index 9ef8c4dda6..d0447af2dd 100644 --- a/openflowjava/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProviderFactory.java +++ b/openflowjava/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProviderFactory.java @@ -7,6 +7,7 @@ */ package org.opendaylight.openflowjava.protocol.spi.connection; +import org.opendaylight.openflowjava.protocol.api.connection.OpenflowDiagStatusProvider; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.config.rev160506.SwitchConnectionConfig; /** @@ -21,5 +22,6 @@ public interface SwitchConnectionProviderFactory { * @param config the SwitchConnectionConfig * @return a SwitchConnectionProvider instance */ - SwitchConnectionProvider newInstance(SwitchConnectionConfig config); + SwitchConnectionProvider newInstance(SwitchConnectionConfig config, + OpenflowDiagStatusProvider openflowPluginDiagStatusProvider); } diff --git a/openflowjava/openflowjava-blueprint-config/src/main/resources/OSGI-INF/blueprint/openflowjava.xml b/openflowjava/openflowjava-blueprint-config/src/main/resources/OSGI-INF/blueprint/openflowjava.xml index d26b04ea4e..9043183f32 100644 --- a/openflowjava/openflowjava-blueprint-config/src/main/resources/OSGI-INF/blueprint/openflowjava.xml +++ b/openflowjava/openflowjava-blueprint-config/src/main/resources/OSGI-INF/blueprint/openflowjava.xml @@ -1,9 +1,8 @@ - + - + @@ -22,6 +22,7 @@ + diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java index 4934a86aa6..a37ce0267b 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java @@ -49,6 +49,7 @@ import org.opendaylight.mdsal.binding.api.NotificationPublishService; import org.opendaylight.mdsal.binding.api.RpcProviderService; import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; +import org.opendaylight.openflowjava.protocol.api.connection.OpenflowDiagStatusProvider; import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider; import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProviderList; import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginProvider; @@ -126,8 +127,9 @@ public class OpenFlowPluginProviderImpl implements private ConnectionManager connectionManager; private ListeningExecutorService executorService; private ContextChainHolderImpl contextChainHolder; - private final OpenflowPluginDiagStatusProvider openflowPluginStatusMonitor; + private final OpenflowDiagStatusProvider openflowDiagStatusProvider; private final SettableFuture fullyStarted = SettableFuture.create(); + private static final String OPENFLOW_SERVICE_NAME = "OPENFLOW"; public static MessageIntelligenceAgency getMessageIntelligenceAgency() { return MESSAGE_INTELLIGENCE_AGENCY; @@ -142,7 +144,7 @@ public class OpenFlowPluginProviderImpl implements final @Reference ClusterSingletonServiceProvider singletonServiceProvider, final @Reference EntityOwnershipService entityOwnershipService, final MastershipChangeServiceManager mastershipChangeServiceManager, - final OpenflowPluginDiagStatusProvider openflowPluginStatusMonitor, + final @Reference OpenflowDiagStatusProvider openflowDiagStatusProvider, final @Reference SystemReadyMonitor systemReadyMonitor) { this.switchConnectionProviders = switchConnectionProviders; this.dataBroker = pingPongDataBroker; @@ -155,7 +157,7 @@ public class OpenFlowPluginProviderImpl implements deviceInitializerProvider = DeviceInitializerProviderFactory.createDefaultProvider(); config = new OpenFlowProviderConfigImpl(configurationService); this.mastershipChangeServiceManager = mastershipChangeServiceManager; - this.openflowPluginStatusMonitor = openflowPluginStatusMonitor; + this.openflowDiagStatusProvider = openflowDiagStatusProvider; systemReadyMonitor.registerListener(this); LOG.info("registered onSystemBootReady() listener for deferred startSwitchConnections()"); } @@ -180,14 +182,14 @@ public class OpenFlowPluginProviderImpl implements @Override public void onSuccess(@Nonnull final List result) { LOG.info("All switchConnectionProviders are up and running ({}).", result.size()); - openflowPluginStatusMonitor.reportStatus(ServiceState.OPERATIONAL); + openflowDiagStatusProvider.reportStatus(OPENFLOW_SERVICE_NAME, ServiceState.OPERATIONAL); fullyStarted.set(null); } @Override public void onFailure(@Nonnull final Throwable throwable) { LOG.warn("Some switchConnectionProviders failed to start.", throwable); - openflowPluginStatusMonitor.reportStatus(ServiceState.ERROR, throwable); + openflowDiagStatusProvider.reportStatus(OPENFLOW_SERVICE_NAME, throwable); fullyStarted.setException(throwable); } }, MoreExecutors.directExecutor()); @@ -311,7 +313,7 @@ public class OpenFlowPluginProviderImpl implements gracefulShutdown(executorService); gracefulShutdown(hashedWheelTimer); unregisterMXBean(MESSAGE_INTELLIGENCE_AGENCY_MX_BEAN_NAME); - openflowPluginStatusMonitor.reportStatus(ServiceState.UNREGISTERED); + openflowDiagStatusProvider.reportStatus(ServiceState.UNREGISTERED); } @SuppressWarnings("checkstyle:IllegalCatch") diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenflowPluginDiagStatusProvider.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenflowPluginDiagStatusProvider.java deleted file mode 100644 index bdaafb2429..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenflowPluginDiagStatusProvider.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.openflowplugin.impl; - -import javax.inject.Inject; -import javax.inject.Singleton; -import org.apache.aries.blueprint.annotation.service.Reference; -import org.opendaylight.infrautils.diagstatus.DiagStatusService; -import org.opendaylight.infrautils.diagstatus.ServiceDescriptor; -import org.opendaylight.infrautils.diagstatus.ServiceState; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Singleton -public class OpenflowPluginDiagStatusProvider { - - private static final Logger LOG = LoggerFactory.getLogger(OpenflowPluginDiagStatusProvider.class); - private static final String OPENFLOW_SERVICE_NAME = "OPENFLOW"; - - private final DiagStatusService diagStatusService; - - @Inject - public OpenflowPluginDiagStatusProvider(final @Reference DiagStatusService diagStatusService) { - this.diagStatusService = diagStatusService; - diagStatusService.register(OPENFLOW_SERVICE_NAME); - } - - public void reportStatus(ServiceState serviceState) { - LOG.debug("reporting status as {} for {}", serviceState, OPENFLOW_SERVICE_NAME); - diagStatusService.report(new ServiceDescriptor(OPENFLOW_SERVICE_NAME, serviceState)); - } - - public void reportStatus(ServiceState serviceState, Throwable throwable) { - LOG.debug("reporting status as {} for {}", serviceState, OPENFLOW_SERVICE_NAME); - diagStatusService.report(new ServiceDescriptor(OPENFLOW_SERVICE_NAME, throwable)); - } - - public void reportStatus(ServiceState serviceState, String description) { - LOG.debug("reporting status as {} for {}", serviceState, OPENFLOW_SERVICE_NAME); - diagStatusService.report(new ServiceDescriptor(OPENFLOW_SERVICE_NAME, serviceState, description)); - } -} diff --git a/openflowplugin-impl/src/main/resources/OSGI-INF/blueprint/openflowplugin-impl.xml b/openflowplugin-impl/src/main/resources/OSGI-INF/blueprint/openflowplugin-impl.xml index 85726b4273..d6c0514cc8 100644 --- a/openflowplugin-impl/src/main/resources/OSGI-INF/blueprint/openflowplugin-impl.xml +++ b/openflowplugin-impl/src/main/resources/OSGI-INF/blueprint/openflowplugin-impl.xml @@ -30,5 +30,7 @@ + + diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImplTest.java index 24383c5469..a1caa8aa33 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImplTest.java @@ -28,6 +28,7 @@ import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipListenerRegistration; import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; +import org.opendaylight.openflowjava.protocol.api.connection.OpenflowDiagStatusProvider; import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider; import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProviderList; import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationProperty; @@ -49,7 +50,7 @@ public class OpenFlowPluginProviderImplTest { NotificationPublishService notificationPublishService; @Mock - OpenflowPluginDiagStatusProvider ofPluginDiagstatusProvider; + OpenflowDiagStatusProvider ofPluginDiagstatusProvider; @Mock SystemReadyMonitor systemReadyMonitor;