Skip to content

Commit f017807

Browse files
ARQ-785 Initial implementation of managed WebLogic containers.
The managed container implementation uses the startWebLogic and stopWebLogic scripts in the WebLogic domain directory to control the WLS container. Refactored the Container configuration classes. Introduced ManagedContainer and RemoteContainer classes to encapsulate operations on managed and remote WLS containers. Refactored and improved the test suite for WebLogic containers. Introduced tests for verifying- 1. JAR deployment, 2. Testable API of Arquillian-Core 1.0.2 3. Multiple deployments in a test class Segregated the others into tests to verify deployment of EARs and WARs, CDI injection, Resource and EJB injection, ArquillianResource injection of URLs and tests run at the client. Detects if the startups and shutdown script has not completed by a pre-determined timeout period, and terminates the script if necessary.
1 parent dc0d84c commit f017807

File tree

83 files changed

+4422
-323
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+4422
-323
lines changed

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,7 @@
7878
<module>wls-common</module>
7979
<module>wls-remote-10.3</module>
8080
<module>wls-remote-12.1</module>
81+
<module>wls-managed-10.3</module>
82+
<module>wls-managed-12.1</module>
8183
</modules>
8284
</project>
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2011, Red Hat Middleware LLC, and individual contributors
4+
* by the @authors tag. See the copyright.txt in the distribution for a
5+
* full listing of individual contributors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.jboss.arquillian.container.wls;
18+
19+
import org.jboss.arquillian.container.spi.ConfigurationException;
20+
21+
/**
22+
* Arquillian properties for the managed WebLogic container. Properties derived from the
23+
* {@link CommonWebLogicConfiguration} class are added to, here.
24+
*
25+
* @author Vineet Reynolds
26+
*
27+
*/
28+
public class CommonManagedWebLogicConfiguration extends CommonWebLogicConfiguration {
29+
30+
private static final String DEFAULT_WIN_STARTUP_SCRIPT = "bin\\\\startWebLogic.cmd";
31+
private static final String DEFAULT_LINUX_STARTUP_SCRIPT = "./bin/startWebLogic.sh";
32+
private static final String DEFAULT_WIN_SHUTDOWN_SCRIPT = "bin\\\\stopWebLogic.cmd";
33+
private static final String DEFAULT_LINUX_SHUTDOWN_SCRIPT = "./bin/stopWebLogic.sh";
34+
35+
private String middlewareHome = System.getenv("MW_HOME");
36+
private String domainDirectory;
37+
private String jvmOptions;
38+
private int timeout = 60;
39+
private boolean outputToConsole = false;
40+
private boolean allowConnectingToRunningServer = false;
41+
private String startServerScript;
42+
private String stopServerScript;
43+
44+
public CommonManagedWebLogicConfiguration() {
45+
super();
46+
}
47+
48+
@Override
49+
public void validate() throws ConfigurationException {
50+
Validate.directoryExists(middlewareHome, "The middlewareHome resolved to " + middlewareHome
51+
+ " and could not be located. Verify the property in arquillian.xml");
52+
Validate.directoryExists(domainDirectory, "The domainDirectory resolved to " + domainDirectory
53+
+ " and could not be located. Verify the property in arquillian.xml");
54+
if (startServerScript != null && startServerScript.length() > 0) {
55+
Validate.isValidFile(startServerScript, "The startServerScript resolved to " + startServerScript
56+
+ " and could not be located. Verify the property in arquillian.xml");
57+
} else {
58+
String os = System.getProperty("os.name").toLowerCase();
59+
if (os.startsWith("windows")) {
60+
startServerScript = DEFAULT_WIN_STARTUP_SCRIPT;
61+
} else {
62+
startServerScript = DEFAULT_LINUX_STARTUP_SCRIPT;
63+
}
64+
}
65+
if (stopServerScript != null && stopServerScript.length() > 0) {
66+
Validate.isValidFile(stopServerScript, "The stopServerScript resolved to " + stopServerScript
67+
+ " and could not be located. Verify the property in arquillian.xml");
68+
} else {
69+
String os = System.getProperty("os.name").toLowerCase();
70+
if (os.startsWith("windows")) {
71+
stopServerScript = DEFAULT_WIN_SHUTDOWN_SCRIPT;
72+
} else {
73+
stopServerScript = DEFAULT_LINUX_SHUTDOWN_SCRIPT;
74+
}
75+
}
76+
super.validate();
77+
}
78+
79+
public String getMiddlewareHome() {
80+
return middlewareHome;
81+
}
82+
83+
/**
84+
*
85+
* @param middlewareHome The directory representing the Oracle Middleware Home. Defaults to the MW_HOME environment
86+
* variable.
87+
*/
88+
public void setMiddlewareHome(String middlewareHome) {
89+
this.middlewareHome = middlewareHome;
90+
}
91+
92+
public String getDomainDirectory() {
93+
return domainDirectory;
94+
}
95+
96+
/**
97+
*
98+
* @param domainDirectory The WebLogic Server domain directory.
99+
*/
100+
public void setDomainDirectory(String domainDirectory) {
101+
this.domainDirectory = domainDirectory;
102+
}
103+
104+
public String getJvmOptions() {
105+
return jvmOptions;
106+
}
107+
108+
/**
109+
*
110+
* @param jvmOptions Used to set the JAVA_OPTIONS environment variable for the shell environment. The environment variable
111+
* can then be used in the script used to start the server.
112+
*/
113+
public void setJvmOptions(String jvmOptions) {
114+
this.jvmOptions = jvmOptions;
115+
}
116+
117+
public int getTimeout() {
118+
return timeout;
119+
}
120+
121+
/**
122+
*
123+
* @param timeout The duration in number of seconds, by which the startup and shutdown script should complete. Defaults to
124+
* 60. If the server is not detected to have started or shutdown by this interval, the container action is deemed to
125+
* have failed.
126+
*/
127+
public void setTimeout(int timeout) {
128+
this.timeout = timeout;
129+
}
130+
131+
public boolean isOutputToConsole() {
132+
return outputToConsole;
133+
}
134+
135+
/**
136+
*
137+
* @param outputToConsole Whether the output from the execution of the shell scripts should be logged to the console.
138+
*/
139+
public void setOutputToConsole(boolean outputToConsole) {
140+
this.outputToConsole = outputToConsole;
141+
}
142+
143+
public boolean isAllowConnectingToRunningServer() {
144+
return allowConnectingToRunningServer;
145+
}
146+
147+
/**
148+
*
149+
* @param allowConnectingToRunningServer Whether Arquillian should be allowed to connect and run tests in an already running
150+
* WebLogic Server instance.
151+
*/
152+
public void setAllowConnectingToRunningServer(boolean allowConnectingToRunningServer) {
153+
this.allowConnectingToRunningServer = allowConnectingToRunningServer;
154+
}
155+
156+
public String getStartServerScript() {
157+
return startServerScript;
158+
}
159+
160+
/**
161+
*
162+
* @param startServerScript The script used to start the WebLogic Server instance. Defaults to the startWebLogic script in
163+
* the bin sub-directory of the domain home.
164+
*/
165+
public void setStartServerScript(String startServerScript) {
166+
this.startServerScript = startServerScript;
167+
}
168+
169+
public String getStopServerScript() {
170+
return stopServerScript;
171+
}
172+
173+
/**
174+
*
175+
* @param stopServerScript The script used to stop the WebLogic Server instance. Defaults to the stopWebLogic script in the
176+
* bin sub-directory of the domain home.
177+
*/
178+
public void setStopServerScript(String stopServerScript) {
179+
this.stopServerScript = stopServerScript;
180+
}
181+
182+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2011, Red Hat Middleware LLC, and individual contributors
4+
* by the @authors tag. See the copyright.txt in the distribution for a
5+
* full listing of individual contributors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.jboss.arquillian.container.wls;
18+
19+
import org.jboss.arquillian.container.spi.client.container.LifecycleException;
20+
21+
/**
22+
* A utility class for performing operations relevant to a WebLogic container managed by Arquillian.
23+
*
24+
* @author Vineet Reynolds
25+
*
26+
*/
27+
public class ManagedContainer extends RemoteContainer {
28+
29+
private CommonManagedWebLogicConfiguration configuration;
30+
private WebLogicServerControl serverControl;
31+
32+
public ManagedContainer(CommonManagedWebLogicConfiguration configuration) {
33+
super(configuration);
34+
this.configuration = configuration;
35+
}
36+
37+
/**
38+
* Starts the managed container process, and then delegates to the remote container implementation to discover additional
39+
* container configuration via JMX.
40+
*/
41+
@Override
42+
public void start() throws LifecycleException {
43+
serverControl = new WebLogicServerControl((CommonManagedWebLogicConfiguration) configuration);
44+
if (serverControl.isServerRunning()) {
45+
if (configuration.isAllowConnectingToRunningServer()) {
46+
super.start();
47+
} else {
48+
throw new LifecycleException("The server is already running! "
49+
+ "Managed containers does not support connecting to running server instances due to the "
50+
+ "possible harmful effect of connecting to the wrong server. Please stop server before running or "
51+
+ "change to another type of container.\n"
52+
+ "To disable this check and allow Arquillian to connect to a running server, "
53+
+ "set allowConnectingToRunningServer to true in the container configuration");
54+
}
55+
} else {
56+
serverControl.startServer();
57+
super.start();
58+
}
59+
}
60+
61+
/**
62+
* Closes all resources consumed by the remote container client, and then stops the managed container process.
63+
*/
64+
@Override
65+
public void stop() throws LifecycleException {
66+
try {
67+
super.stop();
68+
} finally {
69+
serverControl.stopServer();
70+
}
71+
}
72+
73+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2011, Red Hat Middleware LLC, and individual contributors
4+
* by the @authors tag. See the copyright.txt in the distribution for a
5+
* full listing of individual contributors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.jboss.arquillian.container.wls;
18+
19+
import java.io.File;
20+
21+
import org.jboss.arquillian.container.spi.client.container.DeploymentException;
22+
import org.jboss.arquillian.container.spi.client.container.LifecycleException;
23+
import org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData;
24+
import org.jboss.shrinkwrap.api.Archive;
25+
26+
/**
27+
* A utility class for performing operations relevant to a remote WebLogic container used by Arquillian.
28+
*
29+
* @author Vineet Reynolds
30+
*
31+
*/
32+
public class RemoteContainer {
33+
34+
private WebLogicJMXClient jmxClient;
35+
private WebLogicDeployerClient deployerClient;
36+
private CommonWebLogicConfiguration configuration;
37+
38+
public RemoteContainer(CommonWebLogicConfiguration configuration) {
39+
this.configuration = configuration;
40+
}
41+
42+
/**
43+
* Starts a JMX client to read container metadata from the Domain Runtime MBean Server.
44+
*
45+
* @throws LifecycleException When a connection cannot be created to the MBean Server.
46+
*/
47+
public void start() throws LifecycleException {
48+
deployerClient = new WebLogicDeployerClient(configuration);
49+
jmxClient = new WebLogicJMXClient(configuration);
50+
}
51+
52+
/**
53+
* Stops the JMX client.
54+
*
55+
* @throws LifecycleException When there is failure in closing the JMX connection.
56+
*/
57+
public void stop() throws LifecycleException {
58+
jmxClient.close();
59+
}
60+
61+
/**
62+
* Wraps the operation of forking a weblogic.Deployer process to deploy an application.
63+
*
64+
* @param archive The ShrinkWrap archive to deploy
65+
* @return The metadata for the deployed application
66+
* @throws DeploymentException When forking of weblogic.Deployer fails, or when interaction with the forked process fails,
67+
* or when details of the deployment cannot be obtained from the Domain Runtime MBean Server.
68+
*/
69+
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
70+
String deploymentName = getDeploymentName(archive);
71+
File deploymentArchive = ShrinkWrapUtil.toFile(archive);
72+
73+
deployerClient.deploy(deploymentName, deploymentArchive);
74+
ProtocolMetaData metadata = jmxClient.deploy(deploymentName);
75+
return metadata;
76+
}
77+
78+
/**
79+
* Wraps the operation of forking a weblogic.Deployer process to undeploy an application.
80+
*
81+
* @param archive The ShrinkWrap archive to undeploy
82+
* @throws DeploymentException When forking of weblogic.Deployer fails, or when interaction with the forked process fails,
83+
* or when undeployment cannot be confirmed.
84+
*/
85+
public void undeploy(Archive<?> archive) throws DeploymentException {
86+
// Undeploy the application
87+
String deploymentName = getDeploymentName(archive);
88+
deployerClient.undeploy(deploymentName);
89+
90+
// Verify the undeployment from the Domain Runtime MBean Server.
91+
jmxClient.undeploy(deploymentName);
92+
}
93+
94+
private String getDeploymentName(Archive<?> archive) {
95+
String archiveFilename = archive.getName();
96+
int indexOfDot = archiveFilename.indexOf(".");
97+
if (indexOfDot != -1) {
98+
return archiveFilename.substring(0, indexOfDot);
99+
}
100+
return archiveFilename;
101+
}
102+
103+
}

0 commit comments

Comments
 (0)