Search in sources :

Example 1 with ReleaseData

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

the class BoshEditorTest method reconcileReleaseVersion.

@Test
public void reconcileReleaseVersion() throws Exception {
    Editor editor;
    releasesProvider = provideReleasesFrom(new ReleaseData("foo", "123.4"), new ReleaseData("foo", "222.2"), new ReleaseData("bar", "222.2"), new ReleaseData("bar", "333.3"));
    editor = harness.newEditor("releases:\n" + "- version: bogus\n" + "- version: url-makes-this-possibly-correct\n" + "  url: file:///relesease-folder/blah-release.tar.gz\n" + "- name: bar\n" + "  version: url-makes-this-also-possibly-correct\n" + "  url: file:///relesease-folder/other-release.tar.gz");
    editor.ignoreProblem(YamlSchemaProblems.MISSING_PROPERTY);
    editor.assertProblems("bogus|unknown 'ReleaseVersion'. Valid values are: [123.4, 222.2, 333.3, latest]");
    editor = harness.newEditor("releases:\n" + "- version: 123.4\n" + "- version: latest\n" + "- version: bogus\n");
    editor.ignoreProblem(YamlSchemaProblems.MISSING_PROPERTY);
    editor.assertProblems("bogus|unknown 'ReleaseVersion'. Valid values are: [123.4, 222.2, 333.3, latest]");
    editor = harness.newEditor("releases:\n" + "- name: foo\n" + "  version: 123.4\n");
    editor.ignoreProblem(YamlSchemaProblems.MISSING_PROPERTY);
    editor.assertProblems();
    editor = harness.newEditor("releases:\n" + "- name: foo\n" + "  version: 222.2\n");
    editor.ignoreProblem(YamlSchemaProblems.MISSING_PROPERTY);
    editor.assertProblems();
    editor = harness.newEditor("releases:\n" + "- name: foo\n" + "  version: 333.3\n");
    editor.ignoreProblem(YamlSchemaProblems.MISSING_PROPERTY);
    editor.assertProblems("333.3|unknown 'ReleaseVersion[name=foo]'. Valid values are: [123.4, 222.2, latest]");
}
Also used : ReleaseData(org.springframework.ide.vscode.bosh.models.ReleaseData) Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) Test(org.junit.Test)

Example 2 with ReleaseData

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

the class BoshEditorTest method reconcileReleaseNameDef.

@Test
public void reconcileReleaseNameDef() throws Exception {
    releasesProvider = provideReleasesFrom(new ReleaseData("foo", "123.4"), new ReleaseData("foo", "222.2"), new ReleaseData("bar", "222.2"), new ReleaseData("bar", "333.3"));
    Editor editor = harness.newEditor("releases:\n" + "- name: foo\n" + "- name: bar\n" + "- name: bogus\n" + "- name: url-makes-this-ok\n" + "  url: file://blah");
    editor.ignoreProblem(YamlSchemaProblems.MISSING_PROPERTY);
    editor.assertProblems("bogus|unknown 'ReleaseName'. Valid values are: [foo, bar]");
}
Also used : ReleaseData(org.springframework.ide.vscode.bosh.models.ReleaseData) Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) Test(org.junit.Test)

Example 3 with ReleaseData

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

the class BoshEditorTest method contentAssistReleaseVersion.

@Test
public void contentAssistReleaseVersion() throws Exception {
    releasesProvider = provideReleasesFrom(new ReleaseData("foo", "123.4"), new ReleaseData("foo", "222.2"), new ReleaseData("bar", "222.2"), new ReleaseData("bar", "333.3"));
    Editor editor = harness.newEditor("releases:\n" + "- version: <*>");
    editor.assertContextualCompletions("<*>", "123.4<*>", "222.2<*>", "333.3<*>", "latest<*>");
    editor = harness.newEditor("releases:\n" + "- name: foo\n" + "  version: <*>");
    editor.assertContextualCompletions("<*>", "123.4<*>", "222.2<*>", "latest<*>");
    // Still get all suggestions even when 'url' property is added
    editor = harness.newEditor("releases:\n" + "- version: <*>\n" + "  url: blah");
    editor.assertContextualCompletions("<*>", "123.4<*>", "222.2<*>", "333.3<*>", "latest<*>");
    editor = harness.newEditor("releases:\n" + "- name: foo\n" + "  url: blah\n" + "  version: <*>");
    editor.assertContextualCompletions("<*>", "123.4<*>", "222.2<*>", "333.3<*>", "latest<*>");
}
Also used : ReleaseData(org.springframework.ide.vscode.bosh.models.ReleaseData) Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) Test(org.junit.Test)

Example 4 with ReleaseData

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

the class BoshEditorTest method contentAssistReleaseNameDef.

@Test
public void contentAssistReleaseNameDef() throws Exception {
    releasesProvider = provideReleasesFrom(new ReleaseData("foo", "123.4"), new ReleaseData("foo", "222.2"), new ReleaseData("bar", "222.2"), new ReleaseData("bar", "333.3"));
    Editor editor = harness.newEditor("releases:\n" + "- name: <*>");
    editor.assertContextualCompletions("<*>", "bar<*>", "foo<*>");
}
Also used : ReleaseData(org.springframework.ide.vscode.bosh.models.ReleaseData) Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) Test(org.junit.Test)

Example 5 with ReleaseData

use of org.springframework.ide.vscode.bosh.models.ReleaseData 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;
}
Also used : StemcellModel(org.springframework.ide.vscode.bosh.models.StemcellModel) AbstractType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType) YamlSchemaProblems(org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaProblems) ReleasesModel(org.springframework.ide.vscode.bosh.models.ReleasesModel) NodeUtil(org.springframework.ide.vscode.commons.yaml.ast.NodeUtil) YTypeUtil(org.springframework.ide.vscode.commons.yaml.schema.YTypeUtil) YContextSensitive(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YContextSensitive) YamlAstCache(org.springframework.ide.vscode.commons.yaml.ast.YamlAstCache) ASTTypeCache(org.springframework.ide.vscode.commons.yaml.reconcile.ASTTypeCache) 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) YamlFileAST(org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST) Map(java.util.Map) ValueParsers(org.springframework.ide.vscode.commons.util.ValueParsers) BoshModels(org.springframework.ide.vscode.bosh.models.BoshModels) YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) DynamicSchemaContext(org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext) CloudConfigModel(org.springframework.ide.vscode.bosh.models.CloudConfigModel) YTypedProperty(org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty) ImmutableSet(com.google.common.collect.ImmutableSet) CollectorUtil(org.springframework.ide.vscode.commons.util.CollectorUtil) Predicate(java.util.function.Predicate) Collection(java.util.Collection) YamlSchema(org.springframework.ide.vscode.commons.yaml.schema.YamlSchema) Renderables(org.springframework.ide.vscode.commons.util.Renderables) PartialCollection(org.springframework.ide.vscode.commons.util.PartialCollection) UUID(java.util.UUID) Assert(org.springframework.ide.vscode.commons.util.Assert) YType(org.springframework.ide.vscode.commons.yaml.schema.YType) YTypedPropertyImpl(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YTypedPropertyImpl) YBeanType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanType) SchemaBasedSnippetGenerator(org.springframework.ide.vscode.commons.yaml.snippet.SchemaBasedSnippetGenerator) YAtomicType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YAtomicType) List(java.util.List) CachingModelProvider(org.springframework.ide.vscode.bosh.models.CachingModelProvider) DynamicModelProvider(org.springframework.ide.vscode.bosh.models.DynamicModelProvider) ReleaseData(org.springframework.ide.vscode.bosh.models.ReleaseData) Renderable(org.springframework.ide.vscode.commons.util.Renderable) StemcellData(org.springframework.ide.vscode.bosh.models.StemcellData) StemcellsModel(org.springframework.ide.vscode.bosh.models.StemcellsModel) PartialCollection(org.springframework.ide.vscode.commons.util.PartialCollection) YAtomicType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YAtomicType) ReleaseData(org.springframework.ide.vscode.bosh.models.ReleaseData) StemcellData(org.springframework.ide.vscode.bosh.models.StemcellData) YBeanType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanType) YType(org.springframework.ide.vscode.commons.yaml.schema.YType) YTypedProperty(org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty)

Aggregations

ReleaseData (org.springframework.ide.vscode.bosh.models.ReleaseData)5 Test (org.junit.Test)4 Editor (org.springframework.ide.vscode.languageserver.testharness.Editor)3 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Predicate (java.util.function.Predicate)1 Pair (org.apache.commons.lang3.tuple.Pair)1 BoshModels (org.springframework.ide.vscode.bosh.models.BoshModels)1 CachingModelProvider (org.springframework.ide.vscode.bosh.models.CachingModelProvider)1 CloudConfigModel (org.springframework.ide.vscode.bosh.models.CloudConfigModel)1 DynamicModelProvider (org.springframework.ide.vscode.bosh.models.DynamicModelProvider)1 ReleasesModel (org.springframework.ide.vscode.bosh.models.ReleasesModel)1 StemcellData (org.springframework.ide.vscode.bosh.models.StemcellData)1 StemcellModel (org.springframework.ide.vscode.bosh.models.StemcellModel)1 StemcellsModel (org.springframework.ide.vscode.bosh.models.StemcellsModel)1 Assert (org.springframework.ide.vscode.commons.util.Assert)1