2 * Copyright (c) 2016 Cisco Systems, Inc. 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
8 package org.opendaylight.netconf.topology.singleton.impl.utils;
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.netconf.api.DocumentedException;
12 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceId;
13 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
14 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
23 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
24 import org.opendaylight.yangtools.yang.common.Decimal64;
25 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
26 import org.opendaylight.yangtools.yang.common.ErrorTag;
27 import org.opendaylight.yangtools.yang.common.ErrorType;
29 public final class NetconfTopologyUtils {
30 public static final long DEFAULT_REQUEST_TIMEOUT_MILLIS = 60000L;
31 public static final int DEFAULT_KEEPALIVE_DELAY = 0;
32 public static final boolean DEFAULT_RECONNECT_ON_CHANGED_SCHEMA = false;
33 public static final boolean DEFAULT_IS_TCP_ONLY = false;
34 public static final int DEFAULT_CONCURRENT_RPC_LIMIT = 0;
35 public static final int DEFAULT_MAX_CONNECTION_ATTEMPTS = 0;
36 public static final int DEFAULT_BETWEEN_ATTEMPTS_TIMEOUT_MILLIS = 2000;
37 public static final long DEFAULT_CONNECTION_TIMEOUT_MILLIS = 20000L;
38 public static final Decimal64 DEFAULT_SLEEP_FACTOR = Decimal64.valueOf("1.5");
40 private NetconfTopologyUtils() {
44 public static String createActorPath(final String masterMember, final String name) {
45 return masterMember + "/user/" + name;
48 public static String createMasterActorName(final String name, final String masterAddress) {
49 return masterAddress.replace("//", "") + "_" + name;
52 public static @NonNull NodeId getNodeId(final PathArgument pathArgument) {
53 if (pathArgument instanceof IdentifiableItem<?, ?> identifiableItem
54 && identifiableItem.getKey() instanceof NodeKey nodeKey) {
55 return nodeKey.getNodeId();
57 throw new IllegalStateException("Unable to create NodeId from: " + pathArgument);
60 public static @NonNull KeyedInstanceIdentifier<Topology, TopologyKey> createTopologyListPath(
61 final String topologyId) {
62 return InstanceIdentifier.create(NetworkTopology.class)
63 .child(Topology.class, new TopologyKey(new TopologyId(topologyId)));
66 public static @NonNull KeyedInstanceIdentifier<Node, NodeKey> createTopologyNodeListPath(final NodeKey key,
67 final String topologyId) {
68 return createTopologyListPath(topologyId)
69 .child(Node.class, new NodeKey(new NodeId(key.getNodeId().getValue())));
72 public static @NonNull InstanceIdentifier<Node> createTopologyNodePath(final String topologyId) {
73 return createTopologyListPath(topologyId).child(Node.class);
76 public static @NonNull DocumentedException createMasterIsDownException(final RemoteDeviceId id,
77 final Exception cause) {
78 return new DocumentedException(id + ":Master is down. Please try again.", cause,
79 ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.WARNING);