-\r
- // Method to get service invariant uuid from model properties.\r
- private String getServiceInvariantUuidFromProps(ModelProperties props) {\r
- String invariantUuid = "";\r
- Global globalProps = props.getGlobal();\r
- if (globalProps != null && globalProps.getService() != null) {\r
- invariantUuid = globalProps.getService();\r
- }\r
- return invariantUuid;\r
- }\r
-\r
- /**\r
- * This method upload the BluePrint to SDC.\r
- * \r
- * @param prop\r
- * The Clds model Properties\r
- * @param userid\r
- * The user id for SDC\r
- * @param sdcReqUrlsList\r
- * The list of SDC URL to try\r
- * @param formattedSdcReq\r
- * The blueprint to upload\r
- * @param formattedSdcLocationReq\r
- * THe location Blueprint to upload\r
- * @param artifactName\r
- * The artifact name from where we can get the Artifact UUID\r
- * @param locationArtifactName\r
- * The location artifact name from where we can get the Artifact\r
- * UUID\r
- * @throws GeneralSecurityException\r
- * In case of issues with the decryting the encrypted password\r
- * @throws DecoderException\r
- * In case of issues with the decoding of the Hex String\r
- */\r
- public void uploadToSdc(ModelProperties prop, String userid, List<String> sdcReqUrlsList, String formattedSdcReq,\r
- String formattedSdcLocationReq, String artifactName, String locationArtifactName)\r
- throws GeneralSecurityException, DecoderException {\r
- logger.info("userid=" + userid);\r
- String serviceInvariantUuid = getServiceInvariantUuidFromProps(prop);\r
- if (sdcReqUrlsList != null && !sdcReqUrlsList.isEmpty()) {\r
- for (String url : sdcReqUrlsList) {\r
- if (url != null) {\r
- String originalServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid);\r
- logger.info("ServiceUUID used before upload in url:" + originalServiceUuid);\r
- String sdcServicesInformation = getSdcServicesInformation(originalServiceUuid);\r
- SdcServiceDetail cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
- String uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail,\r
- artifactName);\r
- // Upload artifacts to sdc\r
- String updateUrl = uploadedArtifactUuid != null ? url + "/" + uploadedArtifactUuid : url;\r
- String responseStr = uploadArtifactToSdc(prop, userid, updateUrl, formattedSdcReq);\r
- logger.info("value of sdc Response of uploading to sdc :" + responseStr);\r
- String updatedServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid);\r
- if (!originalServiceUuid.equalsIgnoreCase(updatedServiceUuid)) {\r
- url = url.replace(originalServiceUuid, updatedServiceUuid);\r
- }\r
- logger.info("ServiceUUID used after upload in ulr:" + updatedServiceUuid);\r
- sdcServicesInformation = getSdcServicesInformation(updatedServiceUuid);\r
- cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
- uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail,\r
- locationArtifactName);\r
- // To send location information also to sdc\r
- updateUrl = uploadedArtifactUuid != null ? url + "/" + uploadedArtifactUuid : url;\r
- responseStr = uploadArtifactToSdc(prop, userid, updateUrl, formattedSdcLocationReq);\r
- logger.info("value of sdc Response of uploading location to sdc :" + responseStr);\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Method to delete blueprint and location json artifacts from sdc\r
- * \r
- * @param prop\r
- * @param userid\r
- * @param sdcReqUrlsList\r
- * @param artifactName\r
- * @param locationArtifactName\r
- * @throws GeneralSecurityException\r
- * @throws DecoderException\r
- */\r
- public void deleteArtifactsFromSdc(ModelProperties prop, String userid, List<String> sdcReqUrlsList,\r
- String artifactName, String locationArtifactName) throws GeneralSecurityException, DecoderException {\r
- String serviceInvariantUuid = getServiceInvariantUuidFromProps(prop);\r
- for (String url : sdcReqUrlsList) {\r
- String originalServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid);\r
- logger.info("ServiceUUID used before deleting in url:" + originalServiceUuid);\r
- String sdcServicesInformation = getSdcServicesInformation(originalServiceUuid);\r
- SdcServiceDetail cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
- String uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail, artifactName);\r
- String responseStr = deleteArtifact(userid, url, uploadedArtifactUuid);\r
- logger.info("value of sdc Response of deleting blueprint from sdc :" + responseStr);\r
- String updatedServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid);\r
- if (!originalServiceUuid.equalsIgnoreCase(updatedServiceUuid)) {\r
- url = url.replace(originalServiceUuid, updatedServiceUuid);\r
- }\r
- logger.info("ServiceUUID used after delete in ulr:" + updatedServiceUuid);\r
- sdcServicesInformation = getSdcServicesInformation(updatedServiceUuid);\r
- cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
- uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail, locationArtifactName);\r
- responseStr = deleteArtifact(userid, url, uploadedArtifactUuid);\r
- logger.info("value of sdc Response of deleting location json from sdc :" + responseStr);\r
- }\r
- }\r
-\r
- private String deleteArtifact(String userid, String url, String uploadedArtifactUuid) {\r
- try {\r
- String responseStr = "";\r
- if (uploadedArtifactUuid != null && !uploadedArtifactUuid.isEmpty()) {\r
- logger.info("userid=" + userid);\r
- String basicAuth = getSdcBasicAuth();\r
- String sdcXonapInstanceId = refProp.getStringValue("sdc.sdcX-InstanceID");\r
- url = url + "/" + uploadedArtifactUuid;\r
- URL urlObj = new URL(url);\r
- HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
- conn = utils.invoke(conn,"SDC", "deleteArtifact");\r
- conn.setDoOutput(true);\r
- conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), sdcXonapInstanceId);\r
- conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);\r
- conn.setRequestProperty("USER_ID", userid);\r
- conn.setRequestMethod("DELETE");\r
- conn.setRequestProperty("charset", "utf-8");\r
- conn.setUseCaches(false);\r
- conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME),\r
- LoggingUtils.getRequestId());\r
- boolean requestFailed = true;\r
- int responseCode = conn.getResponseCode();\r
- logger.info("responseCode=" + responseCode);\r
- if (responseCode == 200) {\r
- requestFailed = false;\r
- }\r
- responseStr = getResponse(conn);\r
- if (responseStr != null && requestFailed) {\r
- logger.error("requestFailed - responseStr=" + responseStr);\r
- utils.invokeReturn();\r
- throw new BadRequestException(responseStr);\r
- }\r
- }\r
- utils.invokeReturn();\r
- return responseStr;\r
- } catch (IOException | DecoderException | GeneralSecurityException e) {\r
- logger.error("Exception when attempting to communicate with SDC", e);\r
- utils.invokeReturn();\r
- throw new SdcCommunicationException("Exception when attempting to communicate with SDC", e);\r
- }\r
- }\r