Search in sources :

Example 1 with ConnectionException

use of org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.ConnectionException 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)

Example 2 with ConnectionException

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

the class AbstractCFHintsProvider method getHints.

/**
 * @return non-null list of hints. Return empty if no hints available
 */
protected Collection<YValueHint> getHints(List<CFTarget> targets) throws Exception {
    if (targets == null || targets.isEmpty()) {
        // this "don't know" value will suppress bogus warnings in the reconciler.
        return null;
    }
    List<YValueHint> hints = new ArrayList<>();
    boolean validTargetsPresent = false;
    for (CFTarget cfTarget : targets) {
        try {
            // TODO: check if duplicate proposals can be the list of all hints. Duplicates don't seem to cause duplicate proposals. Verify this!
            getHints(cfTarget).stream().filter(hint -> !hints.contains(hint)).forEach(hint -> hints.add(hint));
            validTargetsPresent = true;
        } catch (Exception e) {
        // Drop individual target error
        }
    }
    if (validTargetsPresent) {
        return hints;
    } else {
        throw new ConnectionException(targetCache.getCfClientConfig().getClientParamsProvider().getMessages().noNetworkConnection());
    }
}
Also used : ExceptionUtil(org.springframework.ide.vscode.commons.util.ExceptionUtil) Collection(java.util.Collection) Callable(java.util.concurrent.Callable) CFTarget(org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFTarget) Assert(org.springframework.ide.vscode.commons.util.Assert) NoTargetsException(org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.NoTargetsException) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ValueParseException(org.springframework.ide.vscode.commons.util.ValueParseException) ConnectionException(org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.ConnectionException) CFTargetCache(org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFTargetCache) YValueHint(org.springframework.ide.vscode.commons.yaml.schema.YValueHint) CFTarget(org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFTarget) ArrayList(java.util.ArrayList) YValueHint(org.springframework.ide.vscode.commons.yaml.schema.YValueHint) NoTargetsException(org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.NoTargetsException) ValueParseException(org.springframework.ide.vscode.commons.util.ValueParseException) ConnectionException(org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.ConnectionException) ConnectionException(org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.ConnectionException)

Aggregations

ConnectionException (org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.ConnectionException)2 NoTargetsException (org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.NoTargetsException)2 ValueParseException (org.springframework.ide.vscode.commons.util.ValueParseException)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 CFRoute (org.springframework.ide.vscode.commons.cloudfoundry.client.CFRoute)1 CFTarget (org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFTarget)1 CFTargetCache (org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFTargetCache)1 ReconcileException (org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileException)1 Assert (org.springframework.ide.vscode.commons.util.Assert)1 ExceptionUtil (org.springframework.ide.vscode.commons.util.ExceptionUtil)1 YValueHint (org.springframework.ide.vscode.commons.yaml.schema.YValueHint)1