<build>
<plugins>
- <plugin>
- <groupId>org.apache.aries.blueprint</groupId>
- <artifactId>blueprint-maven-plugin</artifactId>
- <configuration>
- <scanPaths>
- <!-- This is code migrated from openflowjava project and the java package
- does not match artifact groupId, we therefore need to override it.
- -->
- <scanPath>org.opendaylight.openflowjava</scanPath>
- </scanPaths>
- </configuration>
-
- </plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
</dependency>
+
<dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
+ <groupId>org.kohsuke.metainf-services</groupId>
+ <artifactId>metainf-services</artifactId>
</dependency>
<dependency>
- <groupId>javax.inject</groupId>
+ <groupId>com.guicedee.services</groupId>
<artifactId>javax.inject</artifactId>
<optional>true</optional>
</dependency>
<dependency>
- <groupId>javax.annotation</groupId>
- <artifactId>javax.annotation-api</artifactId>
- <optional>true</optional>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.component.annotations</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.aries.blueprint</groupId>
- <artifactId>blueprint-maven-plugin-annotation</artifactId>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <scope>provided</scope>
<optional>true</optional>
</dependency>
+
<dependency>
+ <!-- FIXME: configure slf4j-simple instead -->
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
+
<dependency>
<groupId>org.opendaylight.infrautils</groupId>
<artifactId>infrautils-util</artifactId>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<!-- Explicitly bring in the linux classifier, test may fail on 32-bit linux -->
+ <!--
+ FIXME: I don't think this is a good idea. We should be platform-agnostic
+ for build, so this works on Mac and others as well.
+ x86-64 Linux is tested in CSIT, where this library is present
+ -->
<classifier>linux-x86_64</classifier>
</dependency>
</dependencies>
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 java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import javax.annotation.PreDestroy;
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.ServiceRegistration;
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);
+public final class DefaultOpenflowDiagStatusProvider implements OpenflowDiagStatusProvider {
+ private static final Logger LOG = LoggerFactory.getLogger(DefaultOpenflowDiagStatusProvider.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<String, ServiceState> statusMap = new HashMap<>(Map.of(
+ private final ConcurrentMap<String, ServiceState> statusMap = new ConcurrentHashMap<>(Map.of(
OPENFLOW_SERVICE, STARTING,
OPENFLOW_SERVER_6633, STARTING,
OPENFLOW_SERVER_6653, STARTING));
+ private final DiagStatusService diagStatusService;
+
+ private ServiceRegistration reg;
@Inject
- public OpenflowDiagStatusProviderImpl(final @Reference DiagStatusService diagStatusService) {
+ public DefaultOpenflowDiagStatusProvider(final DiagStatusService diagStatusService) {
this.diagStatusService = diagStatusService;
- diagStatusService.register(OPENFLOW_SERVICE_AGGREGATE);
+ reg = diagStatusService.register(OPENFLOW_SERVICE_AGGREGATE);
+ }
+
+ @PreDestroy
+ public void close() {
+ if (reg != null) {
+ reg.unregister();
+ reg = null;
+ }
}
@Override
}
public void reportStatus() {
- boolean state = statusMap.values().stream().allMatch(serviceState -> serviceState.equals(OPERATIONAL));
- if (state) {
+ if (statusMap.values().stream().allMatch(OPERATIONAL::equals)) {
reportStatus(OPERATIONAL);
}
}
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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 com.google.common.base.Verify.verifyNotNull;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.infrautils.diagstatus.DiagStatusService;
+import org.opendaylight.infrautils.diagstatus.ServiceState;
+import org.opendaylight.openflowjava.protocol.api.connection.OpenflowDiagStatusProvider;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(immediate = true)
+// FIXME: integrate with DefaultOpenflowDiagStatusProvider once we have OSGi R7
+public final class OSGiOpenflowDiagStatusProvider implements OpenflowDiagStatusProvider {
+ private static final Logger LOG = LoggerFactory.getLogger(OSGiOpenflowDiagStatusProvider.class);
+
+ @Reference
+ DiagStatusService diagStatus;
+
+ private DefaultOpenflowDiagStatusProvider delegate = null;
+
+ @Override
+ public void reportStatus(final ServiceState serviceState) {
+ delegate().reportStatus(serviceState);
+ }
+
+ @Override
+ public void reportStatus(final String diagStatusService, final Throwable throwable) {
+ delegate().reportStatus(diagStatusService, throwable);
+ }
+
+ @Override
+ public void reportStatus(final String diagStatusIdentifier, final ServiceState serviceState,
+ final String description) {
+ delegate().reportStatus(diagStatusIdentifier, serviceState, description);
+ }
+
+ @Override
+ public void reportStatus(final String diagStatusIdentifier, final ServiceState serviceState) {
+ delegate().reportStatus(diagStatusIdentifier, serviceState);
+ }
+
+ @Activate
+ void activate() {
+ delegate = new DefaultOpenflowDiagStatusProvider(diagStatus);
+ LOG.info("OpenFlow diagnostic status provider activated");
+ }
+
+ @Deactivate
+ void deactivate() {
+ delegate.close();
+ delegate = null;
+ LOG.info("OpenFlow diagnostic status provider deactivated");
+ }
+
+ private @NonNull DefaultOpenflowDiagStatusProvider delegate() {
+ return verifyNotNull(delegate);
+ }
+}
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.Service;
+import org.kohsuke.MetaInfServices;
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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.config.rev160506.SwitchConnectionConfig;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.config.rev160506._switch.connection.config.Threads;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.config.rev160506._switch.connection.config.Tls;
+import org.osgi.service.component.annotations.Component;
/**
* Implementation of the SwitchConnectionProviderFactory interface.
*/
+@MetaInfServices
@Singleton
-@Service(classes = SwitchConnectionProviderFactory.class)
+@Component(immediate = true)
public class SwitchConnectionProviderFactoryImpl implements SwitchConnectionProviderFactory {
+ @Inject
+ public SwitchConnectionProviderFactoryImpl() {
+ // Exposed for DI
+ }
@Override
public SwitchConnectionProvider newInstance(final SwitchConnectionConfig config,
- final OpenflowDiagStatusProvider openflowPluginDiagStatusProvider) {
- return new SwitchConnectionProviderImpl(new ConnectionConfigurationImpl(config),
- openflowPluginDiagStatusProvider);
+ final OpenflowDiagStatusProvider diagStatus) {
+ return new SwitchConnectionProviderImpl(new ConnectionConfigurationImpl(config), diagStatus);
}
private static class ConnectionConfigurationImpl implements ConnectionConfiguration {