@POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response installSlot(@HeaderParam(GALAXY_AGENT_VERSION_HEADER) String agentVersion, InstallationRepresentation installation, @Context UriInfo uriInfo) { Preconditions.checkNotNull(installation, "installation must not be null"); checkAgentVersion(agent.getAgentStatus(), agentVersion); SlotStatus slotStatus = agent.install(installation.toInstallation()); return Response .created(getSelfUri(slotStatus.getId(), uriInfo.getBaseUri())) .entity(SlotStatusRepresentation.from(slotStatus)) .header(GALAXY_AGENT_VERSION_HEADER, agent.getAgentStatus().getVersion()) .header(GALAXY_SLOT_VERSION_HEADER, slotStatus.getVersion()) .build(); }
@Path("{slotId}") @DELETE public Response terminateSlot(@HeaderParam(GALAXY_AGENT_VERSION_HEADER) String agentVersion, @HeaderParam(GALAXY_SLOT_VERSION_HEADER) String slotVersion, @PathParam("slotId") UUID slotId) { Preconditions.checkNotNull(slotId, "slotId must not be null"); Slot slot = agent.getSlot(slotId); if (slot == null) { return Response.status(Response.Status.NOT_FOUND).build(); } checkAgentVersion(agent.getAgentStatus(), agentVersion); checkSlotVersion(slot.status(), slotVersion); SlotStatus slotStatus = agent.terminateSlot(slotId); if (slotStatus == null) { return Response.status(Response.Status.NOT_FOUND).build(); } return Response.ok(SlotStatusRepresentation.from(slotStatus)) .header(GALAXY_AGENT_VERSION_HEADER, agent.getAgentStatus().getVersion()) .header(GALAXY_SLOT_VERSION_HEADER, slotStatus.getVersion()) .build(); }
@PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response assign(@HeaderParam(GALAXY_AGENT_VERSION_HEADER) String agentVersion, @HeaderParam(GALAXY_SLOT_VERSION_HEADER) String slotVersion, @PathParam("slotId") UUID slotId, InstallationRepresentation installation) { Preconditions.checkNotNull(slotId, "slotId must not be null"); Preconditions.checkNotNull(installation, "installation must not be null"); Slot slot = agent.getSlot(slotId); if (slot == null) { return Response.status(Response.Status.NOT_FOUND).build(); } checkAgentVersion(agent.getAgentStatus(), agentVersion); checkSlotVersion(slot.status(), slotVersion); SlotStatus status = slot.assign(installation.toInstallation()); return Response.ok(SlotStatusRepresentation.from(status)) .header(GALAXY_AGENT_VERSION_HEADER, agent.getAgentStatus().getVersion()) .header(GALAXY_SLOT_VERSION_HEADER, status.getVersion()) .build(); } }