123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907 |
- /*##############################################################################
- HPCC SYSTEMS software Copyright (C) 2012 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.
- ############################################################################## */
- #pragma warning (disable : 4786)
- #include <math.h>
- #include "daclient.hpp"
- #include "daft.hpp"
- #include "daftcfg.hpp"
- #include "fterror.hpp"
- #include "fverror.hpp"
- #include "daftprogress.hpp"
- #include "mpbase.hpp"
- #include "daclient.hpp"
- #include "dadfs.hpp"
- #include "dafdesc.hpp"
- #include "dasds.hpp"
- #include "danqs.hpp"
- #include "dalienv.hpp"
- #include "dautils.hpp"
- #include "jfile.hpp"
- #include "wshelpers.hpp"
- #include "LogicFileWrapper.hpp"
- #include "rmtfile.hpp"
- #include "dfuutil.hpp"
- #include "TpWrapper.hpp"
- #include "WUWrapper.hpp"
- #include "portlist.h"
- #include "roxiecommlib.hpp"
- #include "dfuwu.hpp"
- #include "fverror.hpp"
- #include "nbcd.hpp"
- #include "jstring.hpp"
- #include "exception_util.hpp"
- #include "ws_dfuService.hpp"
- #include "hqlerror.hpp"
- #include "hqlexpr.hpp"
- #include "hqlutil.hpp"
- #include "eclrtl.hpp"
- #include "package.h"
- #include "daaudit.hpp"
- #define Action_Delete "Delete"
- #define Action_AddtoSuperfile "Add To Superfile"
- static const char* FEATURE_URL="DfuAccess";
- #define FILE_NEWEST 1
- #define FILE_OLDEST 2
- #define FILE_LARGEST 3
- #define FILE_SMALLEST 4
- #define COUNTBY_SCOPE "Scope"
- #define COUNTBY_OWNER "Owner"
- #define COUNTBY_DATE "Date"
- #define COUNTBY_YEAR "Year"
- #define COUNTBY_QUARTER "Quarter"
- #define COUNTBY_MONTH "Month"
- #define COUNTBY_DAY "Day"
- #define REMOVE_FILE_SDS_CONNECT_TIMEOUT (1000*15) // 15 seconds
- const unsigned NODE_GROUP_CACHE_DEFAULT_TIMEOUT = 30*60*1000; //30 minutes
- const unsigned MAX_VIEWKEYFILE_ROWS = 1000;
- const unsigned MAX_KEY_ROWS = 20;
- short days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- CThorNodeGroup* CThorNodeGroupCache::readNodeGroup(const char* _groupName)
- {
- Owned<IEnvironmentFactory> factory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> env = factory->openEnvironment();
- Owned<IPropertyTree> root = &env->getPTree();
- Owned<IPropertyTreeIterator> it= root->getElements("Software/ThorCluster");
- ForEach(*it)
- {
- IPropertyTree& cluster = it->query();
- StringBuffer groupName;
- getClusterGroupName(cluster, groupName);
- if (groupName.length() && strieq(groupName.str(), _groupName))
- return new CThorNodeGroup(_groupName, cluster.getCount("ThorSlaveProcess"), cluster.getPropBool("@replicateOutputs", false));
- }
- return NULL;
- }
- CThorNodeGroup* CThorNodeGroupCache::lookup(const char* groupName, unsigned timeout)
- {
- CriticalBlock block(sect);
- CThorNodeGroup* item=SuperHashTableOf<CThorNodeGroup, const char>::find(groupName);
- if (item && !item->checkTimeout(timeout))
- return LINK(item);
- Owned<CThorNodeGroup> e = readNodeGroup(groupName);
- if (e)
- replace(*e.getLink()); //if not exists, will be added.
- return e.getClear();
- }
- void CWsDfuEx::init(IPropertyTree *cfg, const char *process, const char *service)
- {
- StringBuffer xpath;
- DBGLOG("Initializing %s service [process = %s]", service, process);
- espProcess.set(process);
- xpath.appendf("Software/EspProcess[@name=\"%s\"]/EspService[@name=\"%s\"]/DefaultScope", process, service);
- cfg->getProp(xpath.str(), defaultScope_);
- xpath.clear().appendf("Software/EspProcess[@name=\"%s\"]/EspService[@name=\"%s\"]/User", process, service);
- cfg->getProp(xpath.str(), user_);
- xpath.clear().appendf("Software/EspProcess[@name=\"%s\"]/EspService[@name=\"%s\"]/Password", process, service);
- cfg->getProp(xpath.str(), password_);
- StringBuffer disableUppercaseTranslation;
- xpath.clear().appendf("Software/EspProcess[@name=\"%s\"]/EspService[@name=\"%s\"]/DisableUppercaseTranslation", process, service);
- cfg->getProp(xpath.str(), disableUppercaseTranslation);
- m_clusterName.clear();
- xpath.clear().appendf("Software/EspProcess[@name=\"%s\"]/EspService[@name=\"%s\"]/ClusterName", process, service);
- cfg->getProp(xpath.str(), m_clusterName);
- Linked<IPropertyTree> globals;
- globals.set(cfg->queryPropTree(StringBuffer("Software/EspProcess[@name=\"").append(process).append("\"]/EspService[@name=\"").append(service).append("\"]").str()));
- const char * plugins = globals->queryProp("Plugins/@path");
- if (plugins)
- queryTransformerRegistry().addPlugins(plugins);
- m_disableUppercaseTranslation = false;
- if (streq(disableUppercaseTranslation.str(), "true"))
- m_disableUppercaseTranslation = true;
- xpath.setf("Software/EspProcess[@name=\"%s\"]/@PageCacheTimeoutSeconds", process);
- if (cfg->hasProp(xpath.str()))
- setPageCacheTimeoutMilliSeconds(cfg->getPropInt(xpath.str()));
- xpath.setf("Software/EspProcess[@name=\"%s\"]/@MaxPageCacheItems", process);
- if (cfg->hasProp(xpath.str()))
- setMaxPageCacheItems(cfg->getPropInt(xpath.str()));
- xpath.setf("Software/EspProcess[@name=\"%s\"]/EspService[@name=\"%s\"]/NodeGroupCacheMinutes", process, service);
- int timeout = cfg->getPropInt(xpath.str(), -1);
- if (timeout > -1)
- nodeGroupCacheTimeout = (unsigned) timeout*60*1000;
- else
- nodeGroupCacheTimeout = NODE_GROUP_CACHE_DEFAULT_TIMEOUT;
- thorNodeGroupCache.setown(new CThorNodeGroupCache());
- if (!daliClientActive())
- throw MakeStringException(-1, "No Dali Connection Active. Please Specify a Dali to connect to in you configuration file");
- setDaliServixSocketCaching(true);
- }
- bool CWsDfuEx::onDFUSearch(IEspContext &context, IEspDFUSearchRequest & req, IEspDFUSearchResponse & resp)
- {
- try
- {
- if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Read, false))
- throw MakeStringException(ECLWATCH_DFU_ACCESS_DENIED, "Failed to Search Logical Files. Permission denied.");
- StringBuffer username;
- context.getUserID(username);
- Owned<IUserDescriptor> userdesc;
- if(username.length() > 0)
- {
- userdesc.setown(createUserDescriptor());
- userdesc->set(username.str(), context.queryPassword(), context.querySignature());
- }
- CTpWrapper dummy;
- IArrayOf<IEspTpCluster> clusters;
- dummy.getClusterProcessList(eqThorCluster, clusters);
- dummy.getHthorClusterList(clusters);
- StringArray dfuclusters;
- ForEachItemIn(k, clusters)
- {
- IEspTpCluster& cluster = clusters.item(k);
- dfuclusters.append(cluster.getName());
- }
- IArrayOf<IEspTpCluster> clusters1;
- dummy.getClusterProcessList(eqRoxieCluster, clusters1);
- ForEachItemIn(k1, clusters1)
- {
- IEspTpCluster& cluster = clusters1.item(k1);
- StringBuffer slaveName = cluster.getName();
- dfuclusters.append(slaveName.str());
- }
- StringArray ftarray;
- ftarray.append("Logical Files and Superfiles");
- ftarray.append("Logical Files Only");
- ftarray.append("Superfiles Only");
- ftarray.append("Not in Superfiles");
- if (req.getShowExample() && *req.getShowExample())
- resp.setShowExample(req.getShowExample());
- resp.setClusterNames(dfuclusters);
- resp.setFileTypes(ftarray);
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- void addToQueryString(StringBuffer &queryString, const char *name, const char *value)
- {
- if (queryString.length() > 0)
- {
- queryString.append("&");
- }
- queryString.append(name);
- queryString.append("=");
- queryString.append(value);
- }
- void addToQueryStringFromInt(StringBuffer &queryString, const char *name, __int64 value)
- {
- if (queryString.length() > 0)
- {
- queryString.append("&");
- }
- queryString.append(name);
- queryString.append("=");
- queryString.append(value);
- }
- void parseTwoStringArrays(const char *input, StringArray& strarray1, StringArray& strarray2)
- {
- if (!input || strlen(input) <= 2)
- return;
- char c0[2], c1[2];
- c0[0] = input[0], c0[1] = 0;
- c1[0] = input[1], c1[1] = 0;
- //the first string usually is a name; the second is a value
- unsigned int name_len = atoi(c0);
- unsigned int value_len = atoi(c1);
- if (name_len > 0 && value_len > 0)
- {
- char * inputText = (char *) input;
- inputText += 2; //skip 2 chars
- for (;;)
- {
- if (!inputText || strlen(inputText) < name_len + value_len)
- break;
- StringBuffer columnNameLenStr, columnValueLenStr;
- for (unsigned i_name = 0; i_name < name_len; i_name++)
- {
- columnNameLenStr.append(inputText[0]);
- inputText++;
- }
- for (unsigned i_value = 0; i_value < value_len; i_value++)
- {
- columnValueLenStr.append(inputText[0]);
- inputText++;
- }
- unsigned columnNameLen = atoi(columnNameLenStr.str());
- unsigned columnValueLen = atoi(columnValueLenStr.str());
- if (!inputText || strlen(inputText) < columnNameLen + columnValueLen)
- break;
- char * colon = inputText + columnNameLen;
- if (!colon)
- break;
- StringAttr tmp;
- tmp.set(inputText, columnNameLen);
- strarray1.append(tmp.get());
- tmp.set(colon, columnValueLen);
- //tmp.toUpperCase();
- strarray2.append(tmp.get());
- inputText = colon + columnValueLen;
- }
- }
- return;
- }
- bool CWsDfuEx::onDFUQuery(IEspContext &context, IEspDFUQueryRequest & req, IEspDFUQueryResponse & resp)
- {
- try
- {
- if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Read, false))
- throw MakeStringException(ECLWATCH_DFU_ACCESS_DENIED, "Failed to Browse Logical Files. Permission denied.");
- StringBuffer username;
- context.getUserID(username);
- Owned<IUserDescriptor> userdesc;
- if(username.length() > 0)
- {
- userdesc.setown(createUserDescriptor());
- userdesc->set(username.str(), context.queryPassword(), context.querySignature());
- }
- doLogicalFileSearch(context, userdesc.get(), req, resp);
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- bool CWsDfuEx::onDFUInfo(IEspContext &context, IEspDFUInfoRequest &req, IEspDFUInfoResponse &resp)
- {
- try
- {
- if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Read, false))
- throw MakeStringException(ECLWATCH_DFU_ACCESS_DENIED, "Failed to access DFUInfo. Permission denied.");
- StringBuffer username;
- context.getUserID(username);
- Owned<IUserDescriptor> userdesc;
- if(username.length() > 0)
- {
- userdesc.setown(createUserDescriptor());
- userdesc->set(username.str(), context.queryPassword(), context.querySignature());
- }
- if (req.getUpdateDescription())
- {
- double version = context.getClientVersion();
- if (version < 1.38)
- doGetFileDetails(context, userdesc.get(), req.getFileName(), req.getCluster(), req.getQuerySet(), req.getQuery(), req.getFileDesc(),
- req.getIncludeJsonTypeInfo(), req.getIncludeBinTypeInfo(), resp.updateFileDetail());
- else
- doGetFileDetails(context, userdesc.get(), req.getName(), req.getCluster(), req.getQuerySet(), req.getQuery(), req.getFileDesc(),
- req.getIncludeJsonTypeInfo(), req.getIncludeBinTypeInfo(), resp.updateFileDetail());
- }
- else
- {
- doGetFileDetails(context, userdesc.get(), req.getName(), req.getCluster(), req.getQuerySet(), req.getQuery(), NULL,
- req.getIncludeJsonTypeInfo(), req.getIncludeBinTypeInfo(), resp.updateFileDetail());
- }
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- bool CWsDfuEx::onDFUSpace(IEspContext &context, IEspDFUSpaceRequest & req, IEspDFUSpaceResponse & resp)
- {
- try
- {
- if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Read, false))
- throw MakeStringException(ECLWATCH_DFU_ACCESS_DENIED, "Failed to Browse Space Usage. Permission denied.");
- StringBuffer username;
- context.getUserID(username);
- Owned<IUserDescriptor> userdesc;
- if(username.length() > 0)
- {
- userdesc.setown(createUserDescriptor());
- userdesc->set(username.str(), context.queryPassword(), context.querySignature());
- }
- const char *countby = req.getCountBy();
- if (!countby || strlen(countby) < 1)
- return true;
- char *scopeName = NULL;
- StringBuffer filter;
- if(req.getScopeUnder() && *req.getScopeUnder())
- {
- scopeName = (char *) req.getScopeUnder();
- filter.appendf("%s::*", scopeName);
- resp.setScopeUnder(req.getScopeUnder());
- }
- else
- {
- filter.append("*");
- }
- PROGLOG("DFUSpace: filter %s ", filter.str());
- Owned<IDFAttributesIterator> fi = queryDistributedFileDirectory().getDFAttributesIterator(filter, userdesc.get(), true, false, NULL);
- if(!fi)
- throw MakeStringException(ECLWATCH_CANNOT_GET_FILE_ITERATOR,"Cannot get information from file system.");
- const char *ownerUnder = NULL;
- if(req.getOwnerUnder() && *req.getOwnerUnder())
- {
- ownerUnder = req.getOwnerUnder();
- resp.setOwnerUnder(ownerUnder);
- }
- StringBuffer wuFrom, wuTo, interval;
- unsigned yearFrom = 0, monthFrom, dayFrom, yearTo = 0, monthTo, dayTo, hour, minute, second, nano;
- if(req.getStartDate() && *req.getStartDate())
- {
- CDateTime wuTime;
- wuTime.setString(req.getStartDate(),NULL,true);
- wuTime.getDate(yearFrom, monthFrom, dayFrom, true);
- wuTime.getTime(hour, minute, second, nano, true);
- wuFrom.appendf("%4d-%02d-%02d %02d:%02d:%02d",yearFrom,monthFrom,dayFrom,hour,minute,second);
- StringBuffer startDate;
- startDate.appendf("%02d/%02d/%04d", monthFrom, dayFrom, yearFrom);
- resp.setStartDate(startDate.str());
- }
- if(req.getEndDate() && *req.getEndDate())
- {
- CDateTime wuTime;
- wuTime.setString(req.getEndDate(),NULL,true);
- wuTime.getDate(yearTo, monthTo, dayTo, true);
- wuTime.getTime(hour, minute, second, nano, true);
- wuTo.appendf("%4d-%02d-%02d %02d:%02d:%02d",yearTo,monthTo,dayTo,hour,minute,second);
- StringBuffer endDate;
- endDate.appendf("%02d/%02d/%04d", monthTo, dayTo, yearTo);
- resp.setEndDate(endDate.str());
- }
- unsigned i = 0;
- IArrayOf<IEspSpaceItem> SpaceItems64;
- if (!stricmp(countby, COUNTBY_DATE))
- {
- if (yearFrom < 1 || yearTo < 1)
- {
- StringBuffer wuFrom, wuTo;
- bool bFirst = true;
- ForEach(*fi)
- {
- IPropertyTree &attr=fi->query();
- StringBuffer modf(attr.queryProp("@modified"));
- //char* t=strchr(modf.str(),'T');
- //if(t) *t=' ';
- if (bFirst)
- {
- bFirst = false;
- wuFrom = modf.str();
- wuTo = modf.str();
- continue;
- }
- if (strcmp(modf.str(),wuFrom.str())<0)
- wuFrom = modf.str();
- if (strcmp(modf.str(),wuTo.str())>0)
- wuTo = modf.str();
- }
- if (yearFrom < 1)
- {
- CDateTime wuTime;
- wuTime.setString(wuFrom.str(),NULL,true);
- wuTime.getDate(yearFrom, monthFrom, dayFrom, true);
- }
- if (yearTo < 1)
- {
- CDateTime wuTime;
- wuTime.setString(wuTo.str(),NULL,true);
- wuTime.getDate(yearTo, monthTo, dayTo, true);
- }
- }
- interval = req.getInterval();
- resp.setInterval(interval);
- createSpaceItemsByDate(SpaceItems64, interval, yearFrom, monthFrom, dayFrom, yearTo, monthTo, dayTo);
- }
- else
- {
- Owned<IEspSpaceItem> item64 = createSpaceItem();
- if (stricmp(countby, COUNTBY_OWNER))
- {
- if (scopeName)
- item64->setName(scopeName);
- else
- item64->setName("(root)");
- }
- else
- {
- item64->setName("(empty)");
- }
- item64->setNumOfFilesInt(0);
- item64->setNumOfFilesIntUnknown(0);
- item64->setTotalSizeInt(0);
- item64->setLargestSizeInt(0);
- item64->setSmallestSizeInt(0);
- item64->setLargestFile("");
- item64->setSmallestFile("");
- SpaceItems64.append(*item64.getClear());
- }
- ForEach(*fi)
- {
- IPropertyTree &attr=fi->query();
- if (attr.hasProp("@numsubfiles"))
- continue; //exclude superfiles
- if (ownerUnder)
- {
- const char* owner=attr.queryProp("@owner");
- if (owner && stricmp(owner, ownerUnder))
- continue;
- }
- StringBuffer modf(attr.queryProp("@modified"));
- char* t= (char *) strchr(modf.str(),'T');
- if(t) *t=' ';
- if (wuFrom.length() && strcmp(modf.str(),wuFrom.str())<0)
- continue;
- if (wuTo.length() && strcmp(modf.str(),wuTo.str())>0)
- continue;
- if (!stricmp(countby, COUNTBY_DATE))
- {
- setSpaceItemByDate(SpaceItems64, interval, attr.queryProp("@modified"), attr.queryProp("@name"), attr.getPropInt64("@size",-1));
- }
- else if (!stricmp(countby, COUNTBY_OWNER))
- {
- setSpaceItemByOwner(SpaceItems64, attr.queryProp("@owner"), attr.queryProp("@name"), attr.getPropInt64("@size",-1));
- }
- else
- {
- setSpaceItemByScope(SpaceItems64, scopeName, attr.queryProp("@name"), attr.getPropInt64("@size",-1));
- }
- }
- i = 0;
- IEspSpaceItem& item0 = SpaceItems64.item(0);
- if (item0.getNumOfFilesInt() < 1)
- {
- i++;
- }
- double version = context.getClientVersion();
- IArrayOf<IEspDFUSpaceItem> SpaceItems;
- for(; i < SpaceItems64.length();i++)
- {
- IEspSpaceItem& item64 = SpaceItems64.item(i);
- if (item64.getNumOfFilesInt() < 1)
- continue;
- StringBuffer buf;
- Owned<IEspDFUSpaceItem> item1 = createDFUSpaceItem("","");
- __int64 numOfFiles = item64.getNumOfFilesInt();
- __int64 numOfFilesIntUnknown = item64.getNumOfFilesIntUnknown();
- __int64 totalSize = item64.getTotalSizeInt();
- __int64 largestSize = item64.getLargestSizeInt();
- __int64 smallestSize = item64.getSmallestSizeInt();
- if (version >= 1.38)
- {
- item1->setNumOfFilesInt64(numOfFiles);
- item1->setNumOfFilesUnknownInt64(numOfFilesIntUnknown);
- item1->setTotalSizeInt64(totalSize);
- item1->setLargestSizeInt64(largestSize);
- item1->setSmallestSizeInt64(smallestSize);
- }
- item1->setName(item64.getName());
- buf << comma(numOfFiles);
- item1->setNumOfFiles(buf.str());
- buf.clear();
- buf << comma(numOfFilesIntUnknown);
- item1->setNumOfFilesUnknown(buf.str());
- buf.clear();
- buf << comma(totalSize);
- item1->setTotalSize(buf.str());
- buf.clear();
- buf << comma(largestSize);
- item1->setLargestSize(buf.str());
- buf.clear();
- buf << comma(smallestSize);
- item1->setSmallestSize(buf.str());
- item1->setLargestFile(item64.getLargestFile());
- item1->setSmallestFile(item64.getSmallestFile());
- SpaceItems.append(*item1.getClear());
- }
- resp.setDFUSpaceItems(SpaceItems);
- resp.setCountBy(req.getCountBy());
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- bool CWsDfuEx::setSpaceItemByScope(IArrayOf<IEspSpaceItem>& SpaceItems64, const char*scopeName, const char*logicalName, __int64 size)
- {
- char scope[1024];
- scope[0] = 0;
- const char* pName = NULL;
- if (!scopeName)
- {
- pName = strstr(logicalName, "::");
- if (!pName)
- return false;
- strncpy(scope, logicalName, pName - logicalName);
- scope[pName - logicalName] = 0;
- }
- else
- {
- if (strlen(logicalName) <= strlen(scopeName)+2)
- return false;
- char* ppName = (char*) logicalName + strlen(scopeName) + 2;
- pName = strstr(ppName, "::");
- if (pName)
- {
- strncpy(scope, logicalName, pName - logicalName);
- scope[pName - logicalName] = 0;
- }
- }
- if (strlen(scope) > 0)
- {
- IEspSpaceItem *item0 = NULL;
- for(unsigned i = 0; i < SpaceItems64.length();i++)
- {
- IEspSpaceItem& item1 = SpaceItems64.item(i);
- if (!stricmp(item1.getName(), scope))
- {
- item0 = &item1;
- break;
- }
- }
- if (!item0)
- {
- Owned<IEspSpaceItem> item1 = createSpaceItem();
- item1->setName(scope);
- item1->setNumOfFilesInt(1);
- if (size < 0)
- {
- item1->setNumOfFilesIntUnknown(1);
- item1->setTotalSizeInt(0);
- item1->setLargestSizeInt(0);
- item1->setSmallestSizeInt(0);
- item1->setLargestFile("");
- item1->setSmallestFile("");
- }
- else
- {
- item1->setNumOfFilesIntUnknown(0);
- item1->setTotalSizeInt(size);
- item1->setLargestSizeInt(size);
- item1->setSmallestSizeInt(size);
- item1->setLargestFile(logicalName);
- item1->setSmallestFile(logicalName);
- }
- SpaceItems64.append(*item1.getClear());
- }
- else if (size < 0)
- {
- item0->setNumOfFilesIntUnknown(item0->getNumOfFilesIntUnknown() + 1);
- item0->setNumOfFilesInt(item0->getNumOfFilesInt() + 1);
- }
- else
- {
- if (item0->getNumOfFilesInt() == item0->getNumOfFilesIntUnknown() || size > item0->getLargestSizeInt())
- {
- item0->setLargestSizeInt(size);
- item0->setLargestFile(logicalName);
- }
- if (item0->getNumOfFilesInt() == item0->getNumOfFilesIntUnknown() || size < item0->getSmallestSizeInt())
- {
- item0->setSmallestSizeInt(size);
- item0->setSmallestFile(logicalName);
- }
- item0->setNumOfFilesInt(item0->getNumOfFilesInt() + 1);
- item0->setTotalSizeInt(item0->getTotalSizeInt() + size);
- }
- }
- else
- {
- IEspSpaceItem& item0 = SpaceItems64.item(0);
- if (size < 0)
- {
- item0.setNumOfFilesInt(item0.getNumOfFilesInt() + 1);
- item0.setNumOfFilesIntUnknown(item0.getNumOfFilesIntUnknown() + 1);
- }
- else
- {
- if ((item0.getNumOfFilesInt() == item0.getNumOfFilesIntUnknown()) || (size > item0.getLargestSizeInt()))
- {
- item0.setLargestSizeInt(size);
- item0.setLargestFile(logicalName);
- }
- if ((item0.getNumOfFilesInt() == item0.getNumOfFilesIntUnknown()) || (size < item0.getSmallestSizeInt()))
- {
- item0.setSmallestSizeInt(size);
- item0.setSmallestFile(logicalName);
- }
- item0.setNumOfFilesInt(item0.getNumOfFilesInt() + 1);
- item0.setTotalSizeInt(item0.getTotalSizeInt() + size);
- }
- }
- return true;
- }
- bool CWsDfuEx::setSpaceItemByOwner(IArrayOf<IEspSpaceItem>& SpaceItems64, const char *owner, const char *logicalName, __int64 size)
- {
- if (owner && *owner)
- {
- IEspSpaceItem *item0 = NULL;
- for(unsigned i = 0; i < SpaceItems64.length();i++)
- {
- IEspSpaceItem& item1 = SpaceItems64.item(i);
- if (!stricmp(item1.getName(), owner))
- {
- item0 = &item1;
- break;
- }
- }
- if (!item0)
- {
- Owned<IEspSpaceItem> item1 = createSpaceItem();
- item1->setName(owner);
- item1->setNumOfFilesInt(1);
- if (size < 0)
- {
- item1->setNumOfFilesIntUnknown(1);
- item1->setTotalSizeInt(0);
- item1->setLargestSizeInt(0);
- item1->setSmallestSizeInt(0);
- item1->setLargestFile("");
- item1->setSmallestFile("");
- }
- else
- {
- item1->setNumOfFilesIntUnknown(0);
- item1->setTotalSizeInt(size);
- item1->setLargestSizeInt(size);
- item1->setSmallestSizeInt(size);
- item1->setLargestFile(logicalName);
- item1->setSmallestFile(logicalName);
- }
- SpaceItems64.append(*item1.getClear());
- }
- else if (size < 0)
- {
- item0->setNumOfFilesIntUnknown(item0->getNumOfFilesIntUnknown() + 1);
- item0->setNumOfFilesInt(item0->getNumOfFilesInt() + 1);
- }
- else
- {
- if (item0->getNumOfFilesInt() == item0->getNumOfFilesIntUnknown() || size > item0->getLargestSizeInt())
- {
- item0->setLargestSizeInt(size);
- item0->setLargestFile(logicalName);
- }
- if (item0->getNumOfFilesInt() == item0->getNumOfFilesIntUnknown() || size < item0->getSmallestSizeInt())
- {
- item0->setSmallestSizeInt(size);
- item0->setSmallestFile(logicalName);
- }
- item0->setNumOfFilesInt(item0->getNumOfFilesInt() + 1);
- item0->setTotalSizeInt(item0->getTotalSizeInt() + size);
- }
- }
- else
- {
- IEspSpaceItem& item0 = SpaceItems64.item(0);
- if (size < 0)
- {
- item0.setNumOfFilesInt(item0.getNumOfFilesInt() + 1);
- item0.setNumOfFilesIntUnknown(item0.getNumOfFilesIntUnknown() + 1);
- }
- else
- {
- if ((item0.getNumOfFilesInt() == item0.getNumOfFilesIntUnknown()) || (size > item0.getLargestSizeInt()))
- {
- item0.setLargestSizeInt(size);
- item0.setLargestFile(logicalName);
- }
- if ((item0.getNumOfFilesInt() == item0.getNumOfFilesIntUnknown()) || (size < item0.getSmallestSizeInt()))
- {
- item0.setSmallestSizeInt(size);
- item0.setSmallestFile(logicalName);
- }
- item0.setNumOfFilesInt(item0.getNumOfFilesInt() + 1);
- item0.setTotalSizeInt(item0.getTotalSizeInt() + size);
- }
- }
- return true;
- }
- bool CWsDfuEx::createSpaceItemsByDate(IArrayOf<IEspSpaceItem>& SpaceItems, StringBuffer interval, unsigned& yearFrom,
- unsigned& monthFrom, unsigned& dayFrom, unsigned& yearTo, unsigned& monthTo, unsigned& dayTo)
- {
- if (!stricmp(interval, COUNTBY_YEAR))
- {
- for (unsigned i = yearFrom; i <= yearTo; i++)
- {
- Owned<IEspSpaceItem> item64 = createSpaceItem();
- StringBuffer name;
- name.appendf("%04d", i);
- item64->setName(name.str());
- item64->setNumOfFilesInt(0);
- item64->setNumOfFilesIntUnknown(0);
- item64->setTotalSizeInt(0);
- item64->setLargestSizeInt(0);
- item64->setSmallestSizeInt(0);
- item64->setLargestFile("");
- item64->setSmallestFile("");
- SpaceItems.append(*item64.getClear());
- }
- }
- else if (!stricmp(interval, COUNTBY_QUARTER))
- {
- for (unsigned i = yearFrom; i <= yearTo; i++)
- {
- int quartStart = 1;
- int quartEnd = 4;
- if (i == yearFrom)
- {
- if (monthFrom > 9)
- {
- quartStart = 4;
- }
- else if (monthFrom > 6)
- {
- quartStart = 3;
- }
- else if (monthFrom > 3)
- {
- quartStart = 2;
- }
- }
- if (i == yearTo)
- {
- if (monthTo > 9)
- {
- quartEnd = 4;
- }
- else if (monthTo > 6)
- {
- quartEnd = 3;
- }
- else if (monthTo > 3)
- {
- quartEnd = 2;
- }
- }
- for (int j = quartStart; j <= quartEnd; j++)
- {
- Owned<IEspSpaceItem> item64 = createSpaceItem();
- StringBuffer name;
- name.appendf("%04d quarter: %d", i, j);
- item64->setName(name.str());
- item64->setNumOfFilesInt(0);
- item64->setNumOfFilesIntUnknown(0);
- item64->setTotalSizeInt(0);
- item64->setLargestSizeInt(0);
- item64->setSmallestSizeInt(0);
- item64->setLargestFile("");
- item64->setSmallestFile("");
- SpaceItems.append(*item64.getClear());
- }
- }
- }
- else if (!stricmp(interval, COUNTBY_MONTH))
- {
- for (unsigned i = yearFrom; i <= yearTo; i++)
- {
- int jFrom = (i != yearFrom) ? 1 : monthFrom;
- int jTo = (i != yearTo) ? 12 : monthTo;
- for (int j = jFrom; j <= jTo; j++)
- {
- Owned<IEspSpaceItem> item64 = createSpaceItem();
- StringBuffer name;
- name.appendf("%04d-%02d", i, j);
- item64->setName(name.str());
- item64->setNumOfFilesInt(0);
- item64->setNumOfFilesIntUnknown(0);
- item64->setTotalSizeInt(0);
- item64->setLargestSizeInt(0);
- item64->setSmallestSizeInt(0);
- item64->setLargestFile("");
- item64->setSmallestFile("");
- SpaceItems.append(*item64.getClear());
- }
- }
- }
- else
- {
- for (unsigned i = yearFrom; i <= yearTo; i++)
- {
- int jFrom = (i != yearFrom) ? 1 : monthFrom;
- int jTo = (i != yearTo) ? 12 : monthTo;
- for (int j = jFrom; j <= jTo; j++)
- {
- int dayStart = 1;
- int dayEnd = days[j-1];
- if (i == yearFrom && j == monthFrom)
- {
- dayStart = dayFrom;
- }
- else if (i == yearTo && j == monthTo)
- {
- dayEnd = dayTo;
- }
- for (int k = dayStart; k <= dayEnd; k++)
- {
- Owned<IEspSpaceItem> item64 = createSpaceItem();
- StringBuffer name;
- name.appendf("%04d-%02d-%02d", i, j, k);
- item64->setName(name.str());
- item64->setNumOfFilesInt(0);
- item64->setNumOfFilesIntUnknown(0);
- item64->setTotalSizeInt(0);
- item64->setLargestSizeInt(0);
- item64->setSmallestSizeInt(0);
- item64->setLargestFile("");
- item64->setSmallestFile("");
- SpaceItems.append(*item64.getClear());
- }
- }
- }
- }
- return true;
- }
- bool CWsDfuEx::setSpaceItemByDate(IArrayOf<IEspSpaceItem>& SpaceItems, StringBuffer interval, StringBuffer mod, const char*logicalName, __int64 size)
- {
- unsigned year, month, day;
- CDateTime wuTime;
- wuTime.setString(mod.str(),NULL,true);
- wuTime.getDate(year, month, day, true);
- StringBuffer name;
- if (!stricmp(interval, COUNTBY_YEAR))
- {
- name.appendf("%04d", year);
- }
- else if (!stricmp(interval, COUNTBY_QUARTER))
- {
- int quart = 1;
- if (month > 9)
- {
- quart = 4;
- }
- else if (month > 6)
- {
- quart = 3;
- }
- else if (month > 3)
- {
- quart = 2;
- }
- name.appendf("%04d quarter: %d", year, quart);
- }
- else if (!stricmp(interval, COUNTBY_MONTH))
- {
- name.appendf("%04d-%02d", year, month);
- }
- else
- {
- name.appendf("%04d-%02d-%02d", year, month, day);
- }
- for (unsigned i = 0; i < SpaceItems.length(); i++)
- {
- IEspSpaceItem& item0 = SpaceItems.item(i);
- if (!stricmp(item0.getName(), name))
- {
- if (size < 0)
- {
- item0.setNumOfFilesIntUnknown(item0.getNumOfFilesIntUnknown() + 1);
- }
- else
- {
- if ((item0.getNumOfFilesInt() == item0.getNumOfFilesIntUnknown()) || (size > item0.getLargestSizeInt()))
- {
- item0.setLargestSizeInt(size);
- item0.setLargestFile(logicalName);
- }
- if ((item0.getNumOfFilesInt() == item0.getNumOfFilesIntUnknown()) || (size < item0.getSmallestSizeInt()))
- {
- item0.setSmallestSizeInt(size);
- item0.setSmallestFile(logicalName);
- }
- item0.setTotalSizeInt(item0.getTotalSizeInt() + size);
- }
- item0.setNumOfFilesInt(item0.getNumOfFilesInt() + 1);
- break;
- }
- }
- return true;
- }
- void CWsDfuEx::parseStringArray(const char *input, StringArray& strarray)
- {
- if (!input || !*input)
- return;
- const char *ptr = input;
- const char *pptr = ptr;
- while (pptr[0])
- {
- if (pptr[0] == ',')
- {
- StringAttr tmp;
- tmp.set(ptr, pptr-ptr);
- strarray.append(tmp.get());
- ptr = pptr + 1;
- }
- pptr++;
- }
- if (pptr > ptr)
- {
- StringAttr tmp;
- tmp.set(ptr, pptr-ptr);
- strarray.append(tmp.get());
- }
- }
- int CWsDfuEx::superfileAction(IEspContext &context, const char* action, const char* superfile, StringArray& subfiles,
- const char* beforeSubFile, bool existingSuperfile, bool autocreatesuper, bool deleteFile, bool removeSuperfile)
- {
- if (!action || !*action)
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Superfile action not specified");
- if(!strieq(action, "add") && !strieq(action, "remove"))
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Only Add or Remove is allowed.");
- if (!superfile || !*superfile)
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Superfile name not specified");
- StringBuffer username;
- context.getUserID(username);
- Owned<IUserDescriptor> userdesc;
- if(username.length() > 0)
- {
- userdesc.setown(createUserDescriptor());
- userdesc->set(username.str(), context.queryPassword(), context.querySignature());
- }
- if (!autocreatesuper)
- {//a file lock created by the lookup() will be released after '}'
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(superfile, userdesc.get(), true);
- if (existingSuperfile)
- {
- if (!df)
- throw MakeStringException(ECLWATCH_FILE_NOT_EXIST,"Cannot find file %s.",superfile);
- if(!df->querySuperFile())
- throw MakeStringException(ECLWATCH_NOT_SUPERFILE,"%s is not a superfile.",superfile);
- }
- else if (df)
- throw MakeStringException(ECLWATCH_FILE_ALREADY_EXISTS,"The file %s already exists.",superfile);
- }
- PointerArrayOf<char> subfileArray;
- unsigned num = subfiles.length();
- if (num > 0)
- {
- StringBuffer msgHead;
- if(username.length() > 0)
- msgHead.appendf("%s: Superfile:%s, Subfile(s): ", action, superfile);
- else
- msgHead.appendf("%s: Superfile:%s, Subfile(s): ", action, superfile);
- unsigned filesInMsgBuf = 0;
- StringBuffer msgBuf = msgHead;
- for(unsigned i = 0; i < num; i++)
- {
- subfileArray.append((char*) subfiles.item(i));
- msgBuf.appendf("%s, ", subfiles.item(i));
- filesInMsgBuf++;
- if (filesInMsgBuf > 9)
- {
- PROGLOG("%s",msgBuf.str());
- msgBuf = msgHead;
- filesInMsgBuf = 0;
- }
- }
- if (filesInMsgBuf > 0)
- PROGLOG("%s", msgBuf.str());
- }
- else
- PROGLOG("%s: %s", action, superfile);
- Owned<IDFUhelper> dfuhelper = createIDFUhelper();
- synchronized block(m_superfilemutex);
- if(strieq(action, "add"))
- dfuhelper->addSuper(superfile, userdesc.get(), num, (const char**) subfileArray.getArray(), beforeSubFile, true);
- else
- dfuhelper->removeSuper(superfile, userdesc.get(), num, (const char**) subfileArray.getArray(), deleteFile, removeSuperfile);
- PROGLOG("%s done", action);
- return num;
- }
- bool CWsDfuEx::onAddtoSuperfile(IEspContext &context, IEspAddtoSuperfileRequest &req, IEspAddtoSuperfileResponse &resp)
- {
- try
- {
- if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Write, false))
- throw MakeStringException(ECLWATCH_DFU_ACCESS_DENIED, "Failed to AddtoSuperfile. Permission denied.");
- double version = context.getClientVersion();
- if (version > 1.17)
- {
- const char* backTo = req.getBackToPage();
- if (backTo && *backTo)
- resp.setBackToPage(backTo);
- }
- resp.setSubfiles(req.getSubfiles());
- const char* superfile = req.getSuperfile();
- if (!superfile || !*superfile)
- {
- if (version > 1.15)
- {//Display the subfiles inside a table
- const char* files = req.getSubfiles();
- if (files && *files)
- {
- StringArray subfileNames;
- parseStringArray(files, subfileNames);
- if (subfileNames.length() > 0)
- resp.setSubfileNames(subfileNames);
- }
- }
- return true;//Display a form for user to specify superfile
- }
- if (version > 1.15)
- {
- superfileAction(context, "add", superfile, req.getNames(), NULL, req.getExistingFile(), false, false);
- }
- else
- {
- StringArray subfileNames;
- const char *subfilesStr = req.getSubfiles();
- if (subfilesStr && *subfilesStr)
- parseStringArray(subfilesStr, subfileNames);
- superfileAction(context, "add", superfile, subfileNames, NULL, req.getExistingFile(), false, false);
- }
- resp.setRedirectUrl(StringBuffer("/WsDFU/DFUInfo?Name=").append(superfile));
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- void setDeleteFileResults(const char* fileName, const char* nodeGroup, bool failed, const char *start, const char* text, StringBuffer& resultString,
- IArrayOf<IEspDFUActionInfo>& actionResults)
- {
- if (!fileName || !*fileName)
- return;
- Owned<IEspDFUActionInfo> resultObj = createDFUActionInfo("", "");
- resultObj->setFileName(fileName);
- resultObj->setFailed(failed);
- if (nodeGroup && *nodeGroup)
- resultObj->setNodeGroup(nodeGroup);
- StringBuffer message;
- if (start)
- message.append(start).append(' ');
- message.append(fileName);
- if (nodeGroup && *nodeGroup)
- message.append(" on ").append(nodeGroup);
- if (text && *text)
- message.append(failed ? ": " : " ").append(text);
- resultObj->setActionResult(message);
- resultString.appendf("<Message><Value>%s</Value></Message>", message.str());
- actionResults.append(*resultObj.getClear());
- }
- typedef enum {
- DeleteActionSuccess,
- DeleteActionFailure,
- DeleteActionSkip
- } DeleteActionResult;
- DeleteActionResult doDeleteFile(const char *fn, IUserDescriptor *userdesc, StringArray &superFiles, StringArray &failedFiles,
- const char *auditStr, StringBuffer& returnStr, IArrayOf<IEspDFUActionInfo>& actionResults, bool superFilesOnly, bool removeFromSuperfiles, bool deleteRecursively);
- bool doRemoveFileFromSuperfiles(const char *lfn, IUserDescriptor *userdesc, StringArray &superFiles, StringArray &failedFiles, bool deleteRecursively,
- const char *auditStr, StringBuffer& returnStr, IArrayOf<IEspDFUActionInfo>& actionResults)
- {
- StringArray emptySuperFiles;
- IDistributedFileDirectory &fdir = queryDistributedFileDirectory();
- {
- Owned<IDistributedFile> df = fdir.lookup(lfn, userdesc, true);
- if(!df)
- return false;
- Owned<IDistributedSuperFileIterator> supers = df->getOwningSuperFiles();
- ForEach(*supers)
- {
- IDistributedSuperFile &super = supers->query();
- try
- {
- super.removeSubFile(lfn, false, false, NULL);
- VStringBuffer text("from superfile %s", super.queryLogicalName());
- setDeleteFileResults(lfn, NULL, false, "Removed subfile", text, returnStr, actionResults);
- }
- catch(IException* e)
- {
- StringBuffer emsg;
- VStringBuffer text("from superfile %s: %s", super.queryLogicalName(), e->errorMessage(emsg).str());
- setDeleteFileResults(lfn, NULL, true, "Could not remove subfile ", text, returnStr, actionResults);
- e->Release();
- return false;
- }
- catch(...)
- {
- VStringBuffer text("from superfile %s", super.queryLogicalName());
- setDeleteFileResults(lfn, NULL, true, "Could not remove subfile ", text, returnStr, actionResults);
- return false;
- }
- if (deleteRecursively && super.numSubFiles(false)==0)
- emptySuperFiles.appendUniq(super.queryLogicalName());
- }
- }
- ForEachItemIn(i, emptySuperFiles)
- doDeleteFile(emptySuperFiles.item(i), userdesc, superFiles, failedFiles, auditStr, returnStr, actionResults, false, true, deleteRecursively);
- return true;
- }
- DeleteActionResult doDeleteFile(const char *fn, IUserDescriptor *userdesc, StringArray &superFiles, StringArray &failedFiles,
- const char *auditStr, StringBuffer& returnStr, IArrayOf<IEspDFUActionInfo>& actionResults,
- bool superFilesOnly, bool removeFromSuperfiles, bool deleteRecursively)
- {
- StringArray parsed;
- parsed.appendListUniq(fn, "@");
- const char *lfn = parsed.item(0);
- const char *group = NULL;
- if (parsed.length() > 1)
- {
- group = parsed.item(1);
- if (group && (!*group || strieq(group, "null"))) //null is used by new ECLWatch for a superfile
- group = NULL;
- }
- bool isSuper = false;
- if (superFiles.contains(fn) || failedFiles.contains(fn))
- return DeleteActionSkip;
- try
- {
- IDistributedFileDirectory &fdir = queryDistributedFileDirectory();
- {
- Owned<IDistributedFile> df = fdir.lookup(lfn, userdesc, true);
- if(!df)
- {
- PROGLOG("CWsDfuEx::DFUDeleteFiles: %s not found", lfn);
- setDeleteFileResults(lfn, group, true, "File not found", NULL, returnStr, actionResults);
- return DeleteActionFailure;
- }
- isSuper = df->querySuperFile()!=NULL;
- if (superFilesOnly) // skip non-super files on 1st pass
- {
- if(!isSuper)
- return DeleteActionSkip;
- superFiles.append(fn);
- }
- }
- fdir.removeEntry(fn, userdesc, NULL, REMOVE_FILE_SDS_CONNECT_TIMEOUT, true);
- LOG(daliAuditLogCat, "%s,%s", auditStr, fn);
- setDeleteFileResults(lfn, group, false, isSuper ? "Deleted Superfile" : "Deleted File", NULL, returnStr, actionResults);
- }
- catch(IException* e)
- {
- StringBuffer emsg;
- e->errorMessage(emsg);
- if (removeFromSuperfiles && strstr(emsg, "owned by"))
- {
- if (!doRemoveFileFromSuperfiles(lfn, userdesc, superFiles, failedFiles, deleteRecursively, auditStr, returnStr, actionResults))
- return DeleteActionFailure;
- return doDeleteFile(fn, userdesc, superFiles, failedFiles, auditStr, returnStr, actionResults, superFilesOnly, false, false);
- }
- if (e->errorCode() == DFSERR_CreateAccessDenied)
- emsg.replaceString("Create ", "Delete ");
- setDeleteFileResults(lfn, group, true, "Could not delete", emsg.str(), returnStr, actionResults);
- e->Release();
- return DeleteActionFailure;
- }
- catch(...)
- {
- setDeleteFileResults(lfn, group, true, "Could not delete", "unknown exception", returnStr, actionResults);
- return DeleteActionFailure;
- }
- return DeleteActionSuccess;
- }
- void doDeleteFiles(StringArray &files, IUserDescriptor *userdesc, StringArray &superFiles, StringArray &failedFiles,
- const char *auditStr, StringBuffer &returnStr, IArrayOf<IEspDFUActionInfo> &actionResults,
- bool superFilesOnly, bool removeFromSuperfiles, bool deleteRecursively)
- {
- ForEachItemIn(i, files)
- {
- const char* fn = files.item(i);
- if(!fn || !*fn)
- continue;
- PROGLOG("Deleting %s", fn);
- if (DeleteActionFailure==doDeleteFile(fn, userdesc, superFiles, failedFiles, auditStr, returnStr, actionResults, superFilesOnly, removeFromSuperfiles, deleteRecursively))
- {
- failedFiles.appendUniq(fn);
- PROGLOG("Delete %s failed", fn);
- }
- else
- PROGLOG("Delete %s done", fn);
- }
- }
- inline void doDeleteSuperFiles(StringArray &files, IUserDescriptor *userdesc, StringArray &superFiles,
- StringArray &failedFiles, const char *auditStr, StringBuffer &returnStr, IArrayOf<IEspDFUActionInfo> &actionResults,
- bool removeFromSuperfiles, bool deleteRecursively)
- {
- doDeleteFiles(files, userdesc, superFiles, failedFiles, auditStr, returnStr, actionResults, true, removeFromSuperfiles, deleteRecursively);
- }
- inline void doDeleteSubFiles(StringArray &files, IUserDescriptor *userdesc, StringArray &superFiles,
- StringArray &failedFiles, const char *auditStr, StringBuffer &returnStr, IArrayOf<IEspDFUActionInfo> &actionResults,
- bool removeFromSuperfiles, bool deleteRecursively)
- {
- doDeleteFiles(files, userdesc, superFiles, failedFiles, auditStr, returnStr, actionResults, false, removeFromSuperfiles, deleteRecursively);
- }
- bool CWsDfuEx::DFUDeleteFiles(IEspContext &context, IEspDFUArrayActionRequest &req, IEspDFUArrayActionResponse &resp)
- {
- if (isDetachedFromDali())
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "ESP server is detached from Dali. Please try later.");
- double version = context.getClientVersion();
- Owned<IUserDescriptor> userdesc;
- const char *username = context.queryUserId();
- if(username && *username)
- {
- userdesc.setown(createUserDescriptor());
- userdesc->set(username, context.queryPassword(), context.querySignature());
- }
- StringBuffer returnStr, auditStr = (",FileAccess,WsDfu,DELETED,");
- IArrayOf<IEspDFUActionInfo> actionResults;
- StringArray superFiles, failedFiles;
- auditStr.append(espProcess.get());
- auditStr.append(',');
- if (!isEmptyString(username))
- auditStr.append(username).append('@');
- context.getPeer(auditStr);
- doDeleteSuperFiles(req.getLogicalFiles(), userdesc, superFiles, failedFiles, auditStr.str(),
- returnStr, actionResults, req.getRemoveFromSuperfiles(), req.getRemoveRecursively());
- doDeleteSubFiles(req.getLogicalFiles(), userdesc, superFiles, failedFiles, auditStr.str(),
- returnStr, actionResults, req.getRemoveFromSuperfiles(), req.getRemoveRecursively());
- if (version >= 1.27)
- resp.setActionResults(actionResults);
- if (version < 1.33)
- resp.setDFUArrayActionResult(returnStr.str());
- return true;
- }
- bool CWsDfuEx::onDFUArrayAction(IEspContext &context, IEspDFUArrayActionRequest &req, IEspDFUArrayActionResponse &resp)
- {
- try
- {
- if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Write, false))
- throw MakeStringException(ECLWATCH_DFU_ACCESS_DENIED, "Failed to update Logical Files. Permission denied.");
- CDFUArrayActions action = req.getType();
- if (action == DFUArrayActions_Undefined)
- throw MakeStringException(ECLWATCH_INVALID_INPUT,"Action not defined.");
- double version = context.getClientVersion();
- if (version > 1.03)
- {
- StringBuffer backToPage = req.getBackToPage();
- if (backToPage.length() > 0)
- {
- const char* oldStr = "&";
- const char* newStr = "&";
- backToPage.replaceString(oldStr, newStr);
- resp.setBackToPage(backToPage.str());
- }
- }
- if (action == CDFUArrayActions_Delete)
- return DFUDeleteFiles(context, req, resp);
- //the code below is only for legacy ECLWatch. Other application should use AddtoSuperfile.
- StringBuffer username;
- context.getUserID(username);
- Owned<IUserDescriptor> userdesc;
- if(username.length() > 0)
- {
- userdesc.setown(createUserDescriptor());
- userdesc->set(username.str(), context.queryPassword(), context.querySignature());
- }
- IArrayOf<IEspDFUActionInfo> actionResults;
- StringBuffer errorStr, subfiles;
- for(unsigned i = 0; i < req.getLogicalFiles().length();i++)
- {
- const char* file = req.getLogicalFiles().item(i);
- if(!file || !*file)
- continue;
- unsigned len = strlen(file);
- char* curfile = new char[len+1];
- const char* cluster = NULL;
- const char *pCh = strchr(file, '@');
- if (pCh)
- {
- len = pCh - file;
- if (len+1 < strlen(file))
- cluster = pCh + 1;
- }
- strncpy(curfile, file, len);
- curfile[len] = 0;
- try
- {
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(curfile, userdesc.get(), true);
- if (df)
- {
- if (subfiles.length() > 0)
- subfiles.append(",");
- subfiles.append(curfile);
- }
- else
- setDeleteFileResults(file, NULL, true, NULL, "not found", errorStr, actionResults);
- }
- catch(IException* e)
- {
- StringBuffer emsg;
- e->errorMessage(emsg);
- if (e->errorCode() == DFSERR_CreateAccessDenied)
- emsg.replaceString("Create ", "AddtoSuperfile ");
- setDeleteFileResults(file, NULL, true, NULL, emsg.str(), errorStr, actionResults);
- e->Release();
- }
- catch(...)
- {
- setDeleteFileResults(file, NULL, true, NULL, "unknown exception", errorStr, actionResults);
- }
- delete [] curfile;
- }
- if (version >= 1.27)
- resp.setActionResults(actionResults);
- if (errorStr.length())
- {
- if (version < 1.33)
- resp.setDFUArrayActionResult(errorStr.str());
- return false;
- }
- if (version < 1.18)
- resp.setRedirectUrl(StringBuffer("/WsDFU/AddtoSuperfile?Subfiles=").append(subfiles.str()));
- else
- resp.setRedirectTo(subfiles.str());
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- bool CWsDfuEx::onDFUDefFile(IEspContext &context,IEspDFUDefFileRequest &req, IEspDFUDefFileResponse &resp)
- {
- try
- {
- if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Read, false))
- throw MakeStringException(ECLWATCH_DFU_ACCESS_DENIED, "Failed to access DFUDefFile. Permission denied.");
- CDFUDefFileFormat format = req.getFormat();
- if (format == DFUDefFileFormat_Undefined)
- throw MakeStringException(ECLWATCH_INVALID_INPUT,"Invalid format");
- const char* fileName = req.getName();
- if (!fileName || !*fileName)
- throw MakeStringException(ECLWATCH_MISSING_PARAMS, "File name required");
- PROGLOG("DFUDefFile: %s", fileName);
- StringBuffer username;
- context.getUserID(username);
- StringBuffer rawStr,returnStr;
- Owned<IUserDescriptor> userdesc;
- if(username.length() > 0)
- {
- userdesc.setown(createUserDescriptor());
- userdesc->set(username.str(), context.queryPassword(), context.querySignature());
- }
- getDefFile(userdesc.get(), req.getName(),rawStr);
- StringBuffer xsltFile;
- xsltFile.append(getCFD()).append("smc_xslt/").append(req.getFormatAsString()).append("_def_file.xslt");
- xsltTransformer(xsltFile.str(),rawStr,returnStr);
- //set the file
- MemoryBuffer buff;
- buff.setBuffer(returnStr.length(), (void*)returnStr.str());
- resp.setDefFile(buff);
- //set the type
- StringBuffer type = "text/";
- if (format == CDFUDefFileFormat_xml)
- type.append("xml");
- else
- type.append("plain");
- resp.setDefFile_mimetype(type.str());
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- IHqlExpression * getEclRecordDefinition(const char * ecl)
- {
- MultiErrorReceiver errs;
- OwnedHqlExpr record = parseQuery(ecl, &errs);
- if (errs.errCount())
- {
- StringBuffer errtext;
- IError *first = errs.firstError();
- first->toString(errtext);
- throw MakeStringException(ECLWATCH_CANNOT_PARSE_ECL_QUERY, "Failed in parsing ECL record definition: %s @ %d:%d.", errtext.str(), first->getColumn(), first->getLine());
- }
- if(!record)
- throw MakeStringException(ECLWATCH_CANNOT_PARSE_ECL_QUERY, "Failed in parsing ECL record definition.");
- return record.getClear();
- }
- IHqlExpression * getEclRecordDefinition(IUserDescriptor* udesc, const char* FileName)
- {
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(FileName, udesc);
- if(!df)
- throw MakeStringException(ECLWATCH_FILE_NOT_EXIST,"Cannot find file %s.",FileName);
- if(!df->queryAttributes().hasProp("ECL"))
- throw MakeStringException(ECLWATCH_MISSING_PARAMS,"No record definition for file %s.",FileName);
- return getEclRecordDefinition(df->queryAttributes().queryProp("ECL"));
- }
- bool CWsDfuEx::onDFURecordTypeInfo(IEspContext &context, IEspDFURecordTypeInfoRequest &req, IEspDFURecordTypeInfoResponse &resp)
- {
- try
- {
- if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Read, false))
- throw MakeStringException(ECLWATCH_DFU_ACCESS_DENIED, "Failed to access DFURecordTypeInfo. Permission denied.");
- const char* fileName = req.getName();
- if (!fileName || !*fileName)
- throw MakeStringException(ECLWATCH_MISSING_PARAMS, "File name required");
- PROGLOG("DFURecordTypeInfo file: %s", fileName);
- const char* userId = context.queryUserId();
- Owned<IUserDescriptor> userdesc;
- if(userId && *userId)
- {
- userdesc.setown(createUserDescriptor());
- userdesc->set(userId, context.queryPassword(), context.querySignature());
- }
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(fileName, userdesc);
- if(!df)
- throw MakeStringException(ECLWATCH_FILE_NOT_EXIST,"Cannot find file %s.",fileName);
- if (df->queryAttributes().hasProp("_rtlType"))
- {
- MemoryBuffer layoutBin;
- df->queryAttributes().getPropBin("_rtlType", layoutBin);
- if (req.getIncludeJsonTypeInfo())
- {
- Owned<IRtlFieldTypeDeserializer> deserializer(createRtlFieldTypeDeserializer());
- const RtlTypeInfo *typeInfo = deserializer->deserialize(layoutBin);
- StringBuffer jsonFormat;
- dumpTypeInfo(jsonFormat, typeInfo);
- resp.setJsonInfo(jsonFormat);
- layoutBin.reset(0);
- }
- if (req.getIncludeBinTypeInfo())
- resp.setBinInfo(layoutBin);
- }
- else if (df->queryAttributes().hasProp("ECL"))
- {
- const char * kind = df->queryAttributes().queryProp("@kind");
- bool isIndex = (kind && streq(kind, "key"));
- OwnedHqlExpr record = getEclRecordDefinition(userdesc, fileName);
- if (df->queryAttributes().hasProp("_record_layout"))
- {
- MemoryBuffer mb;
- df->queryAttributes().getPropBin("_record_layout", mb);
- record.setown(patchEclRecordDefinitionFromRecordLayout(record, mb));
- }
- if (req.getIncludeJsonTypeInfo())
- {
- StringBuffer jsonFormat;
- exportJsonType(jsonFormat, record, isIndex);
- resp.setJsonInfo(jsonFormat);
- }
- if (req.getIncludeBinTypeInfo())
- {
- MemoryBuffer binFormat;
- exportBinaryType(binFormat, record, isIndex);
- resp.setBinInfo(binFormat);
- }
- }
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- bool CWsDfuEx::onEclRecordTypeInfo(IEspContext &context, IEspEclRecordTypeInfoRequest &req, IEspEclRecordTypeInfoResponse &resp)
- {
- try
- {
- OwnedHqlExpr record = getEclRecordDefinition(req.getEcl());
- if (req.getIncludeJsonTypeInfo())
- {
- StringBuffer jsonFormat;
- exportJsonType(jsonFormat, record, false); // MORE - could allow isIndex to be passed in?
- resp.setJsonInfo(jsonFormat);
- }
- if (req.getIncludeBinTypeInfo())
- {
- MemoryBuffer binFormat;
- exportBinaryType(binFormat, record, false);
- resp.setBinInfo(binFormat);
- }
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- void CWsDfuEx::xsltTransformer(const char* xsltPath,StringBuffer& source,StringBuffer& returnStr)
- {
- if (m_xsl.get() == 0)
- {
- m_xsl.setown(getXslProcessor());
- }
- Owned<IXslTransform> xform = m_xsl->createXslTransform();
- xform->loadXslFromFile(xsltPath);
- xform->setXmlSource(source.str(), source.length()+1);
- xform->transform(returnStr.clear());
- }
- void CWsDfuEx::getDefFile(IUserDescriptor* udesc, const char* FileName,StringBuffer& returnStr)
- {
- OwnedHqlExpr record = getEclRecordDefinition(udesc, FileName);
- Owned<IPropertyTree> data = createPTree("Table", ipt_caseInsensitive);
- exportData(data, record);
- const char* fname=strrchr(FileName,':');
- data->setProp("filename",fname ? fname+1 : FileName);
- toXML(data, returnStr, 0, 0);
- }
- bool CWsDfuEx::checkFileContent(IEspContext &context, IUserDescriptor* udesc, const char * logicalName, const char * cluster)
- {
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(logicalName, udesc);
- if (!df)
- return false;
- if (!cluster || !stricmp(cluster, ""))
- {
- StringAttr eclCluster;
- const char* wuid = df->queryAttributes().queryProp("@workunit");
- if (wuid && *wuid)
- {
- try
- {
- Owned<IWorkUnitFactory> factory = getWorkUnitFactory();
- if (factory)
- {
- IConstWorkUnit* wu = factory->openWorkUnit(wuid, context.querySecManager(), context.queryUser());
- if (wu)
- eclCluster.set(wu->queryClusterName());
- }
- }
- catch(...)
- {
- return false;
- }
- }
- if (!eclCluster.length())
- return false;
- }
- bool blocked;
- if (df->isCompressed(&blocked) && !blocked)
- return false;
- IPropertyTree & properties = df->queryAttributes();
- const char * format = properties.queryProp("@format");
- if (format && (stricmp(format,"csv")==0 || memicmp(format, "utf", 3) == 0))
- {
- return true;
- }
- const char * recordEcl = properties.queryProp("ECL");
- if (!recordEcl)
- return false;
- MultiErrorReceiver errs;
- Owned< IHqlExpression> ret = ::parseQuery(recordEcl, &errs);
- return errs.errCount() == 0;
- }
- bool FindInStringArray(StringArray& clusters, const char *cluster)
- {
- bool bFound = false;
- if(cluster && *cluster)
- {
- if (clusters.ordinality())
- {
- ForEachItemIn(i, clusters)
- {
- const char* cluster0 = clusters.item(i);
- if(cluster0 && *cluster0 && !stricmp(cluster, cluster0))
- return true;
- }
- }
- }
- else
- {
- #if 0 //Comment out since clusters are not set for some old files
- if (!clusters.ordinality())
- return true;
- ForEachItemIn(i, clusters)
- {
- const char* cluster0 = clusters.item(i);
- if(cluster0 && !*cluster0)
- {
- return true;
- }
- }
- #else
- return true;
- #endif
- }
- return bFound;
- }
- static void getFilePermission(CDfsLogicalFileName &dlfn, ISecUser & user, IUserDescriptor* udesc, ISecManager* secmgr, SecAccessFlags& permission)
- {
- if (dlfn.isMulti())
- {
- if (!dlfn.isExpanded())
- dlfn.expand(udesc);
- unsigned i = dlfn.multiOrdinality();
- while (i--)
- {
- getFilePermission((CDfsLogicalFileName &)dlfn.multiItem(i), user, udesc, secmgr, permission);
- }
- }
- else
- {
- SecAccessFlags permissionTemp;
- if (dlfn.isForeign())
- {
- permissionTemp = queryDistributedFileDirectory().getFilePermissions(dlfn.get(), udesc);
- }
- else
- {
- StringBuffer scopes;
- dlfn.getScopes(scopes);
- permissionTemp = secmgr->authorizeFileScope(user, scopes.str());
- }
- //Descrease the permission whenever a component has a lower permission.
- if (permissionTemp < permission)
- permission = permissionTemp;
- }
- return;
- }
- bool CWsDfuEx::getUserFilePermission(IEspContext &context, IUserDescriptor* udesc, const char* logicalName, SecAccessFlags& permission)
- {
- ISecManager* secmgr = context.querySecManager();
- if (!secmgr)
- {
- return false;
- }
- StringBuffer username;
- StringBuffer password;
- udesc->getUserName(username);
- if (username.length() < 1)
- {
- DBGLOG("User Name not defined\n");
- return false;
- }
- udesc->getPassword(password);
- Owned<ISecUser> user = secmgr->createUser(username);
- if (!user)
- {
- DBGLOG("User %s not found\n", username.str());
- return false;
- }
- if (password.length() > 0)
- user->credentials().setPassword(password);
- CDfsLogicalFileName dlfn;
- dlfn.set(logicalName);
- //Start from the SecAccess_Full. Decrease the permission whenever a component has a lower permission.
- permission = SecAccess_Full;
- getFilePermission(dlfn, *user, udesc, secmgr, permission);
- return true;
- }
- void CWsDfuEx::getFilePartsOnClusters(IEspContext &context, const char* clusterReq, StringArray& clusters, IDistributedFile* df, IEspDFUFileDetail& FileDetails,
- offset_t& mn, offset_t& mx, offset_t& sum, offset_t& count)
- {
- double version = context.getClientVersion();
- IArrayOf<IConstDFUFilePartsOnCluster>& partsOnClusters = FileDetails.getDFUFilePartsOnClusters();
- ForEachItemIn(i, clusters)
- {
- const char* clusterName = clusters.item(i);
- if (!clusterName || !*clusterName || (clusterReq && *clusterReq && !strieq(clusterReq, clusterName)))
- continue;
- Owned<IEspDFUFilePartsOnCluster> partsOnCluster = createDFUFilePartsOnCluster("","");
- partsOnCluster->setCluster(clusterName);
- IArrayOf<IConstDFUPart>& filePartList = partsOnCluster->getDFUFileParts();
- Owned<IFileDescriptor> fdesc = df->getFileDescriptor(clusterName);
- Owned<IPartDescriptorIterator> pi = fdesc->getIterator();
- ForEach(*pi)
- {
- IPartDescriptor& part = pi->query();
- unsigned partIndex = part.queryPartIndex();
- __int64 size = -1;
- StringBuffer partSizeStr;
- IPropertyTree* partPropertyTree = &part.queryProperties();
- if (!partPropertyTree)
- partSizeStr.set("<N/A>");
- else
- {
- size = partPropertyTree->getPropInt64("@size", -1);
- comma c4(size);
- partSizeStr<<c4;
- count++;
- sum+=size;
- if(size>mx) mx=size;
- if(size<mn) mn=size;
- }
- for (unsigned int i=0; i<part.numCopies(); i++)
- {
- StringBuffer b;
- part.queryNode(i)->endpoint().getUrlStr(b);
- Owned<IEspDFUPart> FilePart = createDFUPart("","");
- FilePart->setId(partIndex+1);
- FilePart->setPartsize(partSizeStr.str());
- if (version >= 1.38)
- FilePart->setPartSizeInt64(size);
- FilePart->setIp(b.str());
- FilePart->setCopy(i+1);
- filePartList.append(*FilePart.getClear());
- }
- }
- if (version >= 1.31)
- {
- IClusterInfo* clusterInfo = fdesc->queryCluster(clusterName);
- if (clusterInfo) //Should be valid. But, check it just in case.
- {
- partsOnCluster->setReplicate(clusterInfo->queryPartDiskMapping().isReplicated());
- Owned<CThorNodeGroup> nodeGroup = thorNodeGroupCache->lookup(clusterName, nodeGroupCacheTimeout);
- if (nodeGroup)
- partsOnCluster->setCanReplicate(nodeGroup->queryCanReplicate());
- const char* defaultDir = fdesc->queryDefaultDir();
- if (defaultDir && *defaultDir)
- {
- DFD_OS os = SepCharBaseOs(getPathSepChar(defaultDir));
- StringBuffer baseDir, repDir;
- clusterInfo->getBaseDir(baseDir, os);
- clusterInfo->getReplicateDir(repDir, os);
- partsOnCluster->setBaseDir(baseDir.str());
- partsOnCluster->setReplicateDir(baseDir.str());
- }
- }
- }
- partsOnClusters.append(*partsOnCluster.getClear());
- }
- }
- void CWsDfuEx::parseFieldMask(unsigned __int64 fieldMask, unsigned &fieldCount, IntArray &fieldIndexArray)
- {
- while (fieldMask > 0)
- {
- if (fieldMask & 1)
- fieldIndexArray.append(fieldCount); //index from 0
- fieldMask >>= 1;
- fieldCount++;
- }
- }
- void CWsDfuEx::queryFieldNames(IEspContext &context, const char *fileName, const char *cluster,
- unsigned __int64 fieldMask, StringArray &fieldNames)
- {
- if (!fileName || !*fileName)
- throw MakeStringException(ECLWATCH_MISSING_PARAMS, "File name required");
- Owned<IResultSetFactory> resultSetFactory = getSecResultSetFactory(context.querySecManager(), context.queryUser(), context.queryUserId(), context.queryPassword());
- Owned<INewResultSet> result = resultSetFactory->createNewFileResultSet(fileName, cluster);
- if (!result)
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Failed to access FileResultSet for %s.", fileName);
- unsigned fieldCount = 0;
- IntArray fieldIndexArray;
- parseFieldMask(fieldMask, fieldCount, fieldIndexArray);
- const IResultSetMetaData& metaData = result->getMetaData();
- unsigned totalColumns = (unsigned) metaData.getColumnCount();
- if (fieldCount > totalColumns)
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Invalid FieldMask %" I64F "u: total fields %u, ask for %u.",
- fieldMask, totalColumns, fieldCount);
- ForEachItemIn(i, fieldIndexArray)
- {
- int fieldIndex = fieldIndexArray.item(i);
- SCMStringBuffer columnLabel;
- if (metaData.hasSetTranslation(fieldIndex))
- metaData.getNaturalColumnLabel(columnLabel, fieldIndex);
- if (columnLabel.length() < 1)
- metaData.getColumnLabel(columnLabel, fieldIndex);
- fieldNames.append(columnLabel.str());
- }
- }
- void CWsDfuEx::doGetFileDetails(IEspContext &context, IUserDescriptor *udesc, const char *name, const char *cluster,
- const char *querySet, const char *query, const char *description, bool includeJsonTypeInfo, bool includeBinTypeInfo, IEspDFUFileDetail &FileDetails)
- {
- if (!name || !*name)
- throw MakeStringException(ECLWATCH_MISSING_PARAMS, "File name required");
- PROGLOG("doGetFileDetails: %s", name);
- double version = context.getClientVersion();
- if ((version >= 1.38) && !isEmptyString(querySet) && !isEmptyString(query))
- {
- if (getQueryFile(name, querySet, query, FileDetails))
- return;
- }
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(name, udesc, false, false, true); // lock super-owners
- if(!df)
- throw MakeStringException(ECLWATCH_FILE_NOT_EXIST,"Cannot find file %s.",name);
- StringArray clusters;
- df->getClusterNames(clusters);
- if (cluster && *cluster && !FindInStringArray(clusters, cluster))
- throw MakeStringException(ECLWATCH_FILE_NOT_EXIST,"Cannot find file %s on %s.", name, cluster);
- offset_t size=queryDistributedFileSystem().getSize(df), recordSize=df->queryAttributes().getPropInt64("@recordSize",0);
- CDateTime dt;
- df->getModificationTime(dt);
- const char* lname=df->queryLogicalName(), *fname=strrchr(lname,':');
- FileDetails.setName(lname);
- FileDetails.setFilename(fname ? fname+1 : lname);
- FileDetails.setDir(df->queryDefaultDir());
- FileDetails.setPathMask(df->queryPartMask());
- if (version >= 1.28)
- {
- StringBuffer buf;
- FileDetails.setPrefix(getPrefixFromLogicalName(lname, buf));
- if (cluster && *cluster)
- FileDetails.setNodeGroup(cluster);
- else if (clusters.length() == 1)
- FileDetails.setNodeGroup(clusters.item(0));
- IArrayOf<IEspDFUFileProtect> protectList;
- Owned<IPropertyTreeIterator> itr= df->queryAttributes().getElements("Protect");
- ForEach(*itr)
- {
- IPropertyTree &tree = itr->query();
- const char *owner = tree.queryProp("@name");
- const char *modified = tree.queryProp("@modified");
- int count = tree.getPropInt("@count", 0);
- Owned<IEspDFUFileProtect> protect= createDFUFileProtect();
- if(owner && *owner)
- protect->setOwner(owner);
- if(modified && *modified)
- protect->setModified(modified);
- protect->setCount(count);
- protectList.append(*protect.getLink());
- }
- FileDetails.setProtectList(protectList);
- }
- StringBuffer strDesc = df->queryAttributes().queryProp("@description");
- if (description)
- {
- DistributedFilePropertyLock lock(df);
- lock.queryAttributes().setProp("@description",description);
- strDesc = description;
- }
- FileDetails.setDescription(strDesc);
- if (version >= 1.38)
- FileDetails.setFileSizeInt64(size);
- comma c1(size);
- StringBuffer tmpstr;
- tmpstr<<c1;
- FileDetails.setFilesize(tmpstr.str());
- bool isKeyFile = isFileKey(df);
- if (isKeyFile || df->isCompressed())
- {
- if (version < 1.22)
- FileDetails.setZipFile(true);
- else
- {
- FileDetails.setIsCompressed(true);
- if (df->queryAttributes().hasProp("@compressedSize"))
- {
- __int64 compressedSize = df->queryAttributes().getPropInt64("@compressedSize");
- FileDetails.setCompressedFileSize(compressedSize);
- if (version >= 1.34)
- {
- Decimal d(((double) compressedSize)/size*100);
- d.round(2);
- FileDetails.setPercentCompressed(d.getCString());
- }
- }
- else if (isKeyFile)
- FileDetails.setCompressedFileSize(size);
- }
- }
- if (version >= 1.38)
- FileDetails.setRecordSizeInt64(recordSize);
- comma c2(recordSize);
- tmpstr.clear();
- tmpstr<<c2;
- FileDetails.setRecordSize(tmpstr.str());
- tmpstr.clear();
- __int64 recordCount = -1;
- if (df->queryAttributes().hasProp("@recordCount"))
- {
- recordCount = df->queryAttributes().getPropInt64("@recordCount");
- }
- else if (recordSize)
- {
- recordCount = size/recordSize;
- }
- if (version >= 1.38)
- FileDetails.setRecordCountInt64(recordCount);
- if (recordCount != -1)
- {
- comma c3(recordCount);
- tmpstr<<c3;
- }
- FileDetails.setRecordCount(tmpstr.str());
- FileDetails.setOwner(df->queryAttributes().queryProp("@owner"));
- FileDetails.setJobName(df->queryAttributes().queryProp("@job"));
- if (version >= 1.39)
- {
- if (df->queryAttributes().hasProp("@partitionFieldMask"))
- {
- StringArray partitionFieldNames;
- unsigned __int64 partitionFieldMask = df->queryAttributes().getPropInt64("@partitionFieldMask");
- queryFieldNames(context, name, cluster, partitionFieldMask, partitionFieldNames);
- IEspDFUFilePartition &partition = FileDetails.updatePartition();
- partition.setFieldMask(partitionFieldMask);
- partition.setFieldNames(partitionFieldNames);
- }
- IPropertyTree *bloomTree = df->queryAttributes().queryPropTree("Bloom");
- if (bloomTree)
- {
- StringArray bloomFieldNames;
- unsigned __int64 bloomFieldMask = bloomTree->getPropInt64("@bloomFieldMask");
- queryFieldNames(context, name, cluster, bloomFieldMask, bloomFieldNames);
- IEspDFUFileBloom &bloom = FileDetails.updateBloom();
- bloom.setFieldMask(bloomFieldMask);
- bloom.setFieldNames(bloomFieldNames);
- bloom.setLimit(bloomTree->getPropInt64("@bloomLimit"));
- bloom.setProbability(bloomTree->queryProp("@bloomProbability"));
- }
- }
- //#14280
- IDistributedSuperFile *sf = df->querySuperFile();
- if(sf)
- {
- StringArray farray;
- Owned<IDistributedFileIterator> iter=sf->getSubFileIterator();
- ForEach(*iter)
- {
- StringBuffer subfileName;
- iter->getName(subfileName);
- farray.append(subfileName.str());
- }
- unsigned numSubFiles = farray.length();
- if(numSubFiles > 0)
- {
- FileDetails.setSubfiles(farray);
- }
- if ((version >= 1.28) && (numSubFiles > 1))
- FileDetails.setBrowseData(false); //ViewKeyFile Cannot handle superfile with multiple subfiles
- FileDetails.setIsSuperfile(true);
- return;
- }
- //#14280
- FileDetails.setWuid(df->queryAttributes().queryProp("@workunit"));
- if (version >= 1.28)
- FileDetails.setNumParts(df->numParts());
- //#17430
- {
- IArrayOf<IEspDFULogicalFile> LogicalFiles;
- Owned<IDistributedSuperFileIterator> iter = df->getOwningSuperFiles();
- if(iter.get() != NULL)
- {
- ForEach(*iter)
- {
- //printf("%s,%s\n",iter->query().queryLogicalName(),lname);
- Owned<IEspDFULogicalFile> File = createDFULogicalFile("","");
- File->setName(iter->queryName());
- LogicalFiles.append(*File.getClear());
- }
- }
- if(LogicalFiles.length() > 0)
- {
- FileDetails.setSuperfiles(LogicalFiles);
- }
- }
- //#17430
- //new (optional) attribute on a logical file (@persistent)
- //indicates the ESP page that shows the details of a file. It indicates
- //whether the file was created with a PERSIST() ecl attribute.
- FileDetails.setPersistent(df->queryAttributes().queryProp("@persistent"));
- //@format - what format the file is (if not fixed with)
- FileDetails.setFormat(df->queryAttributes().queryProp("@format"));
- if ((version >= 1.21) && (df->queryAttributes().hasProp("@kind")))
- FileDetails.setContentType(df->queryAttributes().queryProp("@kind"));
- //@maxRecordSize - what the maximum length of records is
- FileDetails.setMaxRecordSize(df->queryAttributes().queryProp("@maxRecordSize"));
- //@csvSeparate - separators between fields for a CSV/utf file
- FileDetails.setCsvSeparate(df->queryAttributes().queryProp("@csvSeparate"));
- //@csvQuote - character used to quote fields for a csv/utf file.
- FileDetails.setCsvQuote(df->queryAttributes().queryProp("@csvQuote"));
- //@csvTerminate - characters used to terminate a record in a csv.utf file
- FileDetails.setCsvTerminate(df->queryAttributes().queryProp("@csvTerminate"));
- //@csvEscape - character used to define escape for a csv/utf file.
- if (version >= 1.20)
- FileDetails.setCsvEscape(df->queryAttributes().queryProp("@csvEscape"));
- //Time and date of the file
- tmpstr.clear();
- dt.getDateString(tmpstr);
- tmpstr.append(" ");
- dt.getTimeString(tmpstr);
- FileDetails.setModified(tmpstr.str());
- if(df->queryAttributes().hasProp("ECL"))
- FileDetails.setEcl(df->queryAttributes().queryProp("ECL"));
- StringBuffer clusterStr;
- ForEachItemIn(i, clusters)
- {
- if (!clusterStr.length())
- clusterStr.append(clusters.item(i));
- else
- clusterStr.append(",").append(clusters.item(i));
- }
- if (clusterStr.length() > 0)
- {
- if (!checkFileContent(context, udesc, name, clusterStr.str()))
- FileDetails.setShowFileContent(false);
- if (version > 1.05)
- {
- bool fromRoxieCluster = false;
- StringArray roxieClusterNames;
- IArrayOf<IEspTpCluster> roxieclusters;
- CTpWrapper dummy;
- dummy.getClusterProcessList(eqRoxieCluster, roxieclusters);
- ForEachItemIn(k, roxieclusters)
- {
- IEspTpCluster& r_cluster = roxieclusters.item(k);
- StringBuffer sName = r_cluster.getName();
- if (FindInStringArray(clusters, sName.str()))
- {
- fromRoxieCluster = true;
- break;
- }
- }
- FileDetails.setFromRoxieCluster(fromRoxieCluster);
- }
- }
- offset_t mn=LLC(0x7fffffffffffffff), mx=0, sum=0, count=0;
- if (version >= 1.25)
- getFilePartsOnClusters(context, cluster, clusters, df, FileDetails, mn, mx, sum, count);
- else
- {
- FileDetails.setCluster(clusters.item(0));
- IArrayOf<IConstDFUPart>& PartList = FileDetails.getDFUFileParts();
- Owned<IDistributedFilePartIterator> pi = df->getIterator();
- ForEach(*pi)
- {
- Owned<IDistributedFilePart> part = &pi->get();
- for (unsigned int i=0; i<part->numCopies(); i++)
- {
- Owned<IEspDFUPart> FilePart = createDFUPart("","");
- StringBuffer b;
- part->queryNode(i)->endpoint().getUrlStr(b);
- FilePart->setId(part->getPartIndex()+1);
- FilePart->setCopy(i+1);
- FilePart->setIp(b.str());
- FilePart->setPartsize("<N/A>");
- try
- {
- offset_t size=queryDistributedFileSystem().getSize(part);
- if (version >= 1.38)
- FilePart->setPartSizeInt64(size);
- comma c4(size);
- tmpstr.clear();
- tmpstr<<c4;
- FilePart->setPartsize(tmpstr.str());
- if(size!=-1)
- {
- count+=1;
- sum+=size;
- if(size>mx) mx=size;
- if(size<mn) mn=size;
- }
- }
- catch(IException *e)
- {
- StringBuffer msg;
- ERRLOG("Exception %d:%s in WS_DFU queryDistributedFileSystem().getSize()", e->errorCode(), e->errorMessage(msg).str());
- e->Release();
- }
- catch(...)
- {
- ERRLOG("Unknown exception in WS_DFU queryDistributedFileSystem().getSize()");
- }
- PartList.append(*FilePart.getClear());
- }
- }
- }
- if(count)
- {
- IEspDFUFileStat& Stat = FileDetails.updateStat();
- offset_t avg=sum/count;
- offset_t minSkew = avg-mn;
- offset_t maxSkew = mx-avg;
- if (version >= 1.38)
- {
- Stat.setMinSkewInt64(minSkew);
- Stat.setMaxSkewInt64(maxSkew);
- }
- comma c5(minSkew);
- tmpstr.clear();
- tmpstr<<c5;
- Stat.setMinSkew(tmpstr.str());
- comma c6(maxSkew);
- tmpstr.clear();
- tmpstr<<c6;
- Stat.setMaxSkew(tmpstr.str());
- }
- if (version > 1.06)
- {
- const char *wuid = df->queryAttributes().queryProp("@workunit");
- if (wuid && *wuid && (wuid[0]=='W'))
- {
- try
- {
- CWUWrapper wu(wuid, context);
- StringArray graphs;
- Owned<IPropertyTreeIterator> f=&wu->getFileIterator();
- ForEach(*f)
- {
- IPropertyTree &query = f->query();
- const char *fileName = query.queryProp("@name");
- const char *graphName = query.queryProp("@graph");
- if (!fileName || !graphName || !*graphName || stricmp(fileName, name))
- continue;
- graphs.append(graphName);
- }
- FileDetails.setGraphs(graphs);
- }
- catch(...)
- {
- DBGLOG("Failed in retrieving graphs from workunit %s", wuid);
- }
- }
- }
- if (version > 1.08 && udesc)
- {
- SecAccessFlags permission;
- if (getUserFilePermission(context, udesc, name, permission))
- {
- switch (permission)
- {
- case SecAccess_Full:
- FileDetails.setUserPermission("Full Access Permission");
- break;
- case SecAccess_Write:
- FileDetails.setUserPermission("Write Access Permission");
- break;
- case SecAccess_Read:
- FileDetails.setUserPermission("Read Access Permission");
- break;
- case SecAccess_Access:
- FileDetails.setUserPermission("Access Permission");
- break;
- case SecAccess_None:
- FileDetails.setUserPermission("None Access Permission");
- break;
- default:
- FileDetails.setUserPermission("Permission Unknown");
- break;
- }
- }
- }
- if (includeJsonTypeInfo||includeBinTypeInfo)
- {
- if (df->queryAttributes().hasProp("_rtlType"))
- {
- MemoryBuffer layoutBin;
- df->queryAttributes().getPropBin("_rtlType", layoutBin);
- if (includeJsonTypeInfo)
- {
- Owned<IRtlFieldTypeDeserializer> deserializer(createRtlFieldTypeDeserializer());
- const RtlTypeInfo *typeInfo = deserializer->deserialize(layoutBin);
- StringBuffer jsonFormat;
- dumpTypeInfo(jsonFormat, typeInfo);
- FileDetails.setJsonInfo(jsonFormat);
- layoutBin.reset(0);
- }
- if (includeBinTypeInfo)
- FileDetails.setBinInfo(layoutBin);
- }
- else if (df->queryAttributes().hasProp("ECL"))
- {
- const char * kind = df->queryAttributes().queryProp("@kind");
- bool isIndex = (kind && streq(kind, "key"));
- OwnedHqlExpr record = getEclRecordDefinition(df->queryAttributes().queryProp("ECL"));
- if (df->queryAttributes().hasProp("_record_layout"))
- {
- MemoryBuffer mb;
- df->queryAttributes().getPropBin("_record_layout", mb);
- record.setown(patchEclRecordDefinitionFromRecordLayout(record, mb));
- }
- if (includeJsonTypeInfo)
- {
- StringBuffer jsonFormat;
- exportJsonType(jsonFormat, record, isIndex);
- FileDetails.setJsonInfo(jsonFormat);
- }
- if (includeBinTypeInfo)
- {
- MemoryBuffer binFormat;
- exportBinaryType(binFormat, record, isIndex);
- FileDetails.setBinInfo(binFormat);
- }
- }
- }
- PROGLOG("doGetFileDetails: %s done", name);
- }
- bool CWsDfuEx::getQueryFile(const char *logicalName, const char *querySet, const char *queryID, IEspDFUFileDetail &fileDetails)
- {
- Owned<IConstWUClusterInfo> info = getTargetClusterInfo(querySet);
- if (!info || (info->getPlatform()!=RoxieCluster))
- return false;
- SCMStringBuffer process;
- info->getRoxieProcess(process);
- if (!process.length())
- return false;
- Owned<IHpccPackageSet> ps = createPackageSet(process.str());
- if (!ps)
- return false;
- const IHpccPackageMap *pm = ps->queryActiveMap(querySet);
- if (!pm)
- return false;
- const IHpccPackage *pkg = pm->matchPackage(queryID);
- if (!pkg)
- return false;
- const char *pkgid = pkg->locateSuperFile(logicalName);
- if (!pkgid)
- return false;
- fileDetails.setName(logicalName);
- fileDetails.setIsSuperfile(true);
- fileDetails.setPackageID(pkgid);
- StringArray subFiles;
- Owned<ISimpleSuperFileEnquiry> ssfe = pkg->resolveSuperFile(logicalName);
- if (ssfe && ssfe->numSubFiles()>0)
- {
- unsigned count = ssfe->numSubFiles();
- while (count--)
- {
- StringBuffer subfile;
- ssfe->getSubFileName(count, subfile);
- subFiles.append(subfile.str());
- }
- if (!subFiles.empty())
- fileDetails.setSubfiles(subFiles);
- }
- return true;
- }
- void CWsDfuEx::getLogicalFileAndDirectory(IEspContext &context, IUserDescriptor* udesc, const char *dirname,
- bool includeSuperOwner, IArrayOf<IEspDFULogicalFile>& logicalFiles, int& numFiles, int& numDirs)
- {
- double version = context.getClientVersion();
- if (dirname && *dirname)
- PROGLOG("getLogicalFileAndDirectory: %s", dirname);
- else
- PROGLOG("getLogicalFileAndDirectory: folder not specified");
- numFiles = 0;
- numDirs = 0;
- if (dirname && *dirname)
- {
- StringBuffer filterBuf;
- setFileNameFilter(NULL, dirname, filterBuf);
- if (includeSuperOwner)
- filterBuf.append(DFUQFTincludeFileAttr).append(DFUQFilterSeparator).append(DFUQSFAOincludeSuperOwner).append(DFUQFilterSeparator);
- //filters used to filter query result received from dali server.
- DFUQResultField localFilters[8];
- localFilters[0] = DFUQRFterm;
- DFUQResultField sortOrder[] = {DFUQRFterm};
- __int64 cacheHint = 0; //No page
- unsigned totalFiles = 0;
- bool allMatchingFilesReceived = true;
- Owned<IDFAttributesIterator> it = queryDistributedFileDirectory().getLogicalFiles(udesc, sortOrder, filterBuf.str(),
- localFilters, NULL, 0, (unsigned)-1, &cacheHint, &totalFiles, &allMatchingFilesReceived, false, false);
- if(!it)
- throw MakeStringException(ECLWATCH_CANNOT_GET_FILE_ITERATOR,"Cannot get LogicalFile information from file system.");
- ForEach(*it)
- addToLogicalFileList(it->query(), NULL, version, logicalFiles);
- numFiles = totalFiles;
- }
- Owned<IDFScopeIterator> iter = queryDistributedFileDirectory().getScopeIterator(udesc,dirname,false);
- if(iter)
- {
- ForEach(*iter)
- {
- const char *scope = iter->query();
- if (scope && *scope)
- {
- Owned<IEspDFULogicalFile> file = createDFULogicalFile("","");
- file->setDirectory(scope);
- file->setIsDirectory(true);
- logicalFiles.append(*file.getClear());
- numDirs++;
- }
- }
- }
- }
- bool CWsDfuEx::onDFUFileView(IEspContext &context, IEspDFUFileViewRequest &req, IEspDFUFileViewResponse &resp)
- {
- try
- {
- if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Read, false))
- throw MakeStringException(ECLWATCH_DFU_ACCESS_DENIED, "Failed to Browse Files by Scope. Permission denied.");
- Owned<IUserDescriptor> userdesc;
- StringBuffer username;
- context.getUserID(username);
- if(username.length() > 0)
- {
- userdesc.setown(createUserDescriptor());
- userdesc->set(username.str(), context.queryPassword(), context.querySignature());
- }
- int numDirs = 0;
- int numFiles = 0;
- IArrayOf<IEspDFULogicalFile> logicalFiles;
- getLogicalFileAndDirectory(context, userdesc.get(), req.getScope(), !req.getIncludeSuperOwner_isNull() && req.getIncludeSuperOwner(), logicalFiles, numFiles, numDirs);
- if (numFiles > 0)
- resp.setNumFiles(numFiles);
- if (req.getScope() && *req.getScope())
- resp.setScope(req.getScope());
- else
- resp.setScope("");
- resp.setDFULogicalFiles(logicalFiles);
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- __int64 CWsDfuEx::findPositionBySize(const __int64 size, bool descend, IArrayOf<IEspDFULogicalFile>& LogicalFiles)
- {
- __int64 addToPos = -1;
- ForEachItemIn(i, LogicalFiles)
- {
- IEspDFULogicalFile& File = LogicalFiles.item(i);
- const char* sSize = File.getLongSize();
- __int64 nSize = atoi64_l(sSize,strlen(sSize));
- if (descend && size > nSize)
- {
- addToPos = i;
- break;
- }
- if (!descend && size < nSize)
- {
- addToPos = i;
- break;
- }
- }
- return addToPos;
- }
- __int64 CWsDfuEx::findPositionByParts(const __int64 parts, bool descend, IArrayOf<IEspDFULogicalFile>& LogicalFiles)
- {
- __int64 addToPos = -1;
- ForEachItemIn(i, LogicalFiles)
- {
- IEspDFULogicalFile& File = LogicalFiles.item(i);
- const char* sParts = File.getParts();
- __int64 nParts = atoi64_l(sParts,strlen(sParts));
- if (descend && parts > nParts)
- {
- addToPos = i;
- break;
- }
- if (!descend && parts < nParts)
- {
- addToPos = i;
- break;
- }
- }
- return addToPos;
- }
- __int64 CWsDfuEx::findPositionByRecords(const __int64 records, bool descend, IArrayOf<IEspDFULogicalFile>& LogicalFiles)
- {
- __int64 addToPos = -1;
- ForEachItemIn(i, LogicalFiles)
- {
- IEspDFULogicalFile& File = LogicalFiles.item(i);
- const char* sRecords = File.getLongRecordCount();
- __int64 nRecords = atoi64_l(sRecords,strlen(sRecords));
- if (descend && records > nRecords)
- {
- addToPos = i;
- break;
- }
- if (!descend && records < nRecords)
- {
- addToPos = i;
- break;
- }
- }
- return addToPos;
- }
- __int64 CWsDfuEx::findPositionByName(const char *name, bool descend, IArrayOf<IEspDFULogicalFile>& LogicalFiles)
- {
- if (!name || (strlen(name) < 1))
- {
- if (descend)
- return -1;
- else
- return 0;
- }
- __int64 addToPos = -1;
- ForEachItemIn(i, LogicalFiles)
- {
- IEspDFULogicalFile& File = LogicalFiles.item(i);
- const char *Name = File.getName();
- if (!Name)
- continue;
- if (descend && strcmp(name, Name)>0)
- {
- addToPos = i;
- break;
- }
- if (!descend && strcmp(name, Name)<0)
- {
- addToPos = i;
- break;
- }
- }
- return addToPos;
- }
- __int64 CWsDfuEx::findPositionByNodeGroup(double version, const char *node, bool descend, IArrayOf<IEspDFULogicalFile>& LogicalFiles)
- {
- if (!node || !*node)
- {
- if (descend)
- return -1;
- else
- return 0;
- }
- __int64 addToPos = -1;
- ForEachItemIn(i, LogicalFiles)
- {
- IEspDFULogicalFile& File = LogicalFiles.item(i);
- const char *nodeGroup = NULL;
- if (version < 1.26)
- nodeGroup = File.getClusterName();
- else
- nodeGroup = File.getNodeGroup();
- if (!nodeGroup)
- continue;
- if (descend && strcmp(node, nodeGroup)>0)
- {
- addToPos = i;
- break;
- }
- if (!descend && strcmp(node, nodeGroup)<0)
- {
- addToPos = i;
- break;
- }
- }
- return addToPos;
- }
- __int64 CWsDfuEx::findPositionByOwner(const char *owner, bool descend, IArrayOf<IEspDFULogicalFile>& LogicalFiles)
- {
- if (!owner || (strlen(owner) < 1))
- {
- if (descend)
- return -1;
- else
- return 0;
- }
- __int64 addToPos = -1;
- ForEachItemIn(i, LogicalFiles)
- {
- IEspDFULogicalFile& File = LogicalFiles.item(i);
- const char *Owner = File.getOwner();
- if (!Owner)
- continue;
- if (descend && strcmp(owner, Owner)>0)
- {
- addToPos = i;
- break;
- }
- if (!descend && strcmp(owner, Owner)<0)
- {
- addToPos = i;
- break;
- }
- }
- return addToPos;
- }
- __int64 CWsDfuEx::findPositionByDate(const char *datetime, bool descend, IArrayOf<IEspDFULogicalFile>& LogicalFiles)
- {
- if (!datetime || (strlen(datetime) < 1))
- {
- if (descend)
- return -1;
- else
- return 0;
- }
- __int64 addToPos = -1;
- ForEachItemIn(i, LogicalFiles)
- {
- IEspDFULogicalFile& File = LogicalFiles.item(i);
- const char *modDate = File.getModified();
- if (!modDate)
- continue;
- if (descend && strcmp(datetime, modDate)>0)
- {
- addToPos = i;
- break;
- }
- if (!descend && strcmp(datetime, modDate)<0)
- {
- addToPos = i;
- break;
- }
- }
- return addToPos;
- }
- __int64 CWsDfuEx::findPositionByDescription(const char *description, bool descend, IArrayOf<IEspDFULogicalFile>& LogicalFiles)
- {
- if (!description || (strlen(description) < 1))
- {
- if (descend)
- return -1;
- else
- return 0;
- }
- __int64 addToPos = -1;
- ForEachItemIn(i, LogicalFiles)
- {
- IEspDFULogicalFile& File = LogicalFiles.item(i);
- const char *Description = File.getDescription();
- if (!Description)
- continue;
- if (descend && strcmp(description, Description)>0)
- {
- addToPos = i;
- break;
- }
- if (!descend && strcmp(description, Description)<0)
- {
- addToPos = i;
- break;
- }
- }
- return addToPos;
- }
- //The code inside this method is copied from previous code for legacy (< 5.0) dali support
- void CWsDfuEx::getAPageOfSortedLogicalFile(IEspContext &context, IUserDescriptor* udesc, IEspDFUQueryRequest & req, IEspDFUQueryResponse & resp)
- {
- double version = context.getClientVersion();
- IArrayOf<IEspDFULogicalFile> LogicalFiles;
- StringBuffer filter;
- const char* fname = req.getLogicalName();
- if(fname && *fname)
- {
- filter.append(fname);
- }
- else
- {
- if(req.getPrefix() && *req.getPrefix())
- {
- filter.append(req.getPrefix());
- filter.append("::");
- }
- filter.append("*");
- }
- Owned<IDFAttributesIterator> fi;
- bool bNotInSuperfile = false;
- const char* sFileType = req.getFileType();
- if (sFileType && !stricmp(sFileType, "Not in Superfiles"))
- {
- bNotInSuperfile = true;
- }
- if (bNotInSuperfile)
- {
- fi.setown(createSubFileFilter(
- queryDistributedFileDirectory().getDFAttributesIterator(filter.toLowerCase().str(),udesc,true,true, NULL),udesc,false)); // NB wrapper owns wrapped iterator
- }
- else
- {
- fi.setown(queryDistributedFileDirectory().getDFAttributesIterator(filter.toLowerCase().str(), udesc,true,true, NULL));
- }
- if(!fi)
- throw MakeStringException(ECLWATCH_CANNOT_GET_FILE_ITERATOR,"Cannot get information from file system.");
- StringBuffer wuFrom, wuTo;
- if(req.getStartDate() && *req.getStartDate())
- {
- CDateTime wuTime;
- wuTime.setString(req.getStartDate(),NULL,true);
- unsigned year, month, day, hour, minute, second, nano;
- wuTime.getDate(year, month, day, true);
- wuTime.getTime(hour, minute, second, nano, true);
- wuFrom.appendf("%4d-%02d-%02d %02d:%02d:%02d",year,month,day,hour,minute,second);
- }
- if(req.getEndDate() && *req.getEndDate())
- {
- CDateTime wuTime;
- wuTime.setString(req.getEndDate(),NULL,true);
- unsigned year, month, day, hour, minute, second, nano;
- wuTime.getDate(year, month, day, true);
- wuTime.getTime(hour, minute, second, nano, true);
- wuTo.appendf("%4d-%02d-%02d %02d:%02d:%02d",year,month,day,hour,minute,second);
- }
- StringBuffer sortBy;
- if(req.getSortby() && *req.getSortby())
- {
- sortBy.append(req.getSortby());
- }
- unsigned pagesize = req.getPageSize();
- if (pagesize < 1)
- {
- pagesize = 100;
- }
- __int64 displayStartReq = 1;
- if (req.getPageStartFrom() > 0)
- displayStartReq = req.getPageStartFrom();
- __int64 displayStart = displayStartReq - 1;
- __int64 displayEnd = displayStart + pagesize;
- bool descending = req.getDescending();
- const int nFirstN = req.getFirstN();
- const char* sFirstNType = req.getFirstNType();
- const __int64 nFileSizeFrom = req.getFileSizeFrom();
- const __int64 nFileSizeTo = req.getFileSizeTo();
- if (nFirstN > 0)
- {
- displayStart = 0;
- displayEnd = nFirstN;
- if (!stricmp(sFirstNType, "newest"))
- {
- sortBy.set("Modified");
- descending = true;
- }
- else if (!stricmp(sFirstNType, "oldest"))
- {
- sortBy.set("Modified");
- descending = false;
- }
- else if (!stricmp(sFirstNType, "largest"))
- {
- sortBy.set("FileSize");
- descending = true;
- }
- else if (!stricmp(sFirstNType, "smallest"))
- {
- sortBy.set("FileSize");
- descending = false;
- }
- pagesize = nFirstN;
- }
- StringArray roxieClusterNames;
- IArrayOf<IEspTpCluster> roxieclusters;
- CTpWrapper dummy;
- dummy.getClusterProcessList(eqRoxieCluster, roxieclusters);
- ForEachItemIn(k, roxieclusters)
- {
- IEspTpCluster& cluster = roxieclusters.item(k);
- StringBuffer sName = cluster.getName();
- roxieClusterNames.append(sName.str());
- }
- StringArray nodeGroupsReq;
- const char* nodeGroupsReqString = req.getNodeGroup();
- if (nodeGroupsReqString && *nodeGroupsReqString)
- nodeGroupsReq.appendListUniq(nodeGroupsReqString, ",");
- StringBuffer size;
- __int64 totalFiles = 0;
- IArrayOf<IEspDFULogicalFile> LogicalFileList;
- ForEach(*fi)
- {
- IPropertyTree &attr=fi->query();
- const char* logicalName=attr.queryProp("@name");
- if (!logicalName || (logicalName[0] == 0))
- continue;
- try
- {
- StringBuffer pref;
- const char *c=strstr(logicalName, "::");
- if (c)
- pref.append(c-logicalName, logicalName);
- else
- pref.append(logicalName);
- const char* owner=attr.queryProp("@owner");
- if (req.getOwner() && *req.getOwner()!=0)
- {
- if (!owner || stricmp(owner, req.getOwner()))
- continue;
- }
- StringArray nodeGroups;
- StringArray fileNodeGroups;
- if (getFileGroups(&attr,fileNodeGroups)==0)
- {
- if (!nodeGroupsReq.length())
- nodeGroups.append("");
- }
- else if (nodeGroupsReq.length() > 0) // check specified cluster name in list
- {
- ForEachItemIn(ii,nodeGroupsReq)
- {
- const char* nodeGroupReq = nodeGroupsReq.item(ii);
- ForEachItemIn(i,fileNodeGroups)
- {
- if (strieq(fileNodeGroups.item(i), nodeGroupReq))
- {
- nodeGroups.append(nodeGroupReq);
- break;
- }
- }
- }
- }
- else if (fileNodeGroups.length())
- {
- ForEachItemIn(i,fileNodeGroups)
- nodeGroups.append(fileNodeGroups.item(i));
- }
- if (sFileType && *sFileType)
- {
- bool bHasSubFiles = attr.hasProp("@numsubfiles");
- if (bHasSubFiles && (bNotInSuperfile || !stricmp(sFileType, "Logical Files Only")))
- continue;
- else if (!bHasSubFiles && !stricmp(sFileType, "Superfiles Only"))
- continue;
- }
- __int64 recordSize=attr.getPropInt64("@recordSize",0), size=attr.getPropInt64("@size",-1);
- if (nFileSizeFrom > 0 && size < nFileSizeFrom)
- continue;
- if (nFileSizeTo > 0 && size > nFileSizeTo)
- continue;
- StringBuffer modf(attr.queryProp("@modified"));
- char* t=(char *) strchr(modf.str(),'T');
- if(t) *t=' ';
- if (wuFrom.length() && strcmp(modf.str(),wuFrom.str())<0)
- continue;
- if (wuTo.length() && strcmp(modf.str(),wuTo.str())>0)
- continue;
- __int64 parts = 0;
- if(!attr.hasProp("@numsubfiles"))
- parts = attr.getPropInt64("@numparts");
- __int64 records = 0;
- if (attr.hasProp("@recordCount"))
- records = attr.getPropInt64("@recordCount");
- else if(recordSize)
- records = size/recordSize;
- const char* desc = attr.queryProp("@description");
- ForEachItemIn(i, nodeGroups)
- {
- const char* nodeGroup = nodeGroups.item(i);
- __int64 addToPos = -1; //Add to tail
- if (stricmp(sortBy, "FileSize")==0)
- {
- addToPos = findPositionBySize(size, descending, LogicalFileList);
- }
- else if (stricmp(sortBy, "Parts")==0)
- {
- addToPos = findPositionByParts(parts, descending, LogicalFileList);
- }
- else if (stricmp(sortBy, "Owner")==0)
- {
- addToPos = findPositionByOwner(owner, descending, LogicalFileList);
- }
- else if (stricmp(sortBy, "NodeGroup")==0)
- {
- addToPos = findPositionByNodeGroup(version, nodeGroup, descending, LogicalFileList);
- }
- else if (stricmp(sortBy, "Records")==0)
- {
- addToPos = findPositionByRecords(records, descending, LogicalFileList);
- }
- else if (stricmp(sortBy, "Modified")==0)
- {
- addToPos = findPositionByDate(modf.str(), descending, LogicalFileList);
- }
- else if (stricmp(sortBy, "Description")==0)
- {
- addToPos = findPositionByDescription(desc, descending, LogicalFileList);
- }
- else
- {
- addToPos = findPositionByName(logicalName, descending, LogicalFileList);
- }
- totalFiles++;
- if (addToPos < 0 && (totalFiles > displayEnd))
- continue;
- Owned<IEspDFULogicalFile> File = createDFULogicalFile("","");
- File->setPrefix(pref);
- if (version < 1.26)
- File->setClusterName(nodeGroup);
- else
- File->setNodeGroup(nodeGroup);
- File->setName(logicalName);
- File->setOwner(owner);
- File->setDescription(desc);
- File->setModified(modf.str());
- File->setReplicate(true);
- ForEachItemIn(j, roxieClusterNames)
- {
- const char* roxieClusterName = roxieClusterNames.item(j);
- if (roxieClusterName && nodeGroup && strieq(roxieClusterName, nodeGroup))
- {
- File->setFromRoxieCluster(true);
- break;
- }
- }
- bool bSuperfile = false;
- int numSubFiles = attr.hasProp("@numsubfiles");
- if(!numSubFiles)
- {
- File->setDirectory(attr.queryProp("@directory"));
- File->setParts(attr.queryProp("@numparts"));
- }
- else
- {
- bSuperfile = true;
- }
- File->setIsSuperfile(bSuperfile);
- if (version < 1.22)
- File->setIsZipfile(isCompressed(attr));
- else
- {
- File->setIsCompressed(isCompressed(attr));
- if (attr.hasProp("@compressedSize"))
- File->setCompressedFileSize(attr.getPropInt64("@compressedSize"));
- }
- //File->setBrowseData(bKeyFile); //Bug: 39750 - All files should be viewable through ViewKeyFile function
- if (numSubFiles > 1) //Bug 41379 - ViewKeyFile Cannot handle superfile with multiple subfiles
- File->setBrowseData(false);
- else
- File->setBrowseData(true);
- if (version > 1.13)
- {
- bool bKeyFile = false;
- const char * kind = attr.queryProp("@kind");
- if (kind && (stricmp(kind, "key") == 0))
- {
- bKeyFile = true;
- }
- if (version < 1.24)
- File->setIsKeyFile(bKeyFile);
- else if (kind && *kind)
- File->setContentType(kind);
- }
- StringBuffer buf;
- buf << comma(size);
- File->setTotalsize(buf.str());
- char temp[64];
- numtostr(temp, size);
- File->setLongSize(temp);
- numtostr(temp, records);
- File->setLongRecordCount(temp);
- if (records > 0)
- File->setRecordCount((buf.clear()<<comma(records)).str());
- if (addToPos < 0)
- LogicalFileList.append(*File.getClear());
- else
- LogicalFileList.add(*File.getClear(), (int) addToPos);
- if (LogicalFileList.length() > displayEnd)
- LogicalFileList.pop();
- }
- }
- catch(IException* e)
- {
- VStringBuffer msg("Failed to retrieve data for logical file %s: ", logicalName);
- int code = e->errorCode();
- e->errorMessage(msg);
- e->Release();
- throw MakeStringException(code, "%s", msg.str());
- }
- }
- if (displayEnd > LogicalFileList.length())
- displayEnd = LogicalFileList.length();
- for (int i = (int) displayStart; i < (int) displayEnd; i++)
- {
- Owned<IEspDFULogicalFile> File = createDFULogicalFile("","");
- IEspDFULogicalFile& File0 = LogicalFileList.item(i);
- File->copy(File0);
- LogicalFiles.append(*File.getClear());
- }
- resp.setNumFiles(totalFiles);
- resp.setPageSize(pagesize);
- resp.setPageStartFrom(displayStart+1);
- resp.setPageEndAt(displayEnd);
- if (displayStart - pagesize > 0)
- resp.setPrevPageFrom(displayStart - pagesize + 1);
- else if(displayStart > 0)
- resp.setPrevPageFrom(1);
- if(displayEnd < totalFiles)
- {
- resp.setNextPageFrom(displayEnd+1);
- resp.setLastPageFrom((int)(pagesize * floor((double) ((totalFiles-1) / pagesize)) + 1));
- }
- StringBuffer basicQuery;
- if (req.getNodeGroup() && *req.getNodeGroup())
- {
- if (version < 1.26)
- resp.setClusterName(req.getNodeGroup());
- else
- resp.setNodeGroup(req.getNodeGroup());
- addToQueryString(basicQuery, "NodeGroup", req.getNodeGroup());
- }
- if (req.getOwner() && *req.getOwner())
- {
- resp.setOwner(req.getOwner());
- addToQueryString(basicQuery, "Owner", req.getOwner());
- }
- if (req.getPrefix() && *req.getPrefix())
- {
- resp.setPrefix(req.getPrefix());
- addToQueryString(basicQuery, "Prefix", req.getPrefix());
- }
- if (req.getLogicalName() && *req.getLogicalName())
- {
- resp.setLogicalName(req.getLogicalName());
- addToQueryString(basicQuery, "LogicalName", req.getLogicalName());
- }
- if (req.getStartDate() && *req.getStartDate())
- {
- resp.setStartDate(req.getStartDate());
- addToQueryString(basicQuery, "StartDate", req.getStartDate());
- }
- if (req.getEndDate() && *req.getEndDate())
- {
- resp.setEndDate(req.getEndDate());
- addToQueryString(basicQuery, "EndDate", req.getEndDate());
- }
- if (req.getFileType() && *req.getFileType())
- {
- resp.setFileType(req.getFileType());
- addToQueryString(basicQuery, "FileType", req.getFileType());
- }
- if (req.getFileSizeFrom())
- {
- resp.setFileSizeFrom(req.getFileSizeFrom());
- addToQueryStringFromInt(basicQuery, "FileSizeFrom", req.getFileSizeFrom());
- }
- if (req.getFileSizeTo())
- {
- resp.setFileSizeTo(req.getFileSizeTo());
- addToQueryStringFromInt(basicQuery, "FileSizeTo", req.getFileSizeTo());
- }
- StringBuffer ParametersForFilters = basicQuery;
- StringBuffer ParametersForPaging = basicQuery;
- addToQueryStringFromInt(ParametersForFilters, "PageSize",pagesize);
- addToQueryStringFromInt(ParametersForPaging, "PageSize", pagesize);
- if (ParametersForFilters.length() > 0)
- resp.setFilters(ParametersForFilters.str());
- sortBy.clear();
- descending = false;
- if ((req.getFirstN() > 0) && req.getFirstNType() && *req.getFirstNType())
- {
- const char *sFirstNType = req.getFirstNType();
- if (!stricmp(sFirstNType, "newest"))
- {
- sortBy.set("Modified");
- descending = true;
- }
- else if (!stricmp(sFirstNType, "oldest"))
- {
- sortBy.set("Modified");
- descending = false;
- }
- else if (!stricmp(sFirstNType, "largest"))
- {
- sortBy.set("FileSize");
- descending = true;
- }
- else if (!stricmp(sFirstNType, "smallest"))
- {
- sortBy.set("FileSize");
- descending = false;
- }
- }
- else if (req.getSortby() && *req.getSortby())
- {
- sortBy.set(req.getSortby());
- if (req.getDescending())
- descending = req.getDescending();
- }
- if (sortBy.length())
- {
- resp.setSortby(sortBy);
- resp.setDescending(descending);
- StringBuffer strbuf = sortBy;
- strbuf.append("=");
- String str1(strbuf.str());
- String str(basicQuery.str());
- if (str.indexOf(str1) < 0)
- {
- addToQueryString(ParametersForPaging, "Sortby", sortBy);
- addToQueryString(basicQuery, "Sortby", sortBy);
- if (descending)
- {
- addToQueryString(ParametersForPaging, "Descending", "1");
- addToQueryString(basicQuery, "Descending", "1");
- }
- }
- }
- if (basicQuery.length() > 0)
- resp.setBasicQuery(basicQuery.str());
- if (ParametersForPaging.length() > 0)
- resp.setParametersForPaging(ParametersForPaging.str());
- resp.setDFULogicalFiles(LogicalFiles);
- return;
- }
- bool CWsDfuEx::addDFUQueryFilter(DFUQResultField *filters, unsigned short &count, MemoryBuffer &buff, const char* value, DFUQResultField name)
- {
- if (!value || !*value)
- return false;
- filters[count++] = name;
- buff.append(value);
- return true;
- }
- void CWsDfuEx::appendDFUQueryFilter(const char *name, DFUQFilterType type, const char *value, StringBuffer& filterBuf)
- {
- if (!name || !*name || !value || !*value)
- return;
- filterBuf.append(type).append(DFUQFilterSeparator).append(name).append(DFUQFilterSeparator).append(value).append(DFUQFilterSeparator);
- }
- void CWsDfuEx::appendDFUQueryFilter(const char *name, DFUQFilterType type, const char *value, const char *valueHigh, StringBuffer& filterBuf)
- {
- if (!name || !*name || !value || !*value)
- return;
- filterBuf.append(type).append(DFUQFilterSeparator).append(name).append(DFUQFilterSeparator).append(value).append(DFUQFilterSeparator);
- filterBuf.append(valueHigh).append(DFUQFilterSeparator);
- }
- void CWsDfuEx::setFileTypeFilter(const char* fileType, StringBuffer& filterBuf)
- {
- DFUQFileTypeFilter fileTypeFilter = DFUQFFTall;
- if (!fileType || !*fileType)
- {
- filterBuf.append(DFUQFTspecial).append(DFUQFilterSeparator).append(DFUQSFFileType).append(DFUQFilterSeparator).append(fileTypeFilter).append(DFUQFilterSeparator);
- return;
- }
- bool notInSuperfile = false;
- if (strieq(fileType, "Superfiles Only"))
- fileTypeFilter = DFUQFFTsuperfileonly;
- else if (strieq(fileType, "Logical Files Only"))
- fileTypeFilter = DFUQFFTnonsuperfileonly;
- else if (strieq(fileType, "Not in Superfiles"))
- notInSuperfile = true;
- else
- fileTypeFilter = DFUQFFTall;
- filterBuf.append(DFUQFTspecial).append(DFUQFilterSeparator).append(DFUQSFFileType).append(DFUQFilterSeparator).append(fileTypeFilter).append(DFUQFilterSeparator);
- if (notInSuperfile)
- appendDFUQueryFilter(getDFUQFilterFieldName(DFUQFFsuperowner), DFUQFThasProp, "0", filterBuf);
- }
- void CWsDfuEx::setFileNameFilter(const char* fname, const char* prefix, StringBuffer &filterBuf)
- {
- StringBuffer fileNameFilter;
- if(fname && *fname)
- fileNameFilter.append(fname);//ex. *part_of_file_name*
- else
- {
- if(prefix && *prefix)
- {
- fileNameFilter.append(prefix);
- fileNameFilter.append("::");
- }
- fileNameFilter.append("*");
- }
- fileNameFilter.toLowerCase();
- filterBuf.append(DFUQFTspecial).append(DFUQFilterSeparator).append(DFUQSFFileNameWithPrefix).append(DFUQFilterSeparator).append(fileNameFilter.str()).append(DFUQFilterSeparator);
- }
- void CWsDfuEx::setFileIterateFilter(unsigned maxFiles, StringBuffer &filterBuf)
- {
- filterBuf.append(DFUQFTspecial).append(DFUQFilterSeparator).append(DFUQSFMaxFiles).append(DFUQFilterSeparator)
- .append(maxFiles).append(DFUQFilterSeparator);
- }
- void CWsDfuEx::setDFUQueryFilters(IEspDFUQueryRequest& req, StringBuffer& filterBuf)
- {
- setFileNameFilter(req.getLogicalName(), req.getPrefix(), filterBuf);
- setFileTypeFilter(req.getFileType(), filterBuf);
- appendDFUQueryFilter(getDFUQFilterFieldName(DFUQFFattrowner), DFUQFTwildcardMatch, req.getOwner(), filterBuf);
- appendDFUQueryFilter(getDFUQFilterFieldName(DFUQFFkind), DFUQFTwildcardMatch, req.getContentType(), filterBuf);
- appendDFUQueryFilter(getDFUQFilterFieldName(DFUQFFgroup), DFUQFTcontainString, req.getNodeGroup(), ",", filterBuf);
- if (!req.getIncludeSuperOwner_isNull() && req.getIncludeSuperOwner())
- filterBuf.append(DFUQFTincludeFileAttr).append(DFUQFilterSeparator).append(DFUQSFAOincludeSuperOwner).append(DFUQFilterSeparator);
- __int64 sizeFrom = req.getFileSizeFrom();
- __int64 sizeTo = req.getFileSizeTo();
- if ((sizeFrom > 0) || (sizeTo > 0))
- {
- StringBuffer buf;
- if (sizeFrom > 0)
- buf.append(sizeFrom);
- buf.append("|");
- if (sizeTo > 0)
- buf.append(sizeTo);
- filterBuf.append(DFUQFTinteger64Range).append(DFUQFilterSeparator).append(getDFUQFilterFieldName(DFUQFFattrsize));
- filterBuf.append(DFUQFilterSeparator).append(buf.str()).append(DFUQFilterSeparator);
- }
- const char* startDate = req.getStartDate();
- const char* endDate = req.getEndDate();
- if((startDate && *startDate) || (endDate && *endDate))
- {
- StringBuffer buf;
- if(startDate && *startDate)
- {
- StringBuffer wuFrom;
- CDateTime wuTime;
- wuTime.setString(startDate,NULL);
- buf.append(wuTime.getString(wuFrom).str());
- }
- buf.append("|");
- if(endDate && *endDate)
- {
- StringBuffer wuTo;
- CDateTime wuTime;
- wuTime.setString(endDate,NULL);
- buf.append(wuTime.getString(wuTo).str());
- }
- filterBuf.append(DFUQFTstringRange).append(DFUQFilterSeparator).append(getDFUQFilterFieldName(DFUQFFtimemodified));
- filterBuf.append(DFUQFilterSeparator).append(buf.str()).append(DFUQFilterSeparator);
- }
- }
- void CWsDfuEx::setDFUQuerySortOrder(IEspDFUQueryRequest& req, StringBuffer& sortBy, bool& descending, DFUQResultField* sortOrder)
- {
- const char* sortByReq = req.getSortby();
- if (!sortByReq || !*sortByReq)
- return;
- sortBy.set(sortByReq);
- if (req.getDescending())
- descending = req.getDescending();
- const char* sortByPtr = sortBy.str();
- if (strieq(sortByPtr, "FileSize"))
- sortOrder[0] = (DFUQResultField) (DFUQRFsize | DFUQRFnumeric);
- else if (strieq(sortByPtr, "IsCompressed"))
- sortOrder[0] = (DFUQResultField) (DFUQRFiscompressed | DFUQRFnumeric);
- else if (strieq(sortByPtr, "CompressedSize"))
- sortOrder[0] = (DFUQResultField) (DFUQRFcompressedsize | DFUQRFnumeric);
- else if (strieq(sortByPtr, "Parts"))
- sortOrder[0] = (DFUQResultField) (DFUQRFnumparts | DFUQRFnumeric);
- else if (strieq(sortByPtr, "Records"))
- sortOrder[0] = (DFUQResultField) (DFUQRFrecordcount | DFUQRFnumeric);
- else if (strieq(sortByPtr, "Owner"))
- sortOrder[0] = DFUQRFowner;
- else if (strieq(sortByPtr, "NodeGroup"))
- sortOrder[0] = DFUQRFnodegroup;
- else if (strieq(sortByPtr, "Modified"))
- sortOrder[0] = DFUQRFtimemodified;
- else if (strieq(sortByPtr, "ContentType"))
- sortOrder[0] = DFUQRFkind;
- else
- sortOrder[0] = DFUQRFname;
- sortOrder[0] = (DFUQResultField) (sortOrder[0] | DFUQRFnocase);
- if (descending)
- sortOrder[0] = (DFUQResultField) (sortOrder[0] | DFUQRFreverse);
- return;
- }
- const char* CWsDfuEx::getPrefixFromLogicalName(const char* logicalName, StringBuffer& prefix)
- {
- if (!logicalName || !*logicalName)
- return NULL;
- const char *c=strstr(logicalName, "::");
- if (c)
- prefix.append(c-logicalName, logicalName);
- else
- prefix.append(logicalName);
- return prefix.str();
- }
- bool CWsDfuEx::addToLogicalFileList(IPropertyTree& file, const char* nodeGroup, double version, IArrayOf<IEspDFULogicalFile>& logicalFiles)
- {
- const char* logicalName = file.queryProp(getDFUQResultFieldName(DFUQRFname));
- if (!logicalName || !*logicalName)
- return false;
- try
- {
- Owned<IEspDFULogicalFile> lFile = createDFULogicalFile("","");
- lFile->setName(logicalName);
- lFile->setOwner(file.queryProp(getDFUQResultFieldName(DFUQRFowner)));
- StringBuffer buf(file.queryProp(getDFUQResultFieldName(DFUQRFtimemodified)));
- lFile->setModified(buf.replace('T', ' ').str());
- lFile->setPrefix(getPrefixFromLogicalName(logicalName, buf.clear()));
- lFile->setDescription(file.queryProp(getDFUQResultFieldName(DFUQRFdescription)));
- if (!nodeGroup || !*nodeGroup)
- nodeGroup = file.queryProp(getDFUQResultFieldName(DFUQRFnodegroup));
- if (nodeGroup && *nodeGroup)
- {
- if (version < 1.26)
- lFile->setClusterName(nodeGroup);
- else
- lFile->setNodeGroup(nodeGroup);
- }
- int numSubFiles = file.hasProp(getDFUQResultFieldName(DFUQRFnumsubfiles));
- if(numSubFiles)
- lFile->setIsSuperfile(true);
- else
- {
- lFile->setIsSuperfile(false);
- lFile->setDirectory(file.queryProp(getDFUQResultFieldName(DFUQRFdirectory)));
- lFile->setParts(file.queryProp(getDFUQResultFieldName(DFUQRFnumparts)));
- }
- lFile->setBrowseData(numSubFiles > 1 ? false : true); ////Bug 41379 - ViewKeyFile Cannot handle superfile with multiple subfiles
- if (version >= 1.30)
- {
- bool persistent = file.getPropBool(getDFUQResultFieldName(DFUQRFpersistent), false);
- if (persistent)
- lFile->setPersistent(true);
- if (file.hasProp(getDFUQResultFieldName(DFUQRFsuperowners)))
- lFile->setSuperOwners(file.queryProp(getDFUQResultFieldName(DFUQRFsuperowners)));
- if (file.hasProp(getDFUQResultFieldName(DFUQRFprotect)))
- lFile->setIsProtected(true);
- }
- __int64 size = file.getPropInt64(getDFUQResultFieldName(DFUQRForigsize),0);
- if (size > 0)
- {
- lFile->setIntSize(size);
- lFile->setTotalsize((buf.clear()<<comma(size)).str());
- }
- __int64 records = file.getPropInt64(getDFUQResultFieldName(DFUQRFrecordcount),0);
- if (!records)
- records = file.getPropInt64(getDFUQResultFieldName(DFUQRForigrecordcount),0);
- if (!records)
- {
- __int64 recordSize=file.getPropInt64(getDFUQResultFieldName(DFUQRFrecordsize),0);
- if(recordSize > 0)
- records = size/recordSize;
- }
- if (records > 0)
- {
- lFile->setIntRecordCount(records);
- lFile->setRecordCount((buf.clear()<<comma(records)).str());
- }
- bool isKeyFile = false;
- if (version > 1.13)
- {
- const char * kind = file.queryProp(getDFUQResultFieldName(DFUQRFkind));
- if (kind && *kind)
- {
- if (strieq(kind, "key"))
- isKeyFile = true;
- if (version >= 1.24)
- lFile->setContentType(kind);
- else
- lFile->setIsKeyFile(isKeyFile);
- }
- }
- bool isFileCompressed = file.getPropBool(getDFUQResultFieldName(DFUQRFiscompressed));
- if (isFileCompressed)
- {
- if (version >= 1.22)
- {
- if (file.hasProp(getDFUQResultFieldName(DFUQRFcompressedsize)))
- lFile->setCompressedFileSize(file.getPropInt64(getDFUQResultFieldName(DFUQRFcompressedsize)));
- else if (isKeyFile)
- lFile->setCompressedFileSize(size);
- }
- }
- if (version < 1.22)
- lFile->setIsZipfile(isFileCompressed);
- else
- lFile->setIsCompressed(isFileCompressed);
- logicalFiles.append(*lFile.getClear());
- }
- catch(IException* e)
- {
- VStringBuffer msg("Failed to retrieve data for logical file %s: ", logicalName);
- int code = e->errorCode();
- e->errorMessage(msg);
- e->Release();
- throw MakeStringException(code, "%s", msg.str());
- }
- return true;
- }
- void CWsDfuEx::setDFUQueryResponse(IEspContext &context, unsigned totalFiles, StringBuffer& sortBy, bool descending, unsigned pageStart, unsigned pageSize,
- IEspDFUQueryRequest& req, IEspDFUQueryResponse& resp)
- {
- //for legacy
- double version = context.getClientVersion();
- unsigned pageEnd = pageStart + pageSize;
- if (pageEnd > totalFiles)
- pageEnd = totalFiles;
- resp.setNumFiles(totalFiles);
- resp.setPageSize(pageSize);
- resp.setPageStartFrom(pageStart+1);
- resp.setPageEndAt(pageEnd);
- if (pageStart > pageSize)
- resp.setPrevPageFrom(pageStart - pageSize + 1);
- else if(pageStart > 0)
- resp.setPrevPageFrom(1);
- if(pageEnd < totalFiles)
- {
- resp.setNextPageFrom(pageEnd+1);
- resp.setLastPageFrom((int)(pageSize * floor((double) ((totalFiles-1) / pageSize)) + 1));
- }
- StringBuffer queryReq;
- if (req.getNodeGroup() && *req.getNodeGroup())
- {
- if (version < 1.26)
- resp.setClusterName(req.getNodeGroup());
- else
- resp.setNodeGroup(req.getNodeGroup());
- addToQueryString(queryReq, "NodeGroup", req.getNodeGroup());
- }
- if (req.getOwner() && *req.getOwner())
- {
- resp.setOwner(req.getOwner());
- addToQueryString(queryReq, "Owner", req.getOwner());
- }
- if (req.getPrefix() && *req.getPrefix())
- {
- resp.setPrefix(req.getPrefix());
- addToQueryString(queryReq, "Prefix", req.getPrefix());
- }
- if (req.getLogicalName() && *req.getLogicalName())
- {
- resp.setLogicalName(req.getLogicalName());
- addToQueryString(queryReq, "LogicalName", req.getLogicalName());
- }
- if (req.getStartDate() && *req.getStartDate())
- {
- resp.setStartDate(req.getStartDate());
- addToQueryString(queryReq, "StartDate", req.getStartDate());
- }
- if (req.getEndDate() && *req.getEndDate())
- {
- resp.setEndDate(req.getEndDate());
- addToQueryString(queryReq, "EndDate", req.getEndDate());
- }
- if (req.getFileType() && *req.getFileType())
- {
- resp.setFileType(req.getFileType());
- addToQueryString(queryReq, "FileType", req.getFileType());
- }
- if (req.getFileSizeFrom())
- {
- resp.setFileSizeFrom(req.getFileSizeFrom());
- addToQueryStringFromInt(queryReq, "FileSizeFrom", req.getFileSizeFrom());
- }
- if (req.getFileSizeTo())
- {
- resp.setFileSizeTo(req.getFileSizeTo());
- addToQueryStringFromInt(queryReq, "FileSizeTo", req.getFileSizeTo());
- }
- StringBuffer queryReqNoPageSize = queryReq;
- addToQueryStringFromInt(queryReq, "PageSize", pageSize);
- resp.setFilters(queryReq.str());
- if (sortBy.length())
- {
- resp.setSortby(sortBy.str());
- resp.setDescending(descending);
- addToQueryString(queryReq, "Sortby", sortBy.str());
- addToQueryString(queryReqNoPageSize, "Sortby", sortBy.str());
- if (descending)
- {
- addToQueryString(queryReq, "Descending", "1");
- addToQueryString(queryReqNoPageSize, "Descending", "1");
- }
- }
- resp.setBasicQuery(queryReqNoPageSize.str());
- resp.setParametersForPaging(queryReq.str());
- return;
- }
- bool CWsDfuEx::doLogicalFileSearch(IEspContext &context, IUserDescriptor* udesc, IEspDFUQueryRequest & req, IEspDFUQueryResponse & resp)
- {
- double version = context.getClientVersion();
- if (req.getOneLevelDirFileReturn())
- {
- int numDirs = 0;
- int numFiles = 0;
- IArrayOf<IEspDFULogicalFile> logicalFiles;
- getLogicalFileAndDirectory(context, udesc, req.getLogicalName(), !req.getIncludeSuperOwner_isNull() && req.getIncludeSuperOwner(), logicalFiles, numFiles, numDirs);
- return true;
- }
- if (queryDaliServerVersion().compare("3.11") < 0)
- {//Dali server does not support Filtered File Query. Use legacy code.
- PROGLOG("DFUQuery: getAPageOfSortedLogicalFile");
- getAPageOfSortedLogicalFile(context, udesc, req, resp);
- return true;
- }
- StringBuffer filterBuf;
- setDFUQueryFilters(req, filterBuf);
- //Now, set filters which are used to filter query result received from dali server.
- unsigned short localFilterCount = 0;
- DFUQResultField localFilters[8];
- MemoryBuffer localFilterBuf;
- addDFUQueryFilter(localFilters, localFilterCount, localFilterBuf, req.getNodeGroup(), DFUQRFnodegroup);
- localFilters[localFilterCount] = DFUQRFterm;
- StringBuffer sortBy;
- bool descending = false;
- DFUQResultField sortOrder[2] = {DFUQRFname, DFUQRFterm};
- setDFUQuerySortOrder(req, sortBy, descending, sortOrder);
- unsigned pageStart = 0;
- if (req.getPageStartFrom() > 0)
- pageStart = req.getPageStartFrom() - 1;
- unsigned pageSize = req.getPageSize();
- if (pageSize < 1)
- pageSize = 100;
- const int firstN = req.getFirstN();
- if (firstN > 0)
- {
- pageStart = 0;
- pageSize = firstN;
- }
- unsigned maxFiles = 0;
- if(!req.getMaxNumberOfFiles_isNull())
- maxFiles = req.getMaxNumberOfFiles();
- if (maxFiles == 0)
- maxFiles = ITERATE_FILTEREDFILES_LIMIT;
- if (maxFiles != ITERATE_FILTEREDFILES_LIMIT)
- setFileIterateFilter(maxFiles, filterBuf);
- __int64 cacheHint = 0;
- if (!req.getCacheHint_isNull())
- cacheHint = req.getCacheHint();
- bool allMatchingFilesReceived = true;
- unsigned totalFiles = 0;
- PROGLOG("DFUQuery: getLogicalFilesSorted");
- Owned<IDFAttributesIterator> it = queryDistributedFileDirectory().getLogicalFilesSorted(udesc, sortOrder, filterBuf.str(),
- localFilters, localFilterBuf.bufferBase(), pageStart, pageSize, &cacheHint, &totalFiles, &allMatchingFilesReceived);
- if(!it)
- throw MakeStringException(ECLWATCH_CANNOT_GET_FILE_ITERATOR,"Cannot get information from file system.");
- PROGLOG("DFUQuery: getLogicalFilesSorted done");
- IArrayOf<IEspDFULogicalFile> logicalFiles;
- ForEach(*it)
- addToLogicalFileList(it->query(), NULL, version, logicalFiles);
- if (!allMatchingFilesReceived)
- {
- VStringBuffer warning("The returned results (%d files) represent a subset of the total number of matches. Using a correct filter may reduce the number of matches.",
- maxFiles);
- resp.setWarning(warning.str());
- resp.setIsSubsetOfFiles(!allMatchingFilesReceived);
- }
- resp.setCacheHint(cacheHint);
- resp.setDFULogicalFiles(logicalFiles);
- setDFUQueryResponse(context, totalFiles, sortBy, descending, pageStart, pageSize, req, resp); //This call may be removed after 5.0
- return true;
- }
- bool CWsDfuEx::onSuperfileList(IEspContext &context, IEspSuperfileListRequest &req, IEspSuperfileListResponse &resp)
- {
- try
- {
- const char* superfile = req.getSuperfile();
- if (!superfile || !*superfile)
- throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Superfile name required");
- PROGLOG("SuperfileList: %s", superfile);
- StringBuffer username;
- context.getUserID(username);
- Owned<IUserDescriptor> userdesc;
- if(username.length() > 0)
- {
- userdesc.setown(createUserDescriptor());
- userdesc->set(username.str(), context.queryPassword(), context.querySignature());
- }
- Owned<IDFUhelper> dfuhelper = createIDFUhelper();
- StringArray farray;
- StringAttrArray subfiles;
- dfuhelper->listSubFiles(req.getSuperfile(), subfiles, userdesc.get());
- for(unsigned i = 0; i < subfiles.length(); i++)
- {
- StringAttrItem& subfile = subfiles.item(i);
- farray.append(subfile.text);
- }
- if(farray.length() > 0)
- resp.setSubfiles(farray);
- resp.setSuperfile(req.getSuperfile());
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- bool CWsDfuEx::onSuperfileAction(IEspContext &context, IEspSuperfileActionRequest &req, IEspSuperfileActionResponse &resp)
- {
- try
- {
- if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Write, false))
- throw MakeStringException(ECLWATCH_DFU_ACCESS_DENIED, "Failed to Superfile action. Permission denied.");
- const char* action = req.getAction();
- const char* superfile = req.getSuperfile();
- superfileAction(context, action, superfile, req.getSubfiles(), req.getBefore(), true, true, req.getDelete(), req.getRemoveSuperfile());
- resp.setRetcode(0);
- if (superfile && *superfile && action && strieq(action, "remove"))
- {
- Owned<IUserDescriptor> udesc;
- udesc.setown(createUserDescriptor());
- udesc->set(context.queryUserId(), context.queryPassword(), context.querySignature());
- Owned<IDistributedSuperFile> fp = queryDistributedFileDirectory().lookupSuperFile(superfile,udesc);
- if (!fp)
- resp.setRetcode(-1); //Superfile has been removed.
- }
- resp.setSuperfile(req.getSuperfile());
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- bool CWsDfuEx::onSavexml(IEspContext &context, IEspSavexmlRequest &req, IEspSavexmlResponse &resp)
- {
- try
- {
- StringBuffer username;
- context.getUserID(username);
- Owned<IUserDescriptor> userdesc;
- if(username.length() > 0)
- {
- userdesc.setown(createUserDescriptor());
- userdesc->set(username.str(), context.queryPassword(), context.querySignature());
- }
- if (!req.getName() || !*req.getName())
- throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Name required");
- PROGLOG("getFileXML: %s", req.getName());
- Owned<IDFUhelper> dfuhelper = createIDFUhelper();
- StringBuffer out;
- dfuhelper->getFileXML(req.getName(), out, userdesc.get());
- MemoryBuffer xmlmap;
- int len = out.length();
- xmlmap.setBuffer(len, out.detach(), true);
- resp.setXmlmap(xmlmap);
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- bool CWsDfuEx::onAdd(IEspContext &context, IEspAddRequest &req, IEspAddResponse &resp)
- {
- try
- {
- StringBuffer username;
- context.getUserID(username);
- Owned<IUserDescriptor> userdesc;
- if(username.length() > 0)
- {
- userdesc.setown(createUserDescriptor());
- userdesc->set(username.str(), context.queryPassword(), context.querySignature());
- }
- if (!req.getDstname() || !*req.getDstname())
- throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Dstname required.");
- PROGLOG("addFileXML: %s", req.getDstname());
- Owned<IDFUhelper> dfuhelper = createIDFUhelper();
- StringBuffer xmlstr(req.getXmlmap().length(),(const char*)req.getXmlmap().bufferBase());
- dfuhelper->addFileXML(req.getDstname(), xmlstr, userdesc.get());
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- bool CWsDfuEx::onAddRemote(IEspContext &context, IEspAddRemoteRequest &req, IEspAddRemoteResponse &resp)
- {
- try
- {
- StringBuffer username;
- context.getUserID(username);
- Owned<IUserDescriptor> userdesc;
- if(username.length() > 0)
- {
- userdesc.setown(createUserDescriptor());
- userdesc->set(username.str(), context.queryPassword(), context.querySignature());
- }
- const char* srcusername = req.getSrcusername();
- Owned<IUserDescriptor> srcuserdesc;
- if(srcusername && *srcusername)
- {
- srcuserdesc.setown(createUserDescriptor());
- srcuserdesc->set(srcusername, req.getSrcpassword(), context.querySignature());
- }
- const char* srcname = req.getSrcname();
- if(srcname == NULL || *srcname == '\0')
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "srcname can't be empty.");
- const char* srcdali = req.getSrcdali();
- if(srcdali == NULL || *srcdali == '\0')
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "srcdali can't be empty.");
- const char* dstname = req.getDstname();
- if(dstname == NULL || *dstname == '\0')
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "dstname can't be empty.");
- PROGLOG("addFileRemote: Srcdali %s, Srcname %s, Dstname %s", srcdali, srcname, dstname);
- SocketEndpoint ep(srcdali);
- Owned<IDFUhelper> dfuhelper = createIDFUhelper();
- dfuhelper->addFileRemote(dstname, ep, srcname, srcuserdesc.get(), userdesc.get());
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- const int INTEGELSIZE = 20;
- const int REALSIZE = 32;
- const int STRINGSIZE = 128;
- bool CWsDfuEx::onDFUGetDataColumns(IEspContext &context, IEspDFUGetDataColumnsRequest &req, IEspDFUGetDataColumnsResponse &resp)
- {
- try
- {
- if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Read, false))
- throw MakeStringException(ECLWATCH_DFU_ACCESS_DENIED, "Failed to View Data File. Permission denied.");
- StringBuffer logicalNameStr;
- char* logicalName0 = (char*) req.getOpenLogicalName();
- if (logicalName0 && *logicalName0)
- {
- logicalNameStr.append(logicalName0);
- logicalNameStr.trim();
- }
- if (logicalNameStr.length() > 0)
- {
- PROGLOG("DFUGetDataColumns: %s", logicalNameStr.str());
- __int64 startIndex = req.getStartIndex();
- __int64 endIndex = req.getEndIndex();
- if (startIndex < 1)
- startIndex = 1;
- if (endIndex < 1)
- endIndex = 100;
- StringArray filterByNames, filterByValues;
- double version = context.getClientVersion();
- if (version > 1.04)
- {
- const char* filterBy = req.getFilterBy();
- if (filterBy && *filterBy)
- {
- parseTwoStringArrays(filterBy, filterByNames, filterByValues);
- }
- const char* showColumns = req.getShowColumns();
- if (showColumns && *showColumns)
- {
- resp.setShowColumns(showColumns);
- }
- }
- StringBuffer username;
- context.getUserID(username);
- Owned<IUserDescriptor> userdesc;
- userdesc.setown(createUserDescriptor());
- userdesc->set(username.str(), context.queryPassword(), context.querySignature());
- {
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(logicalNameStr.str(), userdesc);
- if(!df)
- throw MakeStringException(ECLWATCH_FILE_NOT_EXIST,"Could not find file %s.", logicalNameStr.str());
- IDistributedSuperFile *sf = df->querySuperFile();
- if (sf && (sf->numSubFiles() > 1))
- throw MakeStringException(ECLWATCH_INVALID_ACTION,"This feature is not designed to work with a superfile which contains multiple subfiles.");
- }
- Owned<IResultSetFactory> resultSetFactory = getSecResultSetFactory(context.querySecManager(), context.queryUser(), context.queryUserId(), context.queryPassword());
- Owned<INewResultSet> result;
- if (m_clusterName.length() > 0)
- {
- result.setown(resultSetFactory->createNewFileResultSet(logicalNameStr.str(), m_clusterName.str()));
- }
- else
- {
- result.setown(resultSetFactory->createNewFileResultSet(logicalNameStr.str(), NULL));
- }
- __int64 total=result->getNumRows();
- {
- IArrayOf<IEspDFUDataColumn> dataKeyedColumns[MAX_KEY_ROWS];
- IArrayOf<IEspDFUDataColumn> dataNonKeyedColumns[MAX_KEY_ROWS];
- const IResultSetMetaData & meta = result->getMetaData();
- int columnCount = meta.getColumnCount();
- int keyedColumnCount = meta.getNumKeyedColumns();
- unsigned columnSize = 0;
- int lineSizeCount = 0;
- int lineCount = 0;
- for (int i = 0; i < keyedColumnCount; i++)
- {
- Owned<IEspDFUDataColumn> item = createDFUDataColumn("","");
- bool bNaturalColumn = true;
- SCMStringBuffer columnLabel;
- if (meta.hasSetTranslation(i))
- {
- meta.getNaturalColumnLabel(columnLabel, i);
- }
- if (columnLabel.length() < 1)
- {
- meta.getColumnLabel(columnLabel, i);
- bNaturalColumn = false;
- }
- item->setColumnLabel(columnLabel.str());
- if (version > 1.04 && filterByNames.length() > 0)
- {
- for (unsigned ii = 0; ii < filterByNames.length(); ii++)
- {
- const char* name = filterByNames.item(ii);
- if (name && !stricmp(name, columnLabel.str()))
- {
- const char* value = filterByValues.item(ii);
- if (value && *value)
- {
- item->setColumnValue(value);
- break;
- }
- }
- }
- }
- DisplayType columnType = meta.getColumnDisplayType(i);
- if (bNaturalColumn)
- {
- item->setColumnType("Others");
- item->setColumnSize(STRINGSIZE);
- columnSize = STRINGSIZE;
- item->setMaxSize(columnSize);
- }
- else if (columnType == TypeBoolean)
- {
- item->setColumnType("Boolean");
- item->setMaxSize(1);
- item->setColumnSize(strlen(columnLabel.str()));
- columnSize = 2;
- }
- else
- {
- if (columnType == TypeInteger || columnType == TypeUnsignedInteger)
- {
- item->setColumnType("Integer");
- item->setMaxSize(INTEGELSIZE);
- columnSize = INTEGELSIZE;
- if (strlen(columnLabel.str()) > columnSize)
- columnSize = strlen(columnLabel.str());
- item->setColumnSize(columnSize);
- }
- else if (columnType == TypeReal)
- {
- item->setColumnType("Real");
- item->setMaxSize(REALSIZE);
- columnSize = REALSIZE;
- if (strlen(columnLabel.str()) > columnSize)
- columnSize = strlen(columnLabel.str());
- item->setColumnSize(columnSize);
- }
- else if (columnType == TypeString)
- {
- columnSize = meta.getColumnRawSize(i);
- columnSize = rtlQStrLength(columnSize);
- if (columnSize < 1)
- columnSize = STRINGSIZE;
- else if (columnSize > STRINGSIZE)
- columnSize = STRINGSIZE;
- item->setColumnType("String");
- item->setMaxSize(columnSize);
- if (strlen(columnLabel.str()) > columnSize)
- columnSize = strlen(columnLabel.str());
- item->setColumnSize(columnSize);
- }
- else if (columnType == TypeUnicode)
- {
- item->setColumnType("Others");
- columnSize = (int) (meta.getColumnRawSize(i) * 0.5);
- if (columnSize > STRINGSIZE)
- columnSize = STRINGSIZE;
- item->setColumnSize(columnSize);
- item->setMaxSize(columnSize);
- }
- else
- {
- item->setColumnType("Others");
- columnSize = STRINGSIZE;
- item->setColumnSize(columnSize);
- item->setMaxSize(columnSize);
- }
- }
- columnSize += 7;
- if ((lineSizeCount == 0) && (columnSize > STRINGSIZE)) //One field is big enough to use one line
- {
- if (lineCount >= MAX_KEY_ROWS)
- break;
- dataKeyedColumns[lineCount].append(*item.getLink());
- lineCount++;
- }
- else
- {
- if (lineSizeCount + columnSize < STRINGSIZE)
- {
- lineSizeCount += columnSize;
- }
- else //too big in this line...so, switch to another line
- {
- lineCount++;
- lineSizeCount = columnSize;
- }
- if (lineCount >= MAX_KEY_ROWS)
- break;
- dataKeyedColumns[lineCount].append(*item.getLink());
- }
- }
- columnSize = 0;
- lineSizeCount = 0;
- lineCount = 0;
- for (int ii = keyedColumnCount; ii < columnCount; ii++)
- {
- Owned<IEspDFUDataColumn> item = createDFUDataColumn("","");
- bool bNaturalColumn = true;
- SCMStringBuffer columnLabel;
- if (meta.hasSetTranslation(ii))
- {
- meta.getNaturalColumnLabel(columnLabel, ii);
- }
- if (columnLabel.length() < 1)
- {
- meta.getColumnLabel(columnLabel, ii);
- bNaturalColumn = false;
- }
- item->setColumnLabel(columnLabel.str());
- if (version > 1.04 && filterByNames.length() > 0)
- {
- for (unsigned ii = 0; ii < filterByNames.length(); ii++)
- {
- const char* name = filterByNames.item(ii);
- if (name && !stricmp(name, columnLabel.str()))
- {
- const char* value = filterByValues.item(ii);
- if (value && *value)
- {
- item->setColumnValue(value);
- break;
- }
- }
- }
- }
- DisplayType columnType = meta.getColumnDisplayType(ii);
- if (bNaturalColumn)
- {
- item->setColumnType("Others");
- item->setColumnSize(STRINGSIZE);
- columnSize = STRINGSIZE;
- }
- else if (columnType == TypeBoolean)
- {
- item->setColumnType("Boolean");
- item->setMaxSize(1);
- item->setColumnSize(strlen(columnLabel.str()));
- columnSize = 2;
- }
- else
- {
- if (columnType == TypeInteger || columnType == TypeUnsignedInteger)
- {
- item->setColumnType("Integer");
- item->setMaxSize(INTEGELSIZE);
- columnSize = INTEGELSIZE;
- if (strlen(columnLabel.str()) > columnSize)
- columnSize = strlen(columnLabel.str());
- item->setColumnSize(columnSize);
- }
- else if (columnType == TypeReal)
- {
- item->setColumnType("Real");
- item->setMaxSize(REALSIZE);
- columnSize = REALSIZE;
- if (strlen(columnLabel.str()) > columnSize)
- columnSize = strlen(columnLabel.str());
- item->setColumnSize(columnSize);
- }
- else if (columnType == TypeString)
- {
- columnSize = meta.getColumnRawSize(ii);
- columnSize = rtlQStrLength(columnSize);
- if (columnSize < 1)
- columnSize = STRINGSIZE;
- else if (columnSize > STRINGSIZE)
- columnSize = STRINGSIZE;
- item->setColumnType("String");
- item->setMaxSize(columnSize);
- if (strlen(columnLabel.str()) > columnSize)
- columnSize = strlen(columnLabel.str());
- item->setColumnSize(columnSize);
- }
- else if (columnType == TypeUnicode)
- {
- item->setColumnType("Others");
- columnSize = (int) (meta.getColumnRawSize(ii) * 0.5);
- if (columnSize > STRINGSIZE)
- columnSize = STRINGSIZE;
- item->setColumnSize(columnSize);
- item->setMaxSize(columnSize);
- }
- else
- {
- item->setColumnType("Others");
- columnSize = STRINGSIZE;
- item->setColumnSize(columnSize);
- item->setMaxSize(columnSize);
- }
- }
- columnSize += 7;
- if ((lineSizeCount == 0) && (columnSize > STRINGSIZE))
- {
- if (lineCount >= MAX_KEY_ROWS)
- break;
- dataNonKeyedColumns[lineCount].append(*item.getLink());
- lineCount++;
- }
- else
- {
- if (lineSizeCount + columnSize < STRINGSIZE)
- {
- lineSizeCount += columnSize;
- }
- else
- {
- lineCount++;
- lineSizeCount = columnSize;
- }
- if (lineCount >= MAX_KEY_ROWS)
- break;
- dataNonKeyedColumns[lineCount].append(*item.getLink());
- }
- }
- if (dataKeyedColumns[0].length() > 0)
- resp.setDFUDataKeyedColumns1(dataKeyedColumns[0]);
- if (dataKeyedColumns[1].length() > 0)
- resp.setDFUDataKeyedColumns2(dataKeyedColumns[1]);
- if (dataKeyedColumns[2].length() > 0)
- resp.setDFUDataKeyedColumns3(dataKeyedColumns[2]);
- if (dataKeyedColumns[3].length() > 0)
- resp.setDFUDataKeyedColumns4(dataKeyedColumns[3]);
- if (dataKeyedColumns[4].length() > 0)
- resp.setDFUDataKeyedColumns5(dataKeyedColumns[4]);
- if (dataKeyedColumns[5].length() > 0)
- resp.setDFUDataKeyedColumns6(dataKeyedColumns[5]);
- if (dataKeyedColumns[6].length() > 0)
- resp.setDFUDataKeyedColumns7(dataKeyedColumns[6]);
- if (dataKeyedColumns[7].length() > 0)
- resp.setDFUDataKeyedColumns8(dataKeyedColumns[7]);
- if (dataKeyedColumns[8].length() > 0)
- resp.setDFUDataKeyedColumns9(dataKeyedColumns[8]);
- if (dataKeyedColumns[9].length() > 0)
- resp.setDFUDataKeyedColumns10(dataKeyedColumns[9]);
- if (version > 1.14)
- {
- if (dataKeyedColumns[10].length() > 0)
- resp.setDFUDataKeyedColumns11(dataKeyedColumns[10]);
- if (dataKeyedColumns[11].length() > 0)
- resp.setDFUDataKeyedColumns12(dataKeyedColumns[11]);
- if (dataKeyedColumns[12].length() > 0)
- resp.setDFUDataKeyedColumns13(dataKeyedColumns[12]);
- if (dataKeyedColumns[13].length() > 0)
- resp.setDFUDataKeyedColumns14(dataKeyedColumns[13]);
- if (dataKeyedColumns[14].length() > 0)
- resp.setDFUDataKeyedColumns15(dataKeyedColumns[14]);
- if (dataKeyedColumns[15].length() > 0)
- resp.setDFUDataKeyedColumns16(dataKeyedColumns[15]);
- if (dataKeyedColumns[16].length() > 0)
- resp.setDFUDataKeyedColumns17(dataKeyedColumns[16]);
- if (dataKeyedColumns[17].length() > 0)
- resp.setDFUDataKeyedColumns18(dataKeyedColumns[17]);
- if (dataKeyedColumns[18].length() > 0)
- resp.setDFUDataKeyedColumns19(dataKeyedColumns[18]);
- if (dataKeyedColumns[19].length() > 0)
- resp.setDFUDataKeyedColumns20(dataKeyedColumns[19]);
- }
- if (dataNonKeyedColumns[0].length() > 0)
- resp.setDFUDataNonKeyedColumns1(dataNonKeyedColumns[0]);
- if (dataNonKeyedColumns[1].length() > 0)
- resp.setDFUDataNonKeyedColumns2(dataNonKeyedColumns[1]);
- if (dataNonKeyedColumns[2].length() > 0)
- resp.setDFUDataNonKeyedColumns3(dataNonKeyedColumns[2]);
- if (dataNonKeyedColumns[3].length() > 0)
- resp.setDFUDataNonKeyedColumns4(dataNonKeyedColumns[3]);
- if (dataNonKeyedColumns[4].length() > 0)
- resp.setDFUDataNonKeyedColumns5(dataNonKeyedColumns[4]);
- if (dataNonKeyedColumns[5].length() > 0)
- resp.setDFUDataNonKeyedColumns6(dataNonKeyedColumns[5]);
- if (dataNonKeyedColumns[6].length() > 0)
- resp.setDFUDataNonKeyedColumns7(dataNonKeyedColumns[6]);
- if (dataNonKeyedColumns[7].length() > 0)
- resp.setDFUDataNonKeyedColumns8(dataNonKeyedColumns[7]);
- if (dataNonKeyedColumns[8].length() > 0)
- resp.setDFUDataNonKeyedColumns9(dataNonKeyedColumns[8]);
- if (dataNonKeyedColumns[9].length() > 0)
- resp.setDFUDataNonKeyedColumns10(dataNonKeyedColumns[9]);
- if (version > 1.14)
- {
- if (dataNonKeyedColumns[10].length() > 0)
- resp.setDFUDataNonKeyedColumns11(dataNonKeyedColumns[10]);
- if (dataNonKeyedColumns[11].length() > 0)
- resp.setDFUDataNonKeyedColumns12(dataNonKeyedColumns[11]);
- if (dataNonKeyedColumns[12].length() > 0)
- resp.setDFUDataNonKeyedColumns13(dataNonKeyedColumns[12]);
- if (dataNonKeyedColumns[13].length() > 0)
- resp.setDFUDataNonKeyedColumns14(dataNonKeyedColumns[13]);
- if (dataNonKeyedColumns[14].length() > 0)
- resp.setDFUDataNonKeyedColumns15(dataNonKeyedColumns[14]);
- if (dataNonKeyedColumns[15].length() > 0)
- resp.setDFUDataNonKeyedColumns16(dataNonKeyedColumns[15]);
- if (dataNonKeyedColumns[16].length() > 0)
- resp.setDFUDataNonKeyedColumns17(dataNonKeyedColumns[16]);
- if (dataNonKeyedColumns[17].length() > 0)
- resp.setDFUDataNonKeyedColumns18(dataNonKeyedColumns[17]);
- if (dataNonKeyedColumns[18].length() > 0)
- resp.setDFUDataNonKeyedColumns19(dataNonKeyedColumns[18]);
- if (dataNonKeyedColumns[19].length() > 0)
- resp.setDFUDataNonKeyedColumns20(dataNonKeyedColumns[19]);
- }
- //resp.setColumnCount(columnCount);
- resp.setRowCount(total);
- }
- resp.setLogicalName(logicalNameStr.str());
- resp.setStartIndex(startIndex);
- resp.setEndIndex(endIndex);
- if (version > 1.11)
- {
- if (req.getCluster() && *req.getCluster())
- {
- resp.setCluster(req.getCluster());
- }
- if (req.getClusterType() && *req.getClusterType())
- {
- resp.setClusterType(req.getClusterType());
- }
- }
- }
- if (req.getChooseFile())
- resp.setChooseFile(1);
- else
- resp.setChooseFile(0);
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- bool CWsDfuEx::onDFUSearchData(IEspContext &context, IEspDFUSearchDataRequest &req, IEspDFUSearchDataResponse &resp)
- {
- try
- {
- if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Read, false))
- throw MakeStringException(ECLWATCH_DFU_ACCESS_DENIED, "Failed to View Data File. Permission denied.");
- double version = context.getClientVersion();
- resp.setCluster(req.getCluster());
- resp.setClusterType(req.getClusterType());
- resp.setFile(req.getFile());
- resp.setKey(req.getKey());
- const char* selectedKey = req.getSelectedKey();
- if (strlen(selectedKey) > 0)
- {
- resp.setSelectedKey(req.getSelectedKey());
- }
- else
- {
- resp.setSelectedKey(req.getKey());
- }
- resp.setParentName(req.getParentName());
- resp.setRoxieSelections(req.getRoxieSelections());
- resp.setDisableUppercaseTranslation(req.getDisableUppercaseTranslation());
- const char* openLogicalName = req.getOpenLogicalName();
- if (strlen(openLogicalName) > 0)
- {
- PROGLOG("DFUSearchData: %s", openLogicalName);
- Owned<IEspDFUGetDataColumnsRequest> DataColumnsRequest = createDFUGetDataColumnsRequest();
- Owned<IEspDFUGetDataColumnsResponse> DataColumnsResponse = createDFUGetDataColumnsResponse();
- DataColumnsRequest->setOpenLogicalName(req.getOpenLogicalName());
- DataColumnsRequest->setFilterBy(req.getFilterBy());
- DataColumnsRequest->setShowColumns(req.getShowColumns());
- DataColumnsRequest->setChooseFile(req.getChooseFile());
- DataColumnsRequest->setCluster(req.getCluster());
- DataColumnsRequest->setClusterType(req.getClusterType());
- try
- {
- onDFUGetDataColumns(context, *DataColumnsRequest, *DataColumnsResponse);
- }
- catch(IException* e)
- {
- if (version < 1.08)
- throw e;
- StringBuffer emsg;
- e->errorMessage(emsg);
- e->Release();
- resp.setMsgToDisplay(emsg);
- return true;
- }
- resp.setOpenLogicalName(req.getOpenLogicalName());
- resp.setLogicalName(DataColumnsResponse->getLogicalName());
- resp.setStartIndex(DataColumnsResponse->getStartIndex());
- resp.setEndIndex(DataColumnsResponse->getEndIndex());
- resp.setDFUDataKeyedColumns1(DataColumnsResponse->getDFUDataKeyedColumns1());
- resp.setDFUDataKeyedColumns2(DataColumnsResponse->getDFUDataKeyedColumns2());
- resp.setDFUDataKeyedColumns3(DataColumnsResponse->getDFUDataKeyedColumns3());
- resp.setDFUDataKeyedColumns4(DataColumnsResponse->getDFUDataKeyedColumns4());
- resp.setDFUDataKeyedColumns5(DataColumnsResponse->getDFUDataKeyedColumns5());
- resp.setDFUDataKeyedColumns6(DataColumnsResponse->getDFUDataKeyedColumns6());
- resp.setDFUDataKeyedColumns7(DataColumnsResponse->getDFUDataKeyedColumns7());
- resp.setDFUDataKeyedColumns8(DataColumnsResponse->getDFUDataKeyedColumns8());
- resp.setDFUDataKeyedColumns9(DataColumnsResponse->getDFUDataKeyedColumns9());
- resp.setDFUDataKeyedColumns10(DataColumnsResponse->getDFUDataKeyedColumns10());
- if (version > 1.14)
- {
- resp.setDFUDataKeyedColumns11(DataColumnsResponse->getDFUDataKeyedColumns11());
- resp.setDFUDataKeyedColumns12(DataColumnsResponse->getDFUDataKeyedColumns12());
- resp.setDFUDataKeyedColumns13(DataColumnsResponse->getDFUDataKeyedColumns13());
- resp.setDFUDataKeyedColumns14(DataColumnsResponse->getDFUDataKeyedColumns14());
- resp.setDFUDataKeyedColumns15(DataColumnsResponse->getDFUDataKeyedColumns15());
- resp.setDFUDataKeyedColumns16(DataColumnsResponse->getDFUDataKeyedColumns16());
- resp.setDFUDataKeyedColumns17(DataColumnsResponse->getDFUDataKeyedColumns17());
- resp.setDFUDataKeyedColumns18(DataColumnsResponse->getDFUDataKeyedColumns18());
- resp.setDFUDataKeyedColumns19(DataColumnsResponse->getDFUDataKeyedColumns19());
- resp.setDFUDataKeyedColumns20(DataColumnsResponse->getDFUDataKeyedColumns20());
- }
- resp.setDFUDataNonKeyedColumns1(DataColumnsResponse->getDFUDataNonKeyedColumns1());
- resp.setDFUDataNonKeyedColumns2(DataColumnsResponse->getDFUDataNonKeyedColumns2());
- resp.setDFUDataNonKeyedColumns3(DataColumnsResponse->getDFUDataNonKeyedColumns3());
- resp.setDFUDataNonKeyedColumns4(DataColumnsResponse->getDFUDataNonKeyedColumns4());
- resp.setDFUDataNonKeyedColumns5(DataColumnsResponse->getDFUDataNonKeyedColumns5());
- resp.setDFUDataNonKeyedColumns6(DataColumnsResponse->getDFUDataNonKeyedColumns6());
- resp.setDFUDataNonKeyedColumns7(DataColumnsResponse->getDFUDataNonKeyedColumns7());
- resp.setDFUDataNonKeyedColumns8(DataColumnsResponse->getDFUDataNonKeyedColumns8());
- resp.setDFUDataNonKeyedColumns9(DataColumnsResponse->getDFUDataNonKeyedColumns9());
- resp.setDFUDataNonKeyedColumns10(DataColumnsResponse->getDFUDataNonKeyedColumns10());
- if (version > 1.14)
- {
- resp.setDFUDataNonKeyedColumns11(DataColumnsResponse->getDFUDataNonKeyedColumns11());
- resp.setDFUDataNonKeyedColumns12(DataColumnsResponse->getDFUDataNonKeyedColumns12());
- resp.setDFUDataNonKeyedColumns13(DataColumnsResponse->getDFUDataNonKeyedColumns13());
- resp.setDFUDataNonKeyedColumns14(DataColumnsResponse->getDFUDataNonKeyedColumns14());
- resp.setDFUDataNonKeyedColumns15(DataColumnsResponse->getDFUDataNonKeyedColumns15());
- resp.setDFUDataNonKeyedColumns16(DataColumnsResponse->getDFUDataNonKeyedColumns16());
- resp.setDFUDataNonKeyedColumns17(DataColumnsResponse->getDFUDataNonKeyedColumns17());
- resp.setDFUDataNonKeyedColumns18(DataColumnsResponse->getDFUDataNonKeyedColumns18());
- resp.setDFUDataNonKeyedColumns19(DataColumnsResponse->getDFUDataNonKeyedColumns19());
- resp.setDFUDataNonKeyedColumns20(DataColumnsResponse->getDFUDataNonKeyedColumns20());
- }
- resp.setRowCount(DataColumnsResponse->getRowCount());
- resp.setShowColumns(DataColumnsResponse->getShowColumns());
- resp.setChooseFile(DataColumnsResponse->getChooseFile());
- }
- const char* logicalName = req.getLogicalName();
- if (strlen(logicalName) == 0 && strlen(openLogicalName) > 0)
- {
- logicalName = openLogicalName;
- }
- if (strlen(logicalName) > 0)
- {
- Owned<IEspDFUBrowseDataRequest> browseDataRequest = createDFUBrowseDataRequest();
- Owned<IEspDFUBrowseDataResponse> browseDataResponse = createDFUBrowseDataResponse();
- browseDataRequest->setLogicalName(logicalName);
- const char* parentName = req.getParentName();
- if (parentName && *parentName)
- browseDataRequest->setParentName(parentName);
- browseDataRequest->setFilterBy(req.getFilterBy());
- browseDataRequest->setShowColumns(req.getShowColumns());
- browseDataRequest->setStartForGoback(req.getStartForGoback());
- browseDataRequest->setCountForGoback(req.getCountForGoback());
- browseDataRequest->setChooseFile(req.getChooseFile());
- browseDataRequest->setStart(req.getStart());
- browseDataRequest->setCount(req.getCount());
- browseDataRequest->setSchemaOnly(req.getSchemaOnly());
- browseDataRequest->setCluster(req.getCluster());
- browseDataRequest->setClusterType(req.getClusterType());
- browseDataRequest->setDisableUppercaseTranslation(req.getDisableUppercaseTranslation());
- onDFUBrowseData(context, *browseDataRequest, *browseDataResponse);
- resp.setName(browseDataResponse->getName());
- resp.setLogicalName(browseDataResponse->getLogicalName());
- resp.setFilterBy(browseDataResponse->getFilterBy());
- resp.setFilterForGoBack(browseDataResponse->getFilterForGoBack());
- resp.setColumnsHidden(browseDataResponse->getColumnsHidden());
- resp.setColumnsHidden(browseDataResponse->getColumnsHidden());
- resp.setColumnCount(browseDataResponse->getColumnCount());
- resp.setStartForGoback(browseDataResponse->getStartForGoback());
- resp.setCountForGoback(browseDataResponse->getCountForGoback());
- resp.setChooseFile(browseDataResponse->getChooseFile());
- resp.setStart(browseDataResponse->getStart());
- resp.setCount(browseDataResponse->getCount());
- resp.setPageSize(browseDataResponse->getPageSize());
- resp.setTotal(browseDataResponse->getTotal());
- resp.setResult(browseDataResponse->getResult());
- resp.setMsgToDisplay(browseDataResponse->getMsgToDisplay());
- resp.setSchemaOnly(browseDataResponse->getSchemaOnly());
- resp.setAutoUppercaseTranslation(!m_disableUppercaseTranslation);
- }
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- static const char * const columnTypes[] = { "Boolean", "Integer", "Unsigned Integer", "Real", "String",
- "Data", "Unicode", "Unknown", "BeginIfBlock", "EndIfBlock", "BeginRecord", "EndRecord", "Set", "Dataset", NULL };
- bool CWsDfuEx::onDFUGetFileMetaData(IEspContext &context, IEspDFUGetFileMetaDataRequest & req, IEspDFUGetFileMetaDataResponse & resp)
- {
- class CDFUFileMetaDataReader
- {
- unsigned totalColumnCount;
- unsigned keyedColumnCount;
- StringBuffer XmlSchema, XmlXPathSchema;
- IArrayOf<IEspDFUDataColumn> dataColumns;
- const IResultSetMetaData& metaRoot;
- bool readRootLevelColumns;
- IEspContext &context;
- bool readColumnLabel(const IResultSetMetaData* meta, unsigned columnID, IEspDFUDataColumn* out)
- {
- SCMStringBuffer columnLabel;
- bool isNaturalColumn = true;
- if (meta->hasSetTranslation(columnID))
- meta->getNaturalColumnLabel(columnLabel, columnID);
- if (columnLabel.length() < 1)
- {
- meta->getColumnLabel(columnLabel, columnID);
- isNaturalColumn = false;
- }
- out->setColumnLabel(columnLabel.str());
- out->setIsNaturalColumn(isNaturalColumn);
- return isNaturalColumn;
- }
- void readColumn(const IResultSetMetaData* meta, unsigned& columnID, const bool isKeyed,
- IArrayOf<IEspDFUDataColumn>& dataColumns)
- {
- double version = context.getClientVersion();
- Owned<IEspDFUDataColumn> dataItem = createDFUDataColumn();
- dataItem->setColumnID(columnID+1);
- dataItem->setIsKeyedColumn(isKeyed);
- SCMStringBuffer s;
- dataItem->setColumnEclType(meta->getColumnEclType(s, columnID).str());
- DisplayType columnType = meta->getColumnDisplayType(columnID);
- if ((columnType == TypeUnicode) || columnType == TypeString)
- dataItem->setColumnRawSize(meta->getColumnRawSize(columnID));
- if (readColumnLabel(meta, columnID, dataItem))
- dataItem->setColumnType("Others");
- else if (columnType == TypeBeginRecord)
- dataItem->setColumnType("Record");
- else
- dataItem->setColumnType(columnTypes[columnType]);
- if ((version >= 1.31) && ((columnType == TypeSet) || (columnType == TypeDataset) || (columnType == TypeBeginRecord)))
- checkAndReadNestedColumn(meta, columnID, columnType, dataItem);
- dataColumns.append(*dataItem.getClear());
- }
- void readColumns(const IResultSetMetaData* meta, IArrayOf<IEspDFUDataColumn>& dataColumnArray)
- {
- if (!meta)
- return;
- if (readRootLevelColumns)
- {
- readRootLevelColumns = false;
- totalColumnCount = (unsigned)meta->getColumnCount();
- keyedColumnCount = meta->getNumKeyedColumns();
- unsigned i = 0;
- for (; i < keyedColumnCount; i++)
- readColumn(meta, i, true, dataColumnArray);
- for (i = keyedColumnCount; i < totalColumnCount; i++)
- readColumn(meta, i, false, dataColumnArray);
- }
- else
- {
- unsigned columnCount = (unsigned)meta->getColumnCount();
- for (unsigned i = 0; i < columnCount; i++)
- readColumn(meta, i, false, dataColumnArray);
- }
- }
- void checkAndReadNestedColumn(const IResultSetMetaData* meta, unsigned& columnID,
- DisplayType columnType, IEspDFUDataColumn* dataItem)
- {
- IArrayOf<IEspDFUDataColumn> curDataColumnArray;
- if (columnType == TypeBeginRecord)
- {
- columnID++;
- do
- {
- readColumn(meta, columnID, false, curDataColumnArray);
- } while (meta->getColumnDisplayType(++columnID) != TypeEndRecord);
- }
- else
- readColumns(meta->getChildMeta(columnID), curDataColumnArray);
- dataItem->setDataColumns(curDataColumnArray);
- }
- public:
- CDFUFileMetaDataReader(IEspContext& _context, const IResultSetMetaData& _meta)
- : context(_context), metaRoot(_meta), readRootLevelColumns(true)
- {
- readColumns(&metaRoot, dataColumns);
- };
- inline unsigned getTotalColumnCount() { return totalColumnCount; }
- inline unsigned getKeyedColumnCount() { return keyedColumnCount; }
- inline IArrayOf<IEspDFUDataColumn>& getDataColumns() { return dataColumns; }
- inline StringBuffer& getXmlSchema(StringBuffer& s, const bool addHeader)
- {
- StringBufferAdaptor schema(s);
- metaRoot.getXmlSchema(schema, addHeader);
- return s;
- }
- inline StringBuffer& getXmlXPathSchema(StringBuffer& s, const bool addHeader)
- {
- StringBufferAdaptor XPathSchema(s);
- metaRoot.getXmlXPathSchema(XPathSchema, addHeader);
- return s;
- }
- };
- try
- {
- StringBuffer fileNameStr = req.getLogicalFileName();
- const char* fileName = fileNameStr.trim().str();
- if (!fileName || !*fileName)
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "CWsDfuEx::onDFUGetFileMetaData: LogicalFileName not set");
- {//Check whether the meta data is available for the file. If not, throw an exception.
- StringBuffer nameStr;
- Owned<IUserDescriptor> userdesc = createUserDescriptor();
- userdesc->set(context.getUserID(nameStr).str(), context.queryPassword(), context.querySignature());
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(fileName, userdesc);
- if(!df)
- throw MakeStringException(ECLWATCH_FILE_NOT_EXIST,"CWsDfuEx::onDFUGetFileMetaData: Could not find file %s.", fileName);
- IDistributedSuperFile *sf = df->querySuperFile();
- if (sf && (sf->numSubFiles() > 1))
- throw MakeStringException(ECLWATCH_INVALID_ACTION, "CWsDfuEx::onDFUGetFileMetaData: This feature is not designed to work with a superfile which contains multiple subfiles.");
- }
- const char* cluster = NULL;
- StringBuffer clusterNameStr = req.getClusterName();
- if (clusterNameStr.trim().length() > 0)
- cluster = clusterNameStr.str();
- PROGLOG("DFUGetFileMetaData: %s", fileName);
- Owned<IResultSetFactory> resultSetFactory = getSecResultSetFactory(context.querySecManager(), context.queryUser(), context.queryUserId(), context.queryPassword());
- Owned<INewResultSet> result = resultSetFactory->createNewFileResultSet(fileName, cluster);
- if (!result)
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "CWsDfuEx::onDFUGetFileMetaData: Failed to access FileResultSet for %s.", fileName);
- CDFUFileMetaDataReader dataReader(context, result->getMetaData());
- resp.setTotalColumnCount(dataReader.getTotalColumnCount());
- resp.setKeyedColumnCount(dataReader.getKeyedColumnCount());
- resp.setDataColumns(dataReader.getDataColumns());
- StringBuffer s, s1;
- if (req.getIncludeXmlSchema())
- resp.setXmlSchema(dataReader.getXmlSchema(s, req.getAddHeaderInXmlSchema()).str());
- if (req.getIncludeXmlXPathSchema())
- resp.setXmlXPathSchema(dataReader.getXmlXPathSchema(s1, req.getAddHeaderInXmlXPathSchema()).str());
- resp.setTotalResultRows(result->getNumRows());
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- bool CWsDfuEx::onDFUBrowseData(IEspContext &context, IEspDFUBrowseDataRequest &req, IEspDFUBrowseDataResponse &resp)
- {
- try
- {
- if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Read, false))
- throw MakeStringException(ECLWATCH_DFU_ACCESS_DENIED, "Failed to View Data File. Permission denied.");
- const char* logicalName0 = req.getLogicalName();
- const char* parentName = req.getParentName();
- if (!logicalName0 || !*logicalName0)
- throw MakeStringException(ECLWATCH_INVALID_INPUT,"No LogicalName defined.");
- StringBuffer logicalNameStr;
- if (logicalName0 && *logicalName0)
- {
- logicalNameStr.append(logicalName0);
- logicalNameStr.trim();
- if (logicalNameStr.length() < 1)
- throw MakeStringException(ECLWATCH_INVALID_INPUT,"No LogicalName defined.");
- }
- PROGLOG("DFUBrowseData: %s", logicalNameStr.str());
- __int64 start = req.getStart() > 0 ? req.getStart() : 0;
- __int64 count=req.getCount() ? req.getCount() : 20, requested=count;
- if (count > MAX_VIEWKEYFILE_ROWS)
- throw MakeStringException(ECLWATCH_TOO_MANY_DATA_ROWS,"Browser Cannot display more than %d data rows.", MAX_VIEWKEYFILE_ROWS);
- bool bSchemaOnly=req.getSchemaOnly() ? req.getSchemaOnly() : false;
- bool bDisableUppercaseTranslation = req.getDisableUppercaseTranslation() ? req.getDisableUppercaseTranslation() : false;
- const char* filterBy = req.getFilterBy();
- const char* showColumns = req.getShowColumns();
- __int64 read=0;
- __int64 total = 0;
- StringBuffer msg;
- StringArray columnLabels, columnLabelsType;
- IArrayOf<IEspDFUData> DataList;
- int iRet = GetIndexData(context, bSchemaOnly, logicalNameStr.str(), parentName, filterBy, start, count, read, total, msg, columnLabels, columnLabelsType, DataList, bDisableUppercaseTranslation);
- if (iRet > 0)
- resp.setMsgToDisplay("This search has timed out due to the restrictive filter. There may be more records.");
- //GetIndexData(context, bSchemaOnly, logicalNameStr.str(), "roxie::thor_data400::key::bankruptcyv2::20090721::search::tmsid", filterBy, start, count, read, total, msg, columnLabels, columnLabelsType, DataList);
- resp.setResult(DataList.item(0).getData());
- unsigned int max_name_length = 3; //max length for name length
- unsigned int max_value_length = 4; //max length for value length:
- StringBuffer filterByStr, filterByStr0;
- filterByStr0.appendf("%d%d", max_name_length, max_value_length);
- unsigned columnCount = columnLabels.length();
- IArrayOf<IEspDFUDataColumn> dataColumns;
- double version = context.getClientVersion();
- if (version > 1.04 && columnCount > 0)
- {
- //Find out which columns need to be displayed
- int lenShowCols = 0, showCols[1024];
- const char* showColumns = req.getShowColumns();
- char *pShowColumns = (char*) showColumns;
- while (pShowColumns && *pShowColumns)
- {
- StringBuffer buf;
- while (pShowColumns && isdigit(pShowColumns[0]))
- {
- buf.append(pShowColumns[0]);
- pShowColumns++;
- }
- if (buf.length() > 0)
- {
- showCols[lenShowCols] = atoi(buf.str());
- lenShowCols++;
- }
- if (!pShowColumns || !*pShowColumns)
- break;
- pShowColumns++;
- }
- for(unsigned col = 0; col < columnCount; col++)
- {
- const char* label = columnLabels.item(col);
- const char* type = columnLabelsType.item(col);
- if (!label || !*label || !type || !*type)
- continue;
- Owned<IEspDFUDataColumn> item = createDFUDataColumn("","");
- item->setColumnLabel(label);
- item->setColumnType(type);
- item->setColumnSize(0); //not show this column
- if (!showColumns || !*showColumns)
- {
- item->setColumnSize(1); //Show this column
- }
- else
- {
- for(int col1 = 0; col1 < lenShowCols; col1++)
- {
- if (col == showCols[col1])
- {
- item->setColumnSize(1); //Show this column
- break;
- }
- }
- }
- dataColumns.append(*item.getLink());
- }
- //Re-build filters
- if (filterBy && *filterBy)
- {
- StringArray filterByNames, filterByValues;
- parseTwoStringArrays(filterBy, filterByNames, filterByValues);
- if (filterByNames.length() > 0)
- {
- for (unsigned ii = 0; ii < filterByNames.length(); ii++)
- {
- const char* columnName = filterByNames.item(ii);
- const char* columnValue = filterByValues.item(ii);
- if (columnName && *columnName && columnValue && *columnValue)
- {
- filterByStr.appendf("%s[%s]", columnName, columnValue);
- filterByStr0.appendf("%03d%04d%s%s", (int) strlen(columnName), (int) strlen(columnValue), columnName, columnValue);
- }
- }
- }
- }
- if (req.getStartForGoback())
- resp.setStartForGoback(req.getStartForGoback());
- if (req.getCountForGoback())
- resp.setCountForGoback(req.getCountForGoback());
- }
- //resp.setFilterBy(filterByStr.str());
- if (filterByStr.length() > 0)
- {
- const char* oldStr = "&";
- const char* newStr = "&";
- filterByStr.replaceString(oldStr, newStr);
- resp.setFilterBy(filterByStr.str());
- }
- if (version > 1.04)
- {
- //resp.setFilterForGoBack(filterByStr0.str());
- if (filterByStr0.length() > 0)
- {
- const char* oldStr = "&";
- const char* newStr = "&";
- filterByStr0.replaceString(oldStr, newStr);
- resp.setFilterForGoBack(filterByStr0.str());
- }
- resp.setColumnCount(columnCount);
- if (dataColumns.length() > 0)
- resp.setColumnsHidden(dataColumns);
- }
- if (version > 1.10)
- {
- resp.setSchemaOnly(bSchemaOnly);
- }
- //resp.setName(name.str());
- resp.setLogicalName(logicalNameStr.str());
- resp.setStart(start);
- //if (requested > read)
- // requested = read;
- resp.setPageSize(requested);
- if (count > read)
- {
- count = read;
- }
- resp.setCount(count);
- if (total != UNKNOWN_NUM_ROWS)
- resp.setTotal(total);
- else
- resp.setTotal(-1);
- if (req.getChooseFile())
- resp.setChooseFile(1);
- else
- resp.setChooseFile(0);
- if (version > 1.11)
- {
- if (req.getCluster() && *req.getCluster())
- {
- resp.setCluster(req.getCluster());
- }
- if (req.getClusterType() && *req.getClusterType())
- {
- resp.setClusterType(req.getClusterType());
- }
- }
- if ((version > 1.12) && parentName && *parentName)
- {
- resp.setParentName(parentName);
- }
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- void storeHistoryTreeToArray(IPropertyTree *history, IArrayOf<IEspHistory>& arrHistory)
- {
- Owned<IPropertyTreeIterator> historyIter = history->getElements("*");
- ForEach(*historyIter)
- {
- Owned<IEspHistory> historyRecord = createHistory();
- IPropertyTree & item = historyIter->query();
- historyRecord->setIP(item.queryProp("@ip"));
- historyRecord->setName(item.queryProp("@name"));
- historyRecord->setOperation(item.queryProp("@operation"));
- historyRecord->setOwner(item.queryProp("@owner"));
- historyRecord->setPath(item.queryProp("@path"));
- historyRecord->setTimestamp(item.queryProp("@timestamp"));
- historyRecord->setWorkunit(item.queryProp("@workunit"));
- arrHistory.append(*historyRecord.getClear());
- }
- }
- bool CWsDfuEx::onListHistory(IEspContext &context, IEspListHistoryRequest &req, IEspListHistoryResponse &resp)
- {
- try
- {
- StringBuffer username;
- context.getUserID(username);
- Owned<IUserDescriptor> userdesc;
- if (username.length() > 0)
- {
- userdesc.setown(createUserDescriptor());
- userdesc->set(username.str(), context.queryPassword(), context.querySignature());
- }
- if (!req.getName() || !*req.getName())
- throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Name required");
- PROGLOG("onListHistory: %s", req.getName());
- MemoryBuffer xmlmap;
- IArrayOf<IEspHistory> arrHistory;
- Owned<IDistributedFile> file = queryDistributedFileDirectory().lookup(req.getName(),userdesc.get());
- if (file)
- {
- IPropertyTree *history = file->queryHistory();
- if (history)
- {
- storeHistoryTreeToArray(history, arrHistory);
- if (context.getClientVersion() < 1.36)
- history->serialize(xmlmap);
- }
- if (arrHistory.ordinality())
- resp.setHistory(arrHistory);
- }
- else
- throw MakeStringException(ECLWATCH_FILE_NOT_EXIST,"CWsDfuEx::onListHistory: Could not find file '%s'.", req.getName());
- if (xmlmap.length())
- resp.setXmlmap(xmlmap);
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- bool CWsDfuEx::onEraseHistory(IEspContext &context, IEspEraseHistoryRequest &req, IEspEraseHistoryResponse &resp)
- {
- try
- {
- if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Full, false))
- throw MakeStringException(ECLWATCH_DFU_ACCESS_DENIED, "Failed to Erase History. Permission denied (requires Full).");
- StringBuffer username;
- context.getUserID(username);
- Owned<IUserDescriptor> userdesc;
- if (username.length() > 0)
- {
- userdesc.setown(createUserDescriptor());
- userdesc->set(username.str(), context.queryPassword(), context.querySignature());
- }
- if (!req.getName() || !*req.getName())
- throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Name required");
- PROGLOG("onEraseHistory: %s", req.getName());
- MemoryBuffer xmlmap;
- IArrayOf<IEspHistory> arrHistory;
- Owned<IDistributedFile> file = queryDistributedFileDirectory().lookup(req.getName(),userdesc.get());
- if (file)
- {
- IPropertyTree *history = file->queryHistory();
- if (history)
- {
- storeHistoryTreeToArray(history, arrHistory);
- if (context.getClientVersion() < 1.36)
- history->serialize(xmlmap);
- file->resetHistory();
- }
- if (arrHistory.ordinality())
- resp.setHistory(arrHistory);
- }
- else
- throw MakeStringException(ECLWATCH_FILE_NOT_EXIST,"CWsDfuEx::onEraseHistory: Could not find file '%s'.", req.getName());
- if (xmlmap.length())
- resp.setXmlmap(xmlmap);
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- //////////////////////HPCC Browser//////////////////////////
- static const char* SCHEMANAME = "myschema";
- //void CWsDfuEx::setRootFilter(INewResultSet* result, const char* filterBy, IFilteredResultSet* filter)
- void CWsDfuEx::setRootFilter(INewResultSet* result, const char* filterBy, IResultSetFilter* filter, bool disableUppercaseTranslation)
- {
- if (!filterBy || !*filterBy || !result)
- return;
- //Owned<IFilteredResultSet> filter = result->createFiltered();
- filter->clearFilters();
- const IResultSetMetaData &meta = result->getMetaData();
- unsigned columnCount = meta.getColumnCount();
- if (columnCount < 1)
- return;
- StringArray filterByNames, filterByValues;
- parseTwoStringArrays(filterBy, filterByNames, filterByValues);
- if (filterByNames.length() < 1)
- return;
- for (unsigned ii = 0; ii < filterByNames.length(); ii++)
- {
- const char* columnName = filterByNames.item(ii);
- const char* columnValue0 = filterByValues.item(ii);
- if (!columnName || !*columnName || !columnValue0 || !*columnValue0)
- continue;
- StringBuffer buf(columnValue0);
- if (!disableUppercaseTranslation)
- buf.toUpperCase();
- const char* columnValue = buf.str();
- for(unsigned col = 0; col < columnCount; col++)
- {
- bool hasSetTranslation = false;
- SCMStringBuffer scmbuf;
- if (meta.hasSetTranslation(col))
- {
- hasSetTranslation = true;
- meta.getNaturalColumnLabel(scmbuf, col);
- }
- if (scmbuf.length() < 1)
- {
- meta.getColumnLabel(scmbuf, col);
- }
- if (!stricmp(scmbuf.str(), columnName))
- {
- //filter->addFilter(col, columnValue);
- //filterByStr.appendf("%s[%s]", columnName, columnValue);
- //filterByStr0.appendf("%03d%04d%s%s", strlen(columnName), strlen(columnValue), columnName, columnValue);
- if (hasSetTranslation)
- filter->addNaturalFilter(col, strlen(columnValue), columnValue);
- else
- filter->addFilter(col, strlen(columnValue), columnValue);
- break;
- }
- }
- }
- //result.setown(filter->create());
- return;
- }
- void CWsDfuEx::getMappingColumns(IRelatedBrowseFile * file, bool isPrimary, UnsignedArray& cols)
- {
- const char* logicalName = file->queryDefinition()->queryDistributedFile()->queryLogicalName();
- const char* primaryName = file->queryParentRelation()->queryFileRelationship()->queryPrimaryFilename();
- if (!logicalName || !primaryName || strcmp(logicalName, primaryName))
- return;
- IViewRelation* parentRelation = file->queryParentRelation();
- for (unsigned i=0; i < parentRelation->numMappingFields(); i++)
- {
- //find out the column numbers to remove
- unsigned col = parentRelation->queryMappingField(i, isPrimary);
- cols.append(col);
- }
- #ifdef TESTDATASET
- cols.kill();
- cols.append(2);
- cols.append(3);
- #endif
- return;
- }
- void CWsDfuEx::readColumnsForDisplay(StringBuffer& schemaText, StringArray& columnsDisplay, StringArray& columnsDisplayType)
- {
- if (schemaText.length() < 1)
- return;
- Owned<IPropertyTree> schema = createPTreeFromXMLString(schemaText.str());
- if (!schema)
- return;
- //Find out labels from the second schema used for column mapping
- columnsDisplay.kill();
- Owned<IPropertyTreeIterator> rows4 = schema->getElements("xs:element[@name=\"Dataset\"]/xs:complexType/xs:sequence/xs:element[@name=\"Row\"]/xs:complexType/xs:sequence/*");
- ForEach(*rows4)
- {
- IPropertyTree &e = rows4->query();
- const char* name = e.queryProp("@name");
- const char* type = e.queryProp("@type");
- bool hasChildren = e.hasChildren();
- if (!name || !*name)
- continue;
- columnsDisplay.append(name); //Display this column
- if (type && *type)
- columnsDisplayType.append(type);
- else if (hasChildren)
- columnsDisplayType.append("Object");
- else
- columnsDisplayType.append("Unknown");
- }
- return;
- }
- void CWsDfuEx::mergeSchema(IRelatedBrowseFile * file, StringBuffer& schemaText, StringBuffer schemaText2,
- StringArray& columnsDisplay, StringArray& columnsDisplayType, StringArray& columnsHide)
- {
- if (schemaText.length() < 1)
- return;
- if (schemaText2.length() < 1)
- return;
- Owned<IPropertyTree> schema = createPTreeFromXMLString(schemaText.str());
- Owned<IPropertyTree> schema2 = createPTreeFromXMLString(schemaText2.str());
- if (!schema || !schema2)
- return;
- //Process simpleType part
- Owned<IPropertyTreeIterator> rows1 = schema->getElements("xs:simpleType");
- Owned<IPropertyTreeIterator> rows2 = schema2->getElements("xs:simpleType");
- if (!rows1 || !rows2)
- return;
- ForEach(*rows2)
- {
- IPropertyTree &e = rows2->query();
- const char* name = e.queryProp("@name");
- if (!name || !*name)
- continue;
- bool bFound = false;
- ForEach(*rows1)
- {
- IPropertyTree &e1 = rows1->query();
- const char* name1 = e1.queryProp("@name");
- if (!name1 || !*name1 || stricmp(name1, name))
- continue;
- bFound = true;
- break;
- }
- if (!bFound)
- schema->addPropTree(e.queryName(), LINK(&e));
- }
- IPropertyTree* rows = schema->queryBranch("xs:element[@name=\"Dataset\"]/xs:complexType/xs:sequence/xs:element[@name=\"Row\"]/xs:complexType/xs:sequence");
- if (!rows)
- return;
- //Find out labels used for column mapping
- columnsDisplay.kill();
- columnsDisplayType.kill();
- columnsHide.kill();
- Owned<IPropertyTreeIterator> rows4 = schema->getElements("xs:element[@name=\"Dataset\"]/xs:complexType/xs:sequence/xs:element[@name=\"Row\"]/xs:complexType/xs:sequence/*");
- ForEach(*rows4)
- {
- IPropertyTree &e = rows4->query();
- const char* name = e.queryProp("@name");
- const char* type = e.queryProp("@type");
- bool hasChildren = e.hasChildren();
- if (!name || !*name)
- continue;
- columnsDisplay.append(name); //Display this column
- if (type && *type)
- columnsDisplayType.append(type);
- else if (hasChildren)
- columnsDisplayType.append("Object");
- else
- columnsDisplayType.append("Unknown");
- }
- UnsignedArray cols;
- bool isPrimary = true;
- getMappingColumns(file, isPrimary, cols);
- //Process complexType part for labels
- unsigned col0 = 0;
- Owned<IPropertyTreeIterator> rows3 = schema2->getElements("xs:element[@name=\"Dataset\"]/xs:complexType/xs:sequence/xs:element[@name=\"Row\"]/xs:complexType/xs:sequence/*");
- ForEach(*rows3)
- {
- IPropertyTree &e = rows3->query();
- const char* name = e.queryProp("@name");
- const char* type = e.queryProp("@type");
- bool hasChildren = e.hasChildren();
- if (!name || !*name)
- continue;
- bool bAdd = true;
- bool bRename = false;
- if (cols.ordinality() != 0)
- {
- ForEachItemIn(i1,cols)
- {
- unsigned col = cols.item(i1);
- if (col == col0)
- {
- bAdd = false;
- break;
- }
- }
- }
- #define RENAMESAMECOLUMN
- #ifdef RENAMESAMECOLUMN
- if (columnsDisplay.length() > 0)
- {
- for (unsigned i = 0; i < columnsDisplay.length(); i++)
- {
- const char* label = columnsDisplay.item(i);
- if (!label || strcmp(label, name))
- continue;
- bRename = true;
- break;
- }
- }
- #endif
- if (!bAdd)
- {
- columnsHide.append(name); //hide this column
- }
- else
- {
- if (type && *type)
- columnsDisplayType.append(type);
- else if (hasChildren)
- columnsDisplayType.append("Object");
- else
- columnsDisplayType.append("Unknown");
- #ifdef RENAMESAMECOLUMN
- if (bRename)
- {
- StringBuffer newName(name);
- newName.append("-2");
- columnsDisplay.append(newName.str()); //Display this column
- e.setProp("@name", newName.str());
- rows->addPropTree(e.queryName(), LINK(&e));
- }
- else
- {
- #endif
- columnsDisplay.append(name); //Display this column
- rows->addPropTree(e.queryName(), LINK(&e));
- #ifdef RENAMESAMECOLUMN
- }
- #endif
- }
- col0++;
- }
- //Convert schema tree to schame now
- schemaText.clear();
- toXML(schema, schemaText);
- return;
- }
- void CWsDfuEx::mergeDataRow(StringBuffer& newRow, int depth, IPropertyTreeIterator* it, StringArray& columnsHide, StringArray& columnsUsed)
- {
- if (!it)
- return;
- it->first();
- while(it->isValid())
- {
- IPropertyTree* e = &it->query();
- if (e)
- {
- const char* label = e->queryName();
- if (label && *label)
- {
- #ifdef RENAMESAMECOLUMN
- if (depth < 1)
- columnsUsed.append(label);
- #endif
- bool bHide = false;
- if (columnsHide.length() > 0)
- {
- for (unsigned i = 0 ; i < columnsHide.length(); i++)
- {
- const char* key = columnsHide.item(i);
- if (!key || strcmp(key, label))
- continue;
- bHide = true;
- break;
- }
- }
- #ifdef RENAMESAMECOLUMN
- if (!bHide && depth > 0 && columnsUsed.length() > 0)
- {
- for (unsigned i = 0 ; i < columnsUsed.length(); i++)
- {
- const char* key = columnsUsed.item(i);
- if (!key || strcmp(key, label))
- continue;
- StringBuffer newName(label);
- newName.append("-2");
- e->renameProp("/", newName.str());
- break;
- }
- }
- #endif
- if (!bHide)
- {
- StringBuffer dataRow;
- toXML(e, dataRow);
- newRow.append(dataRow);
- }
- }
- }
- it->next();
- }
- return;
- }
- void CWsDfuEx::mergeDataRow(StringBuffer& newRow, StringBuffer dataRow1, StringBuffer dataRow2, StringArray& columnsHide)
- {
- if (dataRow1.length() < 1)
- return;
- if (dataRow2.length() < 1)
- return;
- Owned<IPropertyTree> data1 = createPTreeFromXMLString(dataRow1.str());
- Owned<IPropertyTree> data2 = createPTreeFromXMLString(dataRow2.str());
- if (!data1 || !data2)
- return;
- newRow.clear();
- newRow.append("<Row>");
- StringArray columnLabels;
- Owned<IPropertyTreeIterator> it = data1->getElements("*");
- if (it)
- {
- StringArray columnLabels0;
- mergeDataRow(newRow, 0, it, columnLabels0, columnLabels);
- }
- Owned<IPropertyTreeIterator> it2 = data2->getElements("*");
- if (it2)
- {
- mergeDataRow(newRow, 1, it2, columnsHide, columnLabels);
- }
- newRow.append("</Row>");
- return;
- }
- void CWsDfuEx::browseRelatedFileSchema(IRelatedBrowseFile * file, const char* parentName, unsigned depth, StringBuffer& schemaText,
- StringArray& columnsDisplay, StringArray& columnsDisplayType, StringArray& columnsHide)
- {
- //if (file in set of files to display or iterate)
- IResultSetCursor * cursor = file->queryCursor();
- if (cursor && cursor->first())
- {
- if (depth < 1)
- {
- const IResultSetMetaData & meta = cursor->queryResultSet()->getMetaData();
- StringBufferAdaptor adaptor(schemaText);
- meta.getXmlSchema(adaptor, false);
- #ifdef TESTDATASET
- schemaText.clear();
- schemaText.append("<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\"");
- schemaText.append(" attributeFormDefault=\"unqualified\">");
- schemaText.append("<xs:element name=\"Dataset\"><xs:complexType><xs:sequence minOccurs=\"0\" maxOccurs=\"unbounded\">");
- schemaText.append("<xs:element name=\"Row\"><xs:complexType><xs:sequence>");
- schemaText.append("<xs:element name=\"state\" type=\"string2\"/>");
- schemaText.append("<xs:element name=\"rtype\" type=\"string2\"/>");
- schemaText.append("<xs:element name=\"id\" type=\"string20\"/>");
- schemaText.append("<xs:element name=\"seq\" type=\"xs:nonNegativeInteger\"/>");
- schemaText.append("<xs:element name=\"num\" type=\"xs:nonNegativeInteger\"/>");
- schemaText.append("<xs:element name=\"date\" type=\"string8\"/>");
- schemaText.append("<xs:element name=\"imglength\" type=\"xs:nonNegativeInteger\"/>");
- schemaText.append("<xs:element name=\"__filepos\" type=\"xs:nonNegativeInteger\"/>");
- schemaText.append("</xs:sequence></xs:complexType></xs:element>");
- schemaText.append("</xs:sequence></xs:complexType></xs:element>");
- schemaText.append("<xs:simpleType name=\"string2\"><xs:restriction base=\"xs:string\"><xs:maxLength value=\"2\"/>");
- schemaText.append("</xs:restriction></xs:simpleType>");
- schemaText.append("<xs:simpleType name=\"string20\"><xs:restriction base=\"xs:string\"><xs:maxLength value=\"20\"/>");
- schemaText.append("</xs:restriction></xs:simpleType>");
- schemaText.append("<xs:simpleType name=\"string8\"><xs:restriction base=\"xs:string\"><xs:maxLength value=\"8\"/>");
- schemaText.append("</xs:restriction></xs:simpleType>");
- schemaText.append("</xs:schema>");
- #endif
- readColumnsForDisplay(schemaText, columnsDisplay, columnsDisplayType);
- }
- else
- {
- StringBuffer schemaText0;
- const IResultSetMetaData & meta = cursor->queryResultSet()->getMetaData();
- StringBufferAdaptor adaptor(schemaText0);
- meta.getXmlSchema(adaptor, false);
- #ifdef TESTDATASET
- schemaText0.clear();
- schemaText0.append("<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\"");
- schemaText0.append(" attributeFormDefault=\"unqualified\">");
- schemaText0.append("<xs:element name=\"Dataset\"><xs:complexType><xs:sequence minOccurs=\"0\" maxOccurs=\"unbounded\">");
- schemaText0.append("<xs:element name=\"Row\"><xs:complexType><xs:sequence>");
- schemaText0.append("<xs:element name=\"date_first_reported\" type=\"string12\"/>");
- schemaText0.append("<xs:element name=\"msa\" type=\"string8\"/>");
- schemaText0.append("<xs:element name=\"sid\" type=\"string20\"/>");
- schemaText0.append("<xs:element name=\"seq\" type=\"xs:nonNegativeInteger\"/>"); //not add
- schemaText0.append("</xs:sequence></xs:complexType></xs:element>");
- schemaText0.append("</xs:sequence></xs:complexType></xs:element>");
- schemaText0.append("<xs:simpleType name=\"string12\"><xs:restriction base=\"xs:string\"><xs:maxLength value=\"12\"/>");
- schemaText0.append("</xs:restriction></xs:simpleType>");
- schemaText0.append("</xs:schema>");
- #endif
- mergeSchema(file, schemaText, schemaText0, columnsDisplay, columnsDisplayType, columnsHide);
- }
- if (parentName && *parentName)
- {
- for (unsigned i = 0;;i++)
- {
- IRelatedBrowseFile * next = file->queryChild(i);
- if (!next)
- break;
- IViewRelatedFile * viewRelatedFile = next->queryDefinition();
- if (!viewRelatedFile)
- continue;
- IDistributedFile * file = viewRelatedFile->queryDistributedFile();
- if (!file)
- continue;
- const char* logicName0 = file->queryLogicalName();
- if (logicName0 && !strcmp(logicName0, parentName))
- browseRelatedFileSchema(next, NULL, depth+1, schemaText, columnsDisplay, columnsDisplayType, columnsHide);
- }
- }
- }
- return;
- }
- int CWsDfuEx::browseRelatedFileDataSet(double version, IRelatedBrowseFile * file, const char* parentName, unsigned depth, __int64 start, __int64& count, __int64& read,
- StringArray& columnsHide, StringArray& dataSetOutput)
- {
- int iRet = 0;
- int rows = 0;
- try
- {
- //if (file in set of files to display or iterate)
- IResultSetCursor * cursor = file->queryCursor();
- if (cursor->first())
- {
- for(bool ok=cursor->absolute(start);ok;ok=cursor->next())
- {
- StringBuffer text;
- StringBufferAdaptor adaptor2(text);
- cursor->getXmlRow(adaptor2);
- StringArray dataSetOutput0;
- if (parentName && *parentName)
- {
- for (unsigned i = 0;;i++)
- {
- IRelatedBrowseFile * next = file->queryChild(i);
- if (!next)
- break;
- IViewRelatedFile * viewRelatedFile = next->queryDefinition();
- if (!viewRelatedFile)
- continue;
- IDistributedFile * file = viewRelatedFile->queryDistributedFile();
- if (!file)
- continue;
- const char* logicName0 = file->queryLogicalName();
- if (logicName0 && !strcmp(logicName0, parentName))
- iRet = browseRelatedFileDataSet(version, next, NULL, depth+1, 0, count, read, columnsHide, dataSetOutput0);
- }
- }
- if (dataSetOutput0.length() < 1)
- {
- dataSetOutput.append(text);
- }
- else
- {
- for (unsigned ii = 0; ii<dataSetOutput0.length(); ii++)
- {
- StringBuffer text0;
- StringBuffer text1 = dataSetOutput0.item(ii);
- if (text1.length() > 0)
- {
- mergeDataRow(text0, text, text1, columnsHide);
- }
- dataSetOutput.append(text0);
- }
- }
- if (depth < 1)
- {
- read++;
- if(read>=count)
- break;
- }
- }
- if (depth < 1)
- {
- if (count > read)
- count = read;
- }
- }
- }
- catch(IException* e)
- {
- if ((version < 1.08) || (e->errorCode() != FVERR_FilterTooRestrictive))
- throw e;
- e->Release();
- iRet = 1;
- }
- return iRet;
- }
- //sample filterBy: 340020001id1
- //sample data: <XmlSchema name="myschema">...</XmlSchema><Dataset xmlSchema="myschema">...</Dataset>
- int CWsDfuEx::GetIndexData(IEspContext &context, bool bSchemaOnly, const char* indexName, const char* parentName, const char* filterBy, __int64 start,
- __int64& count, __int64& read, __int64& total, StringBuffer& message, StringArray& columnLabels,
- StringArray& columnLabelsType, IArrayOf<IEspDFUData>& DataList, bool webDisableUppercaseTranslation)
- {
- if (!indexName || !*indexName)
- return -1;
- double version = context.getClientVersion();
- StringBuffer username;
- context.getUserID(username);
- StringBuffer cluster;
- Owned<IUserDescriptor> userdesc;
- bool disableUppercaseTranslation = false;
- Owned<IDistributedFile> df;
- try
- {
- userdesc.setown(createUserDescriptor());
- userdesc->set(username.str(), context.queryPassword(), context.querySignature());
- df.setown(queryDistributedFileDirectory().lookup(indexName, userdesc));
- if(!df)
- throw MakeStringException(ECLWATCH_FILE_NOT_EXIST,"Could not find file %s.", indexName);
- //Check disableUppercaseTranslation
- StringBuffer mapping;
- df->getColumnMapping(mapping);
- if (mapping.length() > 37 && strstr(mapping.str(), "word{set(stringlib.StringToLowerCase)}"))
- disableUppercaseTranslation = true;
- else if (webDisableUppercaseTranslation)
- disableUppercaseTranslation = webDisableUppercaseTranslation;
- else
- disableUppercaseTranslation = m_disableUppercaseTranslation;
- const char* wuid = df->queryAttributes().queryProp("@workunit");
- if (wuid && *wuid)
- {
- CWUWrapper wu(wuid, context);
- if (wu)
- cluster.append(wu->queryClusterName());
- }
- }
- catch (IException *e)
- {
- DBGLOG(e);
- e->Release();
- }
- catch(...)
- {
- DBGLOG("Unknown Exception - view data file: %s", indexName);
- }
- Owned<IResultSetFactory> resultSetFactory = getSecResultSetFactory(context.querySecManager(), context.queryUser(), context.queryUserId(), context.queryPassword());
- Owned<IViewFileWeb> web;
- Owned<IUserDescriptor> udesc;
- ISecUser * secUser = context.queryUser();
- if(secUser && secUser->getName() && *secUser->getName())
- {
- udesc.setown(createUserDescriptor());
- udesc->set(secUser->getName(), secUser->credentials().getPassword(), context.querySignature());
- }
- if (cluster.length())
- {
- web.setown(createViewFileWeb(*resultSetFactory, cluster, udesc.getLink()));
- }
- else if (m_clusterName.length() > 0)
- {
- web.setown(createViewFileWeb(*resultSetFactory, m_clusterName.str(), udesc.getLink()));
- }
- else
- {
- web.setown(createViewFileWeb(*resultSetFactory, NULL, udesc.getLink()));
- }
- ViewGatherOptions options;
- options.primaryDepth = 100; // we want to traverse secondary->primary, but not the reverse
- options.secondaryDepth = 0;
- options.setPayloadFilter(true); // we're only interested in payload links
- char *indexName0 = (char *) indexName;
- Owned<IFileTreeBrowser> browser;
- try
- {
- web->gatherWeb(indexName0, df, options);
- browser.setown(web->createBrowseTree(indexName0));
- }
- catch(IException* e)
- {
- if ((e->errorCode() != FVERR_CouldNotResolveX) || (indexName[0] != '~'))
- {
- throw e;
- }
- else
- {
- e->Release();
- indexName0 = (char *) (indexName+1);
- web->gatherWeb(indexName0, df, options);
- browser.setown(web->createBrowseTree(indexName0));
- }
- }
- Owned<INewResultSet> result;
- if (cluster && *cluster)
- {
- result.setown(resultSetFactory->createNewFileResultSet(indexName0, cluster));
- }
- else if (m_clusterName.length() > 0)
- {
- result.setown(resultSetFactory->createNewFileResultSet(indexName0, m_clusterName.str()));
- }
- else
- {
- result.setown(resultSetFactory->createNewFileResultSet(indexName0, NULL));
- }
- // Apply the filter to the root node
- if (filterBy && *filterBy)
- {
- //Owned<IFilteredResultSet> filter = result->createFiltered();
- IResultSetFilter* filter = browser->queryRootFilter();
- setRootFilter(result, filterBy, filter, disableUppercaseTranslation);
- ///result.setown(filter->create());
- }
- StringBuffer text, schemaText;
- StringArray columnsHide;
- browseRelatedFileSchema(browser->queryRootFile(), parentName, 0, schemaText, columnLabels, columnLabelsType, columnsHide);
- text.appendf("<XmlSchema name=\"%s\">", SCHEMANAME);
- text.append(schemaText);
- text.append("</XmlSchema>").newline();
- int iRet = 0;
- if (!bSchemaOnly)
- {
- StringArray dataSetOutput;
- iRet = browseRelatedFileDataSet(version, browser->queryRootFile(), parentName, 0, start, count, read, columnsHide, dataSetOutput);
- StringBuffer dataSetText;
- dataSetText.appendf("<Dataset xmlSchema=\"%s\" >", SCHEMANAME);
- dataSetText.newline();
- for (unsigned i = 0; i<dataSetOutput.length(); i++)
- {
- StringBuffer text0 = dataSetOutput.item(i);
- if (text0.length() > 0)
- {
- dataSetText.append(text0);
- dataSetText.newline();
- }
- }
- dataSetText.append("</Dataset>");
- text.append(dataSetText.str());
- }
- MemoryBuffer data;
- struct MemoryBuffer2IStringVal : public CInterface, implements IStringVal
- {
- MemoryBuffer2IStringVal(MemoryBuffer & _buffer) : buffer(_buffer) {}
- IMPLEMENT_IINTERFACE;
- virtual const char * str() const { UNIMPLEMENTED; }
- virtual void set(const char *val) { buffer.append(strlen(val),val); }
- virtual void clear() { } // clearing when appending does nothing
- virtual void setLen(const char *val, unsigned length) { buffer.append(length, val); }
- virtual unsigned length() const { return buffer.length(); };
- MemoryBuffer & buffer;
- } adaptor0(data);
- adaptor0.set(text.str());
- data.append(0);
- total=result->getNumRows();
- Owned<IEspDFUData> item = createDFUData("","");
- item->setName(indexName);
- item->setNumRows(total);
- item->setData(data.toByteArray());
- DataList.append(*item.getClear());
- return iRet;
- }
- //////////////////////HPCC Browser//////////////////////////
|