Search in sources :

Example 1 with RelationshipType

use of org.alien4cloud.tosca.model.types.RelationshipType in project yorc-a4c-plugin by ystia.

the class ToscaExportersTest method testComponentSerialization.

@Test
public void testComponentSerialization() throws Exception {
    Mockito.reset(repositorySearchService);
    String rootDir = "src/test/resources/org/ystia/yorc/alien4cloud/plugin/tosca";
    Csar csar = new Csar("tosca-normative-types", "1.0.0-ALIEN20");
    Mockito.when(repositorySearchService.getArchive(csar.getName(), csar.getVersion())).thenReturn(csar);
    NodeType mockedResult = Mockito.mock(NodeType.class);
    Mockito.when(mockedResult.getArchiveName()).thenReturn("tosca-normative-types");
    Mockito.when(mockedResult.getArchiveVersion()).thenReturn("1.0.0-ALIEN20");
    DeploymentArtifact da = Mockito.mock(DeploymentArtifact.class);
    Mockito.when(da.getArtifactPath()).thenReturn("test");
    Mockito.when(da.getArtifactRef()).thenReturn("test");
    Mockito.when(da.getArtifactType()).thenReturn("file");
    Mockito.when(da.getArchiveName()).thenReturn("tosca-normative-types");
    Mockito.when(da.getArchiveVersion()).thenReturn("1.0.0-ALIEN20");
    Mockito.when(mockedResult.getArtifacts()).thenReturn(Collections.singletonMap("SoftwareComponentArtifact", da));
    Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(Set.class))).thenReturn(mockedResult);
    Mockito.when(mockedResult.getDerivedFrom()).thenReturn(Lists.newArrayList("tosca.nodes.Root"));
    Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(mockedResult);
    Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockedResult);
    Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(DataType.class), Mockito.eq(NormativeCredentialConstant.DATA_TYPE), Mockito.any(Set.class))).thenReturn(Mockito.mock(DataType.class));
    RelationshipType hostedOn = new RelationshipType();
    Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.HostedOn"), Mockito.any(Set.class))).thenReturn(hostedOn);
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(rootDir, "tosca_component_input.yaml"));
    System.out.println(parsingResult.getContext().getParsingErrors());
    assertNoBlocker(parsingResult);
    String resultYaml = toscaComponentExporter.getYaml(parsingResult.getResult());
    System.out.println(resultYaml);
    String expectedResult = FileUtils.readFileToString(Paths.get(rootDir, "tosca_component_output.yaml").toFile(), "UTF-8");
    // Make some whitespaces change here as IDEs have auto-format features that will overwrite them in the file
    expectedResult = expectedResult.replaceAll("verbose:\\n", "verbose: \n");
    expectedResult = expectedResult.replaceAll("default:\\n", "default: \n");
    Assert.assertEquals(expectedResult, resultYaml);
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) DataType(org.alien4cloud.tosca.model.types.DataType) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) Test(org.junit.Test) AbstractPluginTest(org.ystia.yorc.alien4cloud.plugin.AbstractPluginTest)

Example 2 with RelationshipType

use of org.alien4cloud.tosca.model.types.RelationshipType in project alien4cloud by alien4cloud.

the class RebuildRelationshipProcessor method processRelationshipOperation.

@Override
protected void processRelationshipOperation(Csar csar, Topology topology, RebuildRelationshipOperation operation, NodeTemplate nodeTemplate, RelationshipTemplate relationshipTemplate) {
    // rebuild a relationship template based on the current relationship type
    log.debug("Rebuilding the relationship [ {} ] in the node template [ {} ] of topology [ {} ] .", operation.getRelationshipName(), operation.getNodeName(), topology.getId());
    RelationshipType relType = ToscaContext.getOrFail(RelationshipType.class, relationshipTemplate.getType());
    Map<String, AbstractPropertyValue> properties = Maps.newHashMap();
    TemplateBuilder.fillProperties(properties, relType.getProperties(), relationshipTemplate.getProperties());
    relationshipTemplate.setProperties(properties);
    relationshipTemplate.setAttributes(relType.getAttributes());
}
Also used : RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 3 with RelationshipType

use of org.alien4cloud.tosca.model.types.RelationshipType in project alien4cloud by alien4cloud.

the class UnsetRelationshipPropertyAsInputProcessor method processRelationshipOperation.

@Override
protected void processRelationshipOperation(Csar csar, Topology topology, UnsetRelationshipPropertyAsInputOperation 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());
    AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(relationshipPropertyDefinition);
    relationshipTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue);
    log.debug("Remove association from property [ {} ] of relationship template [ {} ] of node [ {} ] to an input of the topology [ {} ].", operation.getPropertyName(), operation.getRelationshipName(), operation.getNodeName(), topology.getId());
}
Also used : RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 4 with RelationshipType

use of org.alien4cloud.tosca.model.types.RelationshipType in project alien4cloud by alien4cloud.

the class UnsetRelationshipPropertyAsSecretProcessor method processRelationshipOperation.

@Override
protected void processRelationshipOperation(Csar csar, Topology topology, UnsetRelationshipPropertyAsSecretOperation 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());
    AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(relationshipPropertyDefinition);
    relationshipTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue);
    log.debug("Remove secret from property [ {} ] of relationship template [ {} ] of node [ {} ] to an input of the topology [ {} ].", operation.getPropertyName(), operation.getRelationshipName(), operation.getNodeName(), topology.getId());
}
Also used : RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 5 with RelationshipType

use of org.alien4cloud.tosca.model.types.RelationshipType in project alien4cloud by alien4cloud.

the class SetSubstitutionTargetServiceRelationshipProcessor method process.

public void process(Csar csar, Topology topology, SubstitutionTarget substitutionTarget, String relationshipType, String relationshipVersion) {
    if (StringUtils.isBlank(relationshipType)) {
        substitutionTarget.setServiceRelationshipType(null);
        return;
    }
    // Check that the relationship type exists
    RelationshipType indexedRelationshipType = toscaTypeSearchService.find(RelationshipType.class, relationshipType, relationshipVersion);
    if (indexedRelationshipType == null) {
        throw new NotFoundException(RelationshipType.class.getName(), relationshipType + ":" + relationshipVersion, "Unable to find relationship type to create template in topology.");
    }
    topologyService.loadType(topology, indexedRelationshipType);
    substitutionTarget.setServiceRelationshipType(relationshipType);
}
Also used : RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) NotFoundException(alien4cloud.exception.NotFoundException)

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