Skip to content

Commit c714c90

Browse files
Merge master
2 parents c1e6fa6 + a85a1f5 commit c714c90

File tree

73 files changed

+2395
-1569
lines changed

Some content is hidden

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

73 files changed

+2395
-1569
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ release.properties
2626
.mvn/maven.config
2727
**/*$py.class
2828
**/*.pyc
29+
**/.DS_Store

README.md

Lines changed: 31 additions & 932 deletions
Large diffs are not rendered by default.

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<parent>
1212
<artifactId>weblogic-deploy</artifactId>
1313
<groupId>com.oracle.weblogic.lifecycle</groupId>
14-
<version>0.15</version>
14+
<version>0.18-SNAPSHOT</version>
1515
<relativePath>../pom.xml</relativePath>
1616
</parent>
1717

core/src/main/java/oracle/weblogic/deploy/aliases/TypeUtils.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
* The Universal Permissive License (UPL), Version 1.0
44
*/
55
package oracle.weblogic.deploy.aliases;
@@ -32,7 +32,7 @@ public final class TypeUtils {
3232
private static final String CLASS = TypeUtils.class.getName();
3333
private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger("wlsdeploy.util");
3434

35-
private static final String DEFAULT_STRING_LIST_DELIMITOR = ",";
35+
public static final String DEFAULT_STRING_LIST_DELIMITER = ",";
3636

3737
private TypeUtils() {
3838
// hide the constructor for this utility class
@@ -76,7 +76,7 @@ public static Object convertToType(String targetTypeName, Object value) throws A
7676
delimiter = File.pathSeparator;
7777
break;
7878
default:
79-
delimiter = DEFAULT_STRING_LIST_DELIMITOR;
79+
delimiter = DEFAULT_STRING_LIST_DELIMITER;
8080
}
8181
return convertToType(targetTypeName, value, delimiter);
8282
}
@@ -154,7 +154,7 @@ public static Object convertToType(String targetTypeName, Object value, String d
154154
* the conversion.
155155
*/
156156
public static Object convertToType(Class<?> targetType, Object value) throws AliasException {
157-
return convertToType(targetType, value, DEFAULT_STRING_LIST_DELIMITOR);
157+
return convertToType(targetType, value, DEFAULT_STRING_LIST_DELIMITER);
158158
}
159159

160160
/**
@@ -231,7 +231,7 @@ public static Object convertToType(Class<?> targetType, Object value, String del
231231
return result;
232232
}
233233

234-
private static String convertToBoolean(String strValue) {
234+
public static String convertToBoolean(String strValue) {
235235
String result;
236236
switch (strValue.toLowerCase(Locale.ENGLISH)) {
237237
case "1":
@@ -246,7 +246,7 @@ private static String convertToBoolean(String strValue) {
246246
return result;
247247
}
248248

249-
private static Character convertToCharacter(String strValue) {
249+
public static Character convertToCharacter(String strValue) {
250250
Character result = null;
251251
if (strValue.length() > 0) {
252252
result = strValue.charAt(0);
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
/*
2+
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3+
* The Universal Permissive License (UPL), Version 1.0
4+
*/
5+
package oracle.weblogic.deploy.util;
6+
7+
import oracle.weblogic.deploy.aliases.TypeUtils;
8+
import oracle.weblogic.deploy.exception.ExceptionHelper;
9+
10+
import java.lang.reflect.Array;
11+
import java.lang.reflect.InvocationTargetException;
12+
import java.lang.reflect.Method;
13+
import java.util.List;
14+
15+
/**
16+
* Utility methods for configuring custom MBeans.
17+
*/
18+
public final class CustomBeanUtils {
19+
20+
private CustomBeanUtils() {
21+
// hide the constructor for this utility class
22+
}
23+
24+
/**
25+
* Invoke the specified set method on the MBean with the provided value, converted to the desired type.
26+
* The conversion and invocation are done together to avoid automatic Jython data conversion.
27+
*
28+
* @param mbean the value to be converted
29+
* @param propertyType the class representing the target type
30+
* @param propertyValue the class representing the target type
31+
* @throws IllegalAccessException if method invocation fails
32+
* @throws IllegalArgumentException if the data conversion or method invocation fails
33+
* @throws InvocationTargetException if method invocation fails
34+
*/
35+
public static void callMethod(Object mbean, Method method, Class<?> propertyType, Object propertyValue)
36+
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
37+
38+
// convert the specified property value to the desired type
39+
Object setValue = CustomBeanUtils.convertValue(propertyValue, propertyType);
40+
41+
// call the setter with the target value
42+
method.invoke(mbean, setValue);
43+
}
44+
45+
/**
46+
* Convert the specified value to the specified type.
47+
* The conversions and available types are specific to user-defined custom mbeans.
48+
*
49+
* @param value the value to be converted
50+
* @param dataType the class representing the target type
51+
* @throws IllegalArgumentException if the data conversion fails
52+
* @return the value converted to the new type, or null if conversion failed
53+
*/
54+
static Object convertValue(Object value, Class<?> dataType) {
55+
// package private to allow unit test access
56+
57+
Object result;
58+
59+
if (Object[].class.isAssignableFrom(dataType)) {
60+
result = convertArrayValue(value, dataType);
61+
} else {
62+
result = convertSingleValue(value, dataType);
63+
}
64+
65+
return result;
66+
}
67+
68+
/**
69+
* Convert the specified array value to the specified type.
70+
* This may require rebuilding the array with the desired type.
71+
*
72+
* @param value the value to be converted
73+
* @param dataType the class representing the target type
74+
* @throws IllegalArgumentException if the data conversion fails
75+
* @return the value converted to the new type, or null if conversion failed
76+
*/
77+
private static Object convertArrayValue(Object value, Class<?> dataType) {
78+
Class<?> componentType = dataType.getComponentType();
79+
Object[] result;
80+
81+
if (dataType.isAssignableFrom(value.getClass())) {
82+
// the value may already match the target type
83+
result = (Object[]) value;
84+
85+
} else {
86+
// rebuild the array with the target component type and converted elements
87+
Object[] source;
88+
89+
if(Object[].class.isAssignableFrom(value.getClass())) {
90+
source = (Object[]) value;
91+
92+
} else if(value instanceof List) {
93+
// probably a python PyList from model
94+
source = ((List) value).toArray();
95+
96+
} else {
97+
String text = value.toString();
98+
source = text.split(TypeUtils.DEFAULT_STRING_LIST_DELIMITER);
99+
}
100+
101+
Object arrayObject = Array.newInstance(componentType, source.length);
102+
103+
for (int i = 0; i < source.length; i++) {
104+
Object elementValue = convertSingleValue(source[i], componentType);
105+
Array.set(arrayObject, i, elementValue);
106+
}
107+
108+
result = (Object[]) arrayObject;
109+
}
110+
111+
return result;
112+
}
113+
114+
/**
115+
* Convert the specified single value to the specified type.
116+
* This invokes the low-level alias conversion methods, with a few adjustments.
117+
*
118+
* @param value the value to be converted
119+
* @param dataType the class representing the target type
120+
* @throws IllegalArgumentException if the data type is not recognized
121+
* @return the value converted to the new type, or null if conversion failed
122+
*/
123+
private static Object convertSingleValue(Object value, Class<?> dataType) {
124+
if (value == null) {
125+
return null;
126+
}
127+
128+
String textValue;
129+
if (value instanceof char[]) {
130+
textValue = String.valueOf((char[]) value);
131+
} else {
132+
textValue = value.toString().trim();
133+
if (textValue.length() == 0) {
134+
return null;
135+
}
136+
}
137+
138+
// This block of code is similar to the conversion in TypeUtils.convertToType(), but with some differences.
139+
// Custom MBeans only allow a subset of the data types of full alias conversion, and the Java types have to
140+
// be strictly maintained to be passed the the reflected set methods. In addition, convertToType() does not
141+
// convert arrays to the proper data type, so that is handled at a more granular level in this class.
142+
143+
Object result;
144+
145+
try {
146+
if (dataType == String.class) {
147+
result = textValue;
148+
149+
} else if((dataType == Boolean.class) || (dataType == Boolean.TYPE)) {
150+
String booleanText = TypeUtils.convertToBoolean(textValue);
151+
result = Boolean.parseBoolean(booleanText);
152+
153+
} else if(dataType == Integer.class) {
154+
result = Integer.valueOf(textValue);
155+
156+
} else if(dataType == Short.class) {
157+
result = Short.valueOf(textValue);
158+
159+
} else if(dataType == Long.class) {
160+
result = Long.valueOf(textValue);
161+
162+
} else if(dataType == Float.class) {
163+
result = Float.valueOf(textValue);
164+
165+
} else if(dataType == Double.class) {
166+
result = Double.valueOf(textValue);
167+
168+
} else if(dataType == Character.class) {
169+
result = TypeUtils.convertToCharacter(textValue);
170+
171+
} else {
172+
String message = ExceptionHelper.getMessage("WLSDPLY-12132", dataType);
173+
throw new IllegalArgumentException(message);
174+
}
175+
176+
} catch(NumberFormatException nfe) {
177+
String message = ExceptionHelper.getMessage("WLSDPLY-12133", textValue, dataType);
178+
throw new IllegalArgumentException(message);
179+
}
180+
181+
return result;
182+
}
183+
}

core/src/main/java/oracle/weblogic/deploy/yaml/AbstractYamlTranslator.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
* The Universal Permissive License (UPL), Version 1.0
44
*/
55
package oracle.weblogic.deploy.yaml;
@@ -72,7 +72,11 @@ public void enterAssign(YamlParser.AssignContext ctx) {
7272
PyObject value = getAssignValue(name, ctx);
7373

7474
PyDictionary container = currentDict.peek();
75-
container.__setitem__(new PyString(name), value);
75+
76+
// null indicates not parsable, Py.None would be returned for legitimate cases
77+
if (value != null) {
78+
container.__setitem__(new PyString(name), value);
79+
}
7680
}
7781

7882
/**

core/src/main/python/create.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
The Universal Permissive License (UPL), Version 1.0
44
55
The main module for the WLSDeploy tool to create empty domains.
@@ -33,6 +33,7 @@
3333
from wlsdeploy.logging.platform_logger import PlatformLogger
3434
from wlsdeploy.tool.create.domain_creator import DomainCreator
3535
from wlsdeploy.tool.create.domain_typedef import DomainTypedef
36+
from wlsdeploy.tool.create.domain_typedef import CREATE_DOMAIN
3637
from wlsdeploy.tool.util import filter_helper
3738
from wlsdeploy.tool.validate.validator import Validator
3839
from wlsdeploy.util import getcreds
@@ -44,7 +45,8 @@
4445
from wlsdeploy.util.model_translator import FileToPython
4546
from wlsdeploy.util.weblogic_helper import WebLogicHelper
4647

47-
_program_name = 'createDomain'
48+
_program_name = CREATE_DOMAIN
49+
4850
_class_name = 'create'
4951
__logger = PlatformLogger('wlsdeploy.create')
5052
__wlst_mode = WlstModes.OFFLINE
@@ -193,8 +195,15 @@ def __process_model_args(optional_arg_map):
193195
try:
194196
archive_file = WLSDeployArchive(archive_file_name)
195197
__tmp_model_dir = FileUtils.createTempDirectory(_program_name)
196-
tmp_model_file = \
197-
FileUtils.fixupFileSeparatorsForJython(archive_file.extractModel(__tmp_model_dir).getAbsolutePath())
198+
tmp_model_raw_file = archive_file.extractModel(__tmp_model_dir)
199+
if not tmp_model_raw_file:
200+
ex = exception_helper.create_cla_exception('WLSDPLY-20026', _program_name, archive_file_name,
201+
CommandLineArgUtil.MODEL_FILE_SWITCH)
202+
ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
203+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
204+
raise ex
205+
206+
tmp_model_file = FileUtils.fixupFileSeparatorsForJython(tmp_model_raw_file.getAbsolutePath())
198207
except (IllegalArgumentException, IllegalStateException, WLSDeployArchiveIOException), archex:
199208
ex = exception_helper.create_cla_exception('WLSDPLY-20010', _program_name, archive_file_name,
200209
archex.getLocalizedMessage(), error=archex)

core/src/main/python/deploy.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
The Universal Permissive License (UPL), Version 1.0
44
55
The entry point for the deployApps tool.
@@ -171,8 +171,15 @@ def __process_model_args(optional_arg_map):
171171
try:
172172
archive_file = WLSDeployArchive(archive_file_name)
173173
__tmp_model_dir = FileUtils.createTempDirectory(_program_name)
174-
model_file_name = \
175-
FileUtils.fixupFileSeparatorsForJython(archive_file.extractModel(__tmp_model_dir).getAbsolutePath())
174+
tmp_model_raw_file = archive_file.extractModel(__tmp_model_dir)
175+
if not tmp_model_raw_file:
176+
ex = exception_helper.create_cla_exception('WLSDPLY-20026', _program_name, archive_file_name,
177+
CommandLineArgUtil.MODEL_FILE_SWITCH)
178+
ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
179+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
180+
raise ex
181+
182+
model_file_name = FileUtils.fixupFileSeparatorsForJython(tmp_model_raw_file.getAbsolutePath())
176183
except (IllegalArgumentException, IllegalStateException, WLSDeployArchiveIOException), archex:
177184
ex = exception_helper.create_cla_exception('WLSDPLY-20010', _program_name, archive_file_name,
178185
archex.getLocalizedMessage(), error=archex)

core/src/main/python/discover.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
The Universal Permissive License (UPL), Version 1.0
44
55
The entry point for the discoverDomain tool.
@@ -20,7 +20,6 @@
2020
from oracle.weblogic.deploy.util import TranslateException
2121
from oracle.weblogic.deploy.util import WLSDeployArchive
2222
from oracle.weblogic.deploy.util import WLSDeployArchiveIOException
23-
from oracle.weblogic.deploy.util import WLSDeployExit
2423
from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion
2524
from oracle.weblogic.deploy.validate import ValidateException
2625

@@ -72,7 +71,8 @@
7271
CommandLineArgUtil.VARIABLE_PROPERTIES_FILE_SWITCH,
7372
CommandLineArgUtil.ADMIN_URL_SWITCH,
7473
CommandLineArgUtil.ADMIN_USER_SWITCH,
75-
CommandLineArgUtil.ADMIN_PASS_SWITCH
74+
CommandLineArgUtil.ADMIN_PASS_SWITCH,
75+
CommandLineArgUtil.TARGET_MODE_SWITCH
7676
]
7777

7878

@@ -153,6 +153,7 @@ def __process_online_args(optional_arg_map):
153153
optional_arg_map[CommandLineArgUtil.ADMIN_PASS_SWITCH] = String(password)
154154

155155
mode = WlstModes.ONLINE
156+
optional_arg_map[CommandLineArgUtil.TARGET_MODE_SWITCH] = 'online'
156157
return mode
157158

158159

0 commit comments

Comments
 (0)