summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java')
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java b/src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java
new file mode 100644
index 00000000..4e4e7217
--- /dev/null
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java
@@ -0,0 +1,75 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.dmi.service.operation;
+
+import org.jetbrains.annotations.NotNull;
+import org.onap.cps.ncmp.dmi.config.DmiConfiguration.SdncProperties;
+import org.onap.cps.ncmp.dmi.service.client.SdncRestconfClient;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SdncOperations {
+
+ private static final String TOPOLOGY_URL_TEMPLATE = "/rests/data/network-topology:network-topology"
+ + "/topology={topologyId}";
+ private static final String MOUNT_URL_TEMPLATE = "/node={nodeId}/yang-ext:mount";
+ private static final String GET_SCHEMA_URL = "/ietf-netconf-monitoring:netconf-state/schemas";
+
+ private SdncProperties sdncProperties;
+ private SdncRestconfClient sdncRestconfClient;
+ private final String topologyUrl;
+ private final String topologyMountUrlTemplate;
+
+ /**
+ * Constructor for {@code SdncOperations}. This method also manipulates
+ * url properties.
+ *
+ * @param sdncProperties {@code SdncProperties}
+ * @param sdncRestconfClient {@code SdncRestconfClient}
+ */
+
+ public SdncOperations(final SdncProperties sdncProperties, final SdncRestconfClient sdncRestconfClient) {
+ this.sdncProperties = sdncProperties;
+ this.sdncRestconfClient = sdncRestconfClient;
+ topologyUrl = TOPOLOGY_URL_TEMPLATE.replace("{topologyId}", this.sdncProperties.getTopologyId());
+ topologyMountUrlTemplate = topologyUrl + MOUNT_URL_TEMPLATE;
+ }
+
+ /**
+ * This method fetches list of modules usind sdnc client.
+ *
+ * @param nodeId node id for node
+ * @return returns {@code ResponseEntity} which contains list of modules
+ */
+ public ResponseEntity<String> getModulesFromNode(final String nodeId) {
+ final String urlWithNodeId = prepareGetSchemaUrl(nodeId);
+ return sdncRestconfClient.getOperation(urlWithNodeId);
+ }
+
+ @NotNull
+ private String prepareGetSchemaUrl(final String nodeId) {
+ final String topologyMountUrl = topologyMountUrlTemplate;
+ final String topologyMountUrlWithNodeId = topologyMountUrl.replace("{nodeId}", nodeId);
+ final String resourceUrl = topologyMountUrlWithNodeId.concat(GET_SCHEMA_URL);
+ return resourceUrl;
+ }
+}