public static RuntimeException launderThrowable(OperationInfo spec, Throwable cause) { if (cause instanceof KubernetesClientException) { return launderThrowable(spec, ((KubernetesClientException)cause).getStatus(), cause); } return launderThrowable(describeOperation(spec)+ " failed.", cause); }
private void appendMessage(StringBuilder msg, Throwable initialCause) { if (initialCause instanceof KubernetesClientException) { KubernetesClientException kce = (KubernetesClientException)initialCause; final Status status = kce.getStatus(); if (status != null) { msg.append(status.getMessage() ).append(' '); } } else if (msg.indexOf(initialCause.toString() ) == -1) { msg.append(initialCause.toString() ).append(' '); } } }
private void appendMessage(StringBuilder msg, Throwable initialCause) { if (initialCause instanceof KubernetesClientException) { KubernetesClientException kce = (KubernetesClientException)initialCause; final Status status = kce.getStatus(); if (status != null) { msg.append(status.getMessage() ).append(' '); } } else if (msg.indexOf(initialCause.toString() ) == -1) { msg.append(initialCause.toString() ).append(' '); } } }
/** * Checks if Excpetion can be retried and if retries are left. * @param e * @param retries */ private static void checkRetryPolicy(KubernetesClientException e, int retries) { if (retries == 0) { throw new KubernetesClientException("Retries exhausted.", e); } else if (e.getCause() instanceof IOException) { LOGGER.warn("Got: {}. Retrying", e.getMessage()); } else if (e.getStatus() != null && (e.getStatus().getCode() == 500 || e.getStatus().getCode() == 503)) { LOGGER.warn("Received HTTP {} from server. Retrying", e.getStatus().getCode()); } else { throw e; } }
@Override public Response toResponse(Exception exception) { final int statusCode; if (exception instanceof WebApplicationException) { statusCode = ((WebApplicationException) exception).getResponse().getStatus(); } else if (exception instanceof KubernetesClientException) { statusCode = ((KubernetesClientException) exception).getStatus().getCode(); } else if (exception instanceof UnresolvedAddressException || exception instanceof JsonProcessingException || exception instanceof UnresolvedAddressSpaceException || exception instanceof ValidationException || exception instanceof UserValidationFailedException) { statusCode = Response.Status.BAD_REQUEST.getStatusCode(); } else { statusCode = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(); } Response response = Response.status(statusCode) .entity(Status.failureStatus(statusCode, getReasonPhrase(statusCode), exception.getMessage())) .build(); if (Response.Status.Family.familyOf(statusCode) == Response.Status.Family.CLIENT_ERROR) { log.info("Returning client error HTTP status {}: {}", statusCode, exception.getMessage()); } else { log.warn("Returning server error HTTP status " + statusCode, exception); } return response; }
@Override public void onClose(KubernetesClientException cause) { if (cause != null) { log.error("Error while watching for build to finish: %s [%d]", cause.getMessage(), cause.getCode()); Status status = cause.getStatus(); if (status != null) { log.error("%s [%s]", status.getReason(), status.getStatus()); } } latch.countDown(); } };
private Build startBuild(OpenShiftClient client, File dockerTar, String buildName) { log.info("Starting Build %s", buildName); try { return client.buildConfigs().withName(buildName) .instantiateBinary() .fromFile(dockerTar); } catch (KubernetesClientException exp) { Status status = exp.getStatus(); if (status != null) { log.error("OpenShift Error: [%d %s] [%s] %s", status.getCode(), status.getStatus(), status.getReason(), status.getMessage()); } if (exp.getCause() instanceof IOException && exp.getCause().getMessage().contains("Stream Closed")) { log.error("Build for %s failed: %s", buildName, exp.getCause().getMessage()); logBuildFailedDetails(client, buildName); } throw exp; } }
private void logBuildFailure(OpenShiftClient client, String buildName) throws Fabric8ServiceException { try { List<Build> builds = client.builds().inNamespace(client.getNamespace()).list().getItems(); for(Build build : builds) { if(build.getMetadata().getName().contains(buildName)) { log.error(build.getMetadata().getName() + "\t" + "\t" + build.getStatus().getReason() + "\t" + build.getStatus().getMessage()); throw new Fabric8ServiceException("Unable to build the image using the OpenShift build service", new KubernetesClientException(build.getStatus().getReason() + " " + build.getStatus().getMessage())); } } log.error("Also, check cluster events via `oc get events` to see what could have possibly gone wrong"); } catch (KubernetesClientException clientException) { Status status = clientException.getStatus(); if (status != null) log.error("OpenShift Error: [%d] %s", status.getCode(), status.getMessage()); } }
@Override public boolean replaceAddress(Address address) { ConfigMap newMap = null; try { String name = getConfigMapName(address.getMetadata().getNamespace(), address.getMetadata().getName()); newMap = create(address); ConfigMap result; if (address.getMetadata().getResourceVersion() != null) { result = client.configMaps() .withName(name) .lockResourceVersion(address.getMetadata().getResourceVersion()) .replace(newMap); } else { result = client.configMaps() .withName(name) .replace(newMap); } cache.replace(newMap); return result != null; } catch (KubernetesClientException e) { if (e.getStatus().getCode() == 404) { return false; } else { throw e; } } }
@Override public boolean replaceAddressSpace(AddressSpace addressSpace) { ConfigMap newMap = null; try { String name = getConfigMapName(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName()); newMap = create(addressSpace); ConfigMap result; if (addressSpace.getMetadata().getResourceVersion() != null) { result = client.configMaps() .withName(name) .lockResourceVersion(addressSpace.getMetadata().getResourceVersion()) .replace(newMap); } else { result = client.configMaps() .withName(name) .replace(newMap); } cache.replace(newMap); return result != null; } catch (KubernetesClientException e) { if (e.getStatus().getCode() == 404) { return false; } else { throw e; } } }
tlsCaCertUri); } catch (final KubernetesClientException kubernetesClientException) { final Status status = kubernetesClientException.getStatus(); if (status == null || !"AlreadyExists".equals(status.getReason())) { throw kubernetesClientException;
tlsCaCertUri); } catch (final KubernetesClientException kubernetesClientException) { final Status status = kubernetesClientException.getStatus(); if (status == null || !"AlreadyExists".equals(status.getReason())) { throw kubernetesClientException;