Пример #1
0
    def Discovery_RPC(self, request):
        assert request.IsInitialized()

        timer = Gauge.get('server.DiscoveryRPC.latency')
        timer.start_timer()
        logger.info('%s handling Discovery RPC from %s' %
                    (self.server_id, request.client_id))
        response = DiscoveryResponse()

        # Sets the master_bns field in the response if there is a current
        # master.
        master = self.job.get_master()

        if master:
            response.master_bns = master.get_server_id()
        else:
            # We don't know who the master is.
            Counter.get('server.incomplete_discovery_response').inc()

        # Goes through the resource ids in the request and sets the
        # safe capacity for every resource that has a safe capacity
        # configured.
        for r in request.resource_id:
            t = global_config.find_resource_template(r)

            if t and t.HasField('safe_capacity'):
                safe = response.safe_capacity.add()
                safe.resource_id = r
                safe.safe_capacity = t.safe_capacity

        assert response.IsInitialized()

        timer.stop_timer()

        return response
Пример #2
0
  def find_resource(self, resource_id):
    # This can only happen in the master!
    assert self.server.is_master()

    # Lineair scan through all the resources in the state to find this
    # resource.
    for r in self.wrapped_state.resource:
      if r.resource_id == resource_id:
        return r

    # The resource was not found. Find the resource template which
    # describes this resource.
    t = global_config.find_resource_template(resource_id)

    # No template found.
    if not t:
      logger.error(
          'Cannot create server state entry for resource %s (no template)' %
          resource_id)
      return None

    # We got the template. Now create a new blank resource entry in the server
    # state.
    logger.info(
        '%s creating new resource %s' %
        (self.get_server_id(), resource_id))
    r = self.wrapped_state.resource.add()
    r.template.CopyFrom(t)
    r.resource_id = resource_id

    # Calculates the time this resource went out of learning mode.
    # Note: This time may be in the past.
    r.learning_mode_expiry_time = self.wrapped_state.election_victory_time + \
      AlgorithmImpl.create(t, self.wrapped_state.server_level).get_max_lease_duration()

    if r.learning_mode_expiry_time > clock.get_time():
      logger.info(
          '%s putting resource %s in learning mode until T=%d' %
          (self.get_server_id(), resource_id,
           r.learning_mode_expiry_time))
      # Schedules an action to log a message when this resource leaves
      # learning mode.
      scheduler.add_absolute(
          r.learning_mode_expiry_time + 1, _LeaveLearningMode(),
          (self.get_server_id(), r.resource_id))

    # Note: At this point this server has not capacity lease for this resource.
    # It is up to the caller to deal with this.
    assert r.IsInitialized()

    return r
Пример #3
0
    def find_resource(self, resource_id):
        # This can only happen in the master!
        assert self.server.is_master()

        # Lineair scan through all the resources in the state to find this
        # resource.
        for r in self.wrapped_state.resource:
            if r.resource_id == resource_id:
                return r

        # The resource was not found. Find the resource template which
        # describes this resource.
        t = global_config.find_resource_template(resource_id)

        # No template found.
        if not t:
            logger.error(
                'Cannot create server state entry for resource %s (no template)'
                % resource_id)
            return None

        # We got the template. Now create a new blank resource entry in the server
        # state.
        logger.info('%s creating new resource %s' %
                    (self.get_server_id(), resource_id))
        r = self.wrapped_state.resource.add()
        r.template.CopyFrom(t)
        r.resource_id = resource_id

        # Calculates the time this resource went out of learning mode.
        # Note: This time may be in the past.
        r.learning_mode_expiry_time = self.wrapped_state.election_victory_time + \
          AlgorithmImpl.create(t, self.wrapped_state.server_level).get_max_lease_duration()

        if r.learning_mode_expiry_time > clock.get_time():
            logger.info('%s putting resource %s in learning mode until T=%d' %
                        (self.get_server_id(), resource_id,
                         r.learning_mode_expiry_time))
            # Schedules an action to log a message when this resource leaves
            # learning mode.
            scheduler.add_absolute(r.learning_mode_expiry_time + 1,
                                   _LeaveLearningMode(),
                                   (self.get_server_id(), r.resource_id))

        # Note: At this point this server has not capacity lease for this resource.
        # It is up to the caller to deal with this.
        assert r.IsInitialized()

        return r
Пример #4
0
  def Discovery_RPC(self, request):
    assert request.IsInitialized()

    timer = Gauge.get('server.DiscoveryRPC.latency')
    timer.start_timer()
    logger.info(
        '%s handling Discovery RPC from %s' %
        (self.server_id, request.client_id))
    response = DiscoveryResponse()

    # Sets the master_bns field in the response if there is a current
    # master.
    master = self.job.get_master()

    if master:
      response.master_bns = master.get_server_id()
    else:
      # We don't know who the master is.
      Counter.get('server.incomplete_discovery_response').inc()

    # Goes through the resource ids in the request and sets the
    # safe capacity for every resource that has a safe capacity
    # configured.
    for r in request.resource_id:
      t = global_config.find_resource_template(r)

      if t and t.HasField('safe_capacity'):
        safe = response.safe_capacity.add()
        safe.resource_id = r
        safe.safe_capacity = t.safe_capacity

    assert response.IsInitialized()

    timer.stop_timer()

    return response