d2841baefb1ae5c471980414b1300f060c9252e5
[transportpce.git] / tests / honeynode / 2.2.1 / restconf / src / main / java / io / fd / honeycomb / northbound / restconf / RestconfModule.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.northbound.restconf;
18
19 import com.google.inject.Singleton;
20 import com.google.inject.name.Names;
21 import io.fd.honeycomb.northbound.NorthboundAbstractModule;
22 import io.fd.honeycomb.northbound.restconf.JettyServerStarter.RestconfJettyServer;
23 import org.eclipse.jetty.server.Server;
24 import org.eclipse.jetty.server.ServerConnector;
25 import org.opendaylight.netconf.sal.rest.api.RestConnector;
26 import org.opendaylight.netconf.sal.rest.impl.RestconfApplication;
27 import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
28 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
29 import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
30 import org.opendaylight.netconf.sal.restconf.impl.StatisticsRestconfServiceWrapper;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public class RestconfModule extends NorthboundAbstractModule<RestconfConfiguration> {
35
36     private static final Logger LOG = LoggerFactory.getLogger(RestconfModule.class);
37
38     public static final String HONEYCOMB_RESTCONF = "honeycomb-restconf";
39     public static final String RESTCONF_HTTP = "restconf-http";
40     public static final String RESTCONF_HTTPS = "restconf-https";
41
42     public RestconfModule() {
43         super(new RestconfConfigurationModule(), RestconfConfiguration.class);
44     }
45
46     @Override
47     protected void configure() {
48         if (!getConfiguration().isRestconfEnabled()) {
49             LOG.info("Restconf is disabled, skipping configuration");
50             return;
51         }
52
53         LOG.info("Starting RESTCONF Northbound");
54         install(new RestconfConfigurationModule());
55         bind(ControllerContext.class).toProvider(ControllerContextProvider.class).in(Singleton.class);
56         bind(BrokerFacade.class).toProvider(BrokerFacadeProvider.class).in(Singleton.class);
57         bind(RestconfImpl.class).toProvider(RestconfServiceProvider.class).in(Singleton.class);
58         bind(StatisticsRestconfServiceWrapper.class)
59                 .toProvider(StatisticsRestconfServiceWrapperProvider.class).in(Singleton.class);
60         bind(RestconfApplication.class).toProvider(RestconfApplicationProvider.class).in(Singleton.class);
61         bind(Server.class).toProvider(JettyServerProvider.class).in(Singleton.class);
62         bind(ServerConnector.class).annotatedWith(Names.named(RESTCONF_HTTP))
63                 .toProvider(HttpConnectorProvider.class)
64                 .in(Singleton.class);
65         bind(ServerConnector.class).annotatedWith(Names.named(RESTCONF_HTTPS))
66                 .toProvider(HttpsConnectorProvider.class)
67                 .in(Singleton.class);
68         bind(RestConnector.class).toProvider(RestconfProvider.class).in(Singleton.class);
69         bind(RestconfJettyServer.class).toProvider(JettyServerStarter.class).asEagerSingleton();
70     }
71 }