Honeynode test tool
[transportpce.git] / tests / honeynode / 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.ServerInit;
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.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 public class RestconfModule extends NorthboundAbstractModule<RestconfConfiguration> {
30
31     private static final Logger LOG = LoggerFactory.getLogger(RestconfModule.class);
32
33     public static final String RESTCONF_HTTP = "restconf-http";
34     public static final String RESTCONF_HTTPS = "restconf-https";
35
36     public RestconfModule() {
37         super(new RestconfConfigurationModule(), RestconfConfiguration.class);
38     }
39
40     @Override
41     protected void configure() {
42         if (!getConfiguration().isRestconfEnabled()) {
43             LOG.info("Restconf is disabled, skipping configuration");
44             return;
45         }
46
47         LOG.info("Starting RESTCONF Northbound");
48         install(new RestconfConfigurationModule());
49         bind(Server.class).toProvider(JettyServerProvider.class).in(Singleton.class);
50         bind(ServerConnector.class).annotatedWith(Names.named(RESTCONF_HTTP))
51                 .toProvider(HttpConnectorProvider.class)
52                 .in(Singleton.class);
53         bind(ServerConnector.class).annotatedWith(Names.named(RESTCONF_HTTPS))
54                 .toProvider(HttpsConnectorProvider.class)
55                 .in(Singleton.class);
56         bind(RestConnector.class).toProvider(RestconfProvider.class).in(Singleton.class);
57         bind(ServerInit.class).toProvider(JettyServerStarter.class).asEagerSingleton();
58     }
59 }