Search in sources :

Example 1 with BoshModels

use of org.springframework.ide.vscode.bosh.models.BoshModels in project sts4 by spring-projects.

the class BoshCloudConfigSchema method createNetworkBlockSchema.

private YType createNetworkBlockSchema(BoshModels models) {
    AbstractType t_manual_nw = f.ybean("ManualNetwork");
    {
        YBeanType t_subnet = f.ybean("Subnet[Manual]");
        addProp(t_subnet, "range", t_ip_range).isRequired(true);
        addProp(t_subnet, "gateway", t_ip_address).isRequired(true);
        addProp(t_subnet, "dns", f.yseq(t_ip_address));
        addProp(t_subnet, "reserved", f.yseq(t_ip_address_or_range));
        addProp(t_subnet, "static", f.yseq(t_ip_address_or_range));
        addProp(t_subnet, "az", t_az_ref);
        addProp(t_subnet, "azs", f.yseq(t_az_ref));
        addProp(t_subnet, "cloud_properties", t_params);
        addProp(t_manual_nw, "subnets", f.yseq(t_subnet)).isRequired(true);
    }
    AbstractType t_vip_nw = f.ybean("VipNetwork");
    addProp(t_vip_nw, "cloud_properties", t_params);
    AbstractType t_dynamic_nw = f.ybean("DynamicNetwork");
    addProp(t_dynamic_nw, "dns", f.yseq(t_ip_address));
    addProp(t_dynamic_nw, "cloud_properties", t_params);
    {
        YBeanType t_subnet = f.ybean("Subnet[Dynamic]");
        addProp(t_subnet, "dns", f.yseq(t_ip_address));
        addProp(t_subnet, "az", t_az_ref);
        addProp(t_subnet, "azs", f.yseq(t_az_ref));
        addProp(t_subnet, "cloud_properties", t_params);
        addProp(t_dynamic_nw, "subnets", f.yseq(t_subnet));
    }
    t_dynamic_nw.require(Constraints.mutuallyExclusive("dns", "subnets"));
    t_dynamic_nw.require(Constraints.mutuallyExclusive("cloud_properties", "subnets"));
    AbstractType t_network = f.contextAware("Network", dc -> {
        String type = models.getTypeTag(dc);
        if (StringUtil.hasText(type)) {
            switch(type) {
                case "manual":
                    return t_manual_nw;
                case "dynamic":
                    return t_dynamic_nw;
                case "vip":
                    return t_vip_nw;
                default:
            }
        }
        return null;
    }).treatAsBean();
    // Add shared properties to the 'super' type.
    addProp(t_network, "name", t_network_def).isPrimary(true);
    addProp(t_network, "type", f.yenum("NetworkType", "manual", "dynamic", "vip")).isRequired(true);
    // Add shared properties to all 'sub' types.
    for (AbstractType subtype : ImmutableList.of(t_dynamic_nw, t_manual_nw, t_vip_nw)) {
        for (YTypedProperty sharedProp : t_network.getProperties()) {
            subtype.addProperty(sharedProp);
        }
    }
    return t_network;
}
Also used : AbstractType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType) YTypedProperty(org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty) CollectorUtil(org.springframework.ide.vscode.commons.util.CollectorUtil) YamlSchemaProblems(org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaProblems) Collection(java.util.Collection) YamlSchema(org.springframework.ide.vscode.commons.yaml.schema.YamlSchema) YTypeUtil(org.springframework.ide.vscode.commons.yaml.schema.YTypeUtil) PartialCollection(org.springframework.ide.vscode.commons.util.PartialCollection) YType(org.springframework.ide.vscode.commons.yaml.schema.YType) ASTTypeCache(org.springframework.ide.vscode.commons.yaml.reconcile.ASTTypeCache) YBeanType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanType) YAtomicType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YAtomicType) Constraints(org.springframework.ide.vscode.commons.yaml.schema.constraints.Constraints) StringUtil(org.springframework.ide.vscode.commons.util.StringUtil) Pair(org.apache.commons.lang3.tuple.Pair) YTypeFactory(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory) ImmutableList(com.google.common.collect.ImmutableList) ValueParsers(org.springframework.ide.vscode.commons.util.ValueParsers) BoshModels(org.springframework.ide.vscode.bosh.models.BoshModels) Lazy(org.springframework.ide.vscode.commons.util.Lazy) AbstractType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType) YBeanType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanType) YTypedProperty(org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 Collection (java.util.Collection)1 Pair (org.apache.commons.lang3.tuple.Pair)1 BoshModels (org.springframework.ide.vscode.bosh.models.BoshModels)1 CollectorUtil (org.springframework.ide.vscode.commons.util.CollectorUtil)1 Lazy (org.springframework.ide.vscode.commons.util.Lazy)1 PartialCollection (org.springframework.ide.vscode.commons.util.PartialCollection)1 StringUtil (org.springframework.ide.vscode.commons.util.StringUtil)1 ValueParsers (org.springframework.ide.vscode.commons.util.ValueParsers)1 ASTTypeCache (org.springframework.ide.vscode.commons.yaml.reconcile.ASTTypeCache)1 YamlSchemaProblems (org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaProblems)1 YType (org.springframework.ide.vscode.commons.yaml.schema.YType)1 YTypeFactory (org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory)1 AbstractType (org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType)1 YAtomicType (org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YAtomicType)1 YBeanType (org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanType)1 YTypeUtil (org.springframework.ide.vscode.commons.yaml.schema.YTypeUtil)1 YTypedProperty (org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty)1 YamlSchema (org.springframework.ide.vscode.commons.yaml.schema.YamlSchema)1 Constraints (org.springframework.ide.vscode.commons.yaml.schema.constraints.Constraints)1