summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main
diff options
context:
space:
mode:
authorDylanB95EST <dylan.byrne@est.tech>2022-04-20 10:35:11 +0100
committerDylanB95EST <dylan.byrne@est.tech>2022-04-29 11:59:29 +0100
commit6369af0f6cb53619daa253d5da0f360f2bf67fc3 (patch)
treed6c5fb0c990a170d5717f09f77034e08c3068635 /cps-ncmp-service/src/main
parentd07a5e3cfd74357c626d099dc5d5812ecd8e33ea (diff)
Watchdog-process that changes CM Handles state
Add a fixed delay scheduler to switch cm-handles found in an ADVISED state to a READY state Scheduler currently runs every 30 seconds Will only update a single cm-handle at a time Queries CM-Handle with Advised States Only using CPS Path. Will choose cm handle at random Issue-ID: CPS-875 Change-Id: Ie1b49c89a0350d20e14748a65f9c1d260d8502d2 Signed-off-by: DylanB95EST <dylan.byrne@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main')
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java2
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java4
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetriever.java2
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java3
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java56
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java87
6 files changed, 150 insertions, 4 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
index e624953f54..c0f73d92d6 100755
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
@@ -184,7 +184,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
CpsValidator.validateNameCharacters(cmHandleId);
final NcmpServiceCmHandle ncmpServiceCmHandle = new NcmpServiceCmHandle();
final YangModelCmHandle yangModelCmHandle =
- yangModelCmHandleRetriever.getDmiServiceNamesAndProperties(cmHandleId);
+ yangModelCmHandleRetriever.getYangModelCmHandle(cmHandleId);
final List<YangModelCmHandle.Property> dmiProperties = yangModelCmHandle.getDmiProperties();
final List<YangModelCmHandle.Property> publicProperties = yangModelCmHandle.getPublicProperties();
ncmpServiceCmHandle.setCmHandleId(yangModelCmHandle.getId());
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java
index ad85edde7b..f145379406 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java
@@ -72,7 +72,7 @@ public class DmiDataOperations extends DmiOperations {
final String topicParamInQuery) {
CpsValidator.validateNameCharacters(cmHandleId);
final YangModelCmHandle yangModelCmHandle =
- yangModelCmHandleRetriever.getDmiServiceNamesAndProperties(cmHandleId);
+ yangModelCmHandleRetriever.getYangModelCmHandle(cmHandleId);
final DmiRequestBody dmiRequestBody = DmiRequestBody.builder()
.operation(READ)
.requestId(requestId)
@@ -104,7 +104,7 @@ public class DmiDataOperations extends DmiOperations {
final String dataType) {
CpsValidator.validateNameCharacters(cmHandleId);
final YangModelCmHandle yangModelCmHandle =
- yangModelCmHandleRetriever.getDmiServiceNamesAndProperties(cmHandleId);
+ yangModelCmHandleRetriever.getYangModelCmHandle(cmHandleId);
final DmiRequestBody dmiRequestBody = DmiRequestBody.builder()
.operation(operation)
.data(requestData)
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetriever.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetriever.java
index 0efe8d5b62..b1ac91d7a3 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetriever.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetriever.java
@@ -48,7 +48,7 @@ public class YangModelCmHandleRetriever {
* @param cmHandleId the id of the cm handle
* @return yang model cm handle
*/
- public YangModelCmHandle getDmiServiceNamesAndProperties(final String cmHandleId) {
+ public YangModelCmHandle getYangModelCmHandle(final String cmHandleId) {
CpsValidator.validateNameCharacters(cmHandleId);
final DataNode cmHandleDataNode = getCmHandleDataNode(cmHandleId);
final NcmpServiceCmHandle ncmpServiceCmHandle = new NcmpServiceCmHandle();
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java
index fd3528187e..289d782cde 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java
@@ -55,6 +55,9 @@ public class YangModelCmHandle {
@JsonProperty("dmi-data-service-name")
private String dmiDataServiceName;
+ @JsonProperty("state")
+ private String cmHandleState;
+
@JsonProperty("dmi-model-service-name")
private String dmiModelServiceName;
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java
new file mode 100644
index 0000000000..69413171d6
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java
@@ -0,0 +1,56 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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.api.inventory.sync;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@EnableScheduling
+@RequiredArgsConstructor
+@Component
+public class ModuleSyncWatchdog {
+
+ private final SyncUtils syncUtils;
+
+ /**
+ * Execute Cm Handle poll which changes the cm handle state from 'ADVISED' to 'READY'.
+ */
+ @Scheduled(fixedDelay = 30000)
+ public void executeAdvisedCmHandlePoll() {
+ YangModelCmHandle newAdvisedCmHandle = syncUtils.getAnAdvisedCmHandle();
+ while (newAdvisedCmHandle != null) {
+ // ToDo When Cm-Handle in the 'ADVISED' state is Retrieved, Set CM-Handle state to 'LOCKED'
+ // and give lock reason
+ // ToDo if lock fails, move to next cm handle.
+ // ToDo Update last update time with a timestamp everytime Cm-handle state is changed
+ syncUtils.updateCmHandleState(newAdvisedCmHandle, "READY");
+ log.info("{} is now in READY state", newAdvisedCmHandle.getId());
+ newAdvisedCmHandle = syncUtils.getAnAdvisedCmHandle();
+ }
+ log.debug("No Cm-Handles currently found in an ADVISED state");
+ }
+
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java
new file mode 100644
index 0000000000..924546433e
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java
@@ -0,0 +1,87 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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.api.inventory.sync;
+
+import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NCMP_DATASPACE_NAME;
+import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NCMP_DMI_REGISTRY_ANCHOR;
+import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NCMP_DMI_REGISTRY_PARENT;
+
+import java.security.SecureRandom;
+import java.time.OffsetDateTime;
+import java.util.List;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.api.CpsDataService;
+import org.onap.cps.ncmp.api.impl.operations.YangModelCmHandleRetriever;
+import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
+import org.onap.cps.spi.CpsDataPersistenceService;
+import org.onap.cps.spi.FetchDescendantsOption;
+import org.onap.cps.spi.model.DataNode;
+import org.onap.cps.utils.JsonObjectMapper;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+@RequiredArgsConstructor
+public class SyncUtils {
+
+ private static final SecureRandom secureRandom = new SecureRandom();
+ private final CpsDataService cpsDataService;
+
+ private final CpsDataPersistenceService cpsDataPersistenceService;
+
+ private final JsonObjectMapper jsonObjectMapper;
+
+ private final YangModelCmHandleRetriever yangModelCmHandleRetriever;
+
+ /**
+ * Query data nodes for cm handles with an "ADVISED" cm handle state, and select a random entry for processing.
+ *
+ * @return a random yang model cm handle with an ADVISED state, return null if not found
+ */
+ public YangModelCmHandle getAnAdvisedCmHandle() {
+ final List<DataNode> advisedCmHandles = cpsDataPersistenceService.queryDataNodes("NCMP-Admin",
+ "ncmp-dmi-registry", "//cm-handles[@state=\"ADVISED\"]",
+ FetchDescendantsOption.OMIT_DESCENDANTS);
+ if (advisedCmHandles.isEmpty()) {
+ return null;
+ }
+ final int randomElementIndex = secureRandom.nextInt(advisedCmHandles.size());
+ final String cmHandleId = advisedCmHandles.get(randomElementIndex).getLeaves()
+ .get("id").toString();
+ return yangModelCmHandleRetriever.getYangModelCmHandle(cmHandleId);
+ }
+
+ /**
+ * Update the Cm Handle state to "READY".
+ *
+ * @param yangModelCmHandle yang model cm handle
+ * @param state cm handle state
+ */
+ public void updateCmHandleState(final YangModelCmHandle yangModelCmHandle, final String state) {
+ yangModelCmHandle.setCmHandleState(state);
+ final String cmHandleJsonData = String.format("{\"cm-handles\":[%s]}",
+ jsonObjectMapper.asJsonString(yangModelCmHandle));
+ cpsDataService.updateNodeLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT,
+ cmHandleJsonData, OffsetDateTime.now());
+ }
+
+}