コード例 #1
0
    async def applyMaintenance(
            self,
            request: MaintenanceDefinition) -> MaintenanceDefinitionResponse:
        # TODO: ungroup if group == False
        shards = []
        for sh in request.shards:
            if sh.shard_index == ALL_SHARDS:
                r = range(self.shards_per_storage_node)
            else:
                r = range(sh.shard_index, sh.shard_index + 1)

            assert sh.node.node_index is not None
            nc = self._nc_by_node_index[sh.node.node_index]
            for shard_index in r:
                shards.append(
                    ShardID(
                        node=NodeID(
                            node_index=nc.node_index,
                            name=nc.name,
                            address=nc.data_address,
                        ),
                        shard_index=shard_index,
                    ))

        shards = tuple(
            sorted(shards, key=lambda s: (s.node.node_index, s.shard_index)))

        seq_nodes = []
        for n in request.sequencer_nodes:
            assert n.node_index is not None
            nc = self._nc_by_node_index[n.node_index]
            seq_nodes.append(
                NodeID(node_index=nc.node_index,
                       name=nc.name,
                       address=nc.data_address))

        mnt = MaintenanceDefinition(
            shards=shards,
            shard_target_state=request.shard_target_state,
            sequencer_nodes=seq_nodes,
            sequencer_target_state=request.sequencer_target_state,
            user=request.user,
            reason=request.reason,
            extras=request.extras,
            skip_safety_checks=request.skip_safety_checks,
            force_restore_rebuilding=request.force_restore_rebuilding,
            group=request.group,
            ttl_seconds=request.ttl_seconds,
            allow_passive_drains=request.allow_passive_drains,
            group_id=gen_word(8),
            last_check_impact_result=None,
            expires_on=1000 *
            (int(datetime.now().timestamp()) + request.ttl_seconds)
            if request.ttl_seconds else None,
            created_on=1000 * int(datetime.now().timestamp()),
            progress=MaintenanceProgress.IN_PROGRESS,
        )
        assert mnt.group_id is not None
        self._maintenances_by_id[mnt.group_id] = mnt
        return MaintenanceDefinitionResponse(maintenances=[mnt])
コード例 #2
0
async def apply_maintenance(
    client: AdminAPI,
    node_ids: Optional[Collection[NodeID]] = None,
    shards: Optional[Collection[ShardID]] = None,
    shard_target_state: Optional[
        ShardOperationalState
    ] = ShardOperationalState.MAY_DISAPPEAR,
    sequencer_nodes: Optional[Collection[NodeID]] = None,
    group: Optional[bool] = True,
    ttl: Optional[timedelta] = None,
    user: Optional[str] = None,
    reason: Optional[str] = None,
    extras: Optional[Mapping[str, str]] = None,
    skip_safety_checks: Optional[bool] = False,
    allow_passive_drains: Optional[bool] = False,
) -> Collection[MaintenanceDefinition]:
    """
    Applies maintenance to MaintenanceManager.
    If `nodes` argument is specified, they're treated as shards and as
        sequencers simultaneously.

    Can return multiple maintenances if group==False.
    """
    node_ids = set(node_ids or [])
    shards = set(shards or [])
    sequencer_nodes = set(sequencer_nodes or []).union(node_ids)

    if ttl is None:
        ttl = timedelta(seconds=0)

    if user is None:
        user = "******"

    if reason is None:
        reason = "Not Specified"

    if extras is None:
        extras = {}

    shards = shards.union({ShardID(node=n, shard_index=-1) for n in node_ids})
    shards = _recombine_shards(shards)

    req = MaintenanceDefinition(
        shards=list(shards),
        shard_target_state=shard_target_state,
        sequencer_nodes=[n for n in sequencer_nodes],
        sequencer_target_state=SequencingState.DISABLED,
        user=user,
        reason=reason,
        extras=extras,
        skip_safety_checks=skip_safety_checks,
        group=group,
        ttl_seconds=int(ttl.total_seconds()),
        allow_passive_drains=allow_passive_drains,
    )
    resp: MaintenanceDefinitionResponse = await admin_api.apply_maintenance(
        client=client, req=req
    )
    return resp.maintenances
コード例 #3
0
def create_maintenance_definition(
    node_ids: Optional[Collection[NodeID]] = None,
    shards: Optional[Collection[ShardID]] = None,
    shard_target_state: Optional[
        ShardOperationalState
    ] = ShardOperationalState.MAY_DISAPPEAR,
    sequencer_nodes: Optional[Collection[NodeID]] = None,
    group: Optional[bool] = True,
    ttl: Optional[timedelta] = None,
    user: Optional[str] = None,
    reason: Optional[str] = None,
    extras: Optional[Mapping[str, str]] = None,
    skip_safety_checks: Optional[bool] = False,
    allow_passive_drains: Optional[bool] = False,
    force_restore_rebuilding: Optional[bool] = False,
    priority: MaintenancePriority = MaintenancePriority.MEDIUM,
    skip_capacity_checks: Optional[bool] = False,
) -> MaintenanceDefinition:
    """
    Shorthand when creating maintenance definitions.

    If `nodes` argument is specified, they're treated as shards and as
        sequencers simultaneously.
    """
    node_ids = set(node_ids or [])
    shards = set(shards or [])
    sequencer_nodes = set(sequencer_nodes or []).union(node_ids)

    if ttl is None:
        ttl = timedelta(seconds=0)

    if user is None:
        user = "******"

    if reason is None:
        reason = "Not Specified"

    if extras is None:
        extras = {}

    shards = shards.union({ShardID(node=n, shard_index=ALL_SHARDS) for n in node_ids})
    shards = _recombine_shards(shards)

    return MaintenanceDefinition(
        shards=list(shards),
        shard_target_state=shard_target_state,
        sequencer_nodes=list(sequencer_nodes),
        sequencer_target_state=SequencingState.DISABLED,
        user=user,
        reason=reason,
        extras=extras,
        skip_safety_checks=skip_safety_checks,
        skip_capacity_checks=skip_capacity_checks,
        group=group,
        ttl_seconds=int(ttl.total_seconds()),
        allow_passive_drains=allow_passive_drains,
        force_restore_rebuilding=force_restore_rebuilding,
        priority=priority,
    )
コード例 #4
0
    async def applyMaintenance(
        self, request: MaintenanceDefinition
    ) -> MaintenanceDefinitionResponse:
        # TODO: ungroup if group == False
        shards = []
        for sh in request.shards:
            if sh.shard_index == -1:
                # TODO: make it unwrap
                pass
            else:
                assert sh.node.node_index is not None
                # pyre-fixme[6]: Expected `int` for 1st param but got `Optional[int]`.
                nc = self._nc_by_node_index[sh.node.node_index]
                shards.append(
                    ShardID(
                        node=NodeID(
                            node_index=nc.node_index,
                            name=nc.name,
                            address=nc.data_address,
                        ),
                        shard_index=sh.shard_index,
                    )
                )

        seq_nodes = []
        for n in request.sequencer_nodes:
            assert n.node_index is not None
            # pyre-fixme[6]: Expected `int` for 1st param but got `Optional[int]`.
            nc = self._nc_by_node_index[n.node_index]
            seq_nodes.append(
                NodeID(node_index=nc.node_index, name=nc.name, address=nc.data_address)
            )

        mnt = MaintenanceDefinition(
            shards=shards,
            shard_target_state=request.shard_target_state,
            sequencer_nodes=seq_nodes,
            sequencer_target_state=request.sequencer_target_state,
            user=request.user,
            reason=request.reason,
            extras=request.extras,
            skip_safety_checks=request.skip_safety_checks,
            force_restore_rebuilding=request.force_restore_rebuilding,
            group=request.group,
            ttl_seconds=request.ttl_seconds,
            allow_passive_drains=request.allow_passive_drains,
            group_id=gen_word(8),
            last_check_impact_result=None,
            expires_on=1000 * (int(datetime.now().timestamp()) + request.ttl_seconds)
            if request.ttl_seconds
            else None,
            created_on=1000 * int(datetime.now().timestamp()),
        )
        assert mnt.group_id is not None
        # pyre-fixme[6]: Expected `str` for 1st param but got `Optional[str]`.
        self._maintenances_by_id[mnt.group_id] = mnt
        return MaintenanceDefinitionResponse(maintenances=[mnt])