Ejemplo n.º 1
0
  /** Marshall the given parameter object, and output to a SdkJsonGenerator */
  public void marshall(StepConfig stepConfig, StructuredJsonGenerator jsonGenerator) {

    if (stepConfig == null) {
      throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
      jsonGenerator.writeStartObject();

      if (stepConfig.getName() != null) {
        jsonGenerator.writeFieldName("Name").writeValue(stepConfig.getName());
      }
      if (stepConfig.getActionOnFailure() != null) {
        jsonGenerator.writeFieldName("ActionOnFailure").writeValue(stepConfig.getActionOnFailure());
      }
      if (stepConfig.getHadoopJarStep() != null) {
        jsonGenerator.writeFieldName("HadoopJarStep");
        HadoopJarStepConfigJsonMarshaller.getInstance()
            .marshall(stepConfig.getHadoopJarStep(), jsonGenerator);
      }

      jsonGenerator.writeEndObject();
    } catch (Throwable t) {
      throw new SdkClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }
  }
  public Request<ListClustersRequest> marshall(ListClustersRequest listClustersRequest) {

    if (listClustersRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<ListClustersRequest> request =
        new DefaultRequest<ListClustersRequest>(listClustersRequest, "AmazonElasticMapReduce");
    request.addHeader("X-Amz-Target", "ElasticMapReduce.ListClusters");

    request.setHttpMethod(HttpMethodName.POST);

    request.setResourcePath("");

    try {
      final StructuredJsonGenerator jsonGenerator = protocolFactory.createGenerator();

      jsonGenerator.writeStartObject();

      if (listClustersRequest.getCreatedAfter() != null) {
        jsonGenerator
            .writeFieldName("CreatedAfter")
            .writeValue(listClustersRequest.getCreatedAfter());
      }
      if (listClustersRequest.getCreatedBefore() != null) {
        jsonGenerator
            .writeFieldName("CreatedBefore")
            .writeValue(listClustersRequest.getCreatedBefore());
      }

      com.amazonaws.internal.SdkInternalList<String> clusterStatesList =
          (com.amazonaws.internal.SdkInternalList<String>) listClustersRequest.getClusterStates();
      if (!clusterStatesList.isEmpty() || !clusterStatesList.isAutoConstruct()) {
        jsonGenerator.writeFieldName("ClusterStates");
        jsonGenerator.writeStartArray();
        for (String clusterStatesListValue : clusterStatesList) {
          if (clusterStatesListValue != null) {
            jsonGenerator.writeValue(clusterStatesListValue);
          }
        }
        jsonGenerator.writeEndArray();
      }
      if (listClustersRequest.getMarker() != null) {
        jsonGenerator.writeFieldName("Marker").writeValue(listClustersRequest.getMarker());
      }

      jsonGenerator.writeEndObject();

      byte[] content = jsonGenerator.getBytes();
      request.setContent(new ByteArrayInputStream(content));
      request.addHeader("Content-Length", Integer.toString(content.length));
      request.addHeader("Content-Type", jsonGenerator.getContentType());
    } catch (Throwable t) {
      throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }

    return request;
  }
  public Request<AddInstanceGroupsRequest> marshall(
      AddInstanceGroupsRequest addInstanceGroupsRequest) {

    if (addInstanceGroupsRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<AddInstanceGroupsRequest> request =
        new DefaultRequest<AddInstanceGroupsRequest>(
            addInstanceGroupsRequest, "AmazonElasticMapReduce");
    request.addHeader("X-Amz-Target", "ElasticMapReduce.AddInstanceGroups");

    request.setHttpMethod(HttpMethodName.POST);

    request.setResourcePath("");

    try {
      final StructuredJsonGenerator jsonGenerator = protocolFactory.createGenerator();

      jsonGenerator.writeStartObject();

      com.amazonaws.internal.SdkInternalList<InstanceGroupConfig> instanceGroupsList =
          (com.amazonaws.internal.SdkInternalList<InstanceGroupConfig>)
              addInstanceGroupsRequest.getInstanceGroups();
      if (!instanceGroupsList.isEmpty() || !instanceGroupsList.isAutoConstruct()) {
        jsonGenerator.writeFieldName("InstanceGroups");
        jsonGenerator.writeStartArray();
        for (InstanceGroupConfig instanceGroupsListValue : instanceGroupsList) {
          if (instanceGroupsListValue != null) {

            InstanceGroupConfigJsonMarshaller.getInstance()
                .marshall(instanceGroupsListValue, jsonGenerator);
          }
        }
        jsonGenerator.writeEndArray();
      }
      if (addInstanceGroupsRequest.getJobFlowId() != null) {
        jsonGenerator
            .writeFieldName("JobFlowId")
            .writeValue(addInstanceGroupsRequest.getJobFlowId());
      }

      jsonGenerator.writeEndObject();

      byte[] content = jsonGenerator.getBytes();
      request.setContent(new ByteArrayInputStream(content));
      request.addHeader("Content-Length", Integer.toString(content.length));
      request.addHeader("Content-Type", jsonGenerator.getContentType());
    } catch (Throwable t) {
      throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }

    return request;
  }
  /** Marshall the given parameter object, and output to a SdkJsonGenerator */
  public void marshall(
      HadoopJarStepConfig hadoopJarStepConfig, StructuredJsonGenerator jsonGenerator) {

    if (hadoopJarStepConfig == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    try {
      jsonGenerator.writeStartObject();

      com.amazonaws.internal.SdkInternalList<KeyValue> propertiesList =
          (com.amazonaws.internal.SdkInternalList<KeyValue>) hadoopJarStepConfig.getProperties();
      if (!propertiesList.isEmpty() || !propertiesList.isAutoConstruct()) {
        jsonGenerator.writeFieldName("Properties");
        jsonGenerator.writeStartArray();
        for (KeyValue propertiesListValue : propertiesList) {
          if (propertiesListValue != null) {

            KeyValueJsonMarshaller.getInstance().marshall(propertiesListValue, jsonGenerator);
          }
        }
        jsonGenerator.writeEndArray();
      }
      if (hadoopJarStepConfig.getJar() != null) {
        jsonGenerator.writeFieldName("Jar").writeValue(hadoopJarStepConfig.getJar());
      }
      if (hadoopJarStepConfig.getMainClass() != null) {
        jsonGenerator.writeFieldName("MainClass").writeValue(hadoopJarStepConfig.getMainClass());
      }

      com.amazonaws.internal.SdkInternalList<String> argsList =
          (com.amazonaws.internal.SdkInternalList<String>) hadoopJarStepConfig.getArgs();
      if (!argsList.isEmpty() || !argsList.isAutoConstruct()) {
        jsonGenerator.writeFieldName("Args");
        jsonGenerator.writeStartArray();
        for (String argsListValue : argsList) {
          if (argsListValue != null) {
            jsonGenerator.writeValue(argsListValue);
          }
        }
        jsonGenerator.writeEndArray();
      }

      jsonGenerator.writeEndObject();
    } catch (Throwable t) {
      throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }
  }
  /** Marshall the given parameter object, and output to a JSONWriter */
  public void marshall(BootstrapActionDetail bootstrapActionDetail, JSONWriter jsonWriter) {
    if (bootstrapActionDetail == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    try {
      jsonWriter.object();

      if (bootstrapActionDetail.getBootstrapActionConfig() != null) {
        jsonWriter.key("BootstrapActionConfig");
        BootstrapActionConfigJsonMarshaller.getInstance()
            .marshall(bootstrapActionDetail.getBootstrapActionConfig(), jsonWriter);
      }

      jsonWriter.endObject();
    } catch (Throwable t) {
      throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }
  }
  public Request<ListInstanceGroupsRequest> marshall(
      ListInstanceGroupsRequest listInstanceGroupsRequest) {

    if (listInstanceGroupsRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<ListInstanceGroupsRequest> request =
        new DefaultRequest<ListInstanceGroupsRequest>(
            listInstanceGroupsRequest, "AmazonElasticMapReduce");
    request.addHeader("X-Amz-Target", "ElasticMapReduce.ListInstanceGroups");

    request.setHttpMethod(HttpMethodName.POST);

    request.setResourcePath("");

    try {
      StringWriter stringWriter = new StringWriter();
      JSONWriter jsonWriter = new JSONWriter(stringWriter);

      jsonWriter.object();

      if (listInstanceGroupsRequest.getClusterId() != null) {
        jsonWriter.key("ClusterId").value(listInstanceGroupsRequest.getClusterId());
      }

      if (listInstanceGroupsRequest.getMarker() != null) {
        jsonWriter.key("Marker").value(listInstanceGroupsRequest.getMarker());
      }

      jsonWriter.endObject();

      String snippet = stringWriter.toString();
      byte[] content = snippet.getBytes(UTF8);
      request.setContent(new StringInputStream(snippet));
      request.addHeader("Content-Length", Integer.toString(content.length));
      request.addHeader("Content-Type", "application/x-amz-json-1.1");
    } catch (Throwable t) {
      throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }

    return request;
  }
  /** Marshall the given parameter object, and output to a SdkJsonGenerator */
  public void marshall(MetricDimension metricDimension, StructuredJsonGenerator jsonGenerator) {

    if (metricDimension == null) {
      throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
      jsonGenerator.writeStartObject();

      if (metricDimension.getKey() != null) {
        jsonGenerator.writeFieldName("Key").writeValue(metricDimension.getKey());
      }
      if (metricDimension.getValue() != null) {
        jsonGenerator.writeFieldName("Value").writeValue(metricDimension.getValue());
      }

      jsonGenerator.writeEndObject();
    } catch (Throwable t) {
      throw new SdkClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }
  }
  /** Marshall the given parameter object, and output to a JSONWriter */
  public void marshall(StepStateChangeReason stepStateChangeReason, JSONWriter jsonWriter) {
    if (stepStateChangeReason == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    try {
      jsonWriter.object();

      if (stepStateChangeReason.getCode() != null) {
        jsonWriter.key("Code").value(stepStateChangeReason.getCode());
      }

      if (stepStateChangeReason.getMessage() != null) {
        jsonWriter.key("Message").value(stepStateChangeReason.getMessage());
      }

      jsonWriter.endObject();
    } catch (Throwable t) {
      throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }
  }
  public Request<SetTerminationProtectionRequest> marshall(
      SetTerminationProtectionRequest setTerminationProtectionRequest) {
    if (setTerminationProtectionRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<SetTerminationProtectionRequest> request =
        new DefaultRequest<SetTerminationProtectionRequest>(
            setTerminationProtectionRequest, "AmazonElasticMapReduce");
    String target = "ElasticMapReduce.SetTerminationProtection";
    request.addHeader("X-Amz-Target", target);
    request.addHeader("Content-Type", "application/x-amz-json-1.1");

    request.setHttpMethod(HttpMethodName.POST);

    String uriResourcePath = "";

    uriResourcePath = uriResourcePath.replaceAll("//", "/");

    if (uriResourcePath.contains("?")) {
      String queryString = uriResourcePath.substring(uriResourcePath.indexOf("?") + 1);
      uriResourcePath = uriResourcePath.substring(0, uriResourcePath.indexOf("?"));

      for (String s : queryString.split("[;&]")) {
        String[] nameValuePair = s.split("=");
        if (nameValuePair.length == 2) {
          request.addParameter(nameValuePair[0], nameValuePair[1]);
        } else {
          request.addParameter(s, null);
        }
      }
    }

    request.setResourcePath(uriResourcePath);

    try {
      StringWriter stringWriter = new StringWriter();
      JSONWriter jsonWriter = new JSONWriter(stringWriter);

      jsonWriter.object();

      com.amazonaws.internal.ListWithAutoConstructFlag<String> jobFlowIdsList =
          (com.amazonaws.internal.ListWithAutoConstructFlag<String>)
              (setTerminationProtectionRequest.getJobFlowIds());
      if (jobFlowIdsList != null
          && !(jobFlowIdsList.isAutoConstruct() && jobFlowIdsList.isEmpty())) {

        jsonWriter.key("JobFlowIds");
        jsonWriter.array();

        for (String jobFlowIdsListValue : jobFlowIdsList) {
          if (jobFlowIdsListValue != null) {
            jsonWriter.value(jobFlowIdsListValue);
          }
        }
        jsonWriter.endArray();
      }
      if (setTerminationProtectionRequest.isTerminationProtected() != null) {
        jsonWriter
            .key("TerminationProtected")
            .value(setTerminationProtectionRequest.isTerminationProtected());
      }

      jsonWriter.endObject();

      String snippet = stringWriter.toString();
      byte[] content = snippet.getBytes("UTF-8");
      request.setContent(new StringInputStream(snippet));
      request.addHeader("Content-Length", Integer.toString(content.length));
    } catch (Throwable t) {
      throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }

    return request;
  }