/** * Tencent is pleased to support the open source community by making Tars available. * * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. * * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * https://opensource.org/licenses/BSD-3-Clause * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ #include "NodeServer.h" #include "servant/Communicator.h" #include "util/tc_option.h" #include "util/tc_file.h" #include "util/tc_config.h" #include using namespace std; using namespace tars; NodeServer g_app; TC_Config* g_pconf; static string outfill(const string& s, char c = ' ', int n = 29) { return (s + string(abs(n - (int)s.length()), c)); } bool getConfig(const string &sLocator,const string &sRegistryObj,string &sNodeId,string &sLocalIp, string &sConfigFile, bool bCloseCout) { try { //string sLocalIp; string sResult; string sTemplate; TC_Config tConf; CommunicatorFactory::getInstance()->getCommunicator()->setProperty("locator",sLocator); RegistryPrx pRegistryPrx = CommunicatorFactory::getInstance()->getCommunicator()->stringToProxy(sRegistryObj); if( sLocalIp.empty() && pRegistryPrx->getClientIp(sLocalIp) != 0) { cerr<<"cannot get localip: " <getNodeTemplate(sNodeId,sTemplate); if(TC_Common::trim(sTemplate) == "" ) { cerr << "cannot get node Template nodeid:"<"); if (sCloseCoutValue == "1") { sTemplate = TC_Common::replace(sTemplate, "closecout=1", "closecout=0"); tConf.parseString(sTemplate); } else if (sCloseCoutValue.empty()) { map m; m["closecout"] = "0"; tConf.insertDomainParam("/tars/application/server", m,true); } else { cerr << "failed to set closeout value" << endl; } } string sConfigPath = TC_File::extractFilePath(sConfigFile); if(!TC_File::makeDirRecursive( sConfigPath )) { cerr<<"cannot create dir: " <"]; ServantPrx prx = CommunicatorFactory::getInstance()->getCommunicator()->stringToProxy(nodeObj); prx->tars_ping(); } void parseConfig(int argc, char *argv[]) { TC_Option tOp;//consider tOp.decode(argc, argv); if (tOp.hasParam("nodeversion")) { cout << "Node:" << TARS_VERSION << "_" << NODE_VERSION << endl; exit(0); } if (tOp.hasParam("monitor")) { try { string configFile = tOp.getValue("config"); monitorNode(configFile); } catch (exception &ex) { cout << "failed:" << ex.what() << endl; exit(-1); } exit(0); return; } string sLocator = tOp.getValue("locator"); string sNodeId = tOp.getValue("nodeid"); string sConfigFile = tOp.getValue("config"); string sRegistryObj = tOp.getValue("registryObj"); string sLocalIp = tOp.getValue("localip"); if(sConfigFile == "") { cerr << endl; cerr <<"start server with locator config, for example: "< mOp = tOp.getMulti(); for(map::const_iterator it = mOp.begin(); it != mOp.end(); ++it) { cout << outfill( it->first)<< it->second << endl; } } int main( int argc, char* argv[] ) { try { TC_Common::daemon(); parseConfig(argc,argv); g_pconf = &g_app.getConfig(); g_app.main( argc, argv ); g_app.waitForShutdown(); } catch ( exception& ex ) { cout<< ex.what() << endl; } catch ( ... ) { cout<< "main unknow exception cathed" << endl; } return 0; }