1 /** 2 * Copyright 2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_CCSRC_PS_CORE_LEADER_SCALER_H_ 18 #define MINDSPORE_CCSRC_PS_CORE_LEADER_SCALER_H_ 19 20 #include <cstdlib> 21 #include <iostream> 22 #include <memory> 23 #include <string> 24 #include <vector> 25 26 #include "ps/core/communicator/tcp_client.h" 27 #include "ps/core/node_manager.h" 28 #include "ps/core/node.h" 29 #include "ps/core/communicator/request_process_result_code.h" 30 #include "ps/constants.h" 31 #include "utils/log_adapter.h" 32 33 namespace mindspore { 34 namespace ps { 35 namespace core { 36 // The class helps scheduler node to do scale out/in operation for the cluster. 37 class LeaderScaler { 38 public: LeaderScaler(Node * const node)39 explicit LeaderScaler(Node *const node) : node_(node) {} 40 ~LeaderScaler() = default; 41 42 // When the scheduler receives the scale out message, it will send this message to the workers and servers. 43 void ScaleOutAsync(const std::shared_ptr<TcpClient> &client, const NodeManager &manager); 44 // When the scheduler receives the scale in message, it will send this message to the workers and servers. 45 void ScaleInAsync(const std::shared_ptr<TcpClient> &client, const NodeManager &manager, bool is_node_scale_in); 46 47 private: 48 // The node_ will only be instantiated with scheduler node. 49 Node *const node_; 50 }; 51 } // namespace core 52 } // namespace ps 53 } // namespace mindspore 54 #endif // MINDSPORE_CCSRC_PS_CORE_LEADER_SCALER_H_ 55