Skip to content

Commit df63a85

Browse files
authored
fix: ensure B/G monitor instances are set up (#1612)
1 parent b0f2ba2 commit df63a85

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

wrapper/src/main/java/software/amazon/jdbc/plugin/bluegreen/BlueGreenStatusMonitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ public BlueGreenStatusMonitor(
141141
this.onBlueGreenStatusChangeFunc = onBlueGreenStatusChangeFunc;
142142

143143
this.blueGreenDialect = (BlueGreenDialect) this.pluginService.getDialect();
144+
}
144145

146+
public void start() {
145147
executorService.submit(this::runMonitoringLoop);
146148
executorService.shutdown(); // executor accepts no more tasks
147149
}

wrapper/src/main/java/software/amazon/jdbc/plugin/bluegreen/BlueGreenStatusProvider.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.List;
2626
import java.util.Map;
2727
import java.util.Map.Entry;
28+
import java.util.Objects;
2829
import java.util.Optional;
2930
import java.util.Properties;
3031
import java.util.Set;
@@ -158,7 +159,7 @@ public BlueGreenStatusProvider(
158159
}
159160

160161
protected void initMonitoring() {
161-
monitors[BlueGreenRole.SOURCE.getValue()] =
162+
final BlueGreenStatusMonitor sourceMonitor =
162163
new BlueGreenStatusMonitor(
163164
BlueGreenRole.SOURCE,
164165
this.bgdId,
@@ -167,7 +168,10 @@ protected void initMonitoring() {
167168
this.getMonitoringProperties(),
168169
statusCheckIntervalMap,
169170
this::prepareStatus);
170-
monitors[BlueGreenRole.TARGET.getValue()] =
171+
monitors[BlueGreenRole.SOURCE.getValue()] = sourceMonitor;
172+
sourceMonitor.start();
173+
174+
final BlueGreenStatusMonitor targetMonitor =
171175
new BlueGreenStatusMonitor(
172176
BlueGreenRole.TARGET,
173177
this.bgdId,
@@ -176,6 +180,8 @@ protected void initMonitoring() {
176180
this.getMonitoringProperties(),
177181
statusCheckIntervalMap,
178182
this::prepareStatus);
183+
monitors[BlueGreenRole.TARGET.getValue()] = targetMonitor;
184+
targetMonitor.start();
179185
}
180186

181187
protected Properties getMonitoringProperties() {
@@ -448,15 +454,15 @@ protected void updateSummaryStatus(BlueGreenRole role, BlueGreenInterimStatus in
448454
protected void updateMonitors() {
449455
switch (this.summaryStatus.getCurrentPhase()) {
450456
case NOT_CREATED:
451-
Arrays.stream(this.monitors).forEach(x -> {
457+
Arrays.stream(this.monitors).filter(Objects::nonNull).forEach(x -> {
452458
x.setIntervalRate(BlueGreenIntervalRate.BASELINE);
453459
x.setCollectIpAddresses(false);
454460
x.setCollectTopology(false);
455461
x.setUseIpAddress(false);
456462
});
457463
break;
458464
case CREATED:
459-
Arrays.stream(this.monitors).forEach(x -> {
465+
Arrays.stream(this.monitors).filter(Objects::nonNull).forEach(x -> {
460466
x.setIntervalRate(BlueGreenIntervalRate.INCREASED);
461467
x.setCollectIpAddresses(true);
462468
x.setCollectTopology(true);
@@ -469,15 +475,15 @@ protected void updateMonitors() {
469475
case PREPARATION:
470476
case IN_PROGRESS:
471477
case POST:
472-
Arrays.stream(this.monitors).forEach(x -> {
478+
Arrays.stream(this.monitors).filter(Objects::nonNull).forEach(x -> {
473479
x.setIntervalRate(BlueGreenIntervalRate.HIGH);
474480
x.setCollectIpAddresses(false);
475481
x.setCollectTopology(false);
476482
x.setUseIpAddress(true);
477483
});
478484
break;
479485
case COMPLETED:
480-
Arrays.stream(this.monitors).forEach(x -> {
486+
Arrays.stream(this.monitors).filter(Objects::nonNull).forEach(x -> {
481487
x.setIntervalRate(BlueGreenIntervalRate.BASELINE);
482488
x.setCollectIpAddresses(false);
483489
x.setCollectTopology(false);

0 commit comments

Comments
 (0)