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.env;
18  
19  import com.amazonaws.services.elasticbeanstalk.model.ConfigurationOptionSetting;
20  import com.amazonaws.services.elasticbeanstalk.model.OptionSpecification;
21  import com.amazonaws.services.elasticbeanstalk.model.UpdateEnvironmentRequest;
22  
23  import org.apache.maven.plugin.MojoExecutionException;
24  import org.apache.maven.plugin.MojoFailureException;
25  import org.apache.maven.plugins.annotations.Mojo;
26  import org.apache.maven.plugins.annotations.Parameter;
27  
28  import br.com.ingenieux.mojo.beanstalk.AbstractNeedsEnvironmentMojo;
29  
30  /**
31   * Updates the environment configuration (optionsSettings / optionsToRemove)
32   *
33   * See the <a href= "http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_UpdateEnvironment.html"
34   * >UpdateEnvironment API</a> call.
35   *
36   * @since 0.2.2
37   */
38  @Mojo(name = "update-environment-options", requiresDirectInvocation = true)
39  public class UpdateEnvironmentOptionsMojo extends AbstractNeedsEnvironmentMojo {
40  
41    /**
42     * Configuration Option Settings
43     */
44    @Parameter ConfigurationOptionSetting[] optionSettings;
45  
46    /**
47     * Configuration Options To Remove
48     */
49    @Parameter OptionSpecification[] optionsToRemove;
50  
51    /**
52     * Environment Name
53     */
54    @Parameter(property = "beanstalk.environmentDescription", defaultValue = "default")
55    String environmentDescription;
56    /**
57     * Version Label to use.
58     */
59    @Parameter(property = "beanstalk.versionLabel")
60    String versionLabel;
61    /**
62     * <p>Template Name.</p>
63     *
64     * <p>Could be either literal or a glob, like, <pre>ingenieux-services-prod-*</pre>. If a glob,
65     * there will be a lookup involved, and the first one in reverse ASCIIbetical order will be
66     * picked upon. </p>
67     */
68    @Parameter(property = "beanstalk.templateName")
69    String templateName;
70    /**
71     * What to set?
72     */
73    @Parameter(property = "beanstalk.whatToSet", defaultValue = "versionLabel", required = true)
74    WhatToSet whatToSet;
75  
76    protected Object executeInternal() throws MojoExecutionException, MojoFailureException {
77      UpdateEnvironmentRequest req = new UpdateEnvironmentRequest();
78  
79      req.setEnvironmentId(curEnv.getEnvironmentId());
80      req.setEnvironmentName(curEnv.getEnvironmentName());
81  
82      if (WhatToSet.versionLabel.equals(whatToSet)) {
83        req.setVersionLabel(versionLabel);
84      } else if (WhatToSet.description.equals(whatToSet)) {
85        req.setDescription(environmentDescription);
86      } else if (WhatToSet.optionSettings.equals(whatToSet)) {
87        req.setOptionSettings(getOptionSettings(optionSettings));
88      } else if (WhatToSet.templateName.equals(whatToSet)) {
89        req.setTemplateName(lookupTemplateName(applicationName, templateName));
90      } else if (WhatToSet.optionsToRemove.equals(whatToSet)) {
91        req.setOptionsToRemove(getOptionsToRemove(optionsToRemove));
92      }
93  
94      return getService().updateEnvironment(req);
95    }
96  
97    public enum WhatToSet {
98      description,
99      optionSettings,
100     templateName,
101     versionLabel,
102     optionsToRemove
103   }
104 }