View Javadoc
1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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  package org.kuali.common.aws.ec2.impl;
17  
18  import org.kuali.common.aws.ec2.api.EC2Service;
19  import org.kuali.common.aws.ec2.model.InstanceStateName;
20  import org.kuali.common.util.Assert;
21  import org.kuali.common.util.condition.Condition;
22  
23  import com.amazonaws.services.ec2.model.Instance;
24  import com.amazonaws.services.ec2.model.InstanceState;
25  
26  /**
27   * This condition being met means that the corresponding EC2 instance has reached <code>targetState</code>
28   */
29  public final class InstanceStateCondition implements Condition {
30  
31  	public InstanceStateCondition(EC2Service service, String instanceId, InstanceStateName targetState) {
32  		Assert.noNulls(service, targetState);
33  		Assert.noBlanks(instanceId);
34  		this.instanceId = instanceId;
35  		this.service = service;
36  		this.targetState = targetState;
37  	}
38  
39  	private final EC2Service service;
40  	private final String instanceId;
41  	private final InstanceStateName targetState;
42  
43  	@Override
44  	public boolean isTrue() {
45  		Instance instance = service.getInstance(instanceId);
46  		InstanceState instanceState = instance.getState();
47  		String stateName = instanceState.getName();
48  		return targetState.getValue().equals(stateName);
49  	}
50  
51  	public EC2Service getService() {
52  		return service;
53  	}
54  
55  	public String getInstanceId() {
56  		return instanceId;
57  	}
58  
59  	public InstanceStateName getTargetState() {
60  		return targetState;
61  	}
62  
63  }