Search in sources :

Example 31 with RelationshipType

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());
    }
}
Also used : ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) PropertyValueException(org.alien4cloud.tosca.editor.exception.PropertyValueException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 32 with RelationshipType

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());
}
Also used : RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 33 with RelationshipType

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;
            }
        }
    }
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult) Then(cucumber.api.java.en.Then)

Example 34 with RelationshipType

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);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Tag(alien4cloud.model.common.Tag)

Example 35 with RelationshipType

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());
}
Also used : ImplementationArtifact(org.alien4cloud.tosca.model.definitions.ImplementationArtifact) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Test(org.junit.Test)

Aggregations

RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)41 NodeType (org.alien4cloud.tosca.model.types.NodeType)22 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)15 Set (java.util.Set)14 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)14 Test (org.junit.Test)14 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)9 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)9 Csar (org.alien4cloud.tosca.model.Csar)8 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)8 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)5 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)5 Interface (org.alien4cloud.tosca.model.definitions.Interface)5 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)4 NotFoundException (alien4cloud.exception.NotFoundException)3 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)3 PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)3 Capability (org.alien4cloud.tosca.model.templates.Capability)3 DataType (org.alien4cloud.tosca.model.types.DataType)3 ParsingError (alien4cloud.tosca.parser.ParsingError)2