use of org.alien4cloud.tosca.model.types.RelationshipType in project alien4cloud by alien4cloud.
the class UpdateRelationshipPropertyValueProcessor method process.
@Override
public void process(Csar csar, Topology topology, UpdateRelationshipPropertyValueOperation operation) {
NodeTemplate nodeTemplate = AlienUtils.getOrFail(topology.getNodeTemplates(), operation.getNodeName(), "The node with name [ {} ] cannot be found in the topology.", operation.getNodeName());
RelationshipTemplate relationshipTemplate = AlienUtils.getOrFail(nodeTemplate.getRelationships(), operation.getRelationshipName(), "The relationship with name [ {} ] cannot be found in the node [ {} ].", operation.getRelationshipName(), operation.getNodeName());
RelationshipType relationshipType = ToscaContext.getOrFail(RelationshipType.class, relationshipTemplate.getType());
PropertyDefinition propertyDefinition = AlienUtils.getOrFail(relationshipType.getProperties(), operation.getPropertyName(), "Property [ {} ] doesn't exists in type [ {} ] for relationship [ {} ] of node [ {} ].", operation.getPropertyName(), relationshipTemplate.getType(), operation.getRelationshipName(), operation.getNodeName());
log.debug("Updating property [ {} ] of the relationship [ {} ] for the Node template [ {} ] from the topology [ {} ]: changing value from [{}] to [{}].", operation.getPropertyName(), relationshipType, operation.getNodeName(), topology.getId(), relationshipType.getProperties().get(operation.getPropertyName()), operation.getPropertyValue());
try {
propertyService.setPropertyValue(relationshipTemplate, propertyDefinition, operation.getPropertyName(), operation.getPropertyValue());
} catch (ConstraintFunctionalException e) {
throw new PropertyValueException("Error when setting relationship " + operation.getNodeName() + "." + operation.getRelationshipName() + " property.", e, operation.getPropertyName(), operation.getPropertyValue());
}
}
use of org.alien4cloud.tosca.model.types.RelationshipType in project alien4cloud by alien4cloud.
the class SetRelationshipPropertyAsSecretProcessor method processRelationshipOperation.
@Override
protected void processRelationshipOperation(Csar csar, Topology topology, SetRelationshipPropertyAsSecretOperation operation, NodeTemplate nodeTemplate, RelationshipTemplate relationshipTemplate) {
RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType());
PropertyDefinition relationshipPropertyDefinition = getOrFail(relationshipType.getProperties(), operation.getPropertyName(), "Property {} do not exist for relationship {} of node {}", operation.getPropertyName(), operation.getRelationshipName(), operation.getNodeName());
FunctionPropertyValue secretFunction = new FunctionPropertyValue();
secretFunction.setFunction(ToscaFunctionConstants.GET_SECRET);
secretFunction.setParameters(Arrays.asList(operation.getSecretPath()));
relationshipTemplate.getProperties().put(operation.getPropertyName(), secretFunction);
log.debug("Associate the property [ {} ] of relationship template [ {} ] of node [ {} ] to secret <path: {} > of the topology [ {} ].", operation.getPropertyName(), operation.getRelationshipName(), operation.getNodeName(), operation.getSecretPath(), topology.getId());
}
use of org.alien4cloud.tosca.model.types.RelationshipType in project alien4cloud by alien4cloud.
the class SearchDefinitionSteps method The_in_the_response_should_all_have_the.
@Then("^The \"([^\"]*)\" in the response should all have the \"([^\"]*)\" \"([^\"]*)\"$")
public void The_in_the_response_should_all_have_the(String searchedComponentType, String propertyValue, String property) throws Throwable {
RestResponse<FacetedSearchResult> restResponse = JsonUtil.read(Context.getInstance().takeRestResponse(), FacetedSearchResult.class);
FacetedSearchResult searchResp = restResponse.getData();
List<Object> resultData = Lists.newArrayList(searchResp.getData());
if (searchedComponentType.equalsIgnoreCase("node types")) {
for (Object object : resultData) {
NodeType idnt = JsonUtil.readObject(JsonUtil.toString(object), NodeType.class);
switch(property) {
case "capability":
assertNotNull(idnt.getCapabilities());
assertTrue(idnt.getCapabilities().contains(new CapabilityDefinition(propertyValue, propertyValue, 1)));
break;
case "requirement":
assertNotNull(idnt.getRequirements());
assertTrue(idnt.getRequirements().contains(new RequirementDefinition(propertyValue, propertyValue)));
break;
default:
break;
}
}
} else if (searchedComponentType.equalsIgnoreCase("relationship types")) {
for (Object object : resultData) {
RelationshipType idrt = JsonUtil.readObject(JsonUtil.toString(object), RelationshipType.class);
switch(property) {
case "validSource":
assertNotNull(idrt.getValidSources());
assertTrue(Arrays.equals(new String[] { propertyValue }, idrt.getValidSources()));
break;
default:
break;
}
}
}
}
use of org.alien4cloud.tosca.model.types.RelationshipType in project alien4cloud by alien4cloud.
the class IndexedModelUtils method mergeInheritableIndex.
public static void mergeInheritableIndex(AbstractInheritableToscaType from, AbstractInheritableToscaType to) {
if (from.getDerivedFrom() != null) {
// use a linked HashSet so we don't add multiple elements more than once.
LinkedHashSet<String> derivedFromSet = new LinkedHashSet<String>();
if (to.getDerivedFrom() != null) {
derivedFromSet.addAll(to.getDerivedFrom());
}
if (from.getDerivedFrom() != null) {
derivedFromSet.addAll(from.getDerivedFrom());
}
to.setDerivedFrom(new ArrayList<String>(derivedFromSet));
}
if (from.getTags() != null) {
if (to.getTags() == null) {
to.setTags(Lists.<Tag>newArrayList());
to.getTags().addAll(from.getTags());
} else {
// copy non existing tags from the parent "from"
for (Tag tag : from.getTags()) {
if (!to.getTags().contains(tag)) {
to.getTags().add(tag);
}
}
}
}
mergePropertiesAndAttributes(from, to);
if (from instanceof NodeType && to instanceof NodeType) {
mergeNodeType((NodeType) from, (NodeType) to);
}
if (from instanceof RelationshipType && to instanceof RelationshipType) {
mergeRelationshipType((RelationshipType) from, (RelationshipType) to);
}
}
use of org.alien4cloud.tosca.model.types.RelationshipType in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method testParseImplementationArtifactWithRepository.
@Test
public void testParseImplementationArtifactWithRepository() throws ParsingException {
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "implementation_artifact.yml"));
ParserTestUtil.displayErrors(parsingResult);
assertTrue(parsingResult.getContext().getParsingErrors().isEmpty());
ArchiveRoot archiveRoot = parsingResult.getResult();
assertNotNull(archiveRoot.getArchive());
Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
Assert.assertEquals(2, archiveRoot.getArtifactTypes().size());
Assert.assertEquals(4, archiveRoot.getNodeTypes().size());
Assert.assertEquals(3, archiveRoot.getRepositories().size());
Assert.assertEquals(3, archiveRoot.getRelationshipTypes().size());
NodeType httpComponent = archiveRoot.getNodeTypes().get("my.http.component");
validateHttpArtifact(httpComponent);
NodeType httpComponentExtended = archiveRoot.getNodeTypes().get("my.http.component.extended");
validateHttpArtifact(httpComponentExtended);
NodeType gitComponent = archiveRoot.getNodeTypes().get("my.git.component");
ImplementationArtifact gitComponentCreateArtifact = getImplementationArtifact(gitComponent, "create");
Assert.assertEquals("master:myGitScript.xyz", gitComponentCreateArtifact.getArtifactRef());
Assert.assertEquals("tosca.artifacts.Implementation.Bash", gitComponentCreateArtifact.getArtifactType());
assertNull(gitComponentCreateArtifact.getRepositoryCredential());
Assert.assertEquals("git_repo", gitComponentCreateArtifact.getRepositoryName());
Assert.assertEquals("git", gitComponentCreateArtifact.getArtifactRepository());
Assert.assertEquals("https://github.com/myId/myRepo.git", gitComponentCreateArtifact.getRepositoryURL());
RelationshipType httpRelationship = archiveRoot.getRelationshipTypes().get("my.http.relationship");
ImplementationArtifact httpRelationshipCreateArtifact = getImplementationArtifact(httpRelationship, "create");
Assert.assertEquals("https://otherCompany/script/short_notation.sh", httpRelationshipCreateArtifact.getArtifactRef());
Assert.assertEquals("tosca.artifacts.Implementation.Bash", httpRelationshipCreateArtifact.getArtifactType());
assertNull(httpRelationshipCreateArtifact.getRepositoryCredential());
assertNull(httpRelationshipCreateArtifact.getRepositoryName());
assertNull(httpRelationshipCreateArtifact.getArtifactRepository());
assertNull(httpRelationshipCreateArtifact.getRepositoryURL());
ImplementationArtifact httpRelationshipStartArtifact = getImplementationArtifact(httpRelationship, "start");
Assert.assertEquals("myScript.abc", httpRelationshipStartArtifact.getArtifactRef());
Assert.assertEquals("tosca.artifacts.Implementation.Bash", httpRelationshipStartArtifact.getArtifactType());
Assert.assertEquals(ImmutableMap.<String, Object>builder().put(NormativeCredentialConstant.USER_KEY, "good_user").put(NormativeCredentialConstant.TOKEN_KEY, "real_secured_password").put(NormativeCredentialConstant.TOKEN_TYPE, "password").build(), httpRelationshipStartArtifact.getRepositoryCredential());
Assert.assertEquals("script_repo", httpRelationshipStartArtifact.getRepositoryName());
assertNull(httpRelationshipStartArtifact.getArtifactRepository());
Assert.assertEquals("https://myCompany/script", httpRelationshipStartArtifact.getRepositoryURL());
}
Aggregations