Search in sources :

Example 6 with DynamicSchemaContext

use of org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext in project sts4 by spring-projects.

the class BoshCommandCloudConfigProvider method getModel.

@Override
public CloudConfigModel getModel(DynamicSchemaContext dc) throws Exception {
    String block = getBlock();
    YamlFileAST ast = parseYaml(block);
    return new CloudConfigModel() {

        @Override
        public Collection<String> getVMTypes() {
            return getNames(VM_TYPE_NAMES);
        }

        @Override
        public Collection<String> getNetworkNames() {
            return getNames(NETWORK_NAMES);
        }

        @Override
        public Collection<String> getAvailabilityZones() {
            return getNames(AVAILABILITY_ZONES);
        }

        @Override
        public Collection<String> getDiskTypes() {
            return getNames(DISK_TYPES);
        }

        @Override
        public Collection<String> getVMExtensions() {
            return getNames(VM_EXTENSIONS);
        }

        private Collection<String> getNames(YamlTraversal namesPath) {
            return namesPath.traverseAmbiguously(ast).flatMap(nameNode -> {
                String name = NodeUtil.asScalar(nameNode);
                return StringUtil.hasText(name) ? Stream.of(name) : Stream.empty();
            }).collect(CollectorUtil.toMultiset());
        }
    };
}
Also used : StringUtil(org.springframework.ide.vscode.commons.util.StringUtil) Stream(java.util.stream.Stream) CollectorUtil(org.springframework.ide.vscode.commons.util.CollectorUtil) YamlTraversal(org.springframework.ide.vscode.commons.yaml.path.YamlTraversal) BoshCliConfig(org.springframework.ide.vscode.bosh.BoshCliConfig) YamlFileAST(org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST) Duration(java.time.Duration) Collection(java.util.Collection) ExternalCommand(org.springframework.ide.vscode.commons.util.ExternalCommand) NodeUtil(org.springframework.ide.vscode.commons.yaml.ast.NodeUtil) YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) DynamicSchemaContext(org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext) YamlFileAST(org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST) YamlTraversal(org.springframework.ide.vscode.commons.yaml.path.YamlTraversal)

Example 7 with DynamicSchemaContext

use of org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext in project sts4 by spring-projects.

the class BoshCommandCloudConfigProviderTest method getStuff.

// For local testing only... in CI builds we don't have the means to use a real bosh director and cli.
// private BoshCommandCloudConfigProvider realProvider = new BoshCommandCloudConfigProvider();
@Test
public void getStuff() throws Exception {
    DynamicSchemaContext dc = Mockito.mock(DynamicSchemaContext.class);
    CloudConfigModel cloudConfig = provider.getModel(dc);
    assertEquals(ImmutableMultiset.of("default", "large"), cloudConfig.getVMTypes());
    assertEquals(ImmutableMultiset.of("default"), cloudConfig.getNetworkNames());
    assertEquals(ImmutableMultiset.of("default", "large"), cloudConfig.getDiskTypes());
    assertEquals(ImmutableMultiset.of("default", "large"), cloudConfig.getVMTypes());
    assertEquals(ImmutableMultiset.of(), cloudConfig.getVMExtensions());
    assertEquals(ImmutableMultiset.of("z1", "z2", "z3"), cloudConfig.getAvailabilityZones());
}
Also used : DynamicSchemaContext(org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext) Test(org.junit.Test)

Aggregations

DynamicSchemaContext (org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext)7 YamlPath (org.springframework.ide.vscode.commons.yaml.path.YamlPath)4 YType (org.springframework.ide.vscode.commons.yaml.schema.YType)4 YTypedProperty (org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty)4 Collection (java.util.Collection)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 CollectorUtil (org.springframework.ide.vscode.commons.util.CollectorUtil)3 Log (org.springframework.ide.vscode.commons.util.Log)3 StringUtil (org.springframework.ide.vscode.commons.util.StringUtil)3 NodeUtil (org.springframework.ide.vscode.commons.yaml.ast.NodeUtil)3 YamlFileAST (org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST)3 ArrayList (java.util.ArrayList)2 Stream (java.util.stream.Stream)2 Test (org.junit.Test)2 IProblemCollector (org.springframework.ide.vscode.commons.languageserver.reconcile.IProblemCollector)2 SnippetBuilder (org.springframework.ide.vscode.commons.languageserver.util.SnippetBuilder)2 IDocument (org.springframework.ide.vscode.commons.util.text.IDocument)2