Search in sources :

Example 6 with NoTargetsException

use of org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.NoTargetsException in project sts4 by spring-projects.

the class ManifestYamlLanguageServer method applyCfLoginParameterSettings.

@SuppressWarnings("unchecked")
private void applyCfLoginParameterSettings(CfTargetsInfo info) {
    List<Target> cfTargets = info.getCfTargets();
    if (cfTargets != null) {
        CfTargetsInfoProvder cfClientParamsProvider = new CfTargetsInfoProvder(info);
        cfClientConfig.setClientParamsProvider(new ClientParamsProvider() {

            @Override
            public Collection<CFClientParams> getParams() throws NoTargetsException, ExecutionException {
                List<ClientParamsProvider> providers = ImmutableList.of(defaultClientParamsProvider, cfClientParamsProvider);
                List<CFClientParams> params = new ArrayList<>();
                for (ClientParamsProvider provider : providers) {
                    try {
                        params.addAll(provider.getParams());
                    } catch (Exception e) {
                    // ignore
                    }
                }
                if (params.isEmpty()) {
                    throw new NoTargetsException(getMessages().noTargetsFound());
                }
                return params;
            }

            @Override
            public CFParamsProviderMessages getMessages() {
                return cfTargets.isEmpty() ? defaultClientParamsProvider.getMessages() : cfClientParamsProvider.getMessages();
            }
        });
    }
}
Also used : Target(org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CfTargetsInfo.Target) NoTargetsException(org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.NoTargetsException) CFParamsProviderMessages(org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFParamsProviderMessages) CfTargetsInfoProvder(org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CfTargetsInfoProvder) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ClientParamsProvider(org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.ClientParamsProvider) ExecutionException(java.util.concurrent.ExecutionException) NoTargetsException(org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.NoTargetsException) JsonSyntaxException(com.google.gson.JsonSyntaxException) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with NoTargetsException

use of org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.NoTargetsException in project sts4 by spring-projects.

the class RouteValueParser method dynamicValidation.

private Object dynamicValidation(String str, Matcher matcher) throws Exception {
    if (domains == null) {
        // If domains is unknown we can't do the dynamic checks, so bail out.
        return str;
    }
    try {
        Collection<String> cloudDomains = Collections.emptyList();
        try {
            cloudDomains = domains.call();
        } catch (ValueParseException e) {
            /*
				 * If domains hint provider throws exception it is
				 * ValueParserException not NoTargetsException. This means no
				 * communication with CF -> abort dyncamic validation
				 */
            return matcher;
        }
        if (cloudDomains == null) {
            // If domains is unknown we can't do the dynamic checks, so bail out.
            return str;
        }
        CFRoute route = CFRoute.builder().from(str, cloudDomains).build();
        if (route.getDomain() == null || route.getDomain().isEmpty()) {
            throw new ValueParseException("Domain is missing.");
        }
        if ((route.getPath() != null && !route.getPath().isEmpty()) && (route.getPort() != CFRoute.NO_PORT)) {
            throw new ValueParseException("Unable to determine type of route. HTTP port may have a path but no port. TCP route may have port but no path.");
        }
        if (route.getPort() > MAX_PORT_NUMBER) {
            String portAndColumn = matcher.group(2);
            int start = str.indexOf(portAndColumn) + 1;
            int end = start + portAndColumn.length() - 1;
            throw new ValueParseException("Invalid port number. Port range must be between 1 and " + MAX_PORT_NUMBER, start, end);
        }
        if (!cloudDomains.contains(route.getDomain())) {
            String hostDomain = matcher.group(1);
            throw new ReconcileException("Unknown 'Domain'. Valid domains are: " + cloudDomains, ManifestYamlSchemaProblemsTypes.UNKNOWN_DOMAIN_PROBLEM, hostDomain.lastIndexOf(route.getDomain()), hostDomain.length());
        }
        return str;
    } catch (ConnectionException | NoTargetsException e) {
        // No connection to CF? Abort dynamic validation
        return str;
    }
}
Also used : NoTargetsException(org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.NoTargetsException) ReconcileException(org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileException) CFRoute(org.springframework.ide.vscode.commons.cloudfoundry.client.CFRoute) ValueParseException(org.springframework.ide.vscode.commons.util.ValueParseException) ConnectionException(org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.ConnectionException)

Aggregations

NoTargetsException (org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.NoTargetsException)7 Test (org.junit.Test)5 Editor (org.springframework.ide.vscode.languageserver.testharness.Editor)3 CompletionItem (org.eclipse.lsp4j.CompletionItem)2 ImmutableList (com.google.common.collect.ImmutableList)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 CFBuildpack (org.springframework.ide.vscode.commons.cloudfoundry.client.CFBuildpack)1 CFRoute (org.springframework.ide.vscode.commons.cloudfoundry.client.CFRoute)1 ClientRequests (org.springframework.ide.vscode.commons.cloudfoundry.client.ClientRequests)1 CFParamsProviderMessages (org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFParamsProviderMessages)1 Target (org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CfTargetsInfo.Target)1 CfTargetsInfoProvder (org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CfTargetsInfoProvder)1 ClientParamsProvider (org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.ClientParamsProvider)1 ConnectionException (org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.ConnectionException)1 ReconcileException (org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileException)1 ValueParseException (org.springframework.ide.vscode.commons.util.ValueParseException)1