def rebalance(self, request: AllocateRequest) -> AllocateResponse: url = "{}/rebalance".format(self.__url) body = request.to_dict() log.debug("url: {}, body: {}".format(url, body)) response = requests.put(url, json=body, headers=self.__headers, timeout=self.__timeout) log.debug("rebalance response code: {}".format(response.status_code)) if response.status_code == 200: return deserialize_response(response.headers, response.json()) raise CpuAllocationException("Failed to rebalance threads: {}".format(response.text))
def rebalance(self, request: AllocateRequest) -> AllocateResponse: url = "{}/rebalance".format(self.__url) body = request.to_dict() try: log.info("rebalancing threads remotely") response = requests.put(url, json=body, headers=self.__headers, timeout=self.__timeout) except requests.exceptions.Timeout as e: log.info("rebalancing threads remotely timed out") raise e if response.status_code == 200: log.info("rebalanced threads remotely") return deserialize_response(response.headers, response.json()) log.error("failed to rebalance threads remotely with status code: %d", response.status_code) raise CpuAllocationException("Failed to rebalance threads: {}".format( response.text))
def get_cpu_event(request: AllocateRequest, response: AllocateResponse): return { "request": request.to_dict(), "response": response.to_dict(), }