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.UpdateEnvironmentRequest;
21  import com.amazonaws.services.elasticbeanstalk.model.UpdateEnvironmentResult;
22  
23  import org.apache.maven.plugins.annotations.Mojo;
24  import org.apache.maven.plugins.annotations.Parameter;
25  
26  import java.util.Arrays;
27  
28  import br.com.ingenieux.mojo.beanstalk.AbstractNeedsEnvironmentMojo;
29  
30  /**
31   * Sets a System Property in a Running Environment
32   *
33   * @since 1.1.0
34   */
35  @Mojo(name = "set-property", requiresDirectInvocation = true)
36  public class SetPropertyMojo extends AbstractNeedsEnvironmentMojo {
37  
38    /**
39     * System Property Name
40     */
41    @Parameter(property = "beanstalk.envName", required = true)
42    String envName;
43  
44    /**
45     * System Property Value
46     */
47    @Parameter(property = "beanstalk.envValue", required = true)
48    String envValue;
49  
50    protected Object executeInternal() throws Exception {
51      waitForNotUpdating();
52  
53      UpdateEnvironmentRequest req = new UpdateEnvironmentRequest().withEnvironmentId(curEnv.getEnvironmentId());
54  
55      req.setOptionSettings(
56          Arrays.asList(
57              new ConfigurationOptionSetting().withNamespace("aws:elasticbeanstalk:application:environment").withOptionName(envName).withValue(envValue)));
58  
59      UpdateEnvironmentResult result = getService().updateEnvironment(req);
60  
61      return result;
62    }
63  }