use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class DeploymentTopologyController method updatePolicySubstitution.
/**
* 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();
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class DeploymentTopologyController method updatePolicySubstitutionProperty.
@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;
}
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class DeploymentTopologyController method execute.
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);
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class DeploymentTopologyController method getDeploymentTopology.
/**
* 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();
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class MockPaaSProvider method doDeploy.
@Override
protected synchronized void doDeploy(final PaaSTopologyDeploymentContext deploymentContext) {
log.info("Deploying deployment [" + deploymentContext.getDeploymentPaaSId() + "]");
paaSDeploymentIdToAlienDeploymentIdMap.put(deploymentContext.getDeploymentPaaSId(), deploymentContext.getDeploymentId());
Topology topology = deploymentContext.getDeploymentTopology();
Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
if (nodeTemplates == null) {
nodeTemplates = Maps.newHashMap();
}
Map<String, Map<String, InstanceInformation>> currentInformations = Maps.newHashMap();
for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplates.entrySet()) {
Map<String, InstanceInformation> instanceInformations = Maps.newHashMap();
currentInformations.put(nodeTemplateEntry.getKey(), instanceInformations);
ScalingPolicy policy = getScalingPolicy(nodeTemplateEntry.getKey(), nodeTemplates, topology);
int initialInstances = policy != null ? policy.getInitialInstances() : 1;
for (int i = 1; i <= initialInstances; i++) {
InstanceInformation newInstanceInformation = newInstance(i);
instanceInformations.put(String.valueOf(i), newInstanceInformation);
notifyInstanceStateChanged(deploymentContext.getDeploymentPaaSId(), nodeTemplateEntry.getKey(), String.valueOf(i), newInstanceInformation, 1);
}
}
runtimeDeploymentInfos.put(deploymentContext.getDeploymentPaaSId(), new MockRuntimeDeploymentInfo(deploymentContext, DeploymentStatus.DEPLOYMENT_IN_PROGRESS, currentInformations));
changeStatus(deploymentContext.getDeploymentPaaSId(), DeploymentStatus.DEPLOYMENT_IN_PROGRESS);
executorService.schedule(new Runnable() {
@Override
public void run() {
switch(deploymentContext.getDeployment().getSourceName()) {
case BAD_APPLICATION_THAT_NEVER_WORKS:
changeStatus(deploymentContext.getDeploymentPaaSId(), DeploymentStatus.FAILURE);
break;
case WARN_APPLICATION_THAT_NEVER_WORKS:
changeStatus(deploymentContext.getDeploymentPaaSId(), DeploymentStatus.WARNING);
break;
default:
changeStatus(deploymentContext.getDeploymentPaaSId(), DeploymentStatus.DEPLOYED);
}
}
}, 5, TimeUnit.SECONDS);
}
Aggregations