Beispiel #1
0
    async def getMaintenances(
        self, filter: MaintenancesFilter
    ) -> MaintenanceDefinitionResponse:
        mnts = [mnt for _, mnt in self._maintenances_by_id.items()]
        mnts = self._filter_mnts(mnts, filter)

        return MaintenanceDefinitionResponse(maintenances=mnts)
Beispiel #2
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])
Beispiel #3
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])
Beispiel #4
0
    async def removeMaintenances(
            self,
            request: RemoveMaintenancesRequest) -> RemoveMaintenancesResponse:
        mnts = [mnt for _, mnt in self._maintenances_by_id.items()]
        if request.filter:
            mnts = self._filter_mnts(mnts, request.filter)

        if not mnts:
            raise MaintenanceMatchError()

        for mnt in mnts:
            del self._maintenances_by_id[mnt.group_id]

        return MaintenanceDefinitionResponse(maintenances=mnts)