Skip to content

Commit 0107bdd

Browse files
adding test that verfies wdt discoverdomain tool (#2397)
* adding test that verfies files generated by wdt discoverdomain tool on onprem domain can be used to start a wko domain * fixing the domain yaml filename since wdt discover domain changed it Co-authored-by: [email protected] <[email protected]>
1 parent e34c5f7 commit 0107bdd

File tree

11 files changed

+1046
-1
lines changed

11 files changed

+1046
-1
lines changed

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItLiftAndShiftFromOnPremDomain.java

Lines changed: 439 additions & 0 deletions
Large diffs are not rendered by default.

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/BuildApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public static Path buildApplication(Path appSrcPath, Map<String, String> antPara
212212
* @return V1Pod created pod object
213213
* @throws ApiException when create pod fails
214214
*/
215-
private static V1Pod setupWebLogicPod(String namespace, V1Container container) {
215+
public static V1Pod setupWebLogicPod(String namespace, V1Container container) {
216216
final LoggingFacade logger = getLogger();
217217
ConditionFactory withStandardRetryPolicy = with().pollDelay(10, SECONDS)
218218
.and().with().pollInterval(2, SECONDS)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Created-By: 1.8.0_201 (Oracle Corporation)
3+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright (c) 2021, Oracle and/or its affiliates.
4+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
5+
-->
6+
<application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.4">
7+
<description>JSP 2.0 Expression Language Example</description>
8+
<display-name>JSP 2.0 Expression Language Example</display-name>
9+
<module>
10+
<web>
11+
<web-uri>opdemo</web-uri>
12+
<context-root>opdemo</context-root>
13+
</web>
14+
</module>
15+
</application>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright (c) 2021, Oracle and/or its affiliates.
4+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
5+
-->
6+
<weblogic-application xmlns="http://www.bea.com/ns/weblogic/90">
7+
</weblogic-application>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright (c) 2021, Oracle and/or its affiliates.
4+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
5+
-->
6+
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4">
7+
</web-app>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<%@page import="java.util.Calendar"
2+
import="java.text.SimpleDateFormat"
3+
import="javax.management.MBeanServer"
4+
import="javax.management.ObjectName"
5+
import="javax.naming.InitialContext"
6+
import="javax.servlet.ServletException"
7+
import="javax.servlet.http.HttpServlet"
8+
import="javax.servlet.http.HttpServletRequest"
9+
import="javax.servlet.http.HttpServletResponse"
10+
import="java.net.InetAddress"%>
11+
<%@ page language="java" contentType="text/html; charset=UTF-8"
12+
pageEncoding="UTF-8"%>
13+
<!DOCTYPE html>
14+
<html>
15+
<body>
16+
<h1>WebLogic on prem to wko App </font></h1><br>
17+
<%
18+
String jdbcDataSourceName = request.getParameter("dsname");
19+
StringBuffer message = new StringBuffer();
20+
message.append("<b>Server time:</b> " + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()));
21+
message.append("<br>");
22+
message.append("<b>Hostname:</b> " + InetAddress.getLocalHost().getHostName());
23+
message.append("<br>");
24+
message.append("<h2>Datasource properties</h2> ");
25+
message.append("<p>");
26+
if (jdbcDataSourceName == null || jdbcDataSourceName.length() == 0) {
27+
message.append("<font color=\"red\">No datasource name provided.</font><br>");
28+
message.append("<font color=\"red\">Append ?dsname=YOUR_DATA_SOURCE_NAME to the URL.</font>");
29+
message.append("</p>");
30+
} else {
31+
message.append("<b>Datasource name:</b> " + jdbcDataSourceName);
32+
message.append("<br>");
33+
try {
34+
InitialContext ctx = new InitialContext();
35+
MBeanServer connection = (MBeanServer) ctx.lookup("java:comp/env/jmx/runtime");
36+
37+
ObjectName jdbcSystemResource = new ObjectName(
38+
"com.bea:Name=" + jdbcDataSourceName + ",Type=JDBCSystemResource");
39+
ObjectName jdbcDataSourceBean = (ObjectName) connection.getAttribute(jdbcSystemResource,
40+
"JDBCResource");
41+
ObjectName jdbcDriverParams = (ObjectName) connection.getAttribute(jdbcDataSourceBean,
42+
"JDBCDriverParams");
43+
44+
String URL = (String) connection.getAttribute(jdbcDriverParams, "Url");
45+
46+
System.out.println("DB URL = " + URL);
47+
48+
ObjectName dsProperties = (ObjectName) connection.getAttribute(jdbcDriverParams, "Properties");
49+
50+
ObjectName[] jdbcPropertyBeans = (ObjectName[]) connection.getAttribute(dsProperties, "Properties");
51+
for (int j = 0; j < jdbcPropertyBeans.length; j++) {
52+
ObjectName jdbcPropertyBean = null;
53+
jdbcPropertyBean = jdbcPropertyBeans[j];
54+
String jdbcPropertyName = (String) connection.getAttribute(jdbcPropertyBean, "Name");
55+
String jdbcPropertyValue = (String) connection.getAttribute(jdbcPropertyBean, "Value");
56+
if (jdbcPropertyName.equals("user")) {
57+
message.append("<b>Database User:</b> " + jdbcPropertyValue);
58+
message.append("<br>");
59+
}
60+
}
61+
message.append("<b>Database URL:</b> " + URL);
62+
message.append("</p>");
63+
} catch (Exception e) {
64+
e.printStackTrace();
65+
message.append("<b>Error:</b> " + e.getClass().getName() + " - " + e.getLocalizedMessage());
66+
}
67+
}
68+
%>
69+
<%=message%>
70+
</body>
71+
</html>
Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
#!/bin/bash
2+
# Copyright (c) 2021, Oracle and/or its affiliates.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
#
5+
# Description:
6+
#
7+
# This script generates model files and variables files by calling WebLogic Deploy Tool (WDT)
8+
# bin/discoverDomain.sh script on an on-prem domain.
9+
#
10+
# It first installs WDT using the given download URLs, and then runs it using the
11+
# given Oracle home. It then generates WDT model file, WDT vars file, etc.
12+
#
13+
# Usage:
14+
#
15+
# Export customized values for the input shell environment variables as needed
16+
# before calling this script.
17+
#
18+
# Outputs:
19+
#
20+
# WDT install: WDT_DIR/weblogic-deploy/...
21+
#
22+
# Copy of wdt model: WDT_DIR/$(basename WDT_MODEL_FILE)
23+
# Copy of wdt vars: WDT_DIR/$(basename WDT_VAR_FILE)
24+
#
25+
# WDT logs: WDT_DIR/weblogic-deploy/logs/...
26+
# WDT stdout: WDT_DIR/createDomain.sh.out
27+
#
28+
# WebLogic domain home: DOMAIN_HOME_DIR
29+
# default: /shared/domains/<domainUID>
30+
#
31+
# Input environment variables:
32+
#
33+
# ORACLE_HOME Oracle home with a WebLogic install.
34+
# default: /u01/oracle
35+
#
36+
# WDT_MODEL_FILE Full path to WDT model file.
37+
# default: the directory that contains this script
38+
# plus "/wdt_model.yaml"
39+
#
40+
# WDT_VAR_FILE Full path to WDT variable file (java properties format).
41+
# default: the directory that contains this script
42+
# plus "/create-domain-inputs.yaml"
43+
#
44+
# WDT_INSTALL_ZIP_FILE Filename of WDT install zip.
45+
# default: weblogic-deploy.zip
46+
#
47+
# WDT_INSTALL_ZIP_URL URL for downloading WDT install zip
48+
# default: https://github.com/oracle/weblogic-deploy-tooling/releases/download/release-1.9.7/$WDT_INSTALL_ZIP_FILE
49+
#
50+
# https_proxy Proxy for downloading WDT_INSTALL_ZIP_URL.
51+
# default: ""
52+
# (If set to empty the script will try with no proxy.)
53+
#
54+
# https_proxy2 Alternate proxy for downloading WDT_INSTALL_ZIP_URL
55+
# default: ""
56+
# (If set to empty the script will try with no proxy.)
57+
#
58+
# WDT_DIR Target location to install and run WDT, and to keep a copy of
59+
# $WDT_MODEL_FILE and $WDT_MODEL_VARS. Also the location
60+
# of WDT log files.
61+
# default: /shared/wdt
62+
# WDT_VERSION WDT version to download.
63+
# default: latest
64+
#
65+
# DOMAIN_HOME_DIR Target location for generated domain.
66+
#
67+
# DOMAIN_TYPE Domain type. It can be WLS, JRF or RestrictedJRF. Default is WLS
68+
#
69+
70+
# Initialize globals
71+
72+
# using "-" instead of ":-" in case proxy vars are explicitly set to "".
73+
https_proxy=${https_proxy-""}
74+
https_proxy2=${https_proxy2-""}
75+
domain_src=${DOMAIN_SRC-""}
76+
discover_domain_output_dir=${DISCOVER_DOMAIN_OUTPUT_DIR-""}
77+
app=${APP-""}
78+
79+
export ORACLE_HOME=${ORACLE_HOME:-/u01/oracle}
80+
81+
SCRIPTPATH="$( cd "$(dirname "$0")" > /dev/null 2>&1 ; pwd -P )"
82+
83+
WDT_DIR=${WDT_DIR:-/u01/wdt}
84+
if [ -z "${WDT_VERSION+x}" ] || [ ${WDT_VERSION} == "latest" ]; then
85+
curl_res=1
86+
max=20
87+
count=0
88+
while [ $curl_res -ne 0 -a $count -lt $max ] ; do
89+
sleep 1
90+
for proxy in "${https_proxy2}" "${https_proxy}"; do
91+
echo @@ "Info: Getting latest release WDT url with https_proxy=\"$proxy\""
92+
https_proxy="${proxy}" \
93+
curl -Ls -w %{url_effective} --connect-timeout 30 -o /dev/null \
94+
https://github.com/oracle/weblogic-deploy-tooling/releases/latest > out
95+
curl_res=$?
96+
if [ $curl_res -eq 0 ]; then
97+
echo "Got URL $(cat out)"
98+
WDT_BASE_URL=$(cat out | sed -e "s/tag/download/g")
99+
rm out
100+
break
101+
fi
102+
done
103+
done
104+
else
105+
WDT_BASE_URL="https://github.com/oracle/weblogic-deploy-tooling/releases/download/release-$WDT_VERSION"
106+
fi
107+
108+
WDT_INSTALL_ZIP_FILE="${WDT_INSTALL_ZIP_FILE:-weblogic-deploy.zip}"
109+
WDT_INSTALL_ZIP_URL=${WDT_INSTALL_ZIP_URL:-"$WDT_BASE_URL/$WDT_INSTALL_ZIP_FILE"}
110+
111+
DOMAIN_TYPE="${DOMAIN_TYPE:-WLS}"
112+
TARGET_TYPE="${TARGET_TYPE:-wko}"
113+
114+
# Define functions
115+
116+
function setup_wdt_shared_dir {
117+
mkdir -p $WDT_DIR || return 1
118+
}
119+
120+
function install_wdt {
121+
#
122+
# Download $WDT_INSTALL_ZIP_FILE from $WDT_INSTALL_ZIP_URL into $WDT_DIR using
123+
# proxies https_proxy or https_proxy2, then unzip the zip file in $WDT_DIR.
124+
#
125+
126+
local save_dir=`pwd`
127+
cd $WDT_DIR || return 1
128+
129+
local curl_res=1
130+
max=20
131+
count=0
132+
while [ $curl_res -ne 0 -a $count -lt $max ] ; do
133+
sleep 10
134+
count=`expr $count + 1`
135+
for proxy in "${https_proxy}" "${https_proxy2}"; do
136+
echo @@ "Info: Downloading $WDT_INSTALL_ZIP_URL with https_proxy=\"$proxy\""
137+
https_proxy="${proxy}" \
138+
curl --silent --show-error --connect-timeout 10 -O -L $WDT_INSTALL_ZIP_URL
139+
curl_res=$?
140+
[ $curl_res -eq 0 ] && break
141+
done
142+
done
143+
if [ $curl_res -ne 0 ] || [ ! -f $WDT_INSTALL_ZIP_FILE ]; then
144+
cd $save_dir
145+
echo @@ "Error: Download failed or $WDT_INSTALL_ZIP_FILE not found."
146+
return 1
147+
fi
148+
149+
echo @@ "Info: Archive downloaded to $WDT_DIR/$WDT_INSTALL_ZIP_FILE, about to unzip via 'jar xf'."
150+
151+
jar xf $WDT_INSTALL_ZIP_FILE
152+
local jar_res=$?
153+
154+
cd $save_dir
155+
156+
if [ $jar_res -ne 0 ]; then
157+
echo @@ "Error: Install failed while unzipping $WDT_DIR/$WDT_INSTALL_ZIP_FILE"
158+
return $jar_res
159+
fi
160+
161+
if [ ! -d "$WDT_DIR/weblogic-deploy/bin" ]; then
162+
echo @@ "Error: Install failed: directory '$WDT_DIR/weblogic-deploy/bin' not found."
163+
return 1
164+
fi
165+
166+
chmod 775 $WDT_DIR/weblogic-deploy/bin/* || return 1
167+
168+
echo @@ "Info: Install succeeded, wdt install is in the $WDT_DIR/weblogic-deploy directory."
169+
return 0
170+
}
171+
172+
function run_wdt {
173+
#
174+
# Run WDT using WDT_VAR_FILE, WDT_MODEL_FILE, and ORACLE_HOME.
175+
# Output:
176+
# - result domain will be in DOMAIN_HOME_DIR
177+
# - logging output is in $WDT_DIR/createDomain.sh.out and $WDT_DIR/weblogic-deploy/logs
178+
# - WDT_VAR_FILE & WDT_MODEL_FILE will be copied to WDT_DIR.
179+
#
180+
181+
# Input files and directories.
182+
183+
local inputs_orig="$WDT_VAR_FILE"
184+
local model_orig="$WDT_MODEL_FILE"
185+
local oracle_home="$ORACLE_HOME"
186+
local wdt_bin_dir="$WDT_DIR/weblogic-deploy/bin"
187+
local wdt_discoverDomain_script="$wdt_bin_dir/discoverDomain.sh"
188+
189+
local domain_home_dir="/u01/$domain_src"
190+
if [ -z "${domain_home_dir}" ]; then
191+
local domain_dir="/shared/domains"
192+
local domain_uid=`egrep 'domainUID' $inputs_orig | awk '{print $2}'`
193+
local domain_home_dir=$domain_dir/$domain_uid
194+
fi
195+
196+
echo domain_home_dir = $domain_home_dir
197+
mkdir -p $domain_home_dir
198+
unzip /u01/${domain_src}.zip -d $domain_home_dir
199+
200+
# Output files and directories.
201+
202+
local variable_file=${domain_src}.properties
203+
local model_file=${domain_src}.yaml
204+
local archive_file=${app}.zip
205+
local output_dir="/u01/${discover_domain_output_dir}"
206+
mkdir -p $output_dir
207+
local out_file=$WDT_DIR/discoverDomain.sh.out
208+
local wdt_log_dir="$WDT_DIR/weblogic-deploy/logs"
209+
210+
local domain_type="$DOMAIN_TYPE"
211+
local target_type="$TARGET_TYPE"
212+
213+
echo @@ "Info: About to run WDT discoverDomain.sh to generate required files to create $domain_type Domain"
214+
215+
for directory in wdt_bin_dir SCRIPTPATH WDT_DIR oracle_home; do
216+
if [ ! -d "${!directory}" ]; then
217+
echo @@ "Error: Could not find ${directory} directory ${!directory}."
218+
return 1
219+
fi
220+
done
221+
222+
local save_dir=`pwd`
223+
cd $output_dir || return 1
224+
225+
echo @@ "Info: WDT discoverDomain.sh output will be in $out_file and $wdt_log_dir"
226+
227+
$wdt_discoverDomain_script \
228+
-oracle_home $oracle_home \
229+
-target $target_type \
230+
-domain_home $domain_home_dir \
231+
-model_file $model_file \
232+
-variable_file $variable_file \
233+
-archive_file $archive_file \
234+
-output_dir $output_dir > $out_file 2>&1
235+
236+
local wdt_res=$?
237+
238+
cd $save_dir
239+
240+
if [ $wdt_res -ne 0 ]; then
241+
cat $WDT_DIR/discoverDomain.sh.out
242+
echo @@ "Info: WDT discoverDomain.sh output is in $out_file and $wdt_log_dir"
243+
echo @@ "Error: WDT discoverDomain.sh failed."
244+
return 1
245+
fi
246+
247+
echo @@ "Info: WDT createDomain.sh succeeded."
248+
return 0
249+
}
250+
251+
# Run
252+
253+
setup_wdt_shared_dir || exit 1
254+
255+
install_wdt || exit 1
256+
257+
run_wdt || exit 1

0 commit comments

Comments
 (0)