@Test @SuppressWarnings(value = { "static-access", "unchecked" }) public void deleteDeployment() throws Exception { AmqpMessageReceiver receiver = new AmqpMessageReceiver(Configuration.amqpAddress, Configuration.amqpUsername, Configuration.amqpPassword, "APPLICATION.>", true); AmqpListListener listener = new AmqpListListener(); receiver.setMessageConsumer(listener); Deployment deployment = new Deployment(); deployment.setId(1); deployment.setOvf("ovf1"); deployment.setPrice("price1"); deployment.setStatus("Status1"); VM vm1 = new VM(); vm1.setId(1); vm1.setIp("10.0.0.1"); vm1.setProviderVmId("aaaa-bbbb-1"); vm1.setStatus("ACTIVE"); vm1.setOvfId("ovf-vm1"); deployment.addVM(vm1); VM vm2 = new VM(); vm2.setId(2); vm2.setIp("10.0.0.2"); vm2.setProviderVmId("aaaa-bbbb-2"); vm2.setStatus("ACTIVE"); vm2.setOvfId("ovf-vm2"); deployment.addVM(vm2); VM vm3 = new VM(); vm3.setId(3); vm3.setIp("10.0.0.3"); vm3.setProviderVmId("aaaa-bbbb-3"); vm3.setStatus("ACTIVE"); vm3.setOvfId("ovf-vm3"); deployment.addVM(vm3); Image image1 = new Image(); image1.setDemo(false); image1.setOvfHref("ovf-href1"); image1.setProviderImageId("zzzz-1"); vm1.addImage(image1); Image image2 = new Image(); image2.setDemo(false); image2.setOvfHref("ovf-href2"); image2.setProviderImageId("zzzz-2"); vm2.addImage(image2); vm3.addImage(image2); Image image3 = new Image(); image3.setDemo(true); image3.setOvfHref("ovf-href2"); image3.setProviderImageId("zzzz-3"); vm2.addImage(image3); PaaSEnergyModeller modeller = mock(PaaSEnergyModeller.class); ApplicationMonitorClient amonitorClient = mock(ApplicationMonitorClient.class); DeploymentDAO deploymentDAO = mock(DeploymentDAO.class); when(deploymentDAO.getById(1)).thenReturn(deployment); when(deploymentDAO.update(deployment)).thenReturn(true); VmManagerClient vmManagerClient = mock(VmManagerClient.class); DeploymentRest deploymentRest = new DeploymentRest(); deploymentRest.deploymentDAO = deploymentDAO; deploymentRest.vmManagerClient = vmManagerClient; deploymentRest.energyModeller = modeller; deploymentRest.applicationMonitorClient = amonitorClient; when(modeller.measure(isNull(String.class), eq("app-name"), eq("1"), argThat(new BaseMatcher<List<String>>() { @Override public boolean matches(Object arg0) { List<String> ids = (List<String>) arg0; boolean isTheList = true; if(!(ids.size() == 3)) isTheList = false; if(!(ids.get(0).equals("1"))) isTheList = false; if(!(ids.get(1).equals("2"))) isTheList = false; if(!(ids.get(2).equals("3"))) isTheList = false; return isTheList; } @Override public void describeTo(Description arg0) {} }), isNull(String.class), eq(Unit.ENERGY), isNull(Timestamp.class), isNull(Timestamp.class))).thenReturn(22.0); Response response = deploymentRest.deleteDeployment("app-name", "1"); assertEquals(204, response.getStatus()); assertEquals("", (String) response.getEntity()); verify(deploymentDAO, times(1)).getById(1); verify(deploymentDAO, times(1)).update(deployment); verify(vmManagerClient, times(1)).deleteVM("aaaa-bbbb-2"); verify(vmManagerClient, times(1)).deleteVM("aaaa-bbbb-1"); verify(vmManagerClient, times(1)).deleteVM("aaaa-bbbb-3"); verify(vmManagerClient, times(1)).deleteImage("zzzz-1"); verify(vmManagerClient, times(1)).deleteImage("zzzz-2"); verify(vmManagerClient, times(0)).deleteImage("zzzz-3"); ArgumentCaptor<EnergyCosumed> argument = ArgumentCaptor.forClass(EnergyCosumed.class); verify(amonitorClient, times(1)).postFinalEnergyConsumption(argument.capture()); assertEquals("22.0 Wh", argument.getValue().getData().getPower()); verify(modeller, times(1)).writeDeploymentRequest(null, "app-name", "1", "1", "aaaa-bbbb-1", "DELETED"); verify(modeller, times(1)).writeDeploymentRequest(null, "app-name", "1", "2", "aaaa-bbbb-2", "DELETED"); Thread.sleep(500l); assertEquals(4, listener.getTextMessages().size()); assertEquals("APPLICATION.app-name.DEPLOYMENT.1.VM.1.DELETED", listener.getTextMessages().get(0).getJMSDestination().toString()); assertEquals("app-name", ModelConverter.jsonToApplicationManagerMessage(listener.getTextMessages().get(0).getText()).getApplicationId()); assertEquals("1", ModelConverter.jsonToApplicationManagerMessage(listener.getTextMessages().get(0).getText()).getDeploymentId()); assertEquals("Status1", ModelConverter.jsonToApplicationManagerMessage(listener.getTextMessages().get(0).getText()).getStatus()); assertEquals("ovf-vm1", ModelConverter.jsonToApplicationManagerMessage(listener.getTextMessages().get(0).getText()).getVms().get(0).getOvfId()); assertEquals("APPLICATION.app-name.DEPLOYMENT.1.VM.2.DELETED", listener.getTextMessages().get(1).getJMSDestination().toString()); assertEquals("app-name", ModelConverter.jsonToApplicationManagerMessage(listener.getTextMessages().get(1).getText()).getApplicationId()); assertEquals("1", ModelConverter.jsonToApplicationManagerMessage(listener.getTextMessages().get(1).getText()).getDeploymentId()); assertEquals("Status1", ModelConverter.jsonToApplicationManagerMessage(listener.getTextMessages().get(1).getText()).getStatus()); assertEquals("ovf-vm2", ModelConverter.jsonToApplicationManagerMessage(listener.getTextMessages().get(1).getText()).getVms().get(0).getOvfId()); assertEquals("APPLICATION.app-name.DEPLOYMENT.1.VM.3.DELETED", listener.getTextMessages().get(2).getJMSDestination().toString()); assertEquals("app-name", ModelConverter.jsonToApplicationManagerMessage(listener.getTextMessages().get(2).getText()).getApplicationId()); assertEquals("1", ModelConverter.jsonToApplicationManagerMessage(listener.getTextMessages().get(2).getText()).getDeploymentId()); assertEquals("Status1", ModelConverter.jsonToApplicationManagerMessage(listener.getTextMessages().get(2).getText()).getStatus()); assertEquals("ovf-vm3", ModelConverter.jsonToApplicationManagerMessage(listener.getTextMessages().get(2).getText()).getVms().get(0).getOvfId()); assertEquals("APPLICATION.app-name.DEPLOYMENT.1.TERMINATED", listener.getTextMessages().get(3).getJMSDestination().toString()); assertEquals("app-name", ModelConverter.jsonToApplicationManagerMessage(listener.getTextMessages().get(3).getText()).getApplicationId()); assertEquals("1", ModelConverter.jsonToApplicationManagerMessage(listener.getTextMessages().get(3).getText()).getDeploymentId()); assertEquals("TERMINATED", ModelConverter.jsonToApplicationManagerMessage(listener.getTextMessages().get(3).getText()).getStatus()); receiver.close(); }
@DELETE @Path("{deployment_id}") @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN }) public Response deleteDeployment(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId) { logger.info("DELETE request to path: /applications/" + applicationName + "/deployments/" + deploymentId); int intDeploymentId = 0; try{ intDeploymentId = Integer.parseInt(deploymentId); } catch (NumberFormatException e){ return buildResponse(Status.BAD_REQUEST, "The deployment id must be a number"); } Deployment deployment = deploymentDAO.getById(intDeploymentId); if (deployment == null){ return buildResponse(Status.NOT_FOUND, "Deployment id = " + deploymentId + " not found in database"); } deployment.setEndDate(DateUtil.getDateStringLogStandardFormat(new Date())); if(Configuration.emCalculateEnergyWhenDeletion != null && Configuration.emCalculateEnergyWhenDeletion.equals("yes")) { EnergyMeasurement energyMeasurement = getEnergyConsumptionFromEM(applicationName, deployment, null, null); EnergyCosumed energyConsumed = new EnergyCosumed(); energyConsumed.setAppId(applicationName); energyConsumed.setInstanceId(deploymentId); Data data = new Data(); data.setEnd(deployment.getEndDate()); data.setStart(deployment.getStartDate()); data.setPower(energyMeasurement.getValue() + " Wh"); energyConsumed.setData(data); applicationMonitorClient.postFinalEnergyConsumption(energyConsumed); } List<VM> deploymentVms = deployment.getVms(); List<Image> images = new ArrayList<Image>(); for (VM vm : deploymentVms){ logger.info("DELETING VM: " + vm.getProviderVmId()); vmManagerClient.deleteVM(vm.getProviderVmId()); vm.setStatus(STATE_VM_DELETED); images.addAll(vm.getImages()); getEnergyModeller().writeDeploymentRequest(vm.getProviderId(), applicationName, "" + deployment.getId(), "" + vm.getId(), vm.getProviderVmId(), vm.getStatus()); AmqpProducer.sendVMDeletedMessage(applicationName, deployment, vm); } Set<String> imageIds = new HashSet<String>(); for(Image image : images) { if(!image.isDemo()) { String id = image.getProviderImageId(); logger.info("TRYING TO DELETE IMAGE: " + id); if(!imageIds.contains(id)) { logger.info("DELETING IMAGE: " + id); imageIds.add(id); vmManagerClient.deleteImage(id); } else { logger.info("IMAGE WITH ID: " + id + " WAS ALREADY PREVIOUSLY DELETED"); } } } deployment.setStatus(Dictionary.APPLICATION_STATUS_TERMINATED); AmqpProducer.sendDeploymentDeletedMessage(applicationName, deployment); deploymentDAO.update(deployment); return buildResponse(Status.NO_CONTENT, ""); }
DeploymentRest extends AbstractRest { @DELETE @Path("{deployment_id}") @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN }) public Response deleteDeployment(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId) { logger.info("DELETE request to path: /applications/" + applicationName + "/deployments/" + deploymentId); int intDeploymentId = 0; try{ intDeploymentId = Integer.parseInt(deploymentId); } catch (NumberFormatException e){ return buildResponse(Status.BAD_REQUEST, "The deployment id must be a number"); } Deployment deployment = deploymentDAO.getById(intDeploymentId); if (deployment == null){ return buildResponse(Status.NOT_FOUND, "Deployment id = " + deploymentId + " not found in database"); } deployment.setEndDate(DateUtil.getDateStringLogStandardFormat(new Date())); if(Configuration.emCalculateEnergyWhenDeletion != null && Configuration.emCalculateEnergyWhenDeletion.equals("yes")) { EnergyMeasurement energyMeasurement = getEnergyConsumptionFromEM(applicationName, deployment, null, null); EnergyCosumed energyConsumed = new EnergyCosumed(); energyConsumed.setAppId(applicationName); energyConsumed.setInstanceId(deploymentId); Data data = new Data(); data.setEnd(deployment.getEndDate()); data.setStart(deployment.getStartDate()); data.setPower(energyMeasurement.getValue() + " Wh"); energyConsumed.setData(data); applicationMonitorClient.postFinalEnergyConsumption(energyConsumed); } List<VM> deploymentVms = deployment.getVms(); List<Image> images = new ArrayList<Image>(); for (VM vm : deploymentVms){ logger.info("DELETING VM: " + vm.getProviderVmId()); vmManagerClient.deleteVM(vm.getProviderVmId()); vm.setStatus(STATE_VM_DELETED); images.addAll(vm.getImages()); getEnergyModeller().writeDeploymentRequest(vm.getProviderId(), applicationName, "" + deployment.getId(), "" + vm.getId(), vm.getProviderVmId(), vm.getStatus()); AmqpProducer.sendVMDeletedMessage(applicationName, deployment, vm); } Set<String> imageIds = new HashSet<String>(); for(Image image : images) { if(!image.isDemo()) { String id = image.getProviderImageId(); logger.info("TRYING TO DELETE IMAGE: " + id); if(!imageIds.contains(id)) { logger.info("DELETING IMAGE: " + id); imageIds.add(id); vmManagerClient.deleteImage(id); } else { logger.info("IMAGE WITH ID: " + id + " WAS ALREADY PREVIOUSLY DELETED"); } } } deployment.setStatus(Dictionary.APPLICATION_STATUS_TERMINATED); AmqpProducer.sendDeploymentDeletedMessage(applicationName, deployment); deploymentDAO.update(deployment); return buildResponse(Status.NO_CONTENT, ""); } }
DeploymentRest extends AbstractRest { @DELETE @Path("{deployment_id}") @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN }) public Response deleteDeployment(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId) { logger.info("DELETE request to path: /applications/" + applicationName + "/deployments/" + deploymentId); int intDeploymentId = 0; try{ intDeploymentId = Integer.parseInt(deploymentId); } catch (NumberFormatException e){ return buildResponse(Status.BAD_REQUEST, "The deployment id must be a number"); } Deployment deployment = deploymentDAO.getById(intDeploymentId); if (deployment == null){ return buildResponse(Status.NOT_FOUND, "Deployment id = " + deploymentId + " not found in database"); } deployment.setEndDate(DateUtil.getDateStringLogStandardFormat(new Date())); if(Configuration.emCalculateEnergyWhenDeletion != null && Configuration.emCalculateEnergyWhenDeletion.equals("yes")) { EnergyMeasurement energyMeasurement = getEnergyConsumptionFromEM(applicationName, deployment, null, null); EnergyCosumed energyConsumed = new EnergyCosumed(); energyConsumed.setAppId(applicationName); energyConsumed.setInstanceId(deploymentId); Data data = new Data(); data.setEnd(deployment.getEndDate()); data.setStart(deployment.getStartDate()); data.setPower(energyMeasurement.getValue() + " Wh"); energyConsumed.setData(data); applicationMonitorClient.postFinalEnergyConsumption(energyConsumed); } List<VM> deploymentVms = deployment.getVms(); List<Image> images = new ArrayList<Image>(); for (VM vm : deploymentVms){ logger.info("DELETING VM: " + vm.getProviderVmId()); vmManagerClient.deleteVM(vm.getProviderVmId()); vm.setStatus(STATE_VM_DELETED); images.addAll(vm.getImages()); getEnergyModeller().writeDeploymentRequest(vm.getProviderId(), applicationName, "" + deployment.getId(), "" + vm.getId(), vm.getProviderVmId(), vm.getStatus()); AmqpProducer.sendVMDeletedMessage(applicationName, deployment, vm); } Set<String> imageIds = new HashSet<String>(); for(Image image : images) { if(!image.isDemo()) { String id = image.getProviderImageId(); logger.info("TRYING TO DELETE IMAGE: " + id); if(!imageIds.contains(id)) { logger.info("DELETING IMAGE: " + id); imageIds.add(id); vmManagerClient.deleteImage(id); } else { logger.info("IMAGE WITH ID: " + id + " WAS ALREADY PREVIOUSLY DELETED"); } } } deployment.setStatus(Dictionary.APPLICATION_STATUS_TERMINATED); AmqpProducer.sendDeploymentDeletedMessage(applicationName, deployment); deploymentDAO.update(deployment); return buildResponse(Status.NO_CONTENT, ""); }  }
DeploymentRest extends AbstractRest { @DELETE @Path("{deployment_id}") @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN }) public Response deleteDeployment(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId) { logger.info("DELETE request to path: /applications/" + applicationName + "/deployments/" + deploymentId); int intDeploymentId = 0; try{ intDeploymentId = Integer.parseInt(deploymentId); } catch (NumberFormatException e){ return buildResponse(Status.BAD_REQUEST, "The deployment id must be a number"); } Deployment deployment = deploymentDAO.getById(intDeploymentId); if (deployment == null){ return buildResponse(Status.NOT_FOUND, "Deployment id = " + deploymentId + " not found in database"); } deployment.setEndDate(DateUtil.getDateStringLogStandardFormat(new Date())); if(Configuration.emCalculateEnergyWhenDeletion != null && Configuration.emCalculateEnergyWhenDeletion.equals("yes")) { EnergyMeasurement energyMeasurement = getEnergyConsumptionFromEM(applicationName, deployment, null, null); EnergyCosumed energyConsumed = new EnergyCosumed(); energyConsumed.setAppId(applicationName); energyConsumed.setInstanceId(deploymentId); Data data = new Data(); data.setEnd(deployment.getEndDate()); data.setStart(deployment.getStartDate()); data.setPower(energyMeasurement.getValue() + " Wh"); energyConsumed.setData(data); applicationMonitorClient.postFinalEnergyConsumption(energyConsumed); } List<VM> deploymentVms = deployment.getVms(); List<Image> images = new ArrayList<Image>(); for (VM vm : deploymentVms){ logger.info("DELETING VM: " + vm.getProviderVmId()); vmManagerClient.deleteVM(vm.getProviderVmId()); vm.setStatus(STATE_VM_DELETED); images.addAll(vm.getImages()); getEnergyModeller().writeDeploymentRequest(vm.getProviderId(), applicationName, "" + deployment.getId(), "" + vm.getId(), vm.getProviderVmId(), vm.getStatus()); AmqpProducer.sendVMDeletedMessage(applicationName, deployment, vm); } Set<String> imageIds = new HashSet<String>(); for(Image image : images) { if(!image.isDemo()) { String id = image.getProviderImageId(); logger.info("TRYING TO DELETE IMAGE: " + id); if(!imageIds.contains(id)) { logger.info("DELETING IMAGE: " + id); imageIds.add(id); vmManagerClient.deleteImage(id); } else { logger.info("IMAGE WITH ID: " + id + " WAS ALREADY PREVIOUSLY DELETED"); } } } deployment.setStatus(Dictionary.APPLICATION_STATUS_TERMINATED); AmqpProducer.sendDeploymentDeletedMessage(applicationName, deployment); deploymentDAO.update(deployment); return buildResponse(Status.NO_CONTENT, ""); }  @GET @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getDeployments(@PathParam("application_name") String applicationName, @DefaultValue("")@QueryParam("status") String status); @GET @Produces(MediaType.APPLICATION_JSON + ";qs=0.5") Response getDeploymentsJSON(@PathParam("application_name") String applicationName, @DefaultValue("")@QueryParam("status") String status); @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response postDeployment(@PathParam("application_name") String applicationName, @QueryParam("negotiation") String negotiation,  @QueryParam("schema") String schema, String payload); @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_JSON) Response postDeploymentJSON(@PathParam("application_name") String applicationName, @QueryParam("negotiation") String negotiation,  @QueryParam("schema") String schema, String payload); @OPTIONS @Path("{deployment_id}") Response optionsForSpecificDeployment(); @GET @Path("{deployment_id}") @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getDeployment(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}") @Produces(MediaType.APPLICATION_JSON + ";qs=0.5") Response getDeploymentJSON(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/agreement") @Produces(MediaType.APPLICATION_XML) Response getDeploymentAgreement(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/ovf") @Produces(MediaType.APPLICATION_XML) Response getDeploymentOvf(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @PUT @Path("{deployment_id}/agreement") @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response putDeploymentAgreement(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @DELETE @Path("{deployment_id}") @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN }) Response deleteDeployment(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/cost-consumption") @Produces(MediaType.APPLICATION_XML) Response getCost(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/energy-consumption") @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getEnergyConsumptionXML(@PathParam("application_name") String applicationName, 
										 @PathParam("deployment_id") String deploymentId,
										 @QueryParam("startTime") String startTime,
			                             @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/energy-consumption") @Produces(MediaType.APPLICATION_JSON + ";qs=0.5") Response getEnergyConsumptionJSON(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId, @QueryParam("startTime") String startTime,
            @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/power-consumption") @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getPowerConsumptionXML(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@QueryParam("startTime") String startTime,
			                            @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/power-consumption") @Produces(MediaType.APPLICATION_JSON + ";qs=0,5") Response getPowerConsumptionJSON(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@QueryParam("startTime") String startTime,
			                            @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/energy-estimation") @Produces(MediaType.APPLICATION_XML) Response getEnergyEstimation(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@QueryParam("duration") String durationQuery); @GET @Path("{deployment_id}/power-estimation") @Produces(MediaType.APPLICATION_XML) Response getPowerEstimation(@PathParam("application_name") String applicationName, 
									   @PathParam("deployment_id") String deploymentId,
										@QueryParam("duration") String durationQuery); @GET @Path("{deployment_id}/events/{event_id}/energy-estimation") @Produces(MediaType.APPLICATION_XML) Response getEnergyEstimationForEvent(@PathParam("application_name") String applicationName, 
												@PathParam("deployment_id") String deploymentId, 
												@PathParam("event_id") String eventId,
												@QueryParam("duration") String durationQuery); @GET @Path("{deployment_id}/events/{event_id}/power-estimation") @Produces(MediaType.APPLICATION_XML) Response getPowerEstimationForEvent(@PathParam("application_name") String applicationName, 
											   @PathParam("deployment_id") String deploymentId, 
											   @PathParam("event_id") String eventId,
											   @QueryParam("duration") String durationQuery); @GET @Path("{deployment_id}/events/{event_id}/energy-consumption") @Produces(MediaType.APPLICATION_XML) Response getEnergyMeasurementForEvent(@PathParam("application_name") String applicationName, 
												 @PathParam("deployment_id") String deploymentId, 
												 @PathParam("event_id") String eventId,
												 @QueryParam("startTime") String startTime,
					                             @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/events/{event_id}/power-consumption") @Produces(MediaType.APPLICATION_XML) Response getPowerConsumptionForEvent(@PathParam("application_name") String applicationName, 
												@PathParam("deployment_id") String deploymentId, 
												@PathParam("event_id") String eventId,
					                            @QueryParam("startTime") String startTime,
					                            @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/predicted-price-for-next-period") @Produces(MediaType.APPLICATION_XML) Response getPredictedPriceForNextPeriod(@PathParam("application_name") String applicationName, 
			                          @PathParam("deployment_id") String deploymentId,
			                          @QueryParam("duration") String duration); @GET @Path("{deployment_id}/events/{event_id}/cost-estimation") @Produces(MediaType.APPLICATION_XML) Response getCostEstimation(@PathParam("application_name") String applicationName, 
			                          @PathParam("deployment_id") String deploymentId,
			                          @PathParam("event_id") String eventId); @GET @Path("{deployment_id}/sla-limits") @Produces(MediaType.APPLICATION_XML) Response getSLALimits(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @POST @Path("{deployment_id}/renegotiate") @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response renegotiateWithPayload(@PathParam("application_name") String applicationName,@PathParam("deployment_id") String deploymentId, String payload); @GET @Path("{deployment_id}/renegotiate") @Produces(MediaType.APPLICATION_XML) Response renegotiate(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/predict-price-next-hour") @Produces(MediaType.APPLICATION_XML) Response predictPriceNextHour(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); }
DeploymentRest extends AbstractRest { @DELETE @Path("{deployment_id}") @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN }) public Response deleteDeployment(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId) { logger.info("DELETE request to path: /applications/" + applicationName + "/deployments/" + deploymentId); int intDeploymentId = 0; try{ intDeploymentId = Integer.parseInt(deploymentId); } catch (NumberFormatException e){ return buildResponse(Status.BAD_REQUEST, "The deployment id must be a number"); } Deployment deployment = deploymentDAO.getById(intDeploymentId); if (deployment == null){ return buildResponse(Status.NOT_FOUND, "Deployment id = " + deploymentId + " not found in database"); } deployment.setEndDate(DateUtil.getDateStringLogStandardFormat(new Date())); if(Configuration.emCalculateEnergyWhenDeletion != null && Configuration.emCalculateEnergyWhenDeletion.equals("yes")) { EnergyMeasurement energyMeasurement = getEnergyConsumptionFromEM(applicationName, deployment, null, null); EnergyCosumed energyConsumed = new EnergyCosumed(); energyConsumed.setAppId(applicationName); energyConsumed.setInstanceId(deploymentId); Data data = new Data(); data.setEnd(deployment.getEndDate()); data.setStart(deployment.getStartDate()); data.setPower(energyMeasurement.getValue() + " Wh"); energyConsumed.setData(data); applicationMonitorClient.postFinalEnergyConsumption(energyConsumed); } List<VM> deploymentVms = deployment.getVms(); List<Image> images = new ArrayList<Image>(); for (VM vm : deploymentVms){ logger.info("DELETING VM: " + vm.getProviderVmId()); vmManagerClient.deleteVM(vm.getProviderVmId()); vm.setStatus(STATE_VM_DELETED); images.addAll(vm.getImages()); getEnergyModeller().writeDeploymentRequest(vm.getProviderId(), applicationName, "" + deployment.getId(), "" + vm.getId(), vm.getProviderVmId(), vm.getStatus()); AmqpProducer.sendVMDeletedMessage(applicationName, deployment, vm); } Set<String> imageIds = new HashSet<String>(); for(Image image : images) { if(!image.isDemo()) { String id = image.getProviderImageId(); logger.info("TRYING TO DELETE IMAGE: " + id); if(!imageIds.contains(id)) { logger.info("DELETING IMAGE: " + id); imageIds.add(id); vmManagerClient.deleteImage(id); } else { logger.info("IMAGE WITH ID: " + id + " WAS ALREADY PREVIOUSLY DELETED"); } } } deployment.setStatus(Dictionary.APPLICATION_STATUS_TERMINATED); AmqpProducer.sendDeploymentDeletedMessage(applicationName, deployment); deploymentDAO.update(deployment); return buildResponse(Status.NO_CONTENT, ""); }  @GET @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getDeployments(@PathParam("application_name") String applicationName, @DefaultValue("")@QueryParam("status") String status); @GET @Produces(MediaType.APPLICATION_JSON + ";qs=0.5") Response getDeploymentsJSON(@PathParam("application_name") String applicationName, @DefaultValue("")@QueryParam("status") String status); @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response postDeployment(@PathParam("application_name") String applicationName, @QueryParam("negotiation") String negotiation,  @QueryParam("schema") String schema, String payload); @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_JSON) Response postDeploymentJSON(@PathParam("application_name") String applicationName, @QueryParam("negotiation") String negotiation,  @QueryParam("schema") String schema, String payload); @OPTIONS @Path("{deployment_id}") Response optionsForSpecificDeployment(); @GET @Path("{deployment_id}") @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getDeployment(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}") @Produces(MediaType.APPLICATION_JSON + ";qs=0.5") Response getDeploymentJSON(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/agreement") @Produces(MediaType.APPLICATION_XML) Response getDeploymentAgreement(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/ovf") @Produces(MediaType.APPLICATION_XML) Response getDeploymentOvf(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @PUT @Path("{deployment_id}/agreement") @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response putDeploymentAgreement(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @DELETE @Path("{deployment_id}") @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN }) Response deleteDeployment(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/cost-consumption") @Produces(MediaType.APPLICATION_XML) Response getCost(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/energy-consumption") @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getEnergyConsumptionXML(@PathParam("application_name") String applicationName, 
										 @PathParam("deployment_id") String deploymentId,
										 @QueryParam("startTime") String startTime,
			                             @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/energy-consumption") @Produces(MediaType.APPLICATION_JSON + ";qs=0.5") Response getEnergyConsumptionJSON(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId, @QueryParam("startTime") String startTime,
            @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/power-consumption") @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getPowerConsumptionXML(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@QueryParam("startTime") String startTime,
			                            @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/power-consumption") @Produces(MediaType.APPLICATION_JSON + ";qs=0,5") Response getPowerConsumptionJSON(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@QueryParam("startTime") String startTime,
			                            @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/energy-estimation") @Produces(MediaType.APPLICATION_XML) Response getEnergyEstimation(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@QueryParam("duration") String durationQuery); @GET @Path("{deployment_id}/power-estimation") @Produces(MediaType.APPLICATION_XML) Response getPowerEstimation(@PathParam("application_name") String applicationName, 
									   @PathParam("deployment_id") String deploymentId,
										@QueryParam("duration") String durationQuery); @GET @Path("{deployment_id}/events/{event_id}/energy-estimation") @Produces(MediaType.APPLICATION_XML) Response getEnergyEstimationForEvent(@PathParam("application_name") String applicationName, 
												@PathParam("deployment_id") String deploymentId, 
												@PathParam("event_id") String eventId,
												@QueryParam("duration") String durationQuery); @GET @Path("{deployment_id}/events/{event_id}/power-estimation") @Produces(MediaType.APPLICATION_XML) Response getPowerEstimationForEvent(@PathParam("application_name") String applicationName, 
											   @PathParam("deployment_id") String deploymentId, 
											   @PathParam("event_id") String eventId,
											   @QueryParam("duration") String durationQuery); @GET @Path("{deployment_id}/events/{event_id}/energy-consumption") @Produces(MediaType.APPLICATION_XML) Response getEnergyMeasurementForEvent(@PathParam("application_name") String applicationName, 
												 @PathParam("deployment_id") String deploymentId, 
												 @PathParam("event_id") String eventId,
												 @QueryParam("startTime") String startTime,
					                             @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/events/{event_id}/power-consumption") @Produces(MediaType.APPLICATION_XML) Response getPowerConsumptionForEvent(@PathParam("application_name") String applicationName, 
												@PathParam("deployment_id") String deploymentId, 
												@PathParam("event_id") String eventId,
					                            @QueryParam("startTime") String startTime,
					                            @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/predicted-price-for-next-period") @Produces(MediaType.APPLICATION_XML) Response getPredictedPriceForNextPeriod(@PathParam("application_name") String applicationName, 
			                          @PathParam("deployment_id") String deploymentId,
			                          @QueryParam("duration") String duration); @GET @Path("{deployment_id}/events/{event_id}/cost-estimation") @Produces(MediaType.APPLICATION_XML) Response getCostEstimation(@PathParam("application_name") String applicationName, 
			                          @PathParam("deployment_id") String deploymentId,
			                          @PathParam("event_id") String eventId); @GET @Path("{deployment_id}/sla-limits") @Produces(MediaType.APPLICATION_XML) Response getSLALimits(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @POST @Path("{deployment_id}/renegotiate") @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response renegotiateWithPayload(@PathParam("application_name") String applicationName,@PathParam("deployment_id") String deploymentId, String payload); @GET @Path("{deployment_id}/renegotiate") @Produces(MediaType.APPLICATION_XML) Response renegotiate(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/predict-price-next-hour") @Produces(MediaType.APPLICATION_XML) Response predictPriceNextHour(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId);  }