use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact 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.definitions.DeploymentArtifact in project yorc-a4c-plugin by ystia.
the class DeployTask method copyArtifacts.
/**
* Copy artifacts to archive
* @param node
* @param zout
*/
private void copyArtifacts(PaaSNodeTemplate node, ZipOutputStream zout) {
String name = node.getId();
// Check if this component has artifacts
Map<String, DeploymentArtifact> map = node.getTemplate().getArtifacts();
if (map == null) {
log.debug("Component with no artifact: " + name);
return;
}
// Process each artifact
for (Map.Entry<String, DeploymentArtifact> da : map.entrySet()) {
String aname = name + "/" + da.getKey();
DeploymentArtifact artifact = da.getValue();
String artRepo = artifact.getArtifactRepository();
if (artRepo == null) {
continue;
}
ShowTopology.printArtifact(artifact);
if (artRepo.equals(ArtifactRepositoryConstants.ALIEN_TOPOLOGY_REPOSITORY)) {
// Copy artifact from topology repository to the root of archive.
String from = artifact.getArtifactPath();
log.debug("Copying local artifact: " + aname + " path=" + from);
Path artifactPath = Paths.get(from);
try {
String filename = artifact.getArtifactRef();
createZipEntries(filename, zout);
copy(artifactPath.toFile(), zout);
} catch (Exception e) {
log.error("Could not copy local artifact " + aname, e);
}
} else {
// Copy remote artifact
String from = artifact.getArtifactPath();
log.debug("Copying remote artifact: " + aname + " path=" + from);
Path artifactPath = Paths.get(from);
try {
String filename = artifact.getArtifactRef();
createZipEntries(filename, zout);
copy(artifactPath.toFile(), zout);
} catch (Exception e) {
log.error("Could not copy remote artifact " + aname, e);
}
// Workaround for a bug in a4c: artifact not added in topology.yml
// TODO Remove this when a4c bug SUPALIEN-926 is fixed.
addRemoteArtifactInTopology(name, da.getKey(), artifact);
}
}
}
use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact in project alien4cloud by alien4cloud.
the class ToscaSerializerTest method simpleTest.
@Ignore
@Test
public void simpleTest() throws IOException, URISyntaxException {
Topology topology = new Topology();
topology.setDependencies(new HashSet<CSARDependency>());
topology.getDependencies().add(new CSARDependency("name1", "1.0"));
topology.getDependencies().add(new CSARDependency("name2", "2.0"));
topology.setInputs(new HashMap<String, PropertyDefinition>());
PropertyDefinition pd1 = new PropertyDefinition();
pd1.setType("string");
pd1.setConstraints(getConstraintList());
pd1.setDescription("A description");
topology.getInputs().put("input1", pd1);
PropertyDefinition pd2 = new PropertyDefinition();
pd2.setType("integer");
pd2.setRequired(false);
pd2.setDefault(new ScalarPropertyValue("10"));
topology.getInputs().put("input2", pd2);
PropertyDefinition pd3 = new PropertyDefinition();
pd3.setType("map");
pd3.setRequired(false);
PropertyDefinition entrySchema = new PropertyDefinition();
entrySchema.setType("integer");
pd3.setEntrySchema(entrySchema);
topology.getInputs().put("input3", pd3);
topology.setNodeTemplates(new HashMap<String, NodeTemplate>());
topology.getNodeTemplates().put("node1", new NodeTemplate());
topology.getNodeTemplates().get("node1").setType("the.node.Type");
topology.getNodeTemplates().get("node1").setProperties(buildSamplePropertyValueMap());
topology.getNodeTemplates().get("node1").setRelationships(new HashMap<String, RelationshipTemplate>());
topology.getNodeTemplates().get("node1").getRelationships().put("hostedOn", new RelationshipTemplate());
topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setTarget("compute2");
topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setRequirementType("capabilities.Capa");
topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setRequirementName("host");
topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setType("relationship.Rel");
topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setProperties(buildSamplePropertyValueMap());
topology.getNodeTemplates().get("node1").setCapabilities(new HashMap<String, Capability>());
Capability capability = new Capability();
capability.setProperties(buildSamplePropertyValueMap());
topology.getNodeTemplates().get("node1").getCapabilities().put("capa1", capability);
// this capability should not appear
topology.getNodeTemplates().get("node1").getCapabilities().put("capa2", new Capability());
topology.getNodeTemplates().get("node1").setArtifacts(new HashMap<String, DeploymentArtifact>());
DeploymentArtifact da = new DeploymentArtifact();
da.setArtifactName("artifact.war");
da.setArtifactRef("010203904872876723");
da.setArtifactType("artifacttypes.Artifact");
topology.getNodeTemplates().get("node1").getArtifacts().put("artifact1", da);
topology.setOutputProperties(new HashMap<String, Set<String>>());
topology.getOutputProperties().put("node1", Sets.newHashSet("prop1", "prop2"));
topology.setOutputAttributes(new HashMap<String, Set<String>>());
topology.getOutputAttributes().put("node1", Sets.newHashSet("att1", "att2"));
Map<String, Object> velocityCtx = new HashMap<String, Object>();
velocityCtx.put("topology", topology);
velocityCtx.put("template_name", "template-id");
velocityCtx.put("template_version", "1.0.0-SNAPSHOT");
velocityCtx.put("template_author", "Foo Bar");
velocityCtx.put("application_description", "Here is a \nmultiline description");
StringWriter writer = new StringWriter();
VelocityUtil.generate("org/alien4cloud/tosca/exporter/topology-alien_dsl_1_4_0.yml.vm", writer, velocityCtx);
System.out.println(writer.toString());
}
use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact in project alien4cloud by alien4cloud.
the class TemplateBuilder method fillDeploymentArtifactsMap.
private static void fillDeploymentArtifactsMap(Map<String, DeploymentArtifact> deploymentArtifacts, Map<String, DeploymentArtifact> fromTypeArtifacts, Map<String, DeploymentArtifact> mapToMerge) {
if (MapUtils.isEmpty(fromTypeArtifacts)) {
fromTypeArtifacts = Maps.newLinkedHashMap();
}
// We need to clone objects
deploymentArtifacts.putAll(fromTypeArtifacts);
for (Map.Entry<String, DeploymentArtifact> entryArtifact : safe(mapToMerge).entrySet()) {
deploymentArtifacts.put(entryArtifact.getKey(), entryArtifact.getValue());
DeploymentArtifact artifactFromType = deploymentArtifacts.get(entryArtifact.getKey());
if (artifactFromType != null && StringUtils.isBlank(entryArtifact.getValue().getArtifactType())) {
entryArtifact.getValue().setArtifactType(artifactFromType.getArtifactType());
}
}
}
use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact in project alien4cloud by alien4cloud.
the class RenameInputArtifactProcessor method process.
@Override
public void process(Csar csar, Topology topology, RenameInputArtifactOperation operation) {
if (operation.getNewInputName() == null || operation.getNewInputName().isEmpty() || !operation.getNewInputName().matches("\\w+")) {
throw new InvalidNameException("newInputName", operation.getNewInputName(), "\\w+");
}
if (safe(topology.getInputArtifacts()).containsKey(operation.getNewInputName())) {
throw new AlreadyExistException("Input artifact with name <" + operation.getNewInputName() + "> already exists.");
}
if (!safe(topology.getInputArtifacts()).containsKey(operation.getInputName())) {
throw new NotFoundException("Input artifact with name <" + operation.getInputName() + "> does not exists.");
}
DeploymentArtifact inputArtifact = topology.getInputArtifacts().remove(operation.getInputName());
topology.getInputArtifacts().put(operation.getNewInputName(), inputArtifact);
// change the value of concerned node template artifacts
for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
for (DeploymentArtifact dArtifact : safe(nodeTemplate.getArtifacts()).values()) {
InputArtifactUtil.updateInputArtifactIdIfNeeded(dArtifact, operation.getInputName(), operation.getNewInputName());
}
}
}
Aggregations