- private void parseAndUpdateCmHandlesInDmiRegistration(final DmiPluginRegistration dmiPluginRegistration) {
- try {
- final List<PersistenceCmHandle> updatedPersistenceCmHandles =
- new LinkedList<>();
- for (final CmHandle cmHandle : dmiPluginRegistration.getUpdatedCmHandles()) {
- updatedPersistenceCmHandles.add(toPersistenceCmHandle(dmiPluginRegistration, cmHandle));
- }
- final PersistenceCmHandlesList persistenceCmHandlesList = new PersistenceCmHandlesList();
- persistenceCmHandlesList.setCmHandles(updatedPersistenceCmHandles);
- final String cmHandlesJsonData = objectMapper.writeValueAsString(persistenceCmHandlesList);
- cpsDataService.updateNodeLeavesAndExistingDescendantLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- "/dmi-registry", cmHandlesJsonData, NO_TIMESTAMP);
- } catch (final JsonProcessingException e) {
- log.error("Parsing error occurred while converting Object to JSON Dmi Registry.");
- throw new DataValidationException(
- "Parsing error occurred while processing DMI Plugin Registration" + dmiPluginRegistration, e
- .getMessage(), e);
+ @Override
+ public Object getResourceDataOperationalForCmHandle(final String cmHandle,
+ final String resourceIdentifier,
+ final String acceptParamInHeader,
+ final String optionsParamInQuery) {
+ return handleResponse(dmiDataOperations.getResourceDataFromDmi(
+ cmHandle,
+ resourceIdentifier,
+ optionsParamInQuery,
+ acceptParamInHeader,
+ DmiOperations.DataStoreEnum.PASSTHROUGH_OPERATIONAL), "Not able to get resource data.");
+ }
+
+ @Override
+ public Object getResourceDataPassThroughRunningForCmHandle(final String cmHandle,
+ final String resourceIdentifier,
+ final String acceptParamInHeader,
+ final String optionsParamInQuery) {
+ return handleResponse(dmiDataOperations.getResourceDataFromDmi(
+ cmHandle,
+ resourceIdentifier,
+ optionsParamInQuery,
+ acceptParamInHeader,
+ DmiOperations.DataStoreEnum.PASSTHROUGH_RUNNING), "Not able to get resource data.");
+ }
+
+ @Override
+ public void writeResourceDataPassThroughRunningForCmHandle(final String cmHandle,
+ final String resourceIdentifier,
+ final OperationEnum operation,
+ final String requestData,
+ final String dataType) {
+ handleResponse(
+ dmiDataOperations.writeResourceDataPassThroughRunningFromDmi(
+ cmHandle, resourceIdentifier, operation, requestData, dataType),
+ "Not able to " + operation + " resource data.");
+ }
+
+
+ @Override
+ public Collection<ModuleReference> getYangResourcesModuleReferences(final String cmHandle) {
+ return cpsModuleService.getYangResourcesModuleReferences(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle);
+ }
+
+ /**
+ * Retrieve cm handle identifiers for the given list of module names.
+ *
+ * @param moduleNames module names.
+ * @return a collection of anchor identifiers
+ */
+ @Override
+ public Collection<String> executeCmHandleHasAllModulesSearch(final Collection<String> moduleNames) {
+ return cpsAdminService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, moduleNames);
+ }
+
+ /**
+ * THis method registers a cm handle and intiates modules sync.
+ *
+ * @param dmiPluginRegistration dmi plugin registration information.
+ * @throws JsonProcessingException thrown if json is malformed or missing.
+ */
+ public void parseAndCreateCmHandlesInDmiRegistrationAndSyncModules(
+ final DmiPluginRegistration dmiPluginRegistration) throws JsonProcessingException {
+ final PersistenceCmHandlesList createdPersistenceCmHandlesList =
+ getUpdatedPersistenceCmHandlesList(dmiPluginRegistration, dmiPluginRegistration.getCreatedCmHandles());
+ registerAndSyncNewCmHandles(createdPersistenceCmHandlesList);
+ }
+
+ private static Object handleResponse(final ResponseEntity<?> responseEntity,
+ final String exceptionMessage) {
+ if (responseEntity.getStatusCode().is2xxSuccessful()) {
+ return responseEntity.getBody();
+ } else {
+ throw new NcmpException(exceptionMessage,
+ "DMI status code: " + responseEntity.getStatusCodeValue()
+ + ", DMI response body: " + responseEntity.getBody());
+ }
+ }
+
+ private void parseAndUpdateCmHandlesInDmiRegistration(final DmiPluginRegistration dmiPluginRegistration)
+ throws JsonProcessingException {
+ final PersistenceCmHandlesList updatedPersistenceCmHandlesList =
+ getUpdatedPersistenceCmHandlesList(dmiPluginRegistration, dmiPluginRegistration.getUpdatedCmHandles());
+ final String cmHandlesAsJson = objectMapper.writeValueAsString(updatedPersistenceCmHandlesList);
+ cpsDataService.updateNodeLeavesAndExistingDescendantLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ "/dmi-registry", cmHandlesAsJson, NO_TIMESTAMP);
+ }
+
+ private PersistenceCmHandlesList getUpdatedPersistenceCmHandlesList(
+ final DmiPluginRegistration dmiPluginRegistration,
+ final List<CmHandle> updatedCmHandles) {
+ return PersistenceCmHandlesList.toPersistenceCmHandlesList(
+ dmiPluginRegistration.getDmiPlugin(),
+ dmiPluginRegistration.getDmiDataPlugin(),
+ dmiPluginRegistration.getDmiModelPlugin(),
+ updatedCmHandles);
+ }
+
+ private static void handleJsonProcessingException(final DmiPluginRegistration dmiPluginRegistration,
+ final JsonProcessingException e) {
+ final String message = "Parsing error occurred while processing DMI Plugin Registration"
+ + dmiPluginRegistration;
+ log.error(message);
+ throw new DataValidationException(message, e.getMessage(), e);
+ }
+
+ private void registerAndSyncNewCmHandles(final PersistenceCmHandlesList persistenceCmHandlesList)
+ throws JsonProcessingException {
+ final String cmHandleJsonData = objectMapper.writeValueAsString(persistenceCmHandlesList);
+ cpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, "/dmi-registry",
+ cmHandleJsonData, NO_TIMESTAMP);
+
+ for (final PersistenceCmHandle persistenceCmHandle : persistenceCmHandlesList.getPersistenceCmHandles()) {
+ syncModulesAndCreateAnchor(persistenceCmHandle);