Ejemplo n.º 1
0
  def test_cluster_state(self):
    password_box = PasswordBox(gen_encryption_key())

    expected = MySQLCluster(
        'cluster1',
        'cluster_user',
        password_box.encrypt('cluster_password'),
        3,
        DEFAULT_TASK_CPUS,
        DEFAULT_TASK_MEM,
        DEFAULT_TASK_DISK)

    expected.tasks['task1'] = MySQLTask(
        'cluster1', 'task1', 'slave1', 'host1', 10000)

    self._state_provider.dump_cluster_state(expected)
    actual = self._state_provider.load_cluster_state('cluster1')

    assert expected.user == actual.user
    assert isinstance(actual.num_nodes, int)
    assert expected.num_nodes == actual.num_nodes
    assert len(expected.tasks) == len(actual.tasks)
    assert expected.tasks['task1'].port == actual.tasks['task1'].port
    assert expected.encrypted_password == actual.encrypted_password
    assert password_box.match('cluster_password', actual.encrypted_password)
Ejemplo n.º 2
0
  def test_cluster_state(self):
    expected = MySQLCluster('cluster1', 'cluster_user', 'cluster_password', 3)

    expected.tasks['task1'] = MySQLTask(
        'cluster1', 'task1', 'slave1', 'host1', 10000)

    self._state_provider.dump_cluster_state(expected)
    actual = self._state_provider.load_cluster_state('cluster1')

    assert expected.user == actual.user
    assert isinstance(actual.num_nodes, int)
    assert expected.num_nodes == actual.num_nodes
    assert len(expected.tasks) == len(actual.tasks)
    assert expected.tasks['task1'].port == actual.tasks['task1'].port
Ejemplo n.º 3
0
    def setUp(self):
        self._driver = FakeDriver()
        self._storage = FakeStorage(SequentialThreadingHandler())
        self._zk_client = FakeClient(storage=self._storage)
        self._zk_client.start()

        self._framework_id = mesos_pb2.FrameworkID()
        self._framework_id.value = "framework_id_0"

        self._offer = mesos_pb2.Offer()
        self._offer.id.value = "offer_id_0"
        self._offer.framework_id.value = self._framework_id.value
        self._offer.slave_id.value = "slave_id_0"
        self._offer.hostname = "localhost"

        resources = create_resources(cpus=4,
                                     mem=512 * 3,
                                     ports=set([10000, 10001, 10002]))
        self._offer.resources.extend(resources)

        self._framework_user = "******"

        self._zk_url = "zk://host/mysos/test"
        self._cluster = MySQLCluster("cluster0", "user", "pass", 3)

        self._tmpdir = tempfile.mkdtemp()
        self._state_provider = LocalStateProvider(self._tmpdir)

        framework_info = mesos_pb2.FrameworkInfo(user=getpass.getuser(),
                                                 name="mysos",
                                                 checkpoint=False)
        self._state = Scheduler(framework_info)
Ejemplo n.º 4
0
    def test_cluster_state(self):
        password_box = PasswordBox(gen_encryption_key())

        expected = MySQLCluster('cluster1', 'cluster_user',
                                password_box.encrypt('cluster_password'), 3,
                                DEFAULT_TASK_CPUS, DEFAULT_TASK_MEM,
                                DEFAULT_TASK_DISK)

        expected.tasks['task1'] = MySQLTask('cluster1', 'task1', 'slave1',
                                            'host1', 10000)

        self._state_provider.dump_cluster_state(expected)
        actual = self._state_provider.load_cluster_state('cluster1')

        assert expected.user == actual.user
        assert isinstance(actual.num_nodes, int)
        assert expected.num_nodes == actual.num_nodes
        assert len(expected.tasks) == len(actual.tasks)
        assert expected.tasks['task1'].port == actual.tasks['task1'].port
        assert expected.encrypted_password == actual.encrypted_password
        assert password_box.match('cluster_password',
                                  actual.encrypted_password)
Ejemplo n.º 5
0
    def setup(self, request):
        self._driver = FakeDriver()
        self._storage = FakeStorage(SequentialThreadingHandler())
        self._zk_client = FakeClient(storage=self._storage)
        self._zk_client.start()

        self._offer = mesos_pb2.Offer()
        self._offer.id.value = "offer_id_0"
        self._offer.framework_id.value = "framework_id_0"
        self._offer.slave_id.value = "slave_id_0"
        self._offer.hostname = "localhost"

        # Enough memory and ports to fit three tasks.
        resources = create_resources(cpus=4,
                                     mem=512 * 3,
                                     ports=set([10000, 10001, 10002]))
        self._offer.resources.extend(resources)

        self._framework_user = "******"

        # Some tests use the default launcher; some don't.
        self._zk_url = "zk://host/mysos/test"
        self._cluster = MySQLCluster("cluster0", "user", "pass", 3)

        # Construct the state provider based on the test parameter.
        if request.param == LocalStateProvider:
            tmpdir = tempfile.mkdtemp()
            self._state_provider = LocalStateProvider(tmpdir)
            request.addfinalizer(lambda: shutil.rmtree(tmpdir, True)
                                 )  # Clean up after ourselves.
        elif request.param == ZooKeeperStateProvider:
            self._state_provider = ZooKeeperStateProvider(
                self._zk_client, "/mysos/test")

        self._launcher = MySQLClusterLauncher(
            self._driver,
            self._cluster,
            self._state_provider,
            self._zk_url,
            self._zk_client,
            self._framework_user,
            "./executor.pex",
            "cmd.sh",
            Amount(5, Time.SECONDS),
            "/etc/mysos/admin_keyfile.yml",
            query_interval=Amount(150, Time.MILLISECONDS))  # Short interval.

        self._elected = threading.Event()
        self._launchers = [self._launcher]  # See teardown().

        request.addfinalizer(self.teardown)
Ejemplo n.º 6
0
    def test_two_launchers(self):
        """Two launchers share resources and launch their clusters successfully."""
        launchers = [
            MySQLClusterLauncher(self._driver,
                                 MySQLCluster("cluster0", "user0", "pass0", 1),
                                 self._state_provider, self._zk_url,
                                 self._zk_client, self._framework_user,
                                 "./executor.pex", "cmd.sh",
                                 Amount(5, Time.SECONDS),
                                 "/etc/mysos/admin_keyfile.yml"),
            MySQLClusterLauncher(self._driver,
                                 MySQLCluster("cluster1", "user1", "pass1", 2),
                                 self._state_provider, self._zk_url,
                                 self._zk_client, self._framework_user,
                                 "./executor.pex", "cmd.sh",
                                 Amount(5, Time.SECONDS),
                                 "/etc/mysos/admin_keyfile.yml")
        ]
        self._launchers.extend(launchers)

        resources = create_resources(cpus=4,
                                     mem=512 * 3,
                                     ports=set([10000, 10001, 10002]))
        self._offer.resources.extend(resources)

        # Three nodes in total across two clusters.
        # Simulate the scheduler.
        for i in range(3):
            for launcher in launchers:
                task_id, remaining = launcher.launch(self._offer)
                if task_id:
                    # Update the offer so other launchers will use its remaining resources.
                    del self._offer.resources[:]
                    self._offer.resources.extend(remaining)
                    break

        tasks = self._driver.method_calls["launchTasks"]
        assert len(tasks) == 3