ecl-package.cpp 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  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 <stdio.h>
  14. #include "jlog.hpp"
  15. #include "jfile.hpp"
  16. #include "jargv.hpp"
  17. #include "build-config.h"
  18. #include "ws_packageprocess_esp.ipp"
  19. #include "eclcmd.hpp"
  20. #include "eclcmd_common.hpp"
  21. #include "eclcmd_core.hpp"
  22. //=========================================================================================
  23. IClientWsPackageProcess *getWsPackageSoapService(const char *server, const char *port, const char *username, const char *password)
  24. {
  25. if(server == NULL)
  26. throw MakeStringException(-1, "Server url not specified");
  27. VStringBuffer url("http://%s:%s/WsPackageProcess", server, port);
  28. IClientWsPackageProcess *packageProcessClient = createWsPackageProcessClient();
  29. packageProcessClient->addServiceUrl(url.str());
  30. packageProcessClient->setUsernameToken(username, password, NULL);
  31. return packageProcessClient;
  32. }
  33. class EclCmdPackageActivate : public EclCmdCommon
  34. {
  35. public:
  36. EclCmdPackageActivate() : optGlobalScope(false)
  37. {
  38. }
  39. virtual bool parseCommandLineOptions(ArgvIterator &iter)
  40. {
  41. if (iter.done())
  42. {
  43. usage();
  44. return false;
  45. }
  46. for (; !iter.done(); iter.next())
  47. {
  48. const char *arg = iter.query();
  49. if (*arg!='-')
  50. {
  51. if (!optTarget.length())
  52. optTarget.set(arg);
  53. else if (!optPackageMap.length())
  54. optPackageMap.set(arg);
  55. else
  56. {
  57. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  58. return false;
  59. }
  60. continue;
  61. }
  62. if (iter.matchFlag(optGlobalScope, ECLOPT_GLOBAL_SCOPE))
  63. continue;
  64. if (EclCmdCommon::matchCommandLineOption(iter, true)!=EclCmdOptionMatch)
  65. return false;
  66. }
  67. return true;
  68. }
  69. virtual bool finalizeOptions(IProperties *globals)
  70. {
  71. if (!EclCmdCommon::finalizeOptions(globals))
  72. return false;
  73. if (optTarget.isEmpty())
  74. {
  75. fprintf(stdout, "\n ... Missing target name\n\n");
  76. usage();
  77. return false;
  78. }
  79. if (optPackageMap.isEmpty())
  80. {
  81. fprintf(stdout, "\n ... Missing package map name\n\n");
  82. usage();
  83. return false;
  84. }
  85. if (optProcess.isEmpty())
  86. optProcess.set("*");
  87. return true;
  88. }
  89. virtual int processCMD()
  90. {
  91. Owned<IClientWsPackageProcess> packageProcessClient = createCmdClient(WsPackageProcess, *this);
  92. Owned<IClientActivatePackageRequest> request = packageProcessClient->createActivatePackageRequest();
  93. request->setTarget(optTarget);
  94. request->setPackageMap(optPackageMap);
  95. request->setProcess(optProcess);
  96. request->setGlobalScope(optGlobalScope);
  97. Owned<IClientActivatePackageResponse> resp = packageProcessClient->ActivatePackage(request);
  98. if (resp->getExceptions().ordinality())
  99. outputMultiExceptions(resp->getExceptions());
  100. return 0;
  101. }
  102. virtual void usage()
  103. {
  104. fputs("\nUsage:\n"
  105. "\n"
  106. "The 'activate' command will deactivate the currently activate packagemap \n"
  107. "and make the specified packagemap the one that is used.\n"
  108. "\n"
  109. "ecl packagemap activate <target> <packagemap>\n"
  110. " Options:\n"
  111. " <target> Name of target containing package map to activate\n"
  112. " <packagemap> Packagemap to activate\n"
  113. " --global-scope The specified packagemap can be shared across multiple targets\n",
  114. stdout);
  115. EclCmdCommon::usage();
  116. }
  117. private:
  118. StringAttr optTarget;
  119. StringAttr optPackageMap;
  120. StringAttr optProcess;
  121. bool optGlobalScope;
  122. };
  123. class EclCmdPackageDeActivate : public EclCmdCommon
  124. {
  125. public:
  126. EclCmdPackageDeActivate() : optGlobalScope(false)
  127. {
  128. }
  129. virtual bool parseCommandLineOptions(ArgvIterator &iter)
  130. {
  131. if (iter.done())
  132. {
  133. usage();
  134. return false;
  135. }
  136. for (; !iter.done(); iter.next())
  137. {
  138. const char *arg = iter.query();
  139. if (*arg!='-')
  140. {
  141. if (!optTarget.length())
  142. optTarget.set(arg);
  143. else if (!optPackageMap.length())
  144. optPackageMap.set(arg);
  145. else
  146. {
  147. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  148. return false;
  149. }
  150. continue;
  151. }
  152. if (iter.matchFlag(optGlobalScope, ECLOPT_GLOBAL_SCOPE))
  153. continue;
  154. if (EclCmdCommon::matchCommandLineOption(iter, true)!=EclCmdOptionMatch)
  155. return false;
  156. }
  157. return true;
  158. }
  159. virtual bool finalizeOptions(IProperties *globals)
  160. {
  161. if (!EclCmdCommon::finalizeOptions(globals))
  162. return false;
  163. if (optTarget.isEmpty())
  164. {
  165. fprintf(stdout, "\n ... Missing target name\n\n");
  166. usage();
  167. return false;
  168. }
  169. if (optPackageMap.isEmpty())
  170. {
  171. fprintf(stdout, "\n ... Missing package map name\n\n");
  172. usage();
  173. return false;
  174. }
  175. if (optProcess.isEmpty())
  176. optProcess.set("*");
  177. return true;
  178. }
  179. virtual int processCMD()
  180. {
  181. Owned<IClientWsPackageProcess> packageProcessClient = createCmdClient(WsPackageProcess, *this);
  182. Owned<IClientDeActivatePackageRequest> request = packageProcessClient->createDeActivatePackageRequest();
  183. request->setTarget(optTarget);
  184. request->setPackageMap(optPackageMap);
  185. request->setProcess(optProcess);
  186. request->setGlobalScope(optGlobalScope);
  187. Owned<IClientDeActivatePackageResponse> resp = packageProcessClient->DeActivatePackage(request);
  188. if (resp->getExceptions().ordinality())
  189. outputMultiExceptions(resp->getExceptions());
  190. return 0;
  191. }
  192. virtual void usage()
  193. {
  194. fputs("\nUsage:\n"
  195. "\n"
  196. "The 'deactivate' command will deactivate the currently activate packagemap \n"
  197. "\n"
  198. "ecl packagemap deactivate <target> <packagemap>\n"
  199. " Options:\n"
  200. " <target> Name of target containing package map to activate\n"
  201. " <packagemap> Packagemap to activate\n"
  202. " --global-scope The specified packagemap can be shared across multiple targets\n",
  203. stdout);
  204. EclCmdCommon::usage();
  205. }
  206. private:
  207. StringAttr optTarget;
  208. StringAttr optPackageMap;
  209. StringAttr optProcess;
  210. bool optGlobalScope;
  211. };
  212. class EclCmdPackageList : public EclCmdCommon
  213. {
  214. public:
  215. EclCmdPackageList()
  216. {
  217. }
  218. virtual bool parseCommandLineOptions(ArgvIterator &iter)
  219. {
  220. for (; !iter.done(); iter.next())
  221. {
  222. const char *arg = iter.query();
  223. if (*arg!='-')
  224. {
  225. if (optTarget.isEmpty())
  226. optTarget.set(arg);
  227. else
  228. {
  229. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  230. return false;
  231. }
  232. continue;
  233. }
  234. if (EclCmdCommon::matchCommandLineOption(iter, true)!=EclCmdOptionMatch)
  235. return false;
  236. }
  237. return true;
  238. }
  239. virtual bool finalizeOptions(IProperties *globals)
  240. {
  241. if (!EclCmdCommon::finalizeOptions(globals))
  242. return false;
  243. return true;
  244. }
  245. virtual int processCMD()
  246. {
  247. Owned<IClientWsPackageProcess> packageProcessClient = createCmdClient(WsPackageProcess, *this);
  248. Owned<IClientListPackageRequest> request = packageProcessClient->createListPackageRequest();
  249. request->setTarget(optTarget);
  250. request->setProcess("*");
  251. Owned<IClientListPackageResponse> resp = packageProcessClient->ListPackage(request);
  252. if (resp->getExceptions().ordinality())
  253. outputMultiExceptions(resp->getExceptions());
  254. else
  255. {
  256. IArrayOf<IConstPackageListMapData> &pkgMapInfo = resp->getPkgListMapData();
  257. unsigned int num = pkgMapInfo.ordinality();
  258. for (unsigned i=0; i<num; i++)
  259. {
  260. IConstPackageListMapData& req = pkgMapInfo.item(i);
  261. printf("\nPackage Id = %s active = %d\n", req.getId(), req.getActive());
  262. IArrayOf<IConstPackageListData> &pkgInfo = req.getPkgListData();
  263. unsigned int numPkgs = pkgInfo.ordinality();
  264. for (unsigned int j = 0; j <numPkgs; j++)
  265. {
  266. IConstPackageListData& req = pkgInfo.item(j);
  267. const char *id = req.getId();
  268. const char *queries = req.getQueries();
  269. if (queries && *queries)
  270. printf("\t\tname = %s queries = %s\n", id, queries);
  271. else
  272. printf("\t\tname = %s\n", id);
  273. }
  274. }
  275. }
  276. return 0;
  277. }
  278. virtual void usage()
  279. {
  280. fputs("\nUsage:\n"
  281. "\n"
  282. "The 'list' command will list package map information for the target cluster \n"
  283. "\n"
  284. "ecl packagemap list <target> \n"
  285. " Options:\n"
  286. " <target> Name of target containing package map to use when retrieving list of package maps\n",
  287. stdout);
  288. EclCmdCommon::usage();
  289. }
  290. private:
  291. StringAttr optTarget;
  292. };
  293. class EclCmdPackageInfo: public EclCmdCommon
  294. {
  295. public:
  296. EclCmdPackageInfo()
  297. {
  298. }
  299. virtual bool parseCommandLineOptions(ArgvIterator &iter)
  300. {
  301. if (iter.done())
  302. {
  303. usage();
  304. return false;
  305. }
  306. for (; !iter.done(); iter.next())
  307. {
  308. const char *arg = iter.query();
  309. if (*arg!='-')
  310. {
  311. if (optTarget.isEmpty())
  312. optTarget.set(arg);
  313. else
  314. {
  315. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  316. return false;
  317. }
  318. continue;
  319. }
  320. if (EclCmdCommon::matchCommandLineOption(iter, true)!=EclCmdOptionMatch)
  321. return false;
  322. }
  323. return true;
  324. }
  325. virtual bool finalizeOptions(IProperties *globals)
  326. {
  327. if (!EclCmdCommon::finalizeOptions(globals))
  328. return false;
  329. return true;
  330. }
  331. virtual int processCMD()
  332. {
  333. Owned<IClientWsPackageProcess> packageProcessClient = createCmdClient(WsPackageProcess, *this);
  334. Owned<IClientGetPackageRequest> request = packageProcessClient->createGetPackageRequest();
  335. request->setTarget(optTarget);
  336. request->setProcess("*");
  337. Owned<IClientGetPackageResponse> resp = packageProcessClient->GetPackage(request);
  338. if (resp->getExceptions().ordinality())
  339. outputMultiExceptions(resp->getExceptions());
  340. else
  341. printf("%s", resp->getInfo());
  342. return 0;
  343. }
  344. virtual void usage()
  345. {
  346. fputs("\nUsage:\n"
  347. "\n"
  348. "The 'info' command will return the contents of the active package map information for the target cluster \n"
  349. "\n"
  350. "ecl packagemap info <target> \n"
  351. " Options:\n"
  352. " <target> Name of the target to use when retrieving active package map information\n",
  353. stdout);
  354. EclCmdCommon::usage();
  355. }
  356. private:
  357. StringAttr optTarget;
  358. };
  359. class EclCmdPackageDelete : public EclCmdCommon
  360. {
  361. public:
  362. EclCmdPackageDelete()
  363. {
  364. }
  365. virtual bool parseCommandLineOptions(ArgvIterator &iter)
  366. {
  367. if (iter.done())
  368. {
  369. usage();
  370. return false;
  371. }
  372. for (; !iter.done(); iter.next())
  373. {
  374. const char *arg = iter.query();
  375. if (*arg!='-')
  376. {
  377. if (!optTarget.length())
  378. optTarget.set(arg);
  379. else if (!optPackageMap.length())
  380. optPackageMap.set(arg);
  381. else
  382. {
  383. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  384. return false;
  385. }
  386. continue;
  387. }
  388. if (iter.matchFlag(optGlobalScope, ECLOPT_GLOBAL_SCOPE))
  389. continue;
  390. if (EclCmdCommon::matchCommandLineOption(iter, true)!=EclCmdOptionMatch)
  391. return false;
  392. }
  393. return true;
  394. }
  395. virtual bool finalizeOptions(IProperties *globals)
  396. {
  397. if (!EclCmdCommon::finalizeOptions(globals))
  398. {
  399. usage();
  400. return false;
  401. }
  402. StringBuffer err;
  403. if (optPackageMap.isEmpty())
  404. err.append("\n ... Missing package map name\n\n");
  405. else if (optTarget.isEmpty())
  406. err.append("\n ... Specify a target cluster name\n\n");
  407. if (err.length())
  408. {
  409. fprintf(stdout, "%s", err.str());
  410. usage();
  411. return false;
  412. }
  413. if (optProcess.isEmpty())
  414. optProcess.set("*");
  415. return true;
  416. }
  417. virtual int processCMD()
  418. {
  419. fprintf(stdout, "\n ... deleting package map %s now\n\n", optPackageMap.sget());
  420. Owned<IClientWsPackageProcess> packageProcessClient = createCmdClient(WsPackageProcess, *this);
  421. Owned<IClientDeletePackageRequest> request = packageProcessClient->createDeletePackageRequest();
  422. request->setTarget(optTarget);
  423. request->setPackageMap(optPackageMap);
  424. request->setProcess(optProcess);
  425. request->setGlobalScope(optGlobalScope);
  426. Owned<IClientDeletePackageResponse> resp = packageProcessClient->DeletePackage(request);
  427. if (resp->getExceptions().ordinality())
  428. outputMultiExceptions(resp->getExceptions());
  429. else
  430. printf("Successfully deleted package %s\n", optPackageMap.get());
  431. return 0;
  432. }
  433. virtual void usage()
  434. {
  435. fputs("\nUsage:\n"
  436. "\n"
  437. "The 'delete' command will delete the package map from the target cluster \n"
  438. "\n"
  439. "ecl packagemap delete <target> <packagemap>\n"
  440. " Options:\n"
  441. " <target> Name of the target to use \n"
  442. " <packagemap> Name of the package map to delete\n"
  443. " --global-scope The specified packagemap is sharable across multiple targets\n",
  444. stdout);
  445. EclCmdCommon::usage();
  446. }
  447. private:
  448. StringAttr optPackageMap;
  449. StringAttr optTarget;
  450. StringAttr optProcess;
  451. bool optGlobalScope;
  452. };
  453. class EclCmdPackageAdd : public EclCmdCommon
  454. {
  455. public:
  456. EclCmdPackageAdd() : optActivate(false), optOverWrite(false), optGlobalScope(false), optNoForeign(false)
  457. {
  458. }
  459. virtual bool parseCommandLineOptions(ArgvIterator &iter)
  460. {
  461. if (iter.done())
  462. {
  463. usage();
  464. return false;
  465. }
  466. for (; !iter.done(); iter.next())
  467. {
  468. const char *arg = iter.query();
  469. if (*arg!='-')
  470. {
  471. if (optTarget.isEmpty())
  472. optTarget.set(arg);
  473. else if (optFileName.isEmpty())
  474. optFileName.set(arg);
  475. else
  476. {
  477. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  478. return false;
  479. }
  480. continue;
  481. }
  482. if (iter.matchOption(optPackageMapId, ECLOPT_PMID))
  483. continue;
  484. if (iter.matchOption(optDaliIP, ECLOPT_DALIIP))
  485. continue;
  486. if (iter.matchOption(optSourceProcess, ECLOPT_SOURCE_PROCESS))
  487. continue;
  488. if (iter.matchFlag(optActivate, ECLOPT_ACTIVATE)||iter.matchFlag(optActivate, ECLOPT_ACTIVATE_S))
  489. continue;
  490. if (iter.matchFlag(optOverWrite, ECLOPT_OVERWRITE)||iter.matchFlag(optOverWrite, ECLOPT_OVERWRITE_S))
  491. continue;
  492. if (iter.matchFlag(optGlobalScope, ECLOPT_GLOBAL_SCOPE))
  493. continue;
  494. if (iter.matchFlag(optNoForeign, ECLOPT_NO_FOREIGN))
  495. continue;
  496. if (EclCmdCommon::matchCommandLineOption(iter, true)!=EclCmdOptionMatch)
  497. return false;
  498. }
  499. return true;
  500. }
  501. virtual bool finalizeOptions(IProperties *globals)
  502. {
  503. if (!EclCmdCommon::finalizeOptions(globals))
  504. {
  505. usage();
  506. return false;
  507. }
  508. StringBuffer err;
  509. if (optFileName.isEmpty())
  510. err.append("\n ... Missing package file name\n\n");
  511. else if (optTarget.isEmpty())
  512. err.append("\n ... Specify a cluster name\n\n");
  513. if (err.length())
  514. {
  515. fprintf(stdout, "%s", err.str());
  516. usage();
  517. return false;
  518. }
  519. if (optProcess.isEmpty())
  520. optProcess.set("*");
  521. if (optPackageMapId.isEmpty())
  522. {
  523. StringBuffer name;
  524. splitFilename(optFileName.get(), NULL, NULL, &name, &name);
  525. optPackageMapId.set(name.str());
  526. }
  527. optPackageMapId.toLowerCase();
  528. return true;
  529. }
  530. virtual int processCMD()
  531. {
  532. Owned<IClientWsPackageProcess> packageProcessClient = createCmdClient(WsPackageProcess, *this);
  533. StringBuffer pkgInfo;
  534. pkgInfo.loadFile(optFileName);
  535. fprintf(stdout, "\n ... adding package map %s now\n\n", optFileName.sget());
  536. Owned<IClientAddPackageRequest> request = packageProcessClient->createAddPackageRequest();
  537. request->setActivate(optActivate);
  538. request->setInfo(pkgInfo);
  539. request->setTarget(optTarget);
  540. request->setPackageMap(optPackageMapId);
  541. request->setProcess(optProcess);
  542. request->setDaliIp(optDaliIP);
  543. request->setOverWrite(optOverWrite);
  544. request->setGlobalScope(optGlobalScope);
  545. request->setSourceProcess(optSourceProcess);
  546. request->setAllowForeignFiles(!optNoForeign);
  547. Owned<IClientAddPackageResponse> resp = packageProcessClient->AddPackage(request);
  548. if (resp->getExceptions().ordinality())
  549. outputMultiExceptions(resp->getExceptions());
  550. StringArray &notFound = resp->getFilesNotFound();
  551. if (notFound.length())
  552. {
  553. fputs("\nFiles defined in package but not found in DFS:\n", stderr);
  554. ForEachItemIn(i, notFound)
  555. fprintf(stderr, " %s\n", notFound.item(i));
  556. fputs("\n", stderr);
  557. }
  558. return 0;
  559. }
  560. virtual void usage()
  561. {
  562. fputs("\nUsage:\n"
  563. "\n"
  564. "The 'add' command will add the package map information to dali \n"
  565. "\n"
  566. "ecl packagemap add [options] <target> <filename>\n"
  567. " Options:\n"
  568. " -O, --overwrite Overwrite existing information\n"
  569. " -A, --activate Activate the package information\n"
  570. " --daliip=<ip> IP of the remote dali to use for logical file lookups\n"
  571. " --pmid Identifier of package map - defaults to filename if not specified\n"
  572. " --global-scope The specified packagemap can be shared across multiple targets\n"
  573. " --source-process Process cluster to copy files from\n"
  574. " --no-foreign Fail if foreign files are used in packagemap\n"
  575. " <target> Name of target to use when adding package map information\n"
  576. " <filename> Name of file containing package map information\n",
  577. stdout);
  578. EclCmdCommon::usage();
  579. }
  580. private:
  581. StringBuffer pkgInfo;
  582. StringAttr optFileName;
  583. StringAttr optTarget;
  584. StringAttr optProcess;
  585. StringAttr optDaliIP;
  586. StringAttr optPackageMapId;
  587. StringAttr optSourceProcess;
  588. bool optActivate;
  589. bool optOverWrite;
  590. bool optGlobalScope;
  591. bool optNoForeign;
  592. };
  593. class EclCmdPackageValidate : public EclCmdCommon
  594. {
  595. public:
  596. EclCmdPackageValidate() : optValidateActive(false), optCheckDFS(false), optGlobalScope(false)
  597. {
  598. }
  599. virtual bool parseCommandLineOptions(ArgvIterator &iter)
  600. {
  601. if (iter.done())
  602. {
  603. usage();
  604. return false;
  605. }
  606. for (; !iter.done(); iter.next())
  607. {
  608. const char *arg = iter.query();
  609. if (*arg!='-')
  610. {
  611. if (optTarget.isEmpty())
  612. optTarget.set(arg);
  613. else if (optFileName.isEmpty())
  614. optFileName.set(arg);
  615. else
  616. {
  617. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  618. return false;
  619. }
  620. continue;
  621. }
  622. if (iter.matchFlag(optValidateActive, ECLOPT_ACTIVE))
  623. continue;
  624. if (iter.matchFlag(optCheckDFS, ECLOPT_CHECK_DFS))
  625. continue;
  626. if (iter.matchOption(optPMID, ECLOPT_PMID) || iter.matchOption(optPMID, ECLOPT_PMID_S))
  627. continue;
  628. if (iter.matchOption(optQueryId, ECLOPT_QUERYID))
  629. continue;
  630. if (iter.matchFlag(optGlobalScope, ECLOPT_GLOBAL_SCOPE))
  631. continue;
  632. if (EclCmdCommon::matchCommandLineOption(iter, true)!=EclCmdOptionMatch)
  633. return false;
  634. }
  635. return true;
  636. }
  637. virtual bool finalizeOptions(IProperties *globals)
  638. {
  639. if (!EclCmdCommon::finalizeOptions(globals))
  640. {
  641. usage();
  642. return false;
  643. }
  644. StringBuffer err;
  645. int pcount=0;
  646. if (optFileName.length())
  647. pcount++;
  648. if (optPMID.length())
  649. pcount++;
  650. if (optValidateActive)
  651. pcount++;
  652. if (pcount==0)
  653. err.append("\n ... Package file name, --pmid, or --active required\n\n");
  654. else if (pcount > 1)
  655. err.append("\n ... Package file name, --pmid, and --active are mutually exclusive\n\n");
  656. if (optTarget.isEmpty())
  657. err.append("\n ... Specify a cluster name\n\n");
  658. if (err.length())
  659. {
  660. fprintf(stdout, "%s", err.str());
  661. usage();
  662. return false;
  663. }
  664. return true;
  665. }
  666. virtual int processCMD()
  667. {
  668. Owned<IClientWsPackageProcess> packageProcessClient = getWsPackageSoapService(optServer, optPort, optUsername, optPassword);
  669. Owned<IClientValidatePackageRequest> request = packageProcessClient->createValidatePackageRequest();
  670. if (optFileName.length())
  671. {
  672. StringBuffer pkgInfo;
  673. pkgInfo.loadFile(optFileName);
  674. fprintf(stdout, "\nvalidating packagemap file %s\n\n", optFileName.sget());
  675. request->setInfo(pkgInfo);
  676. }
  677. request->setActive(optValidateActive);
  678. request->setPMID(optPMID);
  679. request->setTarget(optTarget);
  680. request->setQueryIdToVerify(optQueryId);
  681. request->setCheckDFS(optCheckDFS);
  682. request->setGlobalScope(optGlobalScope);
  683. bool validateMessages = false;
  684. Owned<IClientValidatePackageResponse> resp = packageProcessClient->ValidatePackage(request);
  685. if (resp->getExceptions().ordinality()>0)
  686. {
  687. validateMessages = true;
  688. outputMultiExceptions(resp->getExceptions());
  689. }
  690. StringArray &errors = resp->getErrors();
  691. if (errors.ordinality()>0)
  692. {
  693. validateMessages = true;
  694. fputs(" Error(s):\n", stderr);
  695. ForEachItemIn(i, errors)
  696. fprintf(stderr, " %s\n", errors.item(i));
  697. }
  698. StringArray &warnings = resp->getWarnings();
  699. if (warnings.ordinality()>0)
  700. {
  701. validateMessages = true;
  702. fputs(" Warning(s):\n", stderr);
  703. ForEachItemIn(i, warnings)
  704. fprintf(stderr, " %s\n", warnings.item(i));
  705. }
  706. StringArray &unmatchedQueries = resp->getQueries().getUnmatched();
  707. if (unmatchedQueries.ordinality()>0)
  708. {
  709. validateMessages = true;
  710. fputs("\n Queries without matching package:\n", stderr);
  711. ForEachItemIn(i, unmatchedQueries)
  712. fprintf(stderr, " %s\n", unmatchedQueries.item(i));
  713. }
  714. StringArray &unusedPackages = resp->getPackages().getUnmatched();
  715. if (unusedPackages.ordinality()>0)
  716. {
  717. validateMessages = true;
  718. fputs("\n Packages without matching queries:\n", stderr);
  719. ForEachItemIn(i, unusedPackages)
  720. fprintf(stderr, " %s\n", unusedPackages.item(i));
  721. }
  722. StringArray &unusedFiles = resp->getFiles().getUnmatched();
  723. if (unusedFiles.ordinality()>0)
  724. {
  725. validateMessages = true;
  726. fputs("\n Files without matching package definitions:\n", stderr);
  727. ForEachItemIn(i, unusedFiles)
  728. fprintf(stderr, " %s\n", unusedFiles.item(i));
  729. }
  730. StringArray &notInDFS = resp->getFiles().getNotInDFS();
  731. if (notInDFS.ordinality()>0)
  732. {
  733. validateMessages = true;
  734. fputs("\n Packagemap SubFiles not found in DFS:\n", stderr);
  735. ForEachItemIn(i, notInDFS)
  736. fprintf(stderr, " %s\n", notInDFS.item(i));
  737. }
  738. if (!validateMessages)
  739. fputs(" Validation was successful\n", stdout);
  740. return 0;
  741. }
  742. virtual void usage()
  743. {
  744. fputs("\nUsage:\n"
  745. "\n"
  746. "The 'validate' command will checkout the contents of the package map file \n"
  747. "\n"
  748. "ecl packagemap validate <target> <filename>\n"
  749. " Options:\n"
  750. " <target> Name of target to use when validating package map information\n"
  751. " <filename> Name of file containing package map information\n"
  752. " --active Validate the active packagemap\n"
  753. " --check-dfs Verify that subfiles exist in DFS\n"
  754. " -pm, --pmid Identifier of packagemap to validate\n"
  755. " --global-scope The specified packagemap can be shared across multiple targets\n",
  756. stdout);
  757. EclCmdCommon::usage();
  758. }
  759. private:
  760. StringAttr optFileName;
  761. StringAttr optTarget;
  762. StringAttr optPMID;
  763. StringAttr optQueryId;
  764. bool optValidateActive;
  765. bool optCheckDFS;
  766. bool optGlobalScope;
  767. };
  768. class EclCmdPackageQueryFiles : public EclCmdCommon
  769. {
  770. public:
  771. EclCmdPackageQueryFiles() : optGlobalScope(false)
  772. {
  773. }
  774. virtual bool parseCommandLineOptions(ArgvIterator &iter)
  775. {
  776. if (iter.done())
  777. {
  778. usage();
  779. return false;
  780. }
  781. for (; !iter.done(); iter.next())
  782. {
  783. const char *arg = iter.query();
  784. if (*arg!='-')
  785. {
  786. if (optTarget.isEmpty())
  787. optTarget.set(arg);
  788. else if (optQueryId.isEmpty())
  789. optQueryId.set(arg);
  790. else
  791. {
  792. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  793. return false;
  794. }
  795. continue;
  796. }
  797. if (iter.matchOption(optPMID, ECLOPT_PMID) || iter.matchOption(optPMID, ECLOPT_PMID_S))
  798. continue;
  799. if (iter.matchFlag(optGlobalScope, ECLOPT_GLOBAL_SCOPE))
  800. continue;
  801. if (EclCmdCommon::matchCommandLineOption(iter, true)!=EclCmdOptionMatch)
  802. return false;
  803. }
  804. return true;
  805. }
  806. virtual bool finalizeOptions(IProperties *globals)
  807. {
  808. if (!EclCmdCommon::finalizeOptions(globals))
  809. {
  810. usage();
  811. return false;
  812. }
  813. StringBuffer err;
  814. if (optTarget.isEmpty())
  815. err.append("\n ... A target cluster must be specified\n\n");
  816. if (optQueryId.isEmpty())
  817. err.append("\n ... A query must be specified\n\n");
  818. if (err.length())
  819. {
  820. fprintf(stdout, "%s", err.str());
  821. usage();
  822. return false;
  823. }
  824. return true;
  825. }
  826. virtual int processCMD()
  827. {
  828. Owned<IClientWsPackageProcess> packageProcessClient = getWsPackageSoapService(optServer, optPort, optUsername, optPassword);
  829. Owned<IClientGetQueryFileMappingRequest> request = packageProcessClient->createGetQueryFileMappingRequest();
  830. request->setTarget(optTarget);
  831. request->setQueryName(optQueryId);
  832. request->setPMID(optPMID);
  833. request->setGlobalScope(optGlobalScope);
  834. Owned<IClientGetQueryFileMappingResponse> resp = packageProcessClient->GetQueryFileMapping(request);
  835. if (resp->getExceptions().ordinality()>0)
  836. outputMultiExceptions(resp->getExceptions());
  837. StringArray &unmappedFiles = resp->getUnmappedFiles();
  838. if (!unmappedFiles.ordinality())
  839. fputs("No undefined files found.\n", stderr);
  840. else
  841. {
  842. fputs("Files not defined in PackageMap:\n", stderr);
  843. ForEachItemIn(i, unmappedFiles)
  844. fprintf(stderr, " %s\n", unmappedFiles.item(i));
  845. }
  846. IArrayOf<IConstSuperFile> &superFiles = resp->getSuperFiles();
  847. if (!superFiles.ordinality())
  848. fputs("\nNo matching SuperFiles found in PackageMap.\n", stderr);
  849. else
  850. {
  851. fputs("\nSuperFiles defined in PackageMap:\n", stderr);
  852. ForEachItemIn(i, superFiles)
  853. {
  854. IConstSuperFile &super = superFiles.item(i);
  855. fprintf(stderr, " %s\n", super.getName());
  856. StringArray &subfiles = super.getSubFiles();
  857. if (subfiles.ordinality()>0)
  858. {
  859. ForEachItemIn(sbi, subfiles)
  860. fprintf(stderr, " > %s\n", subfiles.item(sbi));
  861. }
  862. }
  863. }
  864. return 0;
  865. }
  866. virtual void usage()
  867. {
  868. fputs("\nUsage:\n"
  869. "\n"
  870. "The 'query-files' command will list the files referenced by a query, showing if/how they\n"
  871. "are mapped as SuperFiles in the active packagemap. --pmid option allows an inactive\n"
  872. "packagemap to be used instead.\n"
  873. "\n"
  874. "ecl packagemap query-files <target> <queryid>\n"
  875. " Options:\n"
  876. " <target> Name of target to use when validating package map information\n"
  877. " <queryid> Name of query to get file mappings for\n"
  878. " -pm, --pmid Optional id of packagemap to validate, defaults to active\n"
  879. " --global-scope The specified packagemap can be shared across multiple targets\n",
  880. stdout);
  881. EclCmdCommon::usage();
  882. }
  883. private:
  884. StringAttr optTarget;
  885. StringAttr optQueryId;
  886. StringAttr optPMID;
  887. bool optGlobalScope;
  888. };
  889. IEclCommand *createPackageSubCommand(const char *cmdname)
  890. {
  891. if (!cmdname || !*cmdname)
  892. return NULL;
  893. if (strieq(cmdname, "add"))
  894. return new EclCmdPackageAdd();
  895. if (strieq(cmdname, "delete"))
  896. return new EclCmdPackageDelete();
  897. if (strieq(cmdname, "activate"))
  898. return new EclCmdPackageActivate();
  899. if (strieq(cmdname, "deactivate"))
  900. return new EclCmdPackageDeActivate();
  901. if (strieq(cmdname, "info"))
  902. return new EclCmdPackageInfo();
  903. if (strieq(cmdname, "list"))
  904. return new EclCmdPackageList();
  905. if (strieq(cmdname, "validate"))
  906. return new EclCmdPackageValidate();
  907. if (strieq(cmdname, "query-files"))
  908. return new EclCmdPackageQueryFiles();
  909. return NULL;
  910. }
  911. //=========================================================================================
  912. class PackageCMDShell : public EclCMDShell
  913. {
  914. public:
  915. PackageCMDShell(int argc, const char *argv[], EclCommandFactory _factory, const char *_version)
  916. : EclCMDShell(argc, argv, _factory, _version)
  917. {
  918. }
  919. virtual void usage()
  920. {
  921. fprintf(stdout,"\nUsage:\n\n"
  922. "ecl packagemap <command> [command options]\n\n"
  923. " packagemap Commands:\n"
  924. " add Add a package map to the environment\n"
  925. " delete Delete a package map\n"
  926. " activate Activate a package map\n"
  927. " deactivate Deactivate a package map (package map will not get loaded)\n"
  928. " list List loaded package map names\n"
  929. " info Return active package map information\n"
  930. " validate Validate information in the package map file \n"
  931. " query-files Show files used by a query and if/how they are mapped\n"
  932. );
  933. }
  934. };
  935. static int doMain(int argc, const char *argv[])
  936. {
  937. PackageCMDShell processor(argc, argv, createPackageSubCommand, BUILD_TAG);
  938. return processor.run();
  939. }
  940. int main(int argc, const char *argv[])
  941. {
  942. InitModuleObjects();
  943. queryStderrLogMsgHandler()->setMessageFields(0);
  944. unsigned exitCode = doMain(argc, argv);
  945. releaseAtoms();
  946. exit(exitCode);
  947. }