123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116 |
- /*##############################################################################
- HPCC SYSTEMS software Copyright (C) 2013 HPCC Systems®.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- ############################################################################## */
- #include "jliball.hpp"
- #include "esdl_def.hpp"
- #include "esdlcmd_common.hpp"
- #include "esdlcmd_core.hpp"
- #include "build-config.h"
- class EsdlPublishCmdCommon : public EsdlCmdCommon
- {
- protected:
- StringAttr optSource;
- StringAttr optService;
- StringAttr optWSProcAddress;
- StringAttr optWSProcPort;
- StringAttr optVersionStr;
- double optVersion;
- StringAttr optUser;
- StringAttr optPass;
- StringAttr optESDLDefID;
- StringAttr optESDLService;
- StringAttr optTargetESPProcName;
- StringAttr optTargetAddress;
- StringAttr optTargetPort;
- bool optOverWrite;
- Owned<EsdlCmdHelper> esdlHelper;
- public:
- EsdlPublishCmdCommon() : optWSProcAddress("."), optWSProcPort("8010")
- {
- esdlHelper.setown(EsdlCmdHelper::createEsdlHelper());
- }
- virtual int processCMD() = 0;
- virtual bool parseCommandLineOptions(ArgvIterator &iter)
- {
- if (iter.done())
- {
- usage();
- return false;
- }
- for (; !iter.done(); iter.next())
- {
- if (parseCommandLineOption(iter))
- continue;
- if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
- return false;
- }
- return true;
- }
- virtual void usage()
- {
- printf(
- " -s, --server <ip> IP of server running ESDL services\n"
- " --port <port> ESDL services port\n"
- " -u, --username <name> Username for accessing ESDL services\n"
- " -pw, --password <pw> Password for accessing ESDL services\n"
- " --version <ver> ESDL service version\n"
- );
- EsdlCmdCommon::usage();
- }
- virtual bool parseCommandLineOption(ArgvIterator &iter)
- {
- if (iter.matchFlag(optSource, ESDL_CONVERT_SOURCE))
- return true;
- if (iter.matchFlag(optService, ESDLOPT_SERVICE))
- return true;
- if (iter.matchFlag(optWSProcAddress, ESDL_OPT_SERVICE_SERVER) || iter.matchFlag(optWSProcAddress, ESDL_OPTION_SERVICE_SERVER))
- return true;
- if (iter.matchFlag(optWSProcPort, ESDL_OPTION_SERVICE_PORT) || iter.matchFlag(optWSProcPort, ESDL_OPT_SERVICE_PORT))
- return true;
- if (iter.matchFlag(optVersionStr, ESDLOPT_VERSION))
- return true;
- if (iter.matchFlag(optUser, ESDL_OPT_SERVICE_USER) || iter.matchFlag(optUser, ESDL_OPTION_SERVICE_USER))
- return true;
- if (iter.matchFlag(optPass, ESDL_OPT_SERVICE_PASS) || iter.matchFlag(optPass, ESDL_OPTION_SERVICE_PASS))
- return true;
- if (iter.matchFlag(optOverWrite, ESDL_OPTION_OVERWRITE) )
- return true;
- return false;
- }
- virtual bool finalizeOptions(IProperties *globals)
- {
- if (optWSProcAddress.isEmpty())
- throw MakeStringException( 0, "Server address of WsESDLConfig process server must be provided" );
- if (optWSProcPort.isEmpty())
- throw MakeStringException( 0, "Port on which WsESDLConfig is listening must be provided" );
- return true;
- }
- };
- class EsdlPublishCmd : public EsdlPublishCmdCommon
- {
- public:
- int processCMD()
- {
- Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
- Owned<IClientPublishESDLDefinitionRequest> request = esdlConfigClient->createPublishESDLDefinitionRequest();
- StringBuffer esxml;
- esdlHelper->getServiceESXDL(optSource.get(), optESDLService.get(), esxml, optVersion);
- if (esxml.length()==0)
- {
- fprintf(stderr,"\nESDL Definition for service %s could not be loaded from: %s\n", optESDLService.get(), optSource.get());
- return -1;
- }
- request->setServiceName(optESDLService.get());
- if (optVerbose)
- fprintf(stdout,"\nESDL Definition: \n%s\n", esxml.str());
- request->setXMLDefinition(esxml.str());
- request->setDeletePrevious(optOverWrite);
- Owned<IClientPublishESDLDefinitionResponse> resp = esdlConfigClient->PublishESDLDefinition(request);
- bool validateMessages = false;
- if (resp->getExceptions().ordinality()>0)
- {
- EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
- return 1;
- }
- fprintf(stdout, "\n %s. Service Name: %s, Version: %d\n", resp->getStatus().getDescription(),resp->getServiceName(),resp->getEsdlVersion());
- return 0;
- }
- void usage()
- {
- printf("\nUsage:\n\n"
- "esdl publish <servicename> <filename.(ecm|esdl)> [command options]\n\n"
- " <servicename> The ESDL defined ESP service to publish\n"
- " <filename.(ecm|esdl|xml)> The ESDL file containing service definition in esdl format (.ecm |.esdl) or in esxdl format (.xml) \n"
- "Options (use option flag followed by appropriate value):\n"
- " --overwrite Overwrite the latest version of this ESDL Definition\n"
- );
- EsdlPublishCmdCommon::usage();
- }
- bool parseCommandLineOptions(ArgvIterator &iter)
- {
- if (iter.done())
- {
- usage();
- return false;
- }
- //First x parameter's order is fixed.
- //<servicename>
- //<filename.(ecm|esdl|xml)> The ESDL file containing service definition\n"
- for (int cur = 0; cur < 2 && !iter.done(); cur++)
- {
- const char *arg = iter.query();
- if (*arg != '-')
- {
- switch (cur)
- {
- case 0:
- optESDLService.set(arg);
- break;
- case 1:
- optSource.set(arg);
- break;
- }
- }
- else
- {
- fprintf(stderr, "\nOption detected before required arguments: %s\n", arg);
- usage();
- return false;
- }
- iter.next();
- }
- for (; !iter.done(); iter.next())
- {
- if (parseCommandLineOption(iter))
- continue;
- if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
- return false;
- }
- return true;
- }
- bool finalizeOptions(IProperties *globals)
- {
- if (!optVersionStr.isEmpty())
- {
- optVersion = atof( optVersionStr.get() );
- if( optVersion <= 0 )
- {
- throw MakeStringException( 0, "Version option must be followed by a real number > 0" );
- }
- }
- else
- {
- fprintf(stderr, "\nWARNING: ESDL Version not specified.\n");
- }
- if (optSource.isEmpty())
- throw MakeStringException( 0, "Source ESDL XML definition file must be provided" );
- if (optESDLService.isEmpty())
- throw MakeStringException( 0, "Name of ESDL based service must be provided" );
- return EsdlPublishCmdCommon::finalizeOptions(globals);
- }
- };
- class EsdlBindServiceCmd : public EsdlPublishCmdCommon
- {
- protected:
- StringAttr optPortOrName;
- StringAttr optInput;
- public:
- int processCMD()
- {
- Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
- Owned<IClientPublishESDLBindingRequest> request = esdlConfigClient->createPublishESDLBindingRequest();
- fprintf(stdout,"\nAttempting to configure ESDL Service: '%s'\n", optESDLService.get());
- request->setEspProcName(optTargetESPProcName);
- request->setEspPort(optTargetPort);
- request->setEspServiceName(optService);
- request->setEsdlServiceName(optESDLService);
- request->setEsdlDefinitionID(optESDLDefID);
- request->setConfig(optInput);
- request->setOverwrite(optOverWrite);
- if (optVerbose)
- fprintf(stdout,"\nMethod config: %s\n", optInput.get());
- Owned<IClientPublishESDLBindingResponse> resp = esdlConfigClient->PublishESDLBinding(request);
- if (resp->getExceptions().ordinality()>0)
- {
- EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
- return 1;
- }
- fprintf(stdout, "\n %s.\n", resp->getStatus().getDescription());
- return 0;
- }
- void usage()
- {
- printf( "\nUsage:\n\n"
- "esdl bind-service <TargetESPProcessName> <TargetESPBindingPort | TargetESPServiceName> <ESDLDefinitionId> <ESDLServiceName> [command options]\n\n"
- " TargetESPProcessName The target ESP Process name\n"
- " TargetESPBindingPort | TargetESPServiceName Either target ESP binding port or target ESP service name\n"
- " ESDLDefinitionId The Name and version of the ESDL definition to bind to this service (must already be defined in dali.)\n"
- " ESDLServiceName The Name of the ESDL Service (as defined in the ESDL Definition)\n"
- "\nOptions (use option flag followed by appropriate value):\n"
- " --config <file|xml> Configuration XML for all methods associated with the target Service\n"
- " --overwrite Overwrite binding if it already exists\n");
- EsdlPublishCmdCommon::usage();
- printf( "\n Use this command to publish ESDL Service based bindings.\n"
- " To bind an ESDL Service, provide the target ESP process name\n"
- " (ESP Process which will host the ESP Service as defined in the ESDL Definition.) \n"
- " It is also necessary to provide the Port on which this service is configured to run (ESP Binding),\n"
- " and the name of the service you are binding.\n"
- " Optionally provide configuration information either directly, or via a\n"
- " configuration file in the following syntax:\n"
- " <Methods>\n"
- " \t<Method name=\"myMethod\" url=\"http://10.45.22.1:292/somepath?someparam=value\" user=\"myuser\" password=\"mypass\"/>\n"
- " \t<Method name=\"myMethod2\" url=\"http://10.45.22.1:292/somepath?someparam=value\" user=\"myuser\" password=\"mypass\"/>\n"
- " </Methods>\n"
- );
- printf("\nExample:"
- ">esdl bind-service myesp 8088 WsMyService --config /myService/methods.xml\n"
- );
- }
- bool parseCommandLineOptions(ArgvIterator &iter)
- {
- if (iter.done())
- {
- usage();
- return false;
- }
- //First 4 parameter's order is fixed.
- //TargetESPProcessName
- //TargetESPBindingPort | TargetESPServiceName
- //ESDLDefinitionId
- //ESDLServiceName
- for (int cur = 0; cur < 4 && !iter.done(); cur++)
- {
- const char *arg = iter.query();
- if (*arg != '-')
- {
- switch (cur)
- {
- case 0:
- optTargetESPProcName.set(arg);
- break;
- case 1:
- optPortOrName.set(arg);
- break;
- case 2:
- optESDLDefID.set(arg);
- break;
- case 3:
- optESDLService.set(arg);
- break;
- }
- }
- else
- {
- fprintf(stderr, "\nOption detected before required arguments: %s\n", arg);
- usage();
- return false;
- }
- iter.next();
- }
- for (; !iter.done(); iter.next())
- {
- if (parseCommandLineOption(iter))
- continue;
- if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
- return false;
- }
- return true;
- }
- bool parseCommandLineOption(ArgvIterator &iter)
- {
- if (iter.matchFlag(optInput, ESDL_OPTION_CONFIG) )
- return true;
- if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
- return true;
- return false;
- }
- bool finalizeOptions(IProperties *globals)
- {
- if (optInput.length())
- {
- const char *in = optInput.get();
- while (*in && isspace(*in)) in++;
- if (*in!='<')
- {
- StringBuffer content;
- content.loadFile(in);
- optInput.set(content.str());
- }
- }
- if (optESDLDefID.isEmpty())
- throw MakeStringException( 0, "ESDL definition ID must be provided!" );
- if (optESDLService.isEmpty())
- throw MakeStringException( 0, "ESDL service definition name must be provided!" );
- if(optTargetESPProcName.isEmpty())
- throw MakeStringException( 0, "Name of Target ESP process must be provided!" );
- if (optPortOrName.isEmpty())
- throw MakeStringException( 0, "Either the target ESP service port of name must be provided!" );
- else
- {
- const char * portorname = optPortOrName.get();
- isdigit(*portorname) ? optTargetPort.set(portorname) : optService.set(portorname);
- }
- return EsdlPublishCmdCommon::finalizeOptions(globals);
- }
- };
- class EsdlUnBindServiceCmd : public EsdlPublishCmdCommon
- {
- protected:
- StringAttr optEspBinding;
- public:
- int processCMD()
- {
- Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
- Owned<IClientDeleteESDLBindingRequest> request = esdlConfigClient->createDeleteESDLBindingRequest();
- fprintf(stdout,"\nAttempting to un-bind ESDL Service: '%s.%s'\n", optTargetESPProcName.get(), optEspBinding.get());
- StringBuffer id;
- id.setf("%s.%s", optTargetESPProcName.get(), optEspBinding.get());
- request->setId(id);
- Owned<IClientDeleteESDLRegistryEntryResponse> resp = esdlConfigClient->DeleteESDLBinding(request);
- if (resp->getExceptions().ordinality()>0)
- {
- EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
- return 1;
- }
- fprintf(stdout, "\n %s.\n", resp->getStatus().getDescription());
- return 0;
- }
- void usage()
- {
- printf( "\nUsage:\n\n"
- "esdl unbind-service <TargetESPProcessName> <TargetESPBindingPort | TargetESPServiceName> [command options]\n\n"
- " TargetESPProcessName The target ESP Process name\n"
- " TargetESPBindingPort | TargetESPServiceName Either target ESP binding port or target ESP service name\n");
- EsdlPublishCmdCommon::usage();
- printf( "\n Use this command to unpublish ESDL Service based bindings.\n"
- " To unbind an ESDL Service, provide the target ESP process name\n"
- " (ESP Process which will host the ESP Service as defined in the ESDL Definition.) \n"
- " It is also necessary to provide the Port on which this service is configured to run (ESP Binding),\n"
- " and the name of the service you are unbinding.\n"
- );
- printf("\nExample:"
- ">esdl unbind-service myesp 8088 \n"
- );
- }
- bool parseCommandLineOptions(ArgvIterator &iter)
- {
- if (iter.done())
- {
- usage();
- return false;
- }
- for (int cur = 0; cur < 2 && !iter.done(); cur++)
- {
- const char *arg = iter.query();
- if (*arg != '-')
- {
- switch (cur)
- {
- case 0:
- optTargetESPProcName.set(arg);
- break;
- case 1:
- optEspBinding.set(arg);
- break;
- }
- }
- else
- {
- fprintf(stderr, "\nOption detected before required arguments: %s\n", arg);
- usage();
- return false;
- }
- iter.next();
- }
- for (; !iter.done(); iter.next())
- {
- if (parseCommandLineOption(iter))
- continue;
- if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
- return false;
- }
- return true;
- }
- bool parseCommandLineOption(ArgvIterator &iter)
- {
- if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
- return true;
- return false;
- }
- bool finalizeOptions(IProperties *globals)
- {
- if (optTargetESPProcName.isEmpty())
- throw MakeStringException( 0, "Name of Target ESP process must be provided!" );
- if (optEspBinding.isEmpty())
- throw MakeStringException( 0, "Target ESP Binding must be provided!" );
- return EsdlPublishCmdCommon::finalizeOptions(globals);
- }
- };
- class EsdlDeleteESDLDefCmd : public EsdlPublishCmdCommon
- {
- public:
- int processCMD()
- {
- Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
- Owned<IClientDeleteESDLDefinitionRequest> request = esdlConfigClient->createDeleteESDLDefinitionRequest();
- fprintf(stdout,"\nAttempting to delete ESDL definition: '%s.%d'\n", optESDLService.get(), (int)optVersion);
- StringBuffer id;
- id.setf("%s.%d", optESDLService.get(), (int)optVersion);
- request->setId(id);
- Owned<IClientDeleteESDLRegistryEntryResponse> resp = esdlConfigClient->DeleteESDLDefinition(request);
- if (resp->getExceptions().ordinality()>0)
- {
- EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
- return 1;
- }
- fprintf(stdout, "\n %s.\n", resp->getStatus().getDescription());
- return 0;
- }
- void usage()
- {
- printf( "\nUsage:\n\n"
- "esdl delete <ESDLServiceDefinitionName> <ESDLServiceDefinitionVersion> [command options]\n\n"
- " ESDLServiceDefinitionName The name of the ESDL service definition to delete\n"
- " ESDLServiceDefinitionVersion The version of the ESDL service definition to delete\n");
- EsdlPublishCmdCommon::usage();
- printf( "\n Use this command to delete an ESDL Service definition.\n"
- " To delete an ESDL Service definition, provide the definition name and version\n"
- );
- printf("\nExample:"
- ">esdl delete myesdldef 5\n"
- );
- }
- bool parseCommandLineOptions(ArgvIterator &iter)
- {
- if (iter.done())
- {
- usage();
- return false;
- }
- for (int cur = 0; cur < 2 && !iter.done(); cur++)
- {
- const char *arg = iter.query();
- if (*arg != '-')
- {
- switch (cur)
- {
- case 0:
- optESDLService.set(arg);
- break;
- case 1:
- optVersionStr.set(arg);
- break;
- }
- }
- else
- {
- fprintf(stderr, "\nOption detected before required arguments: %s\n", arg);
- usage();
- return false;
- }
- iter.next();
- }
- for (; !iter.done(); iter.next())
- {
- if (parseCommandLineOption(iter))
- continue;
- if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
- return false;
- }
- return true;
- }
- bool parseCommandLineOption(ArgvIterator &iter)
- {
- if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
- return true;
- return false;
- }
- bool finalizeOptions(IProperties *globals)
- {
- if (optESDLService.isEmpty())
- throw MakeStringException( 0, "Name of ESDL service definition must be provided!" );
- if (!optVersionStr.isEmpty())
- {
- optVersion = atof( optVersionStr.get() );
- if( optVersion <= 0 )
- {
- throw MakeStringException( 0, "Version option must be followed by a real number > 0" );
- }
- }
- else
- throw MakeStringException( 0, "ESDL service definition version must be provided!" );
- return EsdlPublishCmdCommon::finalizeOptions(globals);
- }
- };
- class EsdlListESDLDefCmd : public EsdlPublishCmdCommon
- {
- public:
- int processCMD()
- {
- Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
- Owned<IClientListESDLDefinitionsRequest> req = esdlConfigClient->createListESDLDefinitionsRequest();
- fprintf(stdout,"\nAttempting to list ESDL definitions.\n");
- Owned<IClientListESDLDefinitionsResponse> resp = esdlConfigClient->ListESDLDefinitions(req);
- if (resp->getExceptions().ordinality()>0)
- {
- EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
- return 1;
- }
- IArrayOf<IConstESDLDefinition> & defs = resp->getDefinitions();
- if (defs.length() > 0)
- fprintf(stdout, "\nESDL Definitions found:\n");
- ForEachItemIn(defindex, defs)
- {
- IConstESDLDefinition & def = defs.item(defindex);
- fprintf(stdout, "\t%s \n", def.getId());
- }
- return 0;
- }
- void usage()
- {
- printf( "\nUsage:\n\n"
- "esdl list-definitions [command options]\n\n"
- );
- EsdlPublishCmdCommon::usage();
- }
- bool parseCommandLineOptions(ArgvIterator &iter)
- {
- for (; !iter.done(); iter.next())
- {
- if (parseCommandLineOption(iter))
- continue;
- if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
- return false;
- }
- return true;
- }
- bool parseCommandLineOption(ArgvIterator &iter)
- {
- if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
- return true;
- return false;
- }
- bool finalizeOptions(IProperties *globals)
- {
- return EsdlPublishCmdCommon::finalizeOptions(globals);
- }
- };
- class EsdlListESDLBindingsCmd : public EsdlPublishCmdCommon
- {
- public:
- int processCMD()
- {
- Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
- Owned<IClientListESDLBindingsRequest> req = esdlConfigClient->createListESDLBindingsRequest();
- fprintf(stdout,"\nAttempting to list ESDL bindings.\n");
- Owned<IClientListESDLBindingsResponse> resp = esdlConfigClient->ListESDLBindings(req);
- if (resp->getExceptions().ordinality()>0)
- {
- EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
- return 1;
- }
- IArrayOf<IConstESDLBinding> & binds = resp->getBindings();
- if (binds.length() > 0)
- fprintf(stdout, "\nESDL Bindings found:\n");
- ForEachItemIn(bindindex, binds)
- {
- IConstESDLBinding & bind = binds.item(bindindex);
- fprintf(stdout, "\t%s \n", bind.getId());
- }
- return 0;
- }
- void usage()
- {
- printf( "\nUsage:\n\n"
- "esdl list-bindings [command options]\n\n"
- );
- EsdlPublishCmdCommon::usage();
- }
- bool parseCommandLineOptions(ArgvIterator &iter)
- {
- for (; !iter.done(); iter.next())
- {
- if (parseCommandLineOption(iter))
- continue;
- if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
- return false;
- }
- return true;
- }
- bool parseCommandLineOption(ArgvIterator &iter)
- {
- if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
- return true;
- return false;
- }
- bool finalizeOptions(IProperties *globals)
- {
- return EsdlPublishCmdCommon::finalizeOptions(globals);
- }
- };
- class EsdlBindMethodCmd : public EsdlBindServiceCmd
- {
- protected:
- StringAttr optMethod;
- StringAttr optBindingName;
- public:
- int processCMD()
- {
- Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
- Owned<IClientConfigureESDLBindingMethodRequest> request = esdlConfigClient->createConfigureESDLBindingMethodRequest();
- fprintf(stdout,"\nAttempting to configure Method : '%s'.'%s'\n", optService.get(), optMethod.get());
- request->setEspProcName(optTargetESPProcName);
- request->setEspBindingName(optBindingName);
- request->setEsdlServiceName(optService.get());
- VStringBuffer id("%s.%d", optService.get(), (int)optVersion);
- request->setEsdlDefinitionID(id.str());
- request->setConfig(optInput);
- request->setOverwrite(optOverWrite);
- if (optVerbose)
- fprintf(stdout,"\nMethod config: %s\n", optInput.get());
- Owned<IClientConfigureESDLBindingMethodResponse> resp = esdlConfigClient->ConfigureESDLBindingMethod(request);
- if (resp->getExceptions().ordinality()>0)
- {
- EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
- return 1;
- }
- fprintf(stdout, "\n %s.\n", resp->getStatus().getDescription());
- return 0;
- }
- void usage()
- {
- printf( "\nUsage:\n\n"
- "esdl bind-method <TargetESPProcessName> <TargetESPBindingName> <TargetServiceName> <TargetServiceDefVersion> <TargetMethodName> [command options]\n\n"
- " TargetESPProcessName The target ESP Process name\n"
- " TargetESPBindingName The target ESP binding name associated with this service\n"
- " TargetServiceName The name of the Service to bind (must already be defined in dali.)\n"
- " TargetServiceDefVersion The version of the target service ESDL definition (must exist in dali)\n"
- " TargetMethodName The name of the target method (must exist in the service ESDL definition)\n"
- "\nOptions (use option flag followed by appropriate value):\n"
- " --config <file|xml> Configuration XML for all methods associated with the target Service\n"
- " --overwrite Overwrite binding if it already exists\n");
- EsdlPublishCmdCommon::usage();
- printf( "\n Use this command to publish ESDL Service based bindings.\n"
- " To bind a ESDL Service, provide the target ESP process name\n"
- " (esp which will host the service.) \n"
- " It is also necessary to provide the Port on which this service is configured to run (ESP Binding),\n"
- " and the name of the service you are binding.\n"
- " Optionally provide configuration information either directly, or via a\n"
- " configuration file in the following syntax:\n"
- " <Methods>\n"
- " \t<Method name=\"myMethod\" url=\"http://10.45.22.1:292/somepath?someparam=value\" user=\"myuser\" password=\"mypass\"/>\n"
- " \t<Method name=\"myMethod2\" url=\"http://10.45.22.1:292/somepath?someparam=value\" user=\"myuser\" password=\"mypass\"/>\n"
- " </Methods>\n"
- );
- printf("\nExample:"
- ">esdl bind-service myesp 8088 WsMyService --config /myService/methods.xml\n"
- );
- }
- bool parseCommandLineOptions(ArgvIterator &iter)
- {
- if (iter.done())
- {
- usage();
- return false;
- }
- //First 5 parameter order is fixed.
- for (int cur = 0; cur < 5 && !iter.done(); cur++)
- {
- const char *arg = iter.query();
- if (*arg != '-')
- {
- switch (cur)
- {
- case 0:
- optTargetESPProcName.set(arg);
- break;
- case 1:
- optBindingName.set(arg);
- break;
- case 2:
- optService.set(arg);
- break;
- case 3:
- optVersionStr.set(arg);
- break;
- case 4:
- optMethod.set(arg);
- break;
- }
- }
- else
- {
- fprintf(stderr, "\noption detected before required arguments: %s\n", arg);
- usage();
- return false;
- }
- iter.next();
- }
- for (; !iter.done(); iter.next())
- {
- if (parseCommandLineOption(iter))
- continue;
- if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
- return false;
- }
- return true;
- }
- bool finalizeOptions(IProperties *globals)
- {
- if (optInput.length())
- {
- const char *in = optInput.get();
- while (*in && isspace(*in)) in++;
- if (*in!='<')
- {
- StringBuffer content;
- content.loadFile(in);
- optInput.set(content.str());
- }
- }
- if (!optVersionStr.isEmpty())
- {
- optVersion = atof( optVersionStr.get() );
- if( optVersion <= 0 )
- {
- throw MakeStringException( 0, "Version option must be followed by a real number > 0" );
- }
- }
- else
- throw MakeStringException( 0, "ESDL service definition version must be provided!" );
- if(optTargetESPProcName.isEmpty())
- throw MakeStringException( 0, "Name of Target ESP process must be provided" );
- if (optService.isEmpty())
- throw MakeStringException( 0, "Name of ESDL based service must be provided" );
- if (optMethod.isEmpty())
- throw MakeStringException( 0, "Name of ESDL based method must be provided" );
- if (optBindingName.isEmpty())
- throw MakeStringException( 0, "Name of ESP binding must be provided" );
- return EsdlPublishCmdCommon::finalizeOptions(globals);
- }
- };
- class EsdlGetCmd : public EsdlPublishCmdCommon
- {
- protected:
- StringAttr optId;
- public:
- bool parseCommandLineOptions(ArgvIterator &iter)
- {
- if (iter.done())
- {
- usage();
- return false;
- }
- //First parameter is fixed.
- for (int cur = 0; cur < 1 && !iter.done(); cur++)
- {
- const char *arg = iter.query();
- if (*arg != '-')
- {
- optId.set(arg);
- }
- else
- {
- fprintf(stderr, "\noption detected before required arguments: %s\n", arg);
- usage();
- return false;
- }
- iter.next();
- }
- for (; !iter.done(); iter.next())
- {
- if (parseCommandLineOption(iter))
- continue;
- if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
- return false;
- }
- return true;
- }
- bool parseCommandLineOption(ArgvIterator &iter)
- {
- if (iter.matchFlag(optTargetAddress, ESDL_OPTION_TARGET_ESP_ADDRESS))
- return true;
- if (iter.matchFlag(optTargetPort, ESDL_OPTION_TARGET_ESP_PORT) )
- return true;
- if (EsdlPublishCmdCommon::parseCommandLineOption(iter))
- return true;
- return false;
- }
- bool finalizeOptions(IProperties *globals)
- {
- if (optId.isEmpty())
- throw MakeStringException( 0, "ESDL ID must be provided" );
- return EsdlPublishCmdCommon::finalizeOptions(globals);
- }
- };
- class EsdlGetDefinitionCmd : public EsdlGetCmd
- {
- public:
- int processCMD()
- {
- Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
- Owned<IClientGetESDLDefinitionRequest> request = esdlConfigClient->createGetESDLDefinitionRequest();
- fprintf(stdout,"\nAttempting to get ESDL definition: %s\n", optId.get());
- request->setId(optId);
- Owned<IClientGetESDLDefinitionResponse> resp = esdlConfigClient->GetESDLDefinition(request);
- if (resp->getExceptions().ordinality()>0)
- {
- EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
- return 1;
- }
- fprintf(stdout, "\n%s", resp->getXMLDefinition());
- fprintf(stdout, "\n%s.\n", resp->getStatus().getDescription());
- return 0;
- }
- void usage()
- {
- printf( "\nUsage:\n\n"
- "esdl get-definition <ESDLDefinitionID> [command options]\n\n"
- "Options (use option flag followed by appropriate value):\n"
- " ESDLDefinitionID The ESDL Definition id <esdldefname>.<esdldefver>\n"
- );
- EsdlPublishCmdCommon::usage();
- printf( "\n\n Use this command to get DESDL definitions.\n"
- " To specify the target DESDL based service configuration, provide the target ESP process \n"
- " (esp process name or machine IP Address) which hosts the service.\n"
- " It is also necessary to provide the Port on which this service is configured to run,\n"
- " and the name of the service.\n"
- );
- }
- };
- class EsdlGetBindingCmd : public EsdlGetCmd
- {
- public:
- int processCMD()
- {
- Owned<IClientWsESDLConfig> esdlConfigClient = EsdlCmdHelper::getWsESDLConfigSoapService(optWSProcAddress, optWSProcPort, optUser, optPass);
- Owned<IClientGetESDLBindingRequest> request = esdlConfigClient->createGetESDLBindingRequest();
- fprintf(stdout,"\nAttempting to get ESDL binding: %s\n", optId.get());
- request->setEsdlBindingId(optId);
- Owned<IClientGetESDLBindingResponse> resp = esdlConfigClient->GetESDLBinding(request);
- if (resp->getExceptions().ordinality()>0)
- {
- EsdlCmdHelper::outputMultiExceptions(resp->getExceptions());
- return 1;
- }
- fprintf(stdout, "\n%s", resp->getConfigXML());
- fprintf(stdout, "\n%s.\n", resp->getStatus().getDescription());
- return 0;
- }
- void usage()
- {
- printf( "\nUsage:\n\n"
- "esdl get-binding <ESDLBindingId> [command options]\n\n"
- "Options (use option flag followed by appropriate value):\n"
- " ESDLBindingId The target ESDL binding id <espprocessname>.<espbindingname>\n"
- );
- EsdlPublishCmdCommon::usage();
- printf( "\n\n Use this command to get DESDL Service based bindings.\n"
- " To specify the target DESDL based service configuration, provide the target ESP process \n"
- " (esp process name or machine IP Address) which hosts the service.\n"
- " It is also necessary to provide the Port on which this service is configured to run,\n"
- " and the name of the service.\n"
- );
- }
- };
|