Search in sources :

Example 21 with DeploymentGroup

use of com.spotify.helios.common.descriptors.DeploymentGroup in project helios by spotify.

the class DeploymentGroupStatusCommandTest method testDeploymentGroupStatusBeforeRollingUpdate.

@Test
public void testDeploymentGroupStatusBeforeRollingUpdate() throws Exception {
    final DeploymentGroup deploymentGroupWithNoJob = DeploymentGroup.newBuilder().setName(GROUP_NAME).setHostSelectors(HOST_SELECTORS).setRolloutOptions(ROLLOUT_OPTIONS).build();
    final List<DeploymentGroupStatusResponse.HostStatus> hostStatuses = Lists.newArrayList();
    hostStatuses.add(new DeploymentGroupStatusResponse.HostStatus("host1", null, null));
    hostStatuses.add(new DeploymentGroupStatusResponse.HostStatus("host2", null, null));
    hostStatuses.add(new DeploymentGroupStatusResponse.HostStatus("host3", null, null));
    final DeploymentGroupStatusResponse status = new DeploymentGroupStatusResponse(deploymentGroupWithNoJob, DeploymentGroupStatusResponse.Status.IDLE, null, hostStatuses, null);
    when(client.deploymentGroupStatus(GROUP_NAME)).thenReturn(Futures.immediateFuture(status));
    when(options.getString("name")).thenReturn(GROUP_NAME);
    final int ret = command.run(options, client, out, false, null);
    assertEquals(0, ret);
    final String output = baos.toString().replaceAll("\\s+", "");
    final String expected = format("Name: %s" + "Job Id: null" + "Status: IDLE" + "Host selectors:" + "  a = b" + "  foo = bar" + "HOST UP-TO-DATE JOB STATE" + "host1. - -" + "host2. - -" + "host3. - -", GROUP_NAME).replace(" ", "");
    assertEquals(expected, output);
}
Also used : DeploymentGroupStatusResponse(com.spotify.helios.common.protocol.DeploymentGroupStatusResponse) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) Test(org.junit.Test)

Example 22 with DeploymentGroup

use of com.spotify.helios.common.descriptors.DeploymentGroup in project helios by spotify.

the class DeploymentGroupTest method testUpdateDeploymentGroupHosts.

// A test that ensures healthy deployment groups will perform a rolling update when their hosts
// change.
@Test
public void testUpdateDeploymentGroupHosts() throws Exception {
    final ZooKeeperClient client = spy(this.client);
    final ZooKeeperMasterModel masterModel = spy(newMasterModel(client));
    // Return a job so we can add a real deployment group.
    final Job job = Job.newBuilder().setCommand(ImmutableList.of("COMMAND")).setImage("IMAGE").setName("JOB_NAME").setVersion("VERSION").build();
    doReturn(job).when(masterModel).getJob(job.getId());
    // Add a real deployment group.
    final DeploymentGroup dg = DeploymentGroup.newBuilder().setName(GROUP_NAME).setHostSelectors(ImmutableList.of(HostSelector.parse("role=melmac"))).setJobId(job.getId()).setRolloutOptions(RolloutOptions.newBuilder().build()).setRollingUpdateReason(MANUAL).build();
    masterModel.addDeploymentGroup(dg);
    // Setup some hosts
    final String oldHost = "host1";
    final String newHost = "host2";
    client.ensurePath(Paths.configHost(oldHost));
    client.ensurePath(Paths.configHost(newHost));
    client.ensurePath(Paths.statusHostUp(oldHost));
    client.ensurePath(Paths.statusHostUp(newHost));
    // Give the deployment group a host.
    client.setData(Paths.statusDeploymentGroupHosts(dg.getName()), Json.asBytes(ImmutableList.of(oldHost)));
    // And a status...
    client.setData(Paths.statusDeploymentGroup(dg.getName()), DeploymentGroupStatus.newBuilder().setState(DONE).build().toJsonBytes());
    // Switch out our host!
    // TODO(negz): Use an unchanged host, make sure ordering remains the same.
    masterModel.updateDeploymentGroupHosts(dg.getName(), ImmutableList.of(newHost));
    verify(client, times(2)).transaction(opCaptor.capture());
    final DeploymentGroup changed = dg.toBuilder().setRollingUpdateReason(HOSTS_CHANGED).build();
    // Ensure we set the DG status to HOSTS_CHANGED.
    // This means we triggered a rolling update.
    final ZooKeeperOperation setDeploymentGroupHostChanged = set(Paths.configDeploymentGroup(dg.getName()), changed);
    // Ensure ZK tasks are written to:
    // - Perform a rolling undeploy for the removed (old) host
    // - Perform a rolling update for the added (new) host and the unchanged host
    final List<RolloutTask> tasks = ImmutableList.<RolloutTask>builder().addAll(RollingUndeployPlanner.of(changed).plan(singletonList(oldHost))).addAll(RollingUpdatePlanner.of(changed).plan(singletonList(newHost))).build();
    final ZooKeeperOperation setDeploymentGroupTasks = set(Paths.statusDeploymentGroupTasks(dg.getName()), DeploymentGroupTasks.newBuilder().setRolloutTasks(tasks).setTaskIndex(0).setDeploymentGroup(changed).build());
    assertThat(opCaptor.getValue(), hasItems(setDeploymentGroupHostChanged, setDeploymentGroupTasks));
}
Also used : ZooKeeperClient(com.spotify.helios.servicescommon.coordination.ZooKeeperClient) DefaultZooKeeperClient(com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient) ZooKeeperOperation(com.spotify.helios.servicescommon.coordination.ZooKeeperOperation) RolloutTask(com.spotify.helios.common.descriptors.RolloutTask) Job(com.spotify.helios.common.descriptors.Job) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) Test(org.junit.Test)

Example 23 with DeploymentGroup

use of com.spotify.helios.common.descriptors.DeploymentGroup in project helios by spotify.

the class DeploymentGroupResourceTest method testCreateExistingSameDeploymentGroup.

@Test
public void testCreateExistingSameDeploymentGroup() throws Exception {
    final DeploymentGroup dg = mock(DeploymentGroup.class);
    when(dg.getName()).thenReturn("foo");
    when(dg.getHostSelectors()).thenReturn(Lists.newArrayList(FOO_SELECTOR));
    doThrow(new DeploymentGroupExistsException("")).when(model).addDeploymentGroup(dg);
    when(model.getDeploymentGroup("foo")).thenReturn(dg);
    final Response response = resource.createDeploymentGroup(dg);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals(new CreateDeploymentGroupResponse(CreateDeploymentGroupResponse.Status.NOT_MODIFIED), response.getEntity());
}
Also used : RemoveDeploymentGroupResponse(com.spotify.helios.common.protocol.RemoveDeploymentGroupResponse) RollingUpdateResponse(com.spotify.helios.common.protocol.RollingUpdateResponse) CreateDeploymentGroupResponse(com.spotify.helios.common.protocol.CreateDeploymentGroupResponse) Response(javax.ws.rs.core.Response) CreateDeploymentGroupResponse(com.spotify.helios.common.protocol.CreateDeploymentGroupResponse) DeploymentGroupExistsException(com.spotify.helios.master.DeploymentGroupExistsException) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) Test(org.junit.Test)

Example 24 with DeploymentGroup

use of com.spotify.helios.common.descriptors.DeploymentGroup in project helios by spotify.

the class DeploymentGroupResourceTest method testCreateExistingConflictingDeploymentGroup.

@Test
public void testCreateExistingConflictingDeploymentGroup() throws Exception {
    final DeploymentGroup dg = mock(DeploymentGroup.class);
    when(dg.getName()).thenReturn("foo");
    when(dg.getHostSelectors()).thenReturn(Lists.newArrayList(FOO_SELECTOR));
    doThrow(new DeploymentGroupExistsException("")).when(model).addDeploymentGroup(dg);
    final DeploymentGroup existing = mock(DeploymentGroup.class);
    when(existing.getHostSelectors()).thenReturn(Lists.newArrayList(BAZ_SELECTOR));
    when(model.getDeploymentGroup("foo")).thenReturn(existing);
    final Response response = resource.createDeploymentGroup(dg);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals(new CreateDeploymentGroupResponse(CreateDeploymentGroupResponse.Status.CONFLICT), response.getEntity());
}
Also used : RemoveDeploymentGroupResponse(com.spotify.helios.common.protocol.RemoveDeploymentGroupResponse) RollingUpdateResponse(com.spotify.helios.common.protocol.RollingUpdateResponse) CreateDeploymentGroupResponse(com.spotify.helios.common.protocol.CreateDeploymentGroupResponse) Response(javax.ws.rs.core.Response) CreateDeploymentGroupResponse(com.spotify.helios.common.protocol.CreateDeploymentGroupResponse) DeploymentGroupExistsException(com.spotify.helios.master.DeploymentGroupExistsException) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) Test(org.junit.Test)

Example 25 with DeploymentGroup

use of com.spotify.helios.common.descriptors.DeploymentGroup in project helios by spotify.

the class DeploymentGroupResourceTest method testGetDeploymentGroup.

@Test
public void testGetDeploymentGroup() throws Exception {
    final JobId jobId = JobId.newBuilder().setName("my_job").setVersion("0.2").setHash("1234").build();
    final DeploymentGroup dg = DeploymentGroup.newBuilder().setName("foo").setHostSelectors(ImmutableList.of(ROLE_SELECTOR, FOO_SELECTOR)).setJobId(jobId).build();
    when(model.getDeploymentGroup("foo")).thenReturn(dg);
    final Response response = resource.getDeploymentGroup("foo");
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals(dg, response.getEntity());
}
Also used : RemoveDeploymentGroupResponse(com.spotify.helios.common.protocol.RemoveDeploymentGroupResponse) RollingUpdateResponse(com.spotify.helios.common.protocol.RollingUpdateResponse) CreateDeploymentGroupResponse(com.spotify.helios.common.protocol.CreateDeploymentGroupResponse) Response(javax.ws.rs.core.Response) JobId(com.spotify.helios.common.descriptors.JobId) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) Test(org.junit.Test)

Aggregations

DeploymentGroup (com.spotify.helios.common.descriptors.DeploymentGroup)30 Test (org.junit.Test)18 RolloutTask (com.spotify.helios.common.descriptors.RolloutTask)10 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)10 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)6 ZooKeeperOperation (com.spotify.helios.servicescommon.coordination.ZooKeeperOperation)6 Job (com.spotify.helios.common.descriptors.Job)4 CreateDeploymentGroupResponse (com.spotify.helios.common.protocol.CreateDeploymentGroupResponse)4 RollingUpdateResponse (com.spotify.helios.common.protocol.RollingUpdateResponse)4 KeeperException (org.apache.zookeeper.KeeperException)4 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)4 DeploymentGroupStatus (com.spotify.helios.common.descriptors.DeploymentGroupStatus)3 HostStatus (com.spotify.helios.common.descriptors.HostStatus)3 JobId (com.spotify.helios.common.descriptors.JobId)3 RemoveDeploymentGroupResponse (com.spotify.helios.common.protocol.RemoveDeploymentGroupResponse)3 DefaultZooKeeperClient (com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient)3 IOException (java.io.IOException)3 Response (javax.ws.rs.core.Response)3 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)2 Timed (com.codahale.metrics.annotation.Timed)2