Search in sources :

Example 1 with CreateDeploymentGroupResponse

use of com.spotify.helios.common.protocol.CreateDeploymentGroupResponse in project helios by spotify.

the class DeploymentGroupCreateCommand method run.

@Override
int run(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final BufferedReader stdin) throws ExecutionException, InterruptedException, IOException {
    final String name = options.getString(nameArg.getDest());
    final List<HostSelector> hostSelectors = Utils.parseHostSelectors(options, hostSelectorsArg);
    final boolean quiet = options.getBoolean(quietArg.getDest());
    final DeploymentGroup deploymentGroup = DeploymentGroup.newBuilder().setName(name).setHostSelectors(hostSelectors).build();
    if (!quiet && !json) {
        out.println("Creating deployment group: " + deploymentGroup.toJsonString());
    }
    final CreateDeploymentGroupResponse status = client.createDeploymentGroup(deploymentGroup).get();
    if (status == null) {
        throw new RuntimeException("The Helios master could not create a deployment group.");
    }
    if (status.getStatus() != CreateDeploymentGroupResponse.Status.CONFLICT) {
        out.println(status.toJsonString());
        return 0;
    } else {
        if (!quiet && !json) {
            out.println("Failed: " + status);
        } else if (json) {
            out.println(status.toJsonString());
        }
        return 1;
    }
}
Also used : CreateDeploymentGroupResponse(com.spotify.helios.common.protocol.CreateDeploymentGroupResponse) HostSelector(com.spotify.helios.common.descriptors.HostSelector) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup)

Example 2 with CreateDeploymentGroupResponse

use of com.spotify.helios.common.protocol.CreateDeploymentGroupResponse in project helios by spotify.

the class DeploymentGroupResourceTest method testCreateNewDeploymentGroup.

@Test
public void testCreateNewDeploymentGroup() {
    final Response response = resource.createDeploymentGroup(mock(DeploymentGroup.class));
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals(new CreateDeploymentGroupResponse(CreateDeploymentGroupResponse.Status.CREATED), 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) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) Test(org.junit.Test)

Example 3 with CreateDeploymentGroupResponse

use of com.spotify.helios.common.protocol.CreateDeploymentGroupResponse 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 4 with CreateDeploymentGroupResponse

use of com.spotify.helios.common.protocol.CreateDeploymentGroupResponse 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)

Aggregations

DeploymentGroup (com.spotify.helios.common.descriptors.DeploymentGroup)4 CreateDeploymentGroupResponse (com.spotify.helios.common.protocol.CreateDeploymentGroupResponse)4 RemoveDeploymentGroupResponse (com.spotify.helios.common.protocol.RemoveDeploymentGroupResponse)3 RollingUpdateResponse (com.spotify.helios.common.protocol.RollingUpdateResponse)3 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)3 DeploymentGroupExistsException (com.spotify.helios.master.DeploymentGroupExistsException)2 HostSelector (com.spotify.helios.common.descriptors.HostSelector)1