summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java20
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java15
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java39
3 files changed, 51 insertions, 23 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java
index f0d1c9b4b7..d47da6c0cf 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java
@@ -47,7 +47,9 @@ public class InventoryPersistence {
private static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry";
- private static final String XPATH_TO_CM_HANDLE = "/dmi-registry/cm-handles[@id='" + "%s" + "']";
+ private String xpathCmHandle = "/dmi-registry/cm-handles[@id='" + "%s" + "']";
+
+ private static final String ANCESTOR_CM_HANDLES = "\"]/ancestor::cm-handles";
private final JsonObjectMapper jsonObjectMapper;
@@ -57,8 +59,6 @@ public class InventoryPersistence {
private final CpsDataPersistenceService cpsDataPersistenceService;
- private static final CompositeStateBuilder compositeStateBuilder = new CompositeStateBuilder();
-
/**
* Get the Cm Handle Composite State from the data node.
*
@@ -67,9 +67,9 @@ public class InventoryPersistence {
*/
public CompositeState getCmHandleState(final String cmHandleId) {
final DataNode stateAsDataNode = cpsDataService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- String.format(XPATH_TO_CM_HANDLE, cmHandleId) + "/state",
+ String.format(xpathCmHandle, cmHandleId) + "/state",
FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
- return compositeStateBuilder.fromDataNode(stateAsDataNode).build();
+ return new CompositeStateBuilder().fromDataNode(stateAsDataNode).build();
}
/**
@@ -82,7 +82,7 @@ public class InventoryPersistence {
final String cmHandleJsonData = String.format("{\"state\":%s}",
jsonObjectMapper.asJsonString(compositeState));
cpsDataService.replaceNodeTree(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- String.format(XPATH_TO_CM_HANDLE, cmHandleId),
+ String.format(xpathCmHandle, cmHandleId),
cmHandleJsonData, OffsetDateTime.now());
}
@@ -95,7 +95,7 @@ public class InventoryPersistence {
public List<DataNode> getCmHandlesByState(final CmHandleState cmHandleState) {
return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME,
NCMP_DMI_REGISTRY_ANCHOR, "//state[@cm-handle-state=\""
- + cmHandleState + "\"]/ancestor::cm-handles",
+ + cmHandleState + ANCESTOR_CM_HANDLES,
FetchDescendantsOption.OMIT_DESCENDANTS);
}
@@ -121,7 +121,7 @@ public class InventoryPersistence {
public List<DataNode> getCmHandlesByIdAndState(final String cmHandleId, final CmHandleState cmHandleState) {
return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME,
NCMP_DMI_REGISTRY_ANCHOR, "//cm-handles[@id='" + cmHandleId + "']/state[@cm-handle-state=\""
- + cmHandleState + "\"]/ancestor::cm-handles",
+ + cmHandleState + ANCESTOR_CM_HANDLES,
FetchDescendantsOption.OMIT_DESCENDANTS);
}
@@ -133,7 +133,7 @@ public class InventoryPersistence {
public List<DataNode> getCmHandlesByOperationalSyncState(final DataStoreSyncState dataStoreSyncState) {
return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME,
NCMP_DMI_REGISTRY_ANCHOR, "//state/datastores"
- + "/operational[@sync-state=\"" + dataStoreSyncState + "\"]/ancestor::cm-handles",
+ + "/operational[@sync-state=\"" + dataStoreSyncState + ANCESTOR_CM_HANDLES,
FetchDescendantsOption.OMIT_DESCENDANTS);
}
@@ -160,7 +160,7 @@ public class InventoryPersistence {
private DataNode getCmHandleDataNode(final String cmHandle) {
return cpsDataService.getDataNode(NCMP_DATASPACE_NAME,
NCMP_DMI_REGISTRY_ANCHOR,
- String.format(XPATH_TO_CM_HANDLE, cmHandle),
+ String.format(xpathCmHandle, cmHandle),
FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java
index 153921a9f7..adfa33ad81 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java
@@ -21,6 +21,7 @@
package org.onap.cps.ncmp.api.inventory.sync;
import java.time.OffsetDateTime;
+import java.util.function.Consumer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsDataService;
@@ -60,15 +61,21 @@ public class DataSyncWatchdog {
} else {
cpsDataService.saveData("NFP-Operational", cmHandleId,
resourceData, OffsetDateTime.now());
+ setSyncStateToSynchronized().accept(compositeState);
+ inventoryPersistence.saveCmHandleState(cmHandleId, compositeState);
}
+ unSynchronizedReadyCmHandle = syncUtils.getAnUnSynchronizedReadyCmHandle();
+ }
+ log.debug("No Cm-Handles currently found in an READY State and Operational Sync State is UNSYNCHRONIZED");
+ }
+
+ private Consumer<CompositeState> setSyncStateToSynchronized() {
+ return compositeState -> {
compositeState.setLastUpdateTimeNow();
compositeState.getDataStores()
.setOperationalDataStore(CompositeState.Operational.builder()
.dataStoreSyncState(DataStoreSyncState.SYNCHRONIZED)
.lastSyncTime(CompositeState.nowInSyncTimeFormat()).build());
- inventoryPersistence.saveCmHandleState(cmHandleId, compositeState);
- unSynchronizedReadyCmHandle = syncUtils.getAnUnSynchronizedReadyCmHandle();
- }
- log.debug("No Cm-Handles currently found in an READY State and Operational Sync State is UNSYNCHRONIZED");
+ };
}
}
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
index 402f9f6b4f..ac53d881c1 100644
--- 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
@@ -22,11 +22,13 @@
package org.onap.cps.ncmp.api.inventory.sync;
import java.util.List;
+import java.util.function.Consumer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
import org.onap.cps.ncmp.api.inventory.CmHandleState;
import org.onap.cps.ncmp.api.inventory.CompositeState;
+import org.onap.cps.ncmp.api.inventory.DataStoreSyncState;
import org.onap.cps.ncmp.api.inventory.InventoryPersistence;
import org.onap.cps.ncmp.api.inventory.LockReasonCategory;
import org.springframework.scheduling.annotation.Scheduled;
@@ -54,17 +56,14 @@ public class ModuleSyncWatchdog {
final CompositeState compositeState = inventoryPersistence.getCmHandleState(cmHandleId);
try {
moduleSyncService.syncAndCreateSchemaSetAndAnchor(advisedCmHandle);
- compositeState.setCmHandleState(CmHandleState.READY);
+ setCompositeStateToReadyWithInitialDataStoreSyncState().accept(compositeState);
} catch (final Exception e) {
- compositeState.setCmHandleState(CmHandleState.LOCKED);
+ setCompositeStateToLocked().accept(compositeState);
syncUtils.updateLockReasonDetailsAndAttempts(compositeState,
- LockReasonCategory.LOCKED_MISBEHAVING,
- e.getMessage());
+ LockReasonCategory.LOCKED_MISBEHAVING, e.getMessage());
}
- compositeState.setLastUpdateTimeNow();
inventoryPersistence.saveCmHandleState(cmHandleId, compositeState);
- log.info("{} is now in {} state", cmHandleId,
- advisedCmHandle.getCompositeState().getCmHandleState());
+ log.debug("{} is now in {} state", cmHandleId, compositeState.getCmHandleState().name());
advisedCmHandle = syncUtils.getAnAdvisedCmHandle();
}
log.debug("No Cm-Handles currently found in an ADVISED state");
@@ -87,11 +86,33 @@ public class ModuleSyncWatchdog {
}
}
+ private Consumer<CompositeState> setCompositeStateToLocked() {
+ return compositeState -> {
+ compositeState.setCmHandleState(CmHandleState.LOCKED);
+ compositeState.setLastUpdateTimeNow();
+ };
+ }
+
+ private Consumer<CompositeState> setCompositeStateToReadyWithInitialDataStoreSyncState() {
+ return compositeState -> {
+ compositeState.setCmHandleState(CmHandleState.READY);
+ final CompositeState.Operational operational = CompositeState.Operational.builder()
+ .dataStoreSyncState(DataStoreSyncState.UNSYNCHRONIZED)
+ .lastSyncTime(CompositeState.nowInSyncTimeFormat())
+ .build();
+ final CompositeState.DataStores dataStores = CompositeState.DataStores.builder()
+ .operationalDataStore(operational)
+ .build();
+ compositeState.setDataStores(dataStores);
+ };
+ }
+
private void setCompositeStateToAdvisedAndRetainOldLockReasonDetails(final CompositeState compositeState) {
compositeState.setCmHandleState(CmHandleState.ADVISED);
compositeState.setLastUpdateTimeNow();
final String oldLockReasonDetails = compositeState.getLockReason().getDetails();
- compositeState.setLockReason(CompositeState.LockReason.builder()
- .details(oldLockReasonDetails).build());
+ final CompositeState.LockReason lockReason = CompositeState.LockReason.builder()
+ .details(oldLockReasonDetails).build();
+ compositeState.setLockReason(lockReason);
}
}