Switch to MD-SAL APIs
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginTestActivator.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowplugin.test;
9
10 import javax.annotation.PostConstruct;
11 import javax.annotation.PreDestroy;
12 import javax.inject.Singleton;
13 import org.apache.aries.blueprint.annotation.service.Reference;
14 import org.opendaylight.mdsal.binding.api.DataBroker;
15 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
16 import org.opendaylight.mdsal.binding.api.NotificationService;
17 import org.opendaylight.mdsal.binding.api.RpcProviderService;
18 import org.osgi.framework.BundleContext;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 @Singleton
23 public class OpenflowpluginTestActivator implements AutoCloseable {
24     private static final Logger LOG = LoggerFactory
25             .getLogger(OpenflowpluginTestActivator.class);
26
27     private RpcProviderService rpcRegistry;
28     private final OpenflowpluginTestServiceProvider provider;
29     private final OpenflowpluginGroupTestServiceProvider groupProvider = new OpenflowpluginGroupTestServiceProvider();
30     private final OpenflowpluginMeterTestServiceProvider meterProvider = new OpenflowpluginMeterTestServiceProvider();
31     private final OpenflowpluginTableFeaturesTestServiceProvider tableProvider =
32             new OpenflowpluginTableFeaturesTestServiceProvider();
33
34     private final OpenflowpluginTestCommandProvider cmdProvider;
35
36     private final OpenflowpluginGroupTestCommandProvider cmdGroupProvider;
37
38     private final OpenflowpluginMeterTestCommandProvider cmdMeterProvider;
39
40     private final OpenflowpluginTableFeaturesTestCommandProvider cmdTableProvider;
41
42     private final OpenflowpluginStatsTestCommandProvider cmdStatsProvider;
43
44     private final OpenflowpluginTestNodeConnectorNotification cmdNodeConnectorNotification;
45
46     private final OpenflowpluginTestTopologyNotification cmdTopologyNotification;
47
48     private final OpenflowPluginBulkTransactionProvider bulkCmdProvider;
49
50     private final OpenflowPluginBulkGroupTransactionProvider groupCmdProvider;
51
52     public static final String NODE_ID = "foo:node:1";
53
54     public OpenflowpluginTestActivator(@Reference DataBroker dataBroker,
55             @Reference NotificationService notificationService,
56             @Reference NotificationPublishService notificationPublishService, BundleContext ctx) {
57         provider = new OpenflowpluginTestServiceProvider(dataBroker, notificationPublishService);
58         OpenflowpluginTestCommandProvider openflowpluginTestCommandProvider = new OpenflowpluginTestCommandProvider(
59                 dataBroker, notificationService, ctx);
60         this.cmdProvider = openflowpluginTestCommandProvider;
61         OpenflowpluginGroupTestCommandProvider openflowpluginGroupTestCommandProvider =
62                 new OpenflowpluginGroupTestCommandProvider(dataBroker, ctx);
63         this.cmdGroupProvider = openflowpluginGroupTestCommandProvider;
64         OpenflowpluginMeterTestCommandProvider openflowpluginMeterTestCommandProvider =
65                 new OpenflowpluginMeterTestCommandProvider(dataBroker, notificationService, ctx);
66         this.cmdMeterProvider = openflowpluginMeterTestCommandProvider;
67         OpenflowpluginTableFeaturesTestCommandProvider openflowpluginTableFeaturesTestCommandProvider =
68                 new OpenflowpluginTableFeaturesTestCommandProvider(dataBroker, ctx);
69         this.cmdTableProvider = openflowpluginTableFeaturesTestCommandProvider;
70         OpenflowpluginStatsTestCommandProvider openflowpluginStatsTestCommandProvider =
71                 new OpenflowpluginStatsTestCommandProvider(dataBroker, ctx);
72         this.cmdStatsProvider = openflowpluginStatsTestCommandProvider;
73         OpenflowpluginTestNodeConnectorNotification openflowpluginTestNodeConnectorNotification =
74                 new OpenflowpluginTestNodeConnectorNotification(notificationService);
75         this.cmdNodeConnectorNotification = openflowpluginTestNodeConnectorNotification;
76         OpenflowpluginTestTopologyNotification openflowpluginTestTopologyNotification =
77                 new OpenflowpluginTestTopologyNotification(notificationService);
78         this.cmdTopologyNotification = openflowpluginTestTopologyNotification;
79         OpenflowPluginBulkTransactionProvider openflowPluginBulkTransactionProvider =
80                 new OpenflowPluginBulkTransactionProvider(dataBroker, notificationService, ctx);
81         this.bulkCmdProvider = openflowPluginBulkTransactionProvider;
82         OpenflowPluginBulkGroupTransactionProvider openflowPluginBulkGroupTransactionProvider =
83                 new OpenflowPluginBulkGroupTransactionProvider(dataBroker, notificationService, ctx);
84         this.groupCmdProvider = openflowPluginBulkGroupTransactionProvider;
85     }
86
87     @PostConstruct
88     public void init() {
89         provider.register(rpcRegistry);
90
91         groupProvider.register(rpcRegistry);
92         meterProvider.register(rpcRegistry);
93         tableProvider.register(rpcRegistry);
94
95         this.cmdProvider.init();
96         this.cmdGroupProvider.init();
97         this.cmdMeterProvider.init();
98         this.cmdTableProvider.init();
99         this.cmdStatsProvider.init();
100         this.cmdNodeConnectorNotification.init();
101         this.cmdTopologyNotification.init();
102         this.bulkCmdProvider.init();
103         this.groupCmdProvider.init();
104     }
105
106     @Override
107     @PreDestroy
108     @SuppressWarnings("checkstyle:IllegalCatch")
109     public void close() {
110         try {
111             provider.close();
112         } catch (Exception e) {
113             // TODO Auto-generated catch block
114             LOG.error("Stopping bundle OpenflowpluginTestActivator failed.", e);
115         }
116     }
117 }