示例#1
0
 private static <T> T loadResource(String resourcePath, Class<T> type) {
   try {
     return OBJECT_MAPPER.readValue(
         QueryTranslationTest.class.getClassLoader().getResourceAsStream(resourcePath), type);
   } catch (IOException e) {
     throw new RuntimeException("FATAL! Cannot initialize test resource : " + resourcePath);
   }
 }
 public RootPaths getRootPaths() {
   try {
     URL requestUrl = client.getMasterUrl();
     Future<Response> f = getClient().getHttpClient().prepareGet(requestUrl.toString()).execute();
     Response r = f.get();
     assertResponseCode(r, 200);
     return OBJECT_MAPPER.readValue(r.getResponseBodyAsStream(), RootPaths.class);
   } catch (KubernetesClientException e) {
     if (e.getCode() != 404) {
       throw e;
     }
     return null;
   } catch (InterruptedException | ExecutionException | IOException e) {
     throw KubernetesClientException.launderThrowable(e);
   }
 }
 @SuppressWarnings("unchecked")
 public static Map<String, Object> convertJsonToMap(final String jsonData) {
   /*
    * NOTE: @SuppressWarnings("unchecked") because Jackson docs state that
    * a JSON-Object will always return as Map<String, Object>
    * http://wiki.fasterxml.com/JacksonDataBinding
    */
   Map<String, Object> jsonAsMap;
   if (Strings.isBlank(jsonData)) {
     log.warn("jsonResponse was null/empty, returning empty map; was: '{}'", jsonData);
     jsonAsMap = new HashMap<String, Object>();
   } else {
     try {
       jsonAsMap = OBJECT_MAPPER.readValue(jsonData.trim(), Map.class);
     } catch (IOException e) {
       log.error("Failed converting JSON to map: {}", jsonData);
       jsonAsMap = new HashMap<>();
     }
   }
   return jsonAsMap;
 }
  public L list() throws KubernetesClientException {
    try {
      URL requestUrl = getNamespacedUrl();
      AsyncHttpClient.BoundRequestBuilder requestBuilder =
          getClient().getHttpClient().prepareGet(requestUrl.toString());

      String labelQueryParam = getLabelQueryParam();
      if (labelQueryParam.length() > 0) {
        requestBuilder.addQueryParam("labelSelector", labelQueryParam);
      }

      String fieldQueryString = getFieldQueryParam();
      if (fieldQueryString.length() > 0) {
        requestBuilder.addQueryParam("fieldSelector", fieldQueryString);
      }

      Future<Response> f = requestBuilder.execute();
      Response r = f.get();
      assertResponseCode(r, 200);
      return OBJECT_MAPPER.readValue(r.getResponseBodyAsStream(), listType);
    } catch (InterruptedException | ExecutionException | IOException e) {
      throw KubernetesClientException.launderThrowable(e);
    }
  }