View Javadoc
1   /*
2    * Copyright (c) 2016 ingenieux Labs
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package br.com.ingenieux.mojo.beanstalk.cmd.env.update;
18  
19  import com.amazonaws.services.elasticbeanstalk.model.UpdateEnvironmentRequest;
20  import com.amazonaws.services.elasticbeanstalk.model.UpdateEnvironmentResult;
21  
22  import org.apache.maven.plugin.AbstractMojoExecutionException;
23  
24  import java.util.Arrays;
25  
26  import br.com.ingenieux.mojo.beanstalk.AbstractBeanstalkMojo;
27  import br.com.ingenieux.mojo.beanstalk.cmd.BaseCommand;
28  
29  import static org.apache.commons.lang.StringUtils.isNotBlank;
30  
31  public class UpdateEnvironmentCommand extends BaseCommand<UpdateEnvironmentContext, UpdateEnvironmentResult> {
32  
33    /**
34     * Constructor
35     *
36     * @param parentMojo parent mojo
37     */
38    public UpdateEnvironmentCommand(AbstractBeanstalkMojo parentMojo) throws AbstractMojoExecutionException {
39      super(parentMojo);
40    }
41  
42    @Override
43    protected UpdateEnvironmentResult executeInternal(UpdateEnvironmentContext context) throws Exception {
44      UpdateEnvironmentRequest req = new UpdateEnvironmentRequest();
45  
46      if (null != context.environmentDescription) {
47        req.setDescription(context.environmentDescription);
48      }
49  
50      if (null != context.environmentName) {
51        req.setEnvironmentName(context.environmentName);
52      } else if (null != context.environmentId) {
53        req.setEnvironmentId(context.environmentId);
54      }
55  
56      if (null != context.optionSettings && 0 != context.optionSettings.length) {
57        req.setOptionSettings(Arrays.asList(context.optionSettings));
58      }
59      if (null != context.optionsToRemove && 0 != context.optionsToRemove.length) {
60        req.setOptionsToRemove(Arrays.asList(context.optionsToRemove));
61      }
62  
63      if (isNotBlank(context.versionLabel)) {
64        info("Calling update-environment, and using versionLabel: " + context.versionLabel);
65  
66        req.setVersionLabel(context.versionLabel);
67      } else if (isNotBlank(context.templateName)) {
68        info("Calling update-environment, and using templateName: " + context.templateName);
69  
70        req.setTemplateName(context.templateName);
71      }
72  
73      return service.updateEnvironment(req);
74    }
75  }