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 org.apache.maven.plugins.annotations.Mojo;
20  
21  import br.com.ingenieux.mojo.beanstalk.cmd.env.update.UpdateEnvironmentCommand;
22  import br.com.ingenieux.mojo.beanstalk.cmd.env.update.UpdateEnvironmentContext;
23  import br.com.ingenieux.mojo.beanstalk.cmd.env.update.UpdateEnvironmentContextBuilder;
24  
25  /**
26   * Creates (if needed) or Updates an Elastic Beanstalk Environment <p> See the docs for the <a
27   * href= "http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_CreateEnvironment.html"
28   * >CreateEnvironment API</a> call.
29   *
30   * @since 0.2.8
31   */
32  @Mojo(name = "put-environment")
33  public class PutEnvironmentMojo extends CreateEnvironmentMojo {
34  
35    @Override
36    protected void configure() {
37      try {
38        super.projectTags();
39        curEnv = super.lookupEnvironment(applicationName, environmentRef);
40      } catch (Exception exc) {
41        // Previous Environment Does Not Exists. So its fine to just create the new environment.
42      }
43    }
44  
45    @Override
46    protected Object executeInternal() throws Exception {
47      /*
48       * We *DO* have an existing environment. So we're just calling update-environment instead
49       */
50      if (null != curEnv) {
51        UpdateEnvironmentContext context =
52            UpdateEnvironmentContextBuilder.updateEnvironmentContext()
53                .withEnvironmentId(curEnv.getEnvironmentId()) //
54                .withVersionLabel(versionLabel) //
55                .build();
56  
57        UpdateEnvironmentCommandpdate/UpdateEnvironmentCommand.html#UpdateEnvironmentCommand">UpdateEnvironmentCommand command = new UpdateEnvironmentCommand(this);
58  
59        return command.execute(context);
60      }
61  
62      return super.executeInternal();
63    }
64  }