Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
   * 
   *  http://aws.amazon.com/apache2.0
   * 
  * or in the "license" file accompanying this file. This file is distributed
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.services.opsworks.model.transform;
 
 import static com.amazonaws.util.StringUtils.UTF8;
 import static com.amazonaws.util.StringUtils.COMMA_SEPARATOR;
 import java.io.Writer;
 import java.util.Map;
 import java.util.List;
 
Create Layer Request Marshaller
 
 
     public Request<CreateLayerRequestmarshall(CreateLayerRequest createLayerRequest) {
         if (createLayerRequest == null) {
             throw new AmazonClientException("Invalid argument passed to marshall(...)");
         }
 
         Request<CreateLayerRequestrequest = new DefaultRequest<CreateLayerRequest>(createLayerRequest"AWSOpsWorks");
         String target = "OpsWorks_20130218.CreateLayer";
         request.addHeader("X-Amz-Target"target);
 
         request.setHttpMethod(.);
         request.setResourcePath("");
         
         try {
           StringWriter stringWriter = new StringWriter();
           JSONWriter jsonWriter = new JSONWriter(stringWriter);
 
           jsonWriter.object();
           
             if (createLayerRequest.getStackId() != null) {
                 jsonWriter.key("StackId").value(createLayerRequest.getStackId());
             }
             if (createLayerRequest.getType() != null) {
                 jsonWriter.key("Type").value(createLayerRequest.getType());
             }
             if (createLayerRequest.getName() != null) {
                 jsonWriter.key("Name").value(createLayerRequest.getName());
             }
             if (createLayerRequest.getShortname() != null) {
                 jsonWriter.key("Shortname").value(createLayerRequest.getShortname());
             }
             if (createLayerRequest.getAttributes() != null) {
                 jsonWriter.key("Attributes");
                 jsonWriter.object();
                 for (Map.Entry<StringStringattributesListValue : createLayerRequest.getAttributes().entrySet()) {
                     if (attributesListValue.getValue() != null) {
                         jsonWriter.key(attributesListValue.getKey());
 
                         jsonWriter.value(attributesListValue.getValue());
                     }
                 }
                 jsonWriter.endObject();
             }
             if (createLayerRequest.getCustomInstanceProfileArn() != null) {
                 jsonWriter.key("CustomInstanceProfileArn").value(createLayerRequest.getCustomInstanceProfileArn());
             }
 
             com.amazonaws.internal.ListWithAutoConstructFlag<StringcustomSecurityGroupIdsList = (com.amazonaws.internal.ListWithAutoConstructFlag<String>)(createLayerRequest.getCustomSecurityGroupIds());
             if (customSecurityGroupIdsList != null && !(customSecurityGroupIdsList.isAutoConstruct() && customSecurityGroupIdsList.isEmpty())) {
 
                 jsonWriter.key("CustomSecurityGroupIds");
                 jsonWriter.array();
 
                 for (String customSecurityGroupIdsListValue : customSecurityGroupIdsList) {
                     if (customSecurityGroupIdsListValue != null) {
                        jsonWriter.value(customSecurityGroupIdsListValue);
                    }
                }
                jsonWriter.endArray();
            }
            com.amazonaws.internal.ListWithAutoConstructFlag<StringpackagesList = (com.amazonaws.internal.ListWithAutoConstructFlag<String>)(createLayerRequest.getPackages());
            if (packagesList != null && !(packagesList.isAutoConstruct() && packagesList.isEmpty())) {
                jsonWriter.key("Packages");
                jsonWriter.array();
                for (String packagesListValue : packagesList) {
                    if (packagesListValue != null) {
                        jsonWriter.value(packagesListValue);
                    }
                }
                jsonWriter.endArray();
            }
            if (volumeConfigurationsList != null && !(volumeConfigurationsList.isAutoConstruct() && volumeConfigurationsList.isEmpty())) {
                jsonWriter.key("VolumeConfigurations");
                jsonWriter.array();
                for (VolumeConfiguration volumeConfigurationsListValue : volumeConfigurationsList) {
                    if (volumeConfigurationsListValue != null) {
                        jsonWriter.object();
                        if (volumeConfigurationsListValue.getMountPoint() != null) {
                            jsonWriter.key("MountPoint").value(volumeConfigurationsListValue.getMountPoint());
                        }
                        if (volumeConfigurationsListValue.getRaidLevel() != null) {
                            jsonWriter.key("RaidLevel").value(volumeConfigurationsListValue.getRaidLevel());
                        }
                        if (volumeConfigurationsListValue.getNumberOfDisks() != null) {
                            jsonWriter.key("NumberOfDisks").value(volumeConfigurationsListValue.getNumberOfDisks());
                        }
                        if (volumeConfigurationsListValue.getSize() != null) {
                            jsonWriter.key("Size").value(volumeConfigurationsListValue.getSize());
                        }
                        if (volumeConfigurationsListValue.getVolumeType() != null) {
                            jsonWriter.key("VolumeType").value(volumeConfigurationsListValue.getVolumeType());
                        }
                        if (volumeConfigurationsListValue.getIops() != null) {
                            jsonWriter.key("Iops").value(volumeConfigurationsListValue.getIops());
                        }
                        jsonWriter.endObject();
                    }
                }
                jsonWriter.endArray();
            }
            if (createLayerRequest.isEnableAutoHealing() != null) {
                jsonWriter.key("EnableAutoHealing").value(createLayerRequest.isEnableAutoHealing());
            }
            if (createLayerRequest.isAutoAssignElasticIps() != null) {
                jsonWriter.key("AutoAssignElasticIps").value(createLayerRequest.isAutoAssignElasticIps());
            }
            if (createLayerRequest.isAutoAssignPublicIps() != null) {
                jsonWriter.key("AutoAssignPublicIps").value(createLayerRequest.isAutoAssignPublicIps());
            }
            Recipes customRecipes = createLayerRequest.getCustomRecipes();
            if (customRecipes != null) {
                jsonWriter.key("CustomRecipes");
                jsonWriter.object();
                com.amazonaws.internal.ListWithAutoConstructFlag<StringsetupList = (com.amazonaws.internal.ListWithAutoConstructFlag<String>)(customRecipes.getSetup());
                if (setupList != null && !(setupList.isAutoConstruct() && setupList.isEmpty())) {
                    jsonWriter.key("Setup");
                    jsonWriter.array();
                    for (String setupListValue : setupList) {
                        if (setupListValue != null) {
                            jsonWriter.value(setupListValue);
                        }
                    }
                    jsonWriter.endArray();
                }
                com.amazonaws.internal.ListWithAutoConstructFlag<StringconfigureList = (com.amazonaws.internal.ListWithAutoConstructFlag<String>)(customRecipes.getConfigure());
                if (configureList != null && !(configureList.isAutoConstruct() && configureList.isEmpty())) {
                    jsonWriter.key("Configure");
                    jsonWriter.array();
                    for (String configureListValue : configureList) {
                        if (configureListValue != null) {
                            jsonWriter.value(configureListValue);
                        }
                    }
                    jsonWriter.endArray();
                }
                com.amazonaws.internal.ListWithAutoConstructFlag<StringdeployList = (com.amazonaws.internal.ListWithAutoConstructFlag<String>)(customRecipes.getDeploy());
                if (deployList != null && !(deployList.isAutoConstruct() && deployList.isEmpty())) {
                    jsonWriter.key("Deploy");
                    jsonWriter.array();
                    for (String deployListValue : deployList) {
                        if (deployListValue != null) {
                            jsonWriter.value(deployListValue);
                        }
                    }
                    jsonWriter.endArray();
                }
                com.amazonaws.internal.ListWithAutoConstructFlag<StringundeployList = (com.amazonaws.internal.ListWithAutoConstructFlag<String>)(customRecipes.getUndeploy());
                if (undeployList != null && !(undeployList.isAutoConstruct() && undeployList.isEmpty())) {
                    jsonWriter.key("Undeploy");
                    jsonWriter.array();
                    for (String undeployListValue : undeployList) {
                        if (undeployListValue != null) {
                            jsonWriter.value(undeployListValue);
                        }
                    }
                    jsonWriter.endArray();
                }
                com.amazonaws.internal.ListWithAutoConstructFlag<StringshutdownList = (com.amazonaws.internal.ListWithAutoConstructFlag<String>)(customRecipes.getShutdown());
                if (shutdownList != null && !(shutdownList.isAutoConstruct() && shutdownList.isEmpty())) {
                    jsonWriter.key("Shutdown");
                    jsonWriter.array();
                    for (String shutdownListValue : shutdownList) {
                        if (shutdownListValue != null) {
                            jsonWriter.value(shutdownListValue);
                        }
                    }
                    jsonWriter.endArray();
                }
                jsonWriter.endObject();
            }
            if (createLayerRequest.isInstallUpdatesOnBoot() != null) {
                jsonWriter.key("InstallUpdatesOnBoot").value(createLayerRequest.isInstallUpdatesOnBoot());
            }
            if (createLayerRequest.isUseEbsOptimizedInstances() != null) {
                jsonWriter.key("UseEbsOptimizedInstances").value(createLayerRequest.isUseEbsOptimizedInstances());
            }
            LifecycleEventConfiguration lifecycleEventConfiguration = createLayerRequest.getLifecycleEventConfiguration();
            if (lifecycleEventConfiguration != null) {
                jsonWriter.key("LifecycleEventConfiguration");
                jsonWriter.object();
                ShutdownEventConfiguration shutdown = lifecycleEventConfiguration.getShutdown();
                if (shutdown != null) {
                    jsonWriter.key("Shutdown");
                    jsonWriter.object();
                    if (shutdown.getExecutionTimeout() != null) {
                        jsonWriter.key("ExecutionTimeout").value(shutdown.getExecutionTimeout());
                    }
                    if (shutdown.isDelayUntilElbConnectionsDrained() != null) {
                        jsonWriter.key("DelayUntilElbConnectionsDrained").value(shutdown.isDelayUntilElbConnectionsDrained());
                    }
                    jsonWriter.endObject();
                }
                jsonWriter.endObject();
            }
          jsonWriter.endObject();
          String snippet = stringWriter.toString();
          byte[] content = snippet.getBytes();
          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;
    }
New to GrepCode? Check out our FAQ X