Navigation Menu

Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.

Commit

Permalink
Fix deployment group status when no rolling-update
Browse files Browse the repository at this point in the history
  • Loading branch information
davidxia committed Jul 16, 2015
1 parent 8269042 commit 9f8cc39
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
Expand Up @@ -39,7 +39,8 @@ public class DeploymentGroupStatusResponse {
public enum Status { public enum Status {
ROLLING_OUT, ROLLING_OUT,
ACTIVE, ACTIVE,
FAILED FAILED,
IDLE
} }


public static class HostStatus { public static class HostStatus {
Expand Down Expand Up @@ -112,12 +113,12 @@ public DeploymentGroupStatusResponse(
@JsonProperty("status") final Status status, @JsonProperty("status") final Status status,
@JsonProperty("error") final String error, @JsonProperty("error") final String error,
@JsonProperty("hostStatuses") final List<HostStatus> hostStatuses, @JsonProperty("hostStatuses") final List<HostStatus> hostStatuses,
@JsonProperty("deploymentGroupStatus") final DeploymentGroupStatus deploymentGroupStatus) { @JsonProperty("deploymentGroupStatus") @Nullable final DeploymentGroupStatus dgs) {
this.deploymentGroup = deploymentGroup; this.deploymentGroup = deploymentGroup;
this.status = status; this.status = status;
this.error = error; this.error = error;
this.hostStatuses = hostStatuses; this.hostStatuses = hostStatuses;
this.deploymentGroupStatus = deploymentGroupStatus; this.deploymentGroupStatus = dgs;
} }


public DeploymentGroup getDeploymentGroup() { public DeploymentGroup getDeploymentGroup() {
Expand Down
Expand Up @@ -512,6 +512,12 @@ public void rollingUpdateStep(final DeploymentGroup deploymentGroup,
final String statusPath = Paths.statusDeploymentGroup(deploymentGroup.getName()); final String statusPath = Paths.statusDeploymentGroup(deploymentGroup.getName());
final DeploymentGroupStatus status = getDeploymentGroupStatus(deploymentGroup.getName()); final DeploymentGroupStatus status = getDeploymentGroupStatus(deploymentGroup.getName());


if (status == null) {
// The rolling-update command hasn't been called yet for this deployment group.
// The deployment group status doesn't exist yet and there's nothing to do.
return;
}

final List<ZooKeeperOperation> operations = Lists.newArrayList(); final List<ZooKeeperOperation> operations = Lists.newArrayList();


if (status.getState().equals(PLANNING_ROLLOUT)) { if (status.getState().equals(PLANNING_ROLLOUT)) {
Expand Down Expand Up @@ -785,7 +791,13 @@ public DeploymentGroupStatus getDeploymentGroupStatus(final String name)


try { try {
final Node node = client.getNode(Paths.statusDeploymentGroup(name)); final Node node = client.getNode(Paths.statusDeploymentGroup(name));
final DeploymentGroupStatus status = Json.read(node.getBytes(), DeploymentGroupStatus.class);
final byte[] bytes = node.getBytes();
if (bytes.length == 0) {
return null;
}

final DeploymentGroupStatus status = Json.read(bytes, DeploymentGroupStatus.class);
return status.toBuilder() return status.toBuilder()
.setVersion(node.getStat().getVersion()) .setVersion(node.getStat().getVersion())
.build(); .build();
Expand Down
Expand Up @@ -183,10 +183,6 @@ public Response getDeploymentGroupStatus(@PathParam("name") @Valid final String
final DeploymentGroup deploymentGroup = model.getDeploymentGroup(name); final DeploymentGroup deploymentGroup = model.getDeploymentGroup(name);
final DeploymentGroupStatus deploymentGroupStatus = model.getDeploymentGroupStatus(name); final DeploymentGroupStatus deploymentGroupStatus = model.getDeploymentGroupStatus(name);


if (deploymentGroupStatus == null) {
throw new DeploymentGroupDoesNotExistException(name);
}

final List<String> hosts = model.getDeploymentGroupHosts(name); final List<String> hosts = model.getDeploymentGroupHosts(name);


final List<DeploymentGroupStatusResponse.HostStatus> result = Lists.newArrayList(); final List<DeploymentGroupStatusResponse.HostStatus> result = Lists.newArrayList();
Expand All @@ -213,18 +209,19 @@ public Response getDeploymentGroupStatus(@PathParam("name") @Valid final String
} }


final DeploymentGroupStatusResponse.Status status; final DeploymentGroupStatusResponse.Status status;
if (deploymentGroupStatus.getState() == DeploymentGroupStatus.State.FAILED) { if (deploymentGroupStatus == null) {
status = DeploymentGroupStatusResponse.Status.IDLE;
} else if (deploymentGroupStatus.getState() == DeploymentGroupStatus.State.FAILED) {
status = DeploymentGroupStatusResponse.Status.FAILED; status = DeploymentGroupStatusResponse.Status.FAILED;
} else if (deploymentGroupStatus.getSuccessfulIterations() > 0) { } else if (deploymentGroupStatus.getSuccessfulIterations() > 0) {
status = DeploymentGroupStatusResponse.Status.ACTIVE; status = DeploymentGroupStatusResponse.Status.ACTIVE;
} else { } else {
status = DeploymentGroupStatusResponse.Status.ROLLING_OUT; status = DeploymentGroupStatusResponse.Status.ROLLING_OUT;
} }


final String error = deploymentGroupStatus == null ? "" : deploymentGroupStatus.getError();
return Response.ok(new DeploymentGroupStatusResponse( return Response.ok(new DeploymentGroupStatusResponse(
deploymentGroup, status, deploymentGroupStatus.getError(), deploymentGroup, status, error, result, deploymentGroupStatus)).build();
result, deploymentGroupStatus))
.build();
} catch (final DeploymentGroupDoesNotExistException e) { } catch (final DeploymentGroupDoesNotExistException e) {
return Response.status(Response.Status.NOT_FOUND).build(); return Response.status(Response.Status.NOT_FOUND).build();
} }
Expand Down
Expand Up @@ -176,6 +176,14 @@ public void testRollingUpdateGroupNotFound() throws Exception {
RollingUpdateResponse.class).getStatus()); RollingUpdateResponse.class).getStatus());
} }


@Test
public void testStatusNoRollingUpdate() throws Exception {
cli("create-deployment-group", "--json", TEST_GROUP, "foo=bar", "baz=qux");
assertEquals(DeploymentGroupStatusResponse.Status.IDLE,
OBJECT_MAPPER.readValue(cli("status-deployment-group", "--json", TEST_GROUP),
DeploymentGroupStatusResponse.class).getStatus());
}

@Test @Test
public void testRollingUpdateMigrate() throws Exception { public void testRollingUpdateMigrate() throws Exception {
final String host = testHost(); final String host = testHost();
Expand Down

0 comments on commit 9f8cc39

Please sign in to comment.