package org.onap.cps.ncmp.api.inventory.sync;
-import static org.onap.ncmp.cmhandle.lcm.event.Event.Operation.CREATE;
-
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.api.impl.event.NcmpEventsService;
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.CompositeState.LockReason;
import org.onap.cps.ncmp.api.inventory.InventoryPersistence;
import org.onap.cps.ncmp.api.inventory.LockReasonCategory;
import org.springframework.scheduling.annotation.Scheduled;
private final ModuleSyncService moduleSyncService;
- private final NcmpEventsService ncmpEventsService;
-
/**
* Execute Cm Handle poll which changes the cm handle state from 'ADVISED' to 'READY'.
- * Also publish the LCM Create Event when cm handle state is moved to 'READY'.
*/
@Scheduled(fixedDelayString = "${timers.advised-modules-sync.sleep-time-ms:30000}")
public void executeAdvisedCmHandlePoll() {
inventoryPersistence.saveCmHandleState(cmHandleId, compositeState);
log.info("{} is now in {} state", cmHandleId,
advisedCmHandle.getCompositeState().getCmHandleState());
- if (compositeState.getCmHandleState() == CmHandleState.READY) {
- log.debug("Publishing LCM Create Event for cmHandleId : {}", cmHandleId);
- ncmpEventsService.publishNcmpEvent(cmHandleId, CREATE);
- }
advisedCmHandle = syncUtils.getAnAdvisedCmHandle();
}
log.debug("No Cm-Handles currently found in an ADVISED state");
* Execute Cm Handle poll which changes the cm handle state from 'LOCKED' to 'ADVISED'.
*/
@Scheduled(fixedDelayString = "${timers.locked-modules-sync.sleep-time-ms:300000}")
- public void executeLockedMisbehavingCmHandlePoll() {
- final List<YangModelCmHandle> lockedMisbehavingCmHandles = syncUtils.getLockedMisbehavingCmHandles();
- for (final YangModelCmHandle lockedMisbehavingModelCmHandle: lockedMisbehavingCmHandles) {
- final CompositeState updatedCompositeState = lockedMisbehavingModelCmHandle.getCompositeState();
- updatedCompositeState.setCmHandleState(CmHandleState.ADVISED);
- updatedCompositeState.setLastUpdateTimeNow();
- updatedCompositeState.setLockReason(LockReason.builder()
- .details(updatedCompositeState.getLockReason().getDetails()).build());
- log.debug("Locked misbehaving cm handle {} is being recycled", lockedMisbehavingModelCmHandle.getId());
- inventoryPersistence.saveCmHandleState(lockedMisbehavingModelCmHandle.getId(), updatedCompositeState);
+ public void executeLockedCmHandlePoll() {
+ final List<YangModelCmHandle> lockedMisbehavingCmHandles = syncUtils.getLockedMisbehavingYangModelCmHandles();
+ for (final YangModelCmHandle moduleSyncFailedCmHandle : lockedMisbehavingCmHandles) {
+ final CompositeState compositeState = moduleSyncFailedCmHandle.getCompositeState();
+ final boolean isReadyForRetry = syncUtils.isReadyForRetry(compositeState);
+ if (isReadyForRetry) {
+ setCompositeStateToAdvisedAndRetainOldLockReasonDetails(compositeState);
+ log.debug("Locked misbehaving cm handle {} is being recycled", moduleSyncFailedCmHandle.getId());
+ inventoryPersistence.saveCmHandleState(moduleSyncFailedCmHandle.getId(), compositeState);
+ }
}
}
+
+ 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());
+ }
}