X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2Fclient%2Freq%2Fsdc%2FSdcCatalogServices.java;h=9c9402100198ca7464417c461a4d96401679d26d;hb=7a58af870eb9934dfec4b5353672d7c428208116;hp=e3bd17852e643f4574c15d15142cf8a0478658dd;hpb=6b6521b5824f61dea05f400dba41092f3aaa0697;p=clamp.git diff --git a/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java b/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java index e3bd1785..9c940210 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java +++ b/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java @@ -77,9 +77,11 @@ import org.onap.clamp.clds.util.CryptoUtils; import org.onap.clamp.clds.util.JacksonUtils; import org.onap.clamp.clds.util.LoggingUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; @Component +@Primary public class SdcCatalogServices { private static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcCatalogServices.class); @@ -1227,4 +1229,77 @@ public class SdcCatalogServices { } } } + + /** + * Method to delete blueprint and location json artifacts from sdc + * + * @param prop + * @param userid + * @param sdcReqUrlsList + * @param artifactName + * @param locationArtifactName + * @throws GeneralSecurityException + * @throws DecoderException + */ + public void deleteArtifactsFromSdc(ModelProperties prop, String userid, List sdcReqUrlsList, + String artifactName, String locationArtifactName) throws GeneralSecurityException, DecoderException { + String serviceInvariantUuid = getServiceInvariantUuidFromProps(prop); + for (String url : sdcReqUrlsList) { + String originalServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid); + logger.info("ServiceUUID used before deleting in url:" + originalServiceUuid); + String sdcServicesInformation = getSdcServicesInformation(originalServiceUuid); + SdcServiceDetail cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation); + String uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail, artifactName); + String responseStr = deleteArtifact(userid, url, uploadedArtifactUuid); + logger.info("value of sdc Response of deleting blueprint from sdc :" + responseStr); + String updatedServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid); + if (!originalServiceUuid.equalsIgnoreCase(updatedServiceUuid)) { + url = url.replace(originalServiceUuid, updatedServiceUuid); + } + logger.info("ServiceUUID used after delete in ulr:" + updatedServiceUuid); + sdcServicesInformation = getSdcServicesInformation(updatedServiceUuid); + cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation); + uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail, locationArtifactName); + responseStr = deleteArtifact(userid, url, uploadedArtifactUuid); + logger.info("value of sdc Response of deleting location json from sdc :" + responseStr); + } + } + + private String deleteArtifact(String userid, String url, String uploadedArtifactUuid) { + try { + String responseStr = ""; + if (uploadedArtifactUuid != null && !uploadedArtifactUuid.isEmpty()) { + logger.info("userid=" + userid); + String basicAuth = getSdcBasicAuth(); + String sdcXonapInstanceId = refProp.getStringValue("sdc.sdcX-InstanceID"); + url = url + "/" + uploadedArtifactUuid; + URL urlObj = new URL(url); + HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection(); + conn.setDoOutput(true); + conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), sdcXonapInstanceId); + conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth); + conn.setRequestProperty("USER_ID", userid); + conn.setRequestMethod("DELETE"); + conn.setRequestProperty("charset", "utf-8"); + conn.setUseCaches(false); + conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME), + LoggingUtils.getRequestId()); + boolean requestFailed = true; + int responseCode = conn.getResponseCode(); + logger.info("responseCode=" + responseCode); + if (responseCode == 200) { + requestFailed = false; + } + responseStr = getResponse(conn); + if (responseStr != null && requestFailed) { + logger.error("requestFailed - responseStr=" + responseStr); + throw new BadRequestException(responseStr); + } + } + return responseStr; + } catch (IOException | DecoderException | GeneralSecurityException e) { + logger.error("Exception when attempting to communicate with SDC", e); + throw new SdcCommunicationException("Exception when attempting to communicate with SDC", e); + } + } }