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);
}
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());
}
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());
}
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());
}
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);
}
Aggregations