use of org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanType 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;
}
use of org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanType in project sts4 by spring-projects.
the class BoshDeploymentManifestSchema method createV1Schema.
private YBeanType createV1Schema(AbstractType v2Schema) {
YBeanType v1Schema = f.ybean("DeploymentManifestV1");
Map<String, YTypedProperty> v2properties = v2Schema.getPropertiesMap();
ImmutableSet<String> v1Props = ImmutableSet.<String>builder().addAll(DEPRECATED_V1_PROPS).addAll(SHARED_V1_V2_PROPS).build();
for (String name : v1Props) {
YTypedProperty prop = v2properties.get(name);
Assert.isNotNull(prop);
v1Schema.addProperty(prop);
}
return v1Schema;
}
use of org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanType in project sts4 by spring-projects.
the class BoshDeploymentManifestSchema method createV2Schema.
private YBeanType createV2Schema() {
YBeanType v2Schema = f.ybean("BoshDeploymentManifest");
addProp(v2Schema, "name", t_ne_string).isPrimary(true);
addProp(v2Schema, "director_uuid", t_uuid).isDeprecated("bosh v2 CLI no longer checks or requires director_uuid in the deployment manifest. " + "To achieve similar safety make sure to give unique deployment names across environments.");
t_instance_group_name_def = f.yatomic("InstanceGroupName").parseWith(ValueParsers.NE_STRING);
t_stemcell_alias_def = f.yatomic("StemcellAlias").parseWith(ValueParsers.NE_STRING);
t_stemcell_alias_ref = f.yenumFromDynamicValues("StemcellAlias", (dc) -> PartialCollection.compute(() -> astTypes.getDefinedNames(dc, t_stemcell_alias_def)));
t_release_name_def = f.yenumFromDynamicValues("ReleaseName", (dc) -> {
PartialCollection<String> releaseNames = PartialCollection.compute(() -> releasesProvider.getModel(dc).getReleaseNames());
return StringUtil.hasText(getCurrentEntityProperty(dc, "url")) ? releaseNames.addUncertainty() : releaseNames;
});
t_release_name_ref = f.yenumFromDynamicValues("ReleaseName", (dc) -> PartialCollection.compute(() -> astTypes.getDefinedNames(dc, t_release_name_def)));
t_var_name_def = f.yatomic("VariableName").parseWith(ValueParsers.NE_STRING);
// TODO: some kind of checking?
YAtomicType t_ip_address = f.yatomic("IPAddress");
t_ip_address.parseWith(ValueParsers.NE_STRING);
YAtomicType t_url = f.yatomic("URL");
t_url.parseWith(BoshValueParsers.url("http", "https", "file"));
YAtomicType t_network_name = f.yenumFromDynamicValues("NetworkName", (dc) -> PartialCollection.compute(() -> cloudConfigProvider.getModel(dc).getNetworkNames()));
YAtomicType t_disk_type = f.yenumFromDynamicValues("DiskType", (dc) -> PartialCollection.compute(() -> cloudConfigProvider.getModel(dc).getDiskTypes()));
YAtomicType t_vm_extension = f.yenumFromDynamicValues("VMExtension", (dc) -> PartialCollection.compute(() -> cloudConfigProvider.getModel(dc).getVMExtensions()));
YAtomicType t_vm_type = f.yenumFromDynamicValues("VMType", (dc) -> PartialCollection.compute(() -> cloudConfigProvider.getModel(dc).getVMTypes()));
YAtomicType t_az = f.yenumFromDynamicValues("AvailabilityZone", (dc) -> PartialCollection.compute(() -> cloudConfigProvider.getModel(dc).getAvailabilityZones()));
YBeanType t_network = f.ybean("Network");
addProp(t_network, "name", t_network_name).isRequired(true);
addProp(t_network, "static_ips", f.yseq(t_ip_address));
// TODO: Can we determine the set of valid values? How?
addProp(t_network, "default", f.yseq(t_ne_string));
YBeanType t_instance_group_env = f.ybean("InstanceGroupEnv");
addProp(t_instance_group_env, "bosh", t_params);
addProp(t_instance_group_env, "password", t_ne_string);
YType t_release_version = f.yenumFromDynamicValues("ReleaseVersion", // message formatter:
dc -> (s, values) -> {
String name = getCurrentEntityProperty(dc, "name");
if (StringUtil.hasText(name)) {
return "'" + s + "' is an unknown 'ReleaseVersion[name=" + name + "]'. Valid values are: " + values;
} else {
return "'" + s + "' is an unknown 'ReleaseVersion'. Valid values are: " + values;
}
}, // value provider:
dc -> {
PartialCollection<ReleaseData> releases = PartialCollection.compute(() -> releasesProvider.getModel(dc).getReleases());
if (StringUtil.hasText(getCurrentEntityProperty(dc, "url"))) {
releases = releases.addUncertainty();
} else {
String name = getCurrentEntityProperty(dc, "name");
if (StringUtil.hasText(name)) {
releases = releases.map(r -> name.equals(r.getName()) ? r : null);
}
}
return releases.map(r -> r.getVersion()).add("latest");
});
YBeanType t_release = f.ybean("Release");
addProp(t_release, "name", t_release_name_def).isPrimary(true);
addProp(t_release, "version", t_release_version).isRequired(true);
addProp(t_release, "url", t_url);
addProp(t_release, "sha1", t_ne_string);
t_release.require(BoshConstraints.SHA1_REQUIRED_FOR_HTTP_URL);
addProp(v2Schema, "releases", f.yseq(t_release)).isRequired(true);
YBeanType t_stemcell = f.ybean("Stemcell");
YType t_stemcell_name_ref = f.yenumFromDynamicValues("StemcellName", (dc) -> PartialCollection.compute(() -> stemcellsProvider.getModel(dc).getStemcellNames()));
YType t_stemcell_os_ref = f.yenumFromDynamicValues("StemcellOs", (dc) -> PartialCollection.compute(() -> stemcellsProvider.getModel(dc).getStemcellOss()));
YType t_stemcell_version_ref = f.yenumFromDynamicValues("StemcellVersion", (dc) -> (parseString, validValues) -> {
try {
Predicate<StemcellData> filter = getCurrentStemcell(dc).createVersionFilter();
if (filter != StemcellModel.ALLWAYS_TRUE_FILTER) {
return "'" + parseString + "' is an unknown 'StemcellVersion[" + filter + "]'. Valid values are: " + validValues;
}
} catch (Exception e) {
// ignore (parse error most likely)
}
return "'" + parseString + "' is an unknown 'StemcellVersion'. Valid values are: " + validValues;
}, (dc) -> {
Predicate<StemcellData> filter = getCurrentStemcell(dc).createVersionFilter();
return PartialCollection.compute(() -> stemcellsProvider.getModel(dc).getStemcells()).map(sc -> filter.test(sc) ? sc.getVersion() : null).add("latest");
});
addProp(t_stemcell, "alias", t_stemcell_alias_def).isPrimary(true);
addProp(t_stemcell, "version", t_stemcell_version_ref).isRequired(true);
addProp(t_stemcell, "name", t_stemcell_name_ref);
addProp(t_stemcell, "os", t_stemcell_os_ref);
t_stemcell.requireOneOf("name", "os");
addProp(v2Schema, "stemcells", f.yseq(t_stemcell)).isRequired(true);
YBeanType t_update = f.ybean("Update");
addProp(t_update, "canaries", t_strictly_pos_integer).isRequired(true);
addProp(t_update, "max_in_flight", t_pos_integer).isRequired(true);
addProp(t_update, "canary_watch_time", t_integer_or_range).isRequired(true);
addProp(t_update, "update_watch_time", t_integer_or_range).isRequired(true);
addProp(t_update, "serial", t_boolean);
addProp(v2Schema, "update", t_update).isRequired(true);
YBeanType t_job = f.ybean("Job");
addProp(t_job, "name", t_ne_string).isRequired(true);
addProp(t_job, "release", t_release_name_ref).isRequired(true);
addProp(t_job, "consumes", t_params);
addProp(t_job, "provides", t_params);
addProp(t_job, "properties", t_params);
YBeanType t_instance_group = f.ybean("InstanceGroup");
addProp(t_instance_group, "name", t_instance_group_name_def).isPrimary(true);
addProp(t_instance_group, "azs", f.yseq(t_az)).isRequired(true);
// Strictly positive? Or zero is okay?
addProp(t_instance_group, "instances", t_pos_integer).isRequired(true);
addProp(t_instance_group, "jobs", f.yseq(t_job)).isRequired(true);
addProp(t_instance_group, "vm_type", t_vm_type).isRequired(true);
addProp(t_instance_group, "vm_extensions", f.yseq(t_vm_extension));
addProp(t_instance_group, "stemcell", t_stemcell_alias_ref).isRequired(true);
addProp(t_instance_group, "persistent_disk_type", t_disk_type);
addProp(t_instance_group, "networks", f.yseq(t_network)).isRequired(true);
YType t_update_override = f.ybean("UpdateOverrides", t_update.getProperties().stream().map((YTypedProperty prop) -> f.yprop(prop).isRequired(false)).toArray(sz -> new YTypedProperty[sz]));
addProp(t_instance_group, "update", t_update_override);
// TODO: https://www.pivotaltracker.com/story/show/148712595
YType t_migration = t_params;
addProp(t_instance_group, "migrated_from", f.yseq(t_migration));
addProp(t_instance_group, "lifecycle", f.yenum("WorkloadType", "service", "errand"));
addProp(t_instance_group, "properties", t_params).isDeprecated("Deprecated in favor of job level properties and links");
addProp(t_instance_group, "env", t_instance_group_env);
addProp(v2Schema, "instance_groups", f.yseq(t_instance_group)).isRequired(true);
addProp(v2Schema, "properties", t_params).isDeprecated("Deprecated in favor of job level properties and links");
YBeanType t_variable = f.ybean("Variable");
addProp(t_variable, "name", t_var_name_def).isPrimary(true);
YType t_variable_type = f.yenum("VariableType", "certificate", "password", "rsa", "ssh").parseWith(// Override the parser -> no errors / warnings... in theory there could be other valid values.
ValueParsers.NE_STRING);
addProp(t_variable, "type", t_variable_type).isRequired(true);
addProp(t_variable, "options", t_params);
addProp(v2Schema, "variables", f.yseq(t_variable));
addProp(v2Schema, "tags", t_params);
for (String v1Prop : DEPRECATED_V1_PROPS) {
addProp(v2Schema, v1Prop, t_any).isDeprecated("Deprecated: '" + v1Prop + "' is a V1 schema property. Consider migrating your deployment manifest to V2");
}
for (YType defType : getDefinitionTypes()) {
v2Schema.require(Constraints.uniqueDefinition(this.astTypes, defType, YamlSchemaProblems.problemType("BOSH_DUPLICATE_" + defType)));
}
return v2Schema;
}
Aggregations