use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class MockPaaSProvider method switchMaintenanceMode.
@Override
public void switchMaintenanceMode(PaaSDeploymentContext deploymentContext, boolean maintenanceModeOn) {
String deploymentPaaSId = deploymentContext.getDeploymentPaaSId();
MockRuntimeDeploymentInfo runtimeDeploymentInfo = runtimeDeploymentInfos.get(deploymentContext.getDeploymentPaaSId());
Topology topology = runtimeDeploymentInfo.getDeploymentContext().getDeploymentTopology();
Map<String, Map<String, InstanceInformation>> nodes = runtimeDeploymentInfo.getInstanceInformations();
if (nodes == null || nodes.isEmpty()) {
return;
}
for (Entry<String, Map<String, InstanceInformation>> nodeEntry : nodes.entrySet()) {
String nodeTemplateId = nodeEntry.getKey();
Map<String, InstanceInformation> nodeInstances = nodeEntry.getValue();
if (nodeInstances != null && !nodeInstances.isEmpty()) {
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeTemplateId);
NodeType nodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), topology.getDependencies());
if (ToscaTypeUtils.isOfType(nodeType, NormativeComputeConstants.COMPUTE_TYPE)) {
for (Entry<String, InstanceInformation> nodeInstanceEntry : nodeInstances.entrySet()) {
String instanceId = nodeInstanceEntry.getKey();
InstanceInformation instanceInformation = nodeInstanceEntry.getValue();
if (instanceInformation != null) {
switchInstanceMaintenanceMode(deploymentPaaSId, nodeTemplateId, instanceId, instanceInformation, maintenanceModeOn);
}
}
}
}
}
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class RuntimeController method executeOperation.
@ApiOperation(value = "Trigger a custom command on a specific node template of a topology .", authorizations = { @Authorization("APPLICATION_MANAGER") }, notes = "Returns a response with no errors and the command response as data in success case. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/{applicationId:.+?}/operations", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("isAuthenticated()")
@Audit(bodyHiddenFields = { "secretProviderCredentials" })
public DeferredResult<RestResponse<Object>> executeOperation(@PathVariable String applicationId, @RequestBody @Valid OperationExecRequest operationRequest) {
final DeferredResult<RestResponse<Object>> result = new DeferredResult<>(15L * 60L * 1000L);
Application application = applicationService.getOrFail(applicationId);
ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(applicationId, operationRequest.getApplicationEnvironmentId());
AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
Topology topology = deploymentRuntimeStateService.getRuntimeTopologyFromEnvironment(operationRequest.getApplicationEnvironmentId());
// validate the operation request
try {
validateCommand(operationRequest, topology);
} catch (ConstraintViolationException e) {
result.setErrorResult(RestResponseBuilder.<Object>builder().data(e.getConstraintInformation()).error(new RestError(RestErrorCode.PROPERTY_CONSTRAINT_VIOLATION_ERROR.getCode(), e.getMessage())).build());
return result;
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
result.setErrorResult(RestResponseBuilder.<Object>builder().data(e.getConstraintInformation()).error(new RestError(RestErrorCode.PROPERTY_TYPE_VIOLATION_ERROR.getCode(), e.getMessage())).build());
return result;
} catch (ConstraintRequiredParameterException e) {
result.setErrorResult(RestResponseBuilder.<Object>builder().data(e.getConstraintInformation()).error(new RestError(RestErrorCode.PROPERTY_REQUIRED_VIOLATION_ERROR.getCode(), e.getMessage())).build());
return result;
} catch (ConstraintFunctionalException e) {
result.setErrorResult(RestResponseBuilder.<Object>builder().data(e.getConstraintInformation()).error(new RestError(RestErrorCode.PROPERTY_UNKNOWN_VIOLATION_ERROR.getCode(), e.getMessage())).build());
return result;
}
// try to trigger the execution of the operation
try {
deploymentRuntimeService.triggerOperationExecution(operationRequest, new IPaaSCallback<Map<String, String>>() {
@Override
public void onSuccess(Map<String, String> data) {
result.setResult(RestResponseBuilder.<Object>builder().data(data).build());
}
@Override
public void onFailure(Throwable throwable) {
result.setErrorResult(RestResponseBuilder.<Object>builder().error(new RestError(RestErrorCode.NODE_OPERATION_EXECUTION_ERROR.getCode(), throwable.getMessage())).build());
}
});
} catch (OperationExecutionException e) {
result.setErrorResult(RestResponseBuilder.<Object>builder().error(new RestError(RestErrorCode.NODE_OPERATION_EXECUTION_ERROR.getCode(), e.getMessage())).build());
} catch (OrchestratorDisabledException e) {
result.setErrorResult(RestResponseBuilder.<Object>builder().error(new RestError(RestErrorCode.CLOUD_DISABLED_ERROR.getCode(), e.getMessage())).build());
}
return result;
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class DeploymentTopologyController method updateSubstitutionProperty.
@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;
}
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class DeploymentTopologyController method updateSubstitution.
/**
* 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();
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class DeploymentTopologyController method updateSubstitutionCapabilityProperty.
@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;
}
}
Aggregations