Skip to content

Commit 83f2610

Browse files
authored
Merge pull request #234 from oracle/april_cleanup_corrected
April cleanup corrected
2 parents 115841b + 594a559 commit 83f2610

Some content is hidden

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

42 files changed

+2418
-1451
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 http://oss.oracle.com/licenses/upl.
3+
4+
package oracle.kubernetes.operator;
5+
6+
import java.util.ArrayList;
7+
import java.util.concurrent.ScheduledFuture;
8+
9+
import oracle.kubernetes.operator.helpers.DomainPresenceInfo;
10+
import oracle.kubernetes.weblogic.domain.v1.ClusterStartup;
11+
import oracle.kubernetes.weblogic.domain.v1.DomainSpec;
12+
import oracle.kubernetes.weblogic.domain.v1.ServerStartup;
13+
14+
class DomainPresenceControl {
15+
16+
// This method fills in null values which would interfere with the general DomainSpec.equals() method
17+
static void normalizeDomainSpec(DomainSpec spec) {
18+
normalizeImage(spec);
19+
normalizeImagePullPolicy(spec);
20+
normalizeExportT3Channels(spec);
21+
normalizeStartupControl(spec);
22+
normalizeServerStartup(spec);
23+
normalizeClusterStartup(spec);
24+
normalizeReplicas(spec);
25+
}
26+
27+
private static void normalizeImage(DomainSpec spec) {
28+
if (isNotDefined(spec.getImage())) spec.setImage(KubernetesConstants.DEFAULT_IMAGE);
29+
}
30+
31+
private static void normalizeImagePullPolicy(DomainSpec spec) {
32+
if (isNotDefined(spec.getImagePullPolicy())) {
33+
spec.setImagePullPolicy((spec.getImage().endsWith(KubernetesConstants.LATEST_IMAGE_SUFFIX))
34+
? KubernetesConstants.ALWAYS_IMAGEPULLPOLICY
35+
: KubernetesConstants.IFNOTPRESENT_IMAGEPULLPOLICY);
36+
}
37+
}
38+
39+
private static void normalizeExportT3Channels(DomainSpec spec) {
40+
if (spec.getExportT3Channels() == null)
41+
spec.setExportT3Channels(new ArrayList<>());
42+
}
43+
44+
private static void normalizeStartupControl(DomainSpec spec) {
45+
if (isNotDefined(spec.getStartupControl()))
46+
spec.setStartupControl(StartupControlConstants.AUTO_STARTUPCONTROL);
47+
}
48+
49+
private static void normalizeServerStartup(DomainSpec spec) {
50+
if (spec.getServerStartup() == null)
51+
spec.setServerStartup(new ArrayList<>());
52+
else
53+
for (ServerStartup ss : spec.getServerStartup()) {
54+
if (ss.getDesiredState() == null) ss.setDesiredState(WebLogicConstants.RUNNING_STATE);
55+
if (ss.getEnv() == null) ss.setEnv(new ArrayList<>());
56+
}
57+
}
58+
59+
private static void normalizeClusterStartup(DomainSpec spec) {
60+
if (spec.getClusterStartup() == null)
61+
spec.setClusterStartup(new ArrayList<>());
62+
else
63+
for (ClusterStartup cs : spec.getClusterStartup()) {
64+
if (cs.getDesiredState() == null) cs.setDesiredState(WebLogicConstants.RUNNING_STATE);
65+
if (cs.getEnv() == null) cs.setEnv(new ArrayList<>());
66+
if (cs.getReplicas() == null) cs.setReplicas(1);
67+
}
68+
}
69+
70+
private static void normalizeReplicas(DomainSpec spec) {
71+
if (spec.getReplicas() == null) spec.setReplicas(1);
72+
}
73+
74+
private static boolean isNotDefined(String value) {
75+
return value == null || value.length() == 0;
76+
}
77+
78+
static void cancelDomainStatusUpdating(DomainPresenceInfo info) {
79+
ScheduledFuture<?> statusUpdater = info.getStatusUpdater().getAndSet(null);
80+
if (statusUpdater != null) {
81+
statusUpdater.cancel(true);
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)