diff options
author | tragait <rahul.tyagi@est.tech> | 2021-08-06 17:01:31 +0100 |
---|---|---|
committer | tragait <rahul.tyagi@est.tech> | 2021-08-17 13:55:12 +0100 |
commit | e398be5923a47650b109512c795244cdc2b5eb10 (patch) | |
tree | 4d12aa2f7d18785825f4c5b1e9073a68505cf30b /src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java | |
parent | 3139ece993c68ce7e40d166acdd5d9572a3a8a1e (diff) |
implement passthough operational for dmi
Issue-ID: CPS-486
Signed-off-by: tragait <rahul.tyagi@est.tech>
Change-Id: Icf48fa93ea1f0d8a27d2e7e1ab0cfd6096a765ec
Diffstat (limited to 'src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java')
-rw-r--r-- | src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java index bf0689ca..32c8526c 100644 --- a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java +++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java @@ -25,20 +25,22 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import lombok.extern.slf4j.Slf4j; import net.minidev.json.JSONArray; import org.apache.groovy.parser.antlr4.util.StringUtils; +import org.jetbrains.annotations.NotNull; import org.onap.cps.ncmp.dmi.config.DmiPluginConfig.DmiPluginProperties; import org.onap.cps.ncmp.dmi.exception.CmHandleRegistrationException; import org.onap.cps.ncmp.dmi.exception.DmiException; import org.onap.cps.ncmp.dmi.exception.ModuleResourceNotFoundException; import org.onap.cps.ncmp.dmi.exception.ModulesNotFoundException; +import org.onap.cps.ncmp.dmi.exception.ResourceDataNotFound; import org.onap.cps.ncmp.dmi.model.CmHandleOperation; import org.onap.cps.ncmp.dmi.model.CreatedCmHandle; import org.onap.cps.ncmp.dmi.model.ModuleReference; import org.onap.cps.ncmp.dmi.service.client.NcmpRestClient; import org.onap.cps.ncmp.dmi.service.operation.SdncOperations; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @@ -60,10 +62,9 @@ public class DmiServiceImpl implements DmiService { * @param sdncOperations sdncOperations * @param objectMapper objectMapper */ - @Autowired public DmiServiceImpl(final DmiPluginProperties dmiPluginProperties, - final NcmpRestClient ncmpRestClient, - final SdncOperations sdncOperations, final ObjectMapper objectMapper) { + final NcmpRestClient ncmpRestClient, + final SdncOperations sdncOperations, final ObjectMapper objectMapper) { this.dmiPluginProperties = dmiPluginProperties; this.ncmpRestClient = ncmpRestClient; this.objectMapper = objectMapper; @@ -82,7 +83,7 @@ public class DmiServiceImpl implements DmiService { return responseBody; } else { throw new DmiException("SDNC is not able to process request.", - "response code : " + responseEntity.getStatusCode() + " message : " + responseEntity.getBody()); + "response code : " + responseEntity.getStatusCode() + " message : " + responseEntity.getBody()); } } @@ -97,7 +98,7 @@ public class DmiServiceImpl implements DmiService { } else { log.error("SDNC did not return a module resource for the given cmHandle {}", cmHandle); throw new ModuleResourceNotFoundException(cmHandle, - "SDNC did not return a module resource for the given cmHandle."); + "SDNC did not return a module resource for the given cmHandle."); } } return getModuleResponses.toJSONString(); @@ -120,7 +121,7 @@ public class DmiServiceImpl implements DmiService { } catch (final JsonProcessingException e) { log.error("Parsing error occurred while converting cm-handles to JSON {}", cmHandles); throw new DmiException("Internal Server Error.", - "Parsing error occurred while converting given cm-handles object list to JSON "); + "Parsing error occurred while converting given cm-handles object list to JSON "); } final ResponseEntity<String> responseEntity = ncmpRestClient.registerCmHandlesWithNcmp(cmHandlesJson); if (!(responseEntity.getStatusCode() == HttpStatus.CREATED)) { @@ -128,6 +129,31 @@ public class DmiServiceImpl implements DmiService { } } + @Override + public Object getResourceDataOperationalForCmHandle(final @NotNull String cmHandle, + final @NotNull String resourceIdentifier, + final String acceptParam, + final String fieldsQuery, + final Integer depthQuery, + final Map<String, String> cmHandlePropertyMap) { + // not using cmHandlePropertyMap of onap dmi impl , other dmi impl might use this. + final ResponseEntity<String> responseEntity = sdncOperations.getResouceDataForOperational(cmHandle, + resourceIdentifier, + fieldsQuery, + depthQuery, + acceptParam); + return prepareAndSendResponse(responseEntity, cmHandle); + } + + private String prepareAndSendResponse(final ResponseEntity<String> responseEntity, final String cmHandle) { + if (responseEntity.getStatusCode() == HttpStatus.OK) { + return responseEntity.getBody(); + } else { + throw new ResourceDataNotFound(cmHandle, + "response code : " + responseEntity.getStatusCode() + " message : " + responseEntity.getBody()); + } + } + private String createModuleRequest(final ModuleReference moduleReference) { final var ietfNetconfModuleReferences = new LinkedHashMap<>(); ietfNetconfModuleReferences.put("ietf-netconf-monitoring:identifier", moduleReference.getName()); @@ -138,10 +164,10 @@ public class DmiServiceImpl implements DmiService { moduleRequest = writer.writeValueAsString(ietfNetconfModuleReferences); } catch (final JsonProcessingException e) { log.error("JSON exception occurred when creating the module request for the given module reference {}", - moduleReference.getName()); + moduleReference.getName()); throw new DmiException("Unable to process JSON.", - "JSON exception occurred when creating the module request.", e); + "JSON exception occurred when creating the module request.", e); } return moduleRequest; } -} +}
\ No newline at end of file |