Search in sources :

Example 31 with TopologyDTO

use of alien4cloud.topology.TopologyDTO in project alien4cloud by alien4cloud.

the class EditorController method upload.

/**
 * Method exposed to REST to upload a file in an archive under edition.
 *
 * @param topologyId The id of the topology/archive under edition.
 * @param lastOperationId The id of the user last known operation (for optimistic locking edition).
 * @param path The path in which to save/override the file in the archive.
 * @param file The file to save in the archive.
 */
@ApiIgnore
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{topologyId:.+}/upload", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public RestResponse<TopologyDTO> upload(@PathVariable String topologyId, @RequestParam("lastOperationId") String lastOperationId, @RequestParam("path") String path, @RequestParam(value = "file") MultipartFile file) throws IOException {
    if (lastOperationId != null && "null".equals(lastOperationId)) {
        lastOperationId = null;
    }
    try (InputStream artifactStream = file.getInputStream()) {
        UpdateFileOperation updateFileOperation = new UpdateFileOperation(path, artifactStream);
        updateFileOperation.setPreviousOperationId(lastOperationId);
        TopologyDTO topologyDTO = editorService.execute(topologyId, updateFileOperation);
        return RestResponseBuilder.<TopologyDTO>builder().data(topologyDTO).build();
    }
}
Also used : TopologyDTO(alien4cloud.topology.TopologyDTO) InputStream(java.io.InputStream) UpdateFileOperation(org.alien4cloud.tosca.editor.operations.UpdateFileOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ApiIgnore(springfox.documentation.annotations.ApiIgnore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 32 with TopologyDTO

use of alien4cloud.topology.TopologyDTO in project alien4cloud by alien4cloud.

the class TopologyController method get.

/**
 * Retrieve an existing {@link Topology}
 *
 * @param topologyId The id of the topology to retrieve.
 * @return {@link RestResponse}<{@link TopologyDTO}> containing the {@link Topology} and the {@link NodeType} related
 *         to his {@link NodeTemplate}s
 */
@ApiOperation(value = "Retrieve a topology from it's id.", notes = "Returns a topology with it's details. Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ]")
@RequestMapping(value = "/{topologyId:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<TopologyDTO> get(@PathVariable String topologyId) {
    Topology topology = topologyServiceCore.getOrFail(topologyId);
    topologyService.checkAccessAuthorizations(topology);
    try {
        topologyEditionContextManager.init(topologyId);
        editorService.checkTopologyRecovery();
        return RestResponseBuilder.<TopologyDTO>builder().data(dtoBuilder.buildTopologyDTO(EditionContextManager.get())).build();
    } finally {
        topologyEditionContextManager.destroy();
    }
}
Also used : TopologyDTO(alien4cloud.topology.TopologyDTO) Topology(org.alien4cloud.tosca.model.templates.Topology) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with TopologyDTO

use of alien4cloud.topology.TopologyDTO in project alien4cloud by alien4cloud.

the class InputPropertiesStepDefinitions method The_topology_should_not_have_the_property_defined_as_input_property.

@Then("^The topology should not have the property \"([^\"]*)\" defined as input property$")
public void The_topology_should_not_have_the_property_defined_as_input_property(String inputId) throws Throwable {
    TopologyDTO topologyDTO = JsonUtil.read(Context.getRestClientInstance().get("/rest/v1/topologies/" + Context.getInstance().getTopologyId()), TopologyDTO.class, Context.getJsonMapper()).getData();
    Map<String, PropertyDefinition> inputProperties = topologyDTO.getTopology().getInputs();
    Assert.assertFalse(inputProperties.containsKey(inputId));
}
Also used : TopologyDTO(alien4cloud.topology.TopologyDTO) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Then(cucumber.api.java.en.Then)

Example 34 with TopologyDTO

use of alien4cloud.topology.TopologyDTO in project alien4cloud by alien4cloud.

the class InputPropertiesStepDefinitions method The_topology_should_have_the_property_of_the_node_defined_as_input_property.

@Then("^The topology should have the property \"([^\"]*)\" defined as input property$")
public void The_topology_should_have_the_property_of_the_node_defined_as_input_property(String inputId) throws Throwable {
    String response = Context.getRestClientInstance().get("/rest/v1/topologies/" + Context.getInstance().getTopologyId());
    JavaType restResponseType = Context.getJsonMapper().getTypeFactory().constructParametricType(RestResponse.class, TopologyDTO.class);
    TopologyDTO topologyDTO = ((RestResponse<TopologyDTO>) Context.getJsonMapper().readValue(response, restResponseType)).getData();
    Map<String, PropertyDefinition> inputProperties = topologyDTO.getTopology().getInputs();
    Assert.assertNotNull(inputProperties);
    PropertyDefinition inputPropertieDefinition = inputProperties.get(inputId);
    Assert.assertNotNull(inputPropertieDefinition);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) TopologyDTO(alien4cloud.topology.TopologyDTO) RestResponse(alien4cloud.rest.model.RestResponse) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Then(cucumber.api.java.en.Then)

Example 35 with TopologyDTO

use of alien4cloud.topology.TopologyDTO in project alien4cloud by alien4cloud.

the class OutputPropertiesStepDefinitions method The_topology_should_not_have_the_capability_property_of_the_capability_for_the_node_defined_as_output_property.

@Then("^The topology should not have the capability property \"([^\"]*)\" of the capability \"([^\"]*)\" for the node \"([^\"]*)\" defined as output property$")
public void The_topology_should_not_have_the_capability_property_of_the_capability_for_the_node_defined_as_output_property(String propertyName, String capabilityId, String nodeName) throws Throwable {
    TopologyDTO topologyDTO = getTopologyDTO();
    Map<String, Map<String, Set<String>>> outputCapabilityProperties = topologyDTO.getTopology().getOutputCapabilityProperties();
    Assert.assertNotNull(outputCapabilityProperties);
    Map<String, Set<String>> outputPropertiesOfNode = outputCapabilityProperties.get(nodeName);
    Assert.assertNotNull(outputPropertiesOfNode);
    Set<String> outputPropertiesOfCapability = outputPropertiesOfNode.get(capabilityId);
    Assert.assertNotNull(outputPropertiesOfCapability);
    Assert.assertFalse(outputPropertiesOfCapability.contains(propertyName));
}
Also used : Set(java.util.Set) TopologyDTO(alien4cloud.topology.TopologyDTO) Map(java.util.Map) Then(cucumber.api.java.en.Then)

Aggregations

TopologyDTO (alien4cloud.topology.TopologyDTO)44 Then (cucumber.api.java.en.Then)27 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)12 Set (java.util.Set)6 NotFoundException (alien4cloud.exception.NotFoundException)5 RestResponse (alien4cloud.rest.model.RestResponse)4 JavaType (com.fasterxml.jackson.databind.JavaType)4 And (cucumber.api.java.en.And)4 When (cucumber.api.java.en.When)4 Map (java.util.Map)4 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)4 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)4 WorkflowStep (org.alien4cloud.tosca.model.workflow.WorkflowStep)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ApiOperation (io.swagger.annotations.ApiOperation)3 IOException (java.io.IOException)3 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)3 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)3 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)3