Skip to content

Commit f4585c2

Browse files
committed
Merge remote-tracking branch 'origin/develop' into domain-introspection-run
2 parents 0c7e3a9 + 6266293 commit f4585c2

File tree

56 files changed

+1358
-673
lines changed

Some content is hidden

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

56 files changed

+1358
-673
lines changed

README.md

Lines changed: 77 additions & 136 deletions
Large diffs are not rendered by default.

integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,6 @@ public static void verifyBeforeDeletion(Domain domain) throws Exception {
763763
k8sTestUtils.verifyNoReplicaSets(domain1LabelSelector);
764764
k8sTestUtils.verifyServices(domain1LabelSelector, 5);
765765
k8sTestUtils.verifyPvcs(domain1LabelSelector, 1);
766-
k8sTestUtils.verifyIngresses(domainNs, domainUid, domain1LabelSelector, 1);
767766
k8sTestUtils.verifyConfigMaps(domain1LabelSelector, 1);
768767
k8sTestUtils.verifyNoServiceAccounts(domain1LabelSelector);
769768
k8sTestUtils.verifyNoRoles(domain1LabelSelector);
@@ -790,7 +789,6 @@ public static void verifyAfterDeletion(Domain domain) throws Exception {
790789
k8sTestUtils.verifyNoReplicaSets(domain1LabelSelector);
791790
k8sTestUtils.verifyServices(domain1LabelSelector, 0);
792791
k8sTestUtils.verifyPvcs(domain1LabelSelector, 0);
793-
k8sTestUtils.verifyIngresses(domainNs, domainUid, domain1LabelSelector, 0);
794792
k8sTestUtils.verifyConfigMaps(domain1LabelSelector, 0);
795793
k8sTestUtils.verifyNoServiceAccounts(domain1LabelSelector);
796794
k8sTestUtils.verifyNoRoles(domain1LabelSelector);

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/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Sample scripts
44

5+
* [Sample secret for WebLogic admin credentials](scripts/create-weblogic-domain/create-weblogic-credentials.sh) for creating a Kubernetes secret that contains the Administration Server credentials. This secret can be used in creating a WebLogic domain custom resource.
56
* [Sample PV and PVC](scripts/create-weblogic-domain-pv-pvc/README.md) for creating a PV or PVC that can be used by a domain custom resource as the persistent storage for the WebLogic domain home or log files.
67
* [Sample domain home on a persistent volume](scripts/create-weblogic-domain/domain-home-on-pv/README.md) for creating a WebLogic domain home on an existing PV or PVC, and the domain customer resource YAML file for deploying the generated WebLogic domain.
78
* [Sample Elasticsearch and Kibana configuration](scripts/elasticsearch_and_kibana.yaml) for configuring the Elasticsearch and Kibana deployments and services for the operator's logs.

kubernetes/samples/charts/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ The Oracle WebLogic Server Kubernetes Operator supports three load balancers: TR
66

77
* [traefik](traefik/README.md)
88
* [voyager](voyager/README.md)
9-
* [apache-samples](apache-samples/README.md)
9+
* apache-samples [custom-sample](apache-samples/custom-sample/README.md)
10+
* apache-samples [default-sample](apache-samples/default-sample/README.md)
1011
* [ingress-per-domain](ingress-per-domain/README.md)
1112
* [apache-webtier](apache-webtier/README.md)
1213

0 commit comments

Comments
 (0)