diff options
author | Toine Siebelink <toine.siebelink@est.tech> | 2022-05-13 08:03:43 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2022-05-13 08:03:43 +0000 |
commit | 806d31aed57c798cba0ecc33d92e5b43fa1d957b (patch) | |
tree | 87e4b3ba1fc6cff6d9dc40805e8191faeddba82b /cps-ncmp-service/src/main | |
parent | ac57cca55024135a237a7d7f036f80b6b628b868 (diff) | |
parent | f16b9614298e7f0a820435f2dab2a856b487bf45 (diff) |
Merge "Watchdog-process that syncs 'ADVISED' CM Handles"
Diffstat (limited to 'cps-ncmp-service/src/main')
5 files changed, 64 insertions, 15 deletions
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 a981022256..997e7d5324 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 @@ -21,7 +21,9 @@ package org.onap.cps.ncmp.api.impl.config; import java.util.Arrays; +import lombok.AccessLevel; import lombok.Getter; +import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.boot.web.client.RestTemplateBuilder; @@ -30,10 +32,13 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; import org.springframework.http.MediaType; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; +@EnableScheduling @Configuration +@RequiredArgsConstructor(access = AccessLevel.PROTECTED) public class NcmpConfiguration { @Getter @@ -68,4 +73,5 @@ public class NcmpConfiguration { Arrays.asList(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN)); restTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter); } + } 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 289d782cde..5680d54a48 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,6 +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.models.NcmpServiceCmHandle; import org.onap.cps.utils.CpsValidator; @@ -56,7 +57,7 @@ public class YangModelCmHandle { private String dmiDataServiceName; @JsonProperty("state") - private String cmHandleState; + private CmHandleState cmHandleState; @JsonProperty("dmi-model-service-name") private String dmiModelServiceName; 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 new file mode 100644 index 0000000000..0fce1d1890 --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleState.java @@ -0,0 +1,41 @@ +/* + * ============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; + +public enum CmHandleState { + + ADVISED { + @Override + public CmHandleState ready() { + return READY; + } + }, + READY { + @Override + public CmHandleState ready() { + return this; + } + + }; + + public abstract CmHandleState ready(); + +} 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 0d8f852193..368262b972 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 @@ -23,32 +23,32 @@ 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.onap.cps.ncmp.api.inventory.CmHandleState; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Slf4j -@EnableScheduling @RequiredArgsConstructor @Component public class ModuleSyncWatchdog { private final SyncUtils syncUtils; + private final ModuleSyncService moduleSyncService; + /** * Execute Cm Handle poll which changes the cm handle state from 'ADVISED' to 'READY'. */ @Scheduled(fixedDelayString = "${ncmp.timers.advised-modules-sync.sleep-time-ms}") 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(); + 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()); + 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 924546433e..019ab08cab 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 @@ -32,6 +32,7 @@ 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.ncmp.api.inventory.CmHandleState; import org.onap.cps.spi.CpsDataPersistenceService; import org.onap.cps.spi.FetchDescendantsOption; import org.onap.cps.spi.model.DataNode; @@ -74,10 +75,10 @@ public class SyncUtils { * Update the Cm Handle state to "READY". * * @param yangModelCmHandle yang model cm handle - * @param state cm handle state + * @param cmHandleState cm handle state */ - public void updateCmHandleState(final YangModelCmHandle yangModelCmHandle, final String state) { - yangModelCmHandle.setCmHandleState(state); + public void updateCmHandleState(final YangModelCmHandle yangModelCmHandle, final CmHandleState cmHandleState) { + yangModelCmHandle.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, |