SO catalogDB updates
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / onap / so / bpmn / common / scripts / CatalogDbUtils.groovy
index 7511a85..91f73e2 100644 (file)
@@ -22,6 +22,7 @@
 
 package org.onap.so.bpmn.common.scripts
 
+import org.onap.so.logger.LoggingAnchor
 import org.apache.commons.lang3.StringUtils
 import org.camunda.bpm.engine.delegate.DelegateExecution
 import org.json.JSONArray
@@ -31,11 +32,12 @@ import org.onap.so.bpmn.core.UrnPropertiesReader
 import org.onap.so.bpmn.core.json.JsonUtils
 import org.onap.so.client.HttpClient
 import org.onap.so.client.HttpClientFactory
+import org.onap.logging.filter.base.ErrorCode
 import org.onap.so.logger.MessageEnum
-import org.onap.so.logger.MsoLogger
+
 import org.slf4j.Logger
 import org.slf4j.LoggerFactory
-import org.onap.so.utils.TargetEntity
+import org.onap.logging.filter.base.ONAPComponents;
 import org.springframework.web.util.UriUtils
 
 import javax.ws.rs.core.MediaType
@@ -50,13 +52,13 @@ class CatalogDbUtils {
     private static final Logger logger = LoggerFactory.getLogger( CatalogDbUtils.class);
 
        private HttpClientFactory httpClientFactory
-       private MsoUtils msoUtils
-       private  JsonUtils jsonUtils
+       private MsoUtils utils
+       private JsonUtils jsonUtils
        static private String defaultDbAdapterVersion = "v2"
 
-       CatalogDbUtils(HttpClientFactory httpClientFactory, MsoUtils msoUtils, JsonUtils jsonUtils) {
+       CatalogDbUtils(HttpClientFactory httpClientFactory, JsonUtils jsonUtils) {
                this.httpClientFactory = httpClientFactory
-               this.msoUtils = msoUtils
+               this.utils = new MsoUtils()
                this.jsonUtils = jsonUtils
        }
 
@@ -79,9 +81,9 @@ class CatalogDbUtils {
 
                }
                catch (Exception e) {
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                       "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(),
-                                       MsoLogger.ErrorCode.UnknownError.getValue(), e.message);
+                       logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                       "Exception in Querying Catalog DB", "BPMN",
+                                       ErrorCode.UnknownError.getValue(), e.message);
                        throw e
                }
 
@@ -104,7 +106,7 @@ class CatalogDbUtils {
                        }
                }
                catch (Exception e) {
-                       msoUtils.log("ERROR", "Exception in Querying Catalog DB: " + e.message)
+                       logger.error("Exception in Querying Catalog DB: " + e.message)
                        throw e
                }
 
@@ -117,9 +119,9 @@ class CatalogDbUtils {
                        return getResponseFromCatalogDb(execution, endPoint)
                }
                catch (Exception e) {
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                       "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(),
-                                       MsoLogger.ErrorCode.UnknownError.getValue(), e.message);
+                       logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                       "Exception in Querying Catalog DB", "BPMN",
+                                       ErrorCode.UnknownError.getValue(), e.message);
                        throw e
                }
        }
@@ -141,9 +143,9 @@ class CatalogDbUtils {
 
                }
                catch (Exception e) {
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                       "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(),
-                                       MsoLogger.ErrorCode.UnknownError.getValue(), e.message);
+                       logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                       "Exception in Querying Catalog DB", "BPMN",
+                                       ErrorCode.UnknownError.getValue(), e.message);
                        throw e
                }
 
@@ -167,9 +169,9 @@ class CatalogDbUtils {
 
                }
                catch (Exception e) {
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                       "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(),
-                                       MsoLogger.ErrorCode.UnknownError.getValue(), e.message);
+                       logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                       "Exception in Querying Catalog DB", "BPMN",
+                                       ErrorCode.UnknownError.getValue(), e.message);
                        throw e
                }
 
@@ -217,9 +219,9 @@ class CatalogDbUtils {
                        logger.debug("Returning networks JSON: " + modelInfosString)
 
                } catch (Exception e) {
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                       "Exception in parsing Catalog DB Response", "BPMN", MsoLogger.getServiceName(),
-                                       MsoLogger.ErrorCode.UnknownError.getValue(), e.message);
+                       logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                       "Exception in parsing Catalog DB Response", "BPMN",
+                                       ErrorCode.UnknownError.getValue(), e.message);
                }
 
                return modelInfos
@@ -296,9 +298,9 @@ class CatalogDbUtils {
                        logger.debug("Returning vnfs JSON: " + modelInfosString)
 
                } catch (Exception e) {
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                       "Exception in parsing Catalog DB Response", "BPMN", MsoLogger.getServiceName(),
-                                       MsoLogger.ErrorCode.UnknownError.getValue(), e.message);
+                       logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                       "Exception in parsing Catalog DB Response", "BPMN",
+                                       ErrorCode.UnknownError.getValue(), e.message);
                }
 
                return modelInfos
@@ -350,9 +352,9 @@ class CatalogDbUtils {
                        logger.debug("Returning allottedResources JSON: " + modelInfosString)
 
                } catch (Exception e) {
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                       "Exception in parsing Catalog DB Response", "BPMN", MsoLogger.getServiceName(),
-                                       MsoLogger.ErrorCode.UnknownError.getValue(), e.message);
+                       logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                       "Exception in parsing Catalog DB Response", "BPMN",
+                                       ErrorCode.UnknownError.getValue(), e.message);
                }
 
                return modelInfos
@@ -379,9 +381,9 @@ class CatalogDbUtils {
                        logger.debug("Returning serviceResources JSON: " + serviceResourcesObject.toString())
 
                } catch (Exception e) {
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                       "Exception in parsing Catalog DB Response", "BPMN", MsoLogger.getServiceName(),
-                                       MsoLogger.ErrorCode.UnknownError.getValue(), e.message);
+                       logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                       "Exception in parsing Catalog DB Response", "BPMN",
+                                       ErrorCode.UnknownError.getValue(), e.message);
                }
 
                return serviceResourcesObject
@@ -427,9 +429,9 @@ class CatalogDbUtils {
                        modelJson.put("modelInfo", modelInfo)
                }
                catch (Exception e) {
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                       "Exception while parsing model information", "BPMN", MsoLogger.getServiceName(),
-                                       MsoLogger.ErrorCode.UnknownError.getValue(), e.message);
+                       logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                       "Exception while parsing model information", "BPMN",
+                                       ErrorCode.UnknownError.getValue(), e.message);
                }
                return modelInfo
        }
@@ -440,8 +442,7 @@ class CatalogDbUtils {
                        String catalogDbEndpoint = UrnPropertiesReader.getVariable("mso.catalog.db.endpoint",execution)
                        String queryEndpoint = catalogDbEndpoint + "/" + defaultDbAdapterVersion + endPoint
                        def responseData = ''
-                       HttpClient client = httpClientFactory.newJsonClient(new URL(queryEndpoint), TargetEntity.CATALOG_DB)
-                       client.addAdditionalHeader(ONAPLogConstants.Headers.REQUEST_ID, UUID.randomUUID().toString())
+                       HttpClient client = httpClientFactory.newJsonClient(new URL(queryEndpoint), ONAPComponents.CATALOG_DB)
                        client.addAdditionalHeader('X-FromAppId', "BPMN")
                        client.addAdditionalHeader('Accept', MediaType.APPLICATION_JSON)
                        String basicAuthCred = execution.getVariable("BasicAuthHeaderValueDB")
@@ -487,7 +488,7 @@ class CatalogDbUtils {
                        }
                }
                catch (Exception e) {
-                       msoUtils.log("ERROR", "Exception in Querying Catalog DB: " + e.message)
+                       logger.error("Exception in Querying Catalog DB: " + e.message)
                        throw e
                }
 
@@ -499,13 +500,13 @@ class CatalogDbUtils {
                String encodedString = null
                try {
                        String basicAuthValueDB = UrnPropertiesReader.getVariable("mso.adapters.db.auth", execution)
-                       msoUtils.log("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB)
+                       logger.debug("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB)
 
-                       encodedString = msoUtils.getBasicAuth(basicAuthValueDB, UrnPropertiesReader.getVariable("mso.msoKey", execution))
+                       encodedString = utils.getBasicAuth(basicAuthValueDB, UrnPropertiesReader.getVariable("mso.msoKey", execution))
                        execution.setVariable("BasicAuthHeaderValueDB",encodedString)
                } catch (IOException ex) {
                        String dataErrorMessage = " Unable to encode Catalog DB user/password string - " + ex.getMessage()
-                       msoUtils.log("ERROR", dataErrorMessage)
+                       logger.error(dataErrorMessage)
                }
                return encodedString
        }