Skip to content

Commit 5c281a6

Browse files
authored
Managed server not starting with FINER logging level (#1615)
* do not chain duplicate step * createRetry should not chain duplicate steps
1 parent e687563 commit 5c281a6

File tree

3 files changed

+71
-4
lines changed

3 files changed

+71
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public NextAction onFailure(Packet packet, CallResponse<Domain> callResponse) {
228228
}
229229

230230
public Step createRetry(DomainStatusUpdaterContext context, Step next) {
231-
return Step.chain(createDomainRefreshStep(context), updaterStep, next);
231+
return Step.chain(createDomainRefreshStep(context), updaterStep);
232232
}
233233

234234
private Step createDomainRefreshStep(DomainStatusUpdaterContext context) {

operator/src/main/java/oracle/kubernetes/operator/work/Step.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,45 @@ private static int getFirstNonNullIndex(Step[] stepGroups) {
5959
}
6060

6161
private static void addLink(Step stepGroup1, Step stepGroup2) {
62-
lastStep(stepGroup1).next = stepGroup2;
62+
Step lastStep = lastStepIfNoDuplicate(stepGroup1, stepGroup2);
63+
if (lastStep != null) {
64+
// add steps in stepGroup2 to the end of stepGroup1 only if no steps
65+
// appears in both groups to avoid introducing a loop
66+
lastStep.next = stepGroup2;
67+
}
6368
}
6469

65-
private static Step lastStep(Step stepGroup) {
66-
Step s = stepGroup;
70+
/**
71+
* Return last step in stepGroup1, or null if any step appears in both step groups.
72+
*
73+
* @param stepGroup1 Step that we want to find the last step for
74+
* @param stepGroup2 Step to check for duplicates
75+
*
76+
* @return last step in stepGroup1, or null if any step appears in both step groups.
77+
*/
78+
private static Step lastStepIfNoDuplicate(Step stepGroup1, Step stepGroup2) {
79+
Step s = stepGroup1;
80+
List<Step> stepGroup2Array = stepToArray(stepGroup2);
6781
while (s.next != null) {
82+
if (stepGroup2Array.contains(s.next)) {
83+
return null;
84+
}
6885
s = s.next;
6986
}
7087
return s;
7188
}
7289

90+
private static List<Step> stepToArray(Step stepGroup) {
91+
ArrayList<Step> stepsArray = new ArrayList<>();
92+
Step s = stepGroup;
93+
while (s != null) {
94+
stepsArray.add(s);
95+
s = s.next;
96+
}
97+
return stepsArray;
98+
}
99+
100+
73101
String getName() {
74102
String name = getClass().getName();
75103
int idx = name.lastIndexOf('.');

operator/src/test/java/oracle/kubernetes/operator/work/StepChainTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,41 @@ public void whenNoNonNullSteps_throwException() throws Exception {
8282
Step.chain();
8383
}
8484

85+
@Test
86+
public void doNotChainGroupThatContainsDuplicateStep() throws Exception {
87+
Step duplicateStep = new NamedStep("duplicate", new NamedStep("two"));
88+
Step group1 = new NamedStep("one", duplicateStep);
89+
Step group2 = new NamedStep("three", duplicateStep);
90+
91+
Step chain = Step.chain(group1, group2);
92+
93+
assertThat(stepNamesInStepChain(chain), contains("one", "duplicate", "two"));
94+
}
95+
96+
@Test
97+
public void addGroupThatContainsStepsWithSameName() throws Exception {
98+
Step group1 = new NamedStep("one", new NamedStep("two"));
99+
Step group2 = new NamedStep("two", new NamedStep("three"));
100+
101+
Step chain = Step.chain(group1, group2);
102+
103+
assertThat(stepNamesInStepChain(chain), contains("one", "two", "two", "three"));
104+
}
105+
106+
private static List<String> stepNamesInStepChain(Step steps) {
107+
return stepNamesInStepChain(steps, 10);
108+
}
109+
110+
private static List<String> stepNamesInStepChain(Step steps, int maxNumSteps) {
111+
List<String> stepNames = new ArrayList<>(maxNumSteps);
112+
Step s = steps;
113+
while (s != null && stepNames.size() < maxNumSteps) {
114+
stepNames.add(s.getName());
115+
s = s.getNext();
116+
}
117+
return stepNames;
118+
}
119+
85120
private static class NamedStep extends Step {
86121
private static final String NAMES = "names";
87122
private String name;
@@ -95,6 +130,10 @@ private static class NamedStep extends Step {
95130
this.name = name;
96131
}
97132

133+
String getName() {
134+
return name;
135+
}
136+
98137
@SuppressWarnings("unchecked")
99138
private static List<String> getNames(Packet p) {
100139
return (List<String>) p.get(NAMES);

0 commit comments

Comments
 (0)