From 83750c6e9d95d51d2e88c317fca296b85a33214d Mon Sep 17 00:00:00 2001 From: Vishal Mishra Date: Thu, 27 Oct 2016 02:03:32 -0700 Subject: [PATCH] Fix non default config in JBoss 7 --- .../appserver/appserverenumeration.cpp | 40 +++++++++----- .../appserver/jbossappserverinstance.cpp | 20 +++++-- .../appserver/jbossappserverinstance.h | 1 + .../appserverenumeration_test.cpp | 53 +++++++++++++++++++ .../jbossappserverinstance_test.cpp | 29 ++++++++++ 5 files changed, 126 insertions(+), 17 deletions(-) diff --git a/source/code/providers/support/appserver/appserverenumeration.cpp b/source/code/providers/support/appserver/appserverenumeration.cpp index 7b5c2f59..dc3d1cac 100644 --- a/source/code/providers/support/appserver/appserverenumeration.cpp +++ b/source/code/providers/support/appserver/appserverenumeration.cpp @@ -177,8 +177,32 @@ namespace SCXSystemLib // The Logging property is optional when running in domain mode, thus the server data directory is used configFromJBossDomainProperty = ParseOutCommandLineArg(params, "-Djboss.server.data.dir", true, false); configFromJBossStandaloneProperty = ParseOutCommandLineArg(params, "-Dlogging.configuration",true,false); - - if ( configFromDashC.length() != 0 ) + + // Give priority to JBoss 7 and wildfly as they can have non default config. + // If config from -c is checked first It would lead to incorrect install path for JBoss 7 and wildfly. + if ( configFromJBossDomainProperty.length() != 0 ) + { + // Sample domain value: /root/wildfly-8.1.0.CR2/domain/servers/server-one/data + config = configFromJBossDomainProperty; + } + else if ( configFromJBossStandaloneProperty.length() != 0 ) + { + // JBoss standalone can have non default config file (standalone-full.xml, standalone-ha.xml etc.) + // If -c argument is also present then ports should be read from that file + if ( configFromDashC.length() != 0 ) + { + // -c gives relative path of config file wrt configuration directory. + string::size_type loc = configFromJBossStandaloneProperty.find("logging.properties"); + config = configFromJBossStandaloneProperty.substr(0,loc); + config.append(configFromDashC); + } + else + { + // Sample standalone value: /root/wildfly-8.1.0.CR2/standalone/configuration/logging.properties + config = configFromJBossStandaloneProperty; + } + } + else if ( configFromDashC.length() != 0 ) { config = configFromDashC; } @@ -186,17 +210,7 @@ namespace SCXSystemLib { config = configFromJBossProperty; } - else if ( configFromJBossDomainProperty.length() != 0 ) - { - // Sample domain value: /root/wildfly-8.1.0.CR2/domain/servers/server-one/data - config = configFromJBossDomainProperty; - } - else if ( configFromJBossStandaloneProperty.length() != 0 ) - { - // Sample standalone value: /root/wildfly-8.1.0.CR2/standalone/configuration/logging.properties - config = configFromJBossStandaloneProperty; - } - else // ( configFromDashC.length() == 0 ) && ( configFromJBossProperty.length() == 0 ) + else { config = "default"; } diff --git a/source/code/providers/support/appserver/jbossappserverinstance.cpp b/source/code/providers/support/appserver/jbossappserverinstance.cpp index 54a8dbbd..31cecb01 100644 --- a/source/code/providers/support/appserver/jbossappserverinstance.cpp +++ b/source/code/providers/support/appserver/jbossappserverinstance.cpp @@ -179,8 +179,13 @@ namespace SCXSystemLib if (config.find(fJBossStandaloneStr) != std::string::npos) { - fJBossStandaloneCheck = true; - m_config = L"/standalone/configuration/"; + fJBossStandaloneCheck = true; + if(config.find(L".xml") != std::string::npos) + { + std::string::size_type loc = config.find(L"standalone/configuration/"); + m_jbossStandaloneConfigFile = config.substr(loc); + } + m_config = L"/standalone/configuration/"; } else if (config.find(fJBossDomainStr) != std::string::npos) { @@ -898,8 +903,15 @@ namespace SCXSystemLib const string cHttpName("http"); const string cHttpsName("https"); const string cPortAttributeName("port"); - - filename.Append(L"standalone/configuration/standalone.xml"); + + if(m_jbossStandaloneConfigFile.length() != 0) + { + filename.Append(m_jbossStandaloneConfigFile); + } + else + { + filename.Append(L"standalone/configuration/standalone.xml"); + } try { SCXHandle mystream = m_deps->OpenXmlPortsFile(filename.Get()); diff --git a/source/code/providers/support/appserver/jbossappserverinstance.h b/source/code/providers/support/appserver/jbossappserverinstance.h index f18c08c4..7ebe2a6d 100644 --- a/source/code/providers/support/appserver/jbossappserverinstance.h +++ b/source/code/providers/support/appserver/jbossappserverinstance.h @@ -81,6 +81,7 @@ namespace SCXSystemLib std::wstring m_serverName; std::wstring m_basePath; std::wstring m_portsBinding; + std::wstring m_jbossStandaloneConfigFile; SCXCoreLib::SCXHandle m_deps; }; diff --git a/test/code/providers/appserver_provider/appserverenumeration_test.cpp b/test/code/providers/appserver_provider/appserverenumeration_test.cpp index a993c561..02cd4646 100644 --- a/test/code/providers/appserver_provider/appserverenumeration_test.cpp +++ b/test/code/providers/appserver_provider/appserverenumeration_test.cpp @@ -251,6 +251,7 @@ class AppServerEnumeration_Test : public CPPUNIT_NS::TestFixture CPPUNIT_TEST( JBoss_Process_Good_Params_3_Running ); CPPUNIT_TEST( JBoss_Process_Good_Params_22_Running ); CPPUNIT_TEST( JBoss_Domain_Process_Good_Params ); + CPPUNIT_TEST( JBoss_Standalone_Non_Default_Config ); CPPUNIT_TEST( testReadInstancesMethodCalledAtInit ); CPPUNIT_TEST( testWriteInstancesMethodCalledAtCleanup ); CPPUNIT_TEST( Tomcat_Process_Good_Params ); @@ -886,6 +887,58 @@ public: asEnum.CleanUp(); } + + void JBoss_Standalone_Non_Default_Config() + { + SCXCoreLib::SCXHandle pal = SCXCoreLib::SCXHandle(new MockAppServerPALDependencies()); + TestSpyAppServerEnumeration asEnum(pal); + + CPPUNIT_ASSERT(asEnum.Size() == 0); + + SCXCoreLib::SCXHandle inst; + + inst = pal->CreateProcessInstance(1234, "1234"); + inst->AddParameter("/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java"); + inst->AddParameter("-D[Standalone]"); + inst->AddParameter("-XX:+UseCompressedOops"); + inst->AddParameter("-verbose:gc"); + inst->AddParameter("-Xloggc:/konsens/log/rmsvlg/as/4.2.0.2/gc.log"); + inst->AddParameter("-XX:+PrintGCDetails"); + inst->AddParameter("-server"); + inst->AddParameter("-XX:+PrintGCDateStamps"); + inst->AddParameter("-XX:+UseGCLogFileRotation"); + inst->AddParameter("-XX:NumberOfGCLogFiles=5"); + inst->AddParameter("-XX:GCLogFileSize=3M"); + inst->AddParameter("-XX:-TraceClassUnloading"); + inst->AddParameter("-Xms2048m"); + inst->AddParameter("-Xmx2048m"); + inst->AddParameter("-Dorg.jboss.boot.log.file=/konsens/log/rmsvlg/as/4.2.0.2/server.log"); + inst->AddParameter("-Dlogging.configuration=file:/konsens/app/rmsvlg/as/4.2.0.2/standalone/configuration/logging.properties"); + inst->AddParameter("-jar"); + inst->AddParameter("/konsens/app/jboss-eap-6.4/jboss-modules.jar "); + inst->AddParameter("-mp"); + inst->AddParameter("/konsens/app/jboss-eap-6.4/modules"); + inst->AddParameter("-jaxpmodule"); + inst->AddParameter("javax.xml.jaxp-provider"); + inst->AddParameter("org.jboss.as.standalone"); + inst->AddParameter("-Djboss.home.dir=/konsens/app/jboss-eap-6.4"); + inst->AddParameter("-Djboss.server.base.dir=/konsens/app/rmsvlg/as/4.2.0.2/standalone"); + inst->AddParameter("-Djboss.server.log.dir=/konsens/log/rmsvlg/as/4.2.0.2"); + inst->AddParameter("-c"); + inst->AddParameter("standalone-full.xml"); + inst->AddParameter("-b"); + inst->AddParameter("0.0.0.0"); + + asEnum.Update(false); + + CPPUNIT_ASSERT(asEnum.Size() == 1); + + std::vector >::iterator it = asEnum.Begin(); + + CPPUNIT_ASSERT_EQUAL(L"/konsens/app/jboss-eap-6.4/standalone/configuration/",(*it)->GetId()); + + asEnum.CleanUp(); + } /* * The actual reading and writing to the cache has been mocked out. diff --git a/test/code/providers/appserver_provider/jbossappserverinstance_test.cpp b/test/code/providers/appserver_provider/jbossappserverinstance_test.cpp index 8b00a47e..81c80ce8 100644 --- a/test/code/providers/appserver_provider/jbossappserverinstance_test.cpp +++ b/test/code/providers/appserver_provider/jbossappserverinstance_test.cpp @@ -808,6 +808,7 @@ class JBossAppServerInstance_Test : public CPPUNIT_NS::TestFixture CPPUNIT_TEST( testBadVersionXml ); CPPUNIT_TEST( testBadHttpPortValue ); CPPUNIT_TEST( testBadPortOffsetValue ); + CPPUNIT_TEST( testJBoss7WithNonDefaultConfig ); CPPUNIT_TEST( testPort_XMLSetTo_Junk_CommandLineSetTo_ports01 ); CPPUNIT_TEST( testPort_XMLSetTo_Port01_CommandLineSetTo_Junk ); CPPUNIT_TEST( testPort_XMLSetTo_Junk_NoCommandLineBinding ); @@ -1038,6 +1039,34 @@ class JBossAppServerInstance_Test : public CPPUNIT_NS::TestFixture CPPUNIT_ASSERT_EQUAL( L"id/standalone/configuration/standalone.xml", deps->m_xmlPortsFilename); } + + void testJBoss7WithNonDefaultConfig() + { + SCXHandle deps(new JBossAppServerInstanceTestPALDependencies()); + + deps->SetVersion5(false); + deps->SetIncludeJbossJar(false); + deps->SetHttpBinding(false); + deps->SetHttpsBinding(false); + deps->SetVersion7(true); + deps->SetNoVersionFile(true); + + deps->SetBadPortOffsetValue(false); + + SCXHandle asInstance( new JBossAppServerInstance(L"id/", L"id/standalone/configuration/standalone-full.xml", L"", deps) ); + + asInstance->Update(); + + CPPUNIT_ASSERT_EQUAL( L"id/standalone/configuration/", asInstance->GetId()); + CPPUNIT_ASSERT_EQUAL( L"id/standalone/configuration/", asInstance->GetDiskPath()); + CPPUNIT_ASSERT_EQUAL(L"JBoss", asInstance->GetType()); + CPPUNIT_ASSERT_EQUAL(L"7.0.0.Final",asInstance->GetVersion()); + CPPUNIT_ASSERT_EQUAL(L"7",asInstance->GetMajorVersion()); + CPPUNIT_ASSERT_EQUAL(L"8080", asInstance->GetHttpPort()); + CPPUNIT_ASSERT_EQUAL(L"8443", asInstance->GetHttpsPort()); + + CPPUNIT_ASSERT_EQUAL( L"id/standalone/configuration/standalone-full.xml", deps->m_xmlPortsFilename); + } // Test with XML containing bad port-offset attribute in binding socket void testJBoss7WithBadPortOffsetValueSocketBindingValue()