+ protected void processCreatedCmHandles(final DmiPluginRegistration dmiPluginRegistration,
+ final DmiPluginRegistrationResponse dmiPluginRegistrationResponse) {
+ final List<NcmpServiceCmHandle> ncmpServiceCmHandles = dmiPluginRegistration.getCreatedCmHandles();
+ final List<CmHandleRegistrationResponse> failedCmHandleRegistrationResponses = new ArrayList<>();
+
+ try {
+ final Collection<String> rejectedCmHandleIds
+ = checkAlternateIds(ncmpServiceCmHandles, failedCmHandleRegistrationResponses);
+
+ final Collection<String> succeededCmHandleIds = persistCmHandlesWithState(dmiPluginRegistration,
+ dmiPluginRegistrationResponse, ncmpServiceCmHandles, rejectedCmHandleIds);
+
+ processTrustLevels(ncmpServiceCmHandles, succeededCmHandleIds);
+
+ } catch (final AlreadyDefinedException alreadyDefinedException) {
+ failedCmHandleRegistrationResponses.addAll(CmHandleRegistrationResponse.createFailureResponsesFromXpaths(
+ alreadyDefinedException.getAlreadyDefinedObjectNames(), CM_HANDLE_ALREADY_EXIST));
+ } catch (final Exception exception) {
+ final Collection<String> cmHandleIds =
+ ncmpServiceCmHandles.stream().map(NcmpServiceCmHandle::getCmHandleId).collect(Collectors.toList());
+ failedCmHandleRegistrationResponses.addAll(CmHandleRegistrationResponse
+ .createFailureResponses(cmHandleIds, exception));
+ }
+ final List<CmHandleRegistrationResponse> mergedCmHandleRegistrationResponses
+ = new ArrayList<>(failedCmHandleRegistrationResponses);
+ mergedCmHandleRegistrationResponses.addAll(dmiPluginRegistrationResponse.getCreatedCmHandles());
+
+ dmiPluginRegistrationResponse.setCreatedCmHandles(mergedCmHandleRegistrationResponses);
+ }
+
+ protected void processUpdatedCmHandles(final DmiPluginRegistration dmiPluginRegistration,
+ final DmiPluginRegistrationResponse dmiPluginRegistrationResponse) {
+ dmiPluginRegistrationResponse.setUpdatedCmHandles(networkCmProxyDataServicePropertyHandler
+ .updateCmHandleProperties(dmiPluginRegistration.getUpdatedCmHandles()));
+ }
+
+ protected void processUpgradedCmHandles(
+ final DmiPluginRegistration dmiPluginRegistration,
+ final DmiPluginRegistrationResponse dmiPluginRegistrationResponse) {
+
+ final List<String> cmHandleIds = dmiPluginRegistration.getUpgradedCmHandles().getCmHandles();
+ final String upgradedModuleSetTag = dmiPluginRegistration.getUpgradedCmHandles().getModuleSetTag();
+ final Map<YangModelCmHandle, CmHandleState> acceptedCmHandleStatePerCmHandle
+ = new HashMap<>(cmHandleIds.size());
+ final List<CmHandleRegistrationResponse> cmHandleUpgradeResponses = new ArrayList<>(cmHandleIds.size());
+
+ for (final String cmHandleId : cmHandleIds) {
+ try {
+ final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId);
+ if (yangModelCmHandle.getCompositeState().getCmHandleState() == CmHandleState.READY) {
+ if (moduleUpgradeCanBeSkipped(yangModelCmHandle, upgradedModuleSetTag)) {
+ cmHandleUpgradeResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId));
+ } else {
+ updateYangModelCmHandleForUpgrade(yangModelCmHandle, upgradedModuleSetTag);
+ acceptedCmHandleStatePerCmHandle.put(yangModelCmHandle, CmHandleState.LOCKED);
+ }
+ } else {
+ cmHandleUpgradeResponses.add(
+ CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_READY));
+ }
+ } catch (final DataNodeNotFoundException dataNodeNotFoundException) {
+ log.error("Unable to find data node for cm handle id : {} , caused by : {}",
+ cmHandleId, dataNodeNotFoundException.getMessage());
+ cmHandleUpgradeResponses.add(
+ CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND));
+ } catch (final DataValidationException dataValidationException) {
+ log.error("Unable to upgrade cm handle id: {}, caused by : {}",
+ cmHandleId, dataValidationException.getMessage());
+ cmHandleUpgradeResponses.add(
+ CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLE_INVALID_ID));
+ }
+ }
+ cmHandleUpgradeResponses.addAll(upgradeCmHandles(acceptedCmHandleStatePerCmHandle));
+ dmiPluginRegistrationResponse.setUpgradedCmHandles(cmHandleUpgradeResponses);
+ }
+
+ private Collection<String> checkAlternateIds(
+ final List<NcmpServiceCmHandle> cmHandlesToBeCreated,
+ final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses) {
+ final Collection<String> rejectedCmHandleIds = alternateIdChecker
+ .getIdsOfCmHandlesWithRejectedAlternateId(cmHandlesToBeCreated, AlternateIdChecker.Operation.CREATE);
+ cmHandleRegistrationResponses.addAll(CmHandleRegistrationResponse.createFailureResponses(
+ rejectedCmHandleIds, ALTERNATE_ID_ALREADY_ASSOCIATED));
+ return rejectedCmHandleIds;
+ }
+
+ private List<String> persistCmHandlesWithState(final DmiPluginRegistration dmiPluginRegistration,
+ final DmiPluginRegistrationResponse dmiPluginRegistrationResponse,
+ final List<NcmpServiceCmHandle> cmHandlesToBeCreated,
+ final Collection<String> rejectedCmHandleIds) {
+ final List<String> succeededCmHandleIds = new ArrayList<>(cmHandlesToBeCreated.size());
+ final List<YangModelCmHandle> yangModelCmHandlesToRegister = new ArrayList<>(cmHandlesToBeCreated.size());
+ final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses =
+ new ArrayList<>(cmHandlesToBeCreated.size());
+ for (final NcmpServiceCmHandle ncmpServiceCmHandle: cmHandlesToBeCreated) {
+ if (!rejectedCmHandleIds.contains(ncmpServiceCmHandle.getCmHandleId())) {
+ yangModelCmHandlesToRegister.add(getYangModelCmHandle(dmiPluginRegistration, ncmpServiceCmHandle));
+ cmHandleRegistrationResponses.add(
+ CmHandleRegistrationResponse.createSuccessResponse(ncmpServiceCmHandle.getCmHandleId()));
+ succeededCmHandleIds.add(ncmpServiceCmHandle.getCmHandleId());
+ }
+ }
+ lcmEventsCmHandleStateHandler.initiateStateAdvised(yangModelCmHandlesToRegister);
+ dmiPluginRegistrationResponse.setCreatedCmHandles(cmHandleRegistrationResponses);
+ return succeededCmHandleIds;
+ }
+
+ private YangModelCmHandle getYangModelCmHandle(final DmiPluginRegistration dmiPluginRegistration,
+ final NcmpServiceCmHandle ncmpServiceCmHandle) {
+ return YangModelCmHandle.toYangModelCmHandle(
+ dmiPluginRegistration.getDmiPlugin(),
+ dmiPluginRegistration.getDmiDataPlugin(),
+ dmiPluginRegistration.getDmiModelPlugin(),
+ ncmpServiceCmHandle,
+ ncmpServiceCmHandle.getModuleSetTag(),
+ ncmpServiceCmHandle.getAlternateId());
+ }
+
+ private void processTrustLevels(final Collection<NcmpServiceCmHandle> cmHandlesToBeCreated,
+ final Collection<String> succeededCmHandleIds) {
+ final Map<String, TrustLevel> initialTrustLevelPerCmHandleId = new HashMap<>(cmHandlesToBeCreated.size());
+ for (final NcmpServiceCmHandle ncmpServiceCmHandle: cmHandlesToBeCreated) {
+ if (succeededCmHandleIds.contains(ncmpServiceCmHandle.getCmHandleId())) {
+ initialTrustLevelPerCmHandleId.put(ncmpServiceCmHandle.getCmHandleId(),
+ ncmpServiceCmHandle.getRegistrationTrustLevel());
+ }
+ }
+ trustLevelManager.handleInitialRegistrationOfTrustLevels(initialTrustLevelPerCmHandleId);
+ }
+
+ private static boolean moduleUpgradeCanBeSkipped(final YangModelCmHandle yangModelCmHandle,
+ final String upgradedModuleSetTag) {
+ if (StringUtils.isBlank(upgradedModuleSetTag)) {
+ return false;
+ }
+ return yangModelCmHandle.getModuleSetTag().equals(upgradedModuleSetTag);
+ }
+
+ private static void updateYangModelCmHandleForUpgrade(final YangModelCmHandle yangModelCmHandle,
+ final String upgradedModuleSetTag) {
+ final String lockReasonWithModuleSetTag = String.format(ModuleOperationsUtils.MODULE_SET_TAG_MESSAGE_FORMAT,
+ upgradedModuleSetTag);
+ yangModelCmHandle.setCompositeState(new CompositeStateBuilder().withCmHandleState(CmHandleState.READY)
+ .withLockReason(MODULE_UPGRADE, lockReasonWithModuleSetTag).build());