adding a ServerLogClient class and using it to read BE logs
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/22ac8e25 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/22ac8e25 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/22ac8e25 Branch: refs/heads/stratos-4.1.x Commit: 22ac8e2585348f1b1293e3dfd474a1c266a93c36 Parents: 28e65f2 Author: Isuru Haththotuwa <[email protected]> Authored: Fri Nov 20 17:06:35 2015 +0530 Committer: Isuru Haththotuwa <[email protected]> Committed: Sat Nov 21 15:58:12 2015 +0530 ---------------------------------------------------------------------- .../integration/common/ServerLogClient.java | 101 ++++++++++++++++ .../common/StratosTestServerManager.java | 16 --- .../tests/StratosIntegrationTest.java | 2 - .../tests/other/IaasProviderAttributeTest.java | 116 ++++++++++--------- .../cartridge-iaasprovider-attribute-test.json | 4 - .../src/test/resources/common/log4j.properties | 19 ++- 6 files changed, 176 insertions(+), 82 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/22ac8e25/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/ServerLogClient.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/ServerLogClient.java b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/ServerLogClient.java new file mode 100644 index 0000000..2ac6ce9 --- /dev/null +++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/ServerLogClient.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.integration.common; + +import org.apache.axis2.AxisFault; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.automation.engine.context.AutomationContext; +import org.wso2.carbon.integration.common.admin.client.LogViewerClient; +import org.wso2.carbon.integration.common.utils.exceptions.AutomationUtilException; + +import javax.xml.xpath.XPathExpressionException; + +public class ServerLogClient { + + private static final Log log = LogFactory.getLog(ServerLogClient.class); + private LogViewerClient logViewerClient; + private AutomationContext automationContext; + + public ServerLogClient () throws AutomationUtilException { + createAutomationContext(); + createlogViewerClient(getBackEndUrl(), getUsername(), getPassword()); + } + + public ServerLogClient (String backEndUrl, String username, String password) throws + AutomationUtilException { + createlogViewerClient(backEndUrl, username, password); + } + + private void createlogViewerClient(String backEndUrl, String username, String password) throws AutomationUtilException { + try { + logViewerClient = new LogViewerClient(backEndUrl, username, password); + } catch (AxisFault e) { + String errorMsg = "Error in creating LogViewerClient"; + log.error(errorMsg, e); + throw new AutomationUtilException(errorMsg, e); + } + } + + private void createAutomationContext() throws AutomationUtilException { + try { + automationContext = new AutomationContext(); + } catch (XPathExpressionException e) { + String errorMsg = "Error in creating AutomationContext"; + log.error(errorMsg, e); + throw new AutomationUtilException(errorMsg, e); + } + } + + private String getBackEndUrl () throws AutomationUtilException { + try { + return automationContext.getContextUrls().getBackEndUrl(); + } catch (XPathExpressionException e) { + String errorMsg = "Error in getting beck end URL"; + log.error(errorMsg, e); + throw new AutomationUtilException(errorMsg, e); + } + } + + private String getUsername () throws AutomationUtilException { + try { + return automationContext.getSuperTenant().getTenantAdmin().getUserName(); + } catch (XPathExpressionException e) { + String errorMsg = "Error in getting super tenant username"; + log.error(errorMsg, e); + throw new AutomationUtilException(errorMsg, e); + } + } + + private String getPassword () throws AutomationUtilException { + try { + return automationContext.getSuperTenant().getTenantAdmin().getPassword(); + } catch (XPathExpressionException e) { + String errorMsg = "Error in getting super tenant password"; + log.error(errorMsg, e); + throw new AutomationUtilException(errorMsg, e); + } + } + + + public LogViewerClient getLogViewerClient () { + return logViewerClient; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/22ac8e25/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/StratosTestServerManager.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/StratosTestServerManager.java b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/StratosTestServerManager.java index e5bb7f8..d2db900 100644 --- a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/StratosTestServerManager.java +++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/StratosTestServerManager.java @@ -263,14 +263,6 @@ public class StratosTestServerManager extends TestServerManager { public void setWebAppURLHttps(String webAppURLHttps) { this.webAppURLHttps = webAppURLHttps; } - - public ServerLogReader getLogReader () { - return ((StratosServerManager)carbonServer).getInputLogStreamReader(); - } - - public ServerLogReader getErrorLogReader () { - return ((StratosServerManager)carbonServer).getErrorStreamReader(); - } } // TODO: get rid of this class once startup script issue is fixed in automation engine @@ -628,12 +620,4 @@ class StratosServerManager extends CarbonServerManager { } } - - public ServerLogReader getInputLogStreamReader () { - return inputStreamHandler; - } - - public ServerLogReader getErrorStreamReader () { - return errorStreamHandler; - } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/22ac8e25/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/StratosIntegrationTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/StratosIntegrationTest.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/StratosIntegrationTest.java index 3983835..5b397ab 100644 --- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/StratosIntegrationTest.java +++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/StratosIntegrationTest.java @@ -39,7 +39,6 @@ public class StratosIntegrationTest { protected MockIaasApiClient mockIaasApiClient; public static final int GLOBAL_TEST_TIMEOUT = 5 * 60 * 1000; // 5 mins public static final int APPLICATION_TEST_TIMEOUT = 20 * 60 * 1000; // 20 mins - protected StratosTestServerManager stratosTestServerManager; public StratosIntegrationTest() { try { @@ -54,7 +53,6 @@ public class StratosIntegrationTest { stratosSecuredBackendURL = StratosServerExtension.getStratosTestServerManager().getWebAppURLHttps(); restClient = new RestClient(stratosBackendURL, stratosSecuredBackendURL, adminUsername, adminPassword); mockIaasApiClient = new MockIaasApiClient(stratosBackendURL + "/mock-iaas/api"); - stratosTestServerManager = StratosServerExtension.getStratosTestServerManager(); // initialize topology handler before running the tests TopologyHandler.getInstance(); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/stratos/blob/22ac8e25/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/other/IaasProviderAttributeTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/other/IaasProviderAttributeTest.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/other/IaasProviderAttributeTest.java index 70b089b..1f7b042 100644 --- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/other/IaasProviderAttributeTest.java +++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/other/IaasProviderAttributeTest.java @@ -25,10 +25,12 @@ import org.apache.stratos.common.beans.application.ApplicationBean; import org.apache.stratos.common.beans.cartridge.CartridgeBean; import org.apache.stratos.common.beans.cartridge.IaasProviderBean; import org.apache.stratos.integration.common.RestConstants; +import org.apache.stratos.integration.common.ServerLogClient; import org.apache.stratos.integration.common.TopologyHandler; import org.apache.stratos.integration.tests.StratosIntegrationTest; import org.apache.stratos.messaging.domain.application.ApplicationStatus; import org.testng.annotations.Test; +import org.wso2.carbon.logging.view.stub.types.carbon.LogEvent; import java.util.List; @@ -50,7 +52,7 @@ public class IaasProviderAttributeTest extends StratosIntegrationTest { private static final String APPLICATION = "app-iaasprovider-attribute-test"; @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.cartridge.iaas.attributes", "all"}) - public void testIaasProviderAttributesForDefaultCartridge () throws Exception { + public void testIaasProviderAttributes () throws Exception { // add autoscaling policy log.info("Adding autoscaling policy [autoscale policy id] " + AUTOSCALING_POLICY); @@ -118,66 +120,70 @@ public class IaasProviderAttributeTest extends StratosIntegrationTest { TopologyHandler topologyHandler = TopologyHandler.getInstance(); - long time = System.currentTimeMillis() + 300000L; + log.info("Waiting for application status to become ACTIVE..."); + topologyHandler.assertApplicationStatus(applicationBean.getApplicationId(), ApplicationStatus.Active); + // create a ServerLogClientInstance and get logs boolean found = false; - while (System.currentTimeMillis() < time) { - if (!stratosTestServerManager.getLogReader().getOutput().contains("cc_property_value_1") - && stratosTestServerManager.getLogReader().getOutput().contains("cartridge_property_value_1")) { - found = true; - break; + ServerLogClient serverLogClient = new ServerLogClient(stratosSecuredBackendURL + "/services/", + adminUsername, + adminPassword); + LogEvent [] logEvents = serverLogClient.getLogViewerClient().getAllRemoteSystemLogs(); + if (logEvents.length > 0) { + for (int i = 0; i < logEvents.length; i++) { + if (!logEvents[i].getMessage().contains("cartridge_property_value_1") && + logEvents[i].getMessage().contains("cc_property_value_1")) { + found = true; + break; + } } } - assertTrue("Property 'property1' not found | value not equal to 'cartridge_property_value_1'", found); + assertTrue("Property 'property1' not found | value not equal to 'cc_property_value_1'", found); + + // undeploy application + log.info("Un-deploying the application [application id] app-iaasprovider-attribute-test"); + String resourcePathUndeploy = RestConstants.APPLICATIONS + "/app-iaasprovider-attribute-test" + + RestConstants.APPLICATIONS_UNDEPLOY; + + boolean undeployedApp = restClient.undeployEntity(resourcePathUndeploy, RestConstants + .APPLICATIONS_NAME); + assertTrue(undeployedApp); + log.info("Undeployed application 'app-iaasprovider-attribute-test'"); + + // force undeploy to make sure its undeployed + log.info("Force undeployment is going to start for the [application] app-iaasprovider-attribute-test"); + restClient.undeployEntity(RestConstants.APPLICATIONS + "/app-iaasprovider-attribute-test" + + RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS); + + boolean forceUndeployed = topologyHandler.assertApplicationUndeploy("app-iaasprovider-attribute-test"); + assertTrue(String.format("Forceful undeployment failed for the application %s", + "app-iaasprovider-attribute-test"), forceUndeployed); -// log.info("Waiting for application status to become ACTIVE..."); -// topologyHandler.assertApplicationStatus(applicationBean.getApplicationId(), -// ApplicationStatus.Active); -// -// // undeploy application -// log.info("Un-deploying the application [application id] app-iaasprovider-attribute-test"); -// String resourcePathUndeploy = RestConstants.APPLICATIONS + "/app-iaasprovider-attribute-test" + -// RestConstants.APPLICATIONS_UNDEPLOY; -// -// boolean undeployedApp = restClient.undeployEntity(resourcePathUndeploy, RestConstants -// .APPLICATIONS_NAME); -// assertTrue(undeployedApp); -// log.info("Undeployed application 'app-iaasprovider-attribute-test'"); -// -// // force undeploy to make sure its undeployed -// log.info("Force undeployment is going to start for the [application] app-iaasprovider-attribute-test"); -// restClient.undeployEntity(RestConstants.APPLICATIONS + "/app-iaasprovider-attribute-test" + -// RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS); -// -// boolean forceUndeployed = topologyHandler.assertApplicationUndeploy("app-iaasprovider-attribute-test"); -// assertTrue(String.format("Forceful undeployment failed for the application %s", -// "app-iaasprovider-attribute-test"), forceUndeployed); -// -// // update cartridge -// boolean updated = restClient.updateEntity(RESOURCES_PATH + "/cartridges/" + UPDATED_CARTRIDGE + ".json", -// RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); -// assertTrue(updated); -// log.info("Updated cartridge 'cartridge-iaasprovider-attribute-test'"); -// -// // re-deplpoy the application -// resourcePath = RestConstants.APPLICATIONS + "/app-iaasprovider-attribute-test" + -// RestConstants.APPLICATIONS_DEPLOY + "/" + APPLICATION_POLICY; -// appDeployed = restClient.deployEntity(resourcePath, RestConstants.APPLICATIONS_NAME); -// assertTrue(appDeployed); -// log.info("Re-deployed application 'app-iaasprovider-attribute-test'"); -// -// time = System.currentTimeMillis() + 300000L; -// -// found = false; -// while (System.currentTimeMillis() < time) { -// if (stratosTestServerManager.getLogReader().getOutput().contains("cartridge_property_value_1")) { -// found = true; -// break; -// } -// } -// -// assertTrue("Property 'property1' not found | value not equal to 'cartridge_property_value_1'", found); + // update cartridge + boolean updated = restClient.updateEntity(RESOURCES_PATH + "/cartridges/" + UPDATED_CARTRIDGE + ".json", + RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); + assertTrue(updated); + log.info("Updated cartridge 'cartridge-iaasprovider-attribute-test'"); + + // re-deplpoy the application + resourcePath = RestConstants.APPLICATIONS + "/app-iaasprovider-attribute-test" + + RestConstants.APPLICATIONS_DEPLOY + "/" + APPLICATION_POLICY; + appDeployed = restClient.deployEntity(resourcePath, RestConstants.APPLICATIONS_NAME); + assertTrue(appDeployed); + log.info("Re-deployed application 'app-iaasprovider-attribute-test'"); + + logEvents = serverLogClient.getLogViewerClient().getAllRemoteSystemLogs(); + if (logEvents.length > 0) { + for (int i = 0; i < logEvents.length; i++) { + if (logEvents[i].getMessage().contains("cartridge_property_value_1")) { + found = true; + break; + } + } + } + + assertTrue("Property 'property1' not found | value not equal to 'cartridge_property_value_1'", found); terminateAndRemoveAllArtifacts(); } http://git-wip-us.apache.org/repos/asf/stratos/blob/22ac8e25/products/stratos/modules/integration/test-integration/src/test/resources/cartridge-iaas-attribute-test/cartridges/cartridge-iaasprovider-attribute-test.json ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/resources/cartridge-iaas-attribute-test/cartridges/cartridge-iaasprovider-attribute-test.json b/products/stratos/modules/integration/test-integration/src/test/resources/cartridge-iaas-attribute-test/cartridges/cartridge-iaasprovider-attribute-test.json index f9f883b..f819974 100644 --- a/products/stratos/modules/integration/test-integration/src/test/resources/cartridge-iaas-attribute-test/cartridges/cartridge-iaasprovider-attribute-test.json +++ b/products/stratos/modules/integration/test-integration/src/test/resources/cartridge-iaas-attribute-test/cartridges/cartridge-iaasprovider-attribute-test.json @@ -23,10 +23,6 @@ { "name":"tag:Name", "value":"WSO2 PPaaS Default Server" - }, - { - "name":"property1", - "value":"cartridge_property_value_1" } ] } http://git-wip-us.apache.org/repos/asf/stratos/blob/22ac8e25/products/stratos/modules/integration/test-integration/src/test/resources/common/log4j.properties ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/resources/common/log4j.properties b/products/stratos/modules/integration/test-integration/src/test/resources/common/log4j.properties index b99dd63..2d49c47 100644 --- a/products/stratos/modules/integration/test-integration/src/test/resources/common/log4j.properties +++ b/products/stratos/modules/integration/test-integration/src/test/resources/common/log4j.properties @@ -115,14 +115,23 @@ log4j.appender.CARBON_CONSOLE.layout.TenantPattern=%U%@%D[%T] log4j.appender.CARBON_CONSOLE.threshold=DEBUG # CARBON_MEMORY is set to be a MemoryAppender using a PatternLayout. -log4j.appender.CARBON_MEMORY=org.wso2.carbon.logging.appenders.MemoryAppender -log4j.appender.CARBON_MEMORY.layout=org.apache.log4j.PatternLayout -log4j.appender.CARBON_MEMORY.bufferSize=200 +#log4j.appender.CARBON_MEMORY=org.wso2.carbon.logging.appenders.MemoryAppender +#log4j.appender.CARBON_MEMORY.layout=org.apache.log4j.PatternLayout +#log4j.appender.CARBON_MEMORY.bufferSize=200 # ConversionPattern will be overridden by the configuration setting in the DB #log4j.appender.CARBON_MEMORY.layout.ConversionPattern=[%d] %5p - %x %m {%c}%n -log4j.appender.CARBON_MEMORY.layout.ConversionPattern=[%d] %5p {%c} - %x %m%n -log4j.appender.CARBON_MEMORY.threshold=DEBUG +#log4j.appender.CARBON_MEMORY.layout.ConversionPattern=[%d] %5p {%c} - %x %m%n +#log4j.appender.CARBON_MEMORY.threshold=DEBUG +# CARBON_MEMORY is set to be a MemoryAppender using a PatternLayout. +log4j.appender.CARBON_MEMORY=org.wso2.carbon.logging.appender.CarbonMemoryAppender +log4j.appender.CARBON_MEMORY.bufferSize=2000 +log4j.appender.CARBON_MEMORY.layout=org.wso2.carbon.utils.logging.TenantAwarePatternLayout +# ConversionPattern will be overridden by the configuration setting in the DB +log4j.appender.CARBON_MEMORY.layout.ConversionPattern=TID: [%T] [%S] [%d] %P%5p {%c} - %x %m {%c}%n +log4j.appender.CARBON_MEMORY.layout.TenantPattern=%U%@%D [%T] [%S] +log4j.appender.CARBON_MEMORY.columnList=%T,%S,%A,%d,%c,%p,%m,%H,%I,%Stacktrace +log4j.appender.CARBON_MEMORY.threshold=DEBUG # CARBON_LOGFILE is set to be a DailyRollingFileAppender using a PatternLayout. log4j.appender.CARBON_LOGFILE=org.apache.log4j.RollingFileAppender
