Bump upstreams
[netconf.git] / apps / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / impl / utils / NetconfTopologyUtils.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.topology.singleton.impl.utils;
9
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.netconf.api.DocumentedException;
12 import org.opendaylight.netconf.client.mdsal.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.DataObjectStep;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.opendaylight.yangtools.yang.binding.KeyStep;
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;
28
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_MIN_BACKOFF = 2000;
37     public static final long DEFAULT_CONNECTION_TIMEOUT_MILLIS = 20000L;
38     public static final Decimal64 DEFAULT_BACKOFF_MULTIPLIER = Decimal64.valueOf("1.5");
39
40     private NetconfTopologyUtils() {
41         // Hidden on purpose
42     }
43
44     public static String createActorPath(final String masterMember, final String name) {
45         return  masterMember + "/user/" + name;
46     }
47
48     public static String createMasterActorName(final String name, final String masterAddress) {
49         return masterAddress.replace("//", "") + "_" + name;
50     }
51
52     public static @NonNull NodeId getNodeId(final DataObjectStep<?> pathArgument) {
53         if (pathArgument instanceof KeyStep identifiableItem && identifiableItem.key() instanceof NodeKey nodeKey) {
54             return nodeKey.getNodeId();
55         }
56         throw new IllegalStateException("Unable to create NodeId from: " + pathArgument);
57     }
58
59     public static @NonNull KeyedInstanceIdentifier<Topology, TopologyKey> createTopologyListPath(
60             final String topologyId) {
61         return InstanceIdentifier.create(NetworkTopology.class)
62             .child(Topology.class, new TopologyKey(new TopologyId(topologyId)));
63     }
64
65     public static @NonNull KeyedInstanceIdentifier<Node, NodeKey> createTopologyNodeListPath(final NodeKey key,
66             final String topologyId) {
67         return createTopologyListPath(topologyId)
68                 .child(Node.class, new NodeKey(new NodeId(key.getNodeId().getValue())));
69     }
70
71     public static @NonNull InstanceIdentifier<Node> createTopologyNodePath(final String topologyId) {
72         return createTopologyListPath(topologyId).child(Node.class);
73     }
74
75     public static @NonNull DocumentedException createMasterIsDownException(final RemoteDeviceId id,
76             final Exception cause) {
77         return new DocumentedException(id + ":Master is down. Please try again.", cause,
78                 ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.WARNING);
79     }
80 }