@Test public void getEnergySampleBadRequestTest() { VMRest vmRest = new VMRest(); Response response = vmRest.getEnergySample("", "", "", "", 0, 0, 0); assertEquals(400, response.getStatus()); assertEquals("It is mandatory to specify startTime and endTime!!!", (String) response.getEntity()); response = vmRest.getEnergySample("", "", "", "", 1, 0, 0); assertEquals(400, response.getStatus()); assertEquals("It is mandatory to specify startTime and endTime!!!", (String) response.getEntity()); response = vmRest.getEnergySample("", "", "", "", 0, 1, 0); assertEquals(400, response.getStatus()); assertEquals("It is mandatory to specify startTime and endTime!!!", (String) response.getEntity()); }
@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);  }