@Test @SuppressWarnings(value = { "static-access" }) public void getPredictedPriceForNextPeriod() throws Exception { DeploymentRest deploymentRest = new DeploymentRest(); Response response = deploymentRest.getPredictedPriceForNextPeriod("asdf", "11", "aa"); assertEquals(400, response.getStatus()); assertEquals("Duration must be a positive number!!!", (String) response.getEntity()); response = deploymentRest.getPredictedPriceForNextPeriod("asdf", "11", ""); assertEquals(400, response.getStatus()); assertEquals("Duration must be a positive number!!!", (String) response.getEntity()); response = deploymentRest.getPredictedPriceForNextPeriod("asdf", "11", "-2"); assertEquals(400, response.getStatus()); assertEquals("Duration must be a positive number!!!", (String) response.getEntity()); PriceModellerClient pmc = mock(PriceModellerClient.class); deploymentRest.priceModellerClient = pmc; when(pmc.predictPriceForNextPeriod(111, 22.3)).thenReturn(45.7); response = deploymentRest.getPredictedPriceForNextPeriod("asdf", "111", "22.3"); assertEquals(200, response.getStatus()); String entity = (String) response.getEntity(); Cost cost = ModelConverter.xmlCostToObject(entity); assertEquals(45.7, cost.getCharges(), 0.001); assertEquals(-1.0, cost.getEnergyValue(), 0.0001); assertEquals(-1.0, cost.getPowerValue(), 0.0001); }
@GET @Path("{deployment_id}/predicted-price-for-next-period") @Produces(MediaType.APPLICATION_XML) public Response getPredictedPriceForNextPeriod(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId, @QueryParam("duration") String duration) throws InterruptedException { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/predicted-price-for-next-period?duration=" + duration); if(!isNumeric(duration)) { return buildResponse(Status.BAD_REQUEST, "Duration must be a positive number!!!"); } double totalCost = priceModellerClient.predictPriceForNextPeriod(Integer.parseInt(deploymentId), Double.parseDouble(duration)); Cost cost = new Cost(); cost.setCharges(totalCost); cost.setEnergyValue(-1.0); cost.setPowerValue(-1.0); String xml = XMLBuilder.getCostConsumptionForADeployment(cost, applicationName, deploymentId); return buildResponse(Status.OK, xml); }
DeploymentRest extends AbstractRest { @GET @Path("{deployment_id}/predicted-price-for-next-period") @Produces(MediaType.APPLICATION_XML) public Response getPredictedPriceForNextPeriod(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId, @QueryParam("duration") String duration) throws InterruptedException { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/predicted-price-for-next-period?duration=" + duration); if(!isNumeric(duration)) { return buildResponse(Status.BAD_REQUEST, "Duration must be a positive number!!!"); } double totalCost = priceModellerClient.predictPriceForNextPeriod(Integer.parseInt(deploymentId), Double.parseDouble(duration)); Cost cost = new Cost(); cost.setCharges(totalCost); cost.setEnergyValue(-1.0); cost.setPowerValue(-1.0); String xml = XMLBuilder.getCostConsumptionForADeployment(cost, applicationName, deploymentId); return buildResponse(Status.OK, xml); } }
DeploymentRest extends AbstractRest { @GET @Path("{deployment_id}/predicted-price-for-next-period") @Produces(MediaType.APPLICATION_XML) public Response getPredictedPriceForNextPeriod(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId, @QueryParam("duration") String duration) throws InterruptedException { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/predicted-price-for-next-period?duration=" + duration); if(!isNumeric(duration)) { return buildResponse(Status.BAD_REQUEST, "Duration must be a positive number!!!"); } double totalCost = priceModellerClient.predictPriceForNextPeriod(Integer.parseInt(deploymentId), Double.parseDouble(duration)); Cost cost = new Cost(); cost.setCharges(totalCost); cost.setEnergyValue(-1.0); cost.setPowerValue(-1.0); String xml = XMLBuilder.getCostConsumptionForADeployment(cost, applicationName, deploymentId); return buildResponse(Status.OK, xml); }  }
DeploymentRest extends AbstractRest { @GET @Path("{deployment_id}/predicted-price-for-next-period") @Produces(MediaType.APPLICATION_XML) public Response getPredictedPriceForNextPeriod(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId, @QueryParam("duration") String duration) throws InterruptedException { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/predicted-price-for-next-period?duration=" + duration); if(!isNumeric(duration)) { return buildResponse(Status.BAD_REQUEST, "Duration must be a positive number!!!"); } double totalCost = priceModellerClient.predictPriceForNextPeriod(Integer.parseInt(deploymentId), Double.parseDouble(duration)); Cost cost = new Cost(); cost.setCharges(totalCost); cost.setEnergyValue(-1.0); cost.setPowerValue(-1.0); String xml = XMLBuilder.getCostConsumptionForADeployment(cost, applicationName, deploymentId); return buildResponse(Status.OK, xml); }  @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 { @GET @Path("{deployment_id}/predicted-price-for-next-period") @Produces(MediaType.APPLICATION_XML) public Response getPredictedPriceForNextPeriod(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId, @QueryParam("duration") String duration) throws InterruptedException { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/predicted-price-for-next-period?duration=" + duration); if(!isNumeric(duration)) { return buildResponse(Status.BAD_REQUEST, "Duration must be a positive number!!!"); } double totalCost = priceModellerClient.predictPriceForNextPeriod(Integer.parseInt(deploymentId), Double.parseDouble(duration)); Cost cost = new Cost(); cost.setCharges(totalCost); cost.setEnergyValue(-1.0); cost.setPowerValue(-1.0); String xml = XMLBuilder.getCostConsumptionForADeployment(cost, applicationName, deploymentId); return buildResponse(Status.OK, xml); }  @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);  }