2 * Copyright (c) 2016 Brocade Communication Systems and others. All rights reserved.
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
9 package org.opendaylight.netconf.callhome.mount;
11 import java.io.IOException;
13 import java.net.InetSocketAddress;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.netconf.callhome.protocol.CallHomeAuthorizationProvider;
16 import org.opendaylight.netconf.callhome.protocol.NetconfCallHomeServer;
17 import org.opendaylight.netconf.callhome.protocol.NetconfCallHomeServerBuilder;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable {
22 private static final Logger LOG = LoggerFactory.getLogger(IetfZeroTouchCallHomeServerProvider.class);
23 private static final String appName = "CallHomeServer";
25 private final DataBroker dataBroker;
26 private final CallHomeMountDispatcher mountDispacher;
28 protected NetconfCallHomeServer server;
31 private static final String CALL_HOME_PORT_KEY = "DefaultCallHomePort";
33 private final CallHomeAuthProviderImpl authProvider;
36 static String configurationPath = "etc"+File.pathSeparator+"ztp-callhome-config.cfg";
38 private int port = 0; // 0 = use default in NetconfCallHomeBuilder
40 public IetfZeroTouchCallHomeServerProvider(DataBroker dataBroker, CallHomeMountDispatcher mountDispacher) {
41 this.dataBroker = dataBroker;
42 this.mountDispacher = mountDispacher;
43 this.authProvider = new CallHomeAuthProviderImpl(dataBroker);
47 // Register itself as a listener to changes in Devices subtree
49 LOG.info("Initializing provider for {}", appName);
50 loadConfigurableValues(configurationPath);
52 LOG.info("Initialization complete for {}", appName);
53 } catch (IndexOutOfBoundsException | Configuration.ConfigurationException e) {
54 LOG.error("Unable to successfully initialize", e);
58 void loadConfigurableValues(String configurationPath) throws Configuration.ConfigurationException {
60 Configuration configuration = new Configuration(configurationPath);
61 port = configuration.getAsPort(CALL_HOME_PORT_KEY);
62 } catch (Exception e) {
63 LOG.error("Problem trying to load configuration values from {}", configurationPath, e);
67 private CallHomeAuthorizationProvider getCallHomeAuthorization() {
71 private void initializeServer() {
72 LOG.info("Initializing Call Home server instance");
73 CallHomeAuthorizationProvider auth = getCallHomeAuthorization();
74 NetconfCallHomeServerBuilder builder = new NetconfCallHomeServerBuilder(auth, mountDispacher);
77 builder.setBindAddress(new InetSocketAddress(port));
78 server = builder.build();
81 mountDispacher.createTopology();
82 LOG.info("Initialization complete for Call Home server instance");
83 } catch (IOException e) {
84 throw new IllegalStateException("Unable to create Call Home Server.",e);
89 public void close() throws Exception {
95 LOG.info("Successfully closed provider for {}", appName);