Search in sources :

Example 1 with TopologyDTO

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

the class ApplicationDeploymentController method getRuntimeTopology.

/**
 * Get runtime topology of an application on a specific environment or the current deployment topology if no deployment is active.
 * This method is necessary for example to compute output properties / attributes on the client side.
 *
 * @param applicationId application id for which to get the topology
 * @param applicationEnvironmentId application environment for which to get the topology
 * @return {@link RestResponse}<{@link TopologyDTO}> containing the requested runtime {@link Topology} and the
 *         {@link NodeType} related to its {@link NodeTemplate}s
 */
@ApiOperation(value = "Get last runtime (deployed) topology of an application or else get the current deployment topology for the environment.")
@RequestMapping(value = "/{applicationId:.+?}/environments/{applicationEnvironmentId:.+?}/runtime-topology", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<TopologyDTO> getRuntimeTopology(@ApiParam(value = "Id of the application for which to get deployed topology.", required = true) @PathVariable String applicationId, @ApiParam(value = "Id of the environment for which to get deployed topology.", required = true) @PathVariable String applicationEnvironmentId) {
    ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(applicationId, applicationEnvironmentId);
    if (!environment.getApplicationId().equals(applicationId)) {
        throw new NotFoundException("Unable to find environment with id <" + applicationEnvironmentId + "> for application <" + applicationId + ">");
    }
    AuthorizationUtil.checkAuthorizationForEnvironment(applicationService.getOrFail(applicationId), environment, ApplicationEnvironmentRole.APPLICATION_USER);
    Deployment deployment = deploymentService.getActiveDeployment(environment.getId());
    DeploymentTopology deploymentTopology = null;
    if (deployment != null) {
        deploymentTopology = deploymentRuntimeStateService.getRuntimeTopology(deployment.getId());
    }
    return RestResponseBuilder.<TopologyDTO>builder().data(topologyDTOBuilder.initTopologyDTO(deploymentTopology, new TopologyDTO())).build();
}
Also used : TopologyDTO(alien4cloud.topology.TopologyDTO) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) NotFoundException(alien4cloud.exception.NotFoundException) Deployment(alien4cloud.model.deployment.Deployment) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with TopologyDTO

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

the class EditorStepDefs method i_Recover_The_Topology.

@When("^I recover the topology$")
public void i_Recover_The_Topology() throws Throwable {
    thrownException = null;
    try {
        TopologyDTO dto = editorService.recover(topologyIds.getLast(), topologyIdToLastOperationId.get(topologyIds.getLast()));
        topologyIdToLastOperationId.put(topologyIds.getLast(), null);
        dtoEvaluationContext = new StandardEvaluationContext(dto);
        topologyEvaluationContext = new StandardEvaluationContext(dto.getTopology());
    } catch (Exception e) {
        log.error("Error occurred when recovering the topology", e);
        thrownException = e;
        exceptionEvaluationContext = new StandardEvaluationContext(e);
    }
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) TopologyDTO(alien4cloud.topology.TopologyDTO) NotFoundException(alien4cloud.exception.NotFoundException) IOException(java.io.IOException) When(cucumber.api.java.en.When)

Example 3 with TopologyDTO

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

the class TopologyTreeBuilderService method buildPaaSTopology.

/**
 * Build the topology for deployment on the PaaS.
 *
 * @param topology The topology.
 * @return The parsed topology for the PaaS with.
 */
@ToscaContextual
public PaaSTopology buildPaaSTopology(Topology topology) {
    PaaSTopology paaSTopology = buildPaaSTopology(buildPaaSNodeTemplates(topology));
    // Reuse this utility to query all types and inject them in the PaaSTopology
    TopologyDTO topologyDTO = topologyDTOBuilder.initTopologyDTO(topology, new TopologyDTO());
    paaSTopology.setDataTypes(topologyDTO.getDataTypes());
    paaSTopology.setCapabilityTypes(topologyDTO.getCapabilityTypes());
    paaSTopology.setRelationshipTypes(topologyDTO.getRelationshipTypes());
    paaSTopology.setNodeTypes(topologyDTO.getNodeTypes());
    return paaSTopology;
}
Also used : PaaSTopology(alien4cloud.paas.model.PaaSTopology) TopologyDTO(alien4cloud.topology.TopologyDTO) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Example 4 with TopologyDTO

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

the class RuntimeController method getDeployedTopology.

/**
 * Get runtime (deployed) topology of an application on a specific environment
 *
 * @param applicationId application id for which to get the topology
 * @param applicationEnvironmentId application environment for which to get the topology through the version
 * @return {@link RestResponse}<{@link TopologyDTO}> containing the requested runtime {@link Topology} and the
 *         {@link NodeType} related to his {@link NodeTemplate}s
 */
@ApiOperation(value = "Get runtime (deployed) topology of an application on a specific cloud.")
@RequestMapping(value = "/{applicationId:.+?}/environment/{applicationEnvironmentId:.+?}/topology", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<TopologyDTO> getDeployedTopology(@ApiParam(value = "Id of the application for which to get deployed topology.", required = true) @PathVariable String applicationId, @ApiParam(value = "Id of the environment for which to get deployed topology.", required = true) @PathVariable String applicationEnvironmentId) {
    ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(applicationId, applicationEnvironmentId);
    if (!environment.getApplicationId().equals(applicationId)) {
        throw new NotFoundException("Unable to find environment with id <" + applicationEnvironmentId + "> for application <" + applicationId + ">");
    }
    // Security check user must be authorized to deploy the environment (or be application manager)
    AuthorizationUtil.checkAuthorizationForEnvironment(applicationService.getOrFail(applicationId), environment);
    Deployment deployment = deploymentService.getActiveDeploymentOrFail(environment.getId());
    DeploymentTopology deploymentTopology = deploymentRuntimeStateService.getRuntimeTopology(deployment.getId());
    return RestResponseBuilder.<TopologyDTO>builder().data(topologyDTOBuilder.initTopologyDTO(deploymentTopology, new TopologyDTO())).build();
}
Also used : TopologyDTO(alien4cloud.topology.TopologyDTO) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) NotFoundException(alien4cloud.exception.NotFoundException) Deployment(alien4cloud.model.deployment.Deployment) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with TopologyDTO

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

the class ApplicationStepDefinitions method The_created_application_topology_is_the_same_as_the_one_in_the_base_topology_template.

@Then("^The created application topology is the same as the one in the base topology template$")
public void The_created_application_topology_is_the_same_as_the_one_in_the_base_topology_template() throws Throwable {
    // created topology
    String topologyId = Csar.createId(CURRENT_APPLICATION.getId(), VersionUtil.DEFAULT_VERSION_NAME);
    Context.getInstance().registerRestResponse(getRestClientInstance().get("/rest/v1/topologies/" + topologyId));
    TopologyDTO createdTopology = JsonUtil.read(Context.getInstance().getRestResponse(), TopologyDTO.class, Context.getJsonMapper()).getData();
    // base topology template
    // quick win solution
    authSteps.I_am_authenticated_with_role("ARCHITECT");
    String topoResponse = Context.getRestClientInstance().get("/rest/v1/catalog/topologies/" + TopologyTemplateStepDefinitions.CURRENT_TOPOLOGY_TEMP_ID);
    Topology topologyTemplateBase = JsonUtil.read(topoResponse, Topology.class, Context.getJsonMapper()).getData();
    Map<String, NodeTemplate> nodeTemplates = topologyTemplateBase.getNodeTemplates();
    // node templates count test
    assertEquals(createdTopology.getTopology().getNodeTemplates().size(), nodeTemplates.size());
    // node templates name / type test
    for (Map.Entry<String, NodeTemplate> entry : createdTopology.getTopology().getNodeTemplates().entrySet()) {
        assertTrue(nodeTemplates.containsKey(entry.getKey()));
        assertTrue(nodeTemplates.get(entry.getKey()).getType().equals(entry.getValue().getType()));
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) TopologyDTO(alien4cloud.topology.TopologyDTO) TestUtils.nullAsString(alien4cloud.it.utils.TestUtils.nullAsString) Topology(org.alien4cloud.tosca.model.templates.Topology) 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