Fix for timeout error when logging >1MB data 11/79111/5
authorJoss Armstrong <joss.armstrong@ericsson.com>
Mon, 25 Feb 2019 14:35:44 +0000 (14:35 +0000)
committerTakamune Cho <takamune.cho@att.com>
Tue, 26 Feb 2019 17:50:35 +0000 (17:50 +0000)
Potentially large logs moved to TRACE level, INFO level
logs limited in size and related tests updated

Issue-ID: APPC-1489
Change-Id: I9ea85e64380479d835da03ed2af3e4ab96ece67e
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/ConfigComponentAdaptor.java
appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/ConfigComponentAdaptorTest.java
appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/writer/FileWriterNode.java
appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/writer/TestFileWriterNode.java
appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/GraphExecutor.java
appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/executorImpl/GraphExecutorTest.java

index 14c8c41..60c0324 100644 (file)
@@ -6,7 +6,7 @@
  * =============================================================================
  * Modifications Copyright (C) 2018-2019 IBM.
  * =============================================================================
- * Modifications Copyright (C) 2018 Ericsson
+ * Modifications Copyright (C) 2018-2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 
 public class ConfigComponentAdaptor implements SvcLogicAdaptor {
 
-private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigComponentAdaptor.class);
+private static EELFLogger log = EELFManager.getInstance().getLogger(ConfigComponentAdaptor.class);
 DebugLog debugLog = new DebugLog();
 private String configUrl = null;
 private String configUser = null;
@@ -916,8 +916,19 @@ private HttpResponse sendXmlRequest(String xmlRequest, String url, String user,
         WebResource webResource = client.resource(url);
 
         log.info("SENDING...............");
-        log.info(xmlRequest);
-
+        if (log.isTraceEnabled()) {
+            log.trace(xmlRequest);
+        }
+        else {
+            if(xmlRequest.length() > 255 ) {
+                log.info(xmlRequest.substring(0, 255));
+                log.info("\n...\n" + xmlRequest.length() +
+                        " characters in request, turn on TRACE logging to log entire request");
+            }
+            else {
+                log.info(xmlRequest);
+            }
+        }
         String authString = user + ":" + password;
         byte[] authEncBytes = Base64.encode(authString);
         String authStringEnc = new String(authEncBytes);
@@ -1015,6 +1026,21 @@ private String trimResponse(String response) {
     }
     runningConfig = sb.toString();
 
+    if (log.isTraceEnabled()) {
+        log.trace("ConfigComponentAdaptor:RunningConfig after trimResponse : " + runningConfig);
+    }
+    else {
+        if (runningConfig.length() > 255) {
+            log.info("ConfigComponentAdaptor:RunningConfig after trimResponse : " +
+                runningConfig.substring(0, 255));
+            log.info("\n...\n" + runningConfig.length() +
+                    " characters in config, turn on TRACE logging to log entire config");
+        }
+        else {
+            log.info("ConfigComponentAdaptor:RunningConfig after trimResponse : " +
+                    runningConfig);
+        }
+    }
     log.info("ConfigComponentAdaptor:RunningConfig after trimResponse : " + runningConfig);
     return runningConfig;
 }
index 8e8c156..a947f19 100644 (file)
@@ -8,7 +8,7 @@
  * =============================================================================
  * Modifications Copyright (C) 2018-2019 IBM.
  * =============================================================================
- * Modifications Copyright (C) 2018 Ericsson
+ * Modifications Copyright (C) 2018-2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -256,6 +256,24 @@ public class ConfigComponentAdaptorTest {
         assertEquals(ConfigStatus.SUCCESS, cca.configure(key, parameters, ctx));
     }
 
+    @Test
+    public void testXmlGetrunningconfigLongResponse() throws TimedOutException, IOException {
+        Properties props = null;
+        ConfigComponentAdaptor cca = Mockito.spy(new ConfigComponentAdaptor(props));
+        Mockito.doReturn("<configuration xmlns=\"\n<data>\nData line 1\nData line 2\nData line 3\nData line 4\n"
+                + "Data line 5\nData line 6\nData line 7\nData line 8\nData line 9\n Data line 10\n"
+                + "Data line 11\nData line 12\nData line 13\nData line 14\nData line 15\n"
+                + "Data line 16\nData line 17\nData line 18\nData line 19\nData line 20</data>\n</configuration>")
+                .when(mockWrapper)
+                .receiveUntil(Mockito.anyString(), Mockito.anyInt(), Mockito.anyString());
+        Mockito.doReturn(mockWrapper).when(cca).getSshJcraftWrapper();
+        String key = "xml-getrunningconfig";
+        Map<String, String> parameters = new HashMap<>();
+        loadSshParameters(parameters);
+        SvcLogicContext ctx = new SvcLogicContext();
+        assertEquals(ConfigStatus.SUCCESS, cca.configure(key, parameters, ctx));
+    }
+
     @Test
     public void testXmlGetrunningconfigExceptionFlow() throws TimedOutException, IOException {
         Properties props = new Properties();
index 7e0ff01..850efb5 100644 (file)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -40,7 +42,20 @@ public class FileWriterNode implements SvcLogicJavaPlugin {
 
     public void writeFile(Map<String, String> inParams, SvcLogicContext ctx)
         throws SvcLogicException {
-        log.info("Received writeFile call with params : " + inParams);
+        if (log.isTraceEnabled()) {
+            log.trace("Received writeFile call with params : " + inParams);
+        }
+        else {
+            String mapString = inParams.toString();
+            if (mapString.length() > 255) {
+                log.info("Received writeFile call with params : " + mapString.substring(0, 255));
+                log.info("\n...\n" + mapString.length() +
+                        " characters in parameters map, turn on TRACE logging to log entire parameter map");
+            }
+            else {
+                log.info("Received writeFile call with params : " + mapString);
+            }
+        }
         String responsePrefix = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX);
         try {
             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
index 8bbc854..44830ad 100644 (file)
@@ -7,6 +7,8 @@
  * Copyright (C) 2017 Amdocs
  * =============================================================================
  * Modfication Copyright (C) 2018 IBM.
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -49,12 +51,31 @@ public class TestFileWriterNode {
         assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,
                 ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
     }
-    
-    @Test(expected=SvcLogicException.class)
+
+    @Test
+    public void writeFileForLongParameters() throws Exception {
+        FileWriterNode FileWriterNode = new FileWriterNode();
+        Map<String, String> inParams = new HashMap<String, String>();
+        inParams.put(ConfigGeneratorConstant.INPUT_PARAM_FILE_NAME,
+                "src/test/resources/writer/testcvaas.json");
+        inParams.put(ConfigGeneratorConstant.INPUT_PARAM_REQUEST_DATA,
+                "{'name':'Name','role':'admin'}");
+        inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
+        inParams.put("TEST", "Lorem ipsum dolor sit amet, prompta mediocrem quo an, eos odio esse pertinax an."
+                + " Vis timeam suscipiantur no, eos ex vidisse appareat. Vel ipsum verterem in, qui eu cetero"
+                + " vituperatoribus. Semper insolens contentiones mei ea, vitae persius suavitate no quo, prompta"
+                + " impedit minimum cu sed. Everti disputationi id eam, essent.");
+        SvcLogicContext ctx = new SvcLogicContext();
+        FileWriterNode.writeFile(inParams, ctx);
+        assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,
+                ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
+    }
+
+    @Test(expected = SvcLogicException.class)
     public void testWriteFileForEmptyParams() throws Exception {
         FileWriterNode FileWriterNode = new FileWriterNode();
         Map<String, String> inParams = new HashMap<String, String>();
         SvcLogicContext ctx = new SvcLogicContext();
         FileWriterNode.writeFile(inParams, ctx);
-      }
+    }
 }
index 261d64e..10fc319 100644 (file)
@@ -92,7 +92,7 @@ public class GraphExecutor implements FlowExecutorInterface {
             String parmName = (String) key;
             String parmValue = ctx.getAttribute(parmName);
             parms.put(parmName, parmValue);
-            log.info(fn + "Setting Key= " + parmName + "and Value = " + parmValue);
+            log.info(fn + "Setting Key= " + parmName + " and Value = " + parmValue);
 
         }
         Properties returnParams =
@@ -105,7 +105,20 @@ public class GraphExecutor implements FlowExecutorInterface {
 
         while (e.hasMoreElements()) {
             String key = (String) e.nextElement();
-            log.info("NEW KEY =  " + key + " -- " + returnParams.getProperty(key));
+            String property = returnParams.getProperty(key);
+            if (log.isTraceEnabled()) {
+                log.trace("NEW KEY = " + key + " -- " + property);
+            }
+            else {
+                if (property.length() > 255) {
+                    log.info("NEW KEY = " + key + " -- " + property.substring(0, 255));
+                    log.info("\n...\n" + property.length() +
+                            " characters in property, turn on TRACE logging to log entire property");
+                }
+                else {
+                    log.info("NEW KEY = " + key + " -- " + property);
+                }
+            }
 
             ctx.setAttribute(key, returnParams.getProperty(key));
         }
index d7a4ce2..50cb24d 100644 (file)
@@ -103,6 +103,25 @@ public class GraphExecutorTest {
         assertNull(graphExecutor.execute(transaction, ctx));
     }
 
+    @Test
+    public void testExecuteWithLongPropertyValue() throws Exception {
+        GraphExecutor graphExecutor = new GraphExecutor();
+        Whitebox.setInternalState(GraphExecutor.class, "log", log);
+        Properties properties = new Properties();
+        properties.put("TEST", "Lorem ipsum dolor sit amet, prompta mediocrem quo an, eos odio esse pertinax an."
+                + " Vis timeam suscipiantur no, eos ex vidisse appareat. Vel ipsum verterem in, qui eu cetero"
+                + " vituperatoribus. Semper insolens contentiones mei ea, vitae persius suavitate no quo, prompta"
+                + " impedit minimum cu sed. Everti disputationi id eam, essent.");
+        Transaction transaction = Mockito.spy(new Transaction());
+        transaction.setExecutionRPC("EXECUTION_RPC");
+        transaction.setPayload("PAYLOAD");
+        SvcLogicContext ctx = new SvcLogicContext();
+        ctx.setAttribute("TEST", "TEST");
+        Mockito.when(svcLogic.execute(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
+                Mockito.anyString(), Mockito.any(Properties.class))).thenReturn(properties);
+        assertNull(graphExecutor.execute(transaction, ctx));
+    }
+
     @Test
     public void testExecuteFailure() throws Exception {
         GraphExecutor graphExecutor = new GraphExecutor();