123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093 |
- /*##############################################################################
- 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)
- #pragma warning (disable : 4297) // function assumed not to throw an exception but does
- #include "platform.h"
- #include "fileservices.hpp"
- #include "workunit.hpp"
- #include "jio.hpp"
- #include "jmisc.hpp"
- #include "daft.hpp"
- #include "dasess.hpp"
- #include "dautils.hpp"
- #include "daaudit.hpp"
- #include "dfuwu.hpp"
- #include "ws_fs_esp.ipp"
- #include "rmtsmtp.hpp"
- #include "dfuplus.hpp"
- #include "daclient.hpp"
- #include "dasds.hpp"
- #include "enginecontext.hpp"
- #include "environment.hpp"
- #define USE_DALIDFS
- #define SDS_LOCK_TIMEOUT 10000
- #define FILESERVICES_VERSION "FILESERVICES 2.1.4"
- static const char * compatibleVersions[] = {
- "FILESERVICES 2.1 [a68789cfb01d00ef6dc362e52d5eac0e]", // linux version
- "FILESERVICES 2.1.1",
- "FILESERVICES 2.1.2",
- "FILESERVICES 2.1.3",
- "FILESERVICES 2.1.4",
- NULL };
- static const char * EclDefinition = nullptr;//Definitions specified in lib_fileservices.ecllib
- #define WAIT_SECONDS 30
- FILESERVICES_API bool getECLPluginDefinition(ECLPluginDefinitionBlock *pb)
- {
- if (pb->size == sizeof(ECLPluginDefinitionBlockEx))
- {
- ECLPluginDefinitionBlockEx * pbx = (ECLPluginDefinitionBlockEx *) pb;
- pbx->compatibleVersions = compatibleVersions;
- }
- else if (pb->size != sizeof(ECLPluginDefinitionBlock))
- return false;
- pb->magicVersion = PLUGIN_VERSION;
- pb->version = FILESERVICES_VERSION;
- pb->moduleName = "lib_fileservices";
- pb->ECL = EclDefinition;
- pb->flags = PLUGIN_IMPLICIT_MODULE;
- pb->description = "FileServices library";
- return true;
- }
- namespace nsFileservices {
- IPluginContext * parentCtx = NULL;
- static IConstWorkUnit * getWorkunit(ICodeContext * ctx)
- {
- Owned<IWorkUnitFactory> factory = getWorkUnitFactory();
- StringAttr wuid;
- wuid.setown(ctx->getWuid());
- return factory->openWorkUnit(wuid);
- }
- static void setWorkunitState(ICodeContext * ctx, WUState state, const char * msg)
- {
- Owned<IWorkUnit> wu = ctx->updateWorkUnit();
- if (wu)
- {
- wu->setState(state);//resets stateEx
- if (msg)
- wu->setStateEx(msg);
- wu->commit();
- }
- }
- #ifndef _CONTAINERIZED
- static IConstEnvironment * openDaliEnvironment()
- {
- if (daliClientActive())
- {
- Owned<IEnvironmentFactory> factory = getEnvironmentFactory(true);
- return factory->openEnvironment();
- }
- return NULL;
- }
- static IPropertyTree *getEnvironmentTree(IConstEnvironment * daliEnv)
- {
- if (daliEnv)
- return &daliEnv->getPTree(); // No need to clone since daliEnv ensures connection stays alive.
- return getHPCCEnvironment();
- }
- #endif
- static void setServerAccess(CClientFileSpray &server, IConstWorkUnit * wu)
- {
- SCMStringBuffer token;
- wu->getWorkunitDistributedAccessToken(token);
- server.setUsernameToken(wu->queryUser(), token.str(), "");//use workunit token as password
- }
- static StringArray availableWsFS;
- static CriticalSection espURLcrit;
- static void addConfiguredWsFSUrl(const char * url)
- {
- CriticalBlock b(espURLcrit);
- availableWsFS.appendUniq(url);
- }
- static void setContainerLocalCertificate(IEspClientRpcSettings &rpc)
- {
- #ifdef _CONTAINERIZED
- //will only affect HTTPS
- rpc.setMtlsSecretName("local");
- #endif
- }
- static bool contactWsFS(const char * espurl, IConstWorkUnit * wu)
- {
- CClientFileSpray server;
- server.addServiceUrl(espurl);
- setServerAccess(server, wu);
- try
- {
- Owned<IClientEchoDateTime> req = server.createEchoDateTimeRequest();
- setContainerLocalCertificate(req->rpc());
- Owned<IClientEchoDateTimeResponse> result = server.EchoDateTime(req);
- if (result->getResult())
- return true;
- }
- catch(IException *ie)
- {
- StringBuffer error;
- ie->errorMessage(error);
- PROGLOG("Could not contact WsFS: '%s': %s",espurl, error.str());
- ie->Release();
- }
- catch(...)
- {
- PROGLOG("Could not contact WsFS: '%s'",espurl);
- }
- return false;
- }
- static const char * getNextAliveWsFSURL(IConstWorkUnit * wu)
- {
- CriticalBlock b(espURLcrit);
- for (int index = 0; index < availableWsFS.length(); index++)
- {
- const char * currentUrl = availableWsFS.item(index);
- if (contactWsFS(currentUrl, wu))
- return currentUrl;
- }
- return nullptr;
- }
- static bool isUrlListEmpty()
- {
- CriticalBlock b(espURLcrit);
- return availableWsFS.length() == 0;
- }
- static const char *getAccessibleEspServerURL(const char *param, IConstWorkUnit * wu)
- {
- if (param&&*param)
- return param;
- CriticalBlock b(espURLcrit);
- if (isUrlListEmpty())
- {
- #ifdef _CONTAINERIZED
- // Look for 'eclservices' esp service, fallback to 'eclwatch' service.
- Owned<IPropertyTree> globalConfig = getGlobalConfig();
- Owned<IPropertyTreeIterator> iter = globalConfig->getElements("services");
- IPropertyTree * match = nullptr;
- ForEach(*iter)
- {
- IPropertyTree & cur = iter->query();
- //Ecl queries should be connecting to the internal service - not the public services.
- if (cur.getPropBool("@public"))
- continue;
- const char *type = cur.queryProp("@type");
- if (streq("eclservices", type))
- {
- match = &cur;
- break;
- }
- else if (streq("eclwatch", type))
- match = &cur;
- }
- if (match)
- {
- const char * espService = match->queryProp("@name");
- const char *protocol = match->getPropBool("@tls") ? "https" : "http";
- unsigned port = match->getPropInt("@port", 8010);
- VStringBuffer espURL("%s://%s:%u/FileSpray", protocol, espService, port);
- addConfiguredWsFSUrl(espURL.str());
- }
- #else
- Owned<IConstEnvironment> daliEnv = openDaliEnvironment();
- Owned<IPropertyTree> env = getEnvironmentTree(daliEnv);
- if (env.get())
- {
- StringBuffer wsFSUrl;
- StringBuffer espInstanceComputerName;
- StringBuffer bindingProtocol;
- StringBuffer xpath;
- StringBuffer instanceAddress;
- StringBuffer espServiceType;
- Owned<IPropertyTreeIterator> espProcessIter = env->getElements("Software/EspProcess");
- ForEach(*espProcessIter)
- {
- Owned<IPropertyTreeIterator> espBindingIter = espProcessIter->query().getElements("EspBinding");
- ForEach(*espBindingIter)
- {
- espBindingIter->query().getProp("@service",wsFSUrl.clear());
- xpath.setf("Software/EspService[@name=\"%s\"]/Properties/@type", wsFSUrl.str());
- if(env->getProp(xpath.str(), espServiceType.clear()))
- {
- if (!espServiceType.isEmpty() && (strieq(espServiceType.str(),"WsSMC")|| strieq(espServiceType.str(),"FileSpray_Serv")))
- {
- if (espBindingIter->query().getProp("@protocol",bindingProtocol.clear()))
- {
- Owned<IPropertyTreeIterator> espInstanceIter = espProcessIter->query().getElements("Instance");
- ForEach(*espInstanceIter)
- {
- if (espInstanceIter->query().getProp("@computer",espInstanceComputerName.clear()))
- {
- xpath.setf("Hardware/Computer[@name=\"%s\"]/@netAddress",espInstanceComputerName.str());
- if (env->getProp(xpath.str(),instanceAddress.clear()))
- {
- wsFSUrl.setf("%s://%s:%d/FileSpray", bindingProtocol.str(), instanceAddress.str(), espBindingIter->query().getPropInt("@port",8010)); // FileSpray seems to be fixed
- addConfiguredWsFSUrl(wsFSUrl.str());
- }
- }
- }
- }
- }//EclWatch || ws_fs binding
- }
- }//ESPBinding
- }//ESPProcess
- }
- #endif
- if (isUrlListEmpty())
- throw MakeStringException(-1,"Could not find any WS FileSpray in the target HPCC configuration.");
- }
- const char * nextWsFSUrl = getNextAliveWsFSURL(wu);
- if (!nextWsFSUrl||!*nextWsFSUrl)
- throw MakeStringException(-1,"Could not contact any of the configured WS FileSpray instances, check HPCC configuration and system health.");
- PROGLOG("FileServices: Targeting ESP WsFileSpray URL: %s", nextWsFSUrl);
- return nextWsFSUrl;
- }
- StringBuffer & constructLogicalName(IConstWorkUnit * wu, const char * partialLogicalName, StringBuffer & result)
- {
- if (partialLogicalName == NULL)
- throw MakeStringException(0, "Logical Name Cannot be blank");
- if (*partialLogicalName == '~')
- ++partialLogicalName;
- else if (wu)
- {
- StringBuffer prefix;
- wu->getScope(StringBufferAdaptor(prefix));
- if (prefix.length())
- result.append(prefix).append("::");
- }
- result.append(partialLogicalName);
- if ((result.length()>0)&&(strstr(result.str(),"::")==NULL)&&(result.charAt(0)!='#'))
- result.insert(0,".::");
- return result;
- }
- StringBuffer & constructLogicalName(ICodeContext * ctx, const char * partialLogicalName, StringBuffer & result)
- {
- Owned<IConstWorkUnit> wu;
- if (partialLogicalName&&(*partialLogicalName != '~'))
- wu.setown(getWorkunit(ctx));
- return constructLogicalName(wu, partialLogicalName, result);
- }
- static void WUmessage(ICodeContext *ctx, ErrorSeverity sev, const char *fn, const char *msg)
- {
- StringBuffer s("fileservices");
- if (fn)
- s.append(", ").append(fn);
- ctx->addWuExceptionEx(msg, 0, sev, MSGAUD_audit, s.str()); // use plain code context
- return;
- }
- static void AuditMessage(ICodeContext *ctx,
- const char *func,
- const char *lfn1,
- const char *lfn2=NULL)
- {
- // FileServices,WUID,user,function,LFN1,LFN2
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- StringBuffer aln;
- StringAttr wuid;
- wuid.setown(ctx->getWuid());
- aln.append(",FileAccess,FileServices,").append(func).append(',').append(wuid).append(',');
- if (udesc)
- udesc->getUserName(aln);
- if (lfn1&&*lfn1) {
- aln.append(',').append(lfn1);
- if (lfn2&&*lfn2) {
- aln.append(',').append(lfn2);
- }
- }
- LOG(MCauditInfo,"%s",aln.str());
- }
- }//namespace
- using namespace nsFileservices;
- FILESERVICES_API void setPluginContext(IPluginContext * _ctx) { parentCtx = _ctx; }
- FILESERVICES_API char * FILESERVICES_CALL fsGetBuildInfo(void)
- {
- return CTXSTRDUP(parentCtx, FILESERVICES_VERSION);
- }
- //-------------------------------------------------------------------------------------------------------------------------------------------
- FILESERVICES_API void FILESERVICES_CALL fsDeleteLogicalFile(ICodeContext *ctx, const char *name,bool ifexists)
- {
- StringBuffer lfn;
- constructLogicalName(ctx, name, lfn);
- IDistributedFileTransaction *transaction = ctx->querySuperFileTransaction();
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- StringBuffer uname;
- DBGLOG("Deleting NS logical file %s for user %s", lfn.str(),udesc?udesc->getUserName(uname).str():"");
- if (queryDistributedFileDirectory().removeEntry(lfn.str(),udesc,transaction, INFINITE, true))
- {
- StringBuffer s("DeleteLogicalFile ('");
- s.append(lfn);
- if (transaction->active())
- s.append("') added to transaction");
- else
- s.append("') done");
- WUmessage(ctx,SeverityInformation,NULL,s.str());
- AuditMessage(ctx,"DeleteLogicalFile",lfn.str());
- }
- else if (!ifexists)
- {
- throw MakeStringException(0, "Could not delete file %s", lfn.str());
- }
- }
- FILESERVICES_API bool FILESERVICES_CALL fsFileExists(ICodeContext *ctx, const char *name, bool physical)
- {
- StringBuffer lfn;
- constructLogicalName(ctx, name, lfn);
- if (physical)
- return queryDistributedFileDirectory().existsPhysical(lfn.str(),ctx->queryUserDescriptor());
- return queryDistributedFileDirectory().exists(lfn.str(),ctx->queryUserDescriptor(),false,false);
- }
- FILESERVICES_API bool FILESERVICES_CALL fsFileValidate(ICodeContext *ctx, const char *name)
- {
- StringBuffer lfn;
- constructLogicalName(ctx, name, lfn);
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(lfn.str(),udesc, AccessMode::tbdRead, false, false, nullptr, defaultPrivilegedUser);
- if (df)
- {
- Owned<IDistributedFilePartIterator> partIter = df->getIterator();
- ForEach(*partIter)
- {
- IDistributedFilePart & part = partIter->query();
- unsigned numCopies = part.numCopies();
- bool gotone = false;
- offset_t partSize = (offset_t)-1;
- for (unsigned copy=0; copy < numCopies; copy++)
- {
- RemoteFilename remote;
- part.getFilename(remote,copy);
- OwnedIFile file = createIFile(remote);
- if (file->exists())
- {
- offset_t thisSize = file->size();
- if (gotone && (partSize != thisSize))
- throw MakeStringException(0, "Inconsistent file sizes for %s", lfn.str());
- partSize = thisSize;
- gotone = true;
- }
- }
- if (!gotone)
- return false;
- }
- return true;
- }
- return false;
- }
- FILESERVICES_API void FILESERVICES_CALL fsSetReadOnly(ICodeContext *ctx, const char *name, bool ro)
- {
- StringBuffer lfn;
- constructLogicalName(ctx, name, lfn);
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- Owned<IException> error;
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(lfn.str(),udesc, AccessMode::tbdWrite, false, false, nullptr, defaultPrivilegedUser);
- if (df)
- {
- LOG(MCauditInfo, "Set ReadOnly: %s", name);
- Owned<IDistributedFilePartIterator> partIter = df->getIterator();
- ForEach(*partIter)
- {
- IDistributedFilePart & part = partIter->query();
- unsigned numCopies = part.numCopies();
- for (unsigned copy=0; copy < numCopies; copy++)
- {
- RemoteFilename remote;
- part.getFilename(remote,copy);
- OwnedIFile file = createIFile(remote);
- try
- {
- file->setReadOnly(ro);
- }
- catch (IException * e)
- {
- EXCLOG(e);
- e->Release();
- }
- }
- }
- return;
- }
- if (!error)
- error.setown(MakeStringException(0, "Could not find logical file %s", lfn.str()));
- throw error.getClear();
- }
- FILESERVICES_API void FILESERVICES_CALL implementRenameLogicalFile(ICodeContext *ctx, const char *oldname, const char *newname, const bool overwrite)
- {
- StringBuffer oldLfn, newLfn;
- constructLogicalName(ctx, oldname, oldLfn);
- constructLogicalName(ctx, newname, newLfn);
- IDistributedFileTransaction *transaction = ctx->querySuperFileTransaction();
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- IDistributedFileDirectory &distributedDirectory = queryDistributedFileDirectory();
- if (!distributedDirectory.exists(oldLfn.str(), udesc, false, false))
- throw MakeStringException(0, "Old file %s doesn't exists.", oldLfn.str());
- if (overwrite && distributedDirectory.exists(newLfn.str(), udesc, false, false))
- fsDeleteLogicalFile(ctx, newname, true);
- try {
- distributedDirectory.renamePhysical(oldLfn.str(), newLfn.str(), udesc, transaction);
- StringBuffer s("RenameLogicalFile ('");
- s.append(oldLfn).append(", '").append(newLfn).append("') done");
- WUmessage(ctx, SeverityInformation, NULL, s.str());
- AuditMessage(ctx, "RenameLogicalFile", oldLfn.str(), newLfn.str());
- }
- catch (IException *e)
- {
- StringBuffer s;
- e->errorMessage(s);
- WUmessage(ctx, SeverityWarning, "RenameLogicalFile", s.str());
- throw e;
- }
- }
- FILESERVICES_API void FILESERVICES_CALL fsRenameLogicalFile(ICodeContext *ctx, const char *oldname, const char *newname)
- {
- implementRenameLogicalFile(ctx, oldname, newname, false);
- }
- FILESERVICES_API void FILESERVICES_CALL fsRenameLogicalFile_v2(ICodeContext *ctx, const char *oldname, const char *newname, const bool overwrite)
- {
- implementRenameLogicalFile(ctx, oldname, newname, overwrite);
- }
- FILESERVICES_API void FILESERVICES_CALL fsSendEmail_v2(ICodeContext * ctx, const char * to, const char * subject, const char * body, const char * mailServer, unsigned port, const char * sender, const char *cc, const char *bcc, bool highPriority)
- {
- StringArray warnings;
- sendEmail( to, cc, bcc, subject, body, mailServer, port, sender, &warnings, highPriority);
- ForEachItemIn(i,warnings)
- WUmessage(ctx, SeverityWarning, "SendEmail", warnings.item(i));
- }
- FILESERVICES_API void FILESERVICES_CALL fsSendEmail(ICodeContext * ctx, const char * to, const char * subject, const char * body, const char * mailServer, unsigned port, const char * sender)
- {
- fsSendEmail_v2(ctx, to, subject, body, mailServer, port, sender, nullptr, nullptr, false);
- }
- FILESERVICES_API void FILESERVICES_CALL fsSendEmailAttachText_v2(ICodeContext * ctx, const char * to, const char * subject, const char * body, const char * attachment, const char * mimeType, const char * attachmentName, const char * mailServer, unsigned int port, const char * sender, const char *cc, const char *bcc, bool highPriority)
- {
- StringArray warnings;
- sendEmailAttachText(to, cc, bcc, subject, body, attachment, mimeType, attachmentName, mailServer, port, sender, &warnings, highPriority);
- ForEachItemIn(i,warnings)
- WUmessage(ctx, SeverityWarning, "SendEmailAttachText", warnings.item(i));
- }
- FILESERVICES_API void FILESERVICES_CALL fsSendEmailAttachText(ICodeContext * ctx, const char * to, const char * subject, const char * body, const char * attachment, const char * mimeType, const char * attachmentName, const char * mailServer, unsigned int port, const char * sender)
- {
- fsSendEmailAttachText_v2(ctx, to, subject, body, attachment, mimeType, attachmentName, mailServer, port, sender, nullptr, nullptr, false);
- }
- FILESERVICES_API void FILESERVICES_CALL fsSendEmailAttachData_v2(ICodeContext * ctx, const char * to, const char * subject, const char * body, size32_t lenAttachment, const void * attachment, const char * mimeType, const char * attachmentName, const char * mailServer, unsigned int port, const char * sender, const char *cc, const char *bcc, bool highPriority)
- {
- StringArray warnings;
- sendEmailAttachData(to, cc, bcc, subject, body, lenAttachment, attachment, mimeType, attachmentName, mailServer, port, sender, &warnings, highPriority);
- ForEachItemIn(i,warnings)
- WUmessage(ctx, SeverityWarning, "SendEmailAttachData", warnings.item(i));
- }
- FILESERVICES_API void FILESERVICES_CALL fsSendEmailAttachData(ICodeContext * ctx, const char * to, const char * subject, const char * body, size32_t lenAttachment, const void * attachment, const char * mimeType, const char * attachmentName, const char * mailServer, unsigned int port, const char * sender)
- {
- fsSendEmailAttachData_v2(ctx, to, subject, body, lenAttachment, attachment, mimeType, attachmentName, mailServer, port, sender, nullptr, nullptr, false);
- }
- FILESERVICES_API char * FILESERVICES_CALL fsCmdProcess(const char *prog, const char *src)
- {
- throw makeStringException(0, "CmdProcess no longer supported for security reasons");
- }
- FILESERVICES_API void FILESERVICES_CALL fsCmdProcess2(unsigned & tgtLen, char * & tgt, const char *prog, unsigned srcLen, const char * src)
- {
- throw makeStringException(0, "CmdProcess no longer supported for security reasons");
- }
- static void blockUntilComplete(const char * label, IClientFileSpray &server, ICodeContext *ctx, const char * wuid, int timeOut, StringBuffer *stateout=NULL, bool monitoringok=false)
- {
- if (!wuid || strcmp(wuid, "") == 0)
- return;
- if (timeOut == 0)
- return;
- CTimeMon time(timeOut);
- unsigned polltime = 1;
- VStringBuffer reason("Blocked by fileservice activity: %s",label);
- setWorkunitState(ctx, WUStateBlocked, reason.str());
- while(true)
- {
- Owned<IClientGetDFUWorkunit> req = server.createGetDFUWorkunitRequest();
- setContainerLocalCertificate(req->rpc());
- req->setWuid(wuid);
- Owned<IClientGetDFUWorkunitResponse> result = server.GetDFUWorkunit(req);
- const IMultiException* excep = &result->getExceptions();
- if ((excep != NULL) && (excep->ordinality() > 0))
- {
- setWorkunitState(ctx, WUStateRunning, NULL);
- StringBuffer errmsg;
- excep->errorMessage(errmsg);
- throw MakeStringExceptionDirect(0, errmsg.str());
- }
- IConstDFUWorkunit & dfuwu = result->getResult();
- bool aborting = false;
- Owned<IWorkUnit> wu = ctx->updateWorkUnit(); // may return NULL
- if (wu.get()) { // if updatable (e.g. not hthor with no agent context)
- aborting = wu->aborting();
- StringBuffer wuScope, ElapsedLabel, RemainingLabel;
- wuScope.appendf("%s-%s", label, dfuwu.getID());
- ElapsedLabel.append(wuScope).append(" (Elapsed) ");
- RemainingLabel.append(wuScope).append(" (Remaining) ");
- //MORE: I think this are intended to replace the timing information, but will currently combine
- updateWorkunitStat(wu, SSTdfuworkunit, wuScope, StTimeElapsed, ElapsedLabel, milliToNano(time.elapsed()));
- updateWorkunitStat(wu, SSTdfuworkunit, wuScope, StTimeRemaining, RemainingLabel, milliToNano(dfuwu.getSecsLeft()*1000));
- stat_type costFileAccess = money2cost_type(dfuwu.getFileAccessCost());
- updateWorkunitStat(wu, SSTdfuworkunit, wuScope, StCostFileAccess, "", costFileAccess);
- wu->setApplicationValue(label, dfuwu.getID(), dfuwu.getSummaryMessage(), true);
- wu->commit();
- wu.clear();
- }
- DFUstate state = (DFUstate)dfuwu.getState();
- if (stateout)
- stateout->clear().append(dfuwu.getStateMessage());
- switch(state)
- {
- case DFUstate_unknown:
- case DFUstate_scheduled:
- case DFUstate_queued:
- case DFUstate_started:
- case DFUstate_aborting:
- break;
- case DFUstate_monitoring:
- if (monitoringok)
- {
- setWorkunitState(ctx, WUStateRunning, NULL);
- return;
- }
- break;
- case DFUstate_aborted:
- case DFUstate_failed:
- setWorkunitState(ctx, WUStateRunning, NULL);
- throw MakeStringException(0, "DFUServer Error %s", dfuwu.getSummaryMessage());
- case DFUstate_finished:
- setWorkunitState(ctx, WUStateRunning, NULL);
- return;
- }
- if (aborting)
- {
- Owned<IClientAbortDFUWorkunit> abortReq = server.createAbortDFUWorkunitRequest();
- setContainerLocalCertificate(abortReq->rpc());
- abortReq->setWuid(wuid);
- Linked<IClientAbortDFUWorkunitResponse> abortResp = server.AbortDFUWorkunit(abortReq);
- setWorkunitState(ctx, WUStateRunning, NULL);
- // Add warning of DFU Abort Request - should this be information ---
- StringBuffer s("DFU Workunit Abort Requested for ");
- s.append(wuid);
- WUmessage(ctx,SeverityWarning,"blockUntilComplete",s.str());
- throw MakeStringException(0, "Workunit abort request received");
- }
- if (time.timedout()) {
- unsigned left = dfuwu.getSecsLeft();
- setWorkunitState(ctx, WUStateRunning, NULL);
- if (left)
- throw MakeStringException(0, "%s timed out, DFU Secs left: %d)", label, left);
- throw MakeStringException(0, "%s timed out)", label);
- }
- Sleep(polltime*1000);
- polltime *= 2;
- if (polltime>WAIT_SECONDS)
- polltime = WAIT_SECONDS;
- }
- setWorkunitState(ctx, WUStateRunning, NULL);
- }
- //----------------------------------------------------------------------------------
- FILESERVICES_API char * FILESERVICES_CALL implementSprayFixed(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int recordSize, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue, bool noSplit, const char * sourcePlane = nullptr, unsigned destinationNumParts = 0)
- {
- LOG(MCauditInfo, "Spray: %s", destinationLogicalName);
- CClientFileSpray server;
- Owned<IConstWorkUnit> wu = getWorkunit(ctx);
- server.addServiceUrl(getAccessibleEspServerURL(espServerIpPort, wu));
- setServerAccess(server, wu);
- Owned<IClientSprayFixed> req = server.createSprayFixedRequest();
- setContainerLocalCertificate(req->rpc());
- StringBuffer logicalName;
- constructLogicalName(wu, destinationLogicalName, logicalName);
- req->setSourceIP(sourceIP);
- req->setSourcePath(sourcePath);
- req->setSourcePlane(sourcePlane);
- req->setSourceRecordSize(recordSize);
- req->setDestGroup(destinationGroup);
- req->setDestLogicalName(logicalName.str());
- req->setOverwrite(overwrite);
- req->setReplicate(replicate);
- req->setCompress(compress);
- if (maxConnections != -1)
- req->setMaxConnections(maxConnections);
- if (failIfNoSourceFile)
- req->setFailIfNoSourceFile(true);
- req->setExpireDays(expireDays);
- if (!isEmptyString(dfuServerQueue))
- req->setDFUServerQueue(dfuServerQueue);
- if (noSplit)
- req->setNosplit(true);
- Owned<IClientSprayFixedResponse> result = server.SprayFixed(req);
- StringBuffer wuid(result->getWuid());
- if (!wuid.length())
- {
- const IMultiException* excep = &result->getExceptions();
- if ((excep != NULL) && (excep->ordinality() > 0))
- {
- StringBuffer errmsg;
- excep->errorMessage(errmsg);
- throw MakeStringExceptionDirect(0, errmsg.str());
- }
- else
- {
- throw MakeStringExceptionDirect(0, "Result's dfu WUID is empty");
- }
- }
- wu.clear();
- blockUntilComplete("Spray", server, ctx, wuid, timeOut);
- return wuid.detach();
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayFixed(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int recordSize, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile)
- {
- CTXFREE(parentCtx, implementSprayFixed(ctx, sourceIP, sourcePath, recordSize, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, -1, nullptr, false));
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayFixed_v2(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int recordSize, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays)
- {
- CTXFREE(parentCtx, implementSprayFixed(ctx, sourceIP, sourcePath, recordSize, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, nullptr, false));
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayFixed_v3(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int recordSize, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue)
- {
- CTXFREE(parentCtx, implementSprayFixed(ctx, sourceIP, sourcePath, recordSize, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, dfuServerQueue, false));
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayFixed_v4(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int recordSize, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue, bool noSplit)
- {
- CTXFREE(parentCtx, implementSprayFixed(ctx, sourceIP, sourcePath, recordSize, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, dfuServerQueue, noSplit));
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayFixed_v5(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int recordSize, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue, bool noSplit, const char * sourcePlane, unsigned destinationNumParts)
- {
- CTXFREE(parentCtx, implementSprayFixed(ctx, sourceIP, sourcePath, recordSize, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, dfuServerQueue, noSplit, sourcePlane, destinationNumParts));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayFixed(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int recordSize, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile)
- {
- return implementSprayFixed(ctx, sourceIP, sourcePath, recordSize, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, -1, nullptr, false);
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayFixed_v2(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int recordSize, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays)
- {
- return implementSprayFixed(ctx, sourceIP, sourcePath, recordSize, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, nullptr, false);
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayFixed_v3(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int recordSize, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue)
- {
- return implementSprayFixed(ctx, sourceIP, sourcePath, recordSize, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, dfuServerQueue, false);
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayFixed_v4(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int recordSize, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue, bool noSplit)
- {
- return implementSprayFixed(ctx, sourceIP, sourcePath, recordSize, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, dfuServerQueue, noSplit);
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayFixed_v5(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int recordSize, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue, bool noSplit, const char * sourcePlane, unsigned destinationNumParts)
- {
- return implementSprayFixed(ctx, sourceIP, sourcePath, recordSize, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, dfuServerQueue, noSplit, sourcePlane, destinationNumParts);
- }
- //----------------------------------------------------------------------------------
- static char * implementSprayVariable(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * sourceCsvEscape, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, bool recordStructurePresent, bool quotedTerminator, const char * encoding, int expireDays, const char * dfuServerQueue, bool noSplit, const char * sourcePlane = nullptr, unsigned destinationNumParts = 0)
- {
- LOG(MCauditInfo, "Spray: %s", destinationLogicalName);
- CClientFileSpray server;
- Owned<IConstWorkUnit> wu = getWorkunit(ctx);
- server.addServiceUrl(getAccessibleEspServerURL(espServerIpPort,wu));
- setServerAccess(server, wu);
- Owned<IClientSprayVariable> req = server.createSprayVariableRequest();
- setContainerLocalCertificate(req->rpc());
- StringBuffer logicalName;
- constructLogicalName(wu, destinationLogicalName, logicalName);
- req->setSourceIP(sourceIP);
- req->setSourcePath(sourcePath);
- req->setSourcePlane(sourcePlane);
- req->setSourceMaxRecordSize(sourceMaxRecordSize);
- req->setSourceFormat(CDFUfileformat::decode(encoding));
- req->setSourceCsvSeparate(sourceCsvSeparate);
- if (sourceCsvSeparate && *sourceCsvSeparate == '\0')
- req->setNoSourceCsvSeparator(true);
- req->setSourceCsvTerminate(sourceCsvTerminate);
- req->setSourceCsvQuote(sourceCsvQuote);
- if (sourceCsvEscape && *sourceCsvEscape)
- req->setSourceCsvEscape(sourceCsvEscape);
- req->setDestGroup(destinationGroup);
- req->setDestLogicalName(logicalName.str());
- req->setOverwrite(overwrite);
- req->setReplicate(replicate);
- req->setCompress(compress);
- if (maxConnections != -1)
- req->setMaxConnections(maxConnections);
- if (failIfNoSourceFile)
- req->setFailIfNoSourceFile(true);
- if (recordStructurePresent)
- req->setRecordStructurePresent(true);
- if (!quotedTerminator)
- req->setQuotedTerminator(false);
- req->setExpireDays(expireDays);
- if (!isEmptyString(dfuServerQueue))
- req->setDFUServerQueue(dfuServerQueue);
- if (noSplit)
- req->setNosplit(true);
- Owned<IClientSprayResponse> result = server.SprayVariable(req);
- StringBuffer wuid(result->getWuid());
- if (!wuid.length())
- {
- const IMultiException* excep = &result->getExceptions();
- if ((excep != NULL) && (excep->ordinality() > 0))
- {
- StringBuffer errmsg;
- excep->errorMessage(errmsg);
- throw MakeStringExceptionDirect(0, errmsg.str());
- }
- else
- {
- throw MakeStringExceptionDirect(0, "Result's dfu WUID is empty");
- }
- }
- wu.clear();
- blockUntilComplete("Spray", server, ctx, wuid, timeOut);
- return wuid.detach();
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayVariable(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile)
- {
- CTXFREE(parentCtx, implementSprayVariable(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceCsvSeparate, sourceCsvTerminate, sourceCsvQuote, NULL, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, false, true, "ascii", -1, nullptr, false));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayVariable(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile)
- {
- return implementSprayVariable(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceCsvSeparate, sourceCsvTerminate, sourceCsvQuote, NULL, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, false, true, "ascii", -1, nullptr, false);
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayVariable2(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, const char * csvEscape, bool failIfNoSourceFile)
- {
- CTXFREE(parentCtx, implementSprayVariable(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceCsvSeparate, sourceCsvTerminate, sourceCsvQuote, csvEscape, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, false, true, "ascii", -1, nullptr, false));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayVariable2(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, const char * csvEscape, bool failIfNoSourceFile)
- {
- return implementSprayVariable(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceCsvSeparate, sourceCsvTerminate, sourceCsvQuote, csvEscape, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, false, true, "ascii", -1, nullptr, false);
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayVariable_v3(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, const char * csvEscape, bool failIfNoSourceFile, bool recordStructurePresent)
- {
- CTXFREE(parentCtx, implementSprayVariable(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceCsvSeparate, sourceCsvTerminate, sourceCsvQuote, csvEscape, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, recordStructurePresent, true, "ascii", -1, nullptr, false));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayVariable_v3(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, const char * csvEscape, bool failIfNoSourceFile, bool recordStructurePresent)
- {
- return implementSprayVariable(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceCsvSeparate, sourceCsvTerminate, sourceCsvQuote, csvEscape, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, recordStructurePresent, true, "ascii", -1, nullptr, false);
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayVariable_v4(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, const char * csvEscape, bool failIfNoSourceFile, bool recordStructurePresent, bool quotedTerminator)
- {
- CTXFREE(parentCtx, implementSprayVariable(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceCsvSeparate, sourceCsvTerminate, sourceCsvQuote, csvEscape, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, recordStructurePresent, quotedTerminator, "ascii", -1, nullptr, false));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayVariable_v4(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, const char * csvEscape, bool failIfNoSourceFile, bool recordStructurePresent, bool quotedTerminator)
- {
- return implementSprayVariable(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceCsvSeparate, sourceCsvTerminate, sourceCsvQuote, csvEscape, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, recordStructurePresent, quotedTerminator, "ascii", -1, nullptr, false);
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayVariable_v5(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, const char * csvEscape, bool failIfNoSourceFile, bool recordStructurePresent, bool quotedTerminator, const char * encoding)
- {
- CTXFREE(parentCtx, implementSprayVariable(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceCsvSeparate, sourceCsvTerminate, sourceCsvQuote, csvEscape, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, recordStructurePresent, quotedTerminator, encoding, -1, nullptr, false));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayVariable_v5(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, const char * csvEscape, bool failIfNoSourceFile, bool recordStructurePresent, bool quotedTerminator, const char * encoding)
- {
- return implementSprayVariable(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceCsvSeparate, sourceCsvTerminate, sourceCsvQuote, csvEscape, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, recordStructurePresent, quotedTerminator, encoding, -1, nullptr, false);
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayVariable_v6(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, const char * csvEscape, bool failIfNoSourceFile, bool recordStructurePresent, bool quotedTerminator, const char * encoding, int expireDays)
- {
- CTXFREE(parentCtx, implementSprayVariable(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceCsvSeparate, sourceCsvTerminate, sourceCsvQuote, csvEscape, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, recordStructurePresent, quotedTerminator, encoding, expireDays, nullptr, false));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayVariable_v6(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, const char * csvEscape, bool failIfNoSourceFile, bool recordStructurePresent, bool quotedTerminator, const char * encoding, int expireDays)
- {
- return implementSprayVariable(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceCsvSeparate, sourceCsvTerminate, sourceCsvQuote, csvEscape, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, recordStructurePresent, quotedTerminator, encoding, expireDays, nullptr, false);
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayVariable_v7(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, const char * csvEscape, bool failIfNoSourceFile, bool recordStructurePresent, bool quotedTerminator, const char * encoding, int expireDays, const char * dfuServerQueue)
- {
- CTXFREE(parentCtx, implementSprayVariable(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceCsvSeparate, sourceCsvTerminate, sourceCsvQuote, csvEscape, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, recordStructurePresent, quotedTerminator, encoding, expireDays, dfuServerQueue, false));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayVariable_v7(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, const char * csvEscape, bool failIfNoSourceFile, bool recordStructurePresent, bool quotedTerminator, const char * encoding, int expireDays, const char * dfuServerQueue)
- {
- return implementSprayVariable(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceCsvSeparate, sourceCsvTerminate, sourceCsvQuote, csvEscape, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, recordStructurePresent, quotedTerminator, encoding, expireDays, dfuServerQueue, false);
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayVariable_v8(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, const char * csvEscape, bool failIfNoSourceFile, bool recordStructurePresent, bool quotedTerminator, const char * encoding, int expireDays, const char * dfuServerQueue, bool noSplit)
- {
- CTXFREE(parentCtx, implementSprayVariable(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceCsvSeparate, sourceCsvTerminate, sourceCsvQuote, csvEscape, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, recordStructurePresent, quotedTerminator, encoding, expireDays, dfuServerQueue, noSplit));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayVariable_v8(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, const char * csvEscape, bool failIfNoSourceFile, bool recordStructurePresent, bool quotedTerminator, const char * encoding, int expireDays, const char * dfuServerQueue, bool noSplit)
- {
- return implementSprayVariable(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceCsvSeparate, sourceCsvTerminate, sourceCsvQuote, csvEscape, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, recordStructurePresent, quotedTerminator, encoding, expireDays, dfuServerQueue, noSplit);
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayVariable_v9(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, const char * csvEscape, bool failIfNoSourceFile, bool recordStructurePresent, bool quotedTerminator, const char * encoding, int expireDays, const char * dfuServerQueue, bool noSplit, const char * sourcePlane, unsigned destinationNumParts)
- {
- CTXFREE(parentCtx, implementSprayVariable(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceCsvSeparate, sourceCsvTerminate, sourceCsvQuote, csvEscape, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, recordStructurePresent, quotedTerminator, encoding, expireDays, dfuServerQueue, noSplit, sourcePlane, destinationNumParts));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayVariable_v9(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char * sourceCsvSeparate, const char * sourceCsvTerminate, const char * sourceCsvQuote, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, const char * csvEscape, bool failIfNoSourceFile, bool recordStructurePresent, bool quotedTerminator, const char * encoding, int expireDays, const char * dfuServerQueue, bool noSplit, const char * sourcePlane, unsigned destinationNumParts)
- {
- return implementSprayVariable(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceCsvSeparate, sourceCsvTerminate, sourceCsvQuote, csvEscape, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, recordStructurePresent, quotedTerminator, encoding, expireDays, dfuServerQueue, noSplit, sourcePlane, destinationNumParts);
- }
- //----------------------------------------------------------------------------------
- FILESERVICES_API char * FILESERVICES_CALL implementSprayXml(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char *sourceRowTag, const char *sourceEncoding, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue, bool noSplit, const char * sourcePlane, unsigned destinationNumParts=0)
- {
- LOG(MCauditInfo, "Spray: %s", destinationLogicalName);
- CClientFileSpray server;
- Owned<IConstWorkUnit> wu = getWorkunit(ctx);
- server.addServiceUrl(getAccessibleEspServerURL(espServerIpPort,wu));
- setServerAccess(server, wu);
- Owned<IClientSprayVariable> req = server.createSprayVariableRequest();
- setContainerLocalCertificate(req->rpc());
- StringBuffer logicalName;
- constructLogicalName(wu, destinationLogicalName, logicalName);
- DFUfileformat dfufmt;
- if (sourceEncoding == NULL)
- dfufmt = DFUff_utf8;
- else
- dfufmt = CDFUfileformat::decode(sourceEncoding);
- req->setSourceIP(sourceIP);
- req->setSourcePath(sourcePath);
- req->setSourcePlane(sourcePlane);
- req->setSourceMaxRecordSize(sourceMaxRecordSize);
- req->setSourceFormat(dfufmt);
- req->setSourceRowTag(sourceRowTag);
- req->setDestGroup(destinationGroup);
- req->setDestLogicalName(logicalName.str());
- req->setOverwrite(overwrite);
- req->setReplicate(replicate);
- req->setCompress(compress);
- if (maxConnections != -1)
- req->setMaxConnections(maxConnections);
- if (failIfNoSourceFile)
- req->setFailIfNoSourceFile(true);
- req->setExpireDays(expireDays);
- if (!isEmptyString(dfuServerQueue))
- req->setDFUServerQueue(dfuServerQueue);
- if (noSplit)
- req->setNosplit(true);
- Owned<IClientSprayResponse> result = server.SprayVariable(req);
- StringBuffer wuid(result->getWuid());
- if (!wuid.length())
- {
- const IMultiException* excep = &result->getExceptions();
- if ((excep != NULL) && (excep->ordinality() > 0))
- {
- StringBuffer errmsg;
- excep->errorMessage(errmsg);
- throw MakeStringExceptionDirect(0, errmsg.str());
- }
- else
- {
- throw MakeStringExceptionDirect(0, "Result's dfu WUID is empty");
- }
- }
- wu.clear();
- blockUntilComplete("Spray", server, ctx, wuid, timeOut);
- return wuid.detach();
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayXml(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char *sourceRowTag, const char *sourceEncoding, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile)
- {
- CTXFREE(parentCtx, implementSprayXml(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceRowTag, sourceEncoding, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, -1, nullptr, false, nullptr));
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayXml_v2(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char *sourceRowTag, const char *sourceEncoding, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays)
- {
- CTXFREE(parentCtx, implementSprayXml(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceRowTag, sourceEncoding, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, nullptr, false, nullptr));
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayXml_v3(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char *sourceRowTag, const char *sourceEncoding, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue)
- {
- CTXFREE(parentCtx, implementSprayXml(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceRowTag, sourceEncoding, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, dfuServerQueue, false, nullptr));
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayXml_v4(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char *sourceRowTag, const char *sourceEncoding, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue, bool noSplit)
- {
- CTXFREE(parentCtx, implementSprayXml(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceRowTag, sourceEncoding, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, dfuServerQueue, noSplit, nullptr));
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayXml_v5(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char *sourceRowTag, const char *sourceEncoding, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue, bool noSplit, const char * sourcePlane, unsigned destinationNumParts)
- {
- CTXFREE(parentCtx, implementSprayXml(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceRowTag, sourceEncoding, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, dfuServerQueue, noSplit, sourcePlane, destinationNumParts));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayXml(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char *sourceRowTag, const char *sourceEncoding, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile)
- {
- return implementSprayXml(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceRowTag, sourceEncoding, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, -1, nullptr, false, nullptr);
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayXml_v2(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char *sourceRowTag, const char *sourceEncoding, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays)
- {
- return implementSprayXml(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceRowTag, sourceEncoding, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, nullptr, false, nullptr);
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayXml_v3(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char *sourceRowTag, const char *sourceEncoding, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue)
- {
- return implementSprayXml(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceRowTag, sourceEncoding, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, dfuServerQueue, false, nullptr);
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayXml_v4(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char *sourceRowTag, const char *sourceEncoding, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue, bool noSplit)
- {
- return implementSprayXml(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceRowTag, sourceEncoding, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, dfuServerQueue, noSplit, nullptr);
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayXml_v5(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char *sourceRowTag, const char *sourceEncoding, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue, bool noSplit, const char * sourcePlane, unsigned destinationNumParts)
- {
- return implementSprayXml(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceRowTag, sourceEncoding, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, dfuServerQueue, noSplit, sourcePlane, destinationNumParts);
- }
- //----------------------------------------------------------------------------------
- FILESERVICES_API char * FILESERVICES_CALL implementSprayJson(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char *sourceRowPath, const char *sourceEncoding, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue, bool noSplit, const char * username, const char * userPw, const char * sourcePlane, unsigned destinationNumParts=0)
- {
- LOG(MCauditInfo, "Spray JSON: %s", destinationLogicalName);
- CClientFileSpray server;
- Owned<IConstWorkUnit> wu = getWorkunit(ctx);
- server.addServiceUrl(getAccessibleEspServerURL(espServerIpPort,wu));
- setServerAccess(server, wu);
- Owned<IClientSprayVariable> req = server.createSprayVariableRequest();
- setContainerLocalCertificate(req->rpc());
- StringBuffer logicalName;
- constructLogicalName(wu, destinationLogicalName, logicalName);
- DFUfileformat dfufmt;
- if (sourceEncoding == NULL)
- dfufmt = DFUff_utf8;
- else
- dfufmt = CDFUfileformat::decode(sourceEncoding);
- req->setSourceIP(sourceIP);
- req->setSourcePath(sourcePath);
- req->setSourcePlane(sourcePlane);
- req->setSourceMaxRecordSize(sourceMaxRecordSize);
- req->setSourceFormat(dfufmt);
- req->setSourceRowTag(sourceRowPath);
- req->setDestGroup(destinationGroup);
- req->setDestLogicalName(logicalName.str());
- req->setOverwrite(overwrite);
- req->setReplicate(replicate);
- req->setCompress(compress);
- if (maxConnections != -1)
- req->setMaxConnections(maxConnections);
- if (failIfNoSourceFile)
- req->setFailIfNoSourceFile(true);
- req->setIsJSON(true);
- req->setExpireDays(expireDays);
- if (!isEmptyString(dfuServerQueue))
- req->setDFUServerQueue(dfuServerQueue);
- if (noSplit)
- req->setNosplit(true);
- // Store username/psw
- if (!isEmptyString(username))
- {
- req->setSrcUsername(username);
- if (!isEmptyString(userPw))
- req->setSrcPassword(userPw);
- }
- Owned<IClientSprayResponse> result = server.SprayVariable(req);
- StringBuffer wuid(result->getWuid());
- if (!wuid.length())
- {
- const IMultiException* excep = &result->getExceptions();
- if ((excep != NULL) && (excep->ordinality() > 0))
- {
- StringBuffer errmsg;
- excep->errorMessage(errmsg);
- throw MakeStringExceptionDirect(0, errmsg.str());
- }
- else
- {
- throw MakeStringExceptionDirect(0, "Result's dfu WUID is empty");
- }
- }
- wu.clear();
- blockUntilComplete("Spray", server, ctx, wuid, timeOut);
- return wuid.detach();
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayJson(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char *sourceRowPath, const char *sourceEncoding, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue, bool noSplit, const char * username, const char * userPw)
- {
- CTXFREE(parentCtx, implementSprayJson(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceRowPath, sourceEncoding, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, dfuServerQueue, noSplit, username, userPw, nullptr));
- }
- FILESERVICES_API void FILESERVICES_CALL fsSprayJson_v2(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char *sourceRowPath, const char *sourceEncoding, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue, bool noSplit, const char * username, const char * userPw, const char * sourcePlane, unsigned destinationNumParts)
- {
- CTXFREE(parentCtx, implementSprayJson(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceRowPath, sourceEncoding, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, dfuServerQueue, noSplit, username, userPw, sourcePlane, destinationNumParts));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayJson(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char *sourceRowPath, const char *sourceEncoding, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue, bool noSplit, const char * username, const char * userPw)
- {
- return implementSprayJson(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceRowPath, sourceEncoding, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, dfuServerQueue, noSplit, username, userPw, nullptr);
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfSprayJson_v2(ICodeContext *ctx, const char * sourceIP, const char * sourcePath, int sourceMaxRecordSize, const char *sourceRowPath, const char *sourceEncoding, const char * destinationGroup, const char * destinationLogicalName, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool compress, bool failIfNoSourceFile, int expireDays, const char * dfuServerQueue, bool noSplit, const char * username, const char * userPw, const char * sourcePlane, unsigned destinationNumParts)
- {
- return implementSprayJson(ctx, sourceIP, sourcePath, sourceMaxRecordSize, sourceRowPath, sourceEncoding, destinationGroup, destinationLogicalName, timeOut, espServerIpPort, maxConnections, overwrite, replicate, compress, failIfNoSourceFile, expireDays, dfuServerQueue, noSplit, username, userPw, sourcePlane, destinationNumParts);
- }
- //----------------------------------------------------------------------------------
- static char * implementDespray(ICodeContext *ctx, const char * sourceLogicalName, const char * destinationIP, const char * destinationPath, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, const char * destinationPlane = nullptr)
- {
- LOG(MCauditInfo, "Despray: %s", sourceLogicalName);
- CClientFileSpray server;
- Owned<IConstWorkUnit> wu = getWorkunit(ctx);
- server.addServiceUrl(getAccessibleEspServerURL(espServerIpPort,wu));
- if (wu)
- setServerAccess(server, wu);
- Owned<IClientDespray> req = server.createDesprayRequest();
- setContainerLocalCertificate(req->rpc());
- StringBuffer logicalName;
- constructLogicalName(wu, sourceLogicalName, logicalName);
- req->setSourceLogicalName(logicalName.str());
- req->setDestIP(destinationIP);
- req->setDestPath(destinationPath);
- req->setDestPlane(destinationPlane);
- req->setOverwrite(overwrite);
- if (maxConnections != -1)
- req->setMaxConnections(maxConnections);
- Owned<IClientDesprayResponse> result = server.Despray(req);
- StringBuffer wuid(result->getWuid());
- if (!wuid.length())
- {
- const IMultiException* excep = &result->getExceptions();
- if ((excep != NULL) && (excep->ordinality() > 0))
- {
- StringBuffer errmsg;
- excep->errorMessage(errmsg);
- throw MakeStringExceptionDirect(0, errmsg.str());
- }
- else
- {
- throw MakeStringExceptionDirect(0, "Result's dfu WUID is empty");
- }
- }
- wu.clear();
- blockUntilComplete("Despray", server, ctx, wuid, timeOut);
- return wuid.detach();
- }
- FILESERVICES_API void FILESERVICES_CALL fsDespray(ICodeContext *ctx, const char * sourceLogicalName, const char * destinationIP, const char * destinationPath, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite)
- {
- CTXFREE(parentCtx, implementDespray(ctx, sourceLogicalName, destinationIP, destinationPath, timeOut, espServerIpPort, maxConnections, overwrite));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfDespray(ICodeContext *ctx, const char * sourceLogicalName, const char * destinationIP, const char * destinationPath, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite)
- {
- return implementDespray(ctx, sourceLogicalName, destinationIP, destinationPath, timeOut, espServerIpPort, maxConnections, overwrite);
- }
- FILESERVICES_API void FILESERVICES_CALL fsDespray2(ICodeContext *ctx, const char * sourceLogicalName, const char * destinationIP, const char * destinationPath, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, const char * destinationPlane)
- {
- CTXFREE(parentCtx, implementDespray(ctx, sourceLogicalName, destinationIP, destinationPath, timeOut, espServerIpPort, maxConnections, overwrite, destinationPlane));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfDespray2(ICodeContext *ctx, const char * sourceLogicalName, const char * destinationIP, const char * destinationPath, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, const char * destinationPlane)
- {
- return implementDespray(ctx, sourceLogicalName, destinationIP, destinationPath, timeOut, espServerIpPort, maxConnections, overwrite, destinationPlane);
- }
- FILESERVICES_API char * FILESERVICES_CALL implementCopy(ICodeContext *ctx, const char * sourceLogicalName, const char *destinationGroup, const char * destinationLogicalName, const char * sourceDali, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool asSuperfile, bool compress, bool forcePush, int transferBufferSize, bool preserveCompression, bool noSplit, int expireDays)
- {
- LOG(MCauditInfo, "Copy: %s%s", sourceLogicalName,asSuperfile?" as superfile":"");
- CClientFileSpray server;
- Owned<IConstWorkUnit> wu = getWorkunit(ctx);
- server.addServiceUrl(getAccessibleEspServerURL(espServerIpPort,wu));
- setServerAccess(server, wu);
- Owned<IClientCopy> req = server.createCopyRequest();
- setContainerLocalCertificate(req->rpc());
- if (asSuperfile)
- req->setSuperCopy(true);
- StringBuffer _sourceLogicalName, _destinationLogicalName;
- constructLogicalName(wu, sourceLogicalName, _sourceLogicalName);
- constructLogicalName(wu, destinationLogicalName, _destinationLogicalName);
- req->setSourceLogicalName(_sourceLogicalName.str());
- req->setDestLogicalName(_destinationLogicalName.str());
- if ((destinationGroup != NULL) && (*destinationGroup != '\0'))
- req->setDestGroup(destinationGroup);
- if ((sourceDali != NULL) && (*sourceDali != '\0'))
- req->setSourceDali(sourceDali);
- req->setOverwrite(overwrite);
- req->setReplicate(replicate);
- if (compress)
- req->setCompress(true);
- req->setPreserveCompression(preserveCompression);
- if (forcePush)
- req->setPush(true);
- if (transferBufferSize > 0)
- req->setTransferBufferSize(transferBufferSize);
- if (maxConnections != -1)
- req->setMaxConnections(maxConnections);
- if (noSplit)
- req->setNosplit(true);
- req->setExpireDays(expireDays);
- Owned<IClientCopyResponse> result = server.Copy(req);
- StringBuffer wuid(result->getResult());
- if (!wuid.length())
- {
- const IMultiException* excep = &result->getExceptions();
- if ((excep != NULL) && (excep->ordinality() > 0))
- {
- StringBuffer errmsg;
- excep->errorMessage(errmsg);
- throw MakeStringExceptionDirect(0, errmsg.str());
- }
- else
- {
- throw MakeStringExceptionDirect(0, "Result's dfu WUID is empty");
- }
- }
- wu.clear();
- blockUntilComplete("Copy", server, ctx, wuid, timeOut);
- return wuid.detach();
- }
- FILESERVICES_API void FILESERVICES_CALL fsCopy(ICodeContext *ctx, const char * sourceLogicalName, const char *destinationGroup, const char * destinationLogicalName, const char * sourceDali, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool asSuperfile, bool compress, bool forcePush, int transferBufferSize)
- {
- CTXFREE(parentCtx, implementCopy(ctx, sourceLogicalName, destinationGroup, destinationLogicalName, sourceDali, timeOut, espServerIpPort, maxConnections, overwrite, replicate, asSuperfile, compress, forcePush, transferBufferSize, true, false, -1));
- }
- FILESERVICES_API void FILESERVICES_CALL fsCopy_v2(ICodeContext *ctx, const char * sourceLogicalName, const char *destinationGroup, const char * destinationLogicalName, const char * sourceDali, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool asSuperfile, bool compress, bool forcePush, int transferBufferSize, bool preserveCompression)
- {
- CTXFREE(parentCtx, implementCopy(ctx, sourceLogicalName, destinationGroup, destinationLogicalName, sourceDali, timeOut, espServerIpPort, maxConnections, overwrite, replicate, asSuperfile, compress, forcePush, transferBufferSize, preserveCompression, false, -1));
- }
- FILESERVICES_API void FILESERVICES_CALL fsCopy_v3(ICodeContext *ctx, const char * sourceLogicalName, const char *destinationGroup, const char * destinationLogicalName, const char * sourceDali, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool asSuperfile, bool compress, bool forcePush, int transferBufferSize, bool preserveCompression, bool noSplit, int expireDays)
- {
- CTXFREE(parentCtx, implementCopy(ctx, sourceLogicalName, destinationGroup, destinationLogicalName, sourceDali, timeOut, espServerIpPort, maxConnections, overwrite, replicate, asSuperfile, compress, forcePush, transferBufferSize, preserveCompression, noSplit, expireDays));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfCopy(ICodeContext *ctx, const char * sourceLogicalName, const char *destinationGroup, const char * destinationLogicalName, const char * sourceDali, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool asSuperfile, bool compress, bool forcePush, int transferBufferSize)
- {
- return implementCopy(ctx, sourceLogicalName, destinationGroup, destinationLogicalName, sourceDali, timeOut, espServerIpPort, maxConnections, overwrite, replicate, asSuperfile, compress, forcePush, transferBufferSize, true, false, -1);
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfCopy_v2(ICodeContext *ctx, const char * sourceLogicalName, const char *destinationGroup, const char * destinationLogicalName, const char * sourceDali, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool asSuperfile, bool compress, bool forcePush, int transferBufferSize, bool preserveCompression)
- {
- return implementCopy(ctx, sourceLogicalName, destinationGroup, destinationLogicalName, sourceDali, timeOut, espServerIpPort, maxConnections, overwrite, replicate, asSuperfile, compress, forcePush, transferBufferSize, preserveCompression, false,-1);
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfCopy_v3(ICodeContext *ctx, const char * sourceLogicalName, const char *destinationGroup, const char * destinationLogicalName, const char * sourceDali, int timeOut, const char * espServerIpPort, int maxConnections, bool overwrite, bool replicate, bool asSuperfile, bool compress, bool forcePush, int transferBufferSize, bool preserveCompression, bool noSplit, int expireDays)
- {
- return implementCopy(ctx, sourceLogicalName, destinationGroup, destinationLogicalName, sourceDali, timeOut, espServerIpPort, maxConnections, overwrite, replicate, asSuperfile, compress, forcePush, transferBufferSize, preserveCompression, noSplit, expireDays);
- }
- FILESERVICES_API void FILESERVICES_CALL fsReplicate(ICodeContext *ctx, const char * sourceLogicalName,int timeOut, const char * espServerIpPort)
- {
- CTXFREE(parentCtx, fsfReplicate(ctx, sourceLogicalName, timeOut, espServerIpPort));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfReplicate(ICodeContext *ctx, const char * sourceLogicalName, int timeOut, const char * espServerIpPort)
- {
- LOG(MCauditInfo, "REPLICATE: %s", sourceLogicalName);
- CClientFileSpray server;
- Owned<IConstWorkUnit> wu = getWorkunit(ctx);
- server.addServiceUrl(getAccessibleEspServerURL(espServerIpPort,wu));
- setServerAccess(server, wu);
- Owned<IClientReplicate> req = server.createReplicateRequest();
- setContainerLocalCertificate(req->rpc());
- StringBuffer logicalName;
- constructLogicalName(wu, sourceLogicalName, logicalName);
- req->setSourceLogicalName(logicalName.str());
- Owned<IClientReplicateResponse> result = server.Replicate(req);
- StringBuffer wuid(result->getWuid());
- if (!wuid.length())
- {
- const IMultiException* excep = &result->getExceptions();
- if ((excep != NULL) && (excep->ordinality() > 0))
- {
- StringBuffer errmsg;
- excep->errorMessage(errmsg);
- throw MakeStringExceptionDirect(0, errmsg.str());
- }
- else
- {
- throw MakeStringExceptionDirect(0, "Result's dfu WUID is empty");
- }
- }
- wu.clear();
- blockUntilComplete("Replicate", server, ctx, wuid, timeOut);
- return wuid.detach();
- }
- //===========================================================================================
- // SuperFile API
- /*
- CreateSuperFile(const varstring lsuperfn, boolean sequentialparts=false);
- boolean SuperFileExists(const varstring lsuperfn);
- DeleteSuperFile(const varstring lsuperfn,boolean deletesub=false);
- unsigned4 GetSuperFileSubCount(const varstring lsuperfn);
- varstring GetSuperFileSubName(const varstring lsuperfn,unsigned4 filenum);
- unsigned4 FindSuperFileSubName(const varstring lsuperfn,const varstring lfn);
- StartSuperFileTransaction();
- AddSuperFile(const varstring lsuperfn,const varstring lfn,unsigned4 atpos=0);
- RemoveSuperFile(const varstring lsuperfn,const varstring lfn,boolean del=false);
- ClearSuperFile(const varstring lsuperfn,boolean del=false);
- RemoveOwnedSubFiles(const varstring lsuperfn,boolean del=false);
- SwapSuperFile(const varstring lsuperfn1,const varstring lsuperfn2);
- ReplaceSuperFile(const varstring lsuperfn,const varstring lfn,const varstring bylfn);
- FinishSuperFileTransaction(boolean rollback=false);
- */
- class CImplicitSuperTransaction
- {
- IDistributedFileTransaction *transaction;
- public:
- CImplicitSuperTransaction(IDistributedFileTransaction *_transaction)
- {
- if (!_transaction->active()) // then created implicitly
- {
- transaction = _transaction;
- transaction->start();
- }
- else
- transaction = NULL;
- }
- ~CImplicitSuperTransaction() noexcept(false)
- {
- if (transaction)
- transaction->commit();
- }
- };
- static bool lookupSuperFile(ICodeContext *ctx, const char *lsuperfn, Owned<IDistributedSuperFile> &file, bool throwerr, StringBuffer &lsfn, bool allowforeign, bool cacheFiles=false)
- {
- lsfn.clear();
- IDistributedFileTransaction *transaction = ctx->querySuperFileTransaction();
- assertex(transaction);
- constructLogicalName(ctx, lsuperfn, lsfn);
- if (!allowforeign) {
- CDfsLogicalFileName dlfn;
- dlfn.set(lsfn.str());
- if (dlfn.isForeign())
- throw MakeStringException(0, "Foreign superfile not allowed: %s", lsfn.str());
- }
- file.setown(transaction->lookupSuperFile(lsfn.str()));
- if (file.get())
- return true;
- if (throwerr)
- throw MakeStringException(0, "Could not locate superfile: %s", lsfn.str());
- return false;
- }
- static ISimpleSuperFileEnquiry *getSimpleSuperFileEnquiry(ICodeContext *ctx, const char *lsuperfn)
- {
- IDistributedFileTransaction *transaction = ctx->querySuperFileTransaction();
- assertex(transaction);
- if (transaction->active())
- return NULL;
- StringBuffer lsfn;
- constructLogicalName(ctx, lsuperfn, lsfn);
- return queryDistributedFileDirectory().getSimpleSuperFileEnquiry(lsfn.str(),"Fileservices",ctx->queryUserDescriptor());
- }
- static void CheckNotInTransaction(ICodeContext *ctx, const char *fn)
- {
- IDistributedFileTransaction *transaction = ctx->querySuperFileTransaction();
- assertex(transaction);
- if (transaction->active()) {
- StringBuffer s("Operation not part of transaction : ");
- s.append(fn);
- WUmessage(ctx,SeverityWarning,fn,s.str());
- }
- }
- FILESERVICES_API void FILESERVICES_CALL fsCreateSuperFile(ICodeContext *ctx, const char *lsuperfn, bool sequentialparts, bool ifdoesnotexist)
- {
- IDistributedFileTransaction *transaction = ctx->querySuperFileTransaction();
- assertex(transaction);
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- StringBuffer lsfn;
- constructLogicalName(ctx, lsuperfn, lsfn);
- Owned<IDistributedSuperFile> file = queryDistributedFileDirectory().createSuperFile(lsfn,udesc,!sequentialparts,ifdoesnotexist,transaction);
- StringBuffer s("CreateSuperFile ('");
- s.append(lsfn).append("') done");
- AuditMessage(ctx,"CreateSuperFile",lsfn.str());
- WUmessage(ctx,SeverityInformation,NULL,s.str());
- }
- FILESERVICES_API bool FILESERVICES_CALL fsSuperFileExists(ICodeContext *ctx, const char *lsuperfn)
- {
- StringBuffer lsfn;
- constructLogicalName(ctx, lsuperfn, lsfn);
- return queryDistributedFileDirectory().exists(lsfn,ctx->queryUserDescriptor(),false,true);
- }
- FILESERVICES_API void FILESERVICES_CALL fsDeleteSuperFile(ICodeContext *ctx, const char *lsuperfn,bool deletesub)
- {
- IDistributedFileTransaction *transaction = ctx->querySuperFileTransaction();
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- Owned<IDistributedSuperFile> file;
- StringBuffer lsfn;
- bool found = lookupSuperFile(ctx, lsuperfn, file, false, lsfn, false);
- file.clear(); // MORE: this should really be exists(file)
- StringBuffer s("DeleteSuperFile ('");
- s.append(lsfn).appendf("')");
- if (found) {
- queryDistributedFileDirectory().removeSuperFile(lsfn.str(), deletesub, udesc, transaction);
- if (transaction->active())
- s.append(" action added to transaction");
- else
- s.append(" done");
- } else {
- s.append(" file not found");
- }
- WUmessage(ctx,SeverityInformation,NULL,s.str());
- if (found)
- AuditMessage(ctx,"DeleteSuperFile",lsfn.str());
- }
- FILESERVICES_API unsigned FILESERVICES_CALL fsGetSuperFileSubCount(ICodeContext *ctx, const char *lsuperfn)
- {
- Owned<ISimpleSuperFileEnquiry> enq = getSimpleSuperFileEnquiry(ctx, lsuperfn);
- if (enq)
- return enq->numSubFiles();
- CImplicitSuperTransaction implicitTransaction(ctx->querySuperFileTransaction());
- Owned<IDistributedSuperFile> file;
- StringBuffer lsfn;
- lookupSuperFile(ctx, lsuperfn, file, true, lsfn, true);
- return file->numSubFiles();
- }
- FILESERVICES_API char * FILESERVICES_CALL fsGetSuperFileSubName(ICodeContext *ctx, const char *lsuperfn,unsigned filenum, bool abspath)
- {
- StringBuffer ret;
- if (abspath)
- ret.append('~');
- Owned<ISimpleSuperFileEnquiry> enq = getSimpleSuperFileEnquiry(ctx, lsuperfn);
- if (enq) {
- if (!filenum||!enq->getSubFileName(filenum-1,ret))
- return CTXSTRDUP(parentCtx, "");
- return ret.detach();
- }
- CImplicitSuperTransaction implicitTransaction(ctx->querySuperFileTransaction());
- Owned<IDistributedSuperFile> file;
- StringBuffer lsfn;
- lookupSuperFile(ctx, lsuperfn, file, true, lsfn, true);
- if (!filenum||filenum>file->numSubFiles())
- return CTXSTRDUP(parentCtx, "");
- ret.append(file->querySubFile(filenum-1).queryLogicalName());
- return ret.detach();
- }
- FILESERVICES_API unsigned FILESERVICES_CALL fsFindSuperFileSubName(ICodeContext *ctx, const char *lsuperfn,const char *_lfn)
- {
- StringBuffer lfn;
- constructLogicalName(ctx, _lfn, lfn);
- Owned<ISimpleSuperFileEnquiry> enq = getSimpleSuperFileEnquiry(ctx, lsuperfn);
- if (enq) {
- unsigned n = enq->findSubName(lfn.str());
- return (n==NotFound)?0:n+1;
- }
- CImplicitSuperTransaction implicitTransaction(ctx->querySuperFileTransaction());
- Owned<IDistributedSuperFile> file;
- StringBuffer lsfn;
- lookupSuperFile(ctx, lsuperfn, file, true, lsfn, true);
- unsigned n = 0;
- // could do with better version of this TBD
- Owned<IDistributedFileIterator> iter = file->getSubFileIterator();
- ForEach(*iter) {
- n++;
- if (stricmp(iter->query().queryLogicalName(),lfn.str())==0)
- return n;
- }
- return 0;
- }
- FILESERVICES_API void FILESERVICES_CALL fsStartSuperFileTransaction(IGlobalCodeContext *gctx)
- {
- fslStartSuperFileTransaction(gctx->queryCodeContext());
- }
- FILESERVICES_API void FILESERVICES_CALL fslStartSuperFileTransaction(ICodeContext *ctx)
- {
- IDistributedFileTransaction *transaction = ctx->querySuperFileTransaction();
- assertex(transaction);
- transaction->start();
- WUmessage(ctx,SeverityInformation,NULL,"StartSuperFileTransaction");
- }
- FILESERVICES_API void FILESERVICES_CALL fsAddSuperFile(IGlobalCodeContext *gctx, const char *lsuperfn,const char *_lfn,unsigned atpos,bool addcontents, bool strict)
- {
- fslAddSuperFile(gctx->queryCodeContext(),lsuperfn,_lfn,atpos,addcontents,strict);
- }
- FILESERVICES_API void FILESERVICES_CALL fslAddSuperFile(ICodeContext *ctx, const char *lsuperfn,const char *_lfn,unsigned atpos,bool addcontents, bool strict)
- {
- Owned<IDistributedSuperFile> file;
- StringBuffer lsfn;
- // NB: if adding contents, tell lookupSuperFile to cache the subfiles in the transaction
- if (!lookupSuperFile(ctx, lsuperfn, file, strict, lsfn, false, addcontents)) {
- // auto create
- fsCreateSuperFile(ctx,lsuperfn,false,false);
- lookupSuperFile(ctx, lsuperfn, file, true, lsfn, false, addcontents);
- }
- // Never add super file to itself
- StringBuffer lfn;
- constructLogicalName(ctx, _lfn, lfn);
- if (stricmp(file->queryLogicalName(), lfn.str()) == 0) {
- throw MakeStringException(0, "AddSuperFile: Adding super file %s to itself!", file->queryLogicalName());
- }
- IDistributedFileTransaction *transaction = ctx->querySuperFileTransaction();
- assertex(transaction);
- if (strict||addcontents) {
- Owned<IDistributedSuperFile> subfile;
- subfile.setown(transaction->lookupSuperFile(lfn.str()));
- if (!subfile.get())
- throw MakeStringException(0, "AddSuperFile%s: Could not locate super file %s", addcontents?"(addcontents)":"",lfn.str());
- if (strict&&(subfile->numSubFiles()<1))
- throw MakeStringException(0, "AddSuperFile: Adding empty super file %s", lfn.str());
- }
- StringBuffer other;
- if (atpos>1)
- other.append("#").append(atpos);
- {
- CImplicitSuperTransaction implicitTransaction(transaction);
- file->addSubFile(lfn.str(),atpos>0,(atpos>1)?other.str():NULL,addcontents,transaction);
- file.clear(); // Must clear file before implicit transaction executed in destructor
- }
- StringBuffer s("AddSuperFile ('");
- s.append(lsfn).append("', '");
- s.append(lfn).append('\'');
- if (atpos)
- s.append(", ").append(atpos);
- if (addcontents)
- s.append(", addcontents");
- s.append(") ");
- if (transaction->active())
- s.append("trans");
- else
- s.append("done");
- WUmessage(ctx,SeverityInformation,NULL,s.str());
- AuditMessage(ctx,"AddSuperFile",lsfn.str(),lfn.str());
- }
- FILESERVICES_API void FILESERVICES_CALL fsRemoveSuperFile(IGlobalCodeContext *gctx, const char *lsuperfn,const char *_lfn,bool del,bool remcontents)
- {
- fslRemoveSuperFile(gctx->queryCodeContext(),lsuperfn,_lfn,del,remcontents);
- }
- FILESERVICES_API void FILESERVICES_CALL fslRemoveSuperFile(ICodeContext *ctx, const char *lsuperfn,const char *_lfn,bool del,bool remcontents)
- {
- Owned<IDistributedSuperFile> file;
- StringBuffer lsfn;
- StringBuffer lfn;
- if (_lfn)
- constructLogicalName(ctx, _lfn, lfn);
- lookupSuperFile(ctx, lsuperfn, file, true, lsfn, false, true);
- IDistributedFileTransaction *transaction = ctx->querySuperFileTransaction();
- assertex(transaction);
- {
- CImplicitSuperTransaction implicitTransaction(transaction);
- file->removeSubFile(_lfn?lfn.str():NULL,del,remcontents,transaction);
- file.clear(); // Must clear file before implicit transaction executed in destructor
- }
- StringBuffer s;
- if (_lfn)
- s.append("RemoveSuperFile ('");
- else
- s.append("ClearSuperFile ('");
- s.append(lsfn).append('\'');
- if (_lfn)
- s.append(", '").append(lfn.str()).append('\'');
- if (del)
- s.append(", del");
- if (remcontents)
- s.append(", remcontents");
- s.append(") ");
- if (transaction->active())
- s.append("trans");
- else
- s.append("done");
- WUmessage(ctx,SeverityInformation,NULL,s.str());
- AuditMessage(ctx,"RemoveSuperFile",lsfn.str(),lfn.str());
- }
- FILESERVICES_API void FILESERVICES_CALL fsClearSuperFile(IGlobalCodeContext *gctx, const char *lsuperfn,bool del)
- {
- fsRemoveSuperFile(gctx,lsuperfn,NULL,del);
- }
- FILESERVICES_API void FILESERVICES_CALL fsDeleteOwnedSubFiles(IGlobalCodeContext *gctx, const char *lsuperfn) // Obsolete
- {
- fslRemoveOwnedSubFiles(gctx->queryCodeContext(), lsuperfn, false);
- }
- FILESERVICES_API void FILESERVICES_CALL fsRemoveOwnedSubFiles(IGlobalCodeContext *gctx, const char *lsuperfn, bool del)
- {
- fslRemoveOwnedSubFiles(gctx->queryCodeContext(), lsuperfn, del);
- }
- FILESERVICES_API void FILESERVICES_CALL fslRemoveOwnedSubFiles(ICodeContext *ctx, const char *lsuperfn, bool del)
- {
- Owned<IDistributedSuperFile> file;
- StringBuffer lsfn;
- lookupSuperFile(ctx, lsuperfn, file, true, lsfn, false, true);
- IDistributedFileTransaction *transaction = ctx->querySuperFileTransaction();
- assertex(transaction);
- {
- CImplicitSuperTransaction implicitTransaction(transaction);
- file->removeOwnedSubFiles(del,transaction);
- file.clear(); // Must clear file before implicit transaction executed in destructor
- }
- VStringBuffer s("RemoveOwnedSubFiles ('%s'", lsfn.str());
- if (del)
- s.append(", del");
- s.append(") ");
- if (transaction->active())
- s.append("trans");
- else
- s.append("done");
- WUmessage(ctx,SeverityInformation,NULL,s.str());
- AuditMessage(ctx,"RemoveOwnedSubFiles",lsfn.str());
- }
- FILESERVICES_API void FILESERVICES_CALL fslClearSuperFile(ICodeContext *ctx, const char *lsuperfn,bool del)
- {
- fslRemoveSuperFile(ctx,lsuperfn,NULL,del);
- }
- FILESERVICES_API void FILESERVICES_CALL fsSwapSuperFile(IGlobalCodeContext *gctx, const char *lsuperfn1,const char *lsuperfn2)
- {
- fslSwapSuperFile(gctx->queryCodeContext(),lsuperfn1,lsuperfn2);
- }
- FILESERVICES_API void FILESERVICES_CALL fslSwapSuperFile(ICodeContext *ctx, const char *lsuperfn1,const char *lsuperfn2)
- {
- StringBuffer lsfn1;
- StringBuffer lsfn2;
- Owned<IDistributedSuperFile> file1;
- Owned<IDistributedSuperFile> file2;
- lookupSuperFile(ctx, lsuperfn1, file1, true, lsfn1,false);
- lookupSuperFile(ctx, lsuperfn2, file2, true,lsfn2,false);
- IDistributedFileTransaction *transaction = ctx->querySuperFileTransaction();
- assertex(transaction);
- {
- CImplicitSuperTransaction implicitTransaction(transaction);
- file1->swapSuperFile(file2,transaction);
- // Must clear files before implicit transaction executed in destructor
- file1.clear();
- file2.clear();
- }
- StringBuffer s("SwapSuperFile ('");
- s.append(lsfn1).append("', '");
- s.append(lsfn2).append("') '");
- if (transaction->active())
- s.append("trans");
- else
- s.append("done");
- WUmessage(ctx,SeverityInformation,NULL,s.str());
- AuditMessage(ctx,"SwapSuperFile",lsfn1.str(),lsfn2.str());
- }
- FILESERVICES_API void FILESERVICES_CALL fsReplaceSuperFile(IGlobalCodeContext *gctx, const char *lsuperfn,const char *lfn,const char *bylfn)
- {
- fslReplaceSuperFile(gctx->queryCodeContext(),lsuperfn,lfn,bylfn);
- }
- FILESERVICES_API void FILESERVICES_CALL fslReplaceSuperFile(ICodeContext *ctx, const char *lsuperfn,const char *lfn,const char *bylfn)
- {
- unsigned at = fsFindSuperFileSubName(ctx,lsuperfn,lfn);
- if (!at)
- return;
- fslRemoveSuperFile(ctx,lsuperfn,lfn);
- fslAddSuperFile(ctx,lsuperfn,bylfn,at);
- }
- FILESERVICES_API void FILESERVICES_CALL fsFinishSuperFileTransaction(IGlobalCodeContext *gctx, bool rollback)
- {
- fslFinishSuperFileTransaction(gctx->queryCodeContext(),rollback);
- }
- FILESERVICES_API void FILESERVICES_CALL fslFinishSuperFileTransaction(ICodeContext *ctx, bool rollback)
- {
- IDistributedFileTransaction *transaction = ctx->querySuperFileTransaction();
- assertex(transaction);
- if (transaction->active()) {
- if (rollback)
- transaction->rollback();
- else
- transaction->commit();
- StringBuffer s("FinishSuperFileTransaction ");
- if (rollback)
- s.append("rollback");
- else
- s.append("commit");
- WUmessage(ctx,SeverityInformation,NULL,s.str());
- }
- else {
- StringBuffer s("Invalid FinishSuperFileTransaction ");
- if (rollback)
- s.append("rollback");
- else
- s.append("done");
- s.append(", transaction not active");
- WUmessage(ctx,SeverityInformation,NULL,s.str());
- }
- }
- static char * implementForeignLogicalFileName(ICodeContext *ctx, const char *_lfn, const char *foreigndali, bool abspath, bool omitClusterPrefix)
- {
- StringBuffer lfns;
- Owned<IConstWorkUnit> wu;
- if (!omitClusterPrefix && _lfn&&(*_lfn != '~'))
- wu.setown(getWorkunit(ctx));
- constructLogicalName(wu, _lfn, lfns);
- CDfsLogicalFileName lfn;
- lfn.set(lfns.str());
- if (foreigndali&&*foreigndali) {
- SocketEndpoint ep(foreigndali);
- lfn.setForeign(ep,false);
- }
- else
- lfn.clearForeign();
- StringBuffer ret;
- if (abspath)
- ret.append('~');
- lfn.get(ret);
- return ret.detach();
- }
- FILESERVICES_API char * FILESERVICES_CALL fsForeignLogicalFileName(ICodeContext *ctx, const char *lfn, const char *foreigndali, bool abspath)
- {
- return implementForeignLogicalFileName(ctx, lfn, foreigndali, abspath, false);
- }
- FILESERVICES_API char * FILESERVICES_CALL fsForeignLogicalFileName_v2(ICodeContext *ctx, const char *lfn, const char *foreigndali, bool abspath, bool omitClusterPrefix)
- {
- return implementForeignLogicalFileName(ctx, lfn, foreigndali, abspath, omitClusterPrefix);
- }
- FILESERVICES_API char * FILESERVICES_CALL fsExternalLogicalFileName(const char *location,const char *path,bool abspath)
- {
- StringBuffer ret;
- if (abspath)
- ret.append('~');
- CDfsLogicalFileName lfn;
- lfn.setExternal(location,path);
- return lfn.get(ret).detach();
- }
- FILESERVICES_API char * FILESERVICES_CALL fsWaitDfuWorkunit(IGlobalCodeContext *gctx, const char *wuid, int timeout, const char * espServerIpPort)
- {
- return fslWaitDfuWorkunit(gctx->queryCodeContext(),wuid,timeout,espServerIpPort);
- }
- FILESERVICES_API char * FILESERVICES_CALL fslWaitDfuWorkunit(ICodeContext *ctx, const char *wuid, int timeout, const char * espServerIpPort)
- {
- CClientFileSpray server;
- Owned<IConstWorkUnit> wu = getWorkunit(ctx);
- server.addServiceUrl(getAccessibleEspServerURL(espServerIpPort,wu));
- setServerAccess(server, wu);
- StringBuffer s("Waiting for DFU Workunit ");
- s.append(wuid);
- WUmessage(ctx,SeverityInformation,"WaitDfuWorkunit",s.str());
- StringBuffer state;
- wu.clear();
- blockUntilComplete("WaitDfuWorkunit", server, ctx, wuid, timeout, &state);
- s.clear().append("Finished waiting for DFU Workunit ").append(wuid).append(" state=").append(state.str());
- WUmessage(ctx,SeverityInformation,"WaitDfuWorkunit",s.str());
- return state.detach();
- }
- FILESERVICES_API void FILESERVICES_CALL fsAbortDfuWorkunit(IGlobalCodeContext *gctx, const char *wuid, const char * espServerIpPort)
- {
- fslAbortDfuWorkunit(gctx->queryCodeContext(),wuid,espServerIpPort);
- }
- FILESERVICES_API void FILESERVICES_CALL fslAbortDfuWorkunit(ICodeContext *ctx, const char *wuid, const char * espServerIpPort)
- {
- CClientFileSpray server;
- Owned<IConstWorkUnit> wu = getWorkunit(ctx);
- server.addServiceUrl(getAccessibleEspServerURL(espServerIpPort,wu));
- setServerAccess(server, wu);
- Owned<IClientAbortDFUWorkunit> abortReq = server.createAbortDFUWorkunitRequest();
- setContainerLocalCertificate(abortReq->rpc());
- abortReq->setWuid(wuid);
- Linked<IClientAbortDFUWorkunitResponse> abortResp = server.AbortDFUWorkunit(abortReq);
- StringBuffer s("DFU Workunit Abort Requested for ");
- s.append(wuid);
- WUmessage(ctx,SeverityInformation,"AbortDfuWorkunit",s.str());
- }
- FILESERVICES_API void FILESERVICES_CALL fsMonitorLogicalFileName(ICodeContext *ctx, const char *eventname, const char *_lfn,int shotcount, const char * espServerIpPort)
- {
- CTXFREE(parentCtx, fsfMonitorLogicalFileName(ctx, eventname, _lfn,shotcount, espServerIpPort));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfMonitorLogicalFileName(ICodeContext *ctx, const char *eventname, const char *_lfn,int shotcount, const char * espServerIpPort)
- {
- CClientFileSpray server;
- Owned<IConstWorkUnit> wu = getWorkunit(ctx);
- server.addServiceUrl(getAccessibleEspServerURL(espServerIpPort,wu));
- setServerAccess(server, wu);
- StringBuffer lfn;
- constructLogicalName(ctx, _lfn, lfn);
- if (shotcount == 0)
- shotcount = -1;
- Owned<IClientDfuMonitorRequest> req = server.createDfuMonitorRequest();
- setContainerLocalCertificate(req->rpc());
- req->setEventName(eventname);
- req->setLogicalName(lfn);
- req->setShotLimit(shotcount);
- Owned<IClientDfuMonitorResponse> result = server.DfuMonitor(req);
- StringBuffer res(result->getWuid());
- StringBuffer s("MonitorLogicalFileName ('");
- s.append(lfn).append("'): ").append(res);
- WUmessage(ctx,SeverityInformation,NULL,s.str());
- wu.clear();
- if (res.length()!=0)
- blockUntilComplete("MonitorLogicalFileName",server,ctx,res.str(),1000*60*60,NULL,true);
- return res.detach();
- }
- FILESERVICES_API void FILESERVICES_CALL fsMonitorFile(ICodeContext *ctx, const char *eventname,const char *ip, const char *filename, bool sub, int shotcount, const char * espServerIpPort)
- {
- CTXFREE(parentCtx, fsfMonitorFile(ctx, eventname,ip, filename, sub, shotcount, espServerIpPort));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfMonitorFile(ICodeContext *ctx, const char *eventname,const char *ip, const char *filename, bool sub, int shotcount, const char * espServerIpPort)
- {
- CClientFileSpray server;
- Owned<IConstWorkUnit> wu = getWorkunit(ctx);
- server.addServiceUrl(getAccessibleEspServerURL(espServerIpPort,wu));
- setServerAccess(server, wu);
- if (shotcount == 0)
- shotcount = -1;
- Owned<IClientDfuMonitorRequest> req = server.createDfuMonitorRequest();
- setContainerLocalCertificate(req->rpc());
- req->setEventName(eventname);
- req->setIp(ip);
- req->setFilename(filename);
- req->setShotLimit(shotcount);
- Owned<IClientDfuMonitorResponse> result = server.DfuMonitor(req);
- StringBuffer res(result->getWuid());
- StringBuffer s("MonitorFile (");
- s.append(ip).append(", '").append(filename).append("'): '").append(res);
- WUmessage(ctx,SeverityInformation,NULL,s.str());
- wu.clear();
- if (res.length()!=0)
- blockUntilComplete("MonitorFile",server,ctx,res.str(),1000*60*60,NULL,true);
- return res.detach();
- }
- FILESERVICES_API void FILESERVICES_CALL fsSetFileDescription(ICodeContext *ctx, const char *logicalfilename, const char *value)
- {
- StringBuffer lfn;
- constructLogicalName(ctx, logicalfilename, lfn);
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(lfn.str(),udesc, AccessMode::tbdRead, false, false, nullptr, defaultPrivilegedUser);
- if (df) {
- DistributedFilePropertyLock lock(df);
- lock.queryAttributes().setProp("@description",value);
- }
- else
- throw MakeStringException(0, "SetFileDescription: Could not locate file %s", lfn.str());
- }
- FILESERVICES_API char * FILESERVICES_CALL fsGetFileDescription(ICodeContext *ctx, const char *logicalfilename)
- {
- StringBuffer lfn;
- constructLogicalName(ctx, logicalfilename, lfn);
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(lfn.str(),udesc, AccessMode::tbdRead, false, false, nullptr, defaultPrivilegedUser);
- if (!df)
- throw MakeStringException(0, "GetFileDescription: Could not locate file %s", lfn.str());
- const char * ret = df->queryAttributes().queryProp("@description");
- if (ret)
- return CTXSTRDUP(parentCtx, ret);
- else
- return CTXSTRDUP(parentCtx, "");
- }
- FILESERVICES_API void FILESERVICES_CALL fsRemoteDirectory(size32_t & __lenResult,void * & __result, const char *machine, const char *dir, const char *mask, bool sub)
- {
- MemoryBuffer mb;
- RemoteFilename rfn;
- SocketEndpoint ep(machine);
- if (ep.isNull()){
- if (machine)
- throw MakeStringException(-1, "RemoteDirectory: Could not resolve host '%s'", machine);
- ep.setLocalHost(0);
- }
- rfn.setPath(ep,dir);
- Owned<IFile> f = createIFile(rfn);
- if (f) {
- StringBuffer s;
- StringBuffer ds;
- Owned<IDirectoryIterator> di = f->directoryFiles(mask,sub);
- if (di) {
- ForEach(*di) {
- di->getName(s.clear());
- __int64 fsz = di->getFileSize();
- CDateTime dt;
- di->getModifiedTime(dt);
- size32_t sz = s.length();
- dt.getString(ds.clear());
- ds.padTo(19);
- mb.append(sz).append(sz,s.str()).append(fsz).append(19,ds.str());
- }
- }
- }
- __lenResult = mb.length();
- __result = mb.detach();
- }
- FILESERVICES_API void FILESERVICES_CALL fsLogicalFileList(ICodeContext *ctx, size32_t & __lenResult,void * & __result, const char *mask, bool includenormal, bool includesuper, bool unknownszero, const char *foreigndali)
- {
- IEngineContext *engineCtx = ctx->queryEngineContext();
- if (engineCtx && !engineCtx->allowDaliAccess())
- {
- Owned<IException> e = MakeStringException(-1, "FileServices.LogicalFileList cannot access Dali in this context - this normally means it is being called from a thor slave");
- EXCLOG(e, NULL);
- throw e.getClear();
- }
- MemoryBuffer mb;
- if (!mask||!*mask)
- mask ="*";
- StringBuffer masklower(mask);
- masklower.toLowerCase();
- Owned<IDFAttributesIterator> iter = queryDistributedFileDirectory().getForeignDFAttributesIterator(masklower.str(),ctx->queryUserDescriptor(),true,includesuper,foreigndali);
- if (iter) {
- StringBuffer s;
- ForEach(*iter) {
- IPropertyTree &attr=iter->query();
- const char *name = attr.queryProp("@name");
- if (!name||!*name)
- continue;
- int numsub = attr.getPropInt("@numsubfiles",-1);
- bool issuper = numsub>=0;
- if (issuper) {
- if (!includesuper)
- continue;
- }
- else {
- if (!includenormal)
- continue;
- }
- size32_t sz = strlen(name);
- mb.append(sz).append(sz,name);
- mb.append(issuper);
- __int64 i64;
- __int64 fsz = attr.getPropInt64("@size",-1);
- if ((fsz==-1)&&(unknownszero||(numsub==0)))
- fsz = 0;
- mb.append(fsz);
- i64 = attr.getPropInt64("@recordCount",-1);
- if ((i64==-1)&&(fsz!=-1)) {
- int rsz = attr.getPropInt("@recordSize",0);
- if (rsz>0)
- i64 = fsz/rsz;
- }
- if ((i64==-1)&&(unknownszero||(numsub==0)))
- i64 = 0;
- mb.append(i64);
- attr.getProp("@modified",s.clear());
- s.padTo(19);
- mb.append(19,s.str());
- attr.getProp("@owner",s.clear());
- sz = s.length();
- mb.append(sz).append(sz,s.str());
- attr.getProp("@group",s.clear());
- sz = s.length();
- mb.append(sz).append(sz,s.str());
- }
- }
- __lenResult = mb.length();
- __result = mb.detach();
- }
- FILESERVICES_API void FILESERVICES_CALL fsSuperFileContents(ICodeContext *ctx, size32_t & __lenResult,void * & __result, const char *lsuperfn, bool recurse)
- {
- MemoryBuffer mb;
- Owned<ISimpleSuperFileEnquiry> enq;
- if (!recurse)
- enq.setown(getSimpleSuperFileEnquiry(ctx, lsuperfn));
- if (enq) {
- StringArray subs;
- enq->getContents(subs);
- ForEachItemIn(i,subs) {
- const char *name = subs.item(i);
- size32_t sz = strlen(name);
- if (!sz)
- continue;
- mb.append(sz).append(sz,name);
- }
- }
- else {
- CImplicitSuperTransaction implicitTransaction(ctx->querySuperFileTransaction());
- Owned<IDistributedSuperFile> file;
- StringBuffer lsfn;
- lookupSuperFile(ctx, lsuperfn, file, true, lsfn, true);
- Owned<IDistributedFileIterator> iter = file->getSubFileIterator(recurse);
- StringBuffer name;
- ForEach(*iter) {
- iter->getName(name.clear());
- size32_t sz = name.length();
- if (!sz)
- continue;
- mb.append(sz).append(sz,name.str());
- }
- }
- __lenResult = mb.length();
- __result = mb.detach();
- }
- FILESERVICES_API void FILESERVICES_CALL fsLogicalFileSuperOwners(ICodeContext *ctx,size32_t & __lenResult,void * & __result, const char *logicalfilename)
- {
- MemoryBuffer mb;
- StringBuffer lfn;
- constructLogicalName(ctx, logicalfilename, lfn);
- StringArray owners;
- if (queryDistributedFileDirectory().getFileSuperOwners(lfn.str(),owners)) {
- ForEachItemIn(i,owners) {
- const char *name = owners.item(i);
- size32_t sz = strlen(name);
- if (!sz)
- continue;
- mb.append(sz).append(sz,name);
- }
- }
- else {
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(lfn.str(),udesc,AccessMode::tbdRead,false,true, nullptr, defaultPrivilegedUser); // lock super-owners
- if (df) {
- Owned<IDistributedSuperFileIterator> iter = df->getOwningSuperFiles();
- ForEach(*iter) {
- const char *name = iter->queryName();
- size32_t sz = strlen(name);
- if (!sz)
- continue;
- mb.append(sz).append(sz,name);
- }
- }
- else
- throw MakeStringException(0, "LogicalFileSuperOwners: Could not locate file %s", lfn.str());
- }
- __lenResult = mb.length();
- __result = mb.detach();
- }
- FILESERVICES_API int FILESERVICES_CALL fsCompareFiles(ICodeContext *ctx,const char *name1, const char *name2,bool logicalonly, bool usecrcs)
- {
- StringBuffer lfn1;
- constructLogicalName(ctx, name1, lfn1);
- StringBuffer lfn2;
- constructLogicalName(ctx, name2, lfn2);
- StringBuffer retstr;
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- int ret = queryDistributedFileDirectory().fileCompare(lfn1.str(),lfn2.str(),usecrcs?DFS_COMPARE_FILES_PHYSICAL_CRCS:(logicalonly?DFS_COMPARE_FILES_LOGICAL:DFS_COMPARE_FILES_PHYSICAL),retstr,udesc);
- if (ret==DFS_COMPARE_RESULT_FAILURE)
- throw MakeStringException(ret,"CompareLogicalFiles: %s",retstr.str());
- return ret;
- }
- FILESERVICES_API char * FILESERVICES_CALL fsVerifyFile(ICodeContext *ctx,const char *name,bool usecrcs)
- {
- StringBuffer lfn;
- constructLogicalName(ctx, name, lfn);
- StringBuffer retstr;
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- if (queryDistributedFileDirectory().filePhysicalVerify(lfn.str(),udesc,usecrcs,retstr))
- retstr.append("OK");
- return retstr.detach();
- }
- // RemotePull
- /*
- varstring RemotePull(
- const varstring remoteEspFsURL, // remote ESP URL e.g. 'http://10.173.34.60:8010/FileSpray'
- const varstring sourceLogicalName, // local
- const varstring destinationGroup, // remote
- const varstring destinationLogicalName, // remote (NB full name required)
- integer4 timeOut=-1,
- integer4 maxConnections=-1,
- boolean allowoverwrite=false,
- boolean replicate=false,
- boolean asSuperfile=false);
- */
- FILESERVICES_API char * FILESERVICES_CALL fsfRemotePull_impl(ICodeContext *ctx,
- const char * remoteEspFsURL,
- const char * sourceLogicalName,
- const char *destinationGroup,
- const char * destinationLogicalName,
- int timeOut,
- int maxConnections,
- bool overwrite,
- bool replicate,
- bool asSuperfile,
- bool forcePush,
- int transferBufferSize,
- bool wrap,
- bool compress,
- bool noSplit,
- int expireDays,
- const char *username,
- const char *userPw)
- {
- LOG(MCauditInfo, "RemotePull(%s): %s%s", remoteEspFsURL,sourceLogicalName,asSuperfile?" as superfile":"");
- CClientFileSpray server;
- Owned<IConstWorkUnit> wu = getWorkunit(ctx);
- server.addServiceUrl(remoteEspFsURL);
- setServerAccess(server, wu);
- Owned<IClientCopy> req = server.createCopyRequest();
- setContainerLocalCertificate(req->rpc());
- if (asSuperfile)
- req->setSuperCopy(true);
- StringBuffer _sourceLogicalName, _destinationLogicalName;
- constructLogicalName(wu, sourceLogicalName, _sourceLogicalName);
- // destination name assumed complete (so just skip ~ *)
- while ((*destinationLogicalName=='~')||isspace(*destinationLogicalName))
- destinationLogicalName++;
- _destinationLogicalName.append(destinationLogicalName);
- if (strstr(_destinationLogicalName.str(),"::")==NULL)
- _destinationLogicalName.insert(0,".::");
- StringBuffer _destGroup;
- _destGroup.append(destinationGroup);
- req->setSourceLogicalName(_sourceLogicalName.str());
- req->setDestLogicalName(_destinationLogicalName.str());
- req->setDestGroup(_destGroup.str());
- if (compress)
- req->setCompress(true);
- if (wrap)
- req->setWrap(true);
- StringBuffer sourceDali;
- queryCoven().queryComm().queryGroup().queryNode(0).endpoint().getUrlStr(sourceDali);
- req->setSourceDali(sourceDali);
- req->setOverwrite(overwrite);
- req->setReplicate(replicate);
- if (forcePush)
- req->setPush(true);
- if (transferBufferSize>0)
- req->setTransferBufferSize(transferBufferSize);
- if (noSplit)
- req->setNosplit(true);
- req->setExpireDays(expireDays);
- // Handle username/psw
- if (!isEmptyString(username))
- {
- server.setUsernameToken(username, userPw, nullptr);
- req->setSrcusername(username);
- if (!isEmptyString(userPw))
- req->setSrcpassword(userPw);
- }
- Owned<IClientCopyResponse> result = server.Copy(req);
- StringBuffer wuid(result->getResult());
- if (!wuid.length())
- {
- const IMultiException* excep = &result->getExceptions();
- if ((excep != NULL) && (excep->ordinality() > 0))
- {
- StringBuffer errmsg;
- excep->errorMessage(errmsg);
- throw MakeStringExceptionDirect(0, errmsg.str());
- }
- else
- {
- throw MakeStringExceptionDirect(0, "Result's dfu WUID is empty");
- }
- }
- wu.clear();
- blockUntilComplete("RemotePull", server, ctx, wuid, timeOut);
- return wuid.detach();
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfRemotePull(ICodeContext *ctx,
- const char * remoteEspFsURL,
- const char * sourceLogicalName,
- const char *destinationGroup,
- const char * destinationLogicalName,
- int timeOut,
- int maxConnections,
- bool overwrite,
- bool replicate,
- bool asSuperfile,
- bool forcePush,
- int transferBufferSize,
- bool wrap,
- bool compress)
- {
- return fsfRemotePull_impl(ctx, remoteEspFsURL, sourceLogicalName, destinationGroup, destinationLogicalName, timeOut, maxConnections, overwrite, replicate, asSuperfile,forcePush,transferBufferSize, wrap, compress, false, -1, nullptr, nullptr);
- }
- FILESERVICES_API void FILESERVICES_CALL fsRemotePull(ICodeContext *ctx,
- const char * remoteEspFsURL,
- const char * sourceLogicalName,
- const char *destinationGroup,
- const char * destinationLogicalName,
- int timeOut,
- int maxConnections,
- bool overwrite,
- bool replicate,
- bool asSuperfile,
- bool forcePush,
- int transferBufferSize,
- bool wrap,
- bool compress)
- {
- CTXFREE(parentCtx, fsfRemotePull_impl(ctx, remoteEspFsURL, sourceLogicalName, destinationGroup, destinationLogicalName, timeOut, maxConnections, overwrite, replicate, asSuperfile,forcePush,transferBufferSize, wrap, compress, false, -1, nullptr, nullptr));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfRemotePull_v2(ICodeContext *ctx,
- const char * remoteEspFsURL,
- const char * sourceLogicalName,
- const char *destinationGroup,
- const char * destinationLogicalName,
- int timeOut,
- int maxConnections,
- bool overwrite,
- bool replicate,
- bool asSuperfile,
- bool forcePush,
- int transferBufferSize,
- bool wrap,
- bool compress,
- bool noSplit,
- int expireDays)
- {
- return fsfRemotePull_impl(ctx, remoteEspFsURL, sourceLogicalName, destinationGroup, destinationLogicalName, timeOut, maxConnections, overwrite, replicate, asSuperfile,forcePush,transferBufferSize, wrap, compress, noSplit, expireDays, nullptr, nullptr);
- }
- FILESERVICES_API void FILESERVICES_CALL fsRemotePull_v2(ICodeContext *ctx,
- const char * remoteEspFsURL,
- const char * sourceLogicalName,
- const char *destinationGroup,
- const char * destinationLogicalName,
- int timeOut,
- int maxConnections,
- bool overwrite,
- bool replicate,
- bool asSuperfile,
- bool forcePush,
- int transferBufferSize,
- bool wrap,
- bool compress,
- bool noSplit,
- int expireDays)
- {
- CTXFREE(parentCtx, fsfRemotePull_impl(ctx, remoteEspFsURL, sourceLogicalName, destinationGroup, destinationLogicalName, timeOut, maxConnections, overwrite, replicate, asSuperfile,forcePush,transferBufferSize, wrap, compress, noSplit, expireDays, nullptr, nullptr));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfRemotePull_v3(ICodeContext *ctx,
- const char * remoteEspFsURL,
- const char * sourceLogicalName,
- const char *destinationGroup,
- const char * destinationLogicalName,
- int timeOut,
- int maxConnections,
- bool overwrite,
- bool replicate,
- bool asSuperfile,
- bool forcePush,
- int transferBufferSize,
- bool wrap,
- bool compress,
- bool noSplit,
- int expireDays,
- const char *username,
- const char *userPw)
- {
- return fsfRemotePull_impl(ctx, remoteEspFsURL, sourceLogicalName, destinationGroup, destinationLogicalName, timeOut, maxConnections, overwrite, replicate, asSuperfile,forcePush,transferBufferSize, wrap, compress, noSplit, expireDays, username, userPw);
- }
- FILESERVICES_API void FILESERVICES_CALL fsRemotePull_v3(ICodeContext *ctx,
- const char * remoteEspFsURL,
- const char * sourceLogicalName,
- const char *destinationGroup,
- const char * destinationLogicalName,
- int timeOut,
- int maxConnections,
- bool overwrite,
- bool replicate,
- bool asSuperfile,
- bool forcePush,
- int transferBufferSize,
- bool wrap,
- bool compress,
- bool noSplit,
- int expireDays,
- const char *username,
- const char *userPw)
- {
- CTXFREE(parentCtx, fsfRemotePull_impl(ctx, remoteEspFsURL, sourceLogicalName, destinationGroup, destinationLogicalName, timeOut, maxConnections, overwrite, replicate, asSuperfile,forcePush,transferBufferSize, wrap, compress, noSplit, expireDays, username, userPw));
- }
- FILESERVICES_API void FILESERVICES_CALL fsLogicalFileSuperSubList(ICodeContext *ctx, size32_t & __lenResult,void * & __result)
- {
- MemoryBuffer mb;
- getLogicalFileSuperSubList(mb, ctx->queryUserDescriptor());
- __lenResult = mb.length();
- __result = mb.detach();
- }
- FILESERVICES_API void FILESERVICES_CALL fsPromoteSuperFileList(ICodeContext * ctx,bool isAllLsuperfns,size32_t lenLsuperfns,const void * lsuperfns,const char * addhead,bool deltail,bool createonlyonesuperfile,bool reverse)
- {
- CTXFREE(parentCtx, fsfPromoteSuperFileList(ctx,isAllLsuperfns,lenLsuperfns,lsuperfns,addhead,deltail,createonlyonesuperfile,reverse));
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfPromoteSuperFileList(ICodeContext * ctx,bool isAllLsuperfns,size32_t lenLsuperfns,const void * lsuperfns,const char * addhead,bool deltail,bool createonlyonesuperfile,bool reverse)
- {
- Owned<IConstWorkUnit> wu = getWorkunit(ctx);
- MemoryBuffer mb;
- StringBuffer lfn;
- UnsignedArray lfnofs;
- const char *s = (const char *)lsuperfns;
- // MORE - For now, we need a local transaction
- CheckNotInTransaction(ctx, "PromoteSuperFile");
- while ((size32_t)(s-(const char *)lsuperfns)<lenLsuperfns) {
- constructLogicalName(wu,s,lfn.clear());
- lfnofs.append(mb.length());
- mb.append(lfn);
- s = s+strlen(s)+1;
- }
- PointerArray lfns;
- ForEachItemIn(i,lfnofs) {
- lfns.append((void *)(mb.toByteArray()+lfnofs.item(reverse?(lfnofs.ordinality()-i-1):i)));
- }
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- StringArray toadd;
- toadd.appendListUniq(addhead, ",");
- StringBuffer addlist;
- ForEachItemIn(i1,toadd) {
- if (addlist.length())
- addlist.append(',');
- constructLogicalName(wu,toadd.item(i1),addlist);
- }
- toadd.kill();
- queryDistributedFileDirectory().promoteSuperFiles(lfns.ordinality(),(const char **)lfns.getArray(),addlist.str(),deltail,createonlyonesuperfile,udesc.get(),(unsigned)-1,toadd);
- addlist.clear();
- ForEachItemIn(i2,toadd) {
- if (addlist.length())
- addlist.append(',');
- constructLogicalName(wu,toadd.item(i2),addlist);
- }
- return addlist.detach();
- }
- FILESERVICES_API unsigned __int64 FILESERVICES_CALL fsGetUniqueInteger(ICodeContext * ctx, const char *foreigndali)
- {
- SocketEndpoint ep;
- if (foreigndali&&*foreigndali)
- ep.set(foreigndali);
- IEngineContext *engineContext = ctx->queryEngineContext();
- if (engineContext)
- return engineContext->getGlobalUniqueIds(1,&ep);
- return getGlobalUniqueIds(1,&ep);
- }
- FILESERVICES_API void FILESERVICES_CALL fsAddFileRelationship(ICodeContext * ctx,const char *primary, const char *secondary, const char *primflds, const char *secflds, const char *kind, const char *cardinality, bool payload, const char *description)
- {
- StringBuffer pfn;
- constructLogicalName(ctx, primary, pfn);
- StringBuffer sfn;
- constructLogicalName(ctx, secondary, sfn);
- queryDistributedFileDirectory().addFileRelationship(pfn.str(),sfn.str(),primflds,secflds,kind,cardinality,payload,ctx->queryUserDescriptor(), description);
- StringBuffer s("AddFileRelationship('");
- s.append(pfn.str()).append("','").append(sfn.str()).append("','").append(primflds?primflds:"").append("','").append(secflds?secflds:"").append("','").append(kind?kind:"").append("') done");
- WUmessage(ctx,SeverityInformation,NULL,s.str());
- }
- static inline void addmbstr(MemoryBuffer &mb,const char *s)
- {
- size32_t sz = strlen(s);
- mb.append(sz).append(sz,s);
- }
- FILESERVICES_API void FILESERVICES_CALL fsFileRelationshipList(ICodeContext * ctx,size32_t & __lenResult,void * & __result,const char *primary, const char *secondary, const char *primflds, const char *secflds, const char *kind)
- {
- StringBuffer pfn;
- if (primary&&*primary)
- constructLogicalName(ctx, primary, pfn);
- StringBuffer sfn;
- if (secondary&&*secondary)
- constructLogicalName(ctx, secondary, sfn);
- MemoryBuffer mb;
- Owned<IFileRelationshipIterator> iter = queryDistributedFileDirectory().lookupFileRelationships(pfn.str(),sfn.str(),primflds,secflds,kind);
- if (iter) {
- StringBuffer s;
- ForEach(*iter) {
- IFileRelationship &rel=iter->query();
- addmbstr(mb,rel.queryPrimaryFilename());
- addmbstr(mb,rel.querySecondaryFilename());
- addmbstr(mb,rel.queryPrimaryFields());
- addmbstr(mb,rel.querySecondaryFields());
- addmbstr(mb,rel.queryKind());
- addmbstr(mb,rel.queryCardinality());
- mb.append((byte)(rel.isPayload()?1:0));
- addmbstr(mb,rel.queryDescription());
- }
- }
- __lenResult = mb.length();
- __result = mb.detach();
- }
- FILESERVICES_API void FILESERVICES_CALL fsRemoveFileRelationship(ICodeContext * ctx,const char *primary, const char *secondary, const char *primflds, const char *secflds, const char *kind)
- {
- StringBuffer pfn;
- if (primary&&*primary)
- constructLogicalName(ctx, primary, pfn);
- StringBuffer sfn;
- if (secondary&&*secondary)
- constructLogicalName(ctx, secondary, sfn);
- queryDistributedFileDirectory().removeFileRelationships(pfn.str(),sfn.str(),primflds,secflds,kind);
- }
- FILESERVICES_API void FILESERVICES_CALL fsSetColumnMapping(ICodeContext * ctx,const char *filename, const char *mapping)
- {
- StringBuffer lfn;
- constructLogicalName(ctx, filename, lfn);
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(lfn.str(),ctx->queryUserDescriptor(),AccessMode::tbdWrite,false,false,nullptr,defaultPrivilegedUser);
- if (df)
- df->setColumnMapping(mapping);
- else
- throw MakeStringException(-1, "SetColumnMapping: Could not find logical file %s", lfn.str());
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfGetColumnMapping(ICodeContext * ctx,const char *filename)
- {
- StringBuffer lfn;
- constructLogicalName(ctx, filename, lfn);
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(lfn.str(),ctx->queryUserDescriptor(),AccessMode::tbdWrite,false,false,nullptr,defaultPrivilegedUser);
- if (df) {
- StringBuffer mapping;
- df->getColumnMapping(mapping);
- return mapping.detach();
- }
- throw MakeStringException(-1, "GetColumnMapping: Could not find logical file %s", lfn.str());
- return NULL;
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfRfsQuery(const char *server, const char *query)
- {
- StringBuffer ret;
- ret.append('~');
- CDfsLogicalFileName lfn;
- lfn.setQuery(server,query);
- if (!lfn.isSet())
- throw MakeStringException(-1, "RfsQuery invalid parameter");
- return lfn.get(ret).detach();
- }
- FILESERVICES_API void FILESERVICES_CALL fsRfsAction(const char *server, const char *query)
- {
- CDfsLogicalFileName lfn;
- lfn.setQuery(server,query);
- if (!lfn.isSet())
- throw MakeStringException(-1, "RfsAction invalid parameter");
- RemoteFilename rfn;
- lfn.getExternalFilename(rfn);
- Owned<IFile> file = createIFile(rfn);
- Owned<IFileIO> fileio = file->open(IFOread);
- if (fileio) {
- // lets just try reading a byte to cause action
- byte b;
- fileio->read(0,sizeof(b),&b);
- }
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfGetHostName(const char *ipaddress)
- {
- // not a common routine (no Jlib function!) only support IPv4 initially
- StringBuffer ret;
- if (ipaddress&&*ipaddress) {
- IpAddress ip(ipaddress);
- lookupHostName(ip,ret);
- }
- else
- GetHostName(ret);
- return ret.detach();
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfResolveHostName(const char *hostname)
- {
- StringBuffer ret;
- SocketEndpoint ep(hostname);
- ep.getIpText(ret);
- return ret.detach();
- }
- static void checkExternalFileRights(ICodeContext *ctx, CDfsLogicalFileName &lfn, bool rd,bool wr)
- {
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- unsigned auditflags = 0;
- if (rd)
- auditflags |= (DALI_LDAP_AUDIT_REPORT|DALI_LDAP_READ_WANTED);
- if (wr)
- auditflags |= (DALI_LDAP_AUDIT_REPORT|DALI_LDAP_WRITE_WANTED);
- SecAccessFlags perm = queryDistributedFileDirectory().getFilePermissions(lfn.get(),udesc,auditflags);
- if (wr) {
- if (!HASWRITEPERMISSION(perm)) {
- throw MakeStringException(-1,"Write permission denied for %s", lfn.get());
- }
- }
- if (rd) {
- if (!HASREADPERMISSION(perm)) {
- throw MakeStringException(-1,"Read permission denied for %s", lfn.get());
- }
- }
- }
- FILESERVICES_API void FILESERVICES_CALL fsMoveExternalFile(ICodeContext * ctx,const char *location,const char *frompath,const char *topath)
- {
- SocketEndpoint ep(location);
- if (ep.isNull())
- throw MakeStringException(-1,"fsMoveExternalFile: Cannot resolve location %s",location);
- CDfsLogicalFileName from;
- from.setExternal(location,frompath);
- CDfsLogicalFileName to;
- to.setExternal(location,topath);
- checkExternalFileRights(ctx,from,true,true);
- checkExternalFileRights(ctx,to,false,true);
- RemoteFilename fromrfn;
- fromrfn.setPath(ep,frompath);
- RemoteFilename torfn;
- torfn.setPath(ep,topath);
- Owned<IFile> fileto = createIFile(torfn);
- if (fileto->exists())
- throw MakeStringException(-1,"fsMoveExternalFile: Destination %s already exists", topath);
- fileto.clear();
- Owned<IFile> file = createIFile(fromrfn);
- file->move(topath);
- StringBuffer s("MoveExternalFile ('");
- s.append(location).append(',').append(frompath).append(',').append(topath).append(") done");
- WUmessage(ctx,SeverityInformation,NULL,s.str());
- AuditMessage(ctx,"MoveExternalFile",frompath,topath);
- }
- FILESERVICES_API void FILESERVICES_CALL fsDeleteExternalFile(ICodeContext * ctx,const char *location,const char *path)
- {
- SocketEndpoint ep(location);
- if (ep.isNull())
- throw MakeStringException(-1,"fsDeleteExternalFile: Cannot resolve location %s",location);
- CDfsLogicalFileName lfn;
- lfn.setExternal(location,path);
- checkExternalFileRights(ctx,lfn,false,true);
- RemoteFilename rfn;
- rfn.setPath(ep,path);
- Owned<IFile> file = createIFile(rfn);
- file->remove();
- StringBuffer s("DeleteExternalFile ('");
- s.append(location).append(',').append(path).append(") done");
- WUmessage(ctx,SeverityInformation,NULL,s.str());
- AuditMessage(ctx,"DeleteExternalFile",path);
- }
- FILESERVICES_API void FILESERVICES_CALL fsCreateExternalDirectory(ICodeContext * ctx,const char *location,const char *_path)
- {
- SocketEndpoint ep(location);
- if (ep.isNull())
- throw MakeStringException(-1, "fsCreateExternalDirectory: Cannot resolve location %s",location);
- CDfsLogicalFileName lfn;
- StringBuffer path(_path);
- if (0 == path.length())
- throw MakeStringException(-1, "fsCreateExternalDirectory: empty directory");
- // remove trailing path separator if present to make it look like a regular LFN after lfn.setExternal
- if (isPathSepChar(path.charAt(path.length()-1)))
- path.remove(path.length()-1, 1);
- lfn.setExternal(location,path);
- checkExternalFileRights(ctx,lfn,false,true);
- RemoteFilename rfn;
- rfn.setPath(ep,path);
- Owned<IFile> file = createIFile(rfn);
- file->createDirectory();
- StringBuffer s("CreateExternalDirectory ('");
- s.append(location).append(',').append(path).append(") done");
- WUmessage(ctx,SeverityInformation,NULL,s.str());
- AuditMessage(ctx,"CreateExternalDirectory",path);
- }
- FILESERVICES_API char * FILESERVICES_CALL fsfGetLogicalFileAttribute(ICodeContext * ctx,const char *_lfn,const char *attrname)
- {
- StringBuffer lfn;
- constructLogicalName(ctx, _lfn, lfn);
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(lfn.str(),udesc, AccessMode::tbdRead,false, false, nullptr, defaultPrivilegedUser);
- StringBuffer ret;
- if (df) {
- if (strcmp(attrname,"ECL")==0)
- df->getECL(ret);
- else if (strcmp(attrname,"clusterName")==0)
- df->getClusterName(0,ret);
- else if (strcmp(attrname,"partmask")==0)
- ret.append(df->queryPartMask());
- else if (strcmp(attrname,"directory")==0)
- ret.append(df->queryDefaultDir());
- else if (strcmp(attrname,"numparts")==0)
- ret.append(df->numParts());
- else if (strcmp(attrname,"name")==0)
- ret.append(df->queryLogicalName());
- else if (strcmp(attrname,"modified")==0) {
- CDateTime dt;
- df->getModificationTime(dt);
- dt.getString(ret);
- }
- else if (strcmp(attrname,"protected")==0) {
- IPropertyTree &attr = df->queryAttributes();
- Owned<IPropertyTreeIterator> piter = attr.getElements("Protect");
- ForEach(*piter) {
- const char *name = piter->query().queryProp("@name");
- if (name&&*name) {
- if (ret.length())
- ret.append(',');
- ret.append(name);
- }
- }
- }
- else {
- StringBuffer xpath("@");
- xpath.append(attrname);
- IPropertyTree &attr = df->queryAttributes();
- attr.getProp(xpath.str(),ret);
- }
- }
- else
- throw MakeStringException(0, "GetLogicalFileAttribute: Could not find logical file %s", lfn.str());
- return ret.detach();
- }
- FILESERVICES_API void FILESERVICES_CALL fsProtectLogicalFile(ICodeContext * ctx, const char *_lfn, bool set)
- {
- StringBuffer lfn;
- constructLogicalName(ctx, _lfn, lfn);
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(lfn.str(), udesc, AccessMode::tbdRead, false, false, nullptr, defaultPrivilegedUser);
- if (df)
- {
- StringBuffer uname;
- udesc->getUserName(uname);
- df->setProtect(uname, set);
- if (!set)
- {
- // for backward compatibility only (see HPCC-23190)
- uname.clear().append("user:");
- udesc->getUserName(uname);
- df->setProtect(uname, false);
- }
- }
- else if (set)
- throw MakeStringException(0, "ProtectLogicalFile: Could not find logical file %s", lfn.str());
- }
- static bool build_dfuplus_globals(int argc, const char *argv[], IProperties * globals)
- {
- for (int i = 1; i < argc; i++)
- if (strchr(argv[i],'='))
- globals->loadProp(argv[i]);
- StringBuffer tmp;
- if (globals->hasProp("encrypt")) {
- encrypt(tmp.clear(),globals->queryProp("encrypt") ); // basic encryption at this stage
- globals->setProp("encrypt",tmp.str());
- }
- if (globals->hasProp("decrypt")) {
- encrypt(tmp.clear(),globals->queryProp("decrypt") ); // basic encryption at this stage
- globals->setProp("decrypt",tmp.str());
- }
- return true;
- }
- FILESERVICES_API void FILESERVICES_CALL fsDfuPlusExec(ICodeContext * ctx,const char *_cmd)
- {
- if (!_cmd||!*_cmd)
- return;
- MemoryBuffer mb;
- const char **argv;
- StringBuffer cmdline;
- if (strcmp(_cmd,"dfuplus ")!=0)
- cmdline.append("dfuplus ");
- cmdline.append(_cmd);
- int argc = parseCommandLine(cmdline.str(),mb,argv);
- Owned<IProperties> globals = createProperties(true);
- if (!build_dfuplus_globals(argc, argv, globals))
- throw MakeStringException(-1,"DfuPlusExec: invalid command line");
- const char* server = globals->queryProp("server");
- if (!server || !*server)
- throw MakeStringException(-1,"DfuPlusExec: server url not specified");
- const char* action = globals->queryProp("action");
- if (!action || !*action)
- throw MakeStringException(-1,"DfuPlusExec: no action specified");
- if (ctx) {
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- StringBuffer tmp;
- const char* username = globals->queryProp("username");
- if (!username || !*username)
- globals->setProp("username",udesc->getUserName(tmp.clear()).str());;
- const char* passwd = globals->queryProp("password");
- if (!passwd || !*passwd)
- globals->setProp("password",udesc->getPassword(tmp.clear()).str());;
- }
- class cMsg: implements CDfuPlusMessagerIntercept
- {
- ICodeContext * ctx;
- unsigned limit;
- public:
- cMsg(ICodeContext *_ctx)
- {
- limit = 0;
- ctx = _ctx;
- }
- void info(const char *msg)
- {
- if (ctx&&(++limit<100))
- WUmessage(ctx,SeverityInformation,NULL,msg);
- }
- void err(const char *msg)
- {
- throw MakeStringException(-1,"DfuPlusExec: %s",msg);
- }
- } cmsg(ctx);
- try {
- Owned<CDfuPlusHelper> helper = new CDfuPlusHelper(LINK(globals.get()));
- helper->msgintercept = &cmsg;
- helper->doit();
- }
- catch(IException* e) {
- EXCLOG(e,"fsDfuPlusExec");
- throw;
- }
- }
- FILESERVICES_API char * FILESERVICES_CALL fsGetEspURL(const char *username, const char *userPW)
- {
- #ifdef _CONTAINERIZED
- const IPropertyTree *match = nullptr;
- const char *espService = getComponentConfigSP()->queryProp("@defaultEsp");
- Owned<IPropertyTree> globalConfig = getGlobalConfig();
- if (isEmptyString(espService))
- espService = globalConfig->queryProp("@defaultEsp");
- if (!isEmptyString(espService))
- {
- VStringBuffer service("services[@name='%s']", espService);
- match = globalConfig->queryPropTree(service.str());
- }
- if (!match)
- {
- // Look for 'eclservices' esp service, fallback to 'eclwatch' service.
- Owned<IPropertyTreeIterator> iter = globalConfig->getElements("services");
- ForEach(*iter)
- {
- const char *type = iter->query().queryProp("@type");
- if (streq("eclservices", type))
- {
- match = &iter->query();
- break;
- }
- else if (streq("eclwatch", type))
- match = &iter->query();
- }
- }
- if (match) // MORE - if not found, we could generate a warning - it implies something misconfigured!
- {
- if (!espService)
- espService = match->queryProp("@name");
- StringBuffer credentials;
- if (username && username[0] && userPW && userPW[0])
- credentials.setf("%s:%s@", username, userPW);
- else if (username && username[0])
- credentials.setf("%s@", username);
- const char *protocol = match->getPropBool("@tls") ? "https" : "http";
- unsigned port = match->getPropInt("@port", 8010);
- VStringBuffer espURL("mtls:%s://%s%s:%u", protocol, credentials.str(), espService, port);
- return espURL.detach();
- }
- #else
- Owned<IConstEnvironment> daliEnv = openDaliEnvironment();
- Owned<IPropertyTree> env = getEnvironmentTree(daliEnv);
- if (env.get())
- {
- StringBuffer espURL;
- StringBuffer espInstanceComputerName;
- StringBuffer bindingProtocol;
- StringBuffer xpath;
- StringBuffer instanceAddress;
- StringBuffer espServiceType;
- StringBuffer credentials;
- Owned<IPropertyTreeIterator> espProcessIter = env->getElements("Software/EspProcess");
- ForEach(*espProcessIter)
- {
- Owned<IPropertyTreeIterator> espBindingIter = espProcessIter->query().getElements("EspBinding");
- ForEach(*espBindingIter)
- {
- espBindingIter->query().getProp("@service",espURL.clear());
- xpath.setf("Software/EspService[@name=\"%s\"]/Properties/@type", espURL.str());
- if(env->getProp(xpath.str(), espServiceType.clear()))
- {
- if (strieq(espServiceType.str(),"WsSMC"))
- {
- if (espBindingIter->query().getProp("@protocol",bindingProtocol.clear()))
- {
- Owned<IPropertyTreeIterator> espInstanceIter = espProcessIter->query().getElements("Instance");
- ForEach(*espInstanceIter)
- {
- if (espInstanceIter->query().getProp("@computer",espInstanceComputerName.clear()))
- {
- xpath.setf("Hardware/Computer[@name=\"%s\"]/@netAddress",espInstanceComputerName.str());
- if (env->getProp(xpath.str(),instanceAddress.clear()))
- {
- if (username && username[0] && userPW && userPW[0])
- credentials.setf("%s:%s@", username, userPW);
- else if (username && username[0])
- credentials.setf("%s@", username);
- if (streq(instanceAddress.str(),"."))
- {
- SocketEndpoint ep(instanceAddress.str());
- ep.getIpText(instanceAddress.clear());
- }
- espURL.setf("%s://%s%s:%d", bindingProtocol.str(), credentials.str(), instanceAddress.str(), espBindingIter->query().getPropInt("@port",8010));
- return espURL.detach();
- }
- }
- }
- }
- }
- }
- }
- }
- }
- #endif
- return strdup("");
- }
- FILESERVICES_API char * FILESERVICES_CALL fsGetDefaultDropZone()
- {
- StringBuffer dropZonePath;
- Owned<IPropertyTreeIterator> dropZones = getGlobalConfigSP()->getElements("storage/planes[@category='lz']");
- if (dropZones->first())
- dropZones->query().getProp("@prefix", dropZonePath); // Why the directory? seems a very stange choice
- return strdup(dropZonePath.str());
- }
- FILESERVICES_API void FILESERVICES_CALL fsGetDropZones(ICodeContext *ctx, size32_t & __lenResult, void * & __result)
- {
- MemoryBuffer mb;
- Owned<IPropertyTreeIterator> dropZones = getGlobalConfigSP()->getElements("storage/planes[@category='lz']");
- ForEach(*dropZones)
- {
- const char * directory = dropZones->query().queryProp("@prefix");
- size32_t sz = strlen(directory);
- mb.append(sz).append(sz,directory);
- }
- __lenResult = mb.length();
- __result = mb.detach();
- }
- FILESERVICES_API void FILESERVICES_CALL fsGetLandingZones(ICodeContext *ctx, size32_t & __lenResult, void * & __result)
- {
- MemoryBuffer mb;
- size32_t sz;
- Owned<IPropertyTree> global = getGlobalConfig();
- Owned<IPropertyTreeIterator> dropZones = global->getElements("storage/planes[labels='lz']");
- ForEach(*dropZones)
- {
- const IPropertyTree &dropZone = dropZones->query();
- const char * name = dropZone.queryProp("@name");
- const char * directory = dropZone.queryProp("@prefix");
- const char * hostGroup = dropZone.queryProp("@hostGroup");
- // field "name"
- sz = strlen(name);
- mb.append(sz).append(sz,name);
- // field "prefix"
- sz = strlen(directory);
- mb.append(sz).append(sz,directory);
- // field "host"
- const char * host = nullptr;
- if (hostGroup)
- {
- VStringBuffer xpath("storage/hostGroups[@name='%s']", name);
- IPropertyTree * match = global->queryPropTree(xpath);
- if (match)
- host = match->queryProp("hosts[1]");
- }
- sz = host ? strlen(host) : 0;
- mb.append(sz).append(sz, host);
- }
- __lenResult = mb.length();
- __result = mb.detach();
- }
- FILESERVICES_API int FILESERVICES_CALL fsGetExpireDays(ICodeContext * ctx, const char *_lfn)
- {
- StringBuffer lfn;
- constructLogicalName(ctx, _lfn, lfn);
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(lfn.str(),udesc, AccessMode::tbdRead,false, false, nullptr, defaultPrivilegedUser);
- if (df)
- return df->getExpire();
- else
- throw makeStringExceptionV(0, "GetExpireDays: Could not find logical file %s", lfn.str());
- }
- FILESERVICES_API void FILESERVICES_CALL fsSetExpireDays(ICodeContext * ctx, const char *_lfn, int expireDays)
- {
- if (expireDays < 0)
- throw makeStringExceptionV(0, "SetExpireDays: expireDays parameter value should be >= 0 (%d)", expireDays);
- StringBuffer lfn;
- constructLogicalName(ctx, _lfn, lfn);
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(lfn.str(),udesc, AccessMode::tbdRead,false, false, nullptr, defaultPrivilegedUser);
- if (df)
- df->setExpire(expireDays);
- else
- throw makeStringExceptionV(0, "SetExpireDays: Could not find logical file %s", lfn.str());
- }
- FILESERVICES_API void FILESERVICES_CALL fsClearExpireDays(ICodeContext * ctx, const char *_lfn)
- {
- StringBuffer lfn;
- constructLogicalName(ctx, _lfn, lfn);
- Linked<IUserDescriptor> udesc = ctx->queryUserDescriptor();
- Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(lfn.str(),udesc, AccessMode::tbdRead,false, false, nullptr, defaultPrivilegedUser);
- if (df)
- df->setExpire(-1);
- else
- throw makeStringExceptionV(0, "ClearExpireDays: Could not find logical file %s", lfn.str());
- }
|