PageRenderTime 58ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/deployment/configgen/main.cpp

https://github.com/emuharemagic/HPCC-Platform
C++ | 761 lines | 670 code | 73 blank | 18 comment | 140 complexity | 1822df1389d8abc606909350b4ddac4f MD5 | raw file
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include "jliball.hpp"
  14. #include "XMLTags.h"
  15. #include "configengcallback.hpp"
  16. #include "deploy.hpp"
  17. #include "build-config.h"
  18. #define STANDARD_INDIR COMPONENTFILES_DIR"/configxml"
  19. #define STANDARD_OUTDIR RUNTIME_DIR
  20. void usage()
  21. {
  22. const char* version = "1.1";
  23. printf("HPCC Systems configuration generator. version %s. Usage:\n", version);
  24. puts(" configgen -env <environment file> -ip <ip addr> [options]");
  25. puts("");
  26. puts("options: ");
  27. puts(" -env : The configuration environment to be parsed.");
  28. puts(" -ip : The ip address that will be matched against a component ");
  29. puts(" instance's ip address. If matched, configuration files are ");
  30. puts(" generated for that component");
  31. puts(" -c <component name>: Optional component name for which the ");
  32. puts(" configuration is generated. If -t is also specified, it is ");
  33. puts(" ignored");
  34. puts(" -t <component type>: Optional component type for which the ");
  35. puts(" configuration is generated. If -c is also specified, the ");
  36. puts(" component name is used");
  37. puts(" -id <input directory>: The input directory for the supporting ");
  38. puts(" xml environment files like xsd's, xsl's and ");
  39. puts(" configgencomplist.xml. If not specified, the following ");
  40. puts(" defaults are used. ");
  41. puts(" For win32, 'c:\\trunk\\initfiles\\componentfiles\\configxml'");
  42. puts(" For Linux, '"COMPONENTFILES_DIR"/configxml/'");
  43. puts(" -od <output directory>: The output directory for the generated files.");
  44. puts(" If not specified, the following defaults are used. ");
  45. puts(" For win32, '.'");
  46. puts(" For Linux, '"CONFIG_DIR"'");
  47. puts(" -ldapconfig : Generates a .ldaprc file and puts it in the specified");
  48. puts(" output directory. If output directory is not specified,");
  49. puts(" default output directory is used as mentioned in -od option");
  50. puts(" if a LDAPServer is not defined in the environment, the .ldaprc ");
  51. puts(" file is not generated. If an -ip is not provided, the first");
  52. puts(" instance of the first LDAPserver is used to generate the ");
  53. puts(" .ldaprc file");
  54. puts(" -list: Lists out the components for a specific ip in the format");
  55. puts(" componentType=componentName;config file directory. Does not ");
  56. puts(" generate any output files. If masters and slaves exist for ");
  57. puts(" a component like Roxie or thor, then only the master entry ");
  58. puts(" is returned. ");
  59. puts(" -listall: Lists out all the components specified in the environment");
  60. puts(" that have an instance defined. Does not require an ip. Does ");
  61. puts(" not generate any output files. Output is written to stdout ");
  62. puts(" in the csv format as follows");
  63. puts(" ProcessType,componentName,instanceip,instanceport,runtimedir,logdir");
  64. puts(" Missing fields will be empty.");
  65. puts(" -listdirs: Lists out any directories that need to be created during ");
  66. puts(" init time. Currently, directories for any drop zones ");
  67. puts(" with the same ip as the -ip option are returned. Format is ");
  68. puts(" one directory per line.");
  69. puts(" -listdropzones: Lists out all the dropzones defined in the environment ");
  70. puts(" Does not require an ip. Does not generate any output files.");
  71. puts(" Output is written to stdout. Format is as follows,");
  72. puts(" one entry per line");
  73. puts(" dropzone node ip,dropzone directory");
  74. puts(" -listcommondirs: Lists out all directories that are listed under ");
  75. puts(" Software/Directories section in the following format. ");
  76. puts(" <CategoryName>=<DirectoryValue>");
  77. puts(" Each directory will be listed on a new line.");
  78. puts(" -listldaps: Lists out all LDAPServer instances defined in the ");
  79. puts(" environment in the following format. If the same component");
  80. puts(" has more than one instance, it will be listed as two separate.");
  81. puts(" entries in the output");
  82. puts(" componentName,instanceip");
  83. puts(" -machines: Lists out all names or ips of machines specified in the environment");
  84. puts(" Output is written to stdout, one machine per line.");
  85. puts(" -validateonly: Validates the environment, without generating permanent ");
  86. puts(" configurations. Returns 0 if environment is valid and non zero ");
  87. puts(" in other cases. Validation errors are printed to stderr.");
  88. puts(" Ignores -od flag, if supplied.");
  89. puts(" -v : Print verbose output to stdout");
  90. puts(" -help: print out this usage.");
  91. }
  92. void deleteRecursive(const char* path)
  93. {
  94. Owned<IFile> pDir = createIFile(path);
  95. if (pDir->exists())
  96. {
  97. if (pDir->isDirectory())
  98. {
  99. Owned<IDirectoryIterator> it = pDir->directoryFiles(NULL, false, true);
  100. ForEach(*it)
  101. {
  102. StringBuffer name;
  103. it->getName(name);
  104. StringBuffer childPath(path);
  105. childPath.append(PATHSEPCHAR);
  106. childPath.append(name);
  107. deleteRecursive(childPath.str());
  108. }
  109. }
  110. pDir->remove();
  111. }
  112. }
  113. void copyDirectoryRecursive(const char *source, const char *target)
  114. {
  115. bool first = true;
  116. Owned<IDirectoryIterator> dir = createDirectoryIterator(source, "*");
  117. ForEach (*dir)
  118. {
  119. IFile &sourceFile = dir->query();
  120. if (sourceFile.isFile())
  121. {
  122. StringBuffer targetname(target);
  123. targetname.append(PATHSEPCHAR);
  124. dir->getName(targetname);
  125. OwnedIFile destFile = createIFile(targetname.str());
  126. if (first)
  127. {
  128. if (!recursiveCreateDirectory(target))
  129. throw MakeStringException(-1,"Cannot create directory %s",target);
  130. first = false;
  131. }
  132. copyFile(destFile, &sourceFile);
  133. }
  134. else if (sourceFile.isDirectory())
  135. {
  136. StringBuffer newSource(source);
  137. StringBuffer newTarget(target);
  138. newSource.append(PATHSEPCHAR);
  139. newTarget.append(PATHSEPCHAR);
  140. dir->getName(newSource);
  141. dir->getName(newTarget);
  142. copyDirectoryRecursive(newSource.str(), newTarget.str());
  143. }
  144. }
  145. }
  146. //returns temp path that ends with path sep
  147. //
  148. #ifdef _WIN32
  149. extern DWORD getLastError() { return ::GetLastError(); }
  150. void getTempPath(char* tempPath, unsigned int bufsize, const char* subdir/*=NULL*/)
  151. {
  152. ::GetTempPath(bufsize, tempPath);
  153. ::GetLongPathName(tempPath, tempPath, bufsize);
  154. if (subdir && *subdir)
  155. {
  156. const int len = strlen(tempPath);
  157. char* p = tempPath + len;
  158. strcpy(p, subdir);
  159. p += strlen(subdir);
  160. *p++ = '\\';
  161. *p = '\0';
  162. }
  163. }
  164. #else//Linux specifics follow
  165. extern DWORD getLastError() { return errno; }
  166. void getTempPath(char* tempPath, unsigned int bufsize, const char* subdir/*=NULL*/)
  167. {
  168. assert(bufsize > 5);
  169. strcpy(tempPath, "/tmp/");
  170. if (subdir && *subdir)
  171. {
  172. strcat(tempPath, subdir);
  173. strcat(tempPath, "/");
  174. }
  175. }
  176. #endif
  177. void replaceDotWithHostIp(IPropertyTree* pTree, bool verbose)
  178. {
  179. StringBuffer ip;
  180. queryHostIP().getIpText(ip);
  181. const char* attrs[] = {"@netAddress", "@roxieAddress", "@daliAddress"};
  182. StringBuffer xPath;
  183. for (int i = 0; i < sizeof(attrs)/sizeof(char*); i++)
  184. {
  185. xPath.clear().appendf(".//*[%s]", attrs[i]);
  186. Owned<IPropertyTreeIterator> iter = pTree->getElements(xPath.str());
  187. ForEach(*iter)
  188. {
  189. IPropertyTree* pComponent = &iter->query();
  190. Owned<IAttributeIterator> iAttr = pComponent->getAttributes();
  191. ForEach(*iAttr)
  192. {
  193. const char* attrName = iAttr->queryName();
  194. if (!strcmp(attrName, attrs[i]))
  195. {
  196. String sAttrVal(iAttr->queryValue());
  197. String dot(".");
  198. if (sAttrVal.equals(dot) || sAttrVal.indexOf(".:") == 0 || sAttrVal.indexOf("http://.:") == 0)
  199. {
  200. StringBuffer sb(sAttrVal);
  201. if (sAttrVal.equals(dot))
  202. sb.replaceString(".", ip.str());
  203. else
  204. {
  205. ip.append(":");
  206. sb.replaceString(".:", ip.str());
  207. ip.remove(ip.length() - 1, 1);
  208. }
  209. pComponent->setProp(attrName, sb.str());
  210. if (verbose)
  211. fprintf(stdout, "Replacing '.' with host ip '%s' for component/attribute '%s'[@'%s']\n", ip.str(), pComponent->queryName(), attrName);
  212. }
  213. }
  214. }
  215. }
  216. }
  217. }
  218. int processRequest(const char* in_cfgname, const char* out_dirname, const char* in_dirname,
  219. const char* compName, const char* compType, const char* in_filename,
  220. const char* out_filename, bool generateOutput, const char* ipAddr,
  221. bool listComps, bool verbose, bool listallComps, bool listdirs,
  222. bool listdropzones, bool listcommondirs, bool listMachines, bool validateOnly,
  223. bool listldaps, bool ldapconfig)
  224. {
  225. Owned<IPropertyTree> pEnv = createPTreeFromXMLFile(in_cfgname);
  226. short nodeIndex = 1;
  227. short index = 1;
  228. short compTypeIndex = 0;
  229. short buildSetIndex = 0;
  230. StringBuffer lastCompAdded;
  231. StringBuffer xPath("*");
  232. CConfigEngCallback callback(verbose);
  233. Owned<IPropertyTreeIterator> iter = pEnv->getElements(xPath.str());
  234. Owned<IConstEnvironment> m_pConstEnvironment;
  235. Owned<IEnvironment> m_pEnvironment;
  236. replaceDotWithHostIp(pEnv, verbose);
  237. StringBuffer envXML;
  238. toXML(pEnv, envXML);
  239. Owned<IEnvironmentFactory> factory = getEnvironmentFactory();
  240. m_pEnvironment.setown(factory->loadLocalEnvironment(envXML));
  241. m_pConstEnvironment.set(m_pEnvironment);
  242. if (validateOnly)
  243. {
  244. char tempdir[_MAX_PATH];
  245. StringBuffer sb;
  246. while(true)
  247. {
  248. sb.clear().appendf("%d", msTick());
  249. getTempPath(tempdir, sizeof(tempdir), sb.str());
  250. if (!checkDirExists(tempdir))
  251. {
  252. if (recursiveCreateDirectory(tempdir))
  253. break;
  254. }
  255. }
  256. try
  257. {
  258. Owned<IEnvDeploymentEngine> m_configGenMgr;
  259. CConfigEngCallback callback(verbose, true);
  260. m_configGenMgr.setown(createConfigGenMgr(*m_pConstEnvironment, callback, NULL, in_dirname?in_dirname:"", tempdir, NULL, NULL, NULL));
  261. m_configGenMgr->deploy(DEFLAGS_CONFIGFILES, DEBACKUP_NONE, false, false);
  262. deleteRecursive(tempdir);
  263. }
  264. catch(IException* e)
  265. {
  266. deleteRecursive(tempdir);
  267. throw e;
  268. }
  269. }
  270. else if (ldapconfig)
  271. {
  272. char tempdir[_MAX_PATH];
  273. StringBuffer sb;
  274. while(true)
  275. {
  276. sb.clear().appendf("%d", msTick());
  277. getTempPath(tempdir, sizeof(tempdir), sb.str());
  278. if (!checkDirExists(tempdir))
  279. {
  280. if (recursiveCreateDirectory(tempdir))
  281. break;
  282. }
  283. }
  284. StringBuffer out;
  285. xPath.clear().append(XML_TAG_SOFTWARE"/"XML_TAG_LDAPSERVERPROCESS);
  286. Owned<IPropertyTreeIterator> ldaps = pEnv->getElements(xPath.str());
  287. Owned<IPropertyTree> pSelComps(createPTree("SelectedComponents"));
  288. bool flag = false;
  289. ForEach(*ldaps)
  290. {
  291. IPropertyTree* ldap = &ldaps->query();
  292. IPropertyTree* inst;
  293. int count = 1;
  294. xPath.clear().appendf(XML_TAG_INSTANCE"[%d]", count);
  295. while ((inst = ldap->queryPropTree(xPath.str())) != NULL)
  296. {
  297. if (ipAddr && *ipAddr && strcmp(ipAddr, inst->queryProp(XML_ATTR_NETADDRESS)))
  298. {
  299. ldap->removeTree(inst);
  300. continue;
  301. }
  302. if (!flag)
  303. {
  304. inst->addProp(XML_ATTR_DIRECTORY, ".");
  305. sb.clear().append(tempdir).append(PATHSEPCHAR).append(ldap->queryProp(XML_ATTR_NAME));
  306. xPath.clear().appendf(XML_TAG_INSTANCE"[%d]", ++count);
  307. flag = true;
  308. }
  309. else
  310. {
  311. ldap->removeTree(inst);
  312. }
  313. }
  314. if (flag)
  315. {
  316. pSelComps->addPropTree(XML_TAG_LDAPSERVERPROCESS, createPTreeFromIPT(ldap));
  317. break;
  318. }
  319. }
  320. if (flag)
  321. {
  322. try
  323. {
  324. toXML(pEnv, envXML.clear());
  325. m_pEnvironment.setown(factory->loadLocalEnvironment(envXML));
  326. m_pConstEnvironment.set(m_pEnvironment);
  327. Owned<IEnvDeploymentEngine> m_configGenMgr;
  328. m_configGenMgr.setown(createConfigGenMgr(*m_pConstEnvironment, callback, pSelComps, in_dirname?in_dirname:"", tempdir, compName, compType, ipAddr));
  329. m_configGenMgr->deploy(DEFLAGS_CONFIGFILES, DEBACKUP_NONE, false, false);
  330. copyDirectoryRecursive(sb.str(), out_dirname);
  331. deleteRecursive(tempdir);
  332. }
  333. catch (IException* e)
  334. {
  335. deleteRecursive(tempdir);
  336. throw e;
  337. }
  338. }
  339. }
  340. else if (!listComps && !listallComps && !listdirs && !listdropzones && !listcommondirs && !listMachines
  341. && !listldaps)
  342. {
  343. Owned<IEnvDeploymentEngine> m_configGenMgr;
  344. m_configGenMgr.setown(createConfigGenMgr(*m_pConstEnvironment, callback, NULL, in_dirname?in_dirname:"", out_dirname?out_dirname:"", compName, compType, ipAddr));
  345. m_configGenMgr->deploy(DEFLAGS_CONFIGFILES, DEBACKUP_NONE, false, false);
  346. }
  347. else if (listldaps)
  348. {
  349. StringBuffer out;
  350. xPath.appendf("Software/%s/", XML_TAG_LDAPSERVERPROCESS);
  351. Owned<IPropertyTreeIterator> ldaps = pEnv->getElements(xPath.str());
  352. ForEach(*ldaps)
  353. {
  354. IPropertyTree* ldap = &ldaps->query();
  355. Owned<IPropertyTreeIterator> insts = ldap->getElements(XML_TAG_INSTANCE);
  356. ForEach(*insts)
  357. {
  358. IPropertyTree* inst = &insts->query();
  359. StringBuffer computerName(inst->queryProp(XML_ATTR_COMPUTER));
  360. xPath.clear().appendf("Hardware/Computer[@name=\"%s\"]", computerName.str());
  361. IPropertyTree* pComputer = pEnv->queryPropTree(xPath.str());
  362. if (pComputer)
  363. {
  364. const char* netAddr = pComputer->queryProp("@netAddress");
  365. out.appendf("%s,%s\n", ldap->queryProp(XML_ATTR_NAME), netAddr);
  366. }
  367. }
  368. }
  369. fprintf(stdout, "%s", out.str());
  370. }
  371. else if (listdirs || listdropzones)
  372. {
  373. StringBuffer out;
  374. xPath.clear().appendf("Software/%s", XML_TAG_DROPZONE);
  375. Owned<IPropertyTreeIterator> dropZonesInsts = pEnv->getElements(xPath.str());
  376. ForEach(*dropZonesInsts)
  377. {
  378. IPropertyTree* pDropZone = &dropZonesInsts->query();
  379. StringBuffer computerName(pDropZone->queryProp(XML_ATTR_COMPUTER));
  380. xPath.clear().appendf("Hardware/Computer[@name=\"%s\"]", computerName.str());
  381. IPropertyTree* pComputer = pEnv->queryPropTree(xPath.str());
  382. if (pComputer)
  383. {
  384. const char* netAddr = pComputer->queryProp("@netAddress");
  385. if (listdropzones)
  386. out.appendf("%s,%s\n", netAddr, pDropZone->queryProp(XML_ATTR_DIRECTORY));
  387. else if (matchDeployAddress(ipAddr, netAddr))
  388. out.appendf("%s\n", pDropZone->queryProp(XML_ATTR_DIRECTORY));
  389. }
  390. }
  391. fprintf(stdout, "%s", out.str());
  392. }
  393. else if (listcommondirs)
  394. {
  395. StringBuffer out;
  396. StringBuffer name;
  397. xPath.clear().appendf("Software/Directories/@name");
  398. name.append(pEnv->queryProp(xPath.str()));
  399. xPath.clear().appendf("Software/Directories/Category");
  400. Owned<IPropertyTreeIterator> dirInsts = pEnv->getElements(xPath.str());
  401. ForEach(*dirInsts)
  402. {
  403. IPropertyTree* pDir = &dirInsts->query();
  404. StringBuffer dirName(pDir->queryProp("@dir"));
  405. int len = strrchr(dirName.str(), '/') - dirName.str();
  406. dirName.setLength(len);
  407. if (strstr(dirName.str(), "/[INST]") || strstr(dirName.str(), "/[COMPONENT]"))
  408. continue;
  409. dirName.replaceString("[NAME]", name.str());
  410. out.appendf("%s=%s\n", pDir->queryProp(XML_ATTR_NAME), dirName.str());
  411. }
  412. fprintf(stdout, "%s", out.str());
  413. }
  414. else if (listMachines)
  415. {
  416. StringBuffer out;
  417. Owned<IPropertyTreeIterator> computers = pEnv->getElements("Hardware/Computer");
  418. ForEach(*computers)
  419. {
  420. IPropertyTree* pComputer = &computers->query();
  421. const char *netAddress = pComputer->queryProp("@netAddress");
  422. StringBuffer xpath;
  423. const char* name = pComputer->queryProp(XML_ATTR_NAME);
  424. bool isHPCCNode = false, isSqlOrLdap = false;
  425. xpath.clear().appendf(XML_TAG_SOFTWARE"/*[//"XML_ATTR_COMPUTER"='%s']", name);
  426. Owned<IPropertyTreeIterator> it = pEnv->getElements(xpath.str());
  427. ForEach(*it)
  428. {
  429. IPropertyTree* pComponent = &it->query();
  430. if (!strcmp(pComponent->queryName(), "MySQLProcess") ||
  431. !strcmp(pComponent->queryName(), "LDAPServerProcess"))
  432. isSqlOrLdap = true;
  433. else
  434. {
  435. isHPCCNode = true;
  436. break;
  437. }
  438. }
  439. if (!isHPCCNode && isSqlOrLdap)
  440. continue;
  441. out.appendf("%s,", netAddress ? netAddress : "");
  442. const char *computerType = pComputer->queryProp("@computerType");
  443. if (computerType)
  444. {
  445. xpath.clear().appendf("Hardware/ComputerType[@name='%s']", computerType);
  446. IPropertyTree *pType = pEnv->queryPropTree(xpath.str());
  447. out.appendf("%s", pType->queryProp("@opSys"));
  448. }
  449. out.newline();
  450. }
  451. fprintf(stdout, "%s", out.str());
  452. }
  453. else
  454. {
  455. StringBuffer out;
  456. Owned<IPropertyTree> pSelectedComponents = getInstances(&m_pConstEnvironment->getPTree(), compName, compType, ipAddr, true);
  457. Owned<IPropertyTreeIterator> it = pSelectedComponents->getElements("*");
  458. ForEach(*it)
  459. {
  460. IPropertyTree* pComponent = &it->query();
  461. if (listComps)
  462. {
  463. if (!strcmp(pComponent->queryProp("@buildSet"), "roxie") || !strcmp(pComponent->queryProp("@buildSet"), "thor"))
  464. {
  465. Owned<IPropertyTreeIterator> itInst = pComponent->getElements("*");
  466. ForEach(*itInst)
  467. {
  468. IPropertyTree* pInst = &itInst->query();
  469. String instName(pInst->queryName());
  470. if (!strcmp(instName.toCharArray(), "ThorMasterProcess") || instName.startsWith("RoxieServerProcess"))
  471. {
  472. out.appendf("%s=%s;%s%c%s;%s\n", pComponent->queryProp("@name"), pComponent->queryProp("@buildSet"), out_dirname, PATHSEPCHAR, pComponent->queryProp("@name"),"master");
  473. }
  474. }
  475. }
  476. else
  477. out.appendf("%s=%s;%s%c%s\n", pComponent->queryProp("@name"), pComponent->queryProp("@buildSet"), out_dirname, PATHSEPCHAR, pComponent->queryProp("@name"));
  478. }
  479. else if (listallComps)
  480. {
  481. StringBuffer netAddr;
  482. StringBuffer port;
  483. StringBuffer processName(pComponent->queryName());
  484. bool multiInstances = false;
  485. if(!strcmp(processName.str(), "ThorCluster") || !strcmp(processName.str(), "RoxieCluster"))
  486. {
  487. processName.clear();
  488. multiInstances = true;
  489. }
  490. if (pComponent->numChildren())
  491. {
  492. Owned<IPropertyTreeIterator> itComp = pComponent->getElements("*");
  493. ForEach(*itComp)
  494. {
  495. IPropertyTree* pInst = &itComp->query();
  496. if (!strcmp(pInst->queryName(), "ThorSlaveProcess") || !strcmp(pInst->queryName(), "ThorSpareProcess"))
  497. continue;
  498. netAddr.clear().append(pInst->queryProp("@netAddress"));
  499. port.clear().append(pInst->queryProp("@port"));
  500. if (multiInstances)
  501. processName.clear().append(pInst->queryName());
  502. out.appendf("%s,%s,%s,%s,%s%c%s,%s\n", processName.str(),
  503. pComponent->queryProp("@name"), netAddr.str(), port.str(),
  504. STANDARD_OUTDIR, PATHSEPCHAR, pComponent->queryProp("@name"), pComponent->queryProp("@logDir"));
  505. }
  506. }
  507. else
  508. {
  509. netAddr.clear().append(pComponent->queryProp("@netAddress"));
  510. port.clear().append(pComponent->queryProp("@port"));
  511. out.appendf("%s,%s,%s,%s,%s%c%s,%s\n", pComponent->queryName(),
  512. pComponent->queryProp("@name"), netAddr.str(), port.str(),
  513. STANDARD_OUTDIR, PATHSEPCHAR, pComponent->queryProp("@name"), pComponent->queryProp("@logDir"));
  514. }
  515. }
  516. }
  517. fprintf(stdout, "%s", out.str());
  518. }
  519. return 0;
  520. }
  521. int main(int argc, char** argv)
  522. {
  523. InitModuleObjects();
  524. Owned<IProperties> globals = createProperties(true);
  525. const char* in_filename = NULL;
  526. const char* in_cfgname = NULL;
  527. const char* out_dirname = STANDARD_OUTDIR;
  528. const char* in_dirname = STANDARD_INDIR;
  529. const char* out_filename = NULL;
  530. const char* compName = NULL;
  531. const char* compType = NULL;
  532. StringBuffer ipAddr = NULL;
  533. bool generateOutput = true;
  534. bool listComps = false;
  535. bool verbose = false;
  536. bool listallComps = false;
  537. bool listdirs = false;
  538. bool listdropzones = false;
  539. bool listcommondirs = false;
  540. bool listMachines = false;
  541. bool validateOnly = false;
  542. bool ldapconfig = false;
  543. bool listldaps = false;
  544. int i = 1;
  545. bool writeToFiles = false;
  546. int port = 80;
  547. while(i<argc)
  548. {
  549. if(stricmp(argv[i], "-help") == 0 || stricmp(argv[i], "-?") == 0)
  550. {
  551. usage();
  552. releaseAtoms();
  553. return 0;
  554. }
  555. else if (stricmp(argv[i], "-env") == 0)
  556. {
  557. i++;
  558. in_cfgname = argv[i++];
  559. }
  560. else if (stricmp(argv[i], "-c") == 0)
  561. {
  562. i++;
  563. compName = argv[i++];
  564. }
  565. else if (stricmp(argv[i], "-t") == 0)
  566. {
  567. i++;
  568. compType = argv[i++];
  569. }
  570. else if (stricmp(argv[i], "-ip") == 0)
  571. {
  572. i++;
  573. ipAddr.append(argv[i++]);
  574. if (strcmp(ipAddr, ".")!=0)
  575. {
  576. IpAddress ip(ipAddr.str());
  577. ipAddr.clear();
  578. if (ip.isLoopBack()) // assume they meant any local ip... not sure this is a good idea
  579. ipAddr.append('.');
  580. else
  581. ip.getIpText(ipAddr);
  582. }
  583. }
  584. else if(stricmp(argv[i], "-od") == 0)
  585. {
  586. i++;
  587. out_dirname = argv[i++];
  588. }
  589. else if(stricmp(argv[i], "-id") == 0)
  590. {
  591. i++;
  592. in_dirname = argv[i++];
  593. }
  594. else if (stricmp(argv[i], "-ldapconfig") == 0)
  595. {
  596. i++;
  597. ldapconfig = true;
  598. }
  599. else if (stricmp(argv[i], "-list") == 0)
  600. {
  601. i++;
  602. listComps = true;
  603. }
  604. else if (stricmp(argv[i], "-listall") == 0)
  605. {
  606. i++;
  607. listallComps = true;
  608. }
  609. else if (stricmp(argv[i], "-listdirs") == 0)
  610. {
  611. i++;
  612. listdirs = true;
  613. }
  614. else if (stricmp(argv[i], "-listdropzones") == 0)
  615. {
  616. i++;
  617. listdropzones = true;
  618. }
  619. else if (stricmp(argv[i], "-listcommondirs") == 0)
  620. {
  621. i++;
  622. listcommondirs = true;
  623. }
  624. else if (stricmp(argv[i], "-listldaps") == 0)
  625. {
  626. i++;
  627. listldaps = true;
  628. }
  629. else if (stricmp(argv[i], "-machines") == 0)
  630. {
  631. i++;
  632. listMachines = true;
  633. }
  634. else if (stricmp(argv[i], "-validateonly") == 0)
  635. {
  636. i++;
  637. validateOnly = true;
  638. }
  639. else if (stricmp(argv[i], "-v") == 0)
  640. {
  641. i++;
  642. verbose = true;
  643. }
  644. else
  645. {
  646. fprintf(stderr, "Error: unknown command line parameter: %s\n", argv[i]);
  647. usage();
  648. releaseAtoms();
  649. return 1;
  650. }
  651. }
  652. if (!in_cfgname)
  653. {
  654. fprintf(stderr, "Error: Environment xml file is required. Please specify.\n");
  655. usage();
  656. releaseAtoms();
  657. return 1;
  658. }
  659. if (ipAddr.length() == 0 && !listallComps && !validateOnly && !listcommondirs && !listMachines && !listldaps && !ldapconfig)
  660. ipAddr.clear().append("."); // Meaning match any local address
  661. try
  662. {
  663. processRequest(in_cfgname, out_dirname, in_dirname, compName,
  664. compType,in_filename, out_filename, generateOutput, ipAddr.length() ? ipAddr.str(): NULL,
  665. listComps, verbose, listallComps, listdirs, listdropzones, listcommondirs, listMachines,
  666. validateOnly, listldaps, ldapconfig);
  667. }
  668. catch(IException *excpt)
  669. {
  670. StringBuffer errMsg;
  671. fprintf(stderr, "Exception: %d:\n%s\n", excpt->errorCode(), excpt->errorMessage(errMsg).str());
  672. releaseAtoms();
  673. excpt->Release();
  674. return 1;
  675. }
  676. catch(...)
  677. {
  678. fprintf(stderr, "Unknown exception\n");
  679. releaseAtoms();
  680. return 1;
  681. }
  682. releaseAtoms();
  683. return 0;
  684. }