Skip to content

Commit

Permalink
Resolve #1211 | Changes after code review; admin endpoint accepts Rea…
Browse files Browse the repository at this point in the history
…dOnlyAdmin flag as well
  • Loading branch information
milena.krawczyk committed Jun 15, 2020
1 parent d54d18a commit 002db3d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ public Response setMode(@QueryParam("mode") String mode) {
}
switch (mode) {
case ModeService.READ_WRITE:
modeService.setMode(READ_WRITE);
modeService.setModeByAdmin(READ_WRITE);
break;
case ModeService.READ_ONLY:
modeService.setMode(READ_ONLY_ADMIN);
case ModeService.READ_ONLY_ADMIN:
modeService.setModeByAdmin(READ_ONLY_ADMIN);
break;
default:
return Response.status(Response.Status.BAD_REQUEST).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ private HealthCheckResult doHealthCheck(ZookeeperClient zookeeperClient) {

private void updateMode(List<HealthCheckResult> healthCheckResults) {
if (healthCheckResults.contains(HealthCheckResult.UNHEALTHY)) {
modeService.compareAndSwapMode(ModeService.ManagementMode.READ_WRITE, ModeService.ManagementMode.READ_ONLY);
modeService.setMode(ModeService.ManagementMode.READ_ONLY);
} else {
modeService.compareAndSwapMode(ModeService.ManagementMode.READ_ONLY, ModeService.ManagementMode.READ_WRITE);
modeService.setMode(ModeService.ManagementMode.READ_WRITE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ public ManagementMode getMode() {
return mode;
}

public synchronized void setMode(ManagementMode mode) {
public synchronized void setModeByAdmin(ManagementMode mode) {
this.mode = mode;
}

public boolean isReadOnlyEnabled() {
return mode == ManagementMode.READ_ONLY || mode == ManagementMode.READ_ONLY_ADMIN;
}

public synchronized void compareAndSwapMode(ManagementMode expectedMode, ManagementMode newMode) {
if (mode.equals(expectedMode)) {
setMode(newMode);
public synchronized void setMode(ManagementMode newMode) {
/* READ_ONLY_ADMIN is a flag that can be changed only by admin */
if (!mode.equals(ManagementMode.READ_ONLY_ADMIN)) {
this.mode = newMode;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ class HealthCheckTaskTest extends MultiZookeeperIntegrationTest {

def "should not change status to READ_WRITE if READ_ONLY is set by admin"() {
given:
modeService.setMode(ModeService.ManagementMode.READ_ONLY_ADMIN)
modeService.setModeByAdmin(ModeService.ManagementMode.READ_ONLY_ADMIN)

when:
zookeeper1.start()
healthCheckTask.run()

then:
Expand All @@ -107,17 +106,16 @@ class HealthCheckTaskTest extends MultiZookeeperIntegrationTest {

def "should change status from READ_ONLY_ADMIN to READ_WRITE only by admin"() {
given:
modeService.setMode(ModeService.ManagementMode.READ_ONLY_ADMIN)
modeService.setModeByAdmin(ModeService.ManagementMode.READ_ONLY_ADMIN)

when:
zookeeper1.start()
healthCheckTask.run()

then:
modeService.readOnlyEnabled

when:
modeService.setMode(ModeService.ManagementMode.READ_WRITE)
modeService.setModeByAdmin(ModeService.ManagementMode.READ_WRITE)

then:
!modeService.readOnlyEnabled
Expand Down

0 comments on commit 002db3d

Please sign in to comment.