ecl-package.cpp 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657
  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 "ws_packageprocess_esp.ipp"
  18. #include "eclcmd.hpp"
  19. #include "eclcmd_common.hpp"
  20. #include "eclcmd_core.hpp"
  21. //=========================================================================================
  22. IClientWsPackageProcess *getWsPackageSoapService(const char *server, const char *port, const char *username, const char *password)
  23. {
  24. if(server == NULL)
  25. throw MakeStringException(-1, "Server url not specified");
  26. VStringBuffer url("http://%s:%s/WsPackageProcess", server, port);
  27. IClientWsPackageProcess *packageProcessClient = createWsPackageProcessClient();
  28. packageProcessClient->addServiceUrl(url.str());
  29. packageProcessClient->setUsernameToken(username, password, NULL);
  30. return packageProcessClient;
  31. }
  32. class EclCmdPackageActivate : public EclCmdCommon
  33. {
  34. public:
  35. EclCmdPackageActivate() : optGlobalScope(false)
  36. {
  37. }
  38. virtual eclCmdOptionMatchIndicator parseCommandLineOptions(ArgvIterator &iter)
  39. {
  40. if (iter.done())
  41. return EclCmdOptionNoMatch;
  42. for (; !iter.done(); iter.next())
  43. {
  44. const char *arg = iter.query();
  45. if (*arg!='-')
  46. {
  47. if (!optTarget.length())
  48. optTarget.set(arg);
  49. else if (!optPackageMap.length())
  50. optPackageMap.set(arg);
  51. else
  52. {
  53. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  54. return EclCmdOptionNoMatch;
  55. }
  56. continue;
  57. }
  58. if (iter.matchFlag(optGlobalScope, ECLOPT_GLOBAL_SCOPE))
  59. continue;
  60. eclCmdOptionMatchIndicator ind = EclCmdCommon::matchCommandLineOption(iter, true);
  61. if (ind != EclCmdOptionMatch)
  62. return ind;
  63. }
  64. return EclCmdOptionMatch;
  65. }
  66. virtual bool finalizeOptions(IProperties *globals)
  67. {
  68. if (!EclCmdCommon::finalizeOptions(globals))
  69. return false;
  70. if (optTarget.isEmpty())
  71. {
  72. fprintf(stdout, "\n ... Missing target name\n");
  73. return false;
  74. }
  75. if (optPackageMap.isEmpty())
  76. {
  77. fprintf(stdout, "\n ... Missing package map name\n");
  78. return false;
  79. }
  80. if (optProcess.isEmpty())
  81. optProcess.set("*");
  82. return true;
  83. }
  84. virtual int processCMD()
  85. {
  86. Owned<IClientWsPackageProcess> packageProcessClient = createCmdClient(WsPackageProcess, *this);
  87. Owned<IClientActivatePackageRequest> request = packageProcessClient->createActivatePackageRequest();
  88. setCmdRequestTimeouts(request->rpc(), 0, optWaitConnectMs, optWaitReadSec);
  89. request->setTarget(optTarget);
  90. request->setPackageMap(optPackageMap);
  91. request->setProcess(optProcess);
  92. request->setGlobalScope(optGlobalScope);
  93. Owned<IClientActivatePackageResponse> resp = packageProcessClient->ActivatePackage(request);
  94. return outputMultiExceptionsEx(resp->getExceptions());
  95. }
  96. virtual void usage()
  97. {
  98. fputs("\nUsage:\n"
  99. "\n"
  100. "The 'activate' command will deactivate the currently activate packagemap \n"
  101. "and make the specified packagemap the one that is used.\n"
  102. "\n"
  103. "ecl packagemap activate <target> <packagemap>\n"
  104. " Options:\n"
  105. " <target> Name of target containing package map to activate\n"
  106. " <packagemap> Packagemap to activate\n"
  107. " --global-scope The specified packagemap can be shared across multiple targets\n",
  108. stdout);
  109. EclCmdCommon::usage();
  110. }
  111. private:
  112. StringAttr optTarget;
  113. StringAttr optPackageMap;
  114. StringAttr optProcess;
  115. bool optGlobalScope;
  116. };
  117. class EclCmdPackageDeActivate : public EclCmdCommon
  118. {
  119. public:
  120. EclCmdPackageDeActivate() : optGlobalScope(false)
  121. {
  122. }
  123. virtual eclCmdOptionMatchIndicator parseCommandLineOptions(ArgvIterator &iter)
  124. {
  125. if (iter.done())
  126. return EclCmdOptionNoMatch;
  127. for (; !iter.done(); iter.next())
  128. {
  129. const char *arg = iter.query();
  130. if (*arg!='-')
  131. {
  132. if (!optTarget.length())
  133. optTarget.set(arg);
  134. else if (!optPackageMap.length())
  135. optPackageMap.set(arg);
  136. else
  137. {
  138. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  139. return EclCmdOptionNoMatch;
  140. }
  141. continue;
  142. }
  143. if (iter.matchFlag(optGlobalScope, ECLOPT_GLOBAL_SCOPE))
  144. continue;
  145. eclCmdOptionMatchIndicator ind = EclCmdCommon::matchCommandLineOption(iter, true);
  146. if (ind != EclCmdOptionMatch)
  147. return ind;
  148. }
  149. return EclCmdOptionMatch;
  150. }
  151. virtual bool finalizeOptions(IProperties *globals)
  152. {
  153. if (!EclCmdCommon::finalizeOptions(globals))
  154. return false;
  155. if (optTarget.isEmpty())
  156. {
  157. fprintf(stdout, "\n ... Missing target name\n");
  158. return false;
  159. }
  160. if (optPackageMap.isEmpty())
  161. {
  162. fprintf(stdout, "\n ... Missing package map name\n");
  163. return false;
  164. }
  165. if (optProcess.isEmpty())
  166. optProcess.set("*");
  167. return true;
  168. }
  169. virtual int processCMD()
  170. {
  171. Owned<IClientWsPackageProcess> packageProcessClient = createCmdClient(WsPackageProcess, *this);
  172. Owned<IClientDeActivatePackageRequest> request = packageProcessClient->createDeActivatePackageRequest();
  173. setCmdRequestTimeouts(request->rpc(), 0, optWaitConnectMs, optWaitReadSec);
  174. request->setTarget(optTarget);
  175. request->setPackageMap(optPackageMap);
  176. request->setProcess(optProcess);
  177. request->setGlobalScope(optGlobalScope);
  178. Owned<IClientDeActivatePackageResponse> resp = packageProcessClient->DeActivatePackage(request);
  179. return outputMultiExceptionsEx(resp->getExceptions());
  180. }
  181. virtual void usage()
  182. {
  183. fputs("\nUsage:\n"
  184. "\n"
  185. "The 'deactivate' command will deactivate the currently activate packagemap \n"
  186. "\n"
  187. "ecl packagemap deactivate <target> <packagemap>\n"
  188. " Options:\n"
  189. " <target> Name of target containing package map to activate\n"
  190. " <packagemap> Packagemap to activate\n"
  191. " --global-scope The specified packagemap can be shared across multiple targets\n",
  192. stdout);
  193. EclCmdCommon::usage();
  194. }
  195. private:
  196. StringAttr optTarget;
  197. StringAttr optPackageMap;
  198. StringAttr optProcess;
  199. bool optGlobalScope;
  200. };
  201. class EclCmdPackageList : public EclCmdCommon
  202. {
  203. public:
  204. EclCmdPackageList()
  205. {
  206. }
  207. virtual eclCmdOptionMatchIndicator parseCommandLineOptions(ArgvIterator &iter)
  208. {
  209. for (; !iter.done(); iter.next())
  210. {
  211. const char *arg = iter.query();
  212. if (*arg!='-')
  213. {
  214. if (optTarget.isEmpty())
  215. optTarget.set(arg);
  216. else
  217. {
  218. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  219. return EclCmdOptionNoMatch;
  220. }
  221. continue;
  222. }
  223. eclCmdOptionMatchIndicator ind = EclCmdCommon::matchCommandLineOption(iter, true);
  224. if (ind != EclCmdOptionMatch)
  225. return ind;
  226. }
  227. return EclCmdOptionMatch;
  228. }
  229. virtual bool finalizeOptions(IProperties *globals)
  230. {
  231. if (!EclCmdCommon::finalizeOptions(globals))
  232. return false;
  233. return true;
  234. }
  235. virtual int processCMD()
  236. {
  237. Owned<IClientWsPackageProcess> packageProcessClient = createCmdClient(WsPackageProcess, *this);
  238. Owned<IClientListPackageRequest> request = packageProcessClient->createListPackageRequest();
  239. setCmdRequestTimeouts(request->rpc(), 0, optWaitConnectMs, optWaitReadSec);
  240. request->setTarget(optTarget);
  241. request->setProcess("*");
  242. Owned<IClientListPackageResponse> resp = packageProcessClient->ListPackage(request);
  243. int ret = outputMultiExceptionsEx(resp->getExceptions());
  244. if (ret == 0)
  245. {
  246. IArrayOf<IConstPackageListMapData> &pkgMapInfo = resp->getPkgListMapData();
  247. unsigned int num = pkgMapInfo.ordinality();
  248. for (unsigned i=0; i<num; i++)
  249. {
  250. IConstPackageListMapData& req = pkgMapInfo.item(i);
  251. printf("\nPackage Id = %s active = %d\n", req.getId(), req.getActive());
  252. IArrayOf<IConstPackageListData> &pkgInfo = req.getPkgListData();
  253. unsigned int numPkgs = pkgInfo.ordinality();
  254. for (unsigned int j = 0; j <numPkgs; j++)
  255. {
  256. IConstPackageListData& req = pkgInfo.item(j);
  257. const char *id = req.getId();
  258. const char *queries = req.getQueries();
  259. if (queries && *queries)
  260. printf("\t\tname = %s queries = %s\n", id, queries);
  261. else
  262. printf("\t\tname = %s\n", id);
  263. }
  264. }
  265. }
  266. return ret;
  267. }
  268. virtual void usage()
  269. {
  270. fputs("\nUsage:\n"
  271. "\n"
  272. "The 'list' command will list package map information for the target cluster \n"
  273. "\n"
  274. "ecl packagemap list <target> \n"
  275. " Options:\n"
  276. " <target> Name of target containing package map to use when retrieving list of package maps\n",
  277. stdout);
  278. EclCmdCommon::usage();
  279. }
  280. private:
  281. StringAttr optTarget;
  282. };
  283. class EclCmdPackageInfo: public EclCmdCommon
  284. {
  285. public:
  286. EclCmdPackageInfo()
  287. {
  288. }
  289. virtual eclCmdOptionMatchIndicator parseCommandLineOptions(ArgvIterator &iter)
  290. {
  291. if (iter.done())
  292. return EclCmdOptionNoMatch;
  293. for (; !iter.done(); iter.next())
  294. {
  295. const char *arg = iter.query();
  296. if (*arg!='-')
  297. {
  298. if (optTarget.isEmpty())
  299. optTarget.set(arg);
  300. else
  301. {
  302. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  303. return EclCmdOptionNoMatch;
  304. }
  305. continue;
  306. }
  307. eclCmdOptionMatchIndicator ind = EclCmdCommon::matchCommandLineOption(iter, true);
  308. if (ind != EclCmdOptionMatch)
  309. return ind;
  310. }
  311. return EclCmdOptionMatch;
  312. }
  313. virtual bool finalizeOptions(IProperties *globals)
  314. {
  315. if (!EclCmdCommon::finalizeOptions(globals))
  316. return false;
  317. return true;
  318. }
  319. virtual int processCMD()
  320. {
  321. Owned<IClientWsPackageProcess> packageProcessClient = createCmdClient(WsPackageProcess, *this);
  322. Owned<IClientGetPackageRequest> request = packageProcessClient->createGetPackageRequest();
  323. setCmdRequestTimeouts(request->rpc(), 0, optWaitConnectMs, optWaitReadSec);
  324. request->setTarget(optTarget);
  325. request->setProcess("*");
  326. Owned<IClientGetPackageResponse> resp = packageProcessClient->GetPackage(request);
  327. int ret = outputMultiExceptionsEx(resp->getExceptions());
  328. if (ret == 0)
  329. printf("%s", resp->getInfo());
  330. return ret;
  331. }
  332. virtual void usage()
  333. {
  334. fputs("\nUsage:\n"
  335. "\n"
  336. "The 'info' command will return the contents of the active package map information for the target cluster \n"
  337. "\n"
  338. "ecl packagemap info <target> \n"
  339. " Options:\n"
  340. " <target> Name of the target to use when retrieving active package map information\n",
  341. stdout);
  342. EclCmdCommon::usage();
  343. }
  344. private:
  345. StringAttr optTarget;
  346. };
  347. class EclCmdPackageDelete : public EclCmdCommon
  348. {
  349. public:
  350. EclCmdPackageDelete()
  351. {
  352. }
  353. virtual eclCmdOptionMatchIndicator parseCommandLineOptions(ArgvIterator &iter)
  354. {
  355. if (iter.done())
  356. return EclCmdOptionNoMatch;
  357. for (; !iter.done(); iter.next())
  358. {
  359. const char *arg = iter.query();
  360. if (*arg!='-')
  361. {
  362. if (!optTarget.length())
  363. optTarget.set(arg);
  364. else if (!optPackageMap.length())
  365. optPackageMap.set(arg);
  366. else
  367. {
  368. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  369. return EclCmdOptionNoMatch;
  370. }
  371. continue;
  372. }
  373. if (iter.matchFlag(optGlobalScope, ECLOPT_GLOBAL_SCOPE))
  374. continue;
  375. eclCmdOptionMatchIndicator ind = EclCmdCommon::matchCommandLineOption(iter, true);
  376. if (ind != EclCmdOptionMatch)
  377. return ind;
  378. }
  379. return EclCmdOptionMatch;
  380. }
  381. virtual bool finalizeOptions(IProperties *globals)
  382. {
  383. if (!EclCmdCommon::finalizeOptions(globals))
  384. {
  385. usage();
  386. return false;
  387. }
  388. StringBuffer err;
  389. if (optPackageMap.isEmpty())
  390. err.append("\n ... Missing package map name\n");
  391. else if (optTarget.isEmpty())
  392. err.append("\n ... Specify a target cluster name\n");
  393. if (err.length())
  394. {
  395. fprintf(stdout, "%s", err.str());
  396. return false;
  397. }
  398. if (optProcess.isEmpty())
  399. optProcess.set("*");
  400. return true;
  401. }
  402. virtual int processCMD()
  403. {
  404. fprintf(stdout, "\n ... deleting package map %s now\n\n", optPackageMap.str());
  405. Owned<IClientWsPackageProcess> packageProcessClient = createCmdClient(WsPackageProcess, *this);
  406. Owned<IClientDeletePackageRequest> request = packageProcessClient->createDeletePackageRequest();
  407. setCmdRequestTimeouts(request->rpc(), 0, optWaitConnectMs, optWaitReadSec);
  408. request->setTarget(optTarget);
  409. request->setPackageMap(optPackageMap);
  410. request->setProcess(optProcess);
  411. request->setGlobalScope(optGlobalScope);
  412. Owned<IClientDeletePackageResponse> resp = packageProcessClient->DeletePackage(request);
  413. int ret = outputMultiExceptionsEx(resp->getExceptions());
  414. if (ret == 0)
  415. printf("Successfully deleted package %s\n", optPackageMap.get());
  416. return ret;
  417. }
  418. virtual void usage()
  419. {
  420. fputs("\nUsage:\n"
  421. "\n"
  422. "The 'delete' command will delete the package map from the target cluster \n"
  423. "\n"
  424. "ecl packagemap delete <target> <packagemap>\n"
  425. " Options:\n"
  426. " <target> Name of the target to use \n"
  427. " <packagemap> Name of the package map to delete\n"
  428. " --global-scope The specified packagemap is sharable across multiple targets\n",
  429. stdout);
  430. EclCmdCommon::usage();
  431. }
  432. private:
  433. StringAttr optPackageMap;
  434. StringAttr optTarget;
  435. StringAttr optProcess;
  436. bool optGlobalScope;
  437. };
  438. class EclCmdPackageAdd : public EclCmdCommon
  439. {
  440. public:
  441. EclCmdPackageAdd() : optActivate(false), optOverWrite(false), optGlobalScope(false), optAllowForeign(false), optPreloadAll(false),
  442. optUpdateSuperfiles(false), optUpdateCloneFrom(false), optDontAppendCluster(false), optReplacePackagemap(false)
  443. {
  444. }
  445. virtual eclCmdOptionMatchIndicator parseCommandLineOptions(ArgvIterator &iter)
  446. {
  447. if (iter.done())
  448. return EclCmdOptionNoMatch;
  449. for (; !iter.done(); iter.next())
  450. {
  451. const char *arg = iter.query();
  452. if (*arg!='-')
  453. {
  454. if (optTarget.isEmpty())
  455. optTarget.set(arg);
  456. else if (optFileName.isEmpty())
  457. optFileName.set(arg);
  458. else
  459. {
  460. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  461. return EclCmdOptionNoMatch;
  462. }
  463. continue;
  464. }
  465. if (iter.matchOption(optPackageMapId, ECLOPT_PMID))
  466. continue;
  467. if (iter.matchOption(optDaliIP, ECLOPT_DALIIP))
  468. continue;
  469. if (iter.matchOption(optSourceProcess, ECLOPT_SOURCE_PROCESS))
  470. continue;
  471. if (iter.matchFlag(optActivate, ECLOPT_ACTIVATE)||iter.matchFlag(optActivate, ECLOPT_ACTIVATE_S))
  472. continue;
  473. if (iter.matchFlag(optOverWrite, ECLOPT_OVERWRITE)||iter.matchFlag(optOverWrite, ECLOPT_OVERWRITE_S))
  474. continue;
  475. if (iter.matchFlag(optReplacePackagemap, ECLOPT_REPLACE))
  476. continue;
  477. if (iter.matchFlag(optUpdateSuperfiles, ECLOPT_UPDATE_SUPER_FILES))
  478. continue;
  479. if (iter.matchFlag(optUpdateCloneFrom, ECLOPT_UPDATE_CLONE_FROM))
  480. continue;
  481. if (iter.matchFlag(optDontAppendCluster, ECLOPT_DONT_APPEND_CLUSTER))
  482. continue;
  483. if (iter.matchFlag(optGlobalScope, ECLOPT_GLOBAL_SCOPE))
  484. continue;
  485. if (iter.matchFlag(optAllowForeign, ECLOPT_ALLOW_FOREIGN))
  486. continue;
  487. if (iter.matchFlag(optPreloadAll, ECLOPT_PRELOAD_ALL_PACKAGES))
  488. continue;
  489. eclCmdOptionMatchIndicator ind = EclCmdCommon::matchCommandLineOption(iter, true);
  490. if (ind != EclCmdOptionMatch)
  491. return ind;
  492. }
  493. return EclCmdOptionMatch;
  494. }
  495. virtual bool finalizeOptions(IProperties *globals)
  496. {
  497. if (!EclCmdCommon::finalizeOptions(globals))
  498. {
  499. usage();
  500. return false;
  501. }
  502. StringBuffer err;
  503. if (optFileName.isEmpty())
  504. err.append("\n ... Missing package file name\n");
  505. else if (optTarget.isEmpty())
  506. err.append("\n ... Specify a cluster name\n");
  507. if (err.length())
  508. {
  509. fprintf(stdout, "%s", err.str());
  510. return false;
  511. }
  512. if (optProcess.isEmpty())
  513. optProcess.set("*");
  514. if (optPackageMapId.isEmpty())
  515. {
  516. StringBuffer name;
  517. splitFilename(optFileName.get(), NULL, NULL, &name, &name);
  518. optPackageMapId.set(name.str());
  519. }
  520. optPackageMapId.toLowerCase();
  521. return true;
  522. }
  523. virtual int processCMD()
  524. {
  525. Owned<IClientWsPackageProcess> packageProcessClient = createCmdClient(WsPackageProcess, *this);
  526. StringBuffer pkgInfo;
  527. pkgInfo.loadFile(optFileName);
  528. fprintf(stdout, "\n ... adding package map %s now\n\n", optFileName.str());
  529. Owned<IClientAddPackageRequest> request = packageProcessClient->createAddPackageRequest();
  530. setCmdRequestTimeouts(request->rpc(), 0, optWaitConnectMs, optWaitReadSec);
  531. request->setActivate(optActivate);
  532. request->setInfo(pkgInfo);
  533. request->setTarget(optTarget);
  534. request->setPackageMap(optPackageMapId);
  535. request->setProcess(optProcess);
  536. request->setDaliIp(optDaliIP);
  537. request->setOverWrite(optOverWrite);
  538. request->setGlobalScope(optGlobalScope);
  539. request->setSourceProcess(optSourceProcess);
  540. request->setAllowForeignFiles(optAllowForeign);
  541. request->setPreloadAllPackages(optPreloadAll);
  542. request->setReplacePackageMap(optReplacePackagemap);
  543. request->setUpdateSuperFiles(optUpdateSuperfiles);
  544. request->setUpdateCloneFrom(optUpdateCloneFrom);
  545. request->setAppendCluster(!optDontAppendCluster);
  546. Owned<IClientAddPackageResponse> resp = packageProcessClient->AddPackage(request);
  547. int ret = outputMultiExceptionsEx(resp->getExceptions());
  548. StringArray &notFound = resp->getFilesNotFound();
  549. if (notFound.length())
  550. {
  551. fputs("\nFiles defined in package but not found in DFS:\n", stderr);
  552. ForEachItemIn(i, notFound)
  553. fprintf(stderr, " %s\n", notFound.item(i));
  554. fputs("\n", stderr);
  555. }
  556. return ret;
  557. }
  558. virtual void usage()
  559. {
  560. fputs("\nUsage:\n"
  561. "\n"
  562. "The 'add' command will add the package map information to dali \n"
  563. "\n"
  564. "ecl packagemap add [options] <target> <filename>\n"
  565. " <target> Name of target to use when adding package map information\n"
  566. " <filename> Name of file containing package map information\n"
  567. " Options:\n"
  568. " -O, --overwrite Replace existing packagemap and file information (dangerous)\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. " --allow-foreign Do not fail if foreign files are used in packagemap\n"
  575. " --preload-all Set preload files option for all packages\n"
  576. " --replace Replace existing packagmap"
  577. " --update-super-files Update local DFS super-files if remote DALI has changed\n"
  578. " --update-clone-from Update local clone from location if remote DALI has changed\n"
  579. " --dont-append-cluster Only use to avoid locking issues due to adding cluster to file\n",
  580. stdout);
  581. EclCmdCommon::usage();
  582. }
  583. private:
  584. StringBuffer pkgInfo;
  585. StringAttr optFileName;
  586. StringAttr optTarget;
  587. StringAttr optProcess;
  588. StringAttr optDaliIP;
  589. StringAttr optPackageMapId;
  590. StringAttr optSourceProcess;
  591. bool optActivate;
  592. bool optOverWrite;
  593. bool optReplacePackagemap;
  594. bool optUpdateSuperfiles;
  595. bool optUpdateCloneFrom;
  596. bool optDontAppendCluster; //Undesirable but here temporarily because DALI may have locking issues
  597. bool optGlobalScope;
  598. bool optAllowForeign;
  599. bool optPreloadAll;
  600. };
  601. class EclCmdPackageMapCopy : public EclCmdCommon
  602. {
  603. public:
  604. EclCmdPackageMapCopy()
  605. {
  606. }
  607. virtual eclCmdOptionMatchIndicator parseCommandLineOptions(ArgvIterator &iter) override
  608. {
  609. if (iter.done())
  610. return EclCmdOptionNoMatch;
  611. for (; !iter.done(); iter.next())
  612. {
  613. const char *arg = iter.query();
  614. if (*arg!='-')
  615. {
  616. if (optSrcPath.isEmpty())
  617. optSrcPath.set(arg);
  618. else if (optTarget.isEmpty())
  619. optTarget.set(arg);
  620. else
  621. {
  622. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  623. return EclCmdOptionNoMatch;
  624. }
  625. continue;
  626. }
  627. if (iter.matchOption(optDaliIP, ECLOPT_DALIIP))
  628. continue;
  629. if (iter.matchOption(optPMID, ECLOPT_PMID))
  630. continue;
  631. if (iter.matchOption(optSourceProcess, ECLOPT_SOURCE_PROCESS))
  632. continue;
  633. if (iter.matchFlag(optActivate, ECLOPT_ACTIVATE)||iter.matchFlag(optActivate, ECLOPT_ACTIVATE_S))
  634. continue;
  635. if (iter.matchFlag(optReplacePackagemap, ECLOPT_REPLACE))
  636. continue;
  637. if (iter.matchFlag(optUpdateSuperfiles, ECLOPT_UPDATE_SUPER_FILES))
  638. continue;
  639. if (iter.matchFlag(optUpdateCloneFrom, ECLOPT_UPDATE_CLONE_FROM))
  640. continue;
  641. if (iter.matchFlag(optDontAppendCluster, ECLOPT_DONT_APPEND_CLUSTER))
  642. continue;
  643. if (iter.matchFlag(optPreloadAll, ECLOPT_PRELOAD_ALL_PACKAGES))
  644. continue;
  645. eclCmdOptionMatchIndicator ind = EclCmdCommon::matchCommandLineOption(iter, true);
  646. if (ind != EclCmdOptionMatch)
  647. return ind;
  648. }
  649. return EclCmdOptionMatch;
  650. }
  651. virtual bool finalizeOptions(IProperties *globals) override
  652. {
  653. if (!EclCmdCommon::finalizeOptions(globals))
  654. {
  655. usage();
  656. return false;
  657. }
  658. StringBuffer err;
  659. if (optSrcPath.isEmpty())
  660. err.append("\n ... Missing path to source packagemap\n");
  661. else if (optTarget.isEmpty())
  662. err.append("\n ... Specify a target cluster\n");
  663. if (err.length())
  664. {
  665. fputs(err.str(), stderr);
  666. return false;
  667. }
  668. return true;
  669. }
  670. virtual int processCMD() override
  671. {
  672. Owned<IClientWsPackageProcess> packageProcessClient = createCmdClient(WsPackageProcess, *this);
  673. fprintf(stdout, "\n ... copy package map %s to %s\n\n", optSrcPath.str(), optTarget.str());
  674. Owned<IClientCopyPackageMapRequest> request = packageProcessClient->createCopyPackageMapRequest();
  675. setCmdRequestTimeouts(request->rpc(), 0, optWaitConnectMs, optWaitReadSec);
  676. request->setSourcePath(optSrcPath);
  677. request->setTarget(optTarget);
  678. request->setProcess("*");
  679. request->setPMID(optPMID);
  680. request->setActivate(optActivate);
  681. request->setDaliIp(optDaliIP);
  682. request->setSourceProcess(optSourceProcess);
  683. request->setPreloadAllPackages(optPreloadAll);
  684. request->setReplacePackageMap(optReplacePackagemap);
  685. request->setUpdateSuperFiles(optUpdateSuperfiles);
  686. request->setUpdateCloneFrom(optUpdateCloneFrom);
  687. request->setAppendCluster(!optDontAppendCluster);
  688. Owned<IClientCopyPackageMapResponse> resp = packageProcessClient->CopyPackageMap(request);
  689. int ret = outputMultiExceptionsEx(resp->getExceptions());
  690. StringArray &notFound = resp->getFilesNotFound();
  691. if (notFound.length())
  692. {
  693. fputs("\nFiles defined in package but not found in DFS:\n", stderr);
  694. ForEachItemIn(i, notFound)
  695. fprintf(stderr, " %s\n", notFound.item(i));
  696. fputs("\n", stderr);
  697. }
  698. return ret;
  699. }
  700. virtual void usage() override
  701. {
  702. fputs("\nUsage:\n"
  703. "\n"
  704. "The 'copy' command will copy a package map from one target to another \n"
  705. "\n"
  706. "ecl packagemap copy <path> <target>\n"
  707. " <path> Path to the source packagemap to copy\n"
  708. " The following formats are supported:\n"
  709. " remote PackageMap - //IP:PORT/Target/PackageMapId\n"
  710. " local PackageMap - target/PackageMapId\n"
  711. " <target> Name of target to copy the packagemap to\n"
  712. " Options:\n"
  713. " -A, --activate Activate the package information\n"
  714. " --daliip=<ip> IP of the remote dali to use for logical file lookups\n"
  715. " --pmid Identifier of package map - defaults to source PMID\n"
  716. " --source-process Process cluster to copy files from\n"
  717. " --preload-all Set preload files option for all packages\n"
  718. " --replace Replace existing packagmap\n"
  719. " --update-super-files Update local DFS super-files if remote DALI has changed\n"
  720. " --update-clone-from Update local clone from location if remote DALI has changed\n"
  721. " --dont-append-cluster Only use to avoid locking issues due to adding cluster to file\n",
  722. stdout);
  723. EclCmdCommon::usage();
  724. }
  725. private:
  726. StringAttr optSrcPath;
  727. StringAttr optTarget;
  728. StringAttr optPMID;
  729. StringAttr optDaliIP;
  730. StringAttr optSourceProcess;
  731. bool optActivate = false;
  732. bool optReplacePackagemap = false;
  733. bool optUpdateSuperfiles = false;
  734. bool optUpdateCloneFrom = false;
  735. bool optDontAppendCluster = false; //Undesirable but here temporarily because DALI may have locking issues
  736. bool optPreloadAll = false;
  737. };
  738. class EclCmdPackageValidate : public EclCmdCommon
  739. {
  740. public:
  741. EclCmdPackageValidate() : optValidateActive(false), optCheckDFS(false), optGlobalScope(false)
  742. {
  743. }
  744. virtual eclCmdOptionMatchIndicator parseCommandLineOptions(ArgvIterator &iter)
  745. {
  746. if (iter.done())
  747. return EclCmdOptionNoMatch;
  748. for (; !iter.done(); iter.next())
  749. {
  750. const char *arg = iter.query();
  751. if (*arg!='-')
  752. {
  753. if (optTarget.isEmpty())
  754. optTarget.set(arg);
  755. else if (optFileName.isEmpty())
  756. optFileName.set(arg);
  757. else
  758. {
  759. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  760. return EclCmdOptionNoMatch;
  761. }
  762. continue;
  763. }
  764. if (iter.matchFlag(optValidateActive, ECLOPT_ACTIVE))
  765. continue;
  766. if (iter.matchFlag(optCheckDFS, ECLOPT_CHECK_DFS))
  767. continue;
  768. if (iter.matchOption(optPMID, ECLOPT_PMID) || iter.matchOption(optPMID, ECLOPT_PMID_S))
  769. continue;
  770. if (iter.matchFlag(optGlobalScope, ECLOPT_GLOBAL_SCOPE))
  771. continue;
  772. if (iter.matchFlag(optIgnoreWarnings, ECLOPT_IGNORE_WARNINGS))
  773. continue;
  774. if (iter.matchFlag(optIgnoreOptionalFiles, ECLOPT_IGNORE_OPTIONAL))
  775. continue;
  776. StringAttr queryIds;
  777. if (iter.matchOption(queryIds, ECLOPT_QUERYID))
  778. {
  779. optQueryIds.appendList(queryIds.get(), ",");
  780. continue;
  781. }
  782. if (iter.matchOption(queryIds, ECLOPT_IGNORE_QUERIES))
  783. {
  784. optIgnoreQueries.appendList(queryIds.get(), ",");
  785. continue;
  786. }
  787. eclCmdOptionMatchIndicator ind = EclCmdCommon::matchCommandLineOption(iter, true);
  788. if (ind != EclCmdOptionMatch)
  789. return ind;
  790. }
  791. return EclCmdOptionMatch;
  792. }
  793. virtual bool finalizeOptions(IProperties *globals)
  794. {
  795. if (!EclCmdCommon::finalizeOptions(globals))
  796. {
  797. usage();
  798. return false;
  799. }
  800. StringBuffer err;
  801. int pcount=0;
  802. if (optFileName.length())
  803. pcount++;
  804. if (optPMID.length())
  805. pcount++;
  806. if (optValidateActive)
  807. pcount++;
  808. if (pcount==0)
  809. err.append("\n ... Package file name, --pmid, or --active required\n");
  810. else if (pcount > 1)
  811. err.append("\n ... Package file name, --pmid, and --active are mutually exclusive\n");
  812. if (optTarget.isEmpty())
  813. err.append("\n ... Specify a cluster name\n\n");
  814. if (err.length())
  815. {
  816. fprintf(stdout, "%s", err.str());
  817. return false;
  818. }
  819. return true;
  820. }
  821. void outputLfnCategoryTree(IPropertyTree &querynode, const char *name)
  822. {
  823. StringBuffer lcname(name);
  824. IPropertyTree *catnode = querynode.queryPropTree(lcname.toLowerCase());
  825. if (!catnode)
  826. return;
  827. fprintf(stderr, " [%s]\n", name);
  828. Owned<IPropertyTreeIterator> lfnnodes = catnode->getElements("*");
  829. ForEach(*lfnnodes)
  830. fprintf(stderr, " %s\n", lfnnodes->query().queryName());
  831. }
  832. void outputLfnTree(IPropertyTree *lfntree)
  833. {
  834. Owned<IPropertyTreeIterator> querynodes = lfntree->getElements("*");
  835. ForEach(*querynodes)
  836. {
  837. IPropertyTree &querynode = querynodes->query();
  838. fprintf(stderr, " --%s\n", querynode.queryName());
  839. outputLfnCategoryTree(querynode, "Compulsory");
  840. outputLfnCategoryTree(querynode, "Required");
  841. outputLfnCategoryTree(querynode, "Optional");
  842. }
  843. }
  844. virtual int processCMD()
  845. {
  846. Owned<IClientWsPackageProcess> packageProcessClient = getWsPackageSoapService(optServer, optPort, optUsername, optPassword);
  847. Owned<IClientValidatePackageRequest> request = packageProcessClient->createValidatePackageRequest();
  848. setCmdRequestTimeouts(request->rpc(), 0, optWaitConnectMs, optWaitReadSec);
  849. if (optFileName.length())
  850. {
  851. StringBuffer pkgInfo;
  852. pkgInfo.loadFile(optFileName);
  853. fprintf(stdout, "\nvalidating packagemap file %s\n\n", optFileName.str());
  854. request->setInfo(pkgInfo);
  855. }
  856. request->setActive(optValidateActive);
  857. request->setPMID(optPMID);
  858. request->setTarget(optTarget);
  859. request->setQueriesToVerify(optQueryIds);
  860. request->setQueriesToIgnore(optIgnoreQueries);
  861. request->setCheckDFS(optCheckDFS);
  862. request->setGlobalScope(optGlobalScope);
  863. request->setIgnoreWarnings(optIgnoreWarnings);
  864. request->setIgnoreOptionalFiles(optIgnoreOptionalFiles);
  865. bool validateMessages = false;
  866. Owned<IClientValidatePackageResponse> resp = packageProcessClient->ValidatePackage(request);
  867. int ret = outputMultiExceptionsEx(resp->getExceptions());
  868. if (ret != 0)
  869. validateMessages = true;
  870. const char *pmid = resp->getPMID();
  871. if (!isEmptyString(pmid))
  872. { //server version < 1.04
  873. processValidatePackageResponse(nullptr, nullptr, resp->getErrors(), resp->getWarnings(),
  874. resp->getQueries().getUnmatched(), resp->getPackages().getUnmatched(), resp->getFiles(), validateMessages);
  875. }
  876. else
  877. {
  878. IArrayOf<IConstValidateResult> &results = resp->getResults();
  879. ForEachItemIn(i, results)
  880. {
  881. IConstValidateResult &result = results.item(i);
  882. processValidatePackageResponse(result.getTarget(), result.getPMID(), result.getErrors(), result.getWarnings(),
  883. result.getQueries().getUnmatched(), result.getPackages().getUnmatched(), result.getFiles(), validateMessages);
  884. }
  885. }
  886. if (!validateMessages)
  887. fputs(" Validation was successful\n", stdout);
  888. return ret;
  889. }
  890. bool processValidatePackageResponse(const char *target, const char *pmid, StringArray &errors, StringArray &warnings,
  891. StringArray &unmatchedQueries, StringArray &unusedPackages, IConstValidatePackageFiles &files,
  892. bool &validateMessages)
  893. {
  894. if (!isEmptyString(target) && !isEmptyString(pmid))
  895. fprintf(stderr, " Target: %s, PMID: %s :\n", target, pmid);
  896. if (errors.ordinality()>0)
  897. {
  898. validateMessages = true;
  899. fputs(" Validation Failed!\n", stderr);
  900. fputs(" Error(s):\n", stderr);
  901. ForEachItemIn(i, errors)
  902. fprintf(stderr, " %s\n", errors.item(i));
  903. }
  904. if (warnings.ordinality()>0)
  905. {
  906. validateMessages = true;
  907. fputs(" Warning(s):\n", stderr);
  908. ForEachItemIn(i, warnings)
  909. fprintf(stderr, " %s\n", warnings.item(i));
  910. }
  911. if (unmatchedQueries.ordinality()>0)
  912. {
  913. validateMessages = true;
  914. fputs("\n Queries without matching package:\n", stderr);
  915. ForEachItemIn(i, unmatchedQueries)
  916. fprintf(stderr, " %s\n", unmatchedQueries.item(i));
  917. }
  918. if (unusedPackages.ordinality()>0)
  919. {
  920. validateMessages = true;
  921. fputs("\n Packages without matching queries:\n", stderr);
  922. ForEachItemIn(i, unusedPackages)
  923. fprintf(stderr, " %s\n", unusedPackages.item(i));
  924. }
  925. StringArray &unusedFiles = files.getUnmatched();
  926. if (unusedFiles.ordinality()>0)
  927. {
  928. validateMessages = true;
  929. fputs("\n Query files without matching package definitions:\n", stderr);
  930. Owned<IPropertyTree> filetree = createPTree();
  931. ForEachItemIn(i, unusedFiles)
  932. {
  933. StringArray info;
  934. info.appendList(unusedFiles.item(i), "/");
  935. if (info.length()>=2)
  936. {
  937. IPropertyTree *querynode = ensurePTree(filetree, info.item(0));
  938. if (querynode)
  939. {
  940. StringBuffer category((info.length()>=3) ? info.item(2) : "required");
  941. IPropertyTree *cat = ensurePTree(querynode, category.toLowerCase());
  942. if (cat)
  943. ensurePTree(cat, info.item(1));
  944. }
  945. }
  946. }
  947. outputLfnTree(filetree);
  948. }
  949. StringArray &notInDFS = files.getNotInDFS();
  950. if (notInDFS.ordinality()>0)
  951. {
  952. validateMessages = true;
  953. fputs("\n Packagemap SubFiles not found in DFS:\n", stderr);
  954. ForEachItemIn(i, notInDFS)
  955. fprintf(stderr, " %s\n", notInDFS.item(i));
  956. }
  957. if (!isEmptyString(target) && !isEmptyString(pmid))
  958. fprintf(stderr, "\n Target: %s, PMID: %s done\n\n", target, pmid);
  959. return validateMessages;
  960. }
  961. virtual void usage()
  962. {
  963. fputs("\nUsage:\n"
  964. "\n"
  965. "The 'validate' command will checkout the contents of the package map file \n"
  966. "\n"
  967. "ecl packagemap validate <target> <filename>\n"
  968. " Options:\n"
  969. " <target> Name of target to use when validating package map information\n"
  970. " <filename> Name of file containing package map information\n"
  971. " --active Validate the active packagemap\n"
  972. " --check-dfs Verify that subfiles exist in DFS\n"
  973. " -pm, --pmid Identifier of packagemap to validate\n"
  974. " --queryid Query to verify against packagemap, multiple queries can be\n"
  975. " specified using a comma separated list, or by using --queryid\n"
  976. " more than once. Default is all queries in the target queryset\n"
  977. " --ignore-queries Queries to exclude from verification, multiple queries can be\n"
  978. " specified using wildcards, a comma separated list, or by using\n"
  979. " --ignore-queries more than once.\n"
  980. " --ignore-optional Doesn't warn when optional files are not defined in packagemap.\n"
  981. " --ignore-warnings Doesn't output general packagemap warnings.\n"
  982. " --global-scope The specified packagemap can be shared across multiple targets\n",
  983. stdout);
  984. EclCmdCommon::usage();
  985. }
  986. private:
  987. StringArray optQueryIds;
  988. StringArray optIgnoreQueries;
  989. StringAttr optFileName;
  990. StringAttr optTarget;
  991. StringAttr optPMID;
  992. bool optValidateActive;
  993. bool optCheckDFS;
  994. bool optGlobalScope;
  995. bool optIgnoreWarnings = false;
  996. bool optIgnoreOptionalFiles = false;
  997. };
  998. class EclCmdPackageQueryFiles : public EclCmdCommon
  999. {
  1000. public:
  1001. EclCmdPackageQueryFiles() : optGlobalScope(false)
  1002. {
  1003. }
  1004. virtual eclCmdOptionMatchIndicator parseCommandLineOptions(ArgvIterator &iter)
  1005. {
  1006. if (iter.done())
  1007. return EclCmdOptionNoMatch;
  1008. for (; !iter.done(); iter.next())
  1009. {
  1010. const char *arg = iter.query();
  1011. if (*arg!='-')
  1012. {
  1013. if (optTarget.isEmpty())
  1014. optTarget.set(arg);
  1015. else if (optQueryId.isEmpty())
  1016. optQueryId.set(arg);
  1017. else
  1018. {
  1019. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  1020. return EclCmdOptionNoMatch;
  1021. }
  1022. continue;
  1023. }
  1024. if (iter.matchOption(optPMID, ECLOPT_PMID) || iter.matchOption(optPMID, ECLOPT_PMID_S))
  1025. continue;
  1026. if (iter.matchFlag(optGlobalScope, ECLOPT_GLOBAL_SCOPE))
  1027. continue;
  1028. eclCmdOptionMatchIndicator ind = EclCmdCommon::matchCommandLineOption(iter, true);
  1029. if (ind != EclCmdOptionMatch)
  1030. return ind;
  1031. }
  1032. return EclCmdOptionMatch;
  1033. }
  1034. virtual bool finalizeOptions(IProperties *globals)
  1035. {
  1036. if (!EclCmdCommon::finalizeOptions(globals))
  1037. {
  1038. usage();
  1039. return false;
  1040. }
  1041. StringBuffer err;
  1042. if (optTarget.isEmpty())
  1043. err.append("\n ... A target cluster must be specified\n");
  1044. if (optQueryId.isEmpty())
  1045. err.append("\n ... A query must be specified\n");
  1046. if (err.length())
  1047. {
  1048. fprintf(stdout, "%s", err.str());
  1049. return false;
  1050. }
  1051. return true;
  1052. }
  1053. virtual int processCMD()
  1054. {
  1055. Owned<IClientWsPackageProcess> packageProcessClient = getWsPackageSoapService(optServer, optPort, optUsername, optPassword);
  1056. Owned<IClientGetQueryFileMappingRequest> request = packageProcessClient->createGetQueryFileMappingRequest();
  1057. setCmdRequestTimeouts(request->rpc(), 0, optWaitConnectMs, optWaitReadSec);
  1058. request->setTarget(optTarget);
  1059. request->setQueryName(optQueryId);
  1060. request->setPMID(optPMID);
  1061. request->setGlobalScope(optGlobalScope);
  1062. Owned<IClientGetQueryFileMappingResponse> resp = packageProcessClient->GetQueryFileMapping(request);
  1063. int ret = outputMultiExceptionsEx(resp->getExceptions());
  1064. StringArray &unmappedFiles = resp->getUnmappedFiles();
  1065. if (!unmappedFiles.ordinality())
  1066. fputs("No undefined files found.\n", stderr);
  1067. else
  1068. {
  1069. fputs("Files not defined in PackageMap:\n", stderr);
  1070. ForEachItemIn(i, unmappedFiles)
  1071. fprintf(stderr, " %s\n", unmappedFiles.item(i));
  1072. }
  1073. IArrayOf<IConstSuperFile> &superFiles = resp->getSuperFiles();
  1074. if (!superFiles.ordinality())
  1075. fputs("\nNo matching SuperFiles found in PackageMap.\n", stderr);
  1076. else
  1077. {
  1078. fputs("\nSuperFiles defined in PackageMap:\n", stderr);
  1079. ForEachItemIn(i, superFiles)
  1080. {
  1081. IConstSuperFile &super = superFiles.item(i);
  1082. fprintf(stderr, " %s\n", super.getName());
  1083. StringArray &subfiles = super.getSubFiles();
  1084. if (subfiles.ordinality()>0)
  1085. {
  1086. ForEachItemIn(sbi, subfiles)
  1087. fprintf(stderr, " > %s\n", subfiles.item(sbi));
  1088. }
  1089. }
  1090. }
  1091. return ret;
  1092. }
  1093. virtual void usage()
  1094. {
  1095. fputs("\nUsage:\n"
  1096. "\n"
  1097. "The 'query-files' command will list the files referenced by a query, showing if/how they\n"
  1098. "are mapped as SuperFiles in the active packagemap. --pmid option allows an inactive\n"
  1099. "packagemap to be used instead.\n"
  1100. "\n"
  1101. "ecl packagemap query-files <target> <queryid>\n"
  1102. " Options:\n"
  1103. " <target> Name of target to use when validating package map information\n"
  1104. " <queryid> Name of query to get file mappings for\n"
  1105. " -pm, --pmid Optional id of packagemap to validate, defaults to active\n"
  1106. " --global-scope The specified packagemap can be shared across multiple targets\n",
  1107. stdout);
  1108. EclCmdCommon::usage();
  1109. }
  1110. private:
  1111. StringAttr optTarget;
  1112. StringAttr optQueryId;
  1113. StringAttr optPMID;
  1114. bool optGlobalScope;
  1115. };
  1116. class EclCmdPackageAddPart : public EclCmdCommon
  1117. {
  1118. public:
  1119. EclCmdPackageAddPart() : optDeletePrevious(false), optGlobalScope(false), optAllowForeign(false), optPreloadAll(false), optUpdateSuperfiles(false), optUpdateCloneFrom(false), optDontAppendCluster(false)
  1120. {
  1121. }
  1122. virtual eclCmdOptionMatchIndicator parseCommandLineOptions(ArgvIterator &iter)
  1123. {
  1124. if (iter.done())
  1125. return EclCmdOptionNoMatch;
  1126. for (; !iter.done(); iter.next())
  1127. {
  1128. const char *arg = iter.query();
  1129. if (*arg!='-')
  1130. {
  1131. if (optTarget.isEmpty())
  1132. optTarget.set(arg);
  1133. else if (optPMID.isEmpty())
  1134. optPMID.set(arg);
  1135. else if (optFileName.isEmpty())
  1136. optFileName.set(arg);
  1137. else
  1138. {
  1139. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  1140. return EclCmdOptionNoMatch;
  1141. }
  1142. continue;
  1143. }
  1144. if (iter.matchOption(optPartName, ECLOPT_PART_NAME))
  1145. continue;
  1146. if (iter.matchOption(optDaliIP, ECLOPT_DALIIP))
  1147. continue;
  1148. if (iter.matchOption(optSourceProcess, ECLOPT_SOURCE_PROCESS))
  1149. continue;
  1150. if (iter.matchFlag(optDeletePrevious, ECLOPT_DELETE_PREVIOUS))
  1151. continue;
  1152. if (iter.matchFlag(optGlobalScope, ECLOPT_GLOBAL_SCOPE))
  1153. continue;
  1154. if (iter.matchFlag(optAllowForeign, ECLOPT_ALLOW_FOREIGN))
  1155. continue;
  1156. if (iter.matchFlag(optPreloadAll, ECLOPT_PRELOAD_ALL_PACKAGES))
  1157. continue;
  1158. if (iter.matchFlag(optUpdateSuperfiles, ECLOPT_UPDATE_SUPER_FILES))
  1159. continue;
  1160. if (iter.matchFlag(optUpdateCloneFrom, ECLOPT_UPDATE_CLONE_FROM))
  1161. continue;
  1162. if (iter.matchFlag(optDontAppendCluster, ECLOPT_DONT_APPEND_CLUSTER))
  1163. continue;
  1164. eclCmdOptionMatchIndicator ind = EclCmdCommon::matchCommandLineOption(iter, true);
  1165. if (ind != EclCmdOptionMatch)
  1166. return ind;
  1167. }
  1168. return EclCmdOptionMatch;
  1169. }
  1170. virtual bool finalizeOptions(IProperties *globals)
  1171. {
  1172. if (!EclCmdCommon::finalizeOptions(globals))
  1173. {
  1174. usage();
  1175. return false;
  1176. }
  1177. StringBuffer err;
  1178. if (optFileName.isEmpty())
  1179. err.append("\n ... Missing package file name\n");
  1180. else if (optTarget.isEmpty())
  1181. err.append("\n ... Specify a cluster name\n");
  1182. else if (optPMID.isEmpty())
  1183. err.append("\n ... Specify a packagemap name\n");
  1184. if (err.length())
  1185. {
  1186. fprintf(stdout, "%s", err.str());
  1187. return false;
  1188. }
  1189. if (optPartName.isEmpty())
  1190. {
  1191. StringBuffer name;
  1192. splitFilename(optFileName.get(), NULL, NULL, &name, &name);
  1193. optPartName.set(name.str());
  1194. }
  1195. optPMID.toLowerCase();
  1196. return true;
  1197. }
  1198. virtual int processCMD()
  1199. {
  1200. Owned<IClientWsPackageProcess> packageProcessClient = createCmdClient(WsPackageProcess, *this);
  1201. StringBuffer content;
  1202. content.loadFile(optFileName);
  1203. fprintf(stdout, "\n ... adding packagemap %s part %s from file %s\n\n", optPMID.get(), optPartName.get(), optFileName.get());
  1204. Owned<IClientAddPartToPackageMapRequest> request = packageProcessClient->createAddPartToPackageMapRequest();
  1205. setCmdRequestTimeouts(request->rpc(), 0, optWaitConnectMs, optWaitReadSec);
  1206. request->setTarget(optTarget);
  1207. request->setPackageMap(optPMID);
  1208. request->setPartName(optPartName);
  1209. request->setContent(content);
  1210. request->setDeletePrevious(optDeletePrevious);
  1211. request->setDaliIp(optDaliIP);
  1212. request->setGlobalScope(optGlobalScope);
  1213. request->setSourceProcess(optSourceProcess);
  1214. request->setAllowForeignFiles(optAllowForeign);
  1215. request->setPreloadAllPackages(optPreloadAll);
  1216. request->setUpdateSuperFiles(optUpdateSuperfiles);
  1217. request->setUpdateCloneFrom(optUpdateCloneFrom);
  1218. request->setAppendCluster(!optDontAppendCluster);
  1219. Owned<IClientAddPartToPackageMapResponse> resp = packageProcessClient->AddPartToPackageMap(request);
  1220. int ret = outputMultiExceptionsEx(resp->getExceptions());
  1221. StringArray &notFound = resp->getFilesNotFound();
  1222. if (notFound.length())
  1223. {
  1224. fputs("\nFiles defined in packagemap part but not found in DFS:\n", stderr);
  1225. ForEachItemIn(i, notFound)
  1226. fprintf(stderr, " %s\n", notFound.item(i));
  1227. fputs("\n", stderr);
  1228. }
  1229. return ret;
  1230. }
  1231. virtual void usage()
  1232. {
  1233. fputs("\nUsage:\n"
  1234. "\n"
  1235. "The 'add-part' command will add the packagemap part to an existing packagemap\n"
  1236. "\n"
  1237. "ecl packagemap add-part [options] <target> <pmid> <filename>\n"
  1238. " <target> Name of target to use when adding packagemap part\n"
  1239. " <pmid> Identifier of packagemap to add the part to\n"
  1240. " <filename> Name of file containing packagemap part content\n"
  1241. " Options:\n"
  1242. " --part-name Name of part being added (defaults to filename)\n"
  1243. " --delete-prev Replace an existing part with matching name\n"
  1244. " --daliip=<ip> IP of the remote dali to use for logical file lookups\n"
  1245. " --global-scope The specified packagemap is shared across multiple targets\n"
  1246. " --source-process=<value> Process cluster to copy files from\n"
  1247. " --allow-foreign Do not fail if foreign files are used in packagemap\n"
  1248. " --preload-all Set preload files option for all packages\n"
  1249. " --update-super-files Update local DFS super-files if remote DALI has changed\n"
  1250. " --update-clone-from Update local clone from location if remote DALI has changed\n"
  1251. " --dont-append-cluster Only use to avoid locking issues due to adding cluster to file\n",
  1252. stdout);
  1253. EclCmdCommon::usage();
  1254. }
  1255. private:
  1256. StringAttr optPMID;
  1257. StringAttr optTarget;
  1258. StringAttr optDaliIP;
  1259. StringAttr optSourceProcess;
  1260. StringAttr optPartName;
  1261. StringAttr optFileName;
  1262. bool optDeletePrevious;
  1263. bool optGlobalScope;
  1264. bool optAllowForeign;
  1265. bool optPreloadAll;
  1266. bool optUpdateSuperfiles;
  1267. bool optUpdateCloneFrom;
  1268. bool optDontAppendCluster;
  1269. };
  1270. class EclCmdPackageRemovePart : public EclCmdCommon
  1271. {
  1272. public:
  1273. EclCmdPackageRemovePart()
  1274. {
  1275. }
  1276. virtual eclCmdOptionMatchIndicator parseCommandLineOptions(ArgvIterator &iter)
  1277. {
  1278. if (iter.done())
  1279. return EclCmdOptionNoMatch;
  1280. for (; !iter.done(); iter.next())
  1281. {
  1282. const char *arg = iter.query();
  1283. if (*arg!='-')
  1284. {
  1285. if (!optTarget.length())
  1286. optTarget.set(arg);
  1287. else if (!optPMID.length())
  1288. optPMID.set(arg);
  1289. else if (!optPartName.length())
  1290. optPartName.set(arg);
  1291. else
  1292. {
  1293. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  1294. return EclCmdOptionNoMatch;
  1295. }
  1296. continue;
  1297. }
  1298. if (iter.matchFlag(optGlobalScope, ECLOPT_GLOBAL_SCOPE))
  1299. continue;
  1300. eclCmdOptionMatchIndicator ind = EclCmdCommon::matchCommandLineOption(iter, true);
  1301. if (ind != EclCmdOptionMatch)
  1302. return ind;
  1303. }
  1304. return EclCmdOptionMatch;
  1305. }
  1306. virtual bool finalizeOptions(IProperties *globals)
  1307. {
  1308. if (!EclCmdCommon::finalizeOptions(globals))
  1309. {
  1310. usage();
  1311. return false;
  1312. }
  1313. StringBuffer err;
  1314. if (optPMID.isEmpty())
  1315. err.append("\n ... Missing package map name\n");
  1316. else if (optPartName.isEmpty())
  1317. err.append("\n ... Missing part name\n");
  1318. else if (optTarget.isEmpty())
  1319. err.append("\n ... Specify a target cluster name\n");
  1320. if (err.length())
  1321. {
  1322. fprintf(stdout, "%s", err.str());
  1323. return false;
  1324. }
  1325. return true;
  1326. }
  1327. virtual int processCMD()
  1328. {
  1329. fprintf(stdout, "\n ... removing part %s from packagemap %s\n\n", optPartName.get(), optPMID.get());
  1330. Owned<IClientWsPackageProcess> packageProcessClient = createCmdClient(WsPackageProcess, *this);
  1331. Owned<IClientRemovePartFromPackageMapRequest> request = packageProcessClient->createRemovePartFromPackageMapRequest();
  1332. setCmdRequestTimeouts(request->rpc(), 0, optWaitConnectMs, optWaitReadSec);
  1333. request->setTarget(optTarget);
  1334. request->setPackageMap(optPMID);
  1335. request->setGlobalScope(optGlobalScope);
  1336. request->setPartName(optPartName);
  1337. Owned<IClientRemovePartFromPackageMapResponse> resp = packageProcessClient->RemovePartFromPackageMap(request);
  1338. int ret = outputMultiExceptionsEx(resp->getExceptions());
  1339. if (ret == 0)
  1340. printf("Successfully removed part %s from package %s\n", optPartName.get(), optPMID.get());
  1341. return ret;
  1342. }
  1343. virtual void usage()
  1344. {
  1345. fputs("\nUsage:\n"
  1346. "\n"
  1347. "The 'remove-part' command will remove the given part from the given packagemap\n"
  1348. "\n"
  1349. "ecl packagemap remove-part <target> <packagemap> <partname>\n"
  1350. " <target> Name of the target to use \n"
  1351. " <packagemap> Name of the package map containing the part\n"
  1352. " <partname> Name of the part to remove\n"
  1353. " Options:\n"
  1354. " --global-scope The specified packagemap is sharable across multiple targets\n",
  1355. stdout);
  1356. EclCmdCommon::usage();
  1357. }
  1358. private:
  1359. StringAttr optTarget;
  1360. StringAttr optPMID;
  1361. StringAttr optPartName;
  1362. bool optGlobalScope;
  1363. };
  1364. class EclCmdPackageGetPart: public EclCmdCommon
  1365. {
  1366. public:
  1367. EclCmdPackageGetPart()
  1368. {
  1369. }
  1370. virtual eclCmdOptionMatchIndicator parseCommandLineOptions(ArgvIterator &iter)
  1371. {
  1372. if (iter.done())
  1373. return EclCmdOptionNoMatch;
  1374. for (; !iter.done(); iter.next())
  1375. {
  1376. const char *arg = iter.query();
  1377. if (*arg!='-')
  1378. {
  1379. if (!optTarget.length())
  1380. optTarget.set(arg);
  1381. else if (!optPMID.length())
  1382. optPMID.set(arg);
  1383. else if (!optPartName.length())
  1384. optPartName.set(arg);
  1385. else
  1386. {
  1387. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  1388. return EclCmdOptionNoMatch;
  1389. }
  1390. continue;
  1391. }
  1392. if (iter.matchFlag(optGlobalScope, ECLOPT_GLOBAL_SCOPE))
  1393. continue;
  1394. eclCmdOptionMatchIndicator ind = EclCmdCommon::matchCommandLineOption(iter, true);
  1395. if (ind != EclCmdOptionMatch)
  1396. return ind;
  1397. }
  1398. return EclCmdOptionMatch;
  1399. }
  1400. virtual bool finalizeOptions(IProperties *globals)
  1401. {
  1402. if (!EclCmdCommon::finalizeOptions(globals))
  1403. {
  1404. usage();
  1405. return false;
  1406. }
  1407. StringBuffer err;
  1408. if (optPMID.isEmpty())
  1409. err.append("\n ... Missing package map name\n");
  1410. else if (optPartName.isEmpty())
  1411. err.append("\n ... Missing part name\n");
  1412. else if (optTarget.isEmpty())
  1413. err.append("\n ... Specify a target cluster name\n");
  1414. if (err.length())
  1415. {
  1416. fprintf(stdout, "%s", err.str());
  1417. return false;
  1418. }
  1419. return true;
  1420. }
  1421. virtual int processCMD()
  1422. {
  1423. Owned<IClientWsPackageProcess> packageProcessClient = createCmdClient(WsPackageProcess, *this);
  1424. Owned<IClientGetPartFromPackageMapRequest> request = packageProcessClient->createGetPartFromPackageMapRequest();
  1425. setCmdRequestTimeouts(request->rpc(), 0, optWaitConnectMs, optWaitReadSec);
  1426. request->setTarget(optTarget);
  1427. request->setPackageMap(optPMID);
  1428. request->setGlobalScope(optGlobalScope);
  1429. request->setPartName(optPartName);
  1430. Owned<IClientGetPartFromPackageMapResponse> resp = packageProcessClient->GetPartFromPackageMap(request);
  1431. int ret = outputMultiExceptionsEx(resp->getExceptions());
  1432. if (ret == 0)
  1433. printf("%s", resp->getContent());
  1434. return ret;
  1435. }
  1436. virtual void usage()
  1437. {
  1438. fputs("\nUsage:\n"
  1439. "\n"
  1440. "The 'get-part' command will fetch the given part from the given packagemap\n"
  1441. "\n"
  1442. "ecl packagemap get-part <target> <packagemap> <partname>\n"
  1443. " <target> Name of the target to use \n"
  1444. " <packagemap> Name of the package map containing the part\n"
  1445. " <partname> Name of the part to get\n"
  1446. " Options:\n"
  1447. " --global-scope The specified packagemap is sharable across multiple targets\n",
  1448. stdout);
  1449. EclCmdCommon::usage();
  1450. }
  1451. private:
  1452. StringAttr optTarget;
  1453. StringAttr optPMID;
  1454. StringAttr optPartName;
  1455. bool optGlobalScope;
  1456. };
  1457. IEclCommand *createPackageSubCommand(const char *cmdname)
  1458. {
  1459. if (!cmdname || !*cmdname)
  1460. return NULL;
  1461. if (strieq(cmdname, "add"))
  1462. return new EclCmdPackageAdd();
  1463. if (strieq(cmdname, "copy"))
  1464. return new EclCmdPackageMapCopy();
  1465. if (strieq(cmdname, "delete"))
  1466. return new EclCmdPackageDelete();
  1467. if (strieq(cmdname, "activate"))
  1468. return new EclCmdPackageActivate();
  1469. if (strieq(cmdname, "deactivate"))
  1470. return new EclCmdPackageDeActivate();
  1471. if (strieq(cmdname, "info"))
  1472. return new EclCmdPackageInfo();
  1473. if (strieq(cmdname, "list"))
  1474. return new EclCmdPackageList();
  1475. if (strieq(cmdname, "validate"))
  1476. return new EclCmdPackageValidate();
  1477. if (strieq(cmdname, "query-files"))
  1478. return new EclCmdPackageQueryFiles();
  1479. if (strieq(cmdname, "add-part"))
  1480. return new EclCmdPackageAddPart();
  1481. if (strieq(cmdname, "remove-part"))
  1482. return new EclCmdPackageRemovePart();
  1483. if (strieq(cmdname, "get-part"))
  1484. return new EclCmdPackageGetPart();
  1485. return NULL;
  1486. }
  1487. //=========================================================================================
  1488. class PackageCMDShell : public EclCMDShell
  1489. {
  1490. public:
  1491. PackageCMDShell(int argc, const char *argv[], EclCommandFactory _factory, const char *_version)
  1492. : EclCMDShell(argc, argv, _factory, _version)
  1493. {
  1494. }
  1495. virtual void usage()
  1496. {
  1497. fprintf(stdout,"\nUsage:\n\n"
  1498. "ecl packagemap <command> [command options]\n\n"
  1499. " packagemap Commands:\n"
  1500. " add Add a package map to the environment\n"
  1501. " copy Copy a package map from one target to another\n"
  1502. " delete Delete a package map\n"
  1503. " activate Activate a package map\n"
  1504. " deactivate Deactivate a package map (package map will not get loaded)\n"
  1505. " list List loaded package map names\n"
  1506. " info Return active package map information\n"
  1507. " validate Validate information in the package map file \n"
  1508. " query-files Show files used by a query and if/how they are mapped\n"
  1509. " add-part Add additional packagemap content to an existing packagemap\n"
  1510. " get-part Get the content of a packagemap part from a packagemap\n"
  1511. " remove-part Remove a packagemap part from a packagemap\n"
  1512. );
  1513. }
  1514. };
  1515. static int doMain(int argc, const char *argv[])
  1516. {
  1517. PackageCMDShell processor(argc, argv, createPackageSubCommand, hpccBuildTag);
  1518. return processor.run();
  1519. }
  1520. int main(int argc, const char *argv[])
  1521. {
  1522. InitModuleObjects();
  1523. queryStderrLogMsgHandler()->setMessageFields(0);
  1524. unsigned exitCode = doMain(argc, argv);
  1525. releaseAtoms();
  1526. exit(exitCode);
  1527. }