use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class AddRelationshipProcessor method processNodeOperation.
@Override
protected void processNodeOperation(Csar csar, Topology topology, AddRelationshipOperation operation, NodeTemplate sourceNode) {
if (operation.getRelationshipName() == null || operation.getRelationshipName().isEmpty()) {
throw new InvalidNameException("relationshipName", operation.getRelationshipName(), "Not null or empty");
}
if (AlienUtils.safe(sourceNode.getRelationships()).containsKey(operation.getRelationshipName())) {
throw new AlreadyExistException("Relationship " + operation.getRelationshipName() + " already exist on node " + operation.getNodeName());
}
if (sourceNode.getRequirements() == null || sourceNode.getRequirements().get(operation.getRequirementName()) == null) {
throw new NotFoundException("Unable to find requirement with name <" + operation.getRequirementName() + "> on the source node" + operation.getNodeName());
}
Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
// ensure that the target node exists
TopologyUtils.getNodeTemplate(topology.getId(), operation.getTarget(), nodeTemplates);
// We don't use the tosca context as the relationship type may not be in dependencies yet (that's why we use the load type below).
RelationshipType indexedRelationshipType = toscaTypeSearchService.find(RelationshipType.class, operation.getRelationshipType(), operation.getRelationshipVersion());
if (indexedRelationshipType == null) {
throw new NotFoundException(RelationshipType.class.getName(), operation.getRelationshipType() + ":" + operation.getRelationshipVersion(), "Unable to find relationship type to create template in topology.");
}
boolean upperBoundReachedSource = topologyRequirementBoundsValidationServices.isRequirementUpperBoundReachedForSource(sourceNode, operation.getRequirementName(), topology.getDependencies());
if (upperBoundReachedSource) {
// throw exception here
throw new RequirementBoundException(operation.getNodeName(), operation.getRequirementName());
}
boolean upperBoundReachedTarget = topologyCapabilityBoundsValidationServices.isCapabilityUpperBoundReachedForTarget(operation.getTarget(), nodeTemplates, operation.getTargetedCapabilityName(), topology.getDependencies());
// return with a rest response error
if (upperBoundReachedTarget) {
throw new CapabilityBoundException(operation.getTarget(), operation.getTargetedCapabilityName());
}
topologyService.loadType(topology, indexedRelationshipType);
NodeTemplate newSourceNode = topology.getNodeTemplates().get(sourceNode.getName());
if (sourceNode != newSourceNode) {
// topology has been reloaded
sourceNode = newSourceNode;
}
Map<String, RelationshipTemplate> relationships = sourceNode.getRelationships();
if (relationships == null) {
relationships = Maps.newHashMap();
sourceNode.setRelationships(relationships);
}
RelationshipTemplate relationshipTemplate = new RelationshipTemplate();
relationshipTemplate.setName(operation.getRelationshipName());
relationshipTemplate.setTarget(operation.getTarget());
relationshipTemplate.setTargetedCapabilityName(operation.getTargetedCapabilityName());
relationshipTemplate.setRequirementName(operation.getRequirementName());
relationshipTemplate.setRequirementType(sourceNode.getRequirements().get(operation.getRequirementName()).getType());
relationshipTemplate.setType(indexedRelationshipType.getElementId());
relationshipTemplate.setArtifacts(newLinkedHashMap(indexedRelationshipType.getArtifacts()));
relationshipTemplate.setAttributes(newLinkedHashMap(indexedRelationshipType.getAttributes()));
Map<String, AbstractPropertyValue> properties = new LinkedHashMap<String, AbstractPropertyValue>();
TemplateBuilder.fillProperties(properties, indexedRelationshipType.getProperties(), null);
relationshipTemplate.setProperties(properties);
relationships.put(operation.getRelationshipName(), relationshipTemplate);
TopologyContext topologyContext = workflowBuilderService.buildTopologyContext(topology, csar);
workflowBuilderService.addRelationship(topologyContext, operation.getNodeName(), operation.getRelationshipName());
log.debug("Added relationship to the topology [" + topology.getId() + "], node name [" + operation.getNodeName() + "], relationship name [" + operation.getRelationshipName() + "]");
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class UnsetNodeCapabilityPropertyAsInputProcessor method processNodeOperation.
@Override
protected void processNodeOperation(Csar csar, Topology topology, UnsetNodeCapabilityPropertyAsInputOperation operation, NodeTemplate nodeTemplate) {
Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} do not exist for node {}", operation.getCapabilityName(), operation.getNodeName());
// check if the node property value is a get_input
AbstractPropertyValue currentValue = capabilityTemplate.getProperties().get(operation.getPropertyName());
if (!isGetInput(currentValue)) {
throw new NotFoundException("Property {} of node {} is not associated to an input.", operation.getPropertyName(), operation.getNodeName());
}
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capabilityTemplate.getType());
PropertyDefinition capabilityPropertyDefinition = getOrFail(capabilityType.getProperties(), operation.getPropertyName(), "Property {} do not exist for capability {} of node {}", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName());
AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(capabilityPropertyDefinition);
capabilityTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue);
log.debug("Remove association from property [ {} ] of capability template [ {} ] of node [ {} ] to an input of the topology [ {} ].", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName(), topology.getId());
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class PreDeploymentTopologyValidator method process.
@Override
public void process(Topology topology, FlowExecutionContext context) {
DeploymentMatchingConfiguration matchingConfiguration = context.getConfiguration(DeploymentMatchingConfiguration.class, PreDeploymentTopologyValidator.class.getSimpleName()).orElseThrow(() -> new NotFoundException("Failed to find deployment configuration for pre-deployment validation."));
OrchestratorDeploymentProperties orchestratorDeploymentProperties = context.getConfiguration(OrchestratorDeploymentProperties.class, PreDeploymentTopologyValidator.class.getSimpleName()).orElse(new OrchestratorDeploymentProperties(matchingConfiguration.getVersionId(), matchingConfiguration.getEnvironmentId(), matchingConfiguration.getOrchestratorId()));
TopologyValidationResult validationResult = deploymentTopologyValidationService.validateProcessedDeploymentTopology(topology, matchingConfiguration, orchestratorDeploymentProperties);
for (AbstractTask task : safe(validationResult.getTaskList())) {
context.log().error(task);
}
for (AbstractTask task : safe(validationResult.getInfoList())) {
context.log().info(task);
}
for (AbstractTask task : safe(validationResult.getWarningList())) {
context.log().warn(task);
}
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class SetMatchedNodePropertyModifier method setNodeCapabilityProperty.
private void setNodeCapabilityProperty(FlowExecutionContext context, LocationResourceTemplate locationResourceTemplate, NodeTemplate nodeTemplate, String capabilityName, DeploymentMatchingConfiguration matchingConfiguration) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
Capability locationResourceCapability = locationResourceTemplate.getTemplate().getCapabilities().get(capabilityName);
if (locationResourceCapability == null) {
throw new NotFoundException("The capability <" + capabilityName + "> cannot be found on node template <" + templateId + "> of type <" + locationResourceTemplate.getTemplate().getType() + ">");
}
PropertyDefinition propertyDefinition = ToscaContext.getOrFail(CapabilityType.class, locationResourceCapability.getType()).getProperties().get(propertyName);
if (propertyDefinition == null) {
throw new NotFoundException("No property with name <" + propertyName + "> can be found on capability <" + capabilityName + "> of type <" + locationResourceCapability.getType() + ">");
}
AbstractPropertyValue locationResourcePropertyValue = locationResourceTemplate.getTemplate().getCapabilities().get(capabilityName).getProperties().get(propertyName);
ensureNotSet(locationResourcePropertyValue, "by the admin in the Location Resource Template", propertyName, propertyValue);
AbstractPropertyValue originalNodePropertyValue = safe(nodeTemplate.getCapabilities().get(capabilityName).getProperties()).get(propertyName);
ensureNotSet(originalNodePropertyValue, "in the portable topology", propertyName, propertyValue);
// Update the configuration
NodePropsOverride nodePropsOverride = getTemplatePropsOverride(matchingConfiguration);
if (propertyValue == null && nodePropsOverride.getCapabilities().get(capabilityName) != null) {
nodePropsOverride.getCapabilities().get(capabilityName).getProperties().remove(propertyName);
} else {
// Set check constraints
ConstraintPropertyService.checkPropertyConstraint(propertyName, propertyValue, propertyDefinition);
NodeCapabilitiesPropsOverride nodeCapabilitiesPropsOverride = nodePropsOverride.getCapabilities().computeIfAbsent(capabilityName, k -> new NodeCapabilitiesPropsOverride());
nodeCapabilitiesPropsOverride.getProperties().put(propertyName, PropertyService.asPropertyValue(propertyValue));
}
context.saveConfiguration(matchingConfiguration);
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class TopologyService method loadType.
/**
* Load a type into the topology (add dependency for this new type, upgrade if necessary ...)
*
* If the dependency added has been upgraded into the topology, then recover the topology
*
* @param topology the topology
* @param element the element to load
* @param <T> tosca element type
* @return The real loaded element if element given in argument is from older archive than topology's dependencies
*/
@SuppressWarnings("unchecked")
public <T extends AbstractToscaType> T loadType(Topology topology, T element) {
String type = element.getElementId();
String archiveName = element.getArchiveName();
String archiveVersion = element.getArchiveVersion();
CSARDependency toLoadDependency = csarDependencyLoader.buildDependencyBean(archiveName, archiveVersion);
// FIXME Transitive dependencies could change here and thus types be affected ?
ToscaTypeLoader typeLoader = initializeTypeLoader(topology, true);
boolean upgraded = typeLoader.loadType(type, toLoadDependency);
ToscaContext.get().resetDependencies(typeLoader.getLoadedDependencies());
// Validate does not induce missing types
try {
this.checkForMissingTypes(topology);
} catch (NotFoundException e) {
// Revert changes made to the Context then throw.
ToscaContext.get().resetDependencies(topology.getDependencies());
throw new VersionConflictException("Adding the type [" + element.getId() + "] from archive [" + element.getArchiveName() + ":" + element.getArchiveVersion() + "] changes the topology dependencies and induces missing types. " + "Try with another version instead. Not found : [" + e.getMessage() + "].", e);
}
topology.setDependencies(typeLoader.getLoadedDependencies());
// recover the topology if needed
if (upgraded) {
recover(topology, toLoadDependency);
}
return ToscaContext.getOrFail((Class<T>) element.getClass(), type);
}
Aggregations