From 0500d5dbb363e74983d758288f1ac53ae763683d Mon Sep 17 00:00:00 2001 From: "Masal, Sushil (sm588m)" Date: Sun, 13 Aug 2017 19:10:02 +0530 Subject: Create and store Dependency model from Tosca Updated asdc listerner bundle to create dependency model from tosca artifact reveived from SDC.This dependency model will be in JSON format and will be stored to ASDC_ARTIFACT table as new artifact. Also ASDC_REFERENCE table will be updated to with new artifact details. This commit also include bug fix for MDSALStore to handle all http code for successful rest calls Issue ID: APPC-32 Change-Id: Iaef6cdee67475917968a4bcdec131cd1bc4c4f41 Signed-off-by: Masal, Sushil (sm588m) --- .../org/openecomp/appc/mdsal/impl/Constants.java | 3 +-- .../appc/mdsal/operation/ConfigOperation.java | 23 ++++++++++++---------- .../operation/ConfigOperationRequestFormatter.java | 3 +-- 3 files changed, 15 insertions(+), 14 deletions(-) (limited to 'appc-dg/appc-dg-shared/appc-dg-mdsal-store') diff --git a/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/impl/Constants.java b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/impl/Constants.java index 711ec1d4e..949f6ffa3 100644 --- a/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/impl/Constants.java +++ b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/impl/Constants.java @@ -26,7 +26,7 @@ package org.openecomp.appc.mdsal.impl; /** * This class contains the definitions of all constant values used in the appc-dg-mdsal-store * These properties are used for creating osgi bundle zip file. It also defines contents for Blueprint.xml file of bundle -*/ + */ public class Constants { private Constants(){} @@ -79,7 +79,6 @@ public class Constants { * Base URL for config actions exposed by RESTCONF API */ - public static final String CONFIG_URL = "https://localhost:8443/restconf/config"; public static final String CONFIG_URL_DEFAULT = "https://localhost:8443/restconf/config"; public static final String CONFIG_URL_PROPERTY = "appc.LCM.provider.url"; diff --git a/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/operation/ConfigOperation.java b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/operation/ConfigOperation.java index dbb82468c..5c5a1bb34 100644 --- a/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/operation/ConfigOperation.java +++ b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/operation/ConfigOperation.java @@ -67,7 +67,7 @@ import org.apache.commons.io.IOUtils; /** * Provides method to store configuration to MD-SAL store. It also exposes doPut operation which can be used to invoke REST Put operation. -*/ + */ public class ConfigOperation { private static final EELFLogger LOG = EELFManager.getInstance().getLogger(ConfigOperation.class); @@ -100,7 +100,7 @@ public class ConfigOperation { int httpCode; String respBody ; try { - String path = requestFormatter.buildPath(url, module, containerName, subModules); + String path = requestFormatter.buildPath(module, containerName, subModules); LOG.debug("Configuration Path : " + path); URL serviceUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(), path); HttpResponse response = doPut(serviceUrl , configJson); @@ -111,22 +111,25 @@ public class ConfigOperation { throw new APPCException(e); } - if (httpCode != 200 ) { + if (httpCode < 200 || httpCode >= 300 ) { try { + LOG.debug("Config operation Error response code: " + httpCode); ArrayList errorMessage = new ArrayList<>(); JsonNode responseJson = toJsonNodeFromJsonString(respBody); if(responseJson!=null && responseJson.get("errors")!=null) { JsonNode errors = responseJson.get("errors").get("error"); - for (Iterator i = errors.elements();i.hasNext();){ - JsonNode error = i.next(); - errorMessage.add(error.get("error-message").textValue()); - } + for (Iterator i = errors.elements();i.hasNext();){ + JsonNode error = i.next(); + errorMessage.add(error.get("error-message").textValue()); + } } - throw new APPCException("Failed to load config JSON to MD SAL store. Error Message:" + errorMessage.toString()); + throw new APPCException("Failed to load config JSON to MD SAL store. Error code:" + httpCode +" Error Message:" + errorMessage.toString()); } catch (Exception e) { - LOG.error("Error while loading config JSON to MD SAL store. "+e.getMessage(), e); - throw new APPCException("Error while loading config JSON to MD SAL store. "+ e.getMessage(),e); + LOG.error("Error while loading config JSON to MD SAL store. Error code:" + httpCode +" Error Message:" + e.getMessage(), e); + throw new APPCException("Error while loading config JSON to MD SAL store. Error code:" + httpCode +" Error Message:" + e.getMessage(),e); } + }else{ + LOG.debug("Config operation successful. Response code: " + httpCode); } } diff --git a/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/operation/ConfigOperationRequestFormatter.java b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/operation/ConfigOperationRequestFormatter.java index 94e120faf..26e7669e2 100644 --- a/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/operation/ConfigOperationRequestFormatter.java +++ b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/operation/ConfigOperationRequestFormatter.java @@ -34,13 +34,12 @@ import java.net.URL; public class ConfigOperationRequestFormatter { /** * Build a request url path for config actions - * @param url - base url * @param module - yang module name * @param containerName - yang container name * @param subModules - sub module /container names as string in varargs ( String ) format * @return - resultant path in String format */ - public String buildPath(URL url,String module, String containerName , String... subModules ) { + public String buildPath(String module, String containerName , String... subModules ) { StringBuilder path = new StringBuilder( Constants.CONFIG_PATH + Constants.URL_BACKSLASH + module + ":"+containerName + Constants.URL_BACKSLASH); if(subModules.length >0){ -- cgit 1.2.3-korg