esdl-publish.cpp 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2013 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include "jliball.hpp"
  14. #include "esdl_def.hpp"
  15. #include "esdlcmd_common.hpp"
  16. #include "esdlcmd_core.hpp"
  17. #include "esdlcmdutils.hpp"
  18. class EsdlPublishCmdCommon : public EsdlCmdCommon
  19. {
  20. protected:
  21. StringAttr optSource;
  22. StringAttr optService;
  23. StringAttr optWSProcAddress;
  24. StringAttr optWSProcPort;
  25. StringAttr optUser;
  26. StringAttr optPass;
  27. StringAttr optESDLDefID;
  28. StringAttr optESDLService;
  29. StringAttr optTargetESPProcName;
  30. StringAttr optTargetAddress;
  31. StringAttr optTargetPort;
  32. bool optOverWrite;
  33. Owned<EsdlCmdHelper> esdlHelper;
  34. public:
  35. EsdlPublishCmdCommon() : optWSProcAddress("."), optWSProcPort("8010")
  36. {
  37. esdlHelper.setown(EsdlCmdHelper::createEsdlHelper());
  38. }
  39. virtual int processCMD() = 0;
  40. virtual bool parseCommandLineOptions(ArgvIterator &iter)
  41. {
  42. if (iter.done())
  43. {
  44. usage();
  45. return false;
  46. }
  47. for (; !iter.done(); iter.next())
  48. {
  49. if (parseCommandLineOption(iter))
  50. continue;
  51. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  52. return false;
  53. }
  54. return true;
  55. }
  56. virtual void usage()
  57. {
  58. printf(
  59. " -s, --server <ip> IP of server running WsESDLConfig service\n"
  60. " --port <port> WsESDLConfig service port\n"
  61. " -u, --username <name> Username for accessing WsESDLConfig service\n"
  62. " -pw, --password <pw> Password for accessing WsESDLConfig service\n"
  63. );
  64. EsdlCmdCommon::usage();
  65. }
  66. virtual bool parseCommandLineOption(ArgvIterator &iter)
  67. {
  68. if (iter.matchFlag(optSource, ESDL_CONVERT_SOURCE))
  69. return true;
  70. if (iter.matchFlag(optService, ESDLOPT_SERVICE))
  71. return true;
  72. if (iter.matchFlag(optWSProcAddress, ESDL_OPT_SERVICE_SERVER) || iter.matchFlag(optWSProcAddress, ESDL_OPTION_SERVICE_SERVER))
  73. return true;
  74. if (iter.matchFlag(optWSProcPort, ESDL_OPTION_SERVICE_PORT) || iter.matchFlag(optWSProcPort, ESDL_OPT_SERVICE_PORT))
  75. return true;
  76. if (iter.matchFlag(optUser, ESDL_OPT_SERVICE_USER) || iter.matchFlag(optUser, ESDL_OPTION_SERVICE_USER))
  77. return true;
  78. if (iter.matchFlag(optPass, ESDL_OPT_SERVICE_PASS) || iter.matchFlag(optPass, ESDL_OPTION_SERVICE_PASS))
  79. return true;
  80. if (iter.matchFlag(optOverWrite, ESDL_OPTION_OVERWRITE) )
  81. return true;
  82. return false;
  83. }
  84. virtual bool finalizeOptions(IProperties *globals)
  85. {
  86. if (optWSProcAddress.isEmpty())
  87. throw MakeStringException( 0, "Server address of WsESDLConfig process server must be provided" );
  88. if (optWSProcPort.isEmpty())
  89. throw MakeStringException( 0, "Port on which WsESDLConfig is listening must be provided" );
  90. return true;
  91. }
  92. };
  93. class EsdlPublishCmd : public EsdlPublishCmdCommon
  94. {
  95. public:
  96. int processCMD()
  97. {
  98. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  99. Owned<IClientPublishESDLDefinitionRequest> request = esdlConfigClient->createPublishESDLDefinitionRequest();
  100. StringBuffer esxml;
  101. esdlHelper->getServiceESXDL(optSource.get(), optESDLService.get(), esxml, 0, NULL, (DEPFLAG_INCLUDE_TYPES & ~DEPFLAG_INCLUDE_METHOD), optIncludePath.str(), optTraceFlags());
  102. if (esxml.length()==0)
  103. {
  104. fprintf(stderr,"\nESDL Definition for service %s could not be loaded from: %s\n", optESDLService.get(), optSource.get());
  105. return -1;
  106. }
  107. if (optESDLService.length() != 0)
  108. request->setServiceName(optESDLService.get());
  109. if (optVerbose)
  110. fprintf(stdout,"\nESDL Definition: \n%s\n", esxml.str());
  111. request->setXMLDefinition(esxml.str());
  112. request->setDeletePrevious(optOverWrite);
  113. Owned<IClientPublishESDLDefinitionResponse> resp = esdlConfigClient->PublishESDLDefinition(request);
  114. bool validateMessages = false;
  115. if (resp->getExceptions().ordinality()>0)
  116. {
  117. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  118. return 1;
  119. }
  120. StringBuffer message;
  121. if (optESDLService.length() > 0)
  122. message.setf("ESDL Service: %s: %s", optESDLService.get(), resp->getStatus().getDescription());
  123. else
  124. message.set(resp->getStatus().getDescription());
  125. outputWsStatus(resp->getStatus().getCode(), message.str());
  126. return 0;
  127. }
  128. void usage()
  129. {
  130. printf("\nUsage:\n\n"
  131. "esdl publish <filename.(ecm|esdl|xml)> <servicename> [command options]\n\n"
  132. " <filename.(ecm|esdl|xml)> The ESDL file containing service definition in esdl format (.ecm |.esdl) or in esxdl format (.xml) \n"
  133. " <servicename> The ESDL defined ESP service to publish. Optional.\n"
  134. "Options (use option flag followed by appropriate value):\n"
  135. " --overwrite Overwrite the latest version of this ESDL Definition\n"
  136. ESDLOPT_INCLUDE_PATH_USAGE
  137. );
  138. EsdlPublishCmdCommon::usage();
  139. }
  140. bool parseCommandLineOptions(ArgvIterator &iter)
  141. {
  142. if (iter.done())
  143. {
  144. usage();
  145. return false;
  146. }
  147. //First parameter is required
  148. //<filename.(ecm|esdl|xml)> The ESDL file containing service definition\n"
  149. //Second parameter is now optional but can cause request to fail if not provided
  150. //<servicename>
  151. for (int cur = 0; cur < 2 && !iter.done(); cur++)
  152. {
  153. const char *arg = iter.query();
  154. if (*arg != '-')
  155. {
  156. switch (cur)
  157. {
  158. case 0:
  159. optSource.set(arg);
  160. break;
  161. case 1:
  162. optESDLService.set(arg);
  163. break;
  164. }
  165. }
  166. else
  167. {
  168. if (optSource.isEmpty())
  169. {
  170. fprintf(stderr, "\nOption detected before required arguments: %s\n", arg);
  171. usage();
  172. return false;
  173. }
  174. else
  175. {
  176. fprintf(stderr, "\nWarning: Target ESDL Service was not specified, this request will fail if ESDL definition contains multiple \n");
  177. break;
  178. }
  179. }
  180. iter.next();
  181. }
  182. for (; !iter.done(); iter.next())
  183. {
  184. if (parseCommandLineOption(iter))
  185. continue;
  186. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  187. return false;
  188. }
  189. return true;
  190. }
  191. bool parseCommandLineOption(ArgvIterator &iter)
  192. {
  193. StringAttr oneOption;
  194. if (iter.matchOption(oneOption, ESDLOPT_INCLUDE_PATH) || iter.matchOption(oneOption, ESDLOPT_INCLUDE_PATH_S))
  195. {
  196. if(optIncludePath.length() > 0)
  197. optIncludePath.append(ENVSEPSTR);
  198. optIncludePath.append(oneOption.get());
  199. return true;
  200. }
  201. if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
  202. return true;
  203. return false;
  204. }
  205. bool finalizeOptions(IProperties *globals)
  206. {
  207. extractEsdlCmdOption(optIncludePath, globals, ESDLOPT_INCLUDE_PATH_ENV, ESDLOPT_INCLUDE_PATH_INI, NULL, NULL);
  208. if (optSource.isEmpty())
  209. throw MakeStringException( 0, "Source ESDL definition file (ecm|esdl|xml) must be provided" );
  210. return EsdlPublishCmdCommon::finalizeOptions(globals);
  211. }
  212. private:
  213. StringBuffer optIncludePath;
  214. };
  215. class EsdlBindServiceCmd : public EsdlPublishCmdCommon
  216. {
  217. protected:
  218. StringAttr optBindingName;
  219. StringAttr optPortOrName;
  220. StringAttr optInput;
  221. public:
  222. int processCMD()
  223. {
  224. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  225. Owned<IClientPublishESDLBindingRequest> request = esdlConfigClient->createPublishESDLBindingRequest();
  226. fprintf(stdout,"\nAttempting to publish ESDL binding on process %s %s %s\n", optTargetESPProcName.get(), optBindingName.length() > 0?"binding":"port", optPortOrName.get());
  227. request->setEspProcName(optTargetESPProcName);
  228. if (optBindingName.length() > 0)
  229. request->setEspBindingName(optBindingName.str());
  230. if (optTargetPort.length() > 0)
  231. request->setEspPort(optTargetPort);
  232. request->setEsdlServiceName(optESDLService);
  233. request->setEsdlDefinitionID(optESDLDefID);
  234. request->setConfig(optInput);
  235. request->setOverwrite(optOverWrite);
  236. if (optVerbose)
  237. fprintf(stdout,"\nMethod config: %s\n", optInput.get());
  238. Owned<IClientPublishESDLBindingResponse> resp = esdlConfigClient->PublishESDLBinding(request);
  239. if (resp->getExceptions().ordinality()>0)
  240. {
  241. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  242. return 1;
  243. }
  244. outputWsStatus(resp->getStatus().getCode(), resp->getStatus().getDescription());
  245. return 0;
  246. }
  247. void usage()
  248. {
  249. printf( "\nUsage:\n\n"
  250. "esdl bind-service <TargetESPProcessName> <TargetESPBindingPort | TargetESPBindingName> <ESDLDefinitionId> (<ESDLServiceName>) [command options]\n\n"
  251. " TargetESPProcessName The target ESP Process name\n"
  252. " TargetESPBindingPort | TargetESPBindingName Either target ESP binding port or target ESP binding name\n"
  253. " ESDLDefinitionId The Name and version of the ESDL definition to bind to this service (must already be defined in dali.)\n"
  254. " ESDLServiceName The Name of the ESDL Service (as defined in the ESDL Definition)"
  255. " *Required if ESDL definition contains multiple services\n"
  256. "\nOptions (use option flag followed by appropriate value):\n"
  257. " --config <file|\"xml\"> Configuration XML for all methods associated with the target Service\n"
  258. " --overwrite Overwrite binding if it already exists\n");
  259. EsdlPublishCmdCommon::usage();
  260. printf( "\n Use this command to publish ESDL Service based bindings.\n"
  261. " To bind an ESDL Service, provide the target ESP process name\n"
  262. " (ESP Process which will host the ESP Service as defined in the ESDL Definition.) \n"
  263. " It is also necessary to provide either the Port on which this service is configured to run (ESP Binding),\n"
  264. " or the name of the service you are binding.\n"
  265. " Optionally provide configuration information either directly, or via a\n"
  266. " configuration file in the following syntax:\n"
  267. " <Methods>\n"
  268. " \t<Method name=\"myMethod\" url=\"http://10.45.22.1:292/somepath?someparam=value\" user=\"myuser\" password=\"mypass\"/>\n"
  269. " \t<Method name=\"myMethod2\" url=\"http://10.45.22.1:292/somepath?someparam=value\" user=\"myuser\" password=\"mypass\"/>\n"
  270. " </Methods>\n"
  271. );
  272. printf("\nExample:"
  273. ">esdl bind-service myesp 8088 WsMyService --config /myService/methods.xml\n"
  274. );
  275. }
  276. bool parseCommandLineOptions(ArgvIterator &iter)
  277. {
  278. if (iter.done())
  279. {
  280. usage();
  281. return false;
  282. }
  283. //First 3 parameter's order is fixed.
  284. //TargetESPProcessName
  285. //TargetESPBindingPort | TargetESPServiceName
  286. //ESDLDefinitionId
  287. //4th param is now optional, absence can cause failure
  288. //ESDLServiceName
  289. for (int cur = 0; cur < 4 && !iter.done(); cur++)
  290. {
  291. const char *arg = iter.query();
  292. if (*arg != '-')
  293. {
  294. switch (cur)
  295. {
  296. case 0:
  297. optTargetESPProcName.set(arg);
  298. break;
  299. case 1:
  300. optPortOrName.set(arg);
  301. break;
  302. case 2:
  303. optESDLDefID.set(arg);
  304. break;
  305. case 3:
  306. optESDLService.set(arg);
  307. break;
  308. }
  309. }
  310. else
  311. {
  312. if (cur < 3)
  313. {
  314. fprintf(stderr, "\nOption detected before required arguments: %s\n", arg);
  315. usage();
  316. return false;
  317. }
  318. else
  319. {
  320. fprintf(stderr, "\nWarning ESDL Service name not provided. Can cause failure if ESDL definition contains multiple services\n");
  321. break;
  322. }
  323. }
  324. iter.next();
  325. }
  326. for (; !iter.done(); iter.next())
  327. {
  328. if (parseCommandLineOption(iter))
  329. continue;
  330. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  331. return false;
  332. }
  333. return true;
  334. }
  335. bool parseCommandLineOption(ArgvIterator &iter)
  336. {
  337. if (iter.matchFlag(optInput, ESDL_OPTION_CONFIG) )
  338. return true;
  339. if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
  340. return true;
  341. return false;
  342. }
  343. bool finalizeOptions(IProperties *globals)
  344. {
  345. if (optInput.length())
  346. {
  347. const char *in = optInput.get();
  348. while (*in && isspace(*in)) in++;
  349. if (*in!='<')
  350. {
  351. StringBuffer content;
  352. content.loadFile(in);
  353. optInput.set(content.str());
  354. }
  355. }
  356. if (optESDLDefID.isEmpty())
  357. throw MakeStringException( 0, "ESDL definition ID must be provided!" );
  358. if (optESDLService.isEmpty())
  359. fprintf(stderr, "Warning: ESDL service definition name was not provided. Request will fail if ESDL def contains multiple service defined.");
  360. if(optTargetESPProcName.isEmpty())
  361. throw MakeStringException( 0, "Name of Target ESP process must be provided!" );
  362. if (optPortOrName.isEmpty())
  363. throw MakeStringException( 0, "Either the target ESP service port of name must be provided!" );
  364. else
  365. {
  366. const char * portorname = optPortOrName.get();
  367. isdigit(*portorname) ? optTargetPort.set(portorname) : optBindingName.set(portorname);
  368. }
  369. return EsdlPublishCmdCommon::finalizeOptions(globals);
  370. }
  371. };
  372. class EsdlUnBindServiceCmd : public EsdlPublishCmdCommon
  373. {
  374. protected:
  375. StringAttr optEspBinding;
  376. StringAttr optBindingId;
  377. public:
  378. int processCMD()
  379. {
  380. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  381. Owned<IClientDeleteESDLBindingRequest> request = esdlConfigClient->createDeleteESDLBindingRequest();
  382. fprintf(stdout,"\nAttempting to un-bind ESDL Service: '%s'\n", optBindingId.get());
  383. request->setId(optBindingId);
  384. Owned<IClientDeleteESDLRegistryEntryResponse> resp = esdlConfigClient->DeleteESDLBinding(request);
  385. if (resp->getExceptions().ordinality()>0)
  386. {
  387. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  388. return 1;
  389. }
  390. outputWsStatus(resp->getStatus().getCode(), resp->getStatus().getDescription());
  391. return 0;
  392. }
  393. void usage()
  394. {
  395. printf( "\nUsage:\n\n"
  396. "esdl unbind-service <EsdlBindingId> [command options]\n\n"
  397. " EsdlBindingId Id of the esdl binding\n"
  398. "\n\nOptions:\n"
  399. );
  400. EsdlPublishCmdCommon::usage();
  401. printf( "\n Use this command to unbind ESDL service based bindings.\n"
  402. " To unbind a given ESDL binding, provide the esdl binding id\n"
  403. " Available ESDL bindings to unbind can be found via the '>esdl list-bindings' command."
  404. );
  405. printf("\nExample:"
  406. ">esdl unbind-service myesp.8003.EsdlExample \n"
  407. );
  408. }
  409. bool parseCommandLineOptions(ArgvIterator &iter)
  410. {
  411. if (iter.done())
  412. {
  413. usage();
  414. return false;
  415. }
  416. for (int cur = 0; cur < 1 && !iter.done(); cur++)
  417. {
  418. const char *arg = iter.query();
  419. if (*arg != '-')
  420. {
  421. switch (cur)
  422. {
  423. case 0:
  424. optBindingId.set(arg);
  425. break;
  426. }
  427. }
  428. else
  429. {
  430. fprintf(stderr, "\nOption detected before required arguments: %s\n", arg);
  431. usage();
  432. return false;
  433. }
  434. iter.next();
  435. }
  436. for (; !iter.done(); iter.next())
  437. {
  438. if (parseCommandLineOption(iter))
  439. continue;
  440. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  441. return false;
  442. }
  443. return true;
  444. }
  445. bool parseCommandLineOption(ArgvIterator &iter)
  446. {
  447. if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
  448. return true;
  449. return false;
  450. }
  451. bool finalizeOptions(IProperties *globals)
  452. {
  453. if (optBindingId.isEmpty())
  454. throw MakeStringException( 0, "Esdl binding id must be provided!" );
  455. return EsdlPublishCmdCommon::finalizeOptions(globals);
  456. }
  457. };
  458. class EsdlDeleteESDLDefCmd : public EsdlPublishCmdCommon
  459. {
  460. public:
  461. int processCMD()
  462. {
  463. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  464. Owned<IClientDeleteESDLDefinitionRequest> request = esdlConfigClient->createDeleteESDLDefinitionRequest();
  465. fprintf(stdout,"\nAttempting to delete ESDL definition: '%s'\n", optESDLDefID.get());
  466. request->setId(optESDLDefID.get());
  467. Owned<IClientDeleteESDLRegistryEntryResponse> resp = esdlConfigClient->DeleteESDLDefinition(request);
  468. if (resp->getExceptions().ordinality()>0)
  469. {
  470. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  471. return 1;
  472. }
  473. outputWsStatus(resp->getStatus().getCode(), resp->getStatus().getDescription());
  474. return 0;
  475. }
  476. void usage()
  477. {
  478. printf( "\nUsage:\n\n"
  479. "esdl delete <ESDLDefinitionID> [command options]\n\n"
  480. " ESDLDefinitionID The ESDL definition id <esdldefname>.<esdldefver>\n");
  481. EsdlPublishCmdCommon::usage();
  482. printf( "\n Use this command to delete an ESDL Service definition.\n"
  483. " To delete an ESDL Service definition, provide the ESDL definition id\n"
  484. );
  485. printf("\nExample:"
  486. ">esdl delete myesdldef.5\n"
  487. );
  488. }
  489. bool parseCommandLineOptions(ArgvIterator &iter)
  490. {
  491. if (iter.done())
  492. {
  493. usage();
  494. return false;
  495. }
  496. for (int cur = 0; cur < 1 && !iter.done(); cur++)
  497. {
  498. const char *arg = iter.query();
  499. if (*arg != '-')
  500. {
  501. switch (cur)
  502. {
  503. case 0:
  504. optESDLDefID.set(arg);
  505. break;
  506. }
  507. }
  508. else
  509. {
  510. fprintf(stderr, "\nOption detected before required arguments: %s\n", arg);
  511. usage();
  512. return false;
  513. }
  514. iter.next();
  515. }
  516. for (; !iter.done(); iter.next())
  517. {
  518. if (parseCommandLineOption(iter))
  519. continue;
  520. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  521. return false;
  522. }
  523. return true;
  524. }
  525. bool parseCommandLineOption(ArgvIterator &iter)
  526. {
  527. if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
  528. return true;
  529. return false;
  530. }
  531. bool finalizeOptions(IProperties *globals)
  532. {
  533. if (optESDLDefID.isEmpty())
  534. throw MakeStringException( 0, "ESDLDefinitionID must be provided!" );
  535. return EsdlPublishCmdCommon::finalizeOptions(globals);
  536. }
  537. };
  538. class EsdlListESDLDefCmd : public EsdlPublishCmdCommon
  539. {
  540. public:
  541. int processCMD()
  542. {
  543. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  544. Owned<IClientListESDLDefinitionsRequest> req = esdlConfigClient->createListESDLDefinitionsRequest();
  545. fprintf(stdout,"\nAttempting to list ESDL definitions.\n");
  546. Owned<IClientListESDLDefinitionsResponse> resp = esdlConfigClient->ListESDLDefinitions(req);
  547. if (resp->getExceptions().ordinality()>0)
  548. {
  549. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  550. return 1;
  551. }
  552. IArrayOf<IConstESDLDefinition> & defs = resp->getDefinitions();
  553. if (defs.length() > 0)
  554. fprintf(stdout, "\nESDL Definitions found:\n");
  555. ForEachItemIn(defindex, defs)
  556. {
  557. IConstESDLDefinition & def = defs.item(defindex);
  558. fprintf(stdout, "\t%s \n", def.getId());
  559. }
  560. return 0;
  561. }
  562. void usage()
  563. {
  564. printf( "\nUsage:\n\n"
  565. "esdl list-definitions [command options]\n\n"
  566. );
  567. EsdlPublishCmdCommon::usage();
  568. }
  569. bool parseCommandLineOptions(ArgvIterator &iter)
  570. {
  571. for (; !iter.done(); iter.next())
  572. {
  573. if (parseCommandLineOption(iter))
  574. continue;
  575. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  576. return false;
  577. }
  578. return true;
  579. }
  580. bool parseCommandLineOption(ArgvIterator &iter)
  581. {
  582. if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
  583. return true;
  584. return false;
  585. }
  586. bool finalizeOptions(IProperties *globals)
  587. {
  588. return EsdlPublishCmdCommon::finalizeOptions(globals);
  589. }
  590. };
  591. class EsdlListESDLBindingsCmd : public EsdlPublishCmdCommon
  592. {
  593. public:
  594. int processCMD()
  595. {
  596. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  597. Owned<IClientListESDLBindingsRequest> req = esdlConfigClient->createListESDLBindingsRequest();
  598. fprintf(stdout,"\nAttempting to list ESDL bindings.\n");
  599. Owned<IClientListESDLBindingsResponse> resp = esdlConfigClient->ListESDLBindings(req);
  600. if (resp->getExceptions().ordinality()>0)
  601. {
  602. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  603. return 1;
  604. }
  605. bool found = false;
  606. IArrayOf<IConstEspProcessStruct> & processes = resp->getEspProcesses();
  607. ForEachItemIn(procInd, processes)
  608. {
  609. IConstEspProcessStruct& process = processes.item(procInd);
  610. IArrayOf<IConstEspPortStruct>& ports = process.getPorts();
  611. ForEachItemIn(portInd, ports)
  612. {
  613. IConstEspPortStruct& port = ports.item(portInd);
  614. IArrayOf<IConstESDLBinding>& bindings = port.getBindings();
  615. ForEachItemIn(bindInd, bindings)
  616. {
  617. IConstESDLBinding& binding = bindings.item(bindInd);
  618. if (!found)
  619. {
  620. found = true;
  621. fprintf(stdout, "\nESDL bindings found:\n");
  622. }
  623. fprintf(stdout, "\t%s\n", binding.getId());
  624. }
  625. }
  626. }
  627. if (!found)
  628. fprintf(stdout, "\nNo ESDL binding found.\n");
  629. return 0;
  630. }
  631. void usage()
  632. {
  633. printf( "\nUsage:\n\n"
  634. "esdl list-bindings [command options]\n\n"
  635. );
  636. EsdlPublishCmdCommon::usage();
  637. }
  638. bool parseCommandLineOptions(ArgvIterator &iter)
  639. {
  640. for (; !iter.done(); iter.next())
  641. {
  642. if (parseCommandLineOption(iter))
  643. continue;
  644. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  645. return false;
  646. }
  647. return true;
  648. }
  649. bool parseCommandLineOption(ArgvIterator &iter)
  650. {
  651. if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
  652. return true;
  653. return false;
  654. }
  655. bool finalizeOptions(IProperties *globals)
  656. {
  657. return EsdlPublishCmdCommon::finalizeOptions(globals);
  658. }
  659. };
  660. class EsdlBindMethodCmd : public EsdlBindServiceCmd
  661. {
  662. protected:
  663. StringAttr optMethod;
  664. StringAttr optBindingId;
  665. public:
  666. int processCMD()
  667. {
  668. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  669. Owned<IClientConfigureESDLBindingMethodRequest> request = esdlConfigClient->createConfigureESDLBindingMethodRequest();
  670. fprintf(stdout,"\nAttempting to configure Method : '%s' for binding '%s'\n", optMethod.get(), optBindingId.get());
  671. request->setEsdlBindingId(optBindingId.get());
  672. request->setMethodName(optMethod.get());
  673. request->setConfig(optInput);
  674. request->setOverwrite(optOverWrite);
  675. if (optVerbose)
  676. fprintf(stdout,"\nMethod config: %s\n", optInput.get());
  677. Owned<IClientConfigureESDLBindingMethodResponse> resp = esdlConfigClient->ConfigureESDLBindingMethod(request);
  678. if (resp->getExceptions().ordinality()>0)
  679. {
  680. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  681. return 1;
  682. }
  683. outputWsStatus(resp->getStatus().getCode(), resp->getStatus().getDescription());
  684. return 0;
  685. }
  686. void usage()
  687. {
  688. printf( "\nUsage:\n\n"
  689. "esdl bind-method <TargetESDLBindingID> <TargetMethodName> [command options]\n\n"
  690. " TargetESDLBindingID The id of the target ESDL binding (must exist in dali)\n"
  691. " TargetMethodName The name of the target method (must exist in the service ESDL definition)\n"
  692. "\nOptions (use option flag followed by appropriate value):\n"
  693. " --config <file|xml> Configuration XML for all methods associated with the target Service\n"
  694. " --overwrite Overwrite binding if it already exists\n");
  695. EsdlPublishCmdCommon::usage();
  696. printf( "\n Use this command to publish ESDL Service based bindings.\n"
  697. " To bind a ESDL Service, provide the id of the esdl binding and the method name you're going to configure.\n"
  698. " Optionally provide configuration information either directly, or via a\n"
  699. " configuration file in the following syntax:\n"
  700. " <Methods>\n"
  701. " \t<Method name=\"myMethod\" url=\"http://10.45.22.1:292/somepath?someparam=value\" user=\"myuser\" password=\"mypass\"/>\n"
  702. " \t<Method name=\"myMethod2\" url=\"http://10.45.22.1:292/somepath?someparam=value\" user=\"myuser\" password=\"mypass\"/>\n"
  703. " </Methods>\n"
  704. );
  705. printf("\nExample:"
  706. ">esdl bind-method myesp.8003.EsdlExample myMethod --config /myService/methods.xml\n"
  707. );
  708. }
  709. bool parseCommandLineOptions(ArgvIterator &iter)
  710. {
  711. if (iter.done())
  712. {
  713. usage();
  714. return false;
  715. }
  716. //First 5 parameter order is fixed.
  717. for (int cur = 0; cur < 2 && !iter.done(); cur++)
  718. {
  719. const char *arg = iter.query();
  720. if (*arg != '-')
  721. {
  722. switch (cur)
  723. {
  724. case 0:
  725. optBindingId.set(arg);
  726. break;
  727. case 1:
  728. optMethod.set(arg);
  729. break;
  730. }
  731. }
  732. else
  733. {
  734. fprintf(stderr, "\noption detected before required arguments: %s\n", arg);
  735. usage();
  736. return false;
  737. }
  738. iter.next();
  739. }
  740. for (; !iter.done(); iter.next())
  741. {
  742. if (parseCommandLineOption(iter))
  743. continue;
  744. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  745. return false;
  746. }
  747. return true;
  748. }
  749. bool finalizeOptions(IProperties *globals)
  750. {
  751. if (optInput.length())
  752. {
  753. const char *in = optInput.get();
  754. while (*in && isspace(*in)) in++;
  755. if (*in!='<')
  756. {
  757. StringBuffer content;
  758. content.loadFile(in);
  759. optInput.set(content.str());
  760. }
  761. }
  762. if (optBindingId.isEmpty())
  763. throw MakeStringException( 0, "ESDLBindingID must be provided!" );
  764. if (optMethod.isEmpty())
  765. throw MakeStringException( 0, "Name of ESDL based method must be provided" );
  766. return EsdlPublishCmdCommon::finalizeOptions(globals);
  767. }
  768. };
  769. class EsdlUnBindMethodCmd : public EsdlBindMethodCmd
  770. {
  771. public:
  772. int processCMD()
  773. {
  774. int success = -1;
  775. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  776. Owned<IClientGetESDLBindingRequest> getrequest = esdlConfigClient->createGetESDLBindingRequest();
  777. if (optVerbose)
  778. fprintf(stdout,"\nFetching current ESDL binging configuration for (%s)\n", optBindingId.get());
  779. getrequest->setEsdlBindingId(optBindingId.get());
  780. Owned<IClientGetESDLBindingResponse> getresp = esdlConfigClient->GetESDLBinding(getrequest);
  781. if (getresp->getExceptions().ordinality()>0)
  782. {
  783. EsdlCmdHelper::outputMultiExceptions(getresp->getExceptions());
  784. return success;
  785. }
  786. if (getresp->getStatus().getCode()!=0)
  787. {
  788. fprintf(stderr, "\n Failed to retrieve ESDL Binding configuration for %s: %s.\n", optBindingId.get(), getresp->getStatus().getDescription());
  789. return success;
  790. }
  791. const char * currentconfig = getresp->getConfigXML();
  792. if (currentconfig && *currentconfig)
  793. {
  794. Owned<IPropertyTree> currconfigtree = createPTreeFromXMLString(currentconfig);
  795. if (currconfigtree)
  796. {
  797. VStringBuffer xpath("Definition[1]/Methods/Method[@name='%s']", optMethod.get());
  798. if (currconfigtree->hasProp(xpath.str()))
  799. {
  800. if (currconfigtree->removeProp(xpath.str()))
  801. {
  802. StringBuffer newconfig;
  803. toXML(currconfigtree, newconfig);
  804. Owned<IClientPublishESDLBindingRequest> request = esdlConfigClient->createPublishESDLBindingRequest();
  805. if (optVerbose)
  806. fprintf(stdout,"\nAttempting to remove method '%s' from esdl binding '%s'\n", optMethod.get(), optBindingId.get());
  807. request->setEsdlDefinitionID(getresp->getESDLBinding().getDefinition().getId());
  808. request->setEsdlServiceName(getresp->getServiceName());
  809. request->setEspProcName(getresp->getEspProcName());
  810. request->setEspPort(getresp->getEspPort());
  811. request->setConfig(newconfig.str());
  812. request->setOverwrite(true);
  813. Owned<IClientPublishESDLBindingResponse> resp = esdlConfigClient->PublishESDLBinding(request);
  814. if (resp->getExceptions().ordinality() > 0)
  815. {
  816. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  817. return success;
  818. }
  819. if (resp->getStatus().getCode() == 0)
  820. {
  821. fprintf(stdout, "\nSuccessfully unbound method %s from ESDL Binding %s.\n", optMethod.get(), optBindingId.get());
  822. success = 0;
  823. }
  824. else
  825. fprintf(stderr, "\nCould not unbound method %s from ESDL Binding %s: %s\n", optMethod.get(), optBindingId.get(), resp->getStatus().getDescription());
  826. }
  827. else
  828. fprintf(stderr, "\n Could not remove Method %s from ESDL Binding %s configuration.\n", optMethod.get(), optBindingId.get());
  829. }
  830. else
  831. fprintf(stderr, "\n Method %s doesn't seem to be associated with ESDL Binding %s.\n", optMethod.get(), optBindingId.get());
  832. }
  833. else
  834. fprintf(stderr, "\n Could not interpret configuration for ESDL Binding %s : %s.\n", optBindingId.get(), currentconfig );
  835. }
  836. else
  837. fprintf(stderr, "\n Received empty configuration for ESDL Binding %s.\n", optBindingId.get());
  838. return success;
  839. }
  840. void usage()
  841. {
  842. printf( "\nUsage:\n\n"
  843. "esdl unbind-method <ESDLBindingID> <MethodName> [\n\n"
  844. " ESDLBindingID The id of the esdl binding associated with the target method\n"
  845. " MethodName The name of the target method (must exist in the service ESDL definition)\n");
  846. EsdlPublishCmdCommon::usage();
  847. printf( "\n Use this command to unbind a method configuration currently associated with a given ESDL binding.\n"
  848. " To unbind a method, provide the target esdl binding id and the name of the method to unbind\n");
  849. printf("\nExample:"
  850. ">esdl unbind-method myesp.8003.WsMyService mymethod\n"
  851. );
  852. }
  853. bool parseCommandLineOptions(ArgvIterator &iter)
  854. {
  855. if (iter.done())
  856. {
  857. usage();
  858. return false;
  859. }
  860. //First 4 parameter order is fixed.
  861. for (int cur = 0; cur < 2 && !iter.done(); cur++)
  862. {
  863. const char *arg = iter.query();
  864. if (*arg != '-')
  865. {
  866. switch (cur)
  867. {
  868. case 0:
  869. optBindingId.set(arg);
  870. break;
  871. case 1:
  872. optMethod.set(arg);
  873. break;
  874. }
  875. }
  876. else
  877. {
  878. fprintf(stderr, "\noption detected before required arguments: %s\n", arg);
  879. usage();
  880. return false;
  881. }
  882. iter.next();
  883. }
  884. for (; !iter.done(); iter.next())
  885. {
  886. if (parseCommandLineOption(iter))
  887. continue;
  888. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  889. return false;
  890. }
  891. return true;
  892. }
  893. bool finalizeOptions(IProperties *globals)
  894. {
  895. if(optBindingId.isEmpty())
  896. throw MakeStringException( 0, "Name of Target ESDL Binding must be provided" );
  897. if (optMethod.isEmpty())
  898. throw MakeStringException( 0, "Name of ESDL based method must be provided" );
  899. return EsdlPublishCmdCommon::finalizeOptions(globals);
  900. }
  901. };
  902. class EsdlBindLogTransformCmd : public EsdlBindServiceCmd
  903. {
  904. protected:
  905. StringAttr optLogTransform;
  906. StringAttr optBindingId;
  907. bool optEncoded;
  908. public:
  909. int processCMD()
  910. {
  911. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  912. Owned<IClientConfigureESDLBindingLogTransformRequest> request = esdlConfigClient->createConfigureESDLBindingLogTransformRequest();
  913. fprintf(stdout,"\nAttempting to configure LogTransform : '%s' for binding '%s'\n", optLogTransform.get(), optBindingId.get());
  914. request->setEsdlBindingId(optBindingId.get());
  915. request->setLogTransformName(optLogTransform.get());
  916. request->setConfig(optInput);
  917. request->setOverwrite(optOverWrite);
  918. request->setEncoded(optEncoded);
  919. if (optVerbose)
  920. fprintf(stdout,"\nLogTransform config: %s\n", optInput.get());
  921. Owned<IClientConfigureESDLBindingLogTransformResponse> resp = esdlConfigClient->ConfigureESDLBindingLogTransform(request);
  922. if (resp->getExceptions().ordinality()>0)
  923. {
  924. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  925. return 1;
  926. }
  927. outputWsStatus(resp->getStatus().getCode(), resp->getStatus().getDescription());
  928. return 0;
  929. }
  930. void usage()
  931. {
  932. printf( "\nUsage:\n\n"
  933. "esdl bind-log-transform <TargetESDLBindingID> [TargetLogTransformName] --config <file|xml> [command options]\n\n"
  934. " TargetESDLBindingID The id of the target ESDL binding (must exist in dali)\n"
  935. " TargetLogTransformName The name of the target LogTransform (required when config is xsl transform)\n"
  936. " --config <file|xml> Configuration XML for all LogTransforms associated with the target Service\n"
  937. "\nOptions (use option flag followed by appropriate value):\n"
  938. " --overwrite Overwrite LogTransform if it already exists\n"
  939. " --encoded The LogTransform in config has been encoded.\n");
  940. EsdlPublishCmdCommon::usage();
  941. printf( "\n Use this command to publish ESDL Service based bindings.\n"
  942. " To bind a ESDL Service, provide the id of the esdl binding and the LogTransform name you're going to configure.\n"
  943. " Optionally provide configuration information either directly, or via a\n"
  944. " configuration file in the following syntax:\n"
  945. " <LogTransforms>\n"
  946. " \t<LogTransform name=\"myLogTransform\">escaped transform script</LogTransform>\n"
  947. " \t<LogTransform name=\"myLogTransform2\">escaped transform script</LogTransform>\n"
  948. " </LogTransforms>\n"
  949. " or\n"
  950. " one transform script\n"
  951. );
  952. printf("\nExample:\n"
  953. ">esdl bind-log-transform myesp.8003.EsdlExample myLogTransform --config /myService/log-transforms.xml\n"
  954. "or:\n"
  955. ">esdl bind-log-transform myesp.8003.EsdlExample myLogTransform --config /myService/log-transform.xsl\n"
  956. );
  957. }
  958. bool parseCommandLineOptions(ArgvIterator &iter)
  959. {
  960. if (iter.done())
  961. {
  962. usage();
  963. return false;
  964. }
  965. //First 2 parameter order is fixed.
  966. for (int cur = 0; cur < 2 && !iter.done(); cur++)
  967. {
  968. const char *arg = iter.query();
  969. if (*arg != '-')
  970. {
  971. switch (cur)
  972. {
  973. case 0:
  974. optBindingId.set(arg);
  975. break;
  976. case 1:
  977. optLogTransform.set(arg);
  978. break;
  979. }
  980. }
  981. else
  982. {
  983. fprintf(stderr, "\noption detected before required arguments: %s\n", arg);
  984. usage();
  985. return false;
  986. }
  987. iter.next();
  988. }
  989. for (; !iter.done(); iter.next())
  990. {
  991. if (parseCommandLineOption(iter))
  992. continue;
  993. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  994. return false;
  995. }
  996. return true;
  997. }
  998. bool parseCommandLineOption(ArgvIterator &iter)
  999. {
  1000. if (iter.matchFlag(optEncoded, ESDL_OPTION_ENCODED) )
  1001. return true;
  1002. if (EsdlBindServiceCmd::parseCommandLineOption(iter))
  1003. return true;
  1004. return false;
  1005. }
  1006. bool finalizeOptions(IProperties *globals)
  1007. {
  1008. if (optInput.length())
  1009. {
  1010. const char *in = optInput.get();
  1011. while (*in && isspace(*in)) in++;
  1012. if (*in!='<')
  1013. {
  1014. StringBuffer content;
  1015. content.loadFile(in);
  1016. optInput.set(content.str());
  1017. }
  1018. }
  1019. if (optBindingId.isEmpty())
  1020. throw MakeStringException( 0, "ESDLBindingID must be provided!" );
  1021. if (optLogTransform.isEmpty() && (strncmp(optInput.str(), "<LogTransforms>", 15) != 0))
  1022. throw MakeStringException( 0, "Name of ESDL based LogTransform must be provided" );
  1023. return EsdlPublishCmdCommon::finalizeOptions(globals);
  1024. }
  1025. };
  1026. class EsdlUnBindLogTransformCmd : public EsdlBindLogTransformCmd
  1027. {
  1028. public:
  1029. int processCMD()
  1030. {
  1031. int success = -1;
  1032. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  1033. Owned<IClientGetESDLBindingRequest> getrequest = esdlConfigClient->createGetESDLBindingRequest();
  1034. if (optVerbose)
  1035. fprintf(stdout,"\nFetching current ESDL binding configuration for (%s)\n", optBindingId.get());
  1036. getrequest->setEsdlBindingId(optBindingId.get());
  1037. Owned<IClientGetESDLBindingResponse> getresp = esdlConfigClient->GetESDLBinding(getrequest);
  1038. if (getresp->getExceptions().ordinality()>0)
  1039. {
  1040. EsdlCmdHelper::outputMultiExceptions(getresp->getExceptions());
  1041. return success;
  1042. }
  1043. if (getresp->getStatus().getCode()!=0)
  1044. {
  1045. fprintf(stderr, "\n Failed to retrieve ESDL Binding configuration for %s: %s.\n", optBindingId.get(), getresp->getStatus().getDescription());
  1046. return success;
  1047. }
  1048. const char * currentconfig = getresp->getConfigXML();
  1049. if (currentconfig && *currentconfig)
  1050. {
  1051. Owned<IPropertyTree> currconfigtree = createPTreeFromXMLString(currentconfig, ipt_caseInsensitive | ipt_ordered);
  1052. if (currconfigtree)
  1053. {
  1054. VStringBuffer xpath("Definition[1]/LogTransforms/LogTransform[@name='%s']", optLogTransform.get());
  1055. if (currconfigtree->hasProp(xpath.str()))
  1056. {
  1057. if (currconfigtree->removeProp(xpath.str()))
  1058. {
  1059. StringBuffer newconfig;
  1060. toXML(currconfigtree, newconfig);
  1061. Owned<IClientPublishESDLBindingRequest> request = esdlConfigClient->createPublishESDLBindingRequest();
  1062. if (optVerbose)
  1063. fprintf(stdout,"\nAttempting to remove LogTransform '%s' from esdl binding '%s'\n", optLogTransform.get(), optBindingId.get());
  1064. request->setEsdlDefinitionID(getresp->getESDLBinding().getDefinition().getId());
  1065. request->setEsdlServiceName(getresp->getServiceName());
  1066. request->setEspProcName(getresp->getEspProcName());
  1067. request->setEspPort(getresp->getEspPort());
  1068. request->setConfig(newconfig.str());
  1069. request->setOverwrite(true);
  1070. Owned<IClientPublishESDLBindingResponse> resp = esdlConfigClient->PublishESDLBinding(request);
  1071. if (resp->getExceptions().ordinality() > 0)
  1072. {
  1073. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  1074. return success;
  1075. }
  1076. if (resp->getStatus().getCode() == 0)
  1077. {
  1078. fprintf(stdout, "\nSuccessfully unbound LogTransform %s from ESDL Binding %s.\n", optLogTransform.get(), optBindingId.get());
  1079. success = 0;
  1080. }
  1081. else
  1082. fprintf(stderr, "\nCould not unbound LogTransform %s from ESDL Binding %s: %s\n", optLogTransform.get(), optBindingId.get(), resp->getStatus().getDescription());
  1083. }
  1084. else
  1085. fprintf(stderr, "\n Could not remove LogTransform %s from ESDL Binding %s configuration.\n", optLogTransform.get(), optBindingId.get());
  1086. }
  1087. else
  1088. fprintf(stderr, "\n LogTransform %s doesn't seem to be associated with ESDL Binding %s.\n", optLogTransform.get(), optBindingId.get());
  1089. }
  1090. else
  1091. fprintf(stderr, "\n Could not interpret configuration for ESDL Binding %s : %s.\n", optBindingId.get(), currentconfig );
  1092. }
  1093. else
  1094. fprintf(stderr, "\n Received empty configuration for ESDL Binding %s.\n", optBindingId.get());
  1095. return success;
  1096. }
  1097. void usage()
  1098. {
  1099. printf( "\nUsage:\n\n"
  1100. "esdl unbind-log-transform <ESDLBindingID> <LogTransformName> [\n\n"
  1101. " ESDLBindingID The id of the esdl binding associated with the target LogTransform\n"
  1102. " LogTransformName The name of the target LogTransform (must exist in the service ESDL definition)\n");
  1103. EsdlPublishCmdCommon::usage();
  1104. printf( "\n Use this command to unbind a LogTransform configuration currently associated with a given ESDL binding.\n"
  1105. " To unbind a LogTransform, provide the target esdl binding id and the name of the LogTransform to unbind\n");
  1106. printf("\nExample:"
  1107. ">esdl unbind-log-transform myesp.8003.WsMyService myLogTransform\n"
  1108. );
  1109. }
  1110. bool parseCommandLineOptions(ArgvIterator &iter)
  1111. {
  1112. if (iter.done())
  1113. {
  1114. usage();
  1115. return false;
  1116. }
  1117. //First 2 parameter order is fixed.
  1118. for (int cur = 0; cur < 2 && !iter.done(); cur++)
  1119. {
  1120. const char *arg = iter.query();
  1121. if (*arg != '-')
  1122. {
  1123. switch (cur)
  1124. {
  1125. case 0:
  1126. optBindingId.set(arg);
  1127. break;
  1128. case 1:
  1129. optLogTransform.set(arg);
  1130. break;
  1131. }
  1132. }
  1133. else
  1134. {
  1135. fprintf(stderr, "\noption detected before required arguments: %s\n", arg);
  1136. usage();
  1137. return false;
  1138. }
  1139. iter.next();
  1140. }
  1141. for (; !iter.done(); iter.next())
  1142. {
  1143. if (parseCommandLineOption(iter))
  1144. continue;
  1145. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  1146. return false;
  1147. }
  1148. return true;
  1149. }
  1150. bool finalizeOptions(IProperties *globals)
  1151. {
  1152. if(optBindingId.isEmpty())
  1153. throw MakeStringException( 0, "Name of Target ESDL Binding must be provided" );
  1154. if (optLogTransform.isEmpty())
  1155. throw MakeStringException( 0, "Name of ESDL based LogTransform must be provided" );
  1156. return EsdlPublishCmdCommon::finalizeOptions(globals);
  1157. }
  1158. };
  1159. class EsdlGetCmd : public EsdlPublishCmdCommon
  1160. {
  1161. protected:
  1162. StringAttr optId;
  1163. public:
  1164. bool parseCommandLineOptions(ArgvIterator &iter)
  1165. {
  1166. if (iter.done())
  1167. {
  1168. usage();
  1169. return false;
  1170. }
  1171. //First parameter is fixed.
  1172. for (int cur = 0; cur < 1 && !iter.done(); cur++)
  1173. {
  1174. const char *arg = iter.query();
  1175. if (*arg != '-')
  1176. {
  1177. optId.set(arg);
  1178. }
  1179. else
  1180. {
  1181. fprintf(stderr, "\noption detected before required arguments: %s\n", arg);
  1182. usage();
  1183. return false;
  1184. }
  1185. iter.next();
  1186. }
  1187. for (; !iter.done(); iter.next())
  1188. {
  1189. if (parseCommandLineOption(iter))
  1190. continue;
  1191. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  1192. return false;
  1193. }
  1194. return true;
  1195. }
  1196. bool parseCommandLineOption(ArgvIterator &iter)
  1197. {
  1198. if (iter.matchFlag(optTargetAddress, ESDL_OPTION_TARGET_ESP_ADDRESS))
  1199. return true;
  1200. if (iter.matchFlag(optTargetPort, ESDL_OPTION_TARGET_ESP_PORT) )
  1201. return true;
  1202. if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
  1203. return true;
  1204. return false;
  1205. }
  1206. bool finalizeOptions(IProperties *globals)
  1207. {
  1208. if (optId.isEmpty())
  1209. throw MakeStringException( 0, "ESDL ID must be provided" );
  1210. return EsdlPublishCmdCommon::finalizeOptions(globals);
  1211. }
  1212. };
  1213. class EsdlGetDefinitionCmd : public EsdlGetCmd
  1214. {
  1215. public:
  1216. int processCMD()
  1217. {
  1218. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  1219. Owned<IClientGetESDLDefinitionRequest> request = esdlConfigClient->createGetESDLDefinitionRequest();
  1220. fprintf(stdout,"\nAttempting to get ESDL definition: %s\n", optId.get());
  1221. request->setId(optId);
  1222. Owned<IClientGetESDLDefinitionResponse> resp = esdlConfigClient->GetESDLDefinition(request);
  1223. if (resp->getExceptions().ordinality()>0)
  1224. {
  1225. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  1226. return 1;
  1227. }
  1228. StringBuffer definition;
  1229. definition.set(resp->getXMLDefinition());
  1230. if (definition.length()==0) //as of wsesdlconfig 1.4 getxmldef moves to definition/Interface
  1231. definition.set(resp->getDefinition().getInterface());
  1232. if (definition.length()!=0)
  1233. fprintf(stdout, "\n%s", definition.str());
  1234. outputWsStatus(resp->getStatus().getCode(), resp->getStatus().getDescription());
  1235. return 0;
  1236. }
  1237. void usage()
  1238. {
  1239. printf( "\nUsage:\n\n"
  1240. "esdl get-definition <ESDLDefinitionID> [command options]\n\n"
  1241. "Options (use option flag followed by appropriate value):\n"
  1242. " ESDLDefinitionID The ESDL Definition id <esdldefname>.<esdldefver>\n"
  1243. );
  1244. EsdlPublishCmdCommon::usage();
  1245. printf( "\n\n Use this command to get DESDL definitions.\n"
  1246. " To specify the target DESDL based service configuration, provide the target ESP process \n"
  1247. " (esp process name or machine IP Address) which hosts the service.\n"
  1248. " It is also necessary to provide the Port on which this service is configured to run,\n"
  1249. " and the name of the service.\n"
  1250. );
  1251. }
  1252. };
  1253. class EsdlGetBindingCmd : public EsdlGetCmd
  1254. {
  1255. public:
  1256. int processCMD()
  1257. {
  1258. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  1259. Owned<IClientGetESDLBindingRequest> request = esdlConfigClient->createGetESDLBindingRequest();
  1260. fprintf(stdout,"\nAttempting to get ESDL binding: %s\n", optId.get());
  1261. request->setEsdlBindingId(optId);
  1262. Owned<IClientGetESDLBindingResponse> resp = esdlConfigClient->GetESDLBinding(request);
  1263. if (resp->getExceptions().ordinality()>0)
  1264. {
  1265. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  1266. return 1;
  1267. }
  1268. fprintf(stdout, "\n%s", resp->getConfigXML());
  1269. outputWsStatus(resp->getStatus().getCode(), resp->getStatus().getDescription());
  1270. return 0;
  1271. }
  1272. void usage()
  1273. {
  1274. printf( "\nUsage:\n\n"
  1275. "esdl get-binding <ESDLBindingId> [command options]\n\n"
  1276. "Options (use option flag followed by appropriate value):\n"
  1277. " ESDLBindingId The target ESDL binding id\n"
  1278. );
  1279. EsdlPublishCmdCommon::usage();
  1280. printf( "\n\n Use this command to get DESDL Service based bindings.\n");
  1281. }
  1282. };