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;
}
}
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());
}
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());
}
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());
}
Aggregations