diff --git a/headless-services/bosh-language-server/src/main/java/org/springframework/ide/vscode/bosh/BoshCloudConfigSchema.java b/headless-services/bosh-language-server/src/main/java/org/springframework/ide/vscode/bosh/BoshCloudConfigSchema.java index 541487158..13f882eaf 100644 --- a/headless-services/bosh-language-server/src/main/java/org/springframework/ide/vscode/bosh/BoshCloudConfigSchema.java +++ b/headless-services/bosh-language-server/src/main/java/org/springframework/ide/vscode/bosh/BoshCloudConfigSchema.java @@ -41,7 +41,9 @@ public class BoshCloudConfigSchema extends SchemaSupport implements YamlSchema { private final YType t_vm_type_ref; private final YType t_vm_type_def; private final YType t_network_ref; - private AbstractType t_network_def; + private final YType t_network_def; + private final YType t_disk_type_def; + private final YType t_disk_type_ref; private Collection definitionTypes; private final Lazy>> defAndRefTypes = new Lazy<>(); private AbstractType t_any; @@ -80,6 +82,11 @@ public class BoshCloudConfigSchema extends SchemaSupport implements YamlSchema { t_ip_range = t_ne_string; //TODO? Syntax for ip ranges like 10.10.0.0/22 ? t_ip_address_or_range = t_ne_string; //TODO? + t_disk_type_def = f.yatomic("DiskTypeName").parseWith(ValueParsers.NE_STRING); + t_disk_type_ref = f.yenumFromDynamicValues("DiskTypeName",(dc) -> PartialCollection.compute(() -> + models.astTypes.getDefinedNames(dc, t_disk_type_def) + )); + YType t_network = createNetworkBlockSchema(models); YBeanType t_az = f.ybean("AZ"); @@ -97,12 +104,17 @@ public class BoshCloudConfigSchema extends SchemaSupport implements YamlSchema { addProp(t_vm_type, "name", t_vm_type_def).isPrimary(true); addProp(t_vm_type, "cloud_properties", t_params); + YBeanType t_disk_type = f.ybean("DiskType"); + addProp(t_disk_type, "name", t_disk_type_def).isPrimary(true); + addProp(t_disk_type, "disk_size", t_pos_integer).isRequired(true); + addProp(t_disk_type, "cloud_properties", t_params); + this.toplevelType = f.ybean("CloudConfig"); addProp(toplevelType, "azs", f.yseq(t_az)).isRequired(true); addProp(toplevelType, "networks", f.yseq(t_network)).isRequired(true); addProp(toplevelType, "vm_types", f.yseq(t_vm_type)).isRequired(true); - addProp(toplevelType, "vm_extensions", t_any); - addProp(toplevelType, "disk_types", t_any).isRequired(true); + addProp(toplevelType, "vm_extensions", f.yseq(t_any)); + addProp(toplevelType, "disk_types", f.yseq(t_disk_type)).isRequired(true); addProp(toplevelType, "compilation", t_compilation).isRequired(true); ASTTypeCache astTypes = models.astTypes; @@ -186,7 +198,8 @@ public class BoshCloudConfigSchema extends SchemaSupport implements YamlSchema { return defAndRefTypes.load(() -> ImmutableList.of( Pair.of(t_vm_type_def, t_vm_type_ref), Pair.of(t_network_def, t_network_ref), - Pair.of(t_az_def, t_az_ref) + Pair.of(t_az_def, t_az_ref), + Pair.of(t_disk_type_def, t_disk_type_ref) )); } diff --git a/headless-services/bosh-language-server/src/main/resources/cloud-config/DiskType/cloud_properties.md b/headless-services/bosh-language-server/src/main/resources/cloud-config/DiskType/cloud_properties.md new file mode 100644 index 000000000..67f3a7696 --- /dev/null +++ b/headless-services/bosh-language-server/src/main/resources/cloud-config/DiskType/cloud_properties.md @@ -0,0 +1,11 @@ +Describes any IaaS-specific properties needed to create disks. Examples: `type`, `iops`. Default is `{}` (empty Hash). + +CPI Specific `cloud_properties` + +- See [AWS CPI disk type cloud properties](https://bosh.io/docs/aws-cpi.html#disk-pools) +- See [Azure CPI disk type cloud properties](https://bosh.io/docs/azure-cpi.html#disk-pools) +- See [OpenStack CPI disk type cloud properties](https://bosh.io/docs/openstack-cpi.html#disk-pools) +- See [Softlayer CPI disk type cloud properties](https://bosh.io/docs/softlayer-cpi.html#disk-pools) +- See [Google Cloud Platform CPI disk type cloud properties](https://bosh.io/docs/google-cpi.html#disk-pools) +- See [vSphere CPI disk type cloud properties](https://bosh.io/docs/vsphere-cpi.html#disk-pools) +- See [vCloud CPI disk type cloud properties](https://bosh.io/docs/vcloud-cpi.html#disk-pools) diff --git a/headless-services/bosh-language-server/src/main/resources/cloud-config/DiskType/disk_size.md b/headless-services/bosh-language-server/src/main/resources/cloud-config/DiskType/disk_size.md new file mode 100644 index 000000000..808f3d0f4 --- /dev/null +++ b/headless-services/bosh-language-server/src/main/resources/cloud-config/DiskType/disk_size.md @@ -0,0 +1 @@ +*Require*. Specifies the disk size. `disk_size` must be a positive integer. BOSH creates a [persistent disk](https://bosh.io/docs/persistent-disks.html) of that size in megabytes and attaches it to each job instance VM. \ No newline at end of file diff --git a/headless-services/bosh-language-server/src/main/resources/cloud-config/DiskType/name.md b/headless-services/bosh-language-server/src/main/resources/cloud-config/DiskType/name.md new file mode 100644 index 000000000..147b1a936 --- /dev/null +++ b/headless-services/bosh-language-server/src/main/resources/cloud-config/DiskType/name.md @@ -0,0 +1 @@ +*Required*. A unique name used to identify and reference the disk type \ No newline at end of file diff --git a/headless-services/bosh-language-server/src/test/java/org/springframework/ide/vscode/bosh/BoshEditorTest.java b/headless-services/bosh-language-server/src/test/java/org/springframework/ide/vscode/bosh/BoshEditorTest.java index 745873b9a..a7e38cfd3 100644 --- a/headless-services/bosh-language-server/src/test/java/org/springframework/ide/vscode/bosh/BoshEditorTest.java +++ b/headless-services/bosh-language-server/src/test/java/org/springframework/ide/vscode/bosh/BoshEditorTest.java @@ -2358,7 +2358,7 @@ public class BoshEditorTest { editor.assertProblems("bad-network|unknown 'NetworkName'"); } - @Test public void cloudconfig_network_azs_ca() throws Exception { + @Test public void cloudconfig_azs() throws Exception { Editor editor = harness.newEditor(LanguageId.BOSH_CLOUD_CONFIG, "azs:\n" + "- <*>" @@ -2386,4 +2386,40 @@ public class BoshEditorTest { editor.assertHoverContains("cloud_properties", "Describes any IaaS-specific properties needed to associated with AZ"); } + @Test public void cloudconfig_diskt_types() throws Exception { + Editor editor = harness.newEditor(LanguageId.BOSH_CLOUD_CONFIG, + "disk_types:\n" + + "- <*>" + ); + editor.assertContextualCompletions("<*>", + //snippet: + "name: $1\n" + + " disk_size: $2<*>" + , + //non-snippet: + "name: <*>" + ); + + editor = harness.newEditor(LanguageId.BOSH_CLOUD_CONFIG, + "disk_types:\n" + + "- name: massive-disk\n" + + " <*>" + ); + editor.assertContextualCompletions(PLAIN_COMPLETION, "<*>", + "cloud_properties:\n <*>", + "disk_size: <*>" + ); + + editor = harness.newEditor(LanguageId.BOSH_CLOUD_CONFIG, + "disk_types:\n" + + "- name: default\n" + + " disk_size: 2\n" + + " cloud_properties:\n" + + " type: gp2\n" + ); + editor.assertHoverContains("name", "A unique name used to identify and reference the disk type"); + editor.assertHoverContains("disk_size", "size in megabytes"); + editor.assertHoverContains("cloud_properties", "Describes any IaaS-specific properties needed to create disks"); + } + } diff --git a/headless-services/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/ValueParsers.java b/headless-services/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/ValueParsers.java index ec74ca344..5020cbdfd 100644 --- a/headless-services/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/ValueParsers.java +++ b/headless-services/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/ValueParsers.java @@ -36,6 +36,7 @@ public class ValueParsers { return new ValueParser() { @Override public Object parse(String str) throws Exception { + str = str.replace("_", ""); //Tolerate and ignore underscores in integers. int value = Integer.parseInt(str); if (lowerBound!=null && value