Ejemplo n.º 1
0
    def adjust_server_state(self, servername):
        """Set server state."""
        server = self.servers.get(servername)
        if not server:
            return

        is_up = self.backend.exists(z.path.server_presence(servername))

        # Restore state as it was stored in server placement node.
        placement_node = z.path.placement(servername)
        placement_data = self.backend.get_default(placement_node)
        if not placement_data:
            placement_data = {'state': 'down', 'since': time.time()}
        state = scheduler.State(placement_data['state'])
        since = placement_data['since']
        server.set_state(state, since)

        # If presence does not exist - adjust state to down.
        if not is_up:
            server.state = scheduler.State.down
        else:
            if server.state is not scheduler.State.frozen:
                server.state = scheduler.State.up

        # If state was adjusted - record new state.
        if server.state is not state:
            self._record_server_state(servername)
Ejemplo n.º 2
0
    def adjust_server_state(self, servername):
        """Set server state."""
        server = self.servers.get(servername)
        if not server:
            return

        is_up = self.backend.exists(z.path.server_presence(servername))

        placement_node = z.path.placement(servername)

        # Restore state as it was stored in server placement node.
        state_since = self.backend.get_default(placement_node)
        if not state_since:
            state_since = {'state': 'down', 'since': time.time()}

        state = scheduler.State(state_since['state'])
        since = state_since['since']
        server.set_state(state, since)

        # If presence does not exist - adjust state to down.
        if not is_up:
            server.state = scheduler.State.down
        else:
            if server.state is not scheduler.State.frozen:
                server.state = scheduler.State.up

        # Record server state:
        state, since = server.get_state()
        self.backend.put(placement_node, {
            'state': state.value,
            'since': since
        })
Ejemplo n.º 3
0
    def adjust_server_state(self, servername, readonly=False):
        """Set server state."""
        server = self.servers.get(servername)
        if not server:
            return

        is_up = self.zkclient.exists(z.path.server_presence(servername))

        placement_node = z.path.placement(servername)

        # Restore state as it was stored in server placement node.
        #
        # zkutils.get_default return tuple if need_metadata is True, default it
        # is False, so it will return dict. pylint complains about it,
        # and it should be fixed in zkutils.
        #
        # pylint: disable=R0204
        state_since = zkutils.get_default(self.zkclient, placement_node)
        if not state_since:
            state_since = {'state': 'down', 'since': time.time()}

        state = scheduler.State(state_since['state'])
        since = state_since['since']
        server.set_state(state, since)

        # If presence does not exist - adjust state to down.
        if not is_up:
            server.state = scheduler.State.down
        else:
            if server.state is not scheduler.State.frozen:
                server.state = scheduler.State.up

        # Record server state:
        state, since = server.get_state()
        if not readonly:
            zkutils.put(self.zkclient, placement_node, {
                'state': state.value,
                'since': since
            })