esdl-publish.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  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 "build-config.h"
  18. class EsdlPublishCmdCommon : public EsdlCmdCommon
  19. {
  20. protected:
  21. StringAttr optSource;
  22. StringAttr optService;
  23. StringAttr optWSProcAddress;
  24. StringAttr optWSProcPort;
  25. StringAttr optVersionStr;
  26. double optVersion;
  27. StringAttr optUser;
  28. StringAttr optPass;
  29. StringAttr optESDLDefID;
  30. StringAttr optESDLService;
  31. StringAttr optTargetESPProcName;
  32. StringAttr optTargetAddress;
  33. StringAttr optTargetPort;
  34. bool optOverWrite;
  35. Owned<EsdlCmdHelper> esdlHelper;
  36. public:
  37. EsdlPublishCmdCommon() : optWSProcAddress("."), optWSProcPort("8010")
  38. {
  39. esdlHelper.setown(EsdlCmdHelper::createEsdlHelper());
  40. }
  41. virtual int processCMD() = 0;
  42. virtual bool parseCommandLineOptions(ArgvIterator &iter)
  43. {
  44. if (iter.done())
  45. {
  46. usage();
  47. return false;
  48. }
  49. for (; !iter.done(); iter.next())
  50. {
  51. if (parseCommandLineOption(iter))
  52. continue;
  53. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  54. return false;
  55. }
  56. return true;
  57. }
  58. virtual void usage()
  59. {
  60. printf(
  61. " -s, --server <ip> IP of server running ESDL services\n"
  62. " --port <port> ESDL services port\n"
  63. " -u, --username <name> Username for accessing ESDL services\n"
  64. " -pw, --password <pw> Password for accessing ESDL services\n"
  65. " --version <ver> ESDL service version\n"
  66. );
  67. EsdlCmdCommon::usage();
  68. }
  69. virtual bool parseCommandLineOption(ArgvIterator &iter)
  70. {
  71. if (iter.matchFlag(optSource, ESDL_CONVERT_SOURCE))
  72. return true;
  73. if (iter.matchFlag(optService, ESDLOPT_SERVICE))
  74. return true;
  75. if (iter.matchFlag(optWSProcAddress, ESDL_OPT_SERVICE_SERVER) || iter.matchFlag(optWSProcAddress, ESDL_OPTION_SERVICE_SERVER))
  76. return true;
  77. if (iter.matchFlag(optWSProcPort, ESDL_OPTION_SERVICE_PORT) || iter.matchFlag(optWSProcPort, ESDL_OPT_SERVICE_PORT))
  78. return true;
  79. if (iter.matchFlag(optVersionStr, ESDLOPT_VERSION))
  80. return true;
  81. if (iter.matchFlag(optUser, ESDL_OPT_SERVICE_USER) || iter.matchFlag(optUser, ESDL_OPTION_SERVICE_USER))
  82. return true;
  83. if (iter.matchFlag(optPass, ESDL_OPT_SERVICE_PASS) || iter.matchFlag(optPass, ESDL_OPTION_SERVICE_PASS))
  84. return true;
  85. if (iter.matchFlag(optOverWrite, ESDL_OPTION_OVERWRITE) )
  86. return true;
  87. return false;
  88. }
  89. virtual bool finalizeOptions(IProperties *globals)
  90. {
  91. if (optWSProcAddress.isEmpty())
  92. throw MakeStringException( 0, "Server address of WsESDLConfig process server must be provided" );
  93. if (optWSProcPort.isEmpty())
  94. throw MakeStringException( 0, "Port on which WsESDLConfig is listening must be provided" );
  95. return true;
  96. }
  97. };
  98. class EsdlPublishCmd : public EsdlPublishCmdCommon
  99. {
  100. public:
  101. int processCMD()
  102. {
  103. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  104. Owned<IClientPublishESDLDefinitionRequest> request = esdlConfigClient->createPublishESDLDefinitionRequest();
  105. StringBuffer esxml;
  106. esdlHelper->getServiceESXDL(optSource.get(), optESDLService.get(), esxml, optVersion);
  107. if (esxml.length()==0)
  108. {
  109. fprintf(stderr,"\nESDL Definition for service %s could not be loaded from: %s\n", optESDLService.get(), optSource.get());
  110. return -1;
  111. }
  112. request->setServiceName(optESDLService.get());
  113. if (optVerbose)
  114. fprintf(stdout,"\nESDL Definition: \n%s\n", esxml.str());
  115. request->setXMLDefinition(esxml.str());
  116. request->setDeletePrevious(optOverWrite);
  117. Owned<IClientPublishESDLDefinitionResponse> resp = esdlConfigClient->PublishESDLDefinition(request);
  118. bool validateMessages = false;
  119. if (resp->getExceptions().ordinality()>0)
  120. {
  121. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  122. return 1;
  123. }
  124. fprintf(stdout, "\n %s. Service Name: %s, Version: %d\n", resp->getStatus().getDescription(),resp->getServiceName(),resp->getEsdlVersion());
  125. return 0;
  126. }
  127. void usage()
  128. {
  129. printf("\nUsage:\n\n"
  130. "esdl publish <servicename> <filename.(ecm|esdl)> [command options]\n\n"
  131. " <servicename> The ESDL defined ESP service to publish\n"
  132. " <filename.(ecm|esdl|xml)> The ESDL file containing service definition in esdl format (.ecm |.esdl) or in esxdl format (.xml) \n"
  133. "Options (use option flag followed by appropriate value):\n"
  134. " --overwrite Overwrite the latest version of this ESDL Definition\n"
  135. );
  136. EsdlPublishCmdCommon::usage();
  137. }
  138. bool parseCommandLineOptions(ArgvIterator &iter)
  139. {
  140. if (iter.done())
  141. {
  142. usage();
  143. return false;
  144. }
  145. //First x parameter's order is fixed.
  146. //<servicename>
  147. //<filename.(ecm|esdl|xml)> The ESDL file containing service definition\n"
  148. for (int cur = 0; cur < 2 && !iter.done(); cur++)
  149. {
  150. const char *arg = iter.query();
  151. if (*arg != '-')
  152. {
  153. switch (cur)
  154. {
  155. case 0:
  156. optESDLService.set(arg);
  157. break;
  158. case 1:
  159. optSource.set(arg);
  160. break;
  161. }
  162. }
  163. else
  164. {
  165. fprintf(stderr, "\nOption detected before required arguments: %s\n", arg);
  166. usage();
  167. return false;
  168. }
  169. iter.next();
  170. }
  171. for (; !iter.done(); iter.next())
  172. {
  173. if (parseCommandLineOption(iter))
  174. continue;
  175. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  176. return false;
  177. }
  178. return true;
  179. }
  180. bool finalizeOptions(IProperties *globals)
  181. {
  182. if (!optVersionStr.isEmpty())
  183. {
  184. optVersion = atof( optVersionStr.get() );
  185. if( optVersion <= 0 )
  186. {
  187. throw MakeStringException( 0, "Version option must be followed by a real number > 0" );
  188. }
  189. }
  190. else
  191. {
  192. fprintf(stderr, "\nWARNING: ESDL Version not specified.\n");
  193. }
  194. if (optSource.isEmpty())
  195. throw MakeStringException( 0, "Source ESDL XML definition file must be provided" );
  196. if (optESDLService.isEmpty())
  197. throw MakeStringException( 0, "Name of ESDL based service must be provided" );
  198. return EsdlPublishCmdCommon::finalizeOptions(globals);
  199. }
  200. };
  201. class EsdlBindServiceCmd : public EsdlPublishCmdCommon
  202. {
  203. protected:
  204. StringAttr optPortOrName;
  205. StringAttr optInput;
  206. public:
  207. int processCMD()
  208. {
  209. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  210. Owned<IClientPublishESDLBindingRequest> request = esdlConfigClient->createPublishESDLBindingRequest();
  211. fprintf(stdout,"\nAttempting to configure ESDL Service: '%s'\n", optESDLService.get());
  212. request->setEspProcName(optTargetESPProcName);
  213. request->setEspPort(optTargetPort);
  214. request->setEspServiceName(optService);
  215. request->setEsdlServiceName(optESDLService);
  216. request->setEsdlDefinitionID(optESDLDefID);
  217. request->setConfig(optInput);
  218. request->setOverwrite(optOverWrite);
  219. if (optVerbose)
  220. fprintf(stdout,"\nMethod config: %s\n", optInput.get());
  221. Owned<IClientPublishESDLBindingResponse> resp = esdlConfigClient->PublishESDLBinding(request);
  222. if (resp->getExceptions().ordinality()>0)
  223. {
  224. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  225. return 1;
  226. }
  227. fprintf(stdout, "\n %s.\n", resp->getStatus().getDescription());
  228. return 0;
  229. }
  230. void usage()
  231. {
  232. printf( "\nUsage:\n\n"
  233. "esdl bind-service <TargetESPProcessName> <TargetESPBindingPort | TargetESPServiceName> <ESDLDefinitionId> <ESDLServiceName> [command options]\n\n"
  234. " TargetESPProcessName The target ESP Process name\n"
  235. " TargetESPBindingPort | TargetESPServiceName Either target ESP binding port or target ESP service name\n"
  236. " ESDLDefinitionId The Name and version of the ESDL definition to bind to this service (must already be defined in dali.)\n"
  237. " ESDLServiceName The Name of the ESDL Service (as defined in the ESDL Definition)\n"
  238. "\nOptions (use option flag followed by appropriate value):\n"
  239. " --config <file|xml> Configuration XML for all methods associated with the target Service\n"
  240. " --overwrite Overwrite binding if it already exists\n");
  241. EsdlPublishCmdCommon::usage();
  242. printf( "\n Use this command to publish ESDL Service based bindings.\n"
  243. " To bind an ESDL Service, provide the target ESP process name\n"
  244. " (ESP Process which will host the ESP Service as defined in the ESDL Definition.) \n"
  245. " It is also necessary to provide the Port on which this service is configured to run (ESP Binding),\n"
  246. " and the name of the service you are binding.\n"
  247. " Optionally provide configuration information either directly, or via a\n"
  248. " configuration file in the following syntax:\n"
  249. " <Methods>\n"
  250. " \t<Method name=\"myMethod\" url=\"http://10.45.22.1:292/somepath?someparam=value\" user=\"myuser\" password=\"mypass\"/>\n"
  251. " \t<Method name=\"myMethod2\" url=\"http://10.45.22.1:292/somepath?someparam=value\" user=\"myuser\" password=\"mypass\"/>\n"
  252. " </Methods>\n"
  253. );
  254. printf("\nExample:"
  255. ">esdl bind-service myesp 8088 WsMyService --config /myService/methods.xml\n"
  256. );
  257. }
  258. bool parseCommandLineOptions(ArgvIterator &iter)
  259. {
  260. if (iter.done())
  261. {
  262. usage();
  263. return false;
  264. }
  265. //First 4 parameter's order is fixed.
  266. //TargetESPProcessName
  267. //TargetESPBindingPort | TargetESPServiceName
  268. //ESDLDefinitionId
  269. //ESDLServiceName
  270. for (int cur = 0; cur < 4 && !iter.done(); cur++)
  271. {
  272. const char *arg = iter.query();
  273. if (*arg != '-')
  274. {
  275. switch (cur)
  276. {
  277. case 0:
  278. optTargetESPProcName.set(arg);
  279. break;
  280. case 1:
  281. optPortOrName.set(arg);
  282. break;
  283. case 2:
  284. optESDLDefID.set(arg);
  285. break;
  286. case 3:
  287. optESDLService.set(arg);
  288. break;
  289. }
  290. }
  291. else
  292. {
  293. fprintf(stderr, "\nOption detected before required arguments: %s\n", arg);
  294. usage();
  295. return false;
  296. }
  297. iter.next();
  298. }
  299. for (; !iter.done(); iter.next())
  300. {
  301. if (parseCommandLineOption(iter))
  302. continue;
  303. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  304. return false;
  305. }
  306. return true;
  307. }
  308. bool parseCommandLineOption(ArgvIterator &iter)
  309. {
  310. if (iter.matchFlag(optInput, ESDL_OPTION_CONFIG) )
  311. return true;
  312. if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
  313. return true;
  314. return false;
  315. }
  316. bool finalizeOptions(IProperties *globals)
  317. {
  318. if (optInput.length())
  319. {
  320. const char *in = optInput.get();
  321. while (*in && isspace(*in)) in++;
  322. if (*in!='<')
  323. {
  324. StringBuffer content;
  325. content.loadFile(in);
  326. optInput.set(content.str());
  327. }
  328. }
  329. if (optESDLDefID.isEmpty())
  330. throw MakeStringException( 0, "ESDL definition ID must be provided!" );
  331. if (optESDLService.isEmpty())
  332. throw MakeStringException( 0, "ESDL service definition name must be provided!" );
  333. if(optTargetESPProcName.isEmpty())
  334. throw MakeStringException( 0, "Name of Target ESP process must be provided!" );
  335. if (optPortOrName.isEmpty())
  336. throw MakeStringException( 0, "Either the target ESP service port of name must be provided!" );
  337. else
  338. {
  339. const char * portorname = optPortOrName.get();
  340. isdigit(*portorname) ? optTargetPort.set(portorname) : optService.set(portorname);
  341. }
  342. return EsdlPublishCmdCommon::finalizeOptions(globals);
  343. }
  344. };
  345. class EsdlUnBindServiceCmd : public EsdlPublishCmdCommon
  346. {
  347. protected:
  348. StringAttr optEspBinding;
  349. public:
  350. int processCMD()
  351. {
  352. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  353. Owned<IClientDeleteESDLBindingRequest> request = esdlConfigClient->createDeleteESDLBindingRequest();
  354. fprintf(stdout,"\nAttempting to un-bind ESDL Service: '%s.%s'\n", optTargetESPProcName.get(), optEspBinding.get());
  355. StringBuffer id;
  356. id.setf("%s.%s", optTargetESPProcName.get(), optEspBinding.get());
  357. request->setId(id);
  358. Owned<IClientDeleteESDLRegistryEntryResponse> resp = esdlConfigClient->DeleteESDLBinding(request);
  359. if (resp->getExceptions().ordinality()>0)
  360. {
  361. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  362. return 1;
  363. }
  364. fprintf(stdout, "\n %s.\n", resp->getStatus().getDescription());
  365. return 0;
  366. }
  367. void usage()
  368. {
  369. printf( "\nUsage:\n\n"
  370. "esdl unbind-service <TargetESPProcessName> <TargetESPBindingPort | TargetESPServiceName> [command options]\n\n"
  371. " TargetESPProcessName The target ESP Process name\n"
  372. " TargetESPBindingPort | TargetESPServiceName Either target ESP binding port or target ESP service name\n");
  373. EsdlPublishCmdCommon::usage();
  374. printf( "\n Use this command to unpublish ESDL Service based bindings.\n"
  375. " To unbind an ESDL Service, provide the target ESP process name\n"
  376. " (ESP Process which will host the ESP Service as defined in the ESDL Definition.) \n"
  377. " It is also necessary to provide the Port on which this service is configured to run (ESP Binding),\n"
  378. " and the name of the service you are unbinding.\n"
  379. );
  380. printf("\nExample:"
  381. ">esdl unbind-service myesp 8088 \n"
  382. );
  383. }
  384. bool parseCommandLineOptions(ArgvIterator &iter)
  385. {
  386. if (iter.done())
  387. {
  388. usage();
  389. return false;
  390. }
  391. for (int cur = 0; cur < 2 && !iter.done(); cur++)
  392. {
  393. const char *arg = iter.query();
  394. if (*arg != '-')
  395. {
  396. switch (cur)
  397. {
  398. case 0:
  399. optTargetESPProcName.set(arg);
  400. break;
  401. case 1:
  402. optEspBinding.set(arg);
  403. break;
  404. }
  405. }
  406. else
  407. {
  408. fprintf(stderr, "\nOption detected before required arguments: %s\n", arg);
  409. usage();
  410. return false;
  411. }
  412. iter.next();
  413. }
  414. for (; !iter.done(); iter.next())
  415. {
  416. if (parseCommandLineOption(iter))
  417. continue;
  418. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  419. return false;
  420. }
  421. return true;
  422. }
  423. bool parseCommandLineOption(ArgvIterator &iter)
  424. {
  425. if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
  426. return true;
  427. return false;
  428. }
  429. bool finalizeOptions(IProperties *globals)
  430. {
  431. if (optTargetESPProcName.isEmpty())
  432. throw MakeStringException( 0, "Name of Target ESP process must be provided!" );
  433. if (optEspBinding.isEmpty())
  434. throw MakeStringException( 0, "Target ESP Binding must be provided!" );
  435. return EsdlPublishCmdCommon::finalizeOptions(globals);
  436. }
  437. };
  438. class EsdlDeleteESDLDefCmd : public EsdlPublishCmdCommon
  439. {
  440. public:
  441. int processCMD()
  442. {
  443. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  444. Owned<IClientDeleteESDLDefinitionRequest> request = esdlConfigClient->createDeleteESDLDefinitionRequest();
  445. fprintf(stdout,"\nAttempting to delete ESDL definition: '%s.%d'\n", optESDLService.get(), (int)optVersion);
  446. StringBuffer id;
  447. id.setf("%s.%d", optESDLService.get(), (int)optVersion);
  448. request->setId(id);
  449. Owned<IClientDeleteESDLRegistryEntryResponse> resp = esdlConfigClient->DeleteESDLDefinition(request);
  450. if (resp->getExceptions().ordinality()>0)
  451. {
  452. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  453. return 1;
  454. }
  455. fprintf(stdout, "\n %s.\n", resp->getStatus().getDescription());
  456. return 0;
  457. }
  458. void usage()
  459. {
  460. printf( "\nUsage:\n\n"
  461. "esdl delete <ESDLServiceDefinitionName> <ESDLServiceDefinitionVersion> [command options]\n\n"
  462. " ESDLServiceDefinitionName The name of the ESDL service definition to delete\n"
  463. " ESDLServiceDefinitionVersion The version of the ESDL service definition to delete\n");
  464. EsdlPublishCmdCommon::usage();
  465. printf( "\n Use this command to delete an ESDL Service definition.\n"
  466. " To delete an ESDL Service definition, provide the definition name and version\n"
  467. );
  468. printf("\nExample:"
  469. ">esdl delete myesdldef 5\n"
  470. );
  471. }
  472. bool parseCommandLineOptions(ArgvIterator &iter)
  473. {
  474. if (iter.done())
  475. {
  476. usage();
  477. return false;
  478. }
  479. for (int cur = 0; cur < 2 && !iter.done(); cur++)
  480. {
  481. const char *arg = iter.query();
  482. if (*arg != '-')
  483. {
  484. switch (cur)
  485. {
  486. case 0:
  487. optESDLService.set(arg);
  488. break;
  489. case 1:
  490. optVersionStr.set(arg);
  491. break;
  492. }
  493. }
  494. else
  495. {
  496. fprintf(stderr, "\nOption detected before required arguments: %s\n", arg);
  497. usage();
  498. return false;
  499. }
  500. iter.next();
  501. }
  502. for (; !iter.done(); iter.next())
  503. {
  504. if (parseCommandLineOption(iter))
  505. continue;
  506. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  507. return false;
  508. }
  509. return true;
  510. }
  511. bool parseCommandLineOption(ArgvIterator &iter)
  512. {
  513. if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
  514. return true;
  515. return false;
  516. }
  517. bool finalizeOptions(IProperties *globals)
  518. {
  519. if (optESDLService.isEmpty())
  520. throw MakeStringException( 0, "Name of ESDL service definition must be provided!" );
  521. if (!optVersionStr.isEmpty())
  522. {
  523. optVersion = atof( optVersionStr.get() );
  524. if( optVersion <= 0 )
  525. {
  526. throw MakeStringException( 0, "Version option must be followed by a real number > 0" );
  527. }
  528. }
  529. else
  530. throw MakeStringException( 0, "ESDL service definition version must be provided!" );
  531. return EsdlPublishCmdCommon::finalizeOptions(globals);
  532. }
  533. };
  534. class EsdlListESDLDefCmd : public EsdlPublishCmdCommon
  535. {
  536. public:
  537. int processCMD()
  538. {
  539. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  540. Owned<IClientListESDLDefinitionsRequest> req = esdlConfigClient->createListESDLDefinitionsRequest();
  541. fprintf(stdout,"\nAttempting to list ESDL definitions.\n");
  542. Owned<IClientListESDLDefinitionsResponse> resp = esdlConfigClient->ListESDLDefinitions(req);
  543. if (resp->getExceptions().ordinality()>0)
  544. {
  545. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  546. return 1;
  547. }
  548. IArrayOf<IConstESDLDefinition> & defs = resp->getDefinitions();
  549. if (defs.length() > 0)
  550. fprintf(stdout, "\nESDL Definitions found:\n");
  551. ForEachItemIn(defindex, defs)
  552. {
  553. IConstESDLDefinition & def = defs.item(defindex);
  554. fprintf(stdout, "\t%s \n", def.getId());
  555. }
  556. return 0;
  557. }
  558. void usage()
  559. {
  560. printf( "\nUsage:\n\n"
  561. "esdl list-definitions [command options]\n\n"
  562. );
  563. EsdlPublishCmdCommon::usage();
  564. }
  565. bool parseCommandLineOptions(ArgvIterator &iter)
  566. {
  567. for (; !iter.done(); iter.next())
  568. {
  569. if (parseCommandLineOption(iter))
  570. continue;
  571. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  572. return false;
  573. }
  574. return true;
  575. }
  576. bool parseCommandLineOption(ArgvIterator &iter)
  577. {
  578. if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
  579. return true;
  580. return false;
  581. }
  582. bool finalizeOptions(IProperties *globals)
  583. {
  584. return EsdlPublishCmdCommon::finalizeOptions(globals);
  585. }
  586. };
  587. class EsdlListESDLBindingsCmd : public EsdlPublishCmdCommon
  588. {
  589. public:
  590. int processCMD()
  591. {
  592. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  593. Owned<IClientListESDLBindingsRequest> req = esdlConfigClient->createListESDLBindingsRequest();
  594. fprintf(stdout,"\nAttempting to list ESDL bindings.\n");
  595. Owned<IClientListESDLBindingsResponse> resp = esdlConfigClient->ListESDLBindings(req);
  596. if (resp->getExceptions().ordinality()>0)
  597. {
  598. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  599. return 1;
  600. }
  601. IArrayOf<IConstESDLBinding> & binds = resp->getBindings();
  602. if (binds.length() > 0)
  603. fprintf(stdout, "\nESDL Bindings found:\n");
  604. ForEachItemIn(bindindex, binds)
  605. {
  606. IConstESDLBinding & bind = binds.item(bindindex);
  607. fprintf(stdout, "\t%s \n", bind.getId());
  608. }
  609. return 0;
  610. }
  611. void usage()
  612. {
  613. printf( "\nUsage:\n\n"
  614. "esdl list-bindings [command options]\n\n"
  615. );
  616. EsdlPublishCmdCommon::usage();
  617. }
  618. bool parseCommandLineOptions(ArgvIterator &iter)
  619. {
  620. for (; !iter.done(); iter.next())
  621. {
  622. if (parseCommandLineOption(iter))
  623. continue;
  624. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  625. return false;
  626. }
  627. return true;
  628. }
  629. bool parseCommandLineOption(ArgvIterator &iter)
  630. {
  631. if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
  632. return true;
  633. return false;
  634. }
  635. bool finalizeOptions(IProperties *globals)
  636. {
  637. return EsdlPublishCmdCommon::finalizeOptions(globals);
  638. }
  639. };
  640. class EsdlBindMethodCmd : public EsdlBindServiceCmd
  641. {
  642. protected:
  643. StringAttr optMethod;
  644. StringAttr optBindingName;
  645. public:
  646. int processCMD()
  647. {
  648. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  649. Owned<IClientConfigureESDLBindingMethodRequest> request = esdlConfigClient->createConfigureESDLBindingMethodRequest();
  650. fprintf(stdout,"\nAttempting to configure Method : '%s'.'%s'\n", optService.get(), optMethod.get());
  651. request->setEspProcName(optTargetESPProcName);
  652. request->setEspBindingName(optBindingName);
  653. request->setEsdlServiceName(optService.get());
  654. VStringBuffer id("%s.%d", optService.get(), (int)optVersion);
  655. request->setEsdlDefinitionID(id.str());
  656. request->setConfig(optInput);
  657. request->setOverwrite(optOverWrite);
  658. if (optVerbose)
  659. fprintf(stdout,"\nMethod config: %s\n", optInput.get());
  660. Owned<IClientConfigureESDLBindingMethodResponse> resp = esdlConfigClient->ConfigureESDLBindingMethod(request);
  661. if (resp->getExceptions().ordinality()>0)
  662. {
  663. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  664. return 1;
  665. }
  666. fprintf(stdout, "\n %s.\n", resp->getStatus().getDescription());
  667. return 0;
  668. }
  669. void usage()
  670. {
  671. printf( "\nUsage:\n\n"
  672. "esdl bind-method <TargetESPProcessName> <TargetESPBindingName> <TargetServiceName> <TargetServiceDefVersion> <TargetMethodName> [command options]\n\n"
  673. " TargetESPProcessName The target ESP Process name\n"
  674. " TargetESPBindingName The target ESP binding name associated with this service\n"
  675. " TargetServiceName The name of the Service to bind (must already be defined in dali.)\n"
  676. " TargetServiceDefVersion The version of the target service ESDL definition (must exist in dali)\n"
  677. " TargetMethodName The name of the target method (must exist in the service ESDL definition)\n"
  678. "\nOptions (use option flag followed by appropriate value):\n"
  679. " --config <file|xml> Configuration XML for all methods associated with the target Service\n"
  680. " --overwrite Overwrite binding if it already exists\n");
  681. EsdlPublishCmdCommon::usage();
  682. printf( "\n Use this command to publish ESDL Service based bindings.\n"
  683. " To bind a ESDL Service, provide the target ESP process name\n"
  684. " (esp which will host the service.) \n"
  685. " It is also necessary to provide the Port on which this service is configured to run (ESP Binding),\n"
  686. " and the name of the service you are binding.\n"
  687. " Optionally provide configuration information either directly, or via a\n"
  688. " configuration file in the following syntax:\n"
  689. " <Methods>\n"
  690. " \t<Method name=\"myMethod\" url=\"http://10.45.22.1:292/somepath?someparam=value\" user=\"myuser\" password=\"mypass\"/>\n"
  691. " \t<Method name=\"myMethod2\" url=\"http://10.45.22.1:292/somepath?someparam=value\" user=\"myuser\" password=\"mypass\"/>\n"
  692. " </Methods>\n"
  693. );
  694. printf("\nExample:"
  695. ">esdl bind-service myesp 8088 WsMyService --config /myService/methods.xml\n"
  696. );
  697. }
  698. bool parseCommandLineOptions(ArgvIterator &iter)
  699. {
  700. if (iter.done())
  701. {
  702. usage();
  703. return false;
  704. }
  705. //First 5 parameter order is fixed.
  706. for (int cur = 0; cur < 5 && !iter.done(); cur++)
  707. {
  708. const char *arg = iter.query();
  709. if (*arg != '-')
  710. {
  711. switch (cur)
  712. {
  713. case 0:
  714. optTargetESPProcName.set(arg);
  715. break;
  716. case 1:
  717. optBindingName.set(arg);
  718. break;
  719. case 2:
  720. optService.set(arg);
  721. break;
  722. case 3:
  723. optVersionStr.set(arg);
  724. break;
  725. case 4:
  726. optMethod.set(arg);
  727. break;
  728. }
  729. }
  730. else
  731. {
  732. fprintf(stderr, "\noption detected before required arguments: %s\n", arg);
  733. usage();
  734. return false;
  735. }
  736. iter.next();
  737. }
  738. for (; !iter.done(); iter.next())
  739. {
  740. if (parseCommandLineOption(iter))
  741. continue;
  742. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  743. return false;
  744. }
  745. return true;
  746. }
  747. bool finalizeOptions(IProperties *globals)
  748. {
  749. if (optInput.length())
  750. {
  751. const char *in = optInput.get();
  752. while (*in && isspace(*in)) in++;
  753. if (*in!='<')
  754. {
  755. StringBuffer content;
  756. content.loadFile(in);
  757. optInput.set(content.str());
  758. }
  759. }
  760. if (!optVersionStr.isEmpty())
  761. {
  762. optVersion = atof( optVersionStr.get() );
  763. if( optVersion <= 0 )
  764. {
  765. throw MakeStringException( 0, "Version option must be followed by a real number > 0" );
  766. }
  767. }
  768. else
  769. throw MakeStringException( 0, "ESDL service definition version must be provided!" );
  770. if(optTargetESPProcName.isEmpty())
  771. throw MakeStringException( 0, "Name of Target ESP process must be provided" );
  772. if (optService.isEmpty())
  773. throw MakeStringException( 0, "Name of ESDL based service must be provided" );
  774. if (optMethod.isEmpty())
  775. throw MakeStringException( 0, "Name of ESDL based method must be provided" );
  776. if (optBindingName.isEmpty())
  777. throw MakeStringException( 0, "Name of ESP binding must be provided" );
  778. return EsdlPublishCmdCommon::finalizeOptions(globals);
  779. }
  780. };
  781. class EsdlGetCmd : public EsdlPublishCmdCommon
  782. {
  783. protected:
  784. StringAttr optId;
  785. public:
  786. bool parseCommandLineOptions(ArgvIterator &iter)
  787. {
  788. if (iter.done())
  789. {
  790. usage();
  791. return false;
  792. }
  793. //First parameter is fixed.
  794. for (int cur = 0; cur < 1 && !iter.done(); cur++)
  795. {
  796. const char *arg = iter.query();
  797. if (*arg != '-')
  798. {
  799. optId.set(arg);
  800. }
  801. else
  802. {
  803. fprintf(stderr, "\noption detected before required arguments: %s\n", arg);
  804. usage();
  805. return false;
  806. }
  807. iter.next();
  808. }
  809. for (; !iter.done(); iter.next())
  810. {
  811. if (parseCommandLineOption(iter))
  812. continue;
  813. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  814. return false;
  815. }
  816. return true;
  817. }
  818. bool parseCommandLineOption(ArgvIterator &iter)
  819. {
  820. if (iter.matchFlag(optTargetAddress, ESDL_OPTION_TARGET_ESP_ADDRESS))
  821. return true;
  822. if (iter.matchFlag(optTargetPort, ESDL_OPTION_TARGET_ESP_PORT) )
  823. return true;
  824. if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
  825. return true;
  826. return false;
  827. }
  828. bool finalizeOptions(IProperties *globals)
  829. {
  830. if (optId.isEmpty())
  831. throw MakeStringException( 0, "ESDL ID must be provided" );
  832. return EsdlPublishCmdCommon::finalizeOptions(globals);
  833. }
  834. };
  835. class EsdlGetDefinitionCmd : public EsdlGetCmd
  836. {
  837. public:
  838. int processCMD()
  839. {
  840. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  841. Owned<IClientGetESDLDefinitionRequest> request = esdlConfigClient->createGetESDLDefinitionRequest();
  842. fprintf(stdout,"\nAttempting to get ESDL definition: %s\n", optId.get());
  843. request->setId(optId);
  844. Owned<IClientGetESDLDefinitionResponse> resp = esdlConfigClient->GetESDLDefinition(request);
  845. if (resp->getExceptions().ordinality()>0)
  846. {
  847. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  848. return 1;
  849. }
  850. fprintf(stdout, "\n%s", resp->getXMLDefinition());
  851. fprintf(stdout, "\n%s.\n", resp->getStatus().getDescription());
  852. return 0;
  853. }
  854. void usage()
  855. {
  856. printf( "\nUsage:\n\n"
  857. "esdl get-definition <ESDLDefinitionID> [command options]\n\n"
  858. "Options (use option flag followed by appropriate value):\n"
  859. " ESDLDefinitionID The ESDL Definition id <esdldefname>.<esdldefver>\n"
  860. );
  861. EsdlPublishCmdCommon::usage();
  862. printf( "\n\n Use this command to get DESDL definitions.\n"
  863. " To specify the target DESDL based service configuration, provide the target ESP process \n"
  864. " (esp process name or machine IP Address) which hosts the service.\n"
  865. " It is also necessary to provide the Port on which this service is configured to run,\n"
  866. " and the name of the service.\n"
  867. );
  868. }
  869. };
  870. class EsdlGetBindingCmd : public EsdlGetCmd
  871. {
  872. public:
  873. int processCMD()
  874. {
  875. Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
  876. Owned<IClientGetESDLBindingRequest> request = esdlConfigClient->createGetESDLBindingRequest();
  877. fprintf(stdout,"\nAttempting to get ESDL binding: %s\n", optId.get());
  878. request->setEsdlBindingId(optId);
  879. Owned<IClientGetESDLBindingResponse> resp = esdlConfigClient->GetESDLBinding(request);
  880. if (resp->getExceptions().ordinality()>0)
  881. {
  882. EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
  883. return 1;
  884. }
  885. fprintf(stdout, "\n%s", resp->getConfigXML());
  886. fprintf(stdout, "\n%s.\n", resp->getStatus().getDescription());
  887. return 0;
  888. }
  889. void usage()
  890. {
  891. printf( "\nUsage:\n\n"
  892. "esdl get-binding <ESDLBindingId> [command options]\n\n"
  893. "Options (use option flag followed by appropriate value):\n"
  894. " ESDLBindingId The target ESDL binding id <espprocessname>.<espbindingname>\n"
  895. );
  896. EsdlPublishCmdCommon::usage();
  897. printf( "\n\n Use this command to get DESDL Service based bindings.\n"
  898. " To specify the target DESDL based service configuration, provide the target ESP process \n"
  899. " (esp process name or machine IP Address) which hosts the service.\n"
  900. " It is also necessary to provide the Port on which this service is configured to run,\n"
  901. " and the name of the service.\n"
  902. );
  903. }
  904. };