diff options
15 files changed, 247 insertions, 56 deletions
diff --git a/cps-application/src/main/resources/application.yml b/cps-application/src/main/resources/application.yml index 00424a587..7ad22e977 100644 --- a/cps-application/src/main/resources/application.yml +++ b/cps-application/src/main/resources/application.yml @@ -130,13 +130,14 @@ logging: springframework: INFO
onap:
cps: INFO
-ncmp:
- dmi:
- auth:
- username: ${DMI_USERNAME}
- password: ${DMI_PASSWORD}
- api:
- base-path: dmi
- timers:
- advised-modules-sync:
- sleep-time-ms: 30000
\ No newline at end of file +
+dmi:
+ auth:
+ username: ${DMI_USERNAME}
+ password: ${DMI_PASSWORD}
+ api:
+ base-path: dmi
+
+timers:
+ advised-modules-sync:
+ sleep-time-ms: 30000
\ No newline at end of file diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java index 997e7d532..af33651eb 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java @@ -44,11 +44,11 @@ public class NcmpConfiguration { @Getter @Component public static class DmiProperties { - @Value("${ncmp.dmi.auth.username}") + @Value("${dmi.auth.username}") private String authUsername; - @Value("${ncmp.dmi.auth.password}") + @Value("${dmi.auth.password}") private String authPassword; - @Value("${ncmp.dmi.api.base-path}") + @Value("${dmi.api.base-path}") private String dmiBasePath; } 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 b1ac91d7a..5063e8298 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 @@ -55,9 +55,9 @@ public class YangModelCmHandleRetriever { ncmpServiceCmHandle.setCmHandleId(cmHandleId); populateCmHandleProperties(cmHandleDataNode, ncmpServiceCmHandle); return YangModelCmHandle.toYangModelCmHandle( - String.valueOf(cmHandleDataNode.getLeaves().get("dmi-service-name")), - String.valueOf(cmHandleDataNode.getLeaves().get("dmi-data-service-name")), - String.valueOf(cmHandleDataNode.getLeaves().get("dmi-model-service-name")), + (String) cmHandleDataNode.getLeaves().get("dmi-service-name"), + (String) cmHandleDataNode.getLeaves().get("dmi-data-service-name"), + (String) cmHandleDataNode.getLeaves().get("dmi-model-service-name"), 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 5680d54a4..d4c64eac9 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 @@ -34,7 +34,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.onap.cps.ncmp.api.impl.operations.RequiredDmiService; -import org.onap.cps.ncmp.api.inventory.CmHandleState; +import org.onap.cps.ncmp.api.inventory.CompositeState; import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; import org.onap.cps.utils.CpsValidator; @@ -57,7 +57,7 @@ public class YangModelCmHandle { private String dmiDataServiceName; @JsonProperty("state") - private CmHandleState cmHandleState; + private CompositeState compositeState; @JsonProperty("dmi-model-service-name") private String dmiModelServiceName; @@ -70,8 +70,9 @@ public class YangModelCmHandle { /** * Create a yangModelCmHandle. - * @param dmiServiceName dmi service name - * @param dmiDataServiceName dmi data service name + * + * @param dmiServiceName dmi service name + * @param dmiDataServiceName dmi data service name * @param dmiModelServiceName dmi model service name * @param ncmpServiceCmHandle the cm handle * @return instance of yangModelCmHandle @@ -88,12 +89,13 @@ public class YangModelCmHandle { yangModelCmHandle.setDmiModelServiceName(dmiModelServiceName); yangModelCmHandle.setDmiProperties(asYangModelCmHandleProperties(ncmpServiceCmHandle.getDmiProperties())); yangModelCmHandle.setPublicProperties(asYangModelCmHandleProperties( - ncmpServiceCmHandle.getPublicProperties())); + ncmpServiceCmHandle.getPublicProperties())); return yangModelCmHandle; } /** * Resolve a dmi service name. + * * @param requiredService indicates what typo of service is required * @return dmi service name */ diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleState.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleState.java index 0fce1d189..24fab32a5 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleState.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleState.java @@ -21,21 +21,5 @@ package org.onap.cps.ncmp.api.inventory; public enum CmHandleState { - - ADVISED { - @Override - public CmHandleState ready() { - return READY; - } - }, - READY { - @Override - public CmHandleState ready() { - return this; - } - - }; - - public abstract CmHandleState ready(); - + ADVISED, READY; } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeState.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeState.java new file mode 100644 index 000000000..9ac49a6ce --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeState.java @@ -0,0 +1,104 @@ +/* + * ============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; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + * State Model to store state corresponding to the Yang resource dmi-registry model. + */ +@Getter +@Setter +@NoArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +public class CompositeState { + + @JsonProperty("cm-handle-state") + private CmHandleState cmhandleState; + + @JsonProperty("lock-reason") + private LockReason lockReason; + + @JsonProperty("last-update-time") + private String lastUpdateTime; + + @JsonProperty("data-sync-enabled") + private Boolean dataSyncEnabled; + + @JsonProperty("datastores") + private DataStores dataStores; + + @Data + @Builder + @JsonInclude(JsonInclude.Include.NON_NULL) + public static class LockReason { + + @JsonProperty("reason") + private String reason; + + @JsonProperty("details") + private String details; + + } + + @Data + @Builder + @JsonInclude(JsonInclude.Include.NON_NULL) + public static class DataStores { + + @JsonProperty("operational") + private Operational operationalDataStore; + + @JsonProperty("running") + private Running runningDataStore; + } + + @Data + @Builder + @JsonInclude(JsonInclude.Include.NON_NULL) + public static class Operational { + + @JsonProperty("sync-state") + private String syncState; + + @JsonProperty("last-sync-time") + private String lastSyncTime; + } + + @Data + @Builder + @JsonInclude(JsonInclude.Include.NON_NULL) + public static class Running { + + @JsonProperty("sync-state") + private String syncState; + + @JsonProperty("last-sync-time") + private String lastSyncTime; + } + +} 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 368262b97..353db9d68 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 @@ -39,15 +39,15 @@ public class ModuleSyncWatchdog { /** * Execute Cm Handle poll which changes the cm handle state from 'ADVISED' to 'READY'. */ - @Scheduled(fixedDelayString = "${ncmp.timers.advised-modules-sync.sleep-time-ms}") + @Scheduled(fixedDelayString = "${timers.advised-modules-sync.sleep-time-ms}") public void executeAdvisedCmHandlePoll() { YangModelCmHandle advisedCmHandle = syncUtils.getAnAdvisedCmHandle(); while (advisedCmHandle != null) { - final CmHandleState cmHandleState = advisedCmHandle.getCmHandleState(); moduleSyncService.syncAndCreateSchemaSet(advisedCmHandle); // ToDo Lock Cm Handle if module sync fails - syncUtils.updateCmHandleState(advisedCmHandle, cmHandleState.ready()); - log.info("{} is now in {} state", advisedCmHandle.getId(), advisedCmHandle.getCmHandleState()); + syncUtils.updateCmHandleState(advisedCmHandle, CmHandleState.READY); + log.info("{} is now in {} state", advisedCmHandle.getId(), + advisedCmHandle.getCompositeState().getCmhandleState()); advisedCmHandle = 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 index 019ab08ca..3bc43c566 100644 --- 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 @@ -78,7 +78,7 @@ public class SyncUtils { * @param cmHandleState cm handle state */ public void updateCmHandleState(final YangModelCmHandle yangModelCmHandle, final CmHandleState cmHandleState) { - yangModelCmHandle.setCmHandleState(cmHandleState); + yangModelCmHandle.getCompositeState().setCmhandleState(cmHandleState); final String cmHandleJsonData = String.format("{\"cm-handles\":[%s]}", jsonObjectMapper.asJsonString(yangModelCmHandle)); cpsDataService.updateNodeLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT, diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetrieverSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetrieverSpec.groovy index beea1faad..5ecc8b0da 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetrieverSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetrieverSpec.groovy @@ -79,4 +79,16 @@ class YangModelCmHandleRetrieverSpec extends Specification { and: 'the result is not returned' result == null } + + def "Handling missing service names as null CPS-1043."() { + given: 'the cps data service returns a data node from the DMI registry with empty child and leaf attributes' + def dataNode = new DataNode(childDataNodes:[], leaves: [:]) + mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', xpath, INCLUDE_ALL_DESCENDANTS) >> dataNode + when: 'retrieving the yang modelled cm handle' + def result = objectUnderTest.getYangModelCmHandle(cmHandleId) + then: 'the service names ae returned as null' + result.dmiServiceName == null + result.dmiDataServiceName == null + result.dmiModelServiceName == null + } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateSpec.groovy new file mode 100644 index 000000000..4f4cccfe7 --- /dev/null +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateSpec.groovy @@ -0,0 +1,64 @@ +/* + * ============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 + +import com.fasterxml.jackson.databind.ObjectMapper +import spock.lang.Specification + +import java.time.OffsetDateTime +import java.time.ZoneOffset +import java.time.format.DateTimeFormatter + +import static CompositeState.DataStores +import static CompositeState.LockReason +import static CompositeState.Operational +import static CompositeState.Running +import static org.onap.cps.ncmp.utils.TestUtils.getResourceFileContent +import static org.springframework.util.StringUtils.trimAllWhitespace + +class CompositeStateSpec extends Specification { + + def formattedDateAndTime = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(OffsetDateTime.of(2022, 1, 1, 1, 1, 1, 1, ZoneOffset.MIN)) + def objectMapper = new ObjectMapper() + + def "Composite State Specification"() { + given: "a Composite State" + def compositeState = new CompositeState(cmhandleState: CmHandleState.ADVISED, + lockReason: LockReason.builder().reason('lock-reason').details("lock-misbehaving-details").build(), + lastUpdateTime: formattedDateAndTime.toString(), + dataSyncEnabled: false, + dataStores: dataStores()) + when: 'it is represented as JSON' + def jsonStateModelAsString = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(compositeState) + then: 'it matches expected state model as JSON' + def expectedStateModelAsjson = getResourceFileContent('expectedStateModel.json') + assert trimAllWhitespace(expectedStateModelAsjson) == trimAllWhitespace(jsonStateModelAsString) + } + + def dataStores() { + DataStores.builder().operationalDataStore(Operational.builder() + .syncState('NONE_REQUESTED') + .lastSyncTime(formattedDateAndTime.toString()).build()).runningDataStore(Running.builder() + .syncState('NONE_REQUESTED') + .lastSyncTime(formattedDateAndTime.toString()).build()) + .build() + } +} diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/CmHandleStateSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/CmHandleStateSpec.groovy index 923a9037d..bfc5c6fa3 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/CmHandleStateSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/CmHandleStateSpec.groovy @@ -29,7 +29,7 @@ class CmHandleStateSpec extends Specification{ given: 'a cm handle with an ADVISED state' def cmHandleState = CmHandleState.ADVISED when: 'the state transitions to the READY state' - cmHandleState = cmHandleState.ready() + cmHandleState = CmHandleState.READY then: 'the cm handle state changes to READY' assert CmHandleState.READY == cmHandleState } @@ -38,7 +38,7 @@ class CmHandleStateSpec extends Specification{ given: 'a cm handle with a READY state' def cmHandleState = CmHandleState.READY when: 'the state transitions to READY state' - cmHandleState = cmHandleState.ready() + cmHandleState = CmHandleState.READY then: 'the cm handle state remains as READY' assert CmHandleState.READY == cmHandleState } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy index 0a06fbaa8..35de99fef 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy @@ -23,6 +23,7 @@ package org.onap.cps.ncmp.api.inventory.sync 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 spock.lang.Specification class ModuleSyncSpec extends Specification { @@ -37,8 +38,10 @@ class ModuleSyncSpec extends Specification { def 'Schedule a Cm-Handle Sync for ADVISED Cm-Handles'() { given: 'cm handles in an advised state' - def yangModelCmHandle1 = new YangModelCmHandle(cmHandleState: cmHandleState) - def yangModelCmHandle2 = new YangModelCmHandle(cmHandleState: cmHandleState) + def compositeState = new CompositeState() + compositeState.cmhandleState = cmHandleState + def yangModelCmHandle1 = new YangModelCmHandle(compositeState: compositeState) + def yangModelCmHandle2 = new YangModelCmHandle(compositeState: compositeState) and: 'sync utilities return a cm handle twice' mockSyncUtils.getAnAdvisedCmHandle() >>> [yangModelCmHandle1, yangModelCmHandle2, null] when: 'module sync poll is executed' diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy index e5d3652d2..c80263ef0 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy @@ -25,6 +25,7 @@ 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.ncmp.api.inventory.CmHandleState +import org.onap.cps.ncmp.api.inventory.CompositeState import org.onap.cps.spi.CpsDataPersistenceService import org.onap.cps.spi.FetchDescendantsOption import org.onap.cps.spi.model.DataNode @@ -68,8 +69,10 @@ class SyncUtilsSpec extends Specification{ def 'Update cm handle state from Advised to Ready'() { given: 'a yang model cm handle and the expected json data' - def yangModelCmHandle = new YangModelCmHandle(id: 'Some-Cm-Handle', cmHandleState: CmHandleState.ADVISED) - def expectedJsonData = '{"cm-handles":[{"id":"Some-Cm-Handle","state":"READY"}]}' + def compositeState = new CompositeState() + compositeState.cmhandleState = CmHandleState.ADVISED + def yangModelCmHandle = new YangModelCmHandle(id: 'Some-Cm-Handle', compositeState: compositeState ) + def expectedJsonData = '{"cm-handles":[{"id":"Some-Cm-Handle","state":{"cm-handle-state":"READY"}}]}' when: 'update cm handle state is called' objectUnderTest.updateCmHandleState(yangModelCmHandle, CmHandleState.READY) then: 'update data note leaves is invoked with the correct params' diff --git a/cps-ncmp-service/src/test/resources/application.yml b/cps-ncmp-service/src/test/resources/application.yml index c259bf005..c23926e4e 100644 --- a/cps-ncmp-service/src/test/resources/application.yml +++ b/cps-ncmp-service/src/test/resources/application.yml @@ -16,11 +16,10 @@ # SPDX-License-Identifier: Apache-2.0 # ============LICENSE_END========================================================= -ncmp: - dmi: - auth: - username: some-user - password: some-password - api: - base-path: dmi +dmi: + auth: + username: some-user + password: some-password + api: + base-path: dmi diff --git a/cps-ncmp-service/src/test/resources/expectedStateModel.json b/cps-ncmp-service/src/test/resources/expectedStateModel.json new file mode 100644 index 000000000..a41619434 --- /dev/null +++ b/cps-ncmp-service/src/test/resources/expectedStateModel.json @@ -0,0 +1,19 @@ +{ + "cm-handle-state" : "ADVISED", + "lock-reason" : { + "reason" : "lock-reason", + "details" : "lock-misbehaving-details" + }, + "last-update-time" : "2022-01-01T01:01:01.000-1800", + "data-sync-enabled" : false, + "datastores" : { + "operational" : { + "sync-state" : "NONE_REQUESTED", + "last-sync-time" : "2022-01-01T01:01:01.000-1800" + }, + "running" : { + "sync-state" : "NONE_REQUESTED", + "last-sync-time" : "2022-01-01T01:01:01.000-1800" + } + } +}
\ No newline at end of file |