a62774cef3e0a8402a5f2b71e7eb6f186b2d883b
[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
9 package org.opendaylight.openflowplugin.test;
10
11 import javax.annotation.PostConstruct;
12 import javax.annotation.PreDestroy;
13 import javax.inject.Singleton;
14 import org.apache.aries.blueprint.annotation.service.Reference;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
17 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
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 DataBroker dataBroker;
28     private NotificationProviderService notificationService;
29     private RpcProviderRegistry rpcRegistry;
30     private final OpenflowpluginTestServiceProvider provider;
31     private final OpenflowpluginGroupTestServiceProvider groupProvider = new OpenflowpluginGroupTestServiceProvider();
32     private final OpenflowpluginMeterTestServiceProvider meterProvider = new OpenflowpluginMeterTestServiceProvider();
33     private final OpenflowpluginTableFeaturesTestServiceProvider tableProvider =
34             new OpenflowpluginTableFeaturesTestServiceProvider();
35
36     private final OpenflowpluginTestCommandProvider cmdProvider;
37
38     private final OpenflowpluginGroupTestCommandProvider cmdGroupProvider;
39
40     private final OpenflowpluginMeterTestCommandProvider cmdMeterProvider;
41
42     private final OpenflowpluginTableFeaturesTestCommandProvider cmdTableProvider;
43
44     private final OpenflowpluginStatsTestCommandProvider cmdStatsProvider;
45
46     private final OpenflowpluginTestNodeConnectorNotification cmdNodeConnectorNotification;
47
48     private final OpenflowpluginTestTopologyNotification cmdTopologyNotification;
49
50     private final OpenflowPluginBulkTransactionProvider bulkCmdProvider;
51
52     private final OpenflowPluginBulkGroupTransactionProvider groupCmdProvider;
53
54     public static final String NODE_ID = "foo:node:1";
55
56     public OpenflowpluginTestActivator(@Reference DataBroker dataBroker,
57             @Reference NotificationProviderService notificationService, BundleContext ctx) {
58         provider = new OpenflowpluginTestServiceProvider(dataBroker, notificationService);
59         OpenflowpluginTestCommandProvider openflowpluginTestCommandProvider = new OpenflowpluginTestCommandProvider(
60                 dataBroker, notificationService, ctx);
61         this.cmdProvider = openflowpluginTestCommandProvider;
62         OpenflowpluginGroupTestCommandProvider openflowpluginGroupTestCommandProvider =
63                 new OpenflowpluginGroupTestCommandProvider(dataBroker, ctx);
64         this.cmdGroupProvider = openflowpluginGroupTestCommandProvider;
65         OpenflowpluginMeterTestCommandProvider openflowpluginMeterTestCommandProvider =
66                 new OpenflowpluginMeterTestCommandProvider(dataBroker, notificationService, ctx);
67         this.cmdMeterProvider = openflowpluginMeterTestCommandProvider;
68         OpenflowpluginTableFeaturesTestCommandProvider openflowpluginTableFeaturesTestCommandProvider =
69                 new OpenflowpluginTableFeaturesTestCommandProvider(dataBroker, ctx);
70         this.cmdTableProvider = openflowpluginTableFeaturesTestCommandProvider;
71         OpenflowpluginStatsTestCommandProvider openflowpluginStatsTestCommandProvider =
72                 new OpenflowpluginStatsTestCommandProvider(dataBroker, ctx);
73         this.cmdStatsProvider = openflowpluginStatsTestCommandProvider;
74         OpenflowpluginTestNodeConnectorNotification openflowpluginTestNodeConnectorNotification =
75                 new OpenflowpluginTestNodeConnectorNotification(notificationService);
76         this.cmdNodeConnectorNotification = openflowpluginTestNodeConnectorNotification;
77         OpenflowpluginTestTopologyNotification openflowpluginTestTopologyNotification =
78                 new OpenflowpluginTestTopologyNotification(notificationService);
79         this.cmdTopologyNotification = openflowpluginTestTopologyNotification;
80         OpenflowPluginBulkTransactionProvider openflowPluginBulkTransactionProvider =
81                 new OpenflowPluginBulkTransactionProvider(dataBroker, notificationService, ctx);
82         this.bulkCmdProvider = openflowPluginBulkTransactionProvider;
83         OpenflowPluginBulkGroupTransactionProvider openflowPluginBulkGroupTransactionProvider =
84                 new OpenflowPluginBulkGroupTransactionProvider(dataBroker, notificationService, ctx);
85         this.groupCmdProvider = openflowPluginBulkGroupTransactionProvider;
86     }
87
88     @PostConstruct
89     public void init() {
90         provider.register(rpcRegistry);
91
92         groupProvider.register(rpcRegistry);
93         meterProvider.register(rpcRegistry);
94         tableProvider.register(rpcRegistry);
95
96         this.cmdProvider.init();
97         this.cmdGroupProvider.init();
98         this.cmdMeterProvider.init();
99         this.cmdTableProvider.init();
100         this.cmdStatsProvider.init();
101         this.cmdNodeConnectorNotification.init();
102         this.cmdTopologyNotification.init();
103         this.bulkCmdProvider.init();
104         this.groupCmdProvider.init();
105     }
106
107     @Override
108     @PreDestroy
109     @SuppressWarnings("checkstyle:IllegalCatch")
110     public void close() {
111         try {
112             provider.close();
113         } catch (Exception e) {
114             // TODO Auto-generated catch block
115             LOG.error("Stopping bundle OpenflowpluginTestActivator failed.", e);
116         }
117     }
118 }