Commit aa6a9e44 authored by Spiros Koulouzis's avatar Spiros Koulouzis

added scaler controller. added node name parameter in delete. added queue name in execute

parent 2cf859b7
......@@ -25,9 +25,6 @@ public class DeployerApiController implements DeployerApi {
private final HttpServletRequest request;
@Value("${message.broker.queue.deployer}")
private String queueName;
@Autowired
private DRIPService dripService;
......@@ -43,7 +40,6 @@ public class DeployerApiController implements DeployerApi {
if (accept != null && accept.contains("")) {
try {
dripService.setRequestQeueName(queueName);
String planedYemplateId = dripService.deploy(id);
return new ResponseEntity<>(planedYemplateId, HttpStatus.OK);
......
......@@ -7,19 +7,9 @@ package nl.uva.sne.drip.api;
import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.List;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-06T13:31:49.386Z")
@Api(value = "planner", description = "the planner API")
......
......@@ -26,8 +26,7 @@ public class PlannerApiController implements PlannerApi {
private final HttpServletRequest request;
@Value("${message.broker.queue.planner}")
private String queueName;
@Autowired
private DRIPService dripService;
......@@ -45,7 +44,6 @@ public class PlannerApiController implements PlannerApi {
if (accept != null && accept.contains("text/plain")) {
try {
dripService.setRequestQeueName(queueName);
String planedYemplateId = dripService.plan(id);
return new ResponseEntity<>(planedYemplateId, HttpStatus.OK);
} catch (ApiException | NotFoundException | IOException | TimeoutException | InterruptedException ex) {
......
......@@ -32,9 +32,6 @@ public class ProvisionerApiController implements ProvisionerApi {
private final HttpServletRequest request;
@Value("${message.broker.queue.provisioner}")
private String queueName;
@Autowired
private DRIPService dripService;
......@@ -51,7 +48,6 @@ public class ProvisionerApiController implements ProvisionerApi {
String accept = request.getHeader("Accept");
if (accept != null && accept.contains("text/plain")) {
try {
dripService.setRequestQeueName(queueName);
String planedYemplateId = dripService.provision(id);
return new ResponseEntity<>(planedYemplateId, HttpStatus.OK);
} catch (ApiException | TypeExeption | IOException | TimeoutException | InterruptedException | NotFoundException ex) {
......
/**
* NOTE: This class is auto generated by the swagger code generator program (2.4.10).
* https://github.com/swagger-api/swagger-codegen
* Do not edit the class manually.
*/
package nl.uva.sne.drip.api;
import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-06T13:31:49.386Z")
@Api(value = "scaler", description = "the scaler API")
public interface ScalerApi {
@ApiOperation(value = "provision tosca template", nickname = "scaleProvisionedToscaTemplateByID", notes = "deletes the provisioned Infrastructure", response = String.class, authorizations = {
@Authorization(value = "auth", scopes = {
@AuthorizationScope(scope = "read:ToscaTemplate", description = "read your topolog template")
,
@AuthorizationScope(scope = "write:ToscaTemplate", description = "modify topolog template in your account")
})
}, tags = {})
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = String.class)
,
@ApiResponse(code = 400, message = "Invalid ID supplied")
,
@ApiResponse(code = 404, message = "ToscaTemplate not found")
,
@ApiResponse(code = 405, message = "Invalid input")})
@RequestMapping(value = "/scaler/{id}",
produces = {"text/plain"},
method = RequestMethod.GET)
ResponseEntity<String> scaleProvisionedToscaTemplateByID(
@ApiParam(value = "ID of topolog template to plan", required = true)
@PathVariable("id") String id,
@NotNull @ApiParam(value = "The node to scale", required = true)
@Valid @RequestParam(value = "node_name", required = true) String nodeName,
@NotNull @ApiParam(value = "The number of nodes to scale", required = true)
@Valid @RequestParam(value = "node_num", required = true) Integer nodeNum);
}
package nl.uva.sne.drip.api;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.ApiParam;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import nl.uva.sne.drip.service.DRIPService;
import nl.uva.sne.drip.service.ToscaTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-10-10T17:15:46.465Z")
@Controller
public class ScalerApiController implements ScalerApi {
private static final Logger log = LoggerFactory.getLogger(ScalerApiController.class);
private final HttpServletRequest request;
@Autowired
private ToscaTemplateService toscaTemplateService;
@Autowired
private DRIPService dripService;
@Value("${message.broker.queue.provisioner}")
private String provisionerQueueName;
@org.springframework.beans.factory.annotation.Autowired
public ScalerApiController(ObjectMapper objectMapper, HttpServletRequest request) {
this.request = request;
}
@Override
public ResponseEntity<String> scaleProvisionedToscaTemplateByID(
@ApiParam(value = "ID of topolog template to plan", required = true)
@PathVariable("id") String id,
@NotNull @ApiParam(value = "The node to scale", required = true)
@Valid @RequestParam(value = "node_name", required = true) String nodeName,
@NotNull @ApiParam(value = "The number of nodes to scale", required = true)
@Valid @RequestParam(value = "node_num", required = true) Integer nodeNum) {
String accept = request.getHeader("Accept");
if (accept != null && accept.contains("text/plain")) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
}
......@@ -5,13 +5,9 @@
*/
package nl.uva.sne.drip.api;
import org.springframework.core.io.Resource;
import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -19,92 +15,105 @@ import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.List;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-06T13:31:49.386Z")
@Api(value = "tosca_template", description = "the tosca_template API")
public interface ToscaTemplateApi {
@ApiOperation(value = "Deletes a tosca topology template", nickname = "deleteToscaTemplateByID", notes = "", response = String.class, authorizations = {
@ApiOperation(value = "Deletes a tosca topology template", nickname = "deleteToscaTemplateByID", notes = "If the topology is provisoned it will delete the provison (Infrastructure). If it is deployed it will delete the deploymet too (Application)", response = String.class, authorizations = {
@Authorization(value = "auth", scopes = {
@AuthorizationScope(scope = "read:ToscaTemplate", description = "read your topolog template"),
@AuthorizationScope(scope = "read:ToscaTemplate", description = "read your topolog template")
,
@AuthorizationScope(scope = "write:ToscaTemplate", description = "modify topolog template in your account")
})
}, tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = String.class),
@ApiResponse(code = 400, message = "Invalid ID supplied"),
@ApiResponse(code = 404, message = "ToscaTemplate not found") })
})
}, tags = {})
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = String.class)
,
@ApiResponse(code = 400, message = "Invalid ID supplied")
,
@ApiResponse(code = 404, message = "ToscaTemplate not found")})
@RequestMapping(value = "/tosca_template/{id}",
method = RequestMethod.DELETE)
ResponseEntity<String> deleteToscaTemplateByID(@ApiParam(value = "ID of topology template to return",required=true) @PathVariable("id") String id);
method = RequestMethod.DELETE)
ResponseEntity<String> deleteToscaTemplateByID(@ApiParam(value = "ID of topology template to return", required = true) @PathVariable("id") String id, @ApiParam(value = "The node(s) to delete") @Valid @RequestParam(value = "node_name", required = false) List<String> nodeName);
@ApiOperation(value = "Find topolog template by ID", nickname = "getToscaTemplateByID", notes = "Returns a single topolog template", response = String.class, authorizations = {
@Authorization(value = "auth", scopes = {
@AuthorizationScope(scope = "read:ToscaTemplate", description = "read your topolog template"),
@AuthorizationScope(scope = "read:ToscaTemplate", description = "read your topolog template")
,
@AuthorizationScope(scope = "write:ToscaTemplate", description = "modify topolog template in your account")
})
}, tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = String.class),
@ApiResponse(code = 400, message = "Invalid ID supplied"),
@ApiResponse(code = 404, message = "ToscaTemplate not found"),
@ApiResponse(code = 405, message = "Invalid input") })
})
}, tags = {})
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = String.class)
,
@ApiResponse(code = 400, message = "Invalid ID supplied")
,
@ApiResponse(code = 404, message = "ToscaTemplate not found")
,
@ApiResponse(code = 405, message = "Invalid input")})
@RequestMapping(value = "/tosca_template/{id}",
produces = { "text/plain" },
method = RequestMethod.GET)
ResponseEntity<String> getToscaTemplateByID(@ApiParam(value = "ID of topolog template to return",required=true) @PathVariable("id") String id);
produces = {"text/plain"},
method = RequestMethod.GET)
ResponseEntity<String> getToscaTemplateByID(@ApiParam(value = "ID of topolog template to return", required = true) @PathVariable("id") String id);
@ApiOperation(value = "Get all topolog template IDs", nickname = "getToscaTemplateIDs", notes = "Returns all IDs", response = String.class, responseContainer = "List", authorizations = {
@Authorization(value = "auth", scopes = {
@AuthorizationScope(scope = "read:ToscaTemplate", description = "read your topolog template"),
@AuthorizationScope(scope = "read:ToscaTemplate", description = "read your topolog template")
,
@AuthorizationScope(scope = "write:ToscaTemplate", description = "modify topolog template in your account")
})
}, tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = String.class, responseContainer = "List"),
@ApiResponse(code = 400, message = "Invalid ID supplied"),
@ApiResponse(code = 404, message = "ToscaTemplate not found"),
@ApiResponse(code = 405, message = "Invalid input") })
})
}, tags = {})
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = String.class, responseContainer = "List")
,
@ApiResponse(code = 400, message = "Invalid ID supplied")
,
@ApiResponse(code = 404, message = "ToscaTemplate not found")
,
@ApiResponse(code = 405, message = "Invalid input")})
@RequestMapping(value = "/tosca_template/ids",
produces = { "application/json" },
method = RequestMethod.GET)
produces = {"application/json"},
method = RequestMethod.GET)
ResponseEntity<List<String>> getToscaTemplateIDs();
@ApiOperation(value = "Updates exisintg topolog template", nickname = "updateToscaTemplateByID", notes = "", response = String.class, authorizations = {
@Authorization(value = "auth", scopes = {
@AuthorizationScope(scope = "read:ToscaTemplate", description = "read your topolog template"),
@AuthorizationScope(scope = "read:ToscaTemplate", description = "read your topolog template")
,
@AuthorizationScope(scope = "write:ToscaTemplate", description = "modify topolog template in your account")
})
}, tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = String.class),
@ApiResponse(code = 400, message = "Invalid ID supplied"),
@ApiResponse(code = 404, message = "ToscaTemplate not found"),
@ApiResponse(code = 405, message = "Invalid input") })
})
}, tags = {})
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = String.class)
,
@ApiResponse(code = 400, message = "Invalid ID supplied")
,
@ApiResponse(code = 404, message = "ToscaTemplate not found")
,
@ApiResponse(code = 405, message = "Invalid input")})
@RequestMapping(value = "/tosca_template/{id}",
produces = { "text/plain" },
consumes = { "multipart/form-data" },
method = RequestMethod.PUT)
ResponseEntity<String> updateToscaTemplateByID(@ApiParam(value = "ID of topolog template to return",required=true) @PathVariable("id") String id,@ApiParam(value = "file detail") @Valid @RequestPart("file") MultipartFile file);
produces = {"text/plain"},
consumes = {"multipart/form-data"},
method = RequestMethod.PUT)
ResponseEntity<String> updateToscaTemplateByID(@ApiParam(value = "ID of topolog template to return", required = true) @PathVariable("id") String id, @ApiParam(value = "file detail") @Valid @RequestPart("file") MultipartFile file);
@ApiOperation(value = "upload a tosca template description file", nickname = "uploadToscaTemplate", notes = "uploads and validates TOSCA template file", response = String.class, authorizations = {
@Authorization(value = "auth", scopes = {
@AuthorizationScope(scope = "read:ToscaTemplate", description = "read your topolog template"),
@AuthorizationScope(scope = "read:ToscaTemplate", description = "read your topolog template")
,
@AuthorizationScope(scope = "write:ToscaTemplate", description = "modify topolog template in your account")
})
}, tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = String.class),
@ApiResponse(code = 405, message = "Invalid input") })
})
}, tags = {})
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = String.class)
,
@ApiResponse(code = 405, message = "Invalid input")})
@RequestMapping(value = "/tosca_template",
consumes = { "multipart/form-data" },
method = RequestMethod.POST)
consumes = {"multipart/form-data"},
method = RequestMethod.POST)
ResponseEntity<String> uploadToscaTemplate(@ApiParam(value = "file detail") @Valid @RequestPart("file") MultipartFile file);
}
......@@ -23,6 +23,7 @@ import nl.uva.sne.drip.service.DRIPService;
import nl.uva.sne.drip.service.ToscaTemplateService;
import nl.uva.sne.drip.sure.tosca.client.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-10-10T17:15:46.465Z")
......@@ -39,26 +40,36 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
@Autowired
private DRIPService dripService;
@org.springframework.beans.factory.annotation.Autowired
public ToscaTemplateApiController(ObjectMapper objectMapper, HttpServletRequest request) {
this.request = request;
}
@Override
public ResponseEntity<String> deleteToscaTemplateByID(@ApiParam(value = "ID of topolog template to return", required = true) @PathVariable("id") String id) {
public ResponseEntity<String> deleteToscaTemplateByID(
@ApiParam(value = "ID of topology template to return",required=true)
@PathVariable("id") String id,@ApiParam(value = "The node(s) to delete")
@Valid @RequestParam(value = "node_names", required = false) List<String> nodeName) {
String accept = request.getHeader("Accept");
if (accept != null && accept.contains("text/plain")) {
try {
String deleteedYemplateId = dripService.delete(id);
return new ResponseEntity<>(deleteedYemplateId, HttpStatus.OK);
} catch (NotFoundException | IOException | ApiException | TypeExeption | TimeoutException | InterruptedException ex) {
dripService.delete(id,nodeName);
return new ResponseEntity<>("", HttpStatus.OK);
} catch (IOException | ApiException | TypeExeption | TimeoutException | InterruptedException ex) {
java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.SEVERE, null, ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (NotFoundException ex) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
} else {
return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
}
}
@Override
public ResponseEntity<String> getToscaTemplateByID(@ApiParam(value = "ID of topolog template to return", required = true) @PathVariable("id") String id) {
......@@ -97,7 +108,6 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
} else {
return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
}
}
@Override
......
......@@ -26,6 +26,7 @@ import nl.uva.sne.drip.model.tosca.ToscaTemplate;
import nl.uva.sne.drip.rpc.DRIPCaller;
import nl.uva.sne.drip.sure.tosca.client.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
......@@ -44,8 +45,6 @@ public class DRIPService {
@Autowired
CredentialService credentialService;
private String requestQeueName;
@Autowired
private ToscaHelper helper;
......@@ -60,7 +59,16 @@ public class DRIPService {
PROVISION, DEPLOYMENT
}
private String execute(ToscaTemplate toscaTemplate) throws JsonProcessingException, ApiException, IOException, TimeoutException, InterruptedException {
@Value("${message.broker.queue.provisioner}")
private String provisionerQueueName;
@Value("${message.broker.queue.planner}")
private String plannerQueueName;
@Value("${message.broker.queue.deployer}")
private String deployerQueueName;
private String execute(ToscaTemplate toscaTemplate, String requestQeueName) throws JsonProcessingException, ApiException, IOException, TimeoutException, InterruptedException {
caller.init();
Logger.getLogger(DRIPService.class.getName()).log(Level.INFO, "toscaTemplate:\n{0}", toscaTemplate);
Message message = new Message();
......@@ -76,20 +84,6 @@ public class DRIPService {
}
/**
* @return the requestQeueName
*/
public String getRequestQeueName() {
return requestQeueName;
}
/**
* @param requestQeueName the requestQeueName to set
*/
public void setRequestQeueName(String requestQeueName) {
this.requestQeueName = requestQeueName;
}
private Credential getBestCredential(List<Credential> credentials) {
return credentials.get(0);
}
......@@ -120,14 +114,14 @@ public class DRIPService {
public String plan(String id) throws ApiException, NotFoundException, IOException, JsonProcessingException, TimeoutException, InterruptedException {
ToscaTemplate toscaTemplate = initExecution(id);
return execute(toscaTemplate);
return execute(toscaTemplate,plannerQueueName);
}
public String provision(String id) throws MissingCredentialsException, ApiException, TypeExeption, IOException, JsonProcessingException, TimeoutException, InterruptedException, NotFoundException, MissingVMTopologyException {
ToscaTemplate toscaTemplate = initExecution(id);
toscaTemplate = addCredentials(toscaTemplate);
toscaTemplate = setProvisionerOperation(toscaTemplate, PROVISIONER_OPERATION.PROVISION);
return execute(toscaTemplate);
return execute(toscaTemplate,provisionerQueueName);
}
protected ToscaTemplate setProvisionerOperation(ToscaTemplate toscaTemplate, PROVISIONER_OPERATION operation) throws IOException, JsonProcessingException, ApiException {
......@@ -160,7 +154,7 @@ public class DRIPService {
public String deploy(String id) throws JsonProcessingException, NotFoundException, IOException, ApiException, Exception {
ToscaTemplate toscaTemplate = initExecution(id);
return execute(toscaTemplate);
return execute(toscaTemplate,deployerQueueName);
}
protected ToscaTemplate initExecution(String id) throws JsonProcessingException, NotFoundException, IOException, ApiException {
......@@ -171,17 +165,19 @@ public class DRIPService {
return toscaTemplate;
}
public String delete(String id) throws NotFoundException, IOException, JsonProcessingException, ApiException, TypeExeption, TimeoutException, InterruptedException {
public String delete(String id, List<String> nodeNames) throws NotFoundException, IOException, JsonProcessingException, ApiException, TypeExeption, TimeoutException, InterruptedException {
ToscaTemplate toscaTemplate = initExecution(id);
List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
if (vmTopologies != null) {
for (NodeTemplateMap vmTopology : vmTopologies) {
CloudsStormSubTopology.StatusEnum status = helper.getVMTopologyTemplateStatus(vmTopology);
if (!status.equals(CloudsStormSubTopology.StatusEnum.DELETED)) {
toscaTemplate = setProvisionerOperation(toscaTemplate, PROVISIONER_OPERATION.DELETE);
if (nodeNames == null || nodeNames.isEmpty()) {
List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
if (vmTopologies != null) {
for (NodeTemplateMap vmTopology : vmTopologies) {
CloudsStormSubTopology.StatusEnum status = helper.getVMTopologyTemplateStatus(vmTopology);
if (!status.equals(CloudsStormSubTopology.StatusEnum.DELETED)) {
toscaTemplate = setProvisionerOperation(toscaTemplate, PROVISIONER_OPERATION.DELETE);
}
}
return execute(toscaTemplate,provisionerQueueName);
}
return execute(toscaTemplate);
}
return null;
}
......
......@@ -74,6 +74,12 @@ public class ServiceTests {
@Value("${message.broker.queue.provisioner}")
private String provisionerQueueName;
@Value("${message.broker.queue.planner}")
private String plannerQueueName;
@Value("${message.broker.queue.deployer}")
private String deployerQueueName;
@Value("${message.broker.host}")
private String messageBrokerHost;
......@@ -408,7 +414,6 @@ public class ServiceTests {
MultipartFile file = new MockMultipartFile("file", in);
String id = toscaTemplateService.saveFile(file);
dripService.setRequestQeueName(provisionerQueueName);
ToscaTemplate toscaTemplate = dripService.initExecution(id);
toscaTemplate = dripService.addCredentials(toscaTemplate);
toscaTemplate = dripService.setProvisionerOperation(toscaTemplate, DRIPService.PROVISIONER_OPERATION.PROVISION);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment