Search in sources :

Example 6 with AbstractPropertyValue

use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue 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 7 with AbstractPropertyValue

use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.

the class FunctionEvaluatorTest method nodeGetSecretProp.

@Test
public void nodeGetSecretProp() {
    FunctionEvaluatorContext context = getEvaluationContext();
    NodeTemplate template = context.getTopology().getNodeTemplates().get("my_node");
    AbstractPropertyValue resolved = FunctionEvaluator.tryResolveValue(context, template, template.getProperties(), template.getProperties().get("get_secret_prop"));
    Assert.assertNotNull(resolved);
    Assert.assertEquals(FunctionPropertyValue.class, resolved.getClass());
    Assert.assertEquals("get_secret", ((FunctionPropertyValue) resolved).getFunction());
    Assert.assertEquals("my/path", ((FunctionPropertyValue) resolved).getParameters().get(0));
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Test(org.junit.Test)

Example 8 with AbstractPropertyValue

use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.

the class ToscaSerializerUtilsTest method testMapIsNotEmptyAndContainsNotnullValues.

@Test
public void testMapIsNotEmptyAndContainsNotnullValues() {
    Assert.assertFalse(utils.mapIsNotEmptyAndContainsNotnullValues(null));
    Assert.assertFalse(utils.mapIsNotEmptyAndContainsNotnullValues(Maps.newHashMap()));
    Map<String, Object> map = Maps.newHashMap();
    map.put("key1", null);
    Assert.assertFalse(utils.mapIsNotEmptyAndContainsNotnullValues(map));
    map.put("key2", "something");
    Assert.assertTrue(utils.mapIsNotEmptyAndContainsNotnullValues(map));
    // inner collection
    Map<String, Set<String>> mapOfSet = Maps.newHashMap();
    Set<String> set = Sets.newHashSet();
    mapOfSet.put("key1", set);
    // the set is empty
    Assert.assertFalse(utils.mapIsNotEmptyAndContainsNotnullValues(mapOfSet));
    Set<String> filledSet = Sets.newHashSet("something");
    mapOfSet.put("key2", filledSet);
    // the second set contains something
    Assert.assertTrue(utils.mapIsNotEmptyAndContainsNotnullValues(mapOfSet));
    // inner map
    Map<String, Map<String, Set<String>>> mapOfmap = Maps.newHashMap();
    Map<String, Set<String>> innerMap = Maps.newHashMap();
    mapOfmap.put("key1", innerMap);
    // the inner map is empty
    Assert.assertFalse(utils.mapIsNotEmptyAndContainsNotnullValues(mapOfmap));
    Map<String, Set<String>> innerMap2 = Maps.newHashMap();
    Set<String> emptySet = Sets.newHashSet();
    innerMap2.put("key21", emptySet);
    mapOfmap.put("key2", innerMap2);
    // the inner set is empty
    Assert.assertFalse(utils.mapIsNotEmptyAndContainsNotnullValues(mapOfmap));
    filledSet = Sets.newHashSet("something");
    innerMap2.put("key22", filledSet);
    Assert.assertTrue(utils.mapIsNotEmptyAndContainsNotnullValues(mapOfmap));
    // ScalarPropertyValue
    ScalarPropertyValue spv = new ScalarPropertyValue();
    Map<String, AbstractPropertyValue> apvMap = new HashMap<String, AbstractPropertyValue>();
    apvMap.put("key1", spv);
    Assert.assertFalse(utils.mapIsNotEmptyAndContainsNotnullValues(apvMap));
    spv.setValue("value");
    Assert.assertTrue(utils.mapIsNotEmptyAndContainsNotnullValues(apvMap));
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) HashMap(java.util.HashMap) Map(java.util.Map) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Test(org.junit.Test)

Example 9 with AbstractPropertyValue

use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.

the class ToscaSerializerTest method buildSamplePropertyValueMap.

private Map<String, AbstractPropertyValue> buildSamplePropertyValueMap() {
    Map<String, AbstractPropertyValue> result = new HashMap<String, AbstractPropertyValue>();
    result.put("prop1", new ScalarPropertyValue("value1"));
    FunctionPropertyValue fpv1 = new FunctionPropertyValue();
    fpv1.setFunction("get_property");
    fpv1.setParameters(Lists.newArrayList("p1", "p2"));
    result.put("prop2", fpv1);
    FunctionPropertyValue fpv2 = new FunctionPropertyValue();
    fpv2.setFunction("get_input");
    fpv2.setParameters(Lists.newArrayList("p1"));
    result.put("prop3", fpv2);
    result.put("prop4", null);
    result.put("prop5", new ScalarPropertyValue("a value containing a ["));
    result.put("prop6", new ScalarPropertyValue("a value containing a ]"));
    result.put("prop7", new ScalarPropertyValue("a value containing a {"));
    result.put("prop8", new ScalarPropertyValue("a value containing a }"));
    result.put("prop9", new ScalarPropertyValue("a value containing a :"));
    result.put("prop9", new ScalarPropertyValue("a value containing a \""));
    result.put("prop9", new ScalarPropertyValue("a value containing a : and a \""));
    result.put("prop10", new ScalarPropertyValue(" a value starting with a space"));
    result.put("prop11", new ScalarPropertyValue("a value ending with a space "));
    return result;
}
Also used : HashMap(java.util.HashMap) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 10 with AbstractPropertyValue

use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue 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));
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ListPropertyValue(org.alien4cloud.tosca.model.definitions.ListPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Aggregations

AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)57 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)23 Map (java.util.Map)18 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)17 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)17 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)14 Capability (org.alien4cloud.tosca.model.templates.Capability)14 NotFoundException (alien4cloud.exception.NotFoundException)10 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)9 Test (org.junit.Test)8 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)7 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)7 NodeType (org.alien4cloud.tosca.model.types.NodeType)7 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)6 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)5 List (java.util.List)5 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)5 ConcatPropertyValue (org.alien4cloud.tosca.model.definitions.ConcatPropertyValue)4 ListPropertyValue (org.alien4cloud.tosca.model.definitions.ListPropertyValue)4 HashMap (java.util.HashMap)3