}
}
- public static class IllegalValueException extends ConfigurationException {
- private static final long serialVersionUID = -1172346869408302687L;
-
- private final String key;
- private final String value;
-
- IllegalValueException(final String key, final String value) {
- super("Key has an illegal value. Key: " + key + ", Value: " + value);
- this.key = key;
- this.value = value;
- }
-
- IllegalValueException(final String key, final String value, final Exception cause) {
- super("Key has an illegal value. Key: " + key + ", Value: " + value, cause);
- this.key = key;
- this.value = value;
- }
-
- public String getKey() {
- return key;
- }
-
- public String getValue() {
- return value;
- }
- }
-
private Properties properties;
public Configuration() {
public Configuration(final String path) throws ConfigurationException {
try {
- this.properties = readFromPath(path);
+ properties = readFromPath(path);
} catch (IOException ioe) {
throw new ReadException(path, ioe);
}
}
return result;
}
-
- public int getAsPort(final String key) {
- String keyValue = get(key);
- try {
- int newPort = Integer.parseInt(keyValue);
- if (newPort < 0 || newPort > 65535) {
- throw new IllegalValueException(key, keyValue);
- }
- return newPort;
- } catch (NumberFormatException e) {
- throw new IllegalValueException(key, keyValue, e);
- }
- }
}
*/
package org.opendaylight.netconf.callhome.mount;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.ListenableFuture;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParamsBuilder;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint16;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataTreeChangeListener<AllowedDevices> {
+public final class IetfZeroTouchCallHomeServerProvider
+ implements AutoCloseable, DataTreeChangeListener<AllowedDevices> {
private static final String APPNAME = "CallHomeServer";
static final InstanceIdentifier<AllowedDevices> ALL_DEVICES = InstanceIdentifier.create(NetconfCallhomeServer.class)
.child(AllowedDevices.class);
private final DataBroker dataBroker;
private final CallHomeMountDispatcher mountDispacher;
private final CallHomeAuthProviderImpl authProvider;
+ private final CallhomeStatusReporter statusReporter;
+ private final int port;
- protected NetconfCallHomeServer server;
-
+ private NetconfCallHomeServer server;
private ListenerRegistration<IetfZeroTouchCallHomeServerProvider> listenerReg = null;
- private static final String CALL_HOME_PORT_KEY = "DefaultCallHomePort";
- private int port = 0; // 0 = use default in NetconfCallHomeBuilder
- private final CallhomeStatusReporter statusReporter;
-
public IetfZeroTouchCallHomeServerProvider(final DataBroker dataBroker,
final CallHomeMountDispatcher mountDispacher) {
- this.dataBroker = dataBroker;
- this.mountDispacher = mountDispacher;
+ this(dataBroker, mountDispacher, Uint16.valueOf(4334));
+ }
+
+ public IetfZeroTouchCallHomeServerProvider(final DataBroker dataBroker,
+ final CallHomeMountDispatcher mountDispacher, final Uint16 port) {
+ this.dataBroker = requireNonNull(dataBroker);
+ this.mountDispacher = requireNonNull(mountDispacher);
+
+ LOG.info("Setting port for call home server to {}", port);
+ this.port = port.toJava();
+
// FIXME: these should be separate components
authProvider = new CallHomeAuthProviderImpl(dataBroker);
statusReporter = new CallhomeStatusReporter(dataBroker);
- }
- public void init() {
+ LOG.info("Initializing provider for {}", APPNAME);
+
// Register itself as a listener to changes in Devices subtree
try {
- LOG.info("Initializing provider for {}", APPNAME);
initializeServer();
- listenerReg = dataBroker.registerDataTreeChangeListener(
- DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, ALL_DEVICES), this);
- LOG.info("Initialization complete for {}", APPNAME);
} catch (IOException | Configuration.ConfigurationException e) {
LOG.error("Unable to successfully initialize", e);
+ return;
}
- }
- public void setPort(final String portStr) {
- try {
- Configuration configuration = new Configuration();
- configuration.set(CALL_HOME_PORT_KEY, portStr);
- port = configuration.getAsPort(CALL_HOME_PORT_KEY);
- LOG.info("Setting port for call home server to {}", portStr);
- } catch (Configuration.ConfigurationException e) {
- LOG.error("Problem trying to set port for call home server {}", portStr, e);
- }
+ listenerReg = dataBroker.registerDataTreeChangeListener(
+ DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, ALL_DEVICES), this);
+ LOG.info("Initialization complete for {}", APPNAME);
}
private void initializeServer() throws IOException {