summaryrefslogtreecommitdiffstats
path: root/cps-ri
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ri')
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java35
-rw-r--r--cps-ri/src/main/resources/changelog/db/changes/16-insert-cm-handle-state-forward.sql140
-rw-r--r--cps-ri/src/main/resources/changelog/db/changes/16-insert-cm-handle-state-rollback.sql8
3 files changed, 160 insertions, 23 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
index c13422dc4d..ebc851a443 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
@@ -22,8 +22,6 @@
package org.onap.cps.spi.impl;
-import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
-
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
import java.util.ArrayList;
@@ -102,7 +100,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
@Override
public void addMultipleLists(final String dataspaceName, final String anchorName, final String parentNodeXpath,
- final Collection<Collection<DataNode>> newLists) {
+ final Collection<Collection<DataNode>> newLists) {
final Collection<String> failedXpaths = new HashSet<>();
newLists.forEach(newList -> {
try {
@@ -119,7 +117,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
}
private void addNewChildDataNode(final String dataspaceName, final String anchorName,
- final String parentNodeXpath, final DataNode newChild) {
+ final String parentNodeXpath, final DataNode newChild) {
final FragmentEntity parentFragmentEntity = getFragmentByXpath(dataspaceName, anchorName, parentNodeXpath);
final FragmentEntity newChildAsFragmentEntity =
convertToFragmentWithAllDescendants(parentFragmentEntity.getDataspace(),
@@ -134,7 +132,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
}
private void addChildrenDataNodes(final String dataspaceName, final String anchorName, final String parentNodeXpath,
- final Collection<DataNode> newChildren) {
+ final Collection<DataNode> newChildren) {
final FragmentEntity parentFragmentEntity = getFragmentByXpath(dataspaceName, anchorName, parentNodeXpath);
final List<FragmentEntity> fragmentEntities = new ArrayList<>(newChildren.size());
try {
@@ -154,7 +152,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
}
private void retrySavingEachChildIndividually(final String dataspaceName, final String anchorName,
- final String parentNodeXpath, final Collection<DataNode> newChildren) {
+ final String parentNodeXpath,
+ final Collection<DataNode> newChildren) {
final Collection<String> failedXpaths = new HashSet<>();
for (final DataNode newChild : newChildren) {
try {
@@ -191,7 +190,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
* @return a Fragment built from current DataNode
*/
private FragmentEntity convertToFragmentWithAllDescendants(final DataspaceEntity dataspaceEntity,
- final AnchorEntity anchorEntity, final DataNode dataNodeToBeConverted) {
+ final AnchorEntity anchorEntity,
+ final DataNode dataNodeToBeConverted) {
final FragmentEntity parentFragment = toFragmentEntity(dataspaceEntity, anchorEntity, dataNodeToBeConverted);
final Builder<FragmentEntity> childFragmentsImmutableSetBuilder = ImmutableSet.builder();
for (final DataNode childDataNode : dataNodeToBeConverted.getChildDataNodes()) {
@@ -226,7 +226,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
final AnchorEntity anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
if (isRootXpath(xpath)) {
- return fragmentRepository.findFirstRootByDataspaceAndAnchor(dataspaceEntity, anchorEntity);
+ return fragmentRepository.findFirstRootByDataspaceAndAnchor(
+ dataspaceEntity, anchorEntity);
} else {
final String normalizedXpath;
try {
@@ -235,7 +236,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
throw new CpsPathException(e.getMessage());
}
- return fragmentRepository.getByDataspaceAndAnchorAndXpath(dataspaceEntity, anchorEntity, normalizedXpath);
+ return fragmentRepository.getByDataspaceAndAnchorAndXpath(
+ dataspaceEntity, anchorEntity, normalizedXpath);
}
}
@@ -319,10 +321,10 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
private List<DataNode> getChildDataNodes(final FragmentEntity fragmentEntity,
final FetchDescendantsOption fetchDescendantsOption) {
- if (fetchDescendantsOption == INCLUDE_ALL_DESCENDANTS) {
+ if (fetchDescendantsOption.hasNext()) {
return fragmentEntity.getChildFragments().stream()
- .map(childFragmentEntity -> toDataNode(childFragmentEntity, fetchDescendantsOption))
- .collect(Collectors.toUnmodifiableList());
+ .map(childFragmentEntity -> toDataNode(childFragmentEntity, fetchDescendantsOption.next()))
+ .collect(Collectors.toList());
}
return Collections.emptyList();
}
@@ -355,10 +357,11 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
final List<DataNode> dataNodes) {
final Map<DataNode, FragmentEntity> dataNodeFragmentEntityMap = dataNodes.stream()
- .collect(Collectors.toMap(
- dataNode -> dataNode, dataNode -> getFragmentByXpath(dataspaceName, anchorName, dataNode.getXpath())));
+ .collect(Collectors.toMap(
+ dataNode -> dataNode,
+ dataNode -> getFragmentByXpath(dataspaceName, anchorName, dataNode.getXpath())));
dataNodeFragmentEntityMap.forEach(
- (dataNode, fragmentEntity) -> updateFragmentEntityAndDescendantsWithDataNode(fragmentEntity, dataNode));
+ (dataNode, fragmentEntity) -> updateFragmentEntityAndDescendantsWithDataNode(fragmentEntity, dataNode));
try {
fragmentRepository.saveAll(dataNodeFragmentEntityMap.values());
} catch (final StaleStateException staleStateException) {
@@ -367,7 +370,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
}
private void retryUpdateDataNodesIndividually(final String dataspaceName, final String anchorName,
- final Collection<FragmentEntity> fragmentEntities) {
+ final Collection<FragmentEntity> fragmentEntities) {
final Collection<String> failedXpaths = new HashSet<>();
fragmentEntities.forEach(dataNodeFragment -> {
diff --git a/cps-ri/src/main/resources/changelog/db/changes/16-insert-cm-handle-state-forward.sql b/cps-ri/src/main/resources/changelog/db/changes/16-insert-cm-handle-state-forward.sql
index 64b185f3b2..01d441f460 100644
--- a/cps-ri/src/main/resources/changelog/db/changes/16-insert-cm-handle-state-forward.sql
+++ b/cps-ri/src/main/resources/changelog/db/changes/16-insert-cm-handle-state-forward.sql
@@ -1,3 +1,137 @@
-create view cmHandles as select * from fragment where xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]$';
-insert into fragment(xpath, attributes, anchor_id, parent_id, dataspace_id, schema_node_id) select concat(xpath, '/state'), to_jsonb(concat('{"cm-handle-state": "ADVISED", "last-update-time": "', to_char(now(), 'YYYY-MM-DD"T"HH24:MI:SS.MSTZHTZM'), '"}')::json), anchor_id, id, dataspace_id, schema_node_id from cmHandles;
-drop view cmHandles; \ No newline at end of file
+INSERT INTO
+ fragment(
+ xpath,
+ attributes,
+ anchor_id,
+ parent_id,
+ dataspace_id,
+ schema_node_id
+ )
+SELECT
+ concat(cmHandles.xpath, '/state') AS xpath,
+ to_jsonb(
+ concat(
+ '{"cm-handle-state": "READY", "last-update-time": "',
+ to_char(
+ now(),
+ 'YYYY-MM-DD"T"HH24:MI:SS.MSTZHTZM'
+ ),
+ '", "data-sync-enabled": false}'
+ ) :: json
+ ) AS attributes,
+ cmHandles.anchor_id,
+ cmHandles.id,
+ cmHandles.dataspace_id,
+ cmHandles.schema_node_id
+FROM
+ (
+ SELECT
+ id,
+ xpath,
+ anchor_id,
+ dataspace_id,
+ schema_node_id
+ FROM
+ fragment
+ WHERE
+ xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]$'
+ AND xpath NOT IN (
+ SELECT
+ SUBSTRING(
+ xpath
+ FROM
+ '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]'
+ )
+ FROM
+ fragment
+ WHERE
+ xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state$'
+ )
+ ) AS cmHandles;
+INSERT INTO
+ fragment(
+ xpath,
+ attributes,
+ anchor_id,
+ parent_id,
+ dataspace_id,
+ schema_node_id
+ )
+SELECT
+ concat(cmHandlesStates.xpath, '/datastores'),
+ to_jsonb('{}' :: json),
+ cmHandlesStates.anchor_id,
+ cmHandlesStates.id,
+ cmHandlesStates.dataspace_id,
+ cmHandlesStates.schema_node_id
+FROM
+ (
+ SELECT
+ id,
+ xpath,
+ anchor_id,
+ dataspace_id,
+ schema_node_id
+ FROM
+ fragment
+ WHERE
+ xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state$'
+ AND xpath NOT IN (
+ SELECT
+ SUBSTRING(
+ xpath
+ FROM
+ '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state'
+ )
+ FROM
+ fragment
+ WHERE
+ xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state/datastores$'
+ )
+ ) AS cmHandlesStates;
+INSERT INTO
+ fragment(
+ xpath,
+ attributes,
+ anchor_id,
+ parent_id,
+ dataspace_id,
+ schema_node_id
+ )
+SELECT
+ concat(
+ cmHandlesDatastores.xpath,
+ '/operational'
+ ),
+ to_jsonb(
+ concat('{"sync-state": "NONE_REQUESTED"}') :: json
+ ),
+ cmHandlesDatastores.anchor_id,
+ cmHandlesDatastores.id,
+ cmHandlesDatastores.dataspace_id,
+ cmHandlesDatastores.schema_node_id
+FROM
+ (
+ SELECT
+ id,
+ xpath,
+ anchor_id,
+ dataspace_id,
+ schema_node_id
+ FROM
+ fragment
+ WHERE
+ xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state/datastores$'
+ AND xpath NOT IN (
+ SELECT
+ SUBSTRING(
+ xpath
+ FROM
+ '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state/datastores'
+ )
+ FROM
+ fragment
+ WHERE
+ xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state/datastores/operational$'
+ )
+ ) AS cmHandlesDatastores; \ No newline at end of file
diff --git a/cps-ri/src/main/resources/changelog/db/changes/16-insert-cm-handle-state-rollback.sql b/cps-ri/src/main/resources/changelog/db/changes/16-insert-cm-handle-state-rollback.sql
index aaf05a24cb..4b006ef0e2 100644
--- a/cps-ri/src/main/resources/changelog/db/changes/16-insert-cm-handle-state-rollback.sql
+++ b/cps-ri/src/main/resources/changelog/db/changes/16-insert-cm-handle-state-rollback.sql
@@ -1,4 +1,4 @@
-delete from fragment where xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state/lock-reason$';
-delete from fragment where xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state/datastores/operational$';
-delete from fragment where xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state/datastores$';
-delete from fragment where xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state$'; \ No newline at end of file
+DELETE FROM fragment WHERE xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state/lock-reason$';
+DELETE FROM fragment WHERE xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state/datastores/operational$';
+DELETE FROM fragment WHERE xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state/datastores$';
+DELETE FROM fragment WHERE xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state$'; \ No newline at end of file