summaryrefslogtreecommitdiffstats
path: root/infra
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2017-08-10 14:39:30 +0200
committerMarek Gradzki <mgradzki@cisco.com>2017-08-14 07:01:06 +0000
commit6923420946f05308af6a073d270df41d069dd532 (patch)
treed5e233246a792d223e92253bcc19f1b9b579cc8b /infra
parentd0688f2883b3231e743dcd53bbf2203ec4639c6e (diff)
Shutdown closing of resources
Change-Id: If57a5414153cb983138872c7a1ded7c7066b1b6d Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'infra')
-rw-r--r--infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BGPExtensionConsumerContextProvider.java5
-rw-r--r--infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpRIBProvider.java50
-rw-r--r--infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/RIBExtensionConsumerContextProvider.java4
-rw-r--r--infra/northbound/netconf/src/main/java/io/fd/honeycomb/northbound/netconf/NetconfNotificationMapperProvider.java8
-rw-r--r--infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/JsonUtils.java24
5 files changed, 57 insertions, 34 deletions
diff --git a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BGPExtensionConsumerContextProvider.java b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BGPExtensionConsumerContextProvider.java
index 106a882ec..1bb0c5a1b 100644
--- a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BGPExtensionConsumerContextProvider.java
+++ b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BGPExtensionConsumerContextProvider.java
@@ -18,6 +18,7 @@ package io.fd.honeycomb.infra.bgp;
import com.google.inject.Inject;
import io.fd.honeycomb.binding.init.ProviderTrait;
+import io.fd.honeycomb.data.init.ShutdownHandler;
import java.util.ArrayList;
import java.util.Set;
import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
@@ -34,6 +35,9 @@ final class BGPExtensionConsumerContextProvider extends ProviderTrait<BGPExtensi
@Inject
private Set<BGPExtensionProviderActivator> activators;
+ @Inject
+ private ShutdownHandler shutdownHandler;
+
@Override
protected BGPExtensionConsumerContext create() {
final BGPExtensionProviderContext ctx = new SimpleBGPExtensionProviderContext();
@@ -41,6 +45,7 @@ final class BGPExtensionConsumerContextProvider extends ProviderTrait<BGPExtensi
new SimpleBGPExtensionProviderContextActivator(ctx, new ArrayList<>(activators));
LOG.debug("Starting BGPExtensionConsumerContext with activators: {}", activators);
activator.start();
+ shutdownHandler.register("bgp-extension-context-activator", activator);
return ctx;
}
}
diff --git a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpRIBProvider.java b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpRIBProvider.java
index a25808850..60d478325 100644
--- a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpRIBProvider.java
+++ b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpRIBProvider.java
@@ -21,6 +21,7 @@ import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUti
import com.google.common.collect.ImmutableList;
import com.google.inject.Inject;
import io.fd.honeycomb.binding.init.ProviderTrait;
+import io.fd.honeycomb.data.init.ShutdownHandler;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -70,6 +71,8 @@ final class BgpRIBProvider extends ProviderTrait<RIB> {
private BGPTableTypeRegistryConsumer tableTypeRegistry;
@Inject
private SchemaService schemaService;
+ @Inject
+ private ShutdownHandler shutdownHandler;
@Override
protected RIB create() {
@@ -79,48 +82,49 @@ final class BgpRIBProvider extends ProviderTrait<RIB> {
LOG.debug("Creating BGP RIB: routerId={}, asNumber={}", routerId, asNumber);
// TODO configure other BGP Multiprotocol extensions:
final List<AfiSafi> afiSafi = ImmutableList.of(
- new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
- .addAugmentation(AfiSafi2.class,
- new AfiSafi2Builder().setReceive(cfg.isBgpMultiplePathsEnabled())
- .setSendMax(cfg.bgpSendMaxMaths.get().shortValue()).build())
- .build(),
- new AfiSafiBuilder().setAfiSafiName(IPV4LABELLEDUNICAST.class)
- .addAugmentation(AfiSafi2.class,
- new AfiSafi2Builder().setReceive(cfg.isBgpMultiplePathsEnabled())
- .setSendMax(cfg.bgpSendMaxMaths.get().shortValue()).build())
- .build()
- );
+ new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
+ .addAugmentation(AfiSafi2.class,
+ new AfiSafi2Builder().setReceive(cfg.isBgpMultiplePathsEnabled())
+ .setSendMax(cfg.bgpSendMaxMaths.get().shortValue()).build())
+ .build(),
+ new AfiSafiBuilder().setAfiSafiName(IPV4LABELLEDUNICAST.class)
+ .addAugmentation(AfiSafi2.class,
+ new AfiSafi2Builder().setReceive(cfg.isBgpMultiplePathsEnabled())
+ .setSendMax(cfg.bgpSendMaxMaths.get().shortValue()).build())
+ .build()
+ );
final Map<TablesKey, PathSelectionMode> pathSelectionModes =
- OpenConfigMappingUtil.toPathSelectionMode(afiSafi, tableTypeRegistry)
- .entrySet().stream().collect(Collectors.toMap(entry ->
- new TablesKey(entry.getKey().getAfi(), entry.getKey().getSafi()), Map.Entry::getValue));
+ OpenConfigMappingUtil.toPathSelectionMode(afiSafi, tableTypeRegistry)
+ .entrySet().stream().collect(Collectors.toMap(entry ->
+ new TablesKey(entry.getKey().getAfi(), entry.getKey().getSafi()), Map.Entry::getValue));
// based on org.opendaylight.protocol.bgp.rib.impl.config.RibImpl.createRib
+ final PingPongDataBroker pingPongDataBroker = new PingPongDataBroker(domBroker);
final RIBImpl rib =
- new RIBImpl(new NoopClusterSingletonServiceProvider(), new RibId(cfg.bgpProtocolInstanceName.get()),
- asNumber, new BgpId(routerId), clusterId, extensions, dispatcher, codec,
- new PingPongDataBroker(domBroker), toTableTypes(afiSafi, tableTypeRegistry), pathSelectionModes,
- extensions.getClassLoadingStrategy(), null);
+ new RIBImpl(new NoopClusterSingletonServiceProvider(), new RibId(cfg.bgpProtocolInstanceName.get()),
+ asNumber, new BgpId(routerId), clusterId, extensions, dispatcher, codec,
+ pingPongDataBroker, toTableTypes(afiSafi, tableTypeRegistry), pathSelectionModes,
+ extensions.getClassLoadingStrategy(), null);
// required for proper RIB's CodecRegistry initialization (based on RIBImpl.start)
schemaService.registerSchemaContextListener(rib);
-
+ shutdownHandler.register("ping-pong-data-broker", pingPongDataBroker);
LOG.debug("BGP RIB created successfully: {}", rib);
return rib;
}
/**
- * HC does not support clustering, but BGP uses {@link ClusterSingletonServiceProvider}
- * to initialize {@link RIBImpl}. Therefore we provide this dummy implementation.
+ * HC does not support clustering, but BGP uses {@link ClusterSingletonServiceProvider} to initialize {@link
+ * RIBImpl}. Therefore we provide this dummy implementation.
*/
private static final class NoopClusterSingletonServiceProvider implements ClusterSingletonServiceProvider {
private static final Logger LOG = LoggerFactory.getLogger(NoopClusterSingletonServiceProvider.class);
private static final ClusterSingletonServiceRegistration REGISTRATION =
- () -> LOG.debug("Closing ClusterSingletonServiceRegistration");
+ () -> LOG.debug("Closing ClusterSingletonServiceRegistration");
@Override
public ClusterSingletonServiceRegistration registerClusterSingletonService(
- final ClusterSingletonService clusterSingletonService) {
+ final ClusterSingletonService clusterSingletonService) {
clusterSingletonService.instantiateServiceInstance();
return REGISTRATION;
}
diff --git a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/RIBExtensionConsumerContextProvider.java b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/RIBExtensionConsumerContextProvider.java
index 696726ac4..07ab86992 100644
--- a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/RIBExtensionConsumerContextProvider.java
+++ b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/RIBExtensionConsumerContextProvider.java
@@ -18,6 +18,7 @@ package io.fd.honeycomb.infra.bgp;
import com.google.inject.Inject;
import io.fd.honeycomb.binding.init.ProviderTrait;
+import io.fd.honeycomb.data.init.ShutdownHandler;
import java.util.ArrayList;
import java.util.Set;
import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
@@ -32,6 +33,8 @@ public class RIBExtensionConsumerContextProvider extends ProviderTrait<RIBExtens
private static final Logger LOG = LoggerFactory.getLogger(RIBExtensionConsumerContextProvider.class);
@Inject
private Set<RIBExtensionProviderActivator> activators;
+ @Inject
+ private ShutdownHandler shutdownHandler;
@Override
protected RIBExtensionConsumerContext create() {
@@ -40,6 +43,7 @@ public class RIBExtensionConsumerContextProvider extends ProviderTrait<RIBExtens
new SimpleRIBExtensionProviderContextActivator(ctx, new ArrayList<>(activators));
LOG.debug("Starting RIBExtensionConsumerContext with activators: {}", activators);
activator.start();
+ shutdownHandler.register("rib-extension-consumer-context-activator", activator);
return ctx;
}
}
diff --git a/infra/northbound/netconf/src/main/java/io/fd/honeycomb/northbound/netconf/NetconfNotificationMapperProvider.java b/infra/northbound/netconf/src/main/java/io/fd/honeycomb/northbound/netconf/NetconfNotificationMapperProvider.java
index d097e3419..e402f046d 100644
--- a/infra/northbound/netconf/src/main/java/io/fd/honeycomb/northbound/netconf/NetconfNotificationMapperProvider.java
+++ b/infra/northbound/netconf/src/main/java/io/fd/honeycomb/northbound/netconf/NetconfNotificationMapperProvider.java
@@ -19,6 +19,7 @@ package io.fd.honeycomb.northbound.netconf;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import io.fd.honeycomb.binding.init.ProviderTrait;
+import io.fd.honeycomb.data.init.ShutdownHandler;
import org.opendaylight.controller.config.yang.netconf.mdsal.notification.CapabilityChangeNotificationProducer;
import org.opendaylight.controller.config.yang.netconf.mdsal.notification.NotificationToMdsalWriter;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -54,6 +55,8 @@ public class NetconfNotificationMapperProvider extends ProviderTrait<NetconfOper
private DataBroker dataBroker;
@Inject
private NetconfOperationServiceFactoryListener aggregator;
+ @Inject
+ private ShutdownHandler shutdownHandler;
@Override
protected NetconfNotificationOperationServiceFactory create() {
@@ -68,6 +71,9 @@ public class NetconfNotificationMapperProvider extends ProviderTrait<NetconfOper
LOG.trace("Providing NetconfNotificationOperationServiceFactory");
NetconfNotificationOperationServiceFactory netconfNotificationOperationServiceFactory =
new NetconfNotificationOperationServiceFactory(notificationRegistry, aggregator);
- return netconfNotificationOperationServiceFactory;
+
+ shutdownHandler.register("netconf-notification-service-factory", netconfNotificationOperationServiceFactory);
+ shutdownHandler.register("notification-to-mdsal-writer", writer);
+ return netconfNotificationOperationServiceFactory;
}
}
diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/JsonUtils.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/JsonUtils.java
index 332bf6767..324efc24c 100644
--- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/JsonUtils.java
+++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/JsonUtils.java
@@ -19,6 +19,12 @@ package io.fd.honeycomb.translate.util;
import com.google.common.base.Charsets;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
@@ -39,9 +45,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.Nonnull;
-import java.io.*;
-
public final class JsonUtils {
private static final Logger LOG = LoggerFactory.getLogger(JsonUtils.class);
@@ -66,6 +69,8 @@ public final class JsonUtils {
writeChildren(normalizedNodeWriter,(ContainerNode) rootData);
jsonWriter.endObject();
jsonWriter.flush();
+ normalizedNodeWriter.close();
+ jsonWriter.close();
}
/**
@@ -87,9 +92,9 @@ public final class JsonUtils {
@Nonnull final SchemaNode parentSchema) {
final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> builder =
Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schemaContext.getQName()));
- final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(builder);
- try (final JsonParserStream jsonParser = JsonParserStream.create(writer, schemaContext, parentSchema)) {
+ try (final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(builder);
+ final JsonParserStream jsonParser = JsonParserStream.create(writer, schemaContext, parentSchema)) {
final JsonReader reader = new JsonReader(new InputStreamReader(stream, Charsets.UTF_8));
jsonParser.parse(reader);
} catch (IOException e) {
@@ -105,9 +110,9 @@ public final class JsonUtils {
@Nonnull final YangInstanceIdentifier.NodeIdentifier nodeIdentifier) {
final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> builder =
Builders.containerBuilder().withNodeIdentifier(nodeIdentifier);
- final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(builder);
- try (final JsonParserStream jsonParser = JsonParserStream.create(writer, schemaContext, parentSchema)) {
+ try (final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(builder);
+ final JsonParserStream jsonParser = JsonParserStream.create(writer, schemaContext, parentSchema)) {
final JsonReader reader = new JsonReader(new InputStreamReader(stream, Charsets.UTF_8));
jsonParser.parse(reader);
} catch (IOException e) {
@@ -124,9 +129,8 @@ public final class JsonUtils {
final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders.mapEntryBuilder()
.withNodeIdentifier(nodeIdentifier);
-
- final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(mapEntryBuilder);
- try (final JsonParserStream jsonParser = JsonParserStream.create(writer, schemaContext, parentSchema)) {
+ try (final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(mapEntryBuilder);
+ final JsonParserStream jsonParser = JsonParserStream.create(writer, schemaContext, parentSchema)) {
final JsonReader reader = new JsonReader(new InputStreamReader(stream, Charsets.UTF_8));
jsonParser.parse(reader);
} catch (IOException e) {