How to use the storage.Status function in storage

To help you get started, we’ve selected a few storage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yandex / mastermind / src / cocaine-app / infrastructure.py View on Github external
if group.couple is not None:
            return False

        if in_service and group.group_id in in_service:
            return False

        if not len(group.node_backends):
            return False

        status = status or storage.Status.INIT
        if group.status != status:
            return False

        for nb in group.node_backends:
            if nb.status != storage.Status.OK:
                return False
            if nb.node.host in locked_hosts:
                return False

        if group.type not in types:
            return False

        if max_node_backends and len(group.node_backends) > max_node_backends:
            return False

        return True
github yandex / mastermind / src / cocaine-app / jobs / move.py View on Github external
try:
                        dcs.add(nb.node.host.dc)
                    except CacheUpstreamError:
                        raise RuntimeError('Failed to get dc for host {}'.format(
                            nb.node.host))

                if ug_dc in dcs:
                    raise JobBrokenError(
                        'Cannot move group {0} to uncoupled group '
                        '{1}, because group {2} is already in dc {3}'.format(
                            self.group, self.uncoupled_group, g.group_id, ug_dc))

        src_backend = group.node_backends[0]
        if src_backend.status != storage.Status.OK:
            raise JobBrokenError('Group {0} node backend {1} status is {2}, should be {3}'.format(
                group.group_id, src_backend, src_backend.status, storage.Status.OK))
github yandex / mastermind / src / cocaine-app / planner / lrc_reserve_groups.py View on Github external
group = storage.groups[group_id]
            if group.couple is not None:
                raise ValueError(
                    'Group {} is not an uncoupled lrc group, belongs to couple {}'.format(
                        group,
                        group.couple,
                    )
                )

            if check_status:
                if group.status != storage.Status.INIT:
                    raise ValueError(
                        'Group {} will not be restored, group has status "{}", expected "{}"'.format(
                            group,
                            group.status,
                            storage.Status.INIT,
                        )
                    )

        prepared_uncoupled_group_ids = self._get_prepared_uncoupled_group_ids(group_id)

        host = infrastructure.infrastructure.get_host_by_group_id(group_id)
        if host is None:
            raise RuntimeError('Cannot determine host for group {}'.format(group_id))

        lrc_group_dc = host.dc

        host_nodes = self.host_nodes_by_dc.setdefault(
            lrc_group_dc,
            self._prepare_nodes_subset(lrc_group_dc)
        )
github yandex / mastermind / src / cocaine-app / jobs / convert_to_lrc_groupset.py View on Github external
def _wait_groupset_state_task(self, groupset):
        return tasks.WaitGroupsetStateTask.new(
            self,
            groupset=groupset,
            groupset_statuses=[storage.Status.ARCHIVED],
            sleep_period=self.groupset_creation_sleep_period,
        )
github yandex / mastermind / src / cocaine-app / balancer.py View on Github external
return [group.group_id
                    for group in infrastructure.infrastructure.get_good_uncoupled_groups(
                        including_in_service=in_service,
                        status=status)]
        except Exception:
            logger.exception('Failed to fetch uncoupled groups list')
            pass
        return []

    COUPLE_STATES = {
        'good': [storage.Status.OK],
        'full': [storage.Status.FULL],
        'frozen': [storage.Status.FROZEN],
        'bad': [storage.Status.INIT, storage.Status.BAD],
        'broken': [storage.Status.BROKEN],
        'service-stalled': [storage.Status.SERVICE_STALLED],
        'service-active': [storage.Status.SERVICE_ACTIVE],
    }

    @h.concurrent_handler
    def get_groupsets_list(self, request):
        filter = request.get('filter', {})
        return self._get_groupsets_list(filter=filter)

    def _get_groupsets_list(self, filter):
        # TODO: think on checking input filter parameters and
        # cleaning all that have a value of 'None'. This
        # should be applied to all methods that support filter-like
        # input with possible 'None' values meaning 'disable filter for this
        # parameter'.
        if filter.get('state') is not None and filter['state'] not in self.COUPLE_STATES:
            raise ValueError('Invalid state: {0}'.format(filter['state']))
github yandex / mastermind / src / cocaine-app / old_entities.py View on Github external
if storage.Status.BROKEN in statuses:
            self.status = storage.Status.BROKEN
            self.status_text = ('Group {0} has BROKEN status because '
                                'some node statuses are BROKEN'.format(self))
            return self.status

        if self.type == self.TYPE_DATA:
            # perform checks for common data group
            status = self.update_storage_group_status()
            if status:
                return status
        elif self.type == self.TYPE_CACHE:
            pass

        if storage.Status.RO in statuses:
            self.status = storage.Status.RO
            self.status_text = ('Group {0} is in Read-Only state because '
                                'there is RO node backends'.format(self))

            service_status = self.meta.get('service', {}).get('status')
            if service_status == storage.Status.MIGRATING:
                if self.active_job and self.meta['service']['job_id'] == self.active_job['id']:
                    self.status = storage.Status.MIGRATING
                    self.status_text = ('Group {0} is migrating, job id is {1}'.format(
                        self, self.meta['service']['job_id']))
                else:
                    self.status = storage.Status.BAD
                    self.status_text = ('Group {0} has no active job, but marked as '
                                        'migrating by job id {1}'.format(
                                            self, self.meta['service']['job_id']))
github yandex / mastermind / src / cocaine-app / balancer.py View on Github external
for group in infrastructure.infrastructure.get_good_uncoupled_groups(
                        including_in_service=in_service,
                        status=status)]
        except Exception:
            logger.exception('Failed to fetch uncoupled groups list')
            pass
        return []

    COUPLE_STATES = {
        'good': [storage.Status.OK],
        'full': [storage.Status.FULL],
        'frozen': [storage.Status.FROZEN],
        'bad': [storage.Status.INIT, storage.Status.BAD],
        'broken': [storage.Status.BROKEN],
        'service-stalled': [storage.Status.SERVICE_STALLED],
        'service-active': [storage.Status.SERVICE_ACTIVE],
    }

    @h.concurrent_handler
    def get_groupsets_list(self, request):
        filter = request.get('filter', {})
        return self._get_groupsets_list(filter=filter)

    def _get_groupsets_list(self, filter):
        # TODO: think on checking input filter parameters and
        # cleaning all that have a value of 'None'. This
        # should be applied to all methods that support filter-like
        # input with possible 'None' values meaning 'disable filter for this
        # parameter'.
        if filter.get('state') is not None and filter['state'] not in self.COUPLE_STATES:
            raise ValueError('Invalid state: {0}'.format(filter['state']))
github yandex / mastermind / src / cocaine-app / old_entities.py View on Github external
self, self.meta['service']['job_id']))
                else:
                    self.status = storage.Status.BAD
                    self.status_text = ('Group {0} has no active job, but marked as '
                                        'migrating by job id {1}'.format(
                                            self, self.meta['service']['job_id']))

            return self.status

        if not all(st == storage.Status.OK for st in statuses):
            self.status = storage.Status.BAD
            self.status_text = ('Group {0} is in Bad state because '
                                'some node statuses are not OK'.format(self))
            return self.status

        self.status = storage.Status.COUPLED
        self.status_text = 'Group {0} is OK'.format(self)

        return self.status
github yandex / mastermind / src / cocaine-app / old_entities.py View on Github external
'couple was not created'.format(self))
            return self.status

        if not self.couple.check_groups(self.meta['couple']):
            self.status = storage.Status.BAD
            self.status_text = ('Group {} is in Bad state because couple check fails'.format(self))
            return self.status

        if not self.meta.get('namespace'):
            self.status = storage.Status.BAD
            self.status_text = ('Group {0} is in Bad state because '
                                'no namespace has been assigned to it'.format(self))
            return self.status

        if self.group_id not in self.meta['couple']:
            self.status = storage.Status.BROKEN
            self.status_text = ('Group {0} is in BROKEN state because '
                                'its group id is missing from coupling info'.format(self))
            return self.status
github yandex / mastermind / src / cocaine-app / old_entities.py View on Github external
def __init__(self, node, backend_id):

        self.node = node
        self.backend_id = backend_id

        self.fs = None
        self.group = None
        self.stat = None

        self.disabled = False
        self.start_ts = 0
        self.stalled = False

        self.read_only = False
        self.base_path = None
        self.status = storage.Status.INIT
        self.status_text = "Node %s is not inititalized yet" % (self.__str__())