* ============LICENSE_END============================================\r
* Modifications copyright (c) 2018 Nokia\r
* ===================================================================\r
- * \r
+ *\r
*/\r
\r
package org.onap.clamp.clds.client;\r
import com.att.eelf.configuration.EELFLogger;\r
import com.att.eelf.configuration.EELFManager;\r
import com.fasterxml.jackson.core.JsonProcessingException;\r
-import com.fasterxml.jackson.databind.node.ObjectNode;\r
\r
import java.io.IOException;\r
import java.util.Date;\r
import java.util.List;\r
\r
-import javax.ws.rs.BadRequestException;\r
-\r
import org.json.simple.JSONArray;\r
import org.json.simple.JSONObject;\r
import org.json.simple.parser.JSONParser;\r
protected static final EELFLogger logger = EELFManager.getInstance().getLogger(DcaeInventoryServices.class);\r
protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();\r
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();\r
- private static final String DCAE_INVENTORY_URL = "dcae.inventory.url";\r
- private static final String DCAE_INVENTORY_RETRY_INTERVAL = "dcae.intentory.retry.interval";\r
- private static final String DCAE_INVENTORY_RETRY_LIMIT = "dcae.intentory.retry.limit";\r
- public static final String DCAE_TYPE_NAME = "typeName";\r
- public static final String DCAE_TYPE_ID = "typeId";\r
+ public static final String DCAE_INVENTORY_URL = "dcae.inventory.url";\r
+ public static final String DCAE_INVENTORY_RETRY_INTERVAL = "dcae.intentory.retry.interval";\r
+ public static final String DCAE_INVENTORY_RETRY_LIMIT = "dcae.intentory.retry.limit";\r
private final ClampProperties refProp;\r
private final CldsDao cldsDao;\r
private final DcaeHttpConnectionManager dcaeHttpConnectionManager;\r
\r
@Autowired\r
- public DcaeInventoryServices(ClampProperties refProp, CldsDao cldsDao, DcaeHttpConnectionManager dcaeHttpConnectionManager) {\r
+ public DcaeInventoryServices(ClampProperties refProp, CldsDao cldsDao,\r
+ DcaeHttpConnectionManager dcaeHttpConnectionManager) {\r
this.refProp = refProp;\r
this.cldsDao = cldsDao;\r
this.dcaeHttpConnectionManager = dcaeHttpConnectionManager;\r
}\r
\r
-\r
/**\r
* Set the event inventory.\r
- * \r
+ *\r
* @param cldsModel\r
- * The CldsModel\r
+ * The CldsModel\r
* @param userId\r
- * The user ID\r
+ * The user ID\r
* @throws ParseException\r
- * In case of DCAE Json parse exception\r
+ * In case of DCAE Json parse exception\r
*/\r
public void setEventInventory(CldsModel cldsModel, String userId) throws ParseException, InterruptedException {\r
String artifactName = cldsModel.getControlName();\r
try {\r
// Below are the properties required for calling the dcae inventory\r
ModelProperties prop = new ModelProperties(cldsModel.getName(), cldsModel.getControlName(), null, false,\r
- "{}", cldsModel.getPropText());\r
+ "{}", cldsModel.getPropText());\r
Global global = prop.getGlobal();\r
String invariantServiceUuid = global.getService();\r
List<String> resourceUuidList = global.getResourceVf();\r
}\r
\r
private void analyzeAndSaveDcaeResponse(DcaeInventoryResponse dcaeResponse, CldsModel cldsModel,\r
- DcaeEvent dcaeEvent, String userId) {\r
+ DcaeEvent dcaeEvent, String userId) {\r
if (dcaeResponse != null) {\r
logger.info("Dcae Response for query on inventory: " + dcaeResponse);\r
String oldTypeId = cldsModel.getTypeId();\r
cldsModel.setTypeName(dcaeResponse.getTypeName());\r
}\r
if (oldTypeId == null || !cldsModel.getEvent().getActionCd().equalsIgnoreCase(CldsEvent.ACTION_DISTRIBUTE)\r
- || cldsModel.getEvent().getActionCd().equalsIgnoreCase(CldsEvent.ACTION_SUBMITDCAE)) {\r
+ || cldsModel.getEvent().getActionCd().equalsIgnoreCase(CldsEvent.ACTION_SUBMITDCAE)) {\r
CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), userId, dcaeEvent.getCldsActionCd(),\r
- CldsEvent.ACTION_STATE_RECEIVED, null);\r
+ CldsEvent.ACTION_STATE_RECEIVED, null);\r
}\r
cldsModel.save(cldsDao, userId);\r
} else {\r
}\r
\r
private DcaeInventoryResponse getItemsFromDcaeInventoryResponse(String responseStr)\r
- throws ParseException, IOException {\r
+ throws ParseException, IOException {\r
JSONParser parser = new JSONParser();\r
Object obj0 = parser.parse(responseStr);\r
JSONObject jsonObj = (JSONObject) obj0;\r
JSONArray itemsArray = (JSONArray) jsonObj.get("items");\r
JSONObject dcaeServiceType0 = (JSONObject) itemsArray.get(0);\r
return JacksonUtils.getObjectMapperInstance().readValue(dcaeServiceType0.toString(),\r
- DcaeInventoryResponse.class);\r
+ DcaeInventoryResponse.class);\r
}\r
\r
/**\r
* DO a query to DCAE to get some Information.\r
- * \r
+ *\r
* @param artifactName\r
- * The artifact Name\r
+ * The artifact Name\r
* @param serviceUuid\r
- * The service UUID\r
+ * The service UUID\r
* @param resourceUuid\r
- * The resource UUID\r
+ * The resource UUID\r
* @return The DCAE inventory for the artifact in DcaeInventoryResponse\r
* @throws IOException\r
- * In case of issues with the stream\r
+ * In case of issues with the stream\r
* @throws ParseException\r
- * In case of issues with the Json parsing\r
+ * In case of issues with the Json parsing\r
*/\r
public DcaeInventoryResponse getDcaeInformation(String artifactName, String serviceUuid, String resourceUuid)\r
- throws IOException, ParseException, InterruptedException {\r
+ throws IOException, ParseException, InterruptedException {\r
Date startTime = new Date();\r
LoggingUtils.setTargetContext("DCAE", "getDcaeInformation");\r
String queryString = "?asdcResourceId=" + resourceUuid + "&asdcServiceId=" + serviceUuid + "&typeName="\r
- + artifactName;\r
+ + artifactName;\r
String fullUrl = refProp.getStringValue(DCAE_INVENTORY_URL) + "/dcae-service-types" + queryString;\r
logger.info("Dcae Inventory Service full url - " + fullUrl);\r
DcaeInventoryResponse response = queryDcaeInventory(fullUrl);\r
}\r
\r
private DcaeInventoryResponse queryDcaeInventory(String fullUrl)\r
- throws IOException, InterruptedException, ParseException {\r
+ throws IOException, InterruptedException, ParseException {\r
int retryInterval = 0;\r
int retryLimit = 1;\r
if (refProp.getStringValue(DCAE_INVENTORY_RETRY_LIMIT) != null) {\r
return getItemsFromDcaeInventoryResponse(response);\r
}\r
logger.info(\r
- "Dcae inventory totalCount returned is 0, so waiting " + retryInterval + "ms before retrying ...");\r
+ "Dcae inventory totalCount returned is 0, so waiting " + retryInterval + "ms before retrying ...");\r
// wait for a while and try to connect to DCAE again\r
Thread.sleep(retryInterval);\r
}\r
logger.warn("Dcae inventory totalCount returned is still 0, after " + retryLimit + " attempts, returning NULL");\r
return null;\r
}\r
-\r
- /**\r
- * Inserts a new DCAEServiceType or updates an existing instance. If the\r
- * typeName is same second time(already exists) then the\r
- * DCAEServiceTypeRequest is updated\r
- * \r
- * @param blueprintTemplate\r
- * blueprint content\r
- * @param owner\r
- * owner of the data\r
- * @param typeName\r
- * The type/artifact Name\r
- * @param typeVersion\r
- * type version\r
- * @param asdcServiceId\r
- * The service UUID\r
- * @param asdcResourceId\r
- * The vf UUID\r
- * @return The DCAE inventory type id\r
- */\r
- public String createupdateDCAEServiceType(String blueprintTemplate, String owner, String typeName, int typeVersion,\r
- String asdcServiceId, String asdcResourceId) {\r
- Date startTime = new Date();\r
- LoggingUtils.setTargetContext("DCAE", "createDCAEServiceType");\r
- String typeId = null;\r
- try {\r
- ObjectNode dcaeServiceTypeRequest = JacksonUtils.getObjectMapperInstance().createObjectNode();\r
- dcaeServiceTypeRequest.put("blueprintTemplate", blueprintTemplate);\r
- dcaeServiceTypeRequest.put("owner", owner);\r
- dcaeServiceTypeRequest.put("typeName", typeName);\r
- dcaeServiceTypeRequest.put("typeVersion", typeVersion);\r
- dcaeServiceTypeRequest.put("asdcServiceId", asdcServiceId);\r
- dcaeServiceTypeRequest.put("asdcResourceId", asdcResourceId);\r
- String apiBodyString = dcaeServiceTypeRequest.toString();\r
- logger.info("Dcae api Body String - " + apiBodyString);\r
- String url = refProp.getStringValue(DCAE_INVENTORY_URL) + "/dcae-service-types";\r
- String responseStr = dcaeHttpConnectionManager.doDcaeHttpQuery(url, "POST", apiBodyString,\r
- "application/json");\r
- // If the DCAEServiceTypeRequest is created successfully it will\r
- // return a json object responce containing a node for newly created\r
- // "typeId"\r
- // The newly generated DCAEServiceTypeRequest can then be accessed\r
- // via URL: https://<DCAE_INVENTORY_URL>/dcae-service-types/<typeId>\r
- JSONParser parser = new JSONParser();\r
- Object obj0 = parser.parse(responseStr);\r
- JSONObject jsonObj = (JSONObject) obj0;\r
- typeId = (String) jsonObj.get("typeId"); // need to save this\r
- // as\r
- // service_type_id\r
- // in model table\r
- } catch (IOException | ParseException e) {\r
- logger.error("Exception occurred during createupdateDCAEServiceType Operation with DCAE", e);\r
- throw new BadRequestException("Exception occurred during createupdateDCAEServiceType Operation with DCAE",\r
- e);\r
- } finally {\r
- if (typeId != null) {\r
- LoggingUtils.setResponseContext("0", "Create update DCAE ServiceType success",\r
- this.getClass().getName());\r
- } else {\r
- LoggingUtils.setResponseContext("900", "Create update DCAE ServiceType failed",\r
- this.getClass().getName());\r
- LoggingUtils.setErrorContext("900", "Create update DCAE ServiceType error");\r
- }\r
- LoggingUtils.setTimeContext(startTime, new Date());\r
- metricsLogger.info("createupdateDCAEServiceType complete");\r
- }\r
- return typeId;\r
- }\r
-\r
- /**\r
- * Method to delete blueprint from dcae inventory if it's exists.\r
- * \r
- * @param typeName\r
- * @param serviceUuid\r
- * @param resourceUuid\r
- * @throws InterruptedException\r
- */\r
- public void deleteDCAEServiceType(String typeName, String serviceUuid, String resourceUuid)\r
- throws InterruptedException {\r
- Date startTime = new Date();\r
- LoggingUtils.setTargetContext("DCAE", "deleteDCAEServiceType");\r
- boolean result = false;\r
- try {\r
- DcaeInventoryResponse inventoryResponse = getDcaeInformation(typeName, serviceUuid, resourceUuid);\r
- if (inventoryResponse != null && inventoryResponse.getTypeId() != null) {\r
- String fullUrl = refProp.getStringValue(DCAE_INVENTORY_URL) + "/dcae-service-types/"\r
- + inventoryResponse.getTypeId();\r
- dcaeHttpConnectionManager.doDcaeHttpQuery(fullUrl, "DELETE", null, null);\r
- }\r
- result = true;\r
- } catch (IOException | ParseException e) {\r
- logger.error("Exception occurred during deleteDCAEServiceType Operation with DCAE", e);\r
- throw new BadRequestException("Exception occurred during deleteDCAEServiceType Operation with DCAE", e);\r
- } finally {\r
- if (result) {\r
- LoggingUtils.setResponseContext("0", "Delete DCAE ServiceType success", this.getClass().getName());\r
- } else {\r
- LoggingUtils.setResponseContext("900", "Delete DCAE ServiceType failed", this.getClass().getName());\r
- LoggingUtils.setErrorContext("900", "Delete DCAE ServiceType error");\r
- }\r
- LoggingUtils.setTimeContext(startTime, new Date());\r
- metricsLogger.info("deleteDCAEServiceType completed");\r
- }\r
- }\r
}\r
* ============LICENSE_END============================================\r
* Modifications copyright (c) 2018 Nokia\r
* ===================================================================\r
- * \r
+ *\r
*/\r
\r
package org.onap.clamp.clds.client.req.sdc;\r
import com.fasterxml.jackson.databind.node.TextNode;\r
\r
import java.io.BufferedReader;\r
-import java.io.DataOutputStream;\r
import java.io.IOException;\r
import java.io.InputStream;\r
import java.io.InputStreamReader;\r
import java.util.Iterator;\r
import java.util.List;\r
\r
-import javax.ws.rs.BadRequestException;\r
-\r
import org.apache.commons.codec.DecoderException;\r
-import org.apache.commons.codec.digest.DigestUtils;\r
import org.apache.commons.csv.CSVFormat;\r
import org.apache.commons.csv.CSVRecord;\r
import org.apache.commons.io.IOUtils;\r
import org.onap.clamp.clds.model.CldsVfData;\r
import org.onap.clamp.clds.model.CldsVfKPIData;\r
import org.onap.clamp.clds.model.CldsVfcData;\r
-import org.onap.clamp.clds.model.properties.Global;\r
-import org.onap.clamp.clds.model.properties.ModelProperties;\r
-import org.onap.clamp.clds.model.sdc.SdcArtifact;\r
import org.onap.clamp.clds.model.sdc.SdcResource;\r
import org.onap.clamp.clds.model.sdc.SdcResourceBasicInfo;\r
import org.onap.clamp.clds.model.sdc.SdcServiceDetail;\r
\r
private static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcCatalogServices.class);\r
private static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();\r
- private static final String RESOURCE_VF_TYPE = "VF";\r
- private static final String RESOURCE_VFC_TYPE = "VFC";\r
- private static final String RESOURCE_CVFC_TYPE = "CVFC";\r
- private static final String SDC_REQUESTID_PROPERTY_NAME = "sdc.header.requestId";\r
- private static final String SDC_METADATA_URL_PREFIX = "/metadata";\r
- private static final String SDC_INSTANCE_ID_PROPERTY_NAME = "sdc.InstanceID";\r
- private static final String SDC_CATALOG_URL_PROPERTY_NAME = "sdc.catalog.url";\r
- private static final String SDC_SERVICE_URL_PROPERTY_NAME = "sdc.serviceUrl";\r
- private static final String SDC_INSTANCE_ID_CLAMP = "CLAMP-Tool";\r
- private static final String RESOURCE_URL_PREFIX = "resources";\r
- private static final LoggingUtils utils = new LoggingUtils (logger);\r
+ public static final String RESOURCE_VF_TYPE = "VF";\r
+ public static final String RESOURCE_VFC_TYPE = "VFC";\r
+ public static final String RESOURCE_CVFC_TYPE = "CVFC";\r
+ public static final String SDC_REQUESTID_PROPERTY_NAME = "sdc.header.requestId";\r
+ public static final String SDC_METADATA_URL_PREFIX = "/metadata";\r
+ public static final String SDC_INSTANCE_ID_PROPERTY_NAME = "sdc.InstanceID";\r
+ public static final String SDC_CATALOG_URL_PROPERTY_NAME = "sdc.catalog.url";\r
+ public static final String SDC_SERVICE_URL_PROPERTY_NAME = "sdc.serviceUrl";\r
+ public static final String SDC_INSTANCE_ID_CLAMP = "CLAMP-Tool";\r
+ public static final String RESOURCE_URL_PREFIX = "resources";\r
+ private static final LoggingUtils utils = new LoggingUtils(logger);\r
@Autowired\r
private ClampProperties refProp;\r
\r
*\r
* @return The String with Basic Auth and password\r
* @throws GeneralSecurityException\r
- * In case of issue when decryting the SDC password\r
+ * In case of issue when decryting the SDC password\r
* @throws DecoderException\r
- * In case of issues with the decoding of the HexString message\r
+ * In case of issues with the decoding of the HexString message\r
*/\r
- private String getSdcBasicAuth() throws GeneralSecurityException, DecoderException {\r
+ public String getSdcBasicAuth() throws GeneralSecurityException, DecoderException {\r
String sdcId = refProp.getStringValue("sdc.serviceUsername");\r
String sdcPw = refProp.getStringValue("sdc.servicePassword");\r
String password = CryptoUtils.decrypt(sdcPw);\r
}\r
\r
/**\r
- * This method get the SDC services Information with the corresponding\r
- * Service UUID.\r
- * \r
+ * This method get the SDC services Information with the corresponding Service\r
+ * UUID.\r
+ *\r
* @param uuid\r
- * The service UUID\r
+ * The service UUID\r
* @return A Json String with all the service list\r
* @throws GeneralSecurityException\r
- * In case of issue when decryting the SDC password\r
+ * In case of issue when decryting the SDC password\r
* @throws DecoderException\r
- * In case of issues with the decoding of the Hex String\r
+ * In case of issues with the decoding of the Hex String\r
*/\r
public String getSdcServicesInformation(String uuid) throws GeneralSecurityException, DecoderException {\r
Date startTime = new Date();\r
}\r
URL urlObj = new URL(url);\r
HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
- conn = utils.invoke(conn,"SDC", "getSdcServicesInformation");\r
+ conn = utils.invoke(conn, "SDC", "getSdcServicesInformation");\r
conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), SDC_INSTANCE_ID_CLAMP);\r
conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);\r
conn.setRequestProperty(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8");\r
\r
/**\r
* To remove duplicate serviceUUIDs from sdc services List.\r
- * \r
+ *\r
* @param rawCldsSdcServiceList\r
- * A list of CldsSdcServiceInfo\r
+ * A list of CldsSdcServiceInfo\r
* @return A list of CldsSdcServiceInfo without duplicate service UUID\r
*/\r
public List<SdcServiceInfo> removeDuplicateServices(List<SdcServiceInfo> rawCldsSdcServiceList) {\r
\r
/**\r
* To remove duplicate serviceUUIDs from sdc resources List.\r
- * \r
+ *\r
* @param rawCldsSdcResourceList\r
* @return List of CldsSdcResource\r
*/\r
\r
/**\r
* To remove duplicate basic resources with same resourceUUIDs.\r
- * \r
+ *\r
* @param rawCldsSdcResourceListBasicList\r
* @return List of CldsSdcResourceBasicInfo\r
*/\r
public List<SdcResourceBasicInfo> removeDuplicateSdcResourceBasicInfo(\r
- List<SdcResourceBasicInfo> rawCldsSdcResourceListBasicList) {\r
+ List<SdcResourceBasicInfo> rawCldsSdcResourceListBasicList) {\r
List<SdcResourceBasicInfo> cldsSdcResourceBasicInfoList = new ArrayList<>();\r
if (rawCldsSdcResourceListBasicList != null && !rawCldsSdcResourceListBasicList.isEmpty()) {\r
// sort list\r
}\r
// add the last in the list\r
cldsSdcResourceBasicInfoList\r
- .add(rawCldsSdcResourceListBasicList.get(rawCldsSdcResourceListBasicList.size() - 1));\r
+ .add(rawCldsSdcResourceListBasicList.get(rawCldsSdcResourceListBasicList.size() - 1));\r
}\r
return cldsSdcResourceBasicInfoList;\r
}\r
\r
/**\r
* To get ServiceUUID by using serviceInvariantUUID.\r
- * \r
+ *\r
* @param invariantId\r
- * The invariant ID\r
+ * The invariant ID\r
* @return The service UUID\r
* @throws GeneralSecurityException\r
- * In case of issue when decryting the SDC password\r
+ * In case of issue when decryting the SDC password\r
* @throws DecoderException\r
- * In case of issues with the decoding of the Hex String\r
+ * In case of issues with the decoding of the Hex String\r
*/\r
public String getServiceUuidFromServiceInvariantId(String invariantId)\r
- throws GeneralSecurityException, DecoderException {\r
+ throws GeneralSecurityException, DecoderException {\r
String serviceUuid = "";\r
String responseStr = getSdcServicesInformation(null);\r
List<SdcServiceInfo> rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr);\r
if (cldsSdcServicesList != null && !cldsSdcServicesList.isEmpty()) {\r
for (SdcServiceInfo currCldsSdcServiceInfo : cldsSdcServicesList) {\r
if (currCldsSdcServiceInfo != null && currCldsSdcServiceInfo.getInvariantUUID() != null\r
- && currCldsSdcServiceInfo.getInvariantUUID().equalsIgnoreCase(invariantId)) {\r
+ && currCldsSdcServiceInfo.getInvariantUUID().equalsIgnoreCase(invariantId)) {\r
serviceUuid = currCldsSdcServiceInfo.getUuid();\r
break;\r
}\r
\r
/**\r
* To get CldsAsdsServiceInfo class by parsing json string.\r
- * \r
+ *\r
* @param jsonStr\r
- * The Json string that must be decoded\r
- * @return The list of CldsSdcServiceInfo, if there is a failure it return\r
- * an empty list\r
+ * The Json string that must be decoded\r
+ * @return The list of CldsSdcServiceInfo, if there is a failure it return an\r
+ * empty list\r
*/\r
private List<SdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) {\r
if (StringUtils.isBlank(jsonStr)) {\r
}\r
try {\r
return JacksonUtils.getObjectMapperInstance().readValue(jsonStr, JacksonUtils.getObjectMapperInstance()\r
- .getTypeFactory().constructCollectionType(List.class, SdcServiceInfo.class));\r
+ .getTypeFactory().constructCollectionType(List.class, SdcServiceInfo.class));\r
} catch (IOException e) {\r
logger.error("Error when attempting to decode the JSON containing CldsSdcServiceInfo", e);\r
return new ArrayList<>();\r
* To get List of CldsSdcResourceBasicInfo class by parsing json string.\r
*\r
* @param jsonStr\r
- * The JSOn string that must be decoded\r
- * @return The list of CldsSdcResourceBasicInfo, an empty list in case of\r
- * issues\r
+ * The JSOn string that must be decoded\r
+ * @return The list of CldsSdcResourceBasicInfo, an empty list in case of issues\r
*/\r
private List<SdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) {\r
if (StringUtils.isBlank(jsonStr)) {\r
}\r
try {\r
return JacksonUtils.getObjectMapperInstance().readValue(jsonStr, JacksonUtils.getObjectMapperInstance()\r
- .getTypeFactory().constructCollectionType(List.class, SdcResourceBasicInfo.class));\r
+ .getTypeFactory().constructCollectionType(List.class, SdcResourceBasicInfo.class));\r
} catch (IOException e) {\r
logger.error("Exception occurred when attempting to decode the list of CldsSdcResourceBasicInfo JSON", e);\r
return new ArrayList<>();\r
\r
/**\r
* To get CldsSdcServiceDetail by parsing json string.\r
- * \r
+ *\r
* @param jsonStr\r
* @return\r
*/\r
}\r
}\r
\r
- // upload artifact to sdc based on serviceUUID and resource name on url\r
- private String uploadArtifactToSdc(ModelProperties prop, String userid, String url, String formattedSdcReq) {\r
- // Verify whether it is triggered by Validation Test button from UI\r
- if (prop.isTestOnly()) {\r
- return "sdc artifact upload not executed for test action";\r
- }\r
- try {\r
- logger.info("userid=" + userid);\r
- byte[] postData = formattedSdcReq.getBytes(StandardCharsets.UTF_8);\r
- int postDataLength = postData.length;\r
- HttpURLConnection conn = getSdcHttpUrlConnection(userid, postDataLength, url, formattedSdcReq);\r
- conn = utils.invoke(conn,"SDC", "uploadArtifact");\r
- try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {\r
- wr.write(postData);\r
- }\r
- boolean requestFailed = true;\r
- int responseCode = conn.getResponseCode();\r
- logger.info("responseCode=" + responseCode);\r
- if (responseCode == 200) {\r
- requestFailed = false;\r
- }\r
- String responseStr = getResponse(conn);\r
- if (responseStr != null && requestFailed) {\r
- logger.error("requestFailed - responseStr=" + responseStr);\r
- utils.invokeReturn();\r
- throw new BadRequestException(responseStr);\r
- }\r
- utils.invokeReturn();\r
- return responseStr;\r
- } catch (IOException 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
-\r
- private HttpURLConnection getSdcHttpUrlConnection(String userid, int postDataLength, String url, String content) {\r
- try {\r
- logger.info("userid=" + userid);\r
- String basicAuth = getSdcBasicAuth();\r
- String sdcXonapInstanceId = refProp.getStringValue("sdc.sdcX-InstanceID");\r
- URL urlObj = new URL(url);\r
- HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
- conn.setDoOutput(true);\r
- conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), sdcXonapInstanceId);\r
- conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);\r
- conn.setRequestProperty(HttpHeaders.CONTENT_TYPE, "application/json");\r
- conn.setRequestProperty(HttpHeaders.CONTENT_MD5,\r
- Base64.getEncoder().encodeToString(DigestUtils.md5Hex(content).getBytes("UTF-8")));\r
- conn.setRequestProperty("USER_ID", userid);\r
- conn.setRequestMethod("POST");\r
- conn.setRequestProperty("charset", "utf-8");\r
- conn.setRequestProperty(HttpHeaders.CONTENT_LENGTH, Integer.toString(postDataLength));\r
- conn.setUseCaches(false);\r
- conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME), LoggingUtils.getRequestId());\r
- return conn;\r
- } catch (IOException e) {\r
- logger.error("Exception when attempting to open connection with SDC", e);\r
- throw new SdcCommunicationException("Exception when attempting to open connection with SDC", e);\r
- } catch (DecoderException e) {\r
- logger.error("Exception when attempting to decode the Hex string", e);\r
- throw new SdcCommunicationException("Exception when attempting to decode the Hex string", e);\r
- } catch (GeneralSecurityException e) {\r
- logger.error("Exception when attempting to decrypt the encrypted password", e);\r
- throw new SdcCommunicationException("Exception when attempting to decrypt the encrypted password", e);\r
- }\r
- }\r
-\r
- private String getResponse(HttpURLConnection conn) {\r
+ public String getResponse(HttpURLConnection conn) {\r
try (InputStream is = getInputStream(conn)) {\r
try (BufferedReader in = new BufferedReader(new InputStreamReader(is))) {\r
return IOUtils.toString(in);\r
\r
/**\r
* Check if the SDC Info in cache has expired.\r
- * \r
+ *\r
* @param cldsServiceData\r
- * The object representing the service data\r
+ * The object representing the service data\r
* @return boolean flag\r
* @throws GeneralSecurityException\r
- * In case of issues with the decryting the encrypted password\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
+ * In case of issues with the decoding of the Hex String\r
*/\r
public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData)\r
- throws GeneralSecurityException, DecoderException {\r
+ throws GeneralSecurityException, DecoderException {\r
if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {\r
String cachedServiceUuid = cldsServiceData.getServiceUUID();\r
String latestServiceUuid = getServiceUuidFromServiceInvariantId(cldsServiceData.getServiceInvariantUUID());\r
String configuredMaxAge = refProp.getStringValue("clds.service.cache.invalidate.after.seconds");\r
if (configuredMaxAge == null) {\r
logger.warn(\r
- "clds.service.cache.invalidate.after.seconds NOT set in clds-reference.properties file, taking 60s as default");\r
+ "clds.service.cache.invalidate.after.seconds NOT set in clds-reference.properties file, taking 60s as default");\r
configuredMaxAge = "60";\r
}\r
return (!cachedServiceUuid.equalsIgnoreCase(latestServiceUuid)) || (cldsServiceData.getAgeOfRecord() != null\r
- && cldsServiceData.getAgeOfRecord() > Long.parseLong(configuredMaxAge));\r
+ && cldsServiceData.getAgeOfRecord() > Long.parseLong(configuredMaxAge));\r
} else {\r
return true;\r
}\r
}\r
\r
/**\r
- * Get the Service Data with Alarm Conditions for a given\r
- * invariantServiceUuid.\r
- * \r
+ * Get the Service Data with Alarm Conditions for a given invariantServiceUuid.\r
+ *\r
* @param invariantServiceUuid\r
* @return The CldsServiceData\r
* @throws GeneralSecurityException\r
- * In case of issues with the decryting the encrypted password\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
+ * In case of issues with the decoding of the Hex String\r
*/\r
public CldsServiceData getCldsServiceDataWithAlarmConditions(String invariantServiceUuid)\r
- throws GeneralSecurityException, DecoderException {\r
+ throws GeneralSecurityException, DecoderException {\r
String url = refProp.getStringValue(SDC_SERVICE_URL_PROPERTY_NAME);\r
String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);\r
String serviceUuid = getServiceUuidFromServiceInvariantId(invariantServiceUuid);\r
SdcServiceDetail cldsSdcServiceDetail;\r
try {\r
cldsSdcServiceDetail = JacksonUtils.getObjectMapperInstance().readValue(responseStr,\r
- SdcServiceDetail.class);\r
+ SdcServiceDetail.class);\r
} catch (IOException e) {\r
logger.error("Exception when decoding the CldsServiceData JSON from SDC", e);\r
throw new SdcCommunicationException("Exception when decoding the CldsServiceData JSON from SDC", e);\r
cldsServiceData.setServiceUUID(cldsSdcServiceDetail.getUuid());\r
cldsServiceData.setServiceInvariantUUID(cldsSdcServiceDetail.getInvariantUUID());\r
List<SdcResource> cldsSdcResourceList = removeDuplicateSdcResourceInstances(\r
- cldsSdcServiceDetail.getResources());\r
+ cldsSdcServiceDetail.getResources());\r
if (cldsSdcResourceList != null && !cldsSdcResourceList.isEmpty()) {\r
List<CldsVfData> cldsVfDataList = new ArrayList<>();\r
for (SdcResource currCldsSdcResource : cldsSdcResourceList) {\r
if (currCldsSdcResource != null && currCldsSdcResource.getResoucreType() != null\r
- && "VF".equalsIgnoreCase(currCldsSdcResource.getResoucreType())) {\r
+ && "VF".equalsIgnoreCase(currCldsSdcResource.getResoucreType())) {\r
CldsVfData currCldsVfData = new CldsVfData();\r
currCldsVfData.setVfName(currCldsSdcResource.getResourceInstanceName());\r
currCldsVfData.setVfInvariantResourceUUID(currCldsSdcResource.getResourceInvariantUUID());\r
}\r
\r
private void getAllVfcForVfList(List<CldsVfData> cldsVfDataList, String catalogUrl)\r
- throws GeneralSecurityException {\r
+ throws GeneralSecurityException {\r
// todo : refact this..\r
if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {\r
List<SdcResourceBasicInfo> allVfResources = getAllSdcVForVfcResourcesBasedOnResourceType(RESOURCE_VF_TYPE);\r
List<SdcResourceBasicInfo> allVfcResources = getAllSdcVForVfcResourcesBasedOnResourceType(\r
- RESOURCE_VFC_TYPE);\r
+ RESOURCE_VFC_TYPE);\r
allVfcResources.addAll(getAllSdcVForVfcResourcesBasedOnResourceType(RESOURCE_CVFC_TYPE));\r
for (CldsVfData currCldsVfData : cldsVfDataList) {\r
if (currCldsVfData != null && currCldsVfData.getVfInvariantResourceUUID() != null) {\r
String resourceUuid = getResourceUuidFromResourceInvariantUuid(\r
- currCldsVfData.getVfInvariantResourceUUID(), allVfResources);\r
+ currCldsVfData.getVfInvariantResourceUUID(), allVfResources);\r
if (resourceUuid != null) {\r
String vfResourceUuidUrl = catalogUrl + RESOURCE_URL_PREFIX + "/" + resourceUuid\r
- + SDC_METADATA_URL_PREFIX;\r
+ + SDC_METADATA_URL_PREFIX;\r
String vfResponse = getCldsServicesOrResourcesBasedOnURL(vfResourceUuidUrl);\r
if (vfResponse != null) {\r
// Below 2 line are to get the KPI(field path) data\r
// alarm conditions from artifact\r
for (CldsVfcData currCldsVfcData : vfcDataListFromVfResponse) {\r
if (currCldsVfcData != null\r
- && currCldsVfcData.getVfcInvariantResourceUUID() != null) {\r
+ && currCldsVfcData.getVfcInvariantResourceUUID() != null) {\r
String resourceVfcUuid = getResourceUuidFromResourceInvariantUuid(\r
- currCldsVfcData.getVfcInvariantResourceUUID(), allVfcResources);\r
+ currCldsVfcData.getVfcInvariantResourceUUID(), allVfcResources);\r
if (resourceVfcUuid != null) {\r
String vfcResourceUuidUrl = catalogUrl + RESOURCE_URL_PREFIX + "/"\r
- + resourceVfcUuid + SDC_METADATA_URL_PREFIX;\r
+ + resourceVfcUuid + SDC_METADATA_URL_PREFIX;\r
String vfcResponse = getCldsServicesOrResourcesBasedOnURL(\r
- vfcResourceUuidUrl);\r
+ vfcResourceUuidUrl);\r
if (vfcResponse != null) {\r
List<CldsAlarmCondition> alarmCondtionsFromVfc = getAlarmCondtionsFromVfc(\r
- vfcResponse);\r
+ vfcResponse);\r
currCldsVfcData.setCldsAlarmConditions(alarmCondtionsFromVfc);\r
}\r
} else {\r
logger.info("No resourceVFC UUID found for given invariantID:"\r
- + currCldsVfcData.getVfcInvariantResourceUUID());\r
+ + currCldsVfcData.getVfcInvariantResourceUUID());\r
}\r
}\r
}\r
}\r
} else {\r
logger.info("No resourceUUID found for given invariantREsourceUUID:"\r
- + currCldsVfData.getVfInvariantResourceUUID());\r
+ + currCldsVfData.getVfInvariantResourceUUID());\r
}\r
}\r
}\r
return null;\r
}\r
if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3))\r
- || StringUtils.isBlank(record.get(5))) {\r
+ || StringUtils.isBlank(record.get(5))) {\r
logger.debug("Invalid csv field path Record,one of column is having blank value : " + record);\r
return null;\r
}\r
return;\r
}\r
if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3))\r
- || StringUtils.isBlank(record.get(4))) {\r
+ || StringUtils.isBlank(record.get(4))) {\r
logger.debug("invalid csv alarm Record,one of column is having blank value : " + record);\r
return;\r
}\r
}\r
\r
/**\r
- * Service to services/resources/artifacts from sdc.Pass alarmConditions as\r
- * true to get alarm conditons from artifact url and else it is false\r
- * \r
+ * Service to services/resources/artifacts from sdc.Pass alarmConditions as true\r
+ * to get alarm conditons from artifact url and else it is false\r
+ *\r
* @param url\r
- * The URL to trigger\r
+ * The URL to trigger\r
* @return The String containing the payload\r
*/\r
public String getCldsServicesOrResourcesBasedOnURL(String url) {\r
String urlReworked = removeUnwantedBracesFromString(url);\r
URL urlObj = new URL(urlReworked);\r
HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
- conn = utils.invoke(conn,"SDC", "getSdcResources");\r
+ conn = utils.invoke(conn, "SDC", "getSdcResources");\r
String basicAuth = getSdcBasicAuth();\r
conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), SDC_INSTANCE_ID_CLAMP);\r
conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);\r
* @param cldsServiceData\r
* @return\r
* @throws IOException\r
- * In case of issues during the parsing of the Global Properties\r
+ * In case of issues during the parsing of the Global Properties\r
*/\r
public String createPropertiesObjectByUUID(CldsServiceData cldsServiceData) throws IOException {\r
String totalPropsStr;\r
byIdObjectNode.putPOJO("byVfc", vfcResourceUuidObjectNode);\r
// To create byAlarmCondition with alarmConditionKey\r
List<CldsAlarmCondition> allAlarmConditions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData,\r
- "alarmCondition");\r
+ "alarmCondition");\r
ObjectNode alarmCondObjectNodeByAlarmKey = createAlarmCondObjectNodeByAlarmKey(allAlarmConditions);\r
byIdObjectNode.putPOJO("byAlarmCondition", alarmCondObjectNodeByAlarmKey);\r
// To create byAlertDescription with AlertDescription\r
List<CldsAlarmCondition> allAlertDescriptions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData,\r
- "alertDescription");\r
+ "alertDescription");\r
ObjectNode alertDescObjectNodeByAlert = createAlarmCondObjectNodeByAlarmKey(allAlertDescriptions);\r
byIdObjectNode.putPOJO("byAlertDescription", alertDescObjectNodeByAlert);\r
globalPropsJson.putPOJO("shared", byIdObjectNode);\r
\r
/**\r
* Method to get alarm conditions/alert description from Service Data.\r
- * \r
+ *\r
* @param cldsServiceData\r
- * CldsServiceData the Service Data to analyze\r
+ * CldsServiceData the Service Data to analyze\r
* @param eventName\r
- * The String event name that will be used to filter the alarm\r
- * list\r
+ * The String event name that will be used to filter the alarm list\r
* @return The list of CldsAlarmCondition for the event name specified\r
*/\r
public List<CldsAlarmCondition> getAllAlarmConditionsFromCldsServiceData(CldsServiceData cldsServiceData,\r
- String eventName) {\r
+ String eventName) {\r
List<CldsAlarmCondition> alarmCondList = new ArrayList<>();\r
if (cldsServiceData != null && cldsServiceData.getCldsVfs() != null\r
- && !cldsServiceData.getCldsVfs().isEmpty()) {\r
+ && !cldsServiceData.getCldsVfs().isEmpty()) {\r
for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {\r
alarmCondList.addAll(getAllAlarmConditionsFromCldsVfData(currCldsVfData, eventName));\r
}\r
\r
/**\r
* Method to get alarm conditions/alert description from VF Data.\r
- * \r
+ *\r
* @param currCldsVfData\r
- * The Vf Data to analyze\r
+ * The Vf Data to analyze\r
* @param eventName\r
- * The String event name that will be used to filter the alarm\r
- * list\r
+ * The String event name that will be used to filter the alarm list\r
* @return The list of CldsAlarmCondition for the event name specified\r
*/\r
private List<CldsAlarmCondition> getAllAlarmConditionsFromCldsVfData(CldsVfData currCldsVfData, String eventName) {\r
\r
/**\r
* Method to get alarm conditions/alert description from VFC Data.\r
- * \r
+ *\r
* @param currCldsVfcData\r
- * The VfC Data to analyze\r
+ * The VfC Data to analyze\r
* @param eventName\r
- * The String event name that will be used to filter the alarm\r
- * list\r
+ * The String event name that will be used to filter the alarm list\r
* @return The list of CldsAlarmCondition for the event name specified\r
*/\r
private List<CldsAlarmCondition> getAllAlarmConditionsFromCldsVfcData(CldsVfcData currCldsVfcData,\r
- String eventName) {\r
+ String eventName) {\r
List<CldsAlarmCondition> alarmCondList = new ArrayList<>();\r
if (currCldsVfcData != null && currCldsVfcData.getCldsAlarmConditions() != null\r
- && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {\r
+ && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {\r
for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) {\r
if (currCldsAlarmCondition != null\r
- && currCldsAlarmCondition.getEventName().equalsIgnoreCase(eventName)) {\r
+ && currCldsAlarmCondition.getEventName().equalsIgnoreCase(eventName)) {\r
alarmCondList.add(currCldsAlarmCondition);\r
}\r
}\r
}\r
\r
private void createKpiObjectNodeByVfUuid(ObjectNode vfResourceUuidObjectNode,\r
- List<CldsVfKPIData> cldsVfKpiDataList) {\r
+ List<CldsVfKPIData> cldsVfKpiDataList) {\r
ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
if (cldsVfKpiDataList != null && !cldsVfKpiDataList.isEmpty()) {\r
for (CldsVfKPIData currCldsVfKpiData : cldsVfKpiDataList) {\r
ObjectNode fieldPathObjectNode = mapper.createObjectNode();\r
ObjectNode nfNamingCodeNode = mapper.createObjectNode();\r
fieldPathObjectNode.put(currCldsVfKpiData.getFieldPathValue(),\r
- currCldsVfKpiData.getFieldPathValue());\r
+ currCldsVfKpiData.getFieldPathValue());\r
nfNamingCodeNode.put(currCldsVfKpiData.getNfNamingValue(), currCldsVfKpiData.getNfNamingValue());\r
thresholdNameObjectNode.putPOJO("fieldPath", fieldPathObjectNode);\r
thresholdNameObjectNode.putPOJO("nfNamingCode", nfNamingCodeNode);\r
}\r
\r
private void createAlarmCondObjectNodeByVfcUuid(ObjectNode vfcResourceUuidObjectNode,\r
- List<CldsVfcData> cldsVfcDataList) {\r
+ List<CldsVfcData> cldsVfcDataList) {\r
ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
ObjectNode vfcObjectNode = mapper.createObjectNode();\r
ObjectNode alarmCondNode = mapper.createObjectNode();\r
for (CldsVfcData currCldsVfcData : cldsVfcDataList) {\r
if (currCldsVfcData != null) {\r
if (currCldsVfcData.getCldsAlarmConditions() != null\r
- && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {\r
+ && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {\r
for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) {\r
if ("alarmCondition".equalsIgnoreCase(currCldsAlarmCondition.getEventName())) {\r
alarmCondNode.put(currCldsAlarmCondition.getAlarmConditionKey(),\r
- currCldsAlarmCondition.getAlarmConditionKey());\r
+ currCldsAlarmCondition.getAlarmConditionKey());\r
} else {\r
alertDescNode.put(currCldsAlarmCondition.getAlarmConditionKey(),\r
- currCldsAlarmCondition.getAlarmConditionKey());\r
+ currCldsAlarmCondition.getAlarmConditionKey());\r
}\r
}\r
}\r
\r
/**\r
* Method to create vfc and kpi nodes inside vf node\r
- * \r
+ *\r
* @param mapper\r
* @param cldsVfDataList\r
* @return\r
if (currCldsVfData.getCldsVfcs() != null && !currCldsVfData.getCldsVfcs().isEmpty()) {\r
for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) {\r
if (currCldsVfcData.getCldsAlarmConditions() != null\r
- && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {\r
+ && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {\r
vfcUuidNode.put(currCldsVfcData.getVfcInvariantResourceUUID(),\r
- currCldsVfcData.getVfcName());\r
+ currCldsVfcData.getVfcName());\r
}\r
}\r
} else {\r
if (currCldsVfData.getCldsKPIList() != null && !currCldsVfData.getCldsKPIList().isEmpty()) {\r
for (CldsVfKPIData currCldsVfKPIData : currCldsVfData.getCldsKPIList()) {\r
kpiObjectNode.put(currCldsVfKPIData.getThresholdValue(),\r
- currCldsVfKPIData.getThresholdValue());\r
+ currCldsVfKPIData.getThresholdValue());\r
}\r
} else {\r
kpiObjectNode.put("", "");\r
return vfUuidObjectNode;\r
}\r
\r
- /**\r
- * This method searches the equivalent artifact UUID for a specific\r
- * artifactName in a SdcServiceDetail.\r
- * \r
- * @param cldsSdcServiceDetail\r
- * The SdcServiceDetail that will be analyzed\r
- * @param artifactName\r
- * The artifact name that will be searched\r
- * @return The artifact UUID found\r
- */\r
- public String getArtifactIdIfArtifactAlreadyExists(SdcServiceDetail cldsSdcServiceDetail, String artifactName) {\r
- String artifactUuid = null;\r
- boolean artifactExists = false;\r
- if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null\r
- && !cldsSdcServiceDetail.getResources().isEmpty()) {\r
- for (SdcResource currCldsSdcResource : cldsSdcServiceDetail.getResources()) {\r
- if (artifactExists) {\r
- break;\r
- }\r
- if (currCldsSdcResource != null && currCldsSdcResource.getArtifacts() != null\r
- && !currCldsSdcResource.getArtifacts().isEmpty()) {\r
- for (SdcArtifact currCldsSdcArtifact : currCldsSdcResource.getArtifacts()) {\r
- if (currCldsSdcArtifact != null && currCldsSdcArtifact.getArtifactName() != null\r
- && currCldsSdcArtifact.getArtifactName().equalsIgnoreCase(artifactName)) {\r
- artifactUuid = currCldsSdcArtifact.getArtifactUUID();\r
- artifactExists = true;\r
- break;\r
- }\r
- }\r
- }\r
- }\r
- }\r
- return artifactUuid;\r
- }\r
-\r
// To get all sdc VF/VFC Resources basic info.\r
private List<SdcResourceBasicInfo> getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType) {\r
String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);\r
}\r
\r
private String getResourceUuidFromResourceInvariantUuid(String resourceInvariantUuid,\r
- List<SdcResourceBasicInfo> resourceInfoList) {\r
+ List<SdcResourceBasicInfo> resourceInfoList) {\r
String resourceUuid = null;\r
if (resourceInfoList != null && !resourceInfoList.isEmpty()) {\r
for (SdcResourceBasicInfo currResource : resourceInfoList) {\r
if (currResource != null && currResource.getInvariantUUID() != null && currResource.getUuid() != null\r
- && currResource.getInvariantUUID().equalsIgnoreCase(resourceInvariantUuid)) {\r
+ && currResource.getInvariantUUID().equalsIgnoreCase(resourceInvariantUuid)) {\r
resourceUuid = currResource.getUuid();\r
break;\r
}\r
}\r
return resourceUuid;\r
}\r
-\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
}\r