Skip to content

Commit 6b55f87

Browse files
committed
Merge remote-tracking branch 'origin/develop' into owls-70534-error-handling
2 parents 7b3e55e + 6266293 commit 6b55f87

File tree

29 files changed

+503
-440
lines changed

29 files changed

+503
-440
lines changed

json-schema/src/main/java/oracle/kubernetes/json/Description.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.lang.annotation.RetentionPolicy;
1111
import java.lang.annotation.Target;
1212

13+
/** Supplies a description for a field to be inserted into the generated JSON schema. */
1314
@Retention(RetentionPolicy.RUNTIME)
1415
@Target(FIELD)
1516
public @interface Description {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
5+
package oracle.kubernetes.json;
6+
7+
import static java.lang.annotation.ElementType.FIELD;
8+
9+
import java.lang.annotation.Retention;
10+
import java.lang.annotation.RetentionPolicy;
11+
import java.lang.annotation.Target;
12+
13+
/** Specifies an enum class whose values match the permitted values for the field. */
14+
@Retention(RetentionPolicy.RUNTIME)
15+
@Target(FIELD)
16+
public @interface EnumClass {
17+
Class<? extends java.lang.Enum> value();
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
5+
package oracle.kubernetes.json;
6+
7+
import static java.lang.annotation.ElementType.FIELD;
8+
9+
import java.lang.annotation.Retention;
10+
import java.lang.annotation.RetentionPolicy;
11+
import java.lang.annotation.Target;
12+
13+
/** Supplies an ECMA 262 regular expression that the field must match. */
14+
@Retention(RetentionPolicy.RUNTIME)
15+
@Target(FIELD)
16+
public @interface Pattern {
17+
String value();
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
5+
package oracle.kubernetes.json;
6+
7+
import static java.lang.annotation.ElementType.FIELD;
8+
9+
import java.lang.annotation.Retention;
10+
import java.lang.annotation.RetentionPolicy;
11+
import java.lang.annotation.Target;
12+
13+
/** Specifies minimum and/or maximum permitted values for the field. */
14+
@Retention(RetentionPolicy.RUNTIME)
15+
@Target(FIELD)
16+
public @interface Range {
17+
int minimum() default Integer.MIN_VALUE;
18+
19+
int maximum() default Integer.MAX_VALUE;
20+
}

json-schema/src/main/java/oracle/kubernetes/json/SchemaGenerator.java

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,7 @@
1414
import java.lang.reflect.Modifier;
1515
import java.net.MalformedURLException;
1616
import java.net.URL;
17-
import java.util.ArrayList;
18-
import java.util.Arrays;
19-
import java.util.Collection;
20-
import java.util.HashMap;
21-
import java.util.HashSet;
22-
import java.util.Iterator;
23-
import java.util.List;
24-
import java.util.Map;
25-
import java.util.Set;
17+
import java.util.*;
2618
import javax.annotation.Nonnull;
2719

2820
@SuppressWarnings("WeakerAccess")
@@ -205,15 +197,56 @@ private Object getSubSchema(Field field) {
205197
sub.generateTypeIn(result, field.getType());
206198
String description = getDescription(field);
207199
if (description != null) result.put("description", description);
200+
if (isString(field.getType())) addStringRestrictions(result, field);
201+
if (isNumeric(field.getType())) addRange(result, field);
208202

209203
return result;
210204
}
211205

206+
private boolean isString(Class<?> type) {
207+
return type.equals(String.class);
208+
}
209+
210+
private boolean isNumeric(Class<?> type) {
211+
return Number.class.isAssignableFrom(type) || PRIMITIVE_NUMBERS.contains(type);
212+
}
213+
212214
private String getDescription(Field field) {
213215
Description description = field.getAnnotation(Description.class);
214216
return description != null ? description.value() : null;
215217
}
216218

219+
private void addStringRestrictions(Map<String, Object> result, Field field) {
220+
Class<? extends Enum> enumClass = getEnumClass(field);
221+
if (enumClass != null) addEnumValues(result, enumClass);
222+
223+
String pattern = getPattern(field);
224+
if (pattern != null) result.put("pattern", pattern);
225+
}
226+
227+
private Class<? extends java.lang.Enum> getEnumClass(Field field) {
228+
EnumClass annotation = field.getAnnotation(EnumClass.class);
229+
return annotation != null ? annotation.value() : null;
230+
}
231+
232+
private void addEnumValues(
233+
Map<String, Object> result, Class<? extends java.lang.Enum> enumClass) {
234+
result.put("enum", getEnumValues(enumClass));
235+
}
236+
237+
private String getPattern(Field field) {
238+
Pattern pattern = field.getAnnotation(Pattern.class);
239+
return pattern == null ? null : pattern.value();
240+
}
241+
242+
private void addRange(Map<String, Object> result, Field field) {
243+
Range annotation = field.getAnnotation(Range.class);
244+
if (annotation == null) return;
245+
246+
if (annotation.minimum() > Integer.MIN_VALUE) result.put("minimum", annotation.minimum());
247+
if (annotation.maximum() < Integer.MAX_VALUE) result.put("maximum", annotation.maximum());
248+
}
249+
217250
private class SubSchemaGenerator {
218251
Field field;
219252

@@ -223,9 +256,8 @@ private class SubSchemaGenerator {
223256

224257
private void generateTypeIn(Map<String, Object> result, Class<?> type) {
225258
if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) result.put("type", "boolean");
226-
else if (Number.class.isAssignableFrom(type) || PRIMITIVE_NUMBERS.contains(type))
227-
result.put("type", "number");
228-
else if (type.equals(String.class)) result.put("type", "string");
259+
else if (isNumeric(type)) result.put("type", "number");
260+
else if (isString(type)) result.put("type", "string");
229261
else if (type.isEnum()) generateEnumTypeIn(result, type);
230262
else if (type.isArray()) this.generateArrayTypeIn(result, type);
231263
else if (Collection.class.isAssignableFrom(type)) generateCollectionTypeIn(result);

json-schema/src/test/java/oracle/kubernetes/json/SchemaGeneratorTest.java

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
88
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasNoJsonPath;
9-
import static org.hamcrest.Matchers.arrayContaining;
10-
import static org.hamcrest.Matchers.arrayContainingInAnyOrder;
11-
import static org.hamcrest.Matchers.equalTo;
12-
import static org.hamcrest.Matchers.not;
9+
import static org.hamcrest.Matchers.*;
1310
import static org.junit.Assert.assertThat;
1411

1512
import java.io.IOException;
@@ -112,6 +109,67 @@ private enum TrafficLightColors {
112109
@SuppressWarnings("unused")
113110
private TrafficLightColors colors;
114111

112+
@Test
113+
public void generateSchemaForEnumAnnotatedString() throws NoSuchFieldException {
114+
Object schema = generateForField(getClass().getDeclaredField("colorString"));
115+
116+
assertThat(schema, hasJsonPath("$.colorString.type", equalTo("string")));
117+
assertThat(
118+
schema,
119+
hasJsonPath("$.colorString.enum", arrayContainingInAnyOrder("RED", "YELLOW", "GREEN")));
120+
}
121+
122+
@SuppressWarnings("unused")
123+
@EnumClass(TrafficLightColors.class)
124+
private String colorString;
125+
126+
@Test
127+
public void whenIntegerAnnotatedWithMinimumOnly_addToSchema() throws NoSuchFieldException {
128+
Object schema = generateForField(getClass().getDeclaredField("valueWithMinimum"));
129+
130+
assertThat(schema, hasJsonPath("$.valueWithMinimum.minimum", equalTo(7)));
131+
assertThat(schema, hasNoJsonPath("$.valueWithMinimum.maximum"));
132+
}
133+
134+
@SuppressWarnings("unused")
135+
@Range(minimum = 7)
136+
private int valueWithMinimum;
137+
138+
@Test
139+
public void whenIntegerAnnotatedWithMaximumOnly_addToSchema() throws NoSuchFieldException {
140+
Object schema = generateForField(getClass().getDeclaredField("valueWithMaximum"));
141+
142+
assertThat(schema, hasNoJsonPath("$.valueWithMaximum.minimum"));
143+
assertThat(schema, hasJsonPath("$.valueWithMaximum.maximum", equalTo(43)));
144+
}
145+
146+
@SuppressWarnings("unused")
147+
@Range(maximum = 43)
148+
private int valueWithMaximum;
149+
150+
@Test
151+
public void whenIntegerAnnotatedWithRange_addToSchema() throws NoSuchFieldException {
152+
Object schema = generateForField(getClass().getDeclaredField("valueWithRange"));
153+
154+
assertThat(schema, hasJsonPath("$.valueWithRange.minimum", equalTo(12)));
155+
assertThat(schema, hasJsonPath("$.valueWithRange.maximum", equalTo(85)));
156+
}
157+
158+
@SuppressWarnings("unused")
159+
@Range(minimum = 12, maximum = 85)
160+
private int valueWithRange;
161+
162+
@Test
163+
public void whenStringAnnotatedWithPatterne_addToSchema() throws NoSuchFieldException {
164+
Object schema = generateForField(getClass().getDeclaredField("codeName"));
165+
166+
assertThat(schema, hasJsonPath("$.codeName.pattern", equalTo("[A-Z][a-zA-Z_]*")));
167+
}
168+
169+
@SuppressWarnings("unused")
170+
@Pattern("[A-Z][a-zA-Z_]*")
171+
private String codeName;
172+
115173
@Test
116174
public void generateSchemaForAnnotatedDouble() throws NoSuchFieldException {
117175
Object schema = generateForField(getClass().getDeclaredField("annotatedDouble"));

kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain-inputs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ includeServerOutInPodLog: true
6666
# files in.
6767
# If not specified or empty, domain log file, server logs, server out, and node manager log files
6868
# will be stored in the default logHome location of /shared/logs/<domainUID>/.
69-
#logHome: /shared/logs
69+
logHome:
7070

7171
# Port for the T3Channel of the NetworkAccessPoint
7272
t3ChannelPort: 30012

kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ function createYamlFiles {
295295
domainPVMountPath="/shared"
296296
fi
297297

298+
if [ -z "${logHome}" ]; then
299+
logHome="/shared/logs/${domainUID}"
300+
fi
301+
298302
# Use the default value if not defined.
299303
if [ -z "${createDomainScriptsMountPath}" ]; then
300304
createDomainScriptsMountPath="/u01/weblogic"
@@ -377,6 +381,7 @@ function createYamlFiles {
377381
cp ${dcrInput} ${dcrOutput}
378382
sed -i -e "s:%NAMESPACE%:$namespace:g" ${dcrOutput}
379383
sed -i -e "s:%WEBLOGIC_CREDENTIALS_SECRET_NAME%:${weblogicCredentialsSecretName}:g" ${dcrOutput}
384+
sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%:${imagePullSecretPrefix}:g" ${dcrOutput}
380385
sed -i -e "s:%DOMAIN_UID%:${domainUID}:g" ${dcrOutput}
381386
sed -i -e "s:%DOMAIN_NAME%:${domainName}:g" ${dcrOutput}
382387
sed -i -e "s:%DOMAIN_HOME%:${domainHome}:g" ${dcrOutput}

kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/domain-custom-resource-template.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ spec:
3030
# imagePullPolicy defaults to "Always" if image version is :latest
3131
imagePullPolicy: "%WEBLOGIC_IMAGE_PULL_POLICY%"
3232
# Identify which Secret contains the credentials for pulling an image
33-
imagePullSecrets:
34-
- name: %WEBLOGIC_IMAGE_PULL_SECRET_NAME%
33+
%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%imagePullSecrets:
34+
%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%- name: %WEBLOGIC_IMAGE_PULL_SECRET_NAME%
3535
# Identify which Secret contains the WebLogic Admin credentials (note that there is an example of
3636
# how to create that Secret at the end of this file)
3737
adminSecret:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
5+
package oracle.kubernetes.operator;
6+
7+
public enum ImagePullPolicy {
8+
Always,
9+
Never,
10+
IfNotPresent
11+
}

0 commit comments

Comments
 (0)