Example #1
0
def find_zookeepers(provider):
    """Find running zookeeper instances.

    :param provider: the MachineProvider in charge of the juju

    :return: all running or starting machines configured to run zookeeper, as a
        list of :class:`juju.machine.ProviderMachine`
    :rtype: :class:`twisted.internet.defer.Deferred`

    :raises: :class:`juju.errors.EnvironmentNotFound`
    """
    state = yield provider.load_state()
    _require(state)
    instance_ids = state.get("zookeeper-instances")
    _require(instance_ids)

    machines = []
    missing_instance_ids = []
    for instance_id in instance_ids:
        try:
            machine = yield provider.get_machine(instance_id)
            machines.append(machine)
        except MachinesNotFound as e:
            missing_instance_ids.extend(e.instance_ids)

    if machines:
        returnValue(machines)
    raise EnvironmentNotFound("machines are not running (%s)" %
                              ", ".join(missing_instance_ids))
Example #2
0
 def connect(self, share=False):
     """Connect to juju's zookeeper.
     """
     state = yield self.load_state()
     if not state:
         raise EnvironmentNotFound()
     client = yield ZookeeperClient(state["zookeeper-address"]).connect()
     yield ZookeeperConnect(self).wait_for_initialization(client)
     returnValue(client)
Example #3
0
 def get_zookeeper_machines(self):
     if self._machines:
         return succeed(self._machines[:1])
     return fail(EnvironmentNotFound("not bootstrapped"))
Example #4
0
 def get_zookeeper_machines(self):
     if zookeeper:
         return succeed([zookeeper])
     return fail(EnvironmentNotFound())
Example #5
0
 def get_zookeeper_machines(self):
     if isinstance(self._zookeeper, Exception):
         return fail(self._zookeeper)
     if self._zookeeper:
         return succeed([self._zookeeper])
     return fail(EnvironmentNotFound())
Example #6
0
 def testEnvironmentNotFoundNoInfo(self):
     error = EnvironmentNotFound()
     self.assertEquals(
         str(error), "juju environment not found: no details "
         "available")
Example #7
0
 def testEnvironmentNotFoundWithInfo(self):
     error = EnvironmentNotFound("problem")
     self.assertEquals(str(error), "juju environment not found: problem")
Example #8
0
 def get_zookeeper_machines(self):
     return fail(EnvironmentNotFound("is the environment bootstrapped?"))
Example #9
0
def _require(x):
    if not x:
        raise EnvironmentNotFound("is the environment bootstrapped?")