Search in sources :

Example 1 with DeploymentGroupDoesNotExistException

use of com.spotify.helios.master.DeploymentGroupDoesNotExistException in project helios by spotify.

the class DeploymentGroupResourceTest method testRollingUpdateDeploymentGroupDoesNotExist.

@Test
public void testRollingUpdateDeploymentGroupDoesNotExist() throws Exception {
    doThrow(new DeploymentGroupDoesNotExistException("")).when(model).rollingUpdate(any(DeploymentGroup.class), any(JobId.class), any(RolloutOptions.class));
    final Response response = resource.rollingUpdate("foo", new RollingUpdateRequest(new JobId("foo", "0.3", "1234"), RolloutOptions.newBuilder().build()));
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals(new RollingUpdateResponse(RollingUpdateResponse.Status.DEPLOYMENT_GROUP_NOT_FOUND), response.getEntity());
}
Also used : RolloutOptions(com.spotify.helios.common.descriptors.RolloutOptions) 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) RollingUpdateRequest(com.spotify.helios.common.protocol.RollingUpdateRequest) DeploymentGroupDoesNotExistException(com.spotify.helios.master.DeploymentGroupDoesNotExistException) RollingUpdateResponse(com.spotify.helios.common.protocol.RollingUpdateResponse) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 2 with DeploymentGroupDoesNotExistException

use of com.spotify.helios.master.DeploymentGroupDoesNotExistException in project helios by spotify.

the class DeploymentGroupResource method rollingUpdate.

@POST
@Path("/{name}/rolling-update")
@Produces(APPLICATION_JSON)
@Timed
@ExceptionMetered
public Response rollingUpdate(@PathParam("name") @Valid final String name, @Valid final RollingUpdateRequest args) {
    try {
        final DeploymentGroup deploymentGroup = model.getDeploymentGroup(name);
        model.rollingUpdate(deploymentGroup, args.getJob(), args.getRolloutOptions());
        return Response.ok(new RollingUpdateResponse(RollingUpdateResponse.Status.OK)).build();
    } catch (DeploymentGroupDoesNotExistException e) {
        return Response.ok(new RollingUpdateResponse(RollingUpdateResponse.Status.DEPLOYMENT_GROUP_NOT_FOUND)).build();
    } catch (JobDoesNotExistException e) {
        return Response.ok(new RollingUpdateResponse(RollingUpdateResponse.Status.JOB_NOT_FOUND)).build();
    }
}
Also used : JobDoesNotExistException(com.spotify.helios.master.JobDoesNotExistException) RollingUpdateResponse(com.spotify.helios.common.protocol.RollingUpdateResponse) DeploymentGroupDoesNotExistException(com.spotify.helios.master.DeploymentGroupDoesNotExistException) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Example 3 with DeploymentGroupDoesNotExistException

use of com.spotify.helios.master.DeploymentGroupDoesNotExistException in project helios by spotify.

the class DeploymentGroupResource method getDeploymentGroupStatus.

@GET
@Path("/{name}/status")
@Produces(APPLICATION_JSON)
@Timed
@ExceptionMetered
public Response getDeploymentGroupStatus(@PathParam("name") @Valid final String name) {
    try {
        final DeploymentGroup deploymentGroup = model.getDeploymentGroup(name);
        final DeploymentGroupStatus deploymentGroupStatus = model.getDeploymentGroupStatus(name);
        final List<String> hosts = model.getDeploymentGroupHosts(name);
        final List<DeploymentGroupStatusResponse.HostStatus> result = Lists.newArrayList();
        for (final String host : hosts) {
            final HostStatus hostStatus = model.getHostStatus(host);
            JobId deployedJobId = null;
            TaskStatus.State state = null;
            if (hostStatus != null && hostStatus.getStatus().equals(HostStatus.Status.UP)) {
                for (final Map.Entry<JobId, Deployment> entry : hostStatus.getJobs().entrySet()) {
                    if (name.equals(entry.getValue().getDeploymentGroupName())) {
                        deployedJobId = entry.getKey();
                        final TaskStatus taskStatus = hostStatus.getStatuses().get(deployedJobId);
                        if (taskStatus != null) {
                            state = taskStatus.getState();
                        }
                        break;
                    }
                }
                result.add(new DeploymentGroupStatusResponse.HostStatus(host, deployedJobId, state));
            }
        }
        final DeploymentGroupStatusResponse.Status status;
        if (deploymentGroupStatus == null) {
            status = DeploymentGroupStatusResponse.Status.IDLE;
        } else if (deploymentGroupStatus.getState() == DeploymentGroupStatus.State.FAILED) {
            status = DeploymentGroupStatusResponse.Status.FAILED;
        } else if (deploymentGroupStatus.getState() == DeploymentGroupStatus.State.ROLLING_OUT) {
            status = DeploymentGroupStatusResponse.Status.ROLLING_OUT;
        } else {
            status = DeploymentGroupStatusResponse.Status.ACTIVE;
        }
        final String error = deploymentGroupStatus == null ? "" : deploymentGroupStatus.getError();
        return Response.ok(new DeploymentGroupStatusResponse(deploymentGroup, status, error, result, deploymentGroupStatus)).build();
    } catch (final DeploymentGroupDoesNotExistException e) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
}
Also used : Deployment(com.spotify.helios.common.descriptors.Deployment) DeploymentGroupStatus(com.spotify.helios.common.descriptors.DeploymentGroupStatus) DeploymentGroupDoesNotExistException(com.spotify.helios.master.DeploymentGroupDoesNotExistException) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) DeploymentGroupStatusResponse(com.spotify.helios.common.protocol.DeploymentGroupStatusResponse) HostStatus(com.spotify.helios.common.descriptors.HostStatus) Map(java.util.Map) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) JobId(com.spotify.helios.common.descriptors.JobId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Example 4 with DeploymentGroupDoesNotExistException

use of com.spotify.helios.master.DeploymentGroupDoesNotExistException in project helios by spotify.

the class DeploymentGroupResourceTest method testGetNonExistingDeploymentGroup.

@Test
public void testGetNonExistingDeploymentGroup() throws Exception {
    when(model.getDeploymentGroup(anyString())).thenThrow(new DeploymentGroupDoesNotExistException(""));
    final Response response = resource.getDeploymentGroup("foobar");
    assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
}
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) DeploymentGroupDoesNotExistException(com.spotify.helios.master.DeploymentGroupDoesNotExistException) Test(org.junit.Test)

Example 5 with DeploymentGroupDoesNotExistException

use of com.spotify.helios.master.DeploymentGroupDoesNotExistException in project helios by spotify.

the class DeploymentGroupResourceTest method testRemoveNonExistingDeploymentGroup.

@Test
public void testRemoveNonExistingDeploymentGroup() throws Exception {
    doThrow(new DeploymentGroupDoesNotExistException("")).when(model).removeDeploymentGroup(anyString());
    final Response response = resource.removeDeploymentGroup("foo");
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals(new RemoveDeploymentGroupResponse(RemoveDeploymentGroupResponse.Status.DEPLOYMENT_GROUP_NOT_FOUND), 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) DeploymentGroupDoesNotExistException(com.spotify.helios.master.DeploymentGroupDoesNotExistException) RemoveDeploymentGroupResponse(com.spotify.helios.common.protocol.RemoveDeploymentGroupResponse) Test(org.junit.Test)

Aggregations

DeploymentGroupDoesNotExistException (com.spotify.helios.master.DeploymentGroupDoesNotExistException)5 RollingUpdateResponse (com.spotify.helios.common.protocol.RollingUpdateResponse)4 DeploymentGroup (com.spotify.helios.common.descriptors.DeploymentGroup)3 CreateDeploymentGroupResponse (com.spotify.helios.common.protocol.CreateDeploymentGroupResponse)3 RemoveDeploymentGroupResponse (com.spotify.helios.common.protocol.RemoveDeploymentGroupResponse)3 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)3 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)2 Timed (com.codahale.metrics.annotation.Timed)2 JobId (com.spotify.helios.common.descriptors.JobId)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Deployment (com.spotify.helios.common.descriptors.Deployment)1 DeploymentGroupStatus (com.spotify.helios.common.descriptors.DeploymentGroupStatus)1 HostStatus (com.spotify.helios.common.descriptors.HostStatus)1 RolloutOptions (com.spotify.helios.common.descriptors.RolloutOptions)1 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)1 DeploymentGroupStatusResponse (com.spotify.helios.common.protocol.DeploymentGroupStatusResponse)1 RollingUpdateRequest (com.spotify.helios.common.protocol.RollingUpdateRequest)1 JobDoesNotExistException (com.spotify.helios.master.JobDoesNotExistException)1