13
15
class EC2ZookeeperAware(object):
15
17
def _verify_zookeeper_instances(self, state):
16
"""Verify which zookeeper nodes are running."""
18
"""Verify which zookeeper nodes are running.
20
Returns the first valid instance found as a single element list,
21
or returns an empty list. If
20
instance_info = state.get("zookeeper-instances", None)
22
d = self.ec2.describe_instances(*[i for i in instance_info])
24
def filter_running(instances):
27
for instance in instances:
28
if instance.instance_state == "running":
29
running.append(instance)
30
elif instance.instance_state == "pending":
34
raise EnvironmentPending(
35
"Started machine is still pending.")
37
raise EnvironmentNotFound(
38
"No Ensemble machines found. "
39
"Is the environment bootstrapped?")
42
d.addCallback(filter_running)
26
instances = state.get("zookeeper-instances", None)
31
instance_id = instances.pop(0)
32
d = self.ec2.describe_instances(instance_id)
34
d.addCallback(self._cb_filter_running_zookeeper_instances)
35
d.addErrback(self._eb_invalid_instance_id, instances)
39
def _eb_invalid_instance_id(self, failure, instances):
40
# Trap these failures to continue processing instances
42
EC2Error, EnvironmentPending, EnvironmentNotFound)
44
# Reformat invalid ids ec2 errors into an appros ensemble error.
45
if not instances and failure.check(EC2Error):
46
error_code = failure.value.get_error_codes()
47
if error_code == "InvalidInstanceID.NotFound":
48
raise EnvironmentNotFound(
49
"No Ensemble machines found. "
50
"Is the environment bootstrapped?")
52
# Process next instance
54
instance_id = instances.pop(0)
55
d = self.ec2.describe_instances(instance_id)
57
d.addCallback(self._cb_filter_running_zookeeper_instances)
58
d.addErrback(self._eb_invalid_instance_id, instances)
61
# Return the original failure
64
def _cb_filter_running_zookeeper_instances(self, instances):
65
# instances is either a single element list or an empty list.
66
assert len(instances) <= 1, "Should only process single instance %r"
67
for instance in instances:
68
if instance.instance_state == "running":
70
elif instance.instance_state == "pending":
71
raise EnvironmentPending(
72
"Started machine is still pending.")
73
raise EnvironmentNotFound(
74
"No Ensemble machines found. "
75
"Is the environment bootstrapped?")
46
78
class EC2Connect(EC2Operation, EC2ZookeeperAware):