use of org.alien4cloud.tosca.model.templates.NodeTemplate 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.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class ComplexPropertyMergeTest method mergeComplexProperty.
@Test
public void mergeComplexProperty() {
int i = 1;
while (true) {
NodeTemplate source = topology.getNodeTemplates().get("Source" + i);
if (source == null) {
break;
}
NodeTemplate target = topology.getNodeTemplates().get("Target" + i);
NodeTemplate expected = topology.getNodeTemplates().get("Merged" + i);
Set<String> untouchable = Sets.newHashSet();
Map<String, AbstractPropertyValue> actual = PropertyUtil.merge(source.getProperties(), target.getProperties(), true, untouchable);
Assert.assertEquals("Merge result of Source" + i + " and Target" + i, expected.getProperties(), actual);
i++;
}
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class ServiceResourceServiceTest method testGetByNodeTypes.
@Test
public void testGetByNodeTypes() {
ServiceResource serviceResource = new ServiceResource();
serviceResource.setId("service1");
serviceResource.setNodeInstance(new NodeInstance());
serviceResource.getNodeInstance().setTypeVersion("1.0.0-SNAPSHOT");
serviceResource.getNodeInstance().setNodeTemplate(new NodeTemplate());
serviceResource.getNodeInstance().getNodeTemplate().setType("org.alien4cloud.nodes.MyType");
alienDao.save(serviceResource);
ServiceResource[] services = serviceResourceService.getByNodeTypes("org.alien4cloud.nodes.MyType", "1.0.0-SNAPSHOT");
Assert.assertNotNull(services);
Assert.assertEquals(1, services.length);
services = serviceResourceService.getByNodeTypes("org.alien4cloud.nodes.UnusedType", "1.0.0-SNAPSHOT");
Assert.assertNotNull(services);
Assert.assertEquals(0, services.length);
services = serviceResourceService.getByNodeTypes("org.alien4cloud.nodes.MyType", "1.0.0");
Assert.assertNotNull(services);
Assert.assertEquals(0, services.length);
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class MockPaaSProvider method switchMaintenanceMode.
@Override
public void switchMaintenanceMode(PaaSDeploymentContext deploymentContext, boolean maintenanceModeOn) {
String deploymentPaaSId = deploymentContext.getDeploymentPaaSId();
MockRuntimeDeploymentInfo runtimeDeploymentInfo = runtimeDeploymentInfos.get(deploymentContext.getDeploymentPaaSId());
Topology topology = runtimeDeploymentInfo.getDeploymentContext().getDeploymentTopology();
Map<String, Map<String, InstanceInformation>> nodes = runtimeDeploymentInfo.getInstanceInformations();
if (nodes == null || nodes.isEmpty()) {
return;
}
for (Entry<String, Map<String, InstanceInformation>> nodeEntry : nodes.entrySet()) {
String nodeTemplateId = nodeEntry.getKey();
Map<String, InstanceInformation> nodeInstances = nodeEntry.getValue();
if (nodeInstances != null && !nodeInstances.isEmpty()) {
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeTemplateId);
NodeType nodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), topology.getDependencies());
if (ToscaTypeUtils.isOfType(nodeType, NormativeComputeConstants.COMPUTE_TYPE)) {
for (Entry<String, InstanceInformation> nodeInstanceEntry : nodeInstances.entrySet()) {
String instanceId = nodeInstanceEntry.getKey();
InstanceInformation instanceInformation = nodeInstanceEntry.getValue();
if (instanceInformation != null) {
switchInstanceMaintenanceMode(deploymentPaaSId, nodeTemplateId, instanceId, instanceInformation, maintenanceModeOn);
}
}
}
}
}
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class AntiAffinityModifier method apply.
private void apply(PolicyTemplate policy, Topology topology, FlowExecutionContext context) {
AbstractPropertyValue value = policy.getProperties().get("availability_zones");
List<NodeTemplate> targets = getTargets(policy, topology, context);
if (targets == null) {
// Some targets are not instances of org.alien4cloud.nodes.mock.aws.Compute
return;
}
if (safe(policy.getTargets()).size() < 2) {
context.log().error("Anti-affinity policy {} is not correctly configured, at least 2 targets are required.", policy.getName());
return;
}
if (!(value instanceof ListPropertyValue) || ((ListPropertyValue) value).getValue().size() < 2) {
context.log().error("Anti-affinity policy {} is not correctly configured, zones property is required and must contains at least 2 values.", policy.getName());
return;
}
ListPropertyValue propertyValue = (ListPropertyValue) value;
for (int i = 0; i < targets.size(); i++) {
NodeTemplate nodeTemplate = targets.get(i);
String nodeZone = (String) propertyValue.getValue().get(i % propertyValue.getValue().size());
if (AWS_MOCK_COMPUTE_TYPE.equals(nodeTemplate.getType())) {
context.log().info("Anti-affinity policy {} inject zone property {} to node {}", policy.getName(), nodeZone, nodeTemplate.getName());
nodeTemplate.getProperties().put("zone", new ScalarPropertyValue(nodeZone));
}
}
}
Aggregations