Search in sources :

Example 1 with GenericPolicy

use of org.alien4cloud.tosca.model.templates.GenericPolicy in project alien4cloud by alien4cloud.

the class PolicyDeserializer method deserializeAfterRead.

@Override
protected AbstractPolicy deserializeAfterRead(JsonParser jp, DeserializationContext ctxt, ObjectMapper mapper, ObjectNode root) throws JsonProcessingException {
    AbstractPolicy result = super.deserializeAfterRead(jp, ctxt, mapper, root);
    if (result != null)
        return result;
    // treat anything else as generic policy
    // all data is stored in the field data so extract that
    Map data = mapper.treeToValue(root, Map.class);
    if (data.containsKey("data"))
        data = (Map) data.get("data");
    return new GenericPolicy(data);
}
Also used : GenericPolicy(org.alien4cloud.tosca.model.templates.GenericPolicy) AbstractPolicy(org.alien4cloud.tosca.model.templates.AbstractPolicy) Map(java.util.Map)

Example 2 with GenericPolicy

use of org.alien4cloud.tosca.model.templates.GenericPolicy in project alien4cloud by alien4cloud.

the class GroupPolicyParser method buildPolicy.

private AbstractPolicy buildPolicy(Map<String, Object> nodeMap, Node node, ParsingContextExecution context) {
    String type = (String) nodeMap.get(TYPE);
    AbstractPolicy result = null;
    if (type != null) {
        switch(type) {
            case HaPolicy.HA_POLICY:
                result = new HaPolicy(nodeMap);
                break;
            case LocationPlacementPolicy.LOCATION_PLACEMENT_POLICY:
                Object locationO = nodeMap.get(LocationPlacementPolicy.LOCATION_ID_PROPERTY);
                if (locationO instanceof String) {
                    result = new LocationPlacementPolicy();
                } else {
                    context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.SYNTAX_ERROR, null, node.getStartMark(), "Location id should be a string.", node.getEndMark(), locationO.toString()));
                    return null;
                }
                break;
        }
    }
    if (result == null) {
        result = new GenericPolicy(nodeMap);
    }
    return result;
}
Also used : GenericPolicy(org.alien4cloud.tosca.model.templates.GenericPolicy) AbstractPolicy(org.alien4cloud.tosca.model.templates.AbstractPolicy) HaPolicy(org.alien4cloud.tosca.model.templates.HaPolicy) LocationPlacementPolicy(org.alien4cloud.tosca.model.templates.LocationPlacementPolicy)

Aggregations

AbstractPolicy (org.alien4cloud.tosca.model.templates.AbstractPolicy)2 GenericPolicy (org.alien4cloud.tosca.model.templates.GenericPolicy)2 Map (java.util.Map)1 HaPolicy (org.alien4cloud.tosca.model.templates.HaPolicy)1 LocationPlacementPolicy (org.alien4cloud.tosca.model.templates.LocationPlacementPolicy)1