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