1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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 }