/** * Get a cloud service archive, or fail with {@link NotFoundException} if not found * * @param name The name of the archive. * @param version The version of the archive. * @return The {@link Csar Cloud Service Archive} if found in the repository. */ public Csar getOrFail(String name, String version) { return getOrFail(Csar.createId(name, version)); }
@Id public String getId() { return Csar.createId(archiveName, archiveVersion); }
@Id public String getId() { return Csar.createId(applicationId, version); }
@Override public Csar getArchive(String archiveName, String archiveVersion) { return searchDAO.findById(Csar.class, Csar.createId(archiveName, archiveVersion)); }
public List<ScopeVariableExpressionDTO> getInEnvironmentTypeScope(String varName, String applicationId, String topologyVersion, String environmentType) { applicationService.checkAndGetApplication(applicationId); if (StringUtils.isBlank(environmentType)) { return Arrays.stream(EnvironmentType.values()).map(envType -> getVariableDef(varName, Csar.createId(applicationId, topologyVersion), envType)) .collect(Collectors.toList()); } else { EnvironmentType envType = EnvironmentType.valueOf(environmentType); return Lists.newArrayList(getVariableDef(varName, Csar.createId(applicationId, topologyVersion), envType)); } }
private Collection<? extends String> getEnvironmentTypeTopLevelVariables(String applicationId, String topologyVersion) { applicationService.checkAndGetApplication(applicationId); return Arrays.stream(EnvironmentType.values()) .map(environmentType -> editorFileService.loadEnvironmentTypeVariables(Csar.createId(applicationId, topologyVersion), environmentType).keySet()) .reduce(Sets.newHashSet(), (set, anotherSet) -> Sets.newHashSet(CollectionUtils.union(set, anotherSet))); }
private Collection<? extends String> getEnvironmentTopLevelVariables(String applicationId, String topologyVersion) { applicationService.checkAndGetApplication(applicationId); return Arrays.stream(applicationEnvironmentService.getAuthorizedByApplicationId(applicationId)) .map(env -> editorFileService.loadEnvironmentVariables(Csar.createId(applicationId, topologyVersion), env.getId()).keySet()) .reduce(Sets.newHashSet(), (set, anotherSet) -> Sets.newHashSet(CollectionUtils.union(set, anotherSet))); }
public List<ScopeVariableExpressionDTO> getInEnvironmentScope(String varName, String applicationId, String topologyVersion, String envId) { Application application = applicationService.getOrFail(applicationId); if (StringUtils.isBlank(envId)) { return Arrays.stream(applicationEnvironmentService.getAuthorizedByApplicationId(applicationId)) .map(env -> getVariableDef(varName, Csar.createId(env.getApplicationId(), topologyVersion), env)).collect(Collectors.toList()); } else { ApplicationEnvironment env = applicationEnvironmentService.getOrFail(envId); AuthorizationUtil.checkAuthorizationForEnvironment(application, env); return Lists.newArrayList(getVariableDef(varName, Csar.createId(env.getApplicationId(), topologyVersion), env)); } }
@Id @StringField(indexType = IndexType.not_analyzed, includeInAll = false) @FetchContext(contexts = { SUMMARY }, include = { true }) public String getId() { return createId(name, version); }
/** * Get the topology id linked to the environment * * @param applicationEnvironmentId The id of the environment. * @return a topology id or null */ @Deprecated public String getTopologyId(String applicationEnvironmentId) { ApplicationEnvironment applicationEnvironment = getOrFail(applicationEnvironmentId); ApplicationVersion applicationVersion = applicationVersionService .getOrFailByArchiveId(Csar.createId(applicationEnvironment.getApplicationId(), applicationEnvironment.getTopologyVersion())); ApplicationTopologyVersion topologyVersion = applicationVersion == null ? null : applicationVersion.getTopologyVersions().get(applicationEnvironment.getTopologyVersion()); return topologyVersion == null ? null : topologyVersion.getArchiveId(); }
/** * Update policy substitution. * * @param appId id of the application. * @param environmentId id of the environment. * @return response containing the deployment topology dto {@link DeploymentTopologyDTO}. */ @ApiOperation(value = "Substitute a specific policy by a location policy resource template in the topology of an application, given an environment.", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ DEPLOYMENT_MANAGER ]") @RequestMapping(value = "/policies/{policyId}/substitution", method = RequestMethod.POST) @PreAuthorize("isAuthenticated()") @Audit public RestResponse<DeploymentTopologyDTO> updatePolicySubstitution(@PathVariable String appId, @PathVariable String environmentId, @PathVariable String policyId, @RequestParam String locationResourceTemplateId) { Application application = applicationService.getOrFail(appId); ApplicationEnvironment environment = appEnvironmentService.getOrFail(environmentId); AuthorizationUtil.checkAuthorizationForEnvironment(application, environment); ApplicationTopologyVersion topologyVersion = applicationVersionService .getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion()); Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId()); DeploymentTopologyDTO dto = deploymentTopologyDTOBuilder.prepareDeployment(topology, () -> policyMatchingSubstitutionService.updateSubstitution(application, environment, topology, policyId, locationResourceTemplateId)); return RestResponseBuilder.<DeploymentTopologyDTO> builder().data(dto).build(); }
/** * Update node substitution. * * @param appId id of the application. * @param environmentId id of the environment. * @return response containing the available substitutions. */ @ApiOperation(value = "Substitute a specific node by the location resource template in the topology of an application given an environment.", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ DEPLOYMENT_MANAGER ]") @RequestMapping(value = "/substitutions/{nodeId}", method = RequestMethod.POST) @PreAuthorize("isAuthenticated()") @Audit public RestResponse<DeploymentTopologyDTO> updateSubstitution(@PathVariable String appId, @PathVariable String environmentId, @PathVariable String nodeId, @RequestParam String locationResourceTemplateId) { Application application = applicationService.getOrFail(appId); ApplicationEnvironment environment = appEnvironmentService.getOrFail(environmentId); AuthorizationUtil.checkAuthorizationForEnvironment(application, environment); ApplicationTopologyVersion topologyVersion = applicationVersionService .getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion()); Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId()); DeploymentTopologyDTO dto = deploymentTopologyDTOBuilder.prepareDeployment(topology, () -> nodeMatchingSubstitutionService.updateSubstitution(application, environment, topology, nodeId, locationResourceTemplateId)); return RestResponseBuilder.<DeploymentTopologyDTO> builder().data(dto).build(); }
/** * Get the deployment topology of an application given an environment * * @param appId application Id * @param environmentId environment Id * @return the deployment topology DTO */ @ApiOperation(value = "Get the deployment topology of an application given an environment.", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ DEPLOYMENT_MANAGER ]") @RequestMapping(value = "", method = RequestMethod.GET) @PreAuthorize("isAuthenticated()") public RestResponse<DeploymentTopologyDTO> getDeploymentTopology(@PathVariable String appId, @PathVariable String environmentId) { Application application = applicationService.getOrFail(appId); ApplicationEnvironment environment = appEnvironmentService.getOrFail(environmentId); AuthorizationUtil.checkAuthorizationForEnvironment(application, environment); ApplicationTopologyVersion topologyVersion = applicationVersionService .getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion()); Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId()); // This method prepares the deployment and create a Deployment Topology DTO object. DeploymentTopologyDTO dto = deploymentTopologyDTOBuilder.prepareDeployment(topology, application, environment); return RestResponseBuilder.<DeploymentTopologyDTO> builder().data(dto).build(); }
@ApiOperation(value = "Update substitution's capability property.", authorizations = { @Authorization("ADMIN") }) @RequestMapping(value = "/substitutions/{nodeId}/capabilities/{capabilityName}/properties", method = RequestMethod.POST) @PreAuthorize("isAuthenticated()") @Audit public RestResponse<?> updateSubstitutionCapabilityProperty(@PathVariable String appId, @PathVariable String environmentId, @PathVariable String nodeId, @PathVariable String capabilityName, @RequestBody UpdatePropertyRequest updateRequest) { try { Application application = applicationService.getOrFail(appId); ApplicationEnvironment environment = appEnvironmentService.getOrFail(environmentId); AuthorizationUtil.checkAuthorizationForEnvironment(application, environment); ApplicationTopologyVersion topologyVersion = applicationVersionService .getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion()); Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId()); DeploymentTopologyDTO dto = deploymentTopologyDTOBuilder.prepareDeployment(topology, () -> matchedNodePropertiesConfigService.updateProperty(application, environment, topology, nodeId, Optional.of(capabilityName), updateRequest.getPropertyName(), updateRequest.getPropertyValue())); return RestResponseBuilder.<DeploymentTopologyDTO> builder().data(dto).build(); } catch (ConstraintTechnicalException e) { if (e.getCause() instanceof ConstraintFunctionalException) { return RestConstraintValidator.fromException((ConstraintFunctionalException) e.getCause(), updateRequest.getPropertyName(), updateRequest.getPropertyValue()); } throw e; } }
@ApiOperation(value = "Update node substitution's property.", authorizations = { @Authorization("ADMIN") }) @RequestMapping(value = "/substitutions/{nodeId}/properties", method = RequestMethod.POST) @PreAuthorize("isAuthenticated()") @Audit public RestResponse<?> updateSubstitutionProperty(@PathVariable String appId, @PathVariable String environmentId, @PathVariable String nodeId, @RequestBody UpdatePropertyRequest updateRequest) { try { Application application = applicationService.getOrFail(appId); ApplicationEnvironment environment = appEnvironmentService.getOrFail(environmentId); AuthorizationUtil.checkAuthorizationForEnvironment(application, environment); ApplicationTopologyVersion topologyVersion = applicationVersionService .getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion()); Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId()); DeploymentTopologyDTO dto = deploymentTopologyDTOBuilder.prepareDeployment(topology, () -> matchedNodePropertiesConfigService.updateProperty(application, environment, topology, nodeId, Optional.empty(), updateRequest.getPropertyName(), updateRequest.getPropertyValue())); return RestResponseBuilder.<DeploymentTopologyDTO> builder().data(dto).build(); } catch (ConstraintTechnicalException e) { if (e.getCause() instanceof ConstraintFunctionalException) { return RestConstraintValidator.fromException((ConstraintFunctionalException) e.getCause(), updateRequest.getPropertyName(), updateRequest.getPropertyValue()); } throw e; } }
@ApiOperation(value = "Update policy substitution's property.", authorizations = { @Authorization("ADMIN") }) @RequestMapping(value = "/policies/{nodeId}/substitution/properties", method = RequestMethod.POST) @PreAuthorize("isAuthenticated()") @Audit public RestResponse<?> updatePolicySubstitutionProperty(@PathVariable String appId, @PathVariable String environmentId, @PathVariable String nodeId, @RequestBody UpdatePropertyRequest updateRequest) { try { Application application = applicationService.getOrFail(appId); ApplicationEnvironment environment = appEnvironmentService.getOrFail(environmentId); AuthorizationUtil.checkAuthorizationForEnvironment(application, environment); ApplicationTopologyVersion topologyVersion = applicationVersionService .getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion()); Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId()); DeploymentTopologyDTO dto = deploymentTopologyDTOBuilder.prepareDeployment(topology, () -> matchedPolicyPropertiesConfigService .updateProperty(application, environment, topology, nodeId, updateRequest.getPropertyName(), updateRequest.getPropertyValue())); return RestResponseBuilder.<DeploymentTopologyDTO> builder().data(dto).build(); } catch (ConstraintTechnicalException e) { if (e.getCause() instanceof ConstraintFunctionalException) { return RestConstraintValidator.fromException((ConstraintFunctionalException) e.getCause(), updateRequest.getPropertyName(), updateRequest.getPropertyValue()); } throw e; } }
/** * Get the active deployment monitoring data. * * @param applicationId id of the topology * @return the active deployment */ @ApiOperation(value = "Get active deployment for the given application on the given cloud.", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ DEPLOYMENT_MANAGER ]") @RequestMapping(value = "/{applicationId:.+}/environments/{applicationEnvironmentId}/active-deployment-monitored", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize("isAuthenticated()") public RestResponse<MonitoredDeploymentDTO> getActiveDeploymentMonitored(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId) { Application application = applicationService.checkAndGetApplication(applicationId); // get the topology from the version and the cloud from the environment ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(application.getId(), applicationEnvironmentId); AuthorizationUtil.checkAuthorizationForEnvironment(application, environment, ApplicationEnvironmentRole.APPLICATION_USER); Deployment deployment = deploymentService.getActiveDeployment(environment.getId()); ApplicationTopologyVersion topologyVersion = applicationVersionService .getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion()); Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId()); MonitoredDeploymentDTO monitoredDeploymentDTO = new MonitoredDeploymentDTO(); monitoredDeploymentDTO.setDeployment(deployment); Map<String, Integer> stepInstanceCount = toscaContextualAspect.execInToscaContext(() -> TopologyUtils.estimateWorkflowStepInstanceCount(topology), true, topology); monitoredDeploymentDTO.setWorkflowExpectedStepInstanceCount(stepInstanceCount); return RestResponseBuilder.<MonitoredDeploymentDTO> builder().data(monitoredDeploymentDTO).build(); }
private DeploymentTopologyDTO execute(String applicationId, String environmentId, IDeploymentConfigAction action) { Application application = applicationService.getOrFail(applicationId); ApplicationEnvironment environment = appEnvironmentService.getOrFail(environmentId); AuthorizationUtil.checkAuthorizationForEnvironment(application, environment); ApplicationTopologyVersion topologyVersion = applicationVersionService .getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion()); Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId()); // This method prepares the deployment and create a Deployment Topology DTO object. return deploymentTopologyDTOBuilder.prepareDeployment(topology, application, environment, topologyVersion, action); } }
@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 authSteps.I_am_authenticated_with_role("ARCHITECT"); // quick win solution 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())); } }
private void doCreateApplication(String name, String archiveName, String description, String topologyTemplateId, boolean register) throws IOException { CreateApplicationRequest request = new CreateApplicationRequest(archiveName, name, description, topologyTemplateId); Context.getInstance().registerRestResponse(getRestClientInstance().postJSon("/rest/v1/applications/", JsonUtil.toString(request))); // Registration makes a lot of implicit calls for simplification of features files but make them not fully meaningful. We should stop using group things // and rely on complete features. if (!register) { return; } try { // check the created application (topologyId) RestResponse<String> response = JsonUtil.read(Context.getInstance().getRestResponse(), String.class); String applicationJson = getRestClientInstance().get("/rest/v1/applications/" + response.getData()); Application application = JsonUtil.read(applicationJson, Application.class).getData(); if (application != null) { CURRENT_APPLICATION = application; CURRENT_APPLICATIONS.put(name, application); Context.getInstance().registerApplication(application); Context.getInstance().registerApplicationId(name, application.getId()); setAppEnvironmentIdToContext(application.getName()); setAppVersionIdToContext(application.getId()); String topologyId = Csar.createId(application.getId(), VersionUtil.DEFAULT_VERSION_NAME); assertNotNull(topologyId); Context.getInstance().registerTopologyId(topologyId); } } catch (Throwable t) { } }