Пример #1
0
  @Override
  public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;

    if (obj instanceof Source == false) return false;
    Source other = (Source) obj;
    if (other.getType() == null ^ this.getType() == null) return false;
    if (other.getType() != null && other.getType().equals(this.getType()) == false) return false;
    if (other.getUrl() == null ^ this.getUrl() == null) return false;
    if (other.getUrl() != null && other.getUrl().equals(this.getUrl()) == false) return false;
    if (other.getUsername() == null ^ this.getUsername() == null) return false;
    if (other.getUsername() != null && other.getUsername().equals(this.getUsername()) == false)
      return false;
    if (other.getPassword() == null ^ this.getPassword() == null) return false;
    if (other.getPassword() != null && other.getPassword().equals(this.getPassword()) == false)
      return false;
    if (other.getSshKey() == null ^ this.getSshKey() == null) return false;
    if (other.getSshKey() != null && other.getSshKey().equals(this.getSshKey()) == false)
      return false;
    if (other.getRevision() == null ^ this.getRevision() == null) return false;
    if (other.getRevision() != null && other.getRevision().equals(this.getRevision()) == false)
      return false;
    return true;
  }
  public Request<UpdateStackRequest> marshall(UpdateStackRequest updateStackRequest) {
    if (updateStackRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<UpdateStackRequest> request =
        new DefaultRequest<UpdateStackRequest>(updateStackRequest, "AWSOpsWorks");
    String target = "OpsWorks_20130218.UpdateStack";
    request.addHeader("X-Amz-Target", target);

    request.setHttpMethod(HttpMethodName.POST);
    request.setResourcePath("");

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

      jsonWriter.object();

      if (updateStackRequest.getStackId() != null) {
        jsonWriter.key("StackId").value(updateStackRequest.getStackId());
      }
      if (updateStackRequest.getName() != null) {
        jsonWriter.key("Name").value(updateStackRequest.getName());
      }
      if (updateStackRequest.getAttributes() != null) {
        jsonWriter.key("Attributes");
        jsonWriter.object();
        for (Map.Entry<String, String> attributesListValue :
            updateStackRequest.getAttributes().entrySet()) {
          if (attributesListValue.getValue() != null) {
            jsonWriter.key(attributesListValue.getKey());

            jsonWriter.value(attributesListValue.getValue());
          }
        }
        jsonWriter.endObject();
      }
      if (updateStackRequest.getServiceRoleArn() != null) {
        jsonWriter.key("ServiceRoleArn").value(updateStackRequest.getServiceRoleArn());
      }
      if (updateStackRequest.getDefaultInstanceProfileArn() != null) {
        jsonWriter
            .key("DefaultInstanceProfileArn")
            .value(updateStackRequest.getDefaultInstanceProfileArn());
      }
      if (updateStackRequest.getDefaultOs() != null) {
        jsonWriter.key("DefaultOs").value(updateStackRequest.getDefaultOs());
      }
      if (updateStackRequest.getHostnameTheme() != null) {
        jsonWriter.key("HostnameTheme").value(updateStackRequest.getHostnameTheme());
      }
      if (updateStackRequest.getDefaultAvailabilityZone() != null) {
        jsonWriter
            .key("DefaultAvailabilityZone")
            .value(updateStackRequest.getDefaultAvailabilityZone());
      }
      if (updateStackRequest.getDefaultSubnetId() != null) {
        jsonWriter.key("DefaultSubnetId").value(updateStackRequest.getDefaultSubnetId());
      }
      if (updateStackRequest.getCustomJson() != null) {
        jsonWriter.key("CustomJson").value(updateStackRequest.getCustomJson());
      }
      StackConfigurationManager configurationManager = updateStackRequest.getConfigurationManager();
      if (configurationManager != null) {

        jsonWriter.key("ConfigurationManager");
        jsonWriter.object();

        if (configurationManager.getName() != null) {
          jsonWriter.key("Name").value(configurationManager.getName());
        }
        if (configurationManager.getVersion() != null) {
          jsonWriter.key("Version").value(configurationManager.getVersion());
        }
        jsonWriter.endObject();
      }
      ChefConfiguration chefConfiguration = updateStackRequest.getChefConfiguration();
      if (chefConfiguration != null) {

        jsonWriter.key("ChefConfiguration");
        jsonWriter.object();

        if (chefConfiguration.isManageBerkshelf() != null) {
          jsonWriter.key("ManageBerkshelf").value(chefConfiguration.isManageBerkshelf());
        }
        if (chefConfiguration.getBerkshelfVersion() != null) {
          jsonWriter.key("BerkshelfVersion").value(chefConfiguration.getBerkshelfVersion());
        }
        jsonWriter.endObject();
      }
      if (updateStackRequest.isUseCustomCookbooks() != null) {
        jsonWriter.key("UseCustomCookbooks").value(updateStackRequest.isUseCustomCookbooks());
      }
      Source customCookbooksSource = updateStackRequest.getCustomCookbooksSource();
      if (customCookbooksSource != null) {

        jsonWriter.key("CustomCookbooksSource");
        jsonWriter.object();

        if (customCookbooksSource.getType() != null) {
          jsonWriter.key("Type").value(customCookbooksSource.getType());
        }
        if (customCookbooksSource.getUrl() != null) {
          jsonWriter.key("Url").value(customCookbooksSource.getUrl());
        }
        if (customCookbooksSource.getUsername() != null) {
          jsonWriter.key("Username").value(customCookbooksSource.getUsername());
        }
        if (customCookbooksSource.getPassword() != null) {
          jsonWriter.key("Password").value(customCookbooksSource.getPassword());
        }
        if (customCookbooksSource.getSshKey() != null) {
          jsonWriter.key("SshKey").value(customCookbooksSource.getSshKey());
        }
        if (customCookbooksSource.getRevision() != null) {
          jsonWriter.key("Revision").value(customCookbooksSource.getRevision());
        }
        jsonWriter.endObject();
      }
      if (updateStackRequest.getDefaultSshKeyName() != null) {
        jsonWriter.key("DefaultSshKeyName").value(updateStackRequest.getDefaultSshKeyName());
      }
      if (updateStackRequest.getDefaultRootDeviceType() != null) {
        jsonWriter
            .key("DefaultRootDeviceType")
            .value(updateStackRequest.getDefaultRootDeviceType());
      }
      if (updateStackRequest.isUseOpsworksSecurityGroups() != null) {
        jsonWriter
            .key("UseOpsworksSecurityGroups")
            .value(updateStackRequest.isUseOpsworksSecurityGroups());
      }
      if (updateStackRequest.getAgentVersion() != null) {
        jsonWriter.key("AgentVersion").value(updateStackRequest.getAgentVersion());
      }

      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;
  }
  public Request<CreateStackRequest> marshall(CreateStackRequest createStackRequest) {
    if (createStackRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<CreateStackRequest> request =
        new DefaultRequest<CreateStackRequest>(createStackRequest, "AWSOpsWorks");
    String target = "OpsWorks_20130218.CreateStack";
    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();

      if (createStackRequest.getName() != null) {
        jsonWriter.key("Name").value(createStackRequest.getName());
      }
      if (createStackRequest.getRegion() != null) {
        jsonWriter.key("Region").value(createStackRequest.getRegion());
      }
      if (createStackRequest.getVpcId() != null) {
        jsonWriter.key("VpcId").value(createStackRequest.getVpcId());
      }
      if (createStackRequest.getAttributes() != null) {
        jsonWriter.key("Attributes");
        jsonWriter.object();
        for (Map.Entry<String, String> attributesListValue :
            createStackRequest.getAttributes().entrySet()) {
          if (attributesListValue.getValue() != null) {
            jsonWriter.key(attributesListValue.getKey());

            jsonWriter.value(attributesListValue.getValue());
          }
        }
        jsonWriter.endObject();
      }
      if (createStackRequest.getServiceRoleArn() != null) {
        jsonWriter.key("ServiceRoleArn").value(createStackRequest.getServiceRoleArn());
      }
      if (createStackRequest.getDefaultInstanceProfileArn() != null) {
        jsonWriter
            .key("DefaultInstanceProfileArn")
            .value(createStackRequest.getDefaultInstanceProfileArn());
      }
      if (createStackRequest.getDefaultOs() != null) {
        jsonWriter.key("DefaultOs").value(createStackRequest.getDefaultOs());
      }
      if (createStackRequest.getHostnameTheme() != null) {
        jsonWriter.key("HostnameTheme").value(createStackRequest.getHostnameTheme());
      }
      if (createStackRequest.getDefaultAvailabilityZone() != null) {
        jsonWriter
            .key("DefaultAvailabilityZone")
            .value(createStackRequest.getDefaultAvailabilityZone());
      }
      if (createStackRequest.getDefaultSubnetId() != null) {
        jsonWriter.key("DefaultSubnetId").value(createStackRequest.getDefaultSubnetId());
      }
      if (createStackRequest.getCustomJson() != null) {
        jsonWriter.key("CustomJson").value(createStackRequest.getCustomJson());
      }
      StackConfigurationManager configurationManager = createStackRequest.getConfigurationManager();
      if (configurationManager != null) {

        jsonWriter.key("ConfigurationManager");
        jsonWriter.object();

        if (configurationManager.getName() != null) {
          jsonWriter.key("Name").value(configurationManager.getName());
        }
        if (configurationManager.getVersion() != null) {
          jsonWriter.key("Version").value(configurationManager.getVersion());
        }
        jsonWriter.endObject();
      }
      if (createStackRequest.isUseCustomCookbooks() != null) {
        jsonWriter.key("UseCustomCookbooks").value(createStackRequest.isUseCustomCookbooks());
      }
      Source customCookbooksSource = createStackRequest.getCustomCookbooksSource();
      if (customCookbooksSource != null) {

        jsonWriter.key("CustomCookbooksSource");
        jsonWriter.object();

        if (customCookbooksSource.getType() != null) {
          jsonWriter.key("Type").value(customCookbooksSource.getType());
        }
        if (customCookbooksSource.getUrl() != null) {
          jsonWriter.key("Url").value(customCookbooksSource.getUrl());
        }
        if (customCookbooksSource.getUsername() != null) {
          jsonWriter.key("Username").value(customCookbooksSource.getUsername());
        }
        if (customCookbooksSource.getPassword() != null) {
          jsonWriter.key("Password").value(customCookbooksSource.getPassword());
        }
        if (customCookbooksSource.getSshKey() != null) {
          jsonWriter.key("SshKey").value(customCookbooksSource.getSshKey());
        }
        if (customCookbooksSource.getRevision() != null) {
          jsonWriter.key("Revision").value(customCookbooksSource.getRevision());
        }
        jsonWriter.endObject();
      }
      if (createStackRequest.getDefaultSshKeyName() != null) {
        jsonWriter.key("DefaultSshKeyName").value(createStackRequest.getDefaultSshKeyName());
      }
      if (createStackRequest.getDefaultRootDeviceType() != null) {
        jsonWriter
            .key("DefaultRootDeviceType")
            .value(createStackRequest.getDefaultRootDeviceType());
      }

      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;
  }