@Test @SuppressWarnings(value = { "static-access" }) public void getEnergySampleWithoutIntervalTest() throws Exception { EventSample eventSample1 = new EventSample(); eventSample1.setCvalue(1.0); eventSample1.setEvalue(2.0); eventSample1.setPvalue(3.0); eventSample1.setTimestampBeging(1l); eventSample1.setTimestampEnd(2l); eventSample1.setVmid("vmid"); eventSample1.setAppid("appid"); EventSample eventSample2 = new EventSample(); eventSample2.setCvalue(4.0); eventSample2.setEvalue(5.0); eventSample2.setPvalue(6.0); eventSample2.setTimestampBeging(3l); eventSample2.setTimestampEnd(4l); eventSample2.setVmid("vmid2"); eventSample2.setAppid("appid2"); List<EventSample> eventSamples = new ArrayList<EventSample>(); eventSamples.add(eventSample1); eventSamples.add(eventSample2); 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(4); vm.setProviderVmId("abab"); when(vmDAO.getById(444)).thenReturn(vm); List<String> vmIds = new ArrayList<String>(); vmIds.add("4"); when(energyModeller.eventsData(null, "", "", vmIds, "eventX", new Timestamp(2l), new Timestamp(3l))).thenReturn(eventSamples); Response response = vmRest.getEnergySample("", "", "444", "eventX", 2l, 3l, 0l); assertEquals(200, response.getStatus()); String xml = (String) response.getEntity(); JAXBContext jaxbContext = JAXBContext.newInstance(Collection.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Collection collection = (Collection) jaxbUnmarshaller.unmarshal(new StringReader(xml)); assertEquals("/applications assertEquals(0, collection.getItems().getOffset()); assertEquals(2, collection.getItems().getTotal()); assertEquals(2, collection.getLinks().size()); assertEquals("/applications assertEquals("parent", collection.getLinks().get(0).getRel()); assertEquals(MediaType.APPLICATION_XML, collection.getLinks().get(0).getType()); assertEquals("/applications assertEquals("self", collection.getLinks().get(1).getRel()); assertEquals(MediaType.APPLICATION_XML, collection.getLinks().get(1).getType()); assertEquals(2, collection.getItems().getEventSamples().size()); assertEquals(1.0, collection.getItems().getEventSamples().get(0).getCvalue(), 0.00001); assertEquals(2.0, collection.getItems().getEventSamples().get(0).getEvalue(), 0.00001); assertEquals(3.0, collection.getItems().getEventSamples().get(0).getPvalue(), 0.00001); assertEquals(1l, collection.getItems().getEventSamples().get(0).getTimestampBeging()); assertEquals(2l, collection.getItems().getEventSamples().get(0).getTimestampEnd()); assertEquals("vmid", collection.getItems().getEventSamples().get(0).getVmid()); assertEquals("appid", collection.getItems().getEventSamples().get(0).getAppid()); assertEquals(4.0, collection.getItems().getEventSamples().get(1).getCvalue(), 0.00001); assertEquals(5.0, collection.getItems().getEventSamples().get(1).getEvalue(), 0.00001); assertEquals(6.0, collection.getItems().getEventSamples().get(1).getPvalue(), 0.00001); assertEquals(3l, collection.getItems().getEventSamples().get(1).getTimestampBeging()); assertEquals(4l, collection.getItems().getEventSamples().get(1).getTimestampEnd()); assertEquals("vmid2", collection.getItems().getEventSamples().get(1).getVmid()); assertEquals("appid2", collection.getItems().getEventSamples().get(1).getAppid()); verify(vmDAO, times(1)).getById(444); verify(energyModeller, times(1)).eventsData(null, "", "", vmIds, "eventX", new Timestamp(2l), new Timestamp(3l)); }
@GET @Path("{vm_id}/events/{event_id}/energy-sample") @Produces(MediaType.APPLICATION_XML) public 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) { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/vms/" + vmId + "/events/" + eventId + "/energy-sample?" + "startTime=" + startTime + "&endTime=" + endTime + "&interval=" + interval); if(startTime == 0 || endTime == 0) { return buildResponse(Status.BAD_REQUEST, "It is mandatory to specify startTime and endTime!!!"); } else { String payload = null; VM vm = vmDAO.getById(Integer.parseInt(vmId)); List<String> vmIds = new ArrayList<String>(); vmIds.add("" + vm.getId()); Timestamp startStamp = new Timestamp(startTime); Timestamp endStamp = new Timestamp(endTime); if(interval == 0) { List<eu.ascetic.paas.applicationmanager.model.EventSample> samples = null; List<EventSample> eSamples = energyModeller.eventsData(null, applicationName, deploymentId, vmIds, eventId, startStamp, endStamp); samples = EnergyModellerConverter.convertList(eSamples); payload = XMLBuilder.getEventSampleCollectionXMLInfo(samples, applicationName, deploymentId, vmId, eventId); } return buildResponse(Status.OK, payload); } }
VMRest extends AbstractRest { @GET @Path("{vm_id}/events/{event_id}/energy-sample") @Produces(MediaType.APPLICATION_XML) public 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) { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/vms/" + vmId + "/events/" + eventId + "/energy-sample?" + "startTime=" + startTime + "&endTime=" + endTime + "&interval=" + interval); if(startTime == 0 || endTime == 0) { return buildResponse(Status.BAD_REQUEST, "It is mandatory to specify startTime and endTime!!!"); } else { String payload = null; VM vm = vmDAO.getById(Integer.parseInt(vmId)); List<String> vmIds = new ArrayList<String>(); vmIds.add("" + vm.getId()); Timestamp startStamp = new Timestamp(startTime); Timestamp endStamp = new Timestamp(endTime); if(interval == 0) { List<eu.ascetic.paas.applicationmanager.model.EventSample> samples = null; List<EventSample> eSamples = energyModeller.eventsData(null, applicationName, deploymentId, vmIds, eventId, startStamp, endStamp); samples = EnergyModellerConverter.convertList(eSamples); payload = XMLBuilder.getEventSampleCollectionXMLInfo(samples, applicationName, deploymentId, vmId, eventId); } return buildResponse(Status.OK, payload); } } }
VMRest extends AbstractRest { @GET @Path("{vm_id}/events/{event_id}/energy-sample") @Produces(MediaType.APPLICATION_XML) public 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) { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/vms/" + vmId + "/events/" + eventId + "/energy-sample?" + "startTime=" + startTime + "&endTime=" + endTime + "&interval=" + interval); if(startTime == 0 || endTime == 0) { return buildResponse(Status.BAD_REQUEST, "It is mandatory to specify startTime and endTime!!!"); } else { String payload = null; VM vm = vmDAO.getById(Integer.parseInt(vmId)); List<String> vmIds = new ArrayList<String>(); vmIds.add("" + vm.getId()); Timestamp startStamp = new Timestamp(startTime); Timestamp endStamp = new Timestamp(endTime); if(interval == 0) { List<eu.ascetic.paas.applicationmanager.model.EventSample> samples = null; List<EventSample> eSamples = energyModeller.eventsData(null, applicationName, deploymentId, vmIds, eventId, startStamp, endStamp); samples = EnergyModellerConverter.convertList(eSamples); payload = XMLBuilder.getEventSampleCollectionXMLInfo(samples, applicationName, deploymentId, vmId, eventId); } return buildResponse(Status.OK, payload); } }  }
VMRest extends AbstractRest { @GET @Path("{vm_id}/events/{event_id}/energy-sample") @Produces(MediaType.APPLICATION_XML) public 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) { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/vms/" + vmId + "/events/" + eventId + "/energy-sample?" + "startTime=" + startTime + "&endTime=" + endTime + "&interval=" + interval); if(startTime == 0 || endTime == 0) { return buildResponse(Status.BAD_REQUEST, "It is mandatory to specify startTime and endTime!!!"); } else { String payload = null; VM vm = vmDAO.getById(Integer.parseInt(vmId)); List<String> vmIds = new ArrayList<String>(); vmIds.add("" + vm.getId()); Timestamp startStamp = new Timestamp(startTime); Timestamp endStamp = new Timestamp(endTime); if(interval == 0) { List<eu.ascetic.paas.applicationmanager.model.EventSample> samples = null; List<EventSample> eSamples = energyModeller.eventsData(null, applicationName, deploymentId, vmIds, eventId, startStamp, endStamp); samples = EnergyModellerConverter.convertList(eSamples); payload = XMLBuilder.getEventSampleCollectionXMLInfo(samples, applicationName, deploymentId, vmId, eventId); } return buildResponse(Status.OK, payload); } }  @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}/energy-sample") @Produces(MediaType.APPLICATION_XML) public 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) { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/vms/" + vmId + "/events/" + eventId + "/energy-sample?" + "startTime=" + startTime + "&endTime=" + endTime + "&interval=" + interval); if(startTime == 0 || endTime == 0) { return buildResponse(Status.BAD_REQUEST, "It is mandatory to specify startTime and endTime!!!"); } else { String payload = null; VM vm = vmDAO.getById(Integer.parseInt(vmId)); List<String> vmIds = new ArrayList<String>(); vmIds.add("" + vm.getId()); Timestamp startStamp = new Timestamp(startTime); Timestamp endStamp = new Timestamp(endTime); if(interval == 0) { List<eu.ascetic.paas.applicationmanager.model.EventSample> samples = null; List<EventSample> eSamples = energyModeller.eventsData(null, applicationName, deploymentId, vmIds, eventId, startStamp, endStamp); samples = EnergyModellerConverter.convertList(eSamples); payload = XMLBuilder.getEventSampleCollectionXMLInfo(samples, applicationName, deploymentId, vmId, eventId); } return buildResponse(Status.OK, payload); } }  @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);  }