View Javadoc

1   package org.kuali.maven.ec2;
2   
3   import org.apache.maven.plugin.MojoExecutionException;
4   
5   /**
6    * Connect to EC2 and terminate the indicated instance.
7    *
8    * @goal terminateinstance
9    */
10  public class TerminateInstanceMojo extends AbstractEC2Mojo {
11  
12      /**
13       * The id of the instance to terminate. Set this to <code>NONE</code> to skip attempting to terminate an instance
14       *
15       * @parameter expression="${ec2.instanceId}"
16       * @required
17       */
18      private String instanceId;
19  
20      /**
21       * If true, the build will wait until EC2 reports that the instance has reached the state of "terminated"
22       *
23       * @parameter expression="${ec2.wait}" default-value="false"
24       */
25      private boolean wait;
26  
27      /**
28       * The number of seconds to wait for the instance to terminate before timing out and failing the build
29       *
30       * @parameter expression="${ec2.waitTimeout}" default-value="300"
31       */
32      private int waitTimeout;
33  
34      /**
35       * The state the instance needs to be in before the plugin considers it to be terminated.
36       *
37       * @parameter expression="${ec2.state}" default-value="terminated"
38       */
39      private String state;
40  
41      @Override
42      protected boolean isSkip() {
43          if (Constants.NONE.equals(instanceId)) {
44              getLog().info("instanceId=" + instanceId);
45              return true;
46          } else {
47              return false;
48          }
49      }
50  
51      @Override
52      public void execute(EC2Utils ec2Utils) throws MojoExecutionException {
53          WaitControl wc = new WaitControl(wait, waitTimeout, state);
54          ec2Utils.terminate(instanceId, wc);
55      }
56  
57      public String getInstanceId() {
58          return instanceId;
59      }
60  
61      public void setInstanceId(String id) {
62          this.instanceId = id;
63      }
64  
65      public boolean isWait() {
66          return wait;
67      }
68  
69      public void setWait(boolean wait) {
70          this.wait = wait;
71      }
72  
73      public int getWaitTimeout() {
74          return waitTimeout;
75      }
76  
77      public void setWaitTimeout(int waitTimeout) {
78          this.waitTimeout = waitTimeout;
79      }
80  
81      public String getState() {
82          return state;
83      }
84  
85      public void setState(String state) {
86          this.state = state;
87      }
88  }