Merge "Use static Procedure callback for ApplyJournalEntries"
[controller.git] / opendaylight / netconf / netconf-testtool / src / main / java / org / opendaylight / controller / netconf / test / tool / DummyMonitoringService.java
1 /*
2  * Copyright (c) 2015 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
9 package org.opendaylight.controller.netconf.test.tool;
10
11 import com.google.common.base.Function;
12 import com.google.common.base.Optional;
13 import com.google.common.collect.ArrayListMultimap;
14 import com.google.common.collect.Collections2;
15 import com.google.common.collect.Lists;
16 import java.util.Collections;
17 import java.util.Set;
18 import javax.annotation.Nullable;
19 import org.opendaylight.controller.netconf.api.Capability;
20 import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession;
21 import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.Yang;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.CapabilitiesBuilder;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Schemas;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SchemasBuilder;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Sessions;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SessionsBuilder;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema.Location;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema.Location.Enumeration;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.SchemaBuilder;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.SchemaKey;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.sessions.Session;
36
37 public class DummyMonitoringService implements NetconfMonitoringService {
38
39     private static final Sessions EMPTY_SESSIONS = new SessionsBuilder().setSession(Collections.<Session>emptyList()).build();
40     private static final Function<Capability, Uri> CAPABILITY_URI_FUNCTION = new Function<Capability, Uri>() {
41         @Nullable
42         @Override
43         public Uri apply(Capability capability) {
44             return new Uri(capability.getCapabilityUri());
45         }
46     };
47
48     private static final Function<Capability, Schema> CAPABILITY_SCHEMA_FUNCTION = new Function<Capability, Schema>() {
49         @Nullable
50         @Override
51         public Schema apply(@Nullable Capability capability) {
52             return new SchemaBuilder()
53                     .setIdentifier(capability.getModuleName().get())
54                     .setNamespace(new Uri(capability.getModuleNamespace().get()))
55                     .setFormat(Yang.class)
56                     .setVersion(capability.getRevision().get())
57                     .setLocation(Collections.singletonList(new Location(Enumeration.NETCONF)))
58                     .setKey(new SchemaKey(Yang.class, capability.getModuleName().get(), capability.getRevision().get())).build();
59         }
60     };
61
62     private final Capabilities capabilities;
63     private final ArrayListMultimap<String, Capability> capabilityMultiMap;
64     private final Schemas schemas;
65
66     public DummyMonitoringService(Set<Capability> capabilities) {
67
68         this.capabilities = new CapabilitiesBuilder().setCapability(
69                 Lists.newArrayList(Collections2.transform(capabilities, CAPABILITY_URI_FUNCTION))).build();
70
71         this.capabilityMultiMap = ArrayListMultimap.create();
72         for (Capability cap : capabilities) {
73             capabilityMultiMap.put(cap.getModuleName().get(), cap);
74         }
75
76         this.schemas = new SchemasBuilder().setSchema(Lists.newArrayList(Collections2.transform(capabilities, CAPABILITY_SCHEMA_FUNCTION))).build();
77     }
78
79     @Override
80     public Sessions getSessions() {
81         return EMPTY_SESSIONS;
82     }
83
84     @Override
85     public Schemas getSchemas() {
86         return schemas;
87     }
88
89     @Override
90     public String getSchemaForCapability(String moduleName, Optional<String> revision) {
91
92         for (Capability capability : capabilityMultiMap.get(moduleName)) {
93             if (capability.getRevision().get().equals(revision.get())) {
94                 return capability.getCapabilitySchema().get();
95             }
96         }
97         throw new IllegalArgumentException("Module with name: " + moduleName + " and revision: " + revision + " does not exist");
98     }
99
100     @Override
101     public Capabilities getCapabilities() {
102         return capabilities;
103     }
104
105     @Override
106     public AutoCloseable registerListener(MonitoringListener listener) {
107         return null;
108     }
109
110     @Override
111     public void onCapabilitiesAdded(Set<Capability> addedCaps) {
112
113     }
114
115     @Override
116     public void onCapabilitiesRemoved(Set<Capability> removedCaps) {
117
118     }
119
120     @Override
121     public void onSessionUp(NetconfManagementSession session) {
122
123     }
124
125     @Override
126     public void onSessionDown(NetconfManagementSession session) {
127
128     }
129 }