import java.util.regex.Pattern;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries;
import org.onap.cps.ncmp.api.impl.inventory.CmHandleState;
import org.onap.cps.ncmp.api.impl.inventory.CompositeState;
private final DmiDataOperations dmiDataOperations;
private final JsonObjectMapper jsonObjectMapper;
private static final String RETRY_ATTEMPT_KEY = "attempt";
- public static final String MODULE_SET_TAG_KEY = "moduleSetTag";
- public static final String MODULE_SET_TAG_MESSAGE_FORMAT = "Upgrade to ModuleSetTag: {0}";
- private static final String UPGRADE_FORMAT = "Upgrade to ModuleSetTag: %s";
- private static final String LOCK_REASON_DETAILS_MSG_FORMAT = UPGRADE_FORMAT + " Attempt #%d failed: %s";
+ private static final String MODULE_SET_TAG_KEY = "moduleSetTag";
+ public static final String MODULE_SET_TAG_MESSAGE_FORMAT = "Upgrade to ModuleSetTag: %s";
+ private static final String LOCK_REASON_DETAILS_MSG_FORMAT =
+ MODULE_SET_TAG_MESSAGE_FORMAT + " Attempt #%d failed: %s";
private static final Pattern retryAttemptPattern = Pattern.compile("Attempt #(\\d+) failed:.+");
private static final Pattern moduleSetTagPattern = Pattern.compile("Upgrade to ModuleSetTag: (\\S+)");
private static final String CPS_PATH_CM_HANDLES_MODEL_SYNC_FAILED_OR_UPGRADE = """
if (!compositeStateDetails.isEmpty() && compositeStateDetails.containsKey(RETRY_ATTEMPT_KEY)) {
attempt = 1 + Integer.parseInt(compositeStateDetails.get(RETRY_ATTEMPT_KEY));
}
- final String moduleSetTag = compositeStateDetails.get(MODULE_SET_TAG_KEY);
+ final String moduleSetTag = compositeStateDetails.getOrDefault(MODULE_SET_TAG_KEY, "");
compositeState.setLockReason(CompositeState.LockReason.builder()
- .details(String.format(LOCK_REASON_DETAILS_MSG_FORMAT, StringUtils.isNotBlank(moduleSetTag)
- ? moduleSetTag : "not-specified", attempt, errorMessage)).lockReasonCategory(lockReasonCategory)
+ .details(String.format(LOCK_REASON_DETAILS_MSG_FORMAT, moduleSetTag, attempt, errorMessage))
+ .lockReasonCategory(lockReasonCategory)
.build());
}
* @param compositeState current lock reason of cm handle
* @return true or false based on lock reason category
*/
- public static boolean isInUpgradeOrUpgradeFailed(final CompositeState compositeState) {
+ public static boolean inUpgradeOrUpgradeFailed(final CompositeState compositeState) {
return compositeState.getLockReason() != null
&& (LockReasonCategory.MODULE_UPGRADE.equals(compositeState.getLockReason().getLockReasonCategory())
|| LockReasonCategory.MODULE_UPGRADE_FAILED.equals(compositeState.getLockReason()
.getLockReasonCategory()));
}
+ public static String getUpgradedModuleSetTagFromLockReason(final CompositeState.LockReason lockReason) {
+ return getLockedCompositeStateDetails(lockReason).getOrDefault(MODULE_SET_TAG_KEY, "");
+ }
+
private String getFirstResource(final Object responseBody) {
final String jsonObjectAsString = jsonObjectMapper.asJsonString(responseBody);
final JsonNode overallJsonNode = jsonObjectMapper.convertToJsonNode(jsonObjectAsString);
private List<YangModelCmHandle> convertCmHandlesDataNodesToYangModelCmHandles(
final List<DataNode> cmHandlesAsDataNodeList) {
- return cmHandlesAsDataNodeList.stream()
- .map(cmHandle -> YangDataConverter.convertCmHandleToYangModel(cmHandle,
- cmHandle.getLeaves().get("id").toString())).toList();
+ return cmHandlesAsDataNodeList.stream().map(YangDataConverter::convertCmHandleToYangModel).toList();
}
private boolean isRetryDue(final CompositeState.LockReason compositeStateLockReason, final OffsetDateTime time) {