@Test @SuppressWarnings(value = { "static-access" }) public void testGetPowerConsumptionForAVMAndEvent() throws Exception { VMRest vmRest = new VMRest(); PaaSEnergyModeller energyModeller = mock(PaaSEnergyModeller.class); vmRest.energyModeller = energyModeller; VMDAO vmDAO = mock(VMDAO.class); vmRest.vmDAO = vmDAO; VM vm = new VM(); vm.setId(3); vm.setProviderVmId("abab"); when(vmDAO.getById(444)).thenReturn(vm); List<String> ids = new ArrayList<String>(); ids.add("3"); when(energyModeller.measure(null, "111", "333", ids, "eventX", Unit.POWER, null, null)).thenReturn(22.0); Response response = vmRest.getEventPowerConsumption("111", "333", "444", "eventX", 0, 0, null); assertEquals(200, response.getStatus()); String xml = (String) response.getEntity(); JAXBContext jaxbContext = JAXBContext.newInstance(PowerMeasurement.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); PowerMeasurement powerMeasurement = (PowerMeasurement) jaxbUnmarshaller.unmarshal(new StringReader(xml)); assertEquals("/applications/111/deployments/333/vms/444/events/eventX/power-consumption", powerMeasurement.getHref()); assertEquals(22.0, powerMeasurement.getValue(), 0.00001); assertEquals("Aggregated power consumption in Wh for an event in a specific VM", powerMeasurement.getDescription()); assertEquals(2, powerMeasurement.getLinks().size()); assertEquals("/applications/111/deployments/333/vms/444/events/eventX", powerMeasurement.getLinks().get(0).getHref()); assertEquals("parent", powerMeasurement.getLinks().get(0).getRel()); assertEquals(MediaType.APPLICATION_XML, powerMeasurement.getLinks().get(0).getType()); assertEquals("/applications/111/deployments/333/vms/444/events/eventX/power-consumption", powerMeasurement.getLinks().get(1).getHref()); assertEquals("self",powerMeasurement.getLinks().get(1).getRel()); assertEquals(MediaType.APPLICATION_XML, powerMeasurement.getLinks().get(1).getType()); }
@GET @Path("{vm_id}/events/{event_id}/power-consumption") @Produces(MediaType.APPLICATION_XML) public Response getEventPowerConsumption(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId, @PathParam("vm_id") String vmId, @PathParam("event_id") String eventId, @QueryParam("startTime") long startTime, @QueryParam("endTime") long endTime, @Context UriInfo uriInfo) { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/vms/" + vmId + "/events/" + eventId + "/power-consumption?" + "startTime=" + startTime + "&endTime=" + endTime); return getPowerComsumptionForVM(applicationName, deploymentId, vmId, eventId, startTime, endTime); }
VMRest extends AbstractRest { @GET @Path("{vm_id}/events/{event_id}/power-consumption") @Produces(MediaType.APPLICATION_XML) public Response getEventPowerConsumption(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId, @PathParam("vm_id") String vmId, @PathParam("event_id") String eventId, @QueryParam("startTime") long startTime, @QueryParam("endTime") long endTime, @Context UriInfo uriInfo) { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/vms/" + vmId + "/events/" + eventId + "/power-consumption?" + "startTime=" + startTime + "&endTime=" + endTime); return getPowerComsumptionForVM(applicationName, deploymentId, vmId, eventId, startTime, endTime); } }
VMRest extends AbstractRest { @GET @Path("{vm_id}/events/{event_id}/power-consumption") @Produces(MediaType.APPLICATION_XML) public Response getEventPowerConsumption(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId, @PathParam("vm_id") String vmId, @PathParam("event_id") String eventId, @QueryParam("startTime") long startTime, @QueryParam("endTime") long endTime, @Context UriInfo uriInfo) { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/vms/" + vmId + "/events/" + eventId + "/power-consumption?" + "startTime=" + startTime + "&endTime=" + endTime); return getPowerComsumptionForVM(applicationName, deploymentId, vmId, eventId, startTime, endTime); }  }
VMRest extends AbstractRest { @GET @Path("{vm_id}/events/{event_id}/power-consumption") @Produces(MediaType.APPLICATION_XML) public Response getEventPowerConsumption(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId, @PathParam("vm_id") String vmId, @PathParam("event_id") String eventId, @QueryParam("startTime") long startTime, @QueryParam("endTime") long endTime, @Context UriInfo uriInfo) { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/vms/" + vmId + "/events/" + eventId + "/power-consumption?" + "startTime=" + startTime + "&endTime=" + endTime); return getPowerComsumptionForVM(applicationName, deploymentId, vmId, eventId, startTime, endTime); }  @GET @Produces(MediaType.APPLICATION_XML) Response getVMs(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response postVM(@PathParam("application_name") String applicationName, 
						   @PathParam("deployment_id") String deploymentId,
						   @DefaultValue("false") @QueryParam("force") boolean force,
						   String payload); @DELETE @Path("{vm_id}") Response deleteVM(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId, @PathParam("vm_id") String vmId); @GET @Path("{vm_id}") @Produces(MediaType.APPLICATION_XML) Response getVM(@PathParam("application_name") String applicationName,  @PathParam("deployment_id") String deploymentId, @PathParam("vm_id") String vmId); @GET @Path("{vm_id}/energy-estimation") @Produces(MediaType.APPLICATION_XML) Response getEnergyEstimation(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @DefaultValue("0") @QueryParam("duration") long duration); @GET @Path("{vm_id}/events/{event_id}/energy-estimation") @Produces(MediaType.APPLICATION_XML) Response getEnergyEstimationForAnEvent(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId,
			                             @DefaultValue("0") @QueryParam("duration") long duration); @GET @Path("{vm_id}/power-estimation") @Produces(MediaType.APPLICATION_XML) Response getPowerEstimation(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId); @GET @Path("{vm_id}/events/{event_id}/power-estimation") @Produces(MediaType.APPLICATION_XML) Response getPowerEstimationForAnEvent(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId); @GET @Path("{vm_id}/events/{event_id}/cost-estimation") @Produces(MediaType.APPLICATION_XML) Response getCostEstimation(@PathParam("application_name") String applicationName, 
			                          @PathParam("deployment_id") String deploymentId,
			                          @PathParam("vm_id") String vmId,
			                          @PathParam("event_id") String eventId); @GET @Path("{vm_id}/events/{event_id}/energy-consumption") @Produces(MediaType.APPLICATION_XML) Response getEventEnergyConsumption(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId,
			                             @DefaultValue("0") @QueryParam("startTime") long startTime,
			                             @DefaultValue("0") @QueryParam("endTime") long endTime); @GET @Path("{vm_id}/events/{event_id}/power-consumption") @Produces(MediaType.APPLICATION_XML) Response getEventPowerConsumption(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId,
			                             @QueryParam("startTime") long startTime,
			                             @QueryParam("endTime") long endTime,
			                             @Context UriInfo uriInfo); @GET @Path("{vm_id}/energy-consumption") @Produces(MediaType.APPLICATION_XML) Response getEnergyConsumption(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@PathParam("vm_id") String vmId,
										@DefaultValue("0") @QueryParam("startTime") long startTime,
										@DefaultValue("0") @QueryParam("endTime") long endTime); @GET @Path("{vm_id}/power-consumption") @Produces(MediaType.APPLICATION_XML) Response getPowerConsumption(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@PathParam("vm_id") String vmId,
										@DefaultValue("0") @QueryParam("startTime") long startTime,
										@DefaultValue("0") @QueryParam("endTime") long endTime,
										@Context UriInfo uriInfo); @GET @Path("{vm_id}/events/{event_id}/energy-sample") @Produces(MediaType.APPLICATION_XML) Response getEnergySample(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId,
			                             @DefaultValue("0") @QueryParam("startTime") long startTime,
			                             @DefaultValue("0") @QueryParam("endTime") long endTime,
			                             @DefaultValue("0") @QueryParam("interval") long interval); }
VMRest extends AbstractRest { @GET @Path("{vm_id}/events/{event_id}/power-consumption") @Produces(MediaType.APPLICATION_XML) public Response getEventPowerConsumption(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId, @PathParam("vm_id") String vmId, @PathParam("event_id") String eventId, @QueryParam("startTime") long startTime, @QueryParam("endTime") long endTime, @Context UriInfo uriInfo) { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/vms/" + vmId + "/events/" + eventId + "/power-consumption?" + "startTime=" + startTime + "&endTime=" + endTime); return getPowerComsumptionForVM(applicationName, deploymentId, vmId, eventId, startTime, endTime); }  @GET @Produces(MediaType.APPLICATION_XML) Response getVMs(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response postVM(@PathParam("application_name") String applicationName, 
						   @PathParam("deployment_id") String deploymentId,
						   @DefaultValue("false") @QueryParam("force") boolean force,
						   String payload); @DELETE @Path("{vm_id}") Response deleteVM(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId, @PathParam("vm_id") String vmId); @GET @Path("{vm_id}") @Produces(MediaType.APPLICATION_XML) Response getVM(@PathParam("application_name") String applicationName,  @PathParam("deployment_id") String deploymentId, @PathParam("vm_id") String vmId); @GET @Path("{vm_id}/energy-estimation") @Produces(MediaType.APPLICATION_XML) Response getEnergyEstimation(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @DefaultValue("0") @QueryParam("duration") long duration); @GET @Path("{vm_id}/events/{event_id}/energy-estimation") @Produces(MediaType.APPLICATION_XML) Response getEnergyEstimationForAnEvent(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId,
			                             @DefaultValue("0") @QueryParam("duration") long duration); @GET @Path("{vm_id}/power-estimation") @Produces(MediaType.APPLICATION_XML) Response getPowerEstimation(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId); @GET @Path("{vm_id}/events/{event_id}/power-estimation") @Produces(MediaType.APPLICATION_XML) Response getPowerEstimationForAnEvent(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId); @GET @Path("{vm_id}/events/{event_id}/cost-estimation") @Produces(MediaType.APPLICATION_XML) Response getCostEstimation(@PathParam("application_name") String applicationName, 
			                          @PathParam("deployment_id") String deploymentId,
			                          @PathParam("vm_id") String vmId,
			                          @PathParam("event_id") String eventId); @GET @Path("{vm_id}/events/{event_id}/energy-consumption") @Produces(MediaType.APPLICATION_XML) Response getEventEnergyConsumption(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId,
			                             @DefaultValue("0") @QueryParam("startTime") long startTime,
			                             @DefaultValue("0") @QueryParam("endTime") long endTime); @GET @Path("{vm_id}/events/{event_id}/power-consumption") @Produces(MediaType.APPLICATION_XML) Response getEventPowerConsumption(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId,
			                             @QueryParam("startTime") long startTime,
			                             @QueryParam("endTime") long endTime,
			                             @Context UriInfo uriInfo); @GET @Path("{vm_id}/energy-consumption") @Produces(MediaType.APPLICATION_XML) Response getEnergyConsumption(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@PathParam("vm_id") String vmId,
										@DefaultValue("0") @QueryParam("startTime") long startTime,
										@DefaultValue("0") @QueryParam("endTime") long endTime); @GET @Path("{vm_id}/power-consumption") @Produces(MediaType.APPLICATION_XML) Response getPowerConsumption(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@PathParam("vm_id") String vmId,
										@DefaultValue("0") @QueryParam("startTime") long startTime,
										@DefaultValue("0") @QueryParam("endTime") long endTime,
										@Context UriInfo uriInfo); @GET @Path("{vm_id}/events/{event_id}/energy-sample") @Produces(MediaType.APPLICATION_XML) Response getEnergySample(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId,
			                             @DefaultValue("0") @QueryParam("startTime") long startTime,
			                             @DefaultValue("0") @QueryParam("endTime") long endTime,
			                             @DefaultValue("0") @QueryParam("interval") long interval);  }