Skip to content

Commit 52b33d2

Browse files
committed
Clean checkstyle
1 parent 7bb2beb commit 52b33d2

24 files changed

+427
-348
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ private void generateObjectTypeIn(Map<String, Object> result, Class<?> type) {
421421
result.put("type", "string");
422422
result.put("format", "date-time");
423423
} else {
424-
Map<String, Object> properties = new HashMap<>();
424+
final Map<String, Object> properties = new HashMap<>();
425425
List<String> requiredFields = new ArrayList<>();
426426
result.put("type", "object");
427427
if (includeAdditionalProperties) result.put("additionalProperties", "false");

operator/src/main/java/oracle/kubernetes/operator/Main.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,13 @@ private static Collection<String> getTargetNamespaces(String tnValue, String nam
422422
return targetNamespaces;
423423
}
424424

425+
private static Collection<String> getTargetNamespaces() {
426+
return getTargetNamespaces(
427+
Optional.ofNullable(System.getenv("OPERATOR_TARGET_NAMESPACES"))
428+
.orElse(tuningAndConfig.get("targetNamespaces")),
429+
operatorNamespace);
430+
}
431+
425432
private static void startRestServer(String principal, Collection<String> targetNamespaces)
426433
throws Exception {
427434
RestServer.create(new RestConfigImpl(principal, targetNamespaces));
@@ -504,13 +511,6 @@ private static String computeOperatorNamespace() {
504511
return Optional.ofNullable(System.getenv("OPERATOR_NAMESPACE")).orElse("default");
505512
}
506513

507-
private static Collection<String> getTargetNamespaces() {
508-
return getTargetNamespaces(
509-
Optional.ofNullable(System.getenv("OPERATOR_TARGET_NAMESPACES"))
510-
.orElse(tuningAndConfig.get("targetNamespaces")),
511-
operatorNamespace);
512-
}
513-
514514
private static class DomainListStep extends ResponseStep<DomainList> {
515515
private final String ns;
516516

operator/src/main/java/oracle/kubernetes/operator/calls/SynchronousCallDispatcher.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2017, 2019, 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+
15
package oracle.kubernetes.operator.calls;
26

37
import io.kubernetes.client.ApiClient;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2019, 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.helpers;
6+
7+
import java.lang.reflect.InvocationTargetException;
8+
import java.lang.reflect.Method;
9+
import java.util.Collections;
10+
import java.util.HashMap;
11+
import java.util.List;
12+
import java.util.Map;
13+
14+
class CheckFactory {
15+
static <T> CompatibilityCheck create(String description, List<T> expected, List<T> actual) {
16+
if (canBeMap(expected) && canBeMap(actual))
17+
return new CompatibleMaps<>(description, asMap(expected), asMap(actual));
18+
else return new CompatibleSets<>(description, expected, actual);
19+
}
20+
21+
private static <T> boolean canBeMap(List<T> list) {
22+
return asMap(list) != null;
23+
}
24+
25+
private static <T> Map<String, T> asMap(List<T> values) {
26+
if (values == null) return Collections.emptyMap();
27+
Map<String, T> result = new HashMap<>();
28+
for (T value : values) {
29+
String key = getKey(value);
30+
if (key == null) return null;
31+
result.put(key, value);
32+
}
33+
34+
return result;
35+
}
36+
37+
private static <T> String getKey(T value) {
38+
try {
39+
Method getKey = value.getClass().getDeclaredMethod("getName");
40+
return (String) getKey.invoke(value);
41+
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
42+
return null;
43+
}
44+
}
45+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2019, 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.helpers;
6+
7+
import java.util.ArrayList;
8+
import java.util.Collection;
9+
import java.util.List;
10+
11+
abstract class CollectiveCompatibility implements CompatibilityCheck {
12+
protected List<CompatibilityCheck> checks = new ArrayList<>();
13+
14+
void add(CompatibilityCheck check) {
15+
checks.add(check);
16+
}
17+
18+
protected <T> void add(String description, T expected, T actual) {
19+
add(new Equality(description, expected, actual));
20+
}
21+
22+
void addAll(Collection<CompatibilityCheck> checks) {
23+
this.checks.addAll(checks);
24+
}
25+
26+
@Override
27+
public boolean isCompatible() {
28+
for (CompatibilityCheck check : checks) if (!check.isCompatible()) return false;
29+
30+
return true;
31+
}
32+
33+
@Override
34+
public String getIncompatibility() {
35+
final List<String> reasons = new ArrayList<>();
36+
for (CompatibilityCheck check : checks)
37+
if (!check.isCompatible()) reasons.add(getIndent() + check.getIncompatibility());
38+
return reasons.isEmpty() ? null : getHeader() + String.join("\n", reasons);
39+
}
40+
41+
<T> void addSets(String description, List<T> expected, List<T> actual) {
42+
add(CheckFactory.create(description, expected, actual));
43+
}
44+
45+
@SuppressWarnings("SameParameterValue")
46+
<T> void addSetsIgnoring(String description, List<T> expected, List<T> actual, String... keys) {
47+
add(CheckFactory.create(description, expected, actual).ignoring(keys));
48+
}
49+
50+
String getHeader() {
51+
return "";
52+
}
53+
54+
String getIndent() {
55+
return "";
56+
}
57+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2019, 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.helpers;
6+
7+
interface CompatibilityCheck {
8+
boolean isCompatible();
9+
10+
String getIncompatibility();
11+
12+
default CompatibilityCheck ignoring(String... keys) {
13+
return this;
14+
}
15+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2019, 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.helpers;
6+
7+
import java.util.ArrayList;
8+
import java.util.Arrays;
9+
import java.util.List;
10+
import java.util.Map;
11+
import java.util.Objects;
12+
import java.util.Set;
13+
14+
import static oracle.kubernetes.operator.helpers.PodCompatibility.getMissingElements;
15+
16+
class CompatibleMaps<K, V> implements CompatibilityCheck {
17+
private final String description;
18+
private final Map<K, V> expected;
19+
private final Map<K, V> actual;
20+
private List<String> ignoredKeys = new ArrayList<>();
21+
22+
CompatibleMaps(String description, Map<K, V> expected, Map<K, V> actual) {
23+
this.description = description;
24+
this.expected = expected;
25+
this.actual = actual;
26+
}
27+
28+
@Override
29+
public boolean isCompatible() {
30+
for (K key : expected.keySet()) if (isKeyToCheck(key) && isIncompatible(key)) return false;
31+
return true;
32+
}
33+
34+
private boolean isKeyToCheck(K key) {
35+
return !ignoredKeys.contains(key.toString());
36+
}
37+
38+
private boolean isIncompatible(K key) {
39+
return !actual.containsKey(key) || valuesDiffer(key);
40+
}
41+
42+
private boolean valuesDiffer(K key) {
43+
return !Objects.equals(expected.get(key), actual.get(key));
44+
}
45+
46+
@Override
47+
public String getIncompatibility() {
48+
StringBuilder sb = new StringBuilder();
49+
50+
Set<K> missingKeys = getMissingElements(expected.keySet(), actual.keySet());
51+
if (!missingKeys.isEmpty())
52+
sb.append(String.format("actual %s has no entry for '%s'%n", description, missingKeys));
53+
54+
for (K key : expected.keySet())
55+
if (isKeyToCheck(key) && actual.containsKey(key) && valuesDiffer(key))
56+
sb.append(
57+
String.format(
58+
"actual %s has entry '%s' with value '%s' rather than '%s'%n",
59+
description, key, actual.get(key), expected.get(key)));
60+
61+
return sb.toString();
62+
}
63+
64+
@Override
65+
public CompatibilityCheck ignoring(String... keys) {
66+
ignoredKeys.addAll(Arrays.asList(keys));
67+
return this;
68+
}
69+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2019, 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.helpers;
6+
7+
import java.util.Collection;
8+
9+
import static oracle.kubernetes.operator.helpers.PodCompatibility.asSet;
10+
import static oracle.kubernetes.operator.helpers.PodCompatibility.getMissingElements;
11+
12+
class CompatibleSets<T> implements CompatibilityCheck {
13+
private String description;
14+
private final Collection<T> expected;
15+
private final Collection<T> actual;
16+
17+
CompatibleSets(String description, Collection<T> expected, Collection<T> actual) {
18+
this.description = description;
19+
this.expected = expected;
20+
this.actual = actual;
21+
}
22+
23+
@Override
24+
public boolean isCompatible() {
25+
if (expected == actual) return true;
26+
return asSet(actual).containsAll(asSet(expected));
27+
}
28+
29+
@Override
30+
public String getIncompatibility() {
31+
return String.format(
32+
"actual %s does not have %s", description, getMissingElements(expected, actual));
33+
}
34+
}

operator/src/main/java/oracle/kubernetes/operator/helpers/ConflictRetry.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
public interface ConflictRetry<T> {
1616

1717
/**
18+
* The latest version of the kubernetes object for passing to the kubernetes API, or null if the
19+
* API should not be retried.
20+
*
1821
* @return The latest version of the kubernetes object for passing to the kubernetes API, or null
1922
* if the API should not be retried.
2023
*/

operator/src/main/java/oracle/kubernetes/operator/helpers/DomainPresenceInfo.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ private V1ObjectMeta getMetadata(V1Pod pod) {
188188
return pod == null ? null : pod.getMetadata();
189189
}
190190

191+
private V1ObjectMeta getMetadata(V1Service service) {
192+
return service == null ? null : service.getMetadata();
193+
}
194+
191195
/**
192196
* Computes the result of a delete attempt. If the current pod is newer than the one associated
193197
* with the delete event, returns it; otherwise returns null, thus deleting the value.
@@ -209,6 +213,18 @@ private V1Pod getNewerCurrentOrNull(V1Pod pod, V1Pod event) {
209213
return KubernetesUtils.isFirstNewer(getMetadata(pod), getMetadata(event)) ? pod : null;
210214
}
211215

216+
/**
217+
* Computes the result of a delete attempt. If the current service is newer than the one
218+
* associated with the delete event, returns it; otherwise returns null, thus deleting the value.
219+
*
220+
* @param service the current service
221+
* @param event the service associated with the delete event
222+
* @return the new value for the service.
223+
*/
224+
private V1Service getNewerCurrentOrNull(V1Service service, V1Service event) {
225+
return KubernetesUtils.isFirstNewer(getMetadata(service), getMetadata(event)) ? service : null;
226+
}
227+
212228
/**
213229
* Removes the pod associated with the specified server name, if any.
214230
*
@@ -277,18 +293,6 @@ boolean deleteServerServiceFromEvent(String serverName, V1Service event) {
277293
return deletedService != null;
278294
}
279295

280-
/**
281-
* Computes the result of a delete attempt. If the current service is newer than the one
282-
* associated with the delete event, returns it; otherwise returns null, thus deleting the value.
283-
*
284-
* @param service the current service
285-
* @param event the service associated with the delete event
286-
* @return the new value for the service.
287-
*/
288-
private V1Service getNewerCurrentOrNull(V1Service service, V1Service event) {
289-
return KubernetesUtils.isFirstNewer(getMetadata(service), getMetadata(event)) ? service : null;
290-
}
291-
292296
void removeClusterService(String clusterName) {
293297
clusters.remove(clusterName);
294298
}
@@ -328,10 +332,6 @@ private V1Service getNewerService(V1Service first, V1Service second) {
328332
return KubernetesUtils.isFirstNewer(getMetadata(first), getMetadata(second)) ? first : second;
329333
}
330334

331-
private V1ObjectMeta getMetadata(V1Service service) {
332-
return service == null ? null : service.getMetadata();
333-
}
334-
335335
public V1Service getExternalService(String serverName) {
336336
return getSko(serverName).getExternalService().get();
337337
}

0 commit comments

Comments
 (0)