Пример #1
0
 protected <T, I> T handleCreate(I resource, Class<T> outputType)
     throws ExecutionException, InterruptedException, KubernetesClientException, IOException {
   AsyncHttpClient.BoundRequestBuilder requestBuilder =
       getClient()
           .getHttpClient()
           .preparePost(getNamespacedUrl(checkNamespace(resource)).toString());
   requestBuilder.setBody(OBJECT_MAPPER.writer().writeValueAsString(resource));
   return handleResponse(requestBuilder, 201, outputType);
 }
Пример #2
0
 protected <T> T handleReplace(T updated, Class<T> type)
     throws ExecutionException, InterruptedException, KubernetesClientException, IOException {
   AsyncHttpClient.BoundRequestBuilder requestBuilder =
       getClient()
           .getHttpClient()
           .preparePut(getResourceUrl(checkNamespace(updated), checkName(updated)).toString());
   requestBuilder.setBody(OBJECT_MAPPER.writer().writeValueAsString(updated));
   return handleResponse(requestBuilder, 200, type);
 }
  private void restCall(Tuple tuple) throws ExecutionException, InterruptedException {
    Future<Response> fureRet = null;
    for (RestInfo restInfo : restInfos) {
      String url = restInfo.getUrl();
      String body = restInfo.getBody();
      for (BaseBindColumnDef bindColumn : restInfo.getColumns()) {
        url =
            url.replace(
                "[:" + bindColumn.getName() + "]", tuple.getStringByField(bindColumn.getName()));
        if (body != null) {
          body =
              body.replace(
                  "[:" + bindColumn.getName() + "]", tuple.getStringByField(bindColumn.getName()));
        }
      }

      AsyncHttpClient.BoundRequestBuilder boundRequestBuilder = null;
      if (RestCmd.PUT.equals(restInfo.getCmd())) {
        boundRequestBuilder = asyncHttpClient.preparePut(url);
      } else if (RestCmd.GET.equals(restInfo.getCmd())) {
        boundRequestBuilder = asyncHttpClient.prepareGet(url);
      } else if (RestCmd.DELETE.equals(restInfo.getCmd())) {
        boundRequestBuilder = asyncHttpClient.prepareDelete(url);
      } else if (RestCmd.POST.equals(restInfo.getCmd())) {
        boundRequestBuilder = asyncHttpClient.preparePost(url);
      } else {
        break;
      }

      if (body != null) {
        fureRet = boundRequestBuilder.setBody(body).execute();
      } else {
        fureRet = boundRequestBuilder.execute();
      }

      fureRet.get();
    }
  }
 void setPayload(AsyncHttpClient.BoundRequestBuilder requestBuilder, Payload payload) {
   requestBuilder.setBody(new PayloadEntityWriter(payload));
 }