Example #1
0
    def shrink(self, removal_ids):
        LOG.debug("Shrinking cluster %s.", self.id)

        self.validate_cluster_available()

        cluster_info = self.db_info
        cluster_info.update(task_status=ClusterTasks.SHRINKING_CLUSTER)
        try:
            removal_insts = [
                inst_models.Instance.load(self.context, inst_id)
                for inst_id in removal_ids
            ]
            node_ids = [
                Cluster.get_guest(instance).get_node_id_for_removal()
                for instance in removal_insts
            ]
            if None in node_ids:
                raise TroveError(
                    _("Some nodes cannot be removed (check slots)"))

            all_instances = (inst_models.DBInstance.find_all(
                cluster_id=self.id, deleted=False).all())
            remain_insts = [
                inst_models.Instance.load(self.context, inst.id)
                for inst in all_instances if inst.id not in removal_ids
            ]
            map(lambda x: Cluster.get_guest(x).remove_nodes(node_ids),
                remain_insts)
            map(lambda x: x.update_db(cluster_id=None), removal_insts)
            map(inst_models.Instance.delete, removal_insts)

            return RedisCluster(self.context, cluster_info, self.ds,
                                self.ds_version)
        finally:
            cluster_info.update(task_status=ClusterTasks.NONE)
Example #2
0
File: api.py Project: vmazur/trove
    def shrink(self, removal_ids):
        LOG.debug("Shrinking cluster %s.", self.id)

        self.validate_cluster_available()

        cluster_info = self.db_info
        cluster_info.update(task_status=ClusterTasks.SHRINKING_CLUSTER)
        try:
            removal_insts = [inst_models.Instance.load(self.context, inst_id)
                             for inst_id in removal_ids]
            node_ids = [Cluster.get_guest(instance).get_node_id_for_removal()
                        for instance in removal_insts]
            if None in node_ids:
                raise TroveError(_("Some nodes cannot be removed (check slots)"
                                   ))

            all_instances = (
                inst_models.DBInstance.find_all(cluster_id=self.id,
                                                deleted=False).all())
            remain_insts = [inst_models.Instance.load(self.context, inst.id)
                            for inst in all_instances
                            if inst.id not in removal_ids]
            map(lambda x: Cluster.get_guest(x).remove_nodes(node_ids),
                remain_insts)
            map(lambda x: x.update_db(cluster_id=None), removal_insts)
            map(inst_models.Instance.delete, removal_insts)

            return RedisCluster(self.context, cluster_info,
                                self.ds, self.ds_version)
        finally:
            cluster_info.update(task_status=ClusterTasks.NONE)
Example #3
0
    def shrink(self, removal_ids):
        LOG.debug("Shrinking cluster %s.", self.id)

        self.validate_cluster_available()

        cluster_info = self.db_info
        cluster_info.update(task_status=ClusterTasks.SHRINKING_CLUSTER)
        try:
            removal_insts = [
                inst_models.Instance.load(self.context, inst_id)
                for inst_id in removal_ids
            ]
            node_ids = []
            error_ids = []
            for instance in removal_insts:
                node_id = Cluster.get_guest(instance).get_node_id_for_removal()
                if node_id:
                    node_ids.append(node_id)
                else:
                    error_ids.append(instance.id)
            if error_ids:
                raise exception.ClusterShrinkInstanceInUse(
                    id=error_ids,
                    reason="Nodes cannot be removed. Check slots.")

            all_instances = (inst_models.DBInstance.find_all(
                cluster_id=self.id, deleted=False).all())
            remain_insts = [
                inst_models.Instance.load(self.context, inst.id)
                for inst in all_instances if inst.id not in removal_ids
            ]

            for inst in remain_insts:
                guest = Cluster.get_guest(inst)
                guest.remove_nodes(node_ids)
            for inst in removal_insts:
                inst.update_db(cluster_id=None)
            for inst in removal_insts:
                inst_models.Instance.delete(inst)

            return RedisCluster(self.context, cluster_info, self.ds,
                                self.ds_version)
        finally:
            cluster_info.update(task_status=ClusterTasks.NONE)
Example #4
0
    def shrink(self, removal_ids):
        LOG.debug("Shrinking cluster %s.", self.id)

        self.validate_cluster_available()

        cluster_info = self.db_info
        cluster_info.update(task_status=ClusterTasks.SHRINKING_CLUSTER)
        try:
            removal_insts = [inst_models.Instance.load(self.context, inst_id)
                             for inst_id in removal_ids]
            node_ids = []
            error_ids = []
            for instance in removal_insts:
                node_id = Cluster.get_guest(instance).get_node_id_for_removal()
                if node_id:
                    node_ids.append(node_id)
                else:
                    error_ids.append(instance.id)
            if error_ids:
                raise exception.ClusterShrinkInstanceInUse(
                    id=error_ids,
                    reason="Nodes cannot be removed. Check slots."
                )

            all_instances = (
                inst_models.DBInstance.find_all(cluster_id=self.id,
                                                deleted=False).all())
            remain_insts = [inst_models.Instance.load(self.context, inst.id)
                            for inst in all_instances
                            if inst.id not in removal_ids]

            for inst in remain_insts:
                guest = Cluster.get_guest(inst)
                guest.remove_nodes(node_ids)
            for inst in removal_insts:
                inst.update_db(cluster_id=None)
            for inst in removal_insts:
                inst_models.Instance.delete(inst)

            return RedisCluster(self.context, cluster_info,
                                self.ds, self.ds_version)
        finally:
            cluster_info.update(task_status=ClusterTasks.NONE)
    def test_controller_action_no_strategy(self,
                                           mock_cluster_load):

        body = {'do_stuff2': {}}
        tenant_id = Mock()
        context = trove_testtools.TroveTestContext(self)
        cluster_id = Mock()

        req = Mock()
        req.environ = MagicMock()
        req.environ.get = Mock(return_value=context)

        db_info = DBCluster(ClusterTasks.NONE, id=cluster_id,
                            tenant_id=tenant_id)
        cluster = Cluster(context, db_info, datastore='test_ds',
                          datastore_version='test_dsv')
        mock_cluster_load.return_value = cluster

        self.assertRaisesRegexp(exception.TroveError,
                                'Action do_stuff2 not supported',
                                self.controller.action, req,
                                body, tenant_id, cluster_id)