use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class DeploymentEventHandler method checkDeploymentAuthorization.
private void checkDeploymentAuthorization(Authentication authentication, User a4cUser, String deploymentId) {
Deployment deployment = alienDAO.findById(Deployment.class, deploymentId);
switch(deployment.getSourceType()) {
case APPLICATION:
// check if the user has right for the environment associated with the deployment.
ApplicationEnvironment environment = alienDAO.findById(ApplicationEnvironment.class, deployment.getEnvironmentId());
if (environment == null) {
log.error("Environment with id [{}] do not exist any more for deployment [{}]", deployment.getEnvironmentId(), deployment.getId());
throw new NotFoundException("Environment with id [" + deployment.getEnvironmentId() + "] do not exist any more for deployment [" + deployment.getId() + "]");
}
AuthorizationUtil.checkAuthorization(a4cUser, environment, ApplicationRole.APPLICATION_MANAGER, ApplicationEnvironmentRole.values());
break;
case CSAR:
AuthorizationUtil.checkHasOneRoleIn(authentication, Role.COMPONENTS_MANAGER);
}
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class BlockStorageEventHandler method getAggregatedVolumeIds.
private Map<String, Object> getAggregatedVolumeIds(DeploymentTopology topology, String nodeTemplateId, Map<String, Object> persistentProperties) {
NodeTemplate nodeTemplate;
try {
nodeTemplate = TopologyUtils.getNodeTemplate(topology, nodeTemplateId);
} catch (NotFoundException e) {
log.warn("Fail to update volumeIds for node " + nodeTemplateId, e);
return null;
}
Map<String, Object> aggregatedProperties = Maps.newHashMap();
Map<String, Object> concernedNodeProperties = extractConcernedNodeProperties(nodeTemplate.getName(), nodeTemplate.getProperties(), persistentProperties.keySet());
List<Map<String, String>> splittedNodeProperties = splitNodePropertiesValue(concernedNodeProperties);
if (!persistentPropertiesAlreadyExist(persistentProperties, splittedNodeProperties)) {
aggregatedProperties = buildAggregatedProperties(persistentProperties, concernedNodeProperties);
}
return aggregatedProperties;
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class BlockStorageEventHandler method updateApplicationTopology.
private void updateApplicationTopology(PaaSInstancePersistentResourceMonitorEvent persistentResourceEvent, final Map<String, Object> persistentProperties) {
Deployment deployment = deploymentService.get(persistentResourceEvent.getDeploymentId());
String topologyId = deployment.getSourceId() + ":" + deployment.getVersionId();
Topology topology = topoServiceCore.getOrFail(topologyId);
// The deployment topology may have changed and the node removed, in such situations there is nothing to update as the block won't be reused.
NodeTemplate nodeTemplate;
try {
nodeTemplate = TopologyUtils.getNodeTemplate(topology, persistentResourceEvent.getNodeTemplateId());
} catch (NotFoundException e) {
log.warn("Fail to update persistent resource for node {}", persistentResourceEvent.getNodeTemplateId(), e);
return;
}
for (String propertyName : persistentProperties.keySet()) {
Object propertyValue = persistentProperties.get(propertyName);
AbstractPropertyValue abstractPropertyValue = nodeTemplate.getProperties().get(propertyName);
if (abstractPropertyValue != null && abstractPropertyValue instanceof FunctionPropertyValue) {
// the value is set in the topology
FunctionPropertyValue function = (FunctionPropertyValue) abstractPropertyValue;
if (function.getFunction().equals(ToscaFunctionConstants.GET_INPUT) && propertyValue instanceof String) {
DeploymentInputs deploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(deployment.getVersionId(), deployment.getEnvironmentId()));
// the value is set in the input (deployment setup)
log.info("Updating deploymentsetup [ {} ] input properties [ {} ] to add a new VolumeId", deploymentInputs.getId(), function.getTemplateName());
log.debug("Property [ {} ] to update: [ {} ]. New value is [ {} ]", propertyName, persistentResourceEvent.getPersistentProperties().get(propertyName), propertyValue);
deploymentInputs.getInputs().put(function.getTemplateName(), new ScalarPropertyValue((String) propertyValue));
deploymentConfigurationDao.save(deploymentInputs);
} else {
// this is not supported / print a warning
log.warn("Failed to store the id of the created block storage [ {} ] for deployment [ {} ] application [ {} ] environment [ {} ]");
return;
}
} else {
DeploymentMatchingConfiguration matchingConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(deployment.getVersionId(), deployment.getEnvironmentId()));
log.info("Updating deployment topology: Persistent resource property [ {} ] for node template <{}.{}> to add a value", propertyName, matchingConfiguration.getId(), persistentResourceEvent.getNodeTemplateId());
log.debug("Value to add: [ {} ]. New value is [ {} ]", persistentResourceEvent.getPersistentProperties().get(propertyName), propertyValue);
matchingConfiguration.getMatchedNodesConfiguration().get(persistentResourceEvent.getNodeTemplateId()).getProperties().put(propertyName, getPropertyValue(propertyValue));
deploymentConfigurationDao.save(matchingConfiguration);
}
}
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class WorkflowUtils method getRelationshipTarget.
private static String getRelationshipTarget(String source, String relationshipId, TopologyContext topologyContext) {
NodeTemplate sourceNode = safe(topologyContext.getTopology().getNodeTemplates()).get(source);
if (sourceNode == null) {
throw new NotFoundException("Source " + source + " cannot be found in the topology " + topologyContext.getTopology().getId());
}
RelationshipTemplate relationshipTemplate = safe(sourceNode.getRelationships()).get(relationshipId);
if (relationshipTemplate == null) {
throw new NotFoundException("Source " + source + " does not have the relationship " + relationshipId + " in the topology " + topologyContext.getTopology().getId());
}
return relationshipTemplate.getTarget();
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class WorkflowsBuilderService method connectStepTo.
public Workflow connectStepTo(Topology topology, Csar csar, String workflowName, String stepId, String[] stepNames) {
TopologyContext topologyContext = buildTopologyContext(topology, csar);
Workflow wf = topology.getWorkflows().get(workflowName);
if (wf == null) {
throw new NotFoundException(String.format("The workflow '%s' can not be found", workflowName));
}
AbstractWorkflowBuilder builder = getWorkflowBuilder(topologyContext.getDSLVersion(), wf);
builder.connectStepTo(wf, stepId, stepNames);
workflowValidator.validate(topologyContext, wf);
return wf;
}
Aggregations