def assign_threads(self, request: AllocateThreadsRequest) -> AllocateResponse: self.__call_meta = {} cpu = request.get_cpu() cpu_usage = request.get_cpu_usage() workloads = request.get_workloads() workload_id = request.get_workload_id() curr_ids_per_workload = cpu.get_workload_ids_to_thread_ids() return AllocateResponse( self.__compute_allocation(cpu, workload_id, workloads, curr_ids_per_workload, cpu_usage, True), self.get_name(), self.__call_meta)
def free_threads(self, request: AllocateThreadsRequest) -> AllocateResponse: self.__call_meta = {} cpu = request.get_cpu() cpu_usage = request.get_cpu_usage() workloads = request.get_workloads() workload_id = request.get_workload_id() curr_ids_per_workload = cpu.get_workload_ids_to_thread_ids() if workload_id not in curr_ids_per_workload: raise Exception("workload_id=`%s` is not placed on the instance. Cannot free it." % (workload_id,)) return AllocateResponse( self.__compute_allocation(cpu, workload_id, workloads, curr_ids_per_workload, cpu_usage, False), self.get_name(), self.__call_meta)