Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPCC-30579 Retrieve remote storage targets in ESP FileSpray #17988

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions dali/base/dautils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,21 @@ IPropertyTree * findDropZonePlane(const char * path, const char * host, bool ipM
return findPlane("lz", path, host, ipMatch, mustMatch);
}

bool allowForeign()
{
StringBuffer optValue;
// NB: component setting takes precedence over global
getComponentConfigSP()->getProp("expert/@allowForeign", optValue);
if (!optValue.isEmpty())
return strToBool(optValue);

getGlobalConfigSP()->getProp("expert/@allowForeign", optValue);
if (!optValue.isEmpty())
return strToBool(optValue);
// default denied in cloud, allowed in bare-metal
return isContainerized() ? false : true;
}

extern da_decl const char *queryDfsXmlBranchName(DfsXmlBranchKind kind)
{
switch (kind) {
Expand Down
1 change: 1 addition & 0 deletions dali/base/dautils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ extern da_decl bool isHostInPlane(IPropertyTree *plane, const char *host, bool i
extern da_decl bool getPlaneHost(StringBuffer &host, IPropertyTree *plane, unsigned which);
extern da_decl void getPlaneHosts(StringArray &hosts, IPropertyTree *plane);
extern da_decl bool isPathInPlane(IPropertyTree *plane, const char *path);
extern da_decl bool allowForeign();
extern da_decl void setPageCacheTimeoutMilliSeconds(unsigned timeoutSeconds);
extern da_decl void setMaxPageCacheItems(unsigned _maxPageCacheItems);
extern da_decl IRemoteConnection* connectXPathOrFile(const char* path, bool safe, StringBuffer& xpath);
Expand Down
21 changes: 3 additions & 18 deletions esp/clients/ws_dfsclient/ws_dfsclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,24 +807,9 @@ IDistributedFile *lookup(CDfsLogicalFileName &lfn, IUserDescriptor *user, Access
bool isForeign = false;
try { isForeign = lfn.isForeign(); }
catch(IException *e) { e->Release(); } // catch and ignore multi lfn case, will be checked later
if (isForeign)
{
// default denied in cloud, allowed in bare-metal
bool allow = isContainerized() ? false : true;
StringBuffer optValue;
// NB: component setting takes precedence over global
getComponentConfigSP()->getProp("expert/@allowForeign", optValue.clear());
if (optValue.length())
allow = strToBool(optValue);
else
{
getGlobalConfigSP()->getProp("expert/@allowForeign", optValue);
if (optValue.length())
allow = strToBool(optValue);
}
if (!allow)
throw makeStringExceptionV(0, "foreign access is not permitted from this system (file='%s')", lfn.get());
}
if (isForeign && !allowForeign())
throw makeStringExceptionV(0, "foreign access is not permitted from this system (file='%s')", lfn.get());

// DFS service currently only supports remote files
if (isWrite(accessMode))
viaDali = true;
Expand Down
13 changes: 12 additions & 1 deletion esp/scm/ws_fs.ecm
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,19 @@ ESPresponse [exceptions_inline, nil_remove] GetDFUServerQueuesResponse
ESParray<string> Names;
};

ESPrequest GetRemoteTargetsRequest
{
};

ESPresponse [exceptions_inline, nil_remove] GetRemoteTargetsResponse
{
ESParray<string> TargetNames;
bool AllowForeign;
};

ESPservice [
auth_feature("DEFERRED"),
version("1.25"),
version("1.26"),
exceptions_inline("./smc_xslt/exceptions.xslt")] FileSpray
{
ESPmethod EchoDateTime(EchoDateTime, EchoDateTimeResponse);
Expand Down Expand Up @@ -751,6 +761,7 @@ ESPservice [
ESPmethod [min_ver("1.13")] DropZoneFileSearch(DropZoneFileSearchRequest, DropZoneFileSearchResponse);
ESPmethod GetSprayTargets(GetSprayTargetsRequest, GetSprayTargetsResponse);
ESPmethod [min_ver("1.14")] GetDFUServerQueues(GetDFUServerQueuesRequest, GetDFUServerQueuesResponse);
ESPmethod [min_ver("1.26")] GetRemoteTargets(GetRemoteTargetsRequest, GetRemoteTargetsResponse);
};

SCMexportdef(FileSpray);
Expand Down
21 changes: 21 additions & 0 deletions esp/services/ws_fs/ws_fsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3818,3 +3818,24 @@ bool CFileSprayEx::onGetDFUServerQueues(IEspContext &context, IEspGetDFUServerQu

return true;
}

bool CFileSprayEx::onGetRemoteTargets(IEspContext &context, IEspGetRemoteTargetsRequest &req, IEspGetRemoteTargetsResponse &resp)
{
try
{
context.ensureFeatureAccess(FILE_SPRAY_URL, SecAccess_Read, ECLWATCH_FILE_SPRAY_ACCESS_DENIED, "Permission denied.");

StringArray remoteTargetNames;
Owned<IPropertyTreeIterator> remoteItr = getRemoteStoragesIterator();
ForEach(*remoteItr)
remoteTargetNames.append(remoteItr->query().queryProp("@name"));
resp.setTargetNames(remoteTargetNames);
resp.setAllowForeign(allowForeign());
}
catch(IException* e)
{
FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
}

return true;
}
1 change: 1 addition & 0 deletions esp/services/ws_fs/ws_fsService.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class CFileSprayEx : public CFileSpray
virtual bool onDeleteDropZoneFiles(IEspContext &context, IEspDeleteDropZoneFilesRequest &req, IEspDFUWorkunitsActionResponse &resp);
virtual bool onGetSprayTargets(IEspContext &context, IEspGetSprayTargetsRequest &req, IEspGetSprayTargetsResponse &resp);
virtual bool onGetDFUServerQueues(IEspContext &context, IEspGetDFUServerQueuesRequest &req, IEspGetDFUServerQueuesResponse &resp);
virtual bool onGetRemoteTargets(IEspContext &context, IEspGetRemoteTargetsRequest &req, IEspGetRemoteTargetsResponse &resp);

protected:
StringBuffer m_QueueLabel;
Expand Down
5 changes: 5 additions & 0 deletions system/jlib/jfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7657,6 +7657,11 @@ IPropertyTree * getRemoteStorage(const char * name)
return global->getPropTree(xpath);
}

IPropertyTreeIterator * getRemoteStoragesIterator()
{
return getGlobalConfigSP()->getElements("storage/remote");
}

IPropertyTreeIterator * getPlanesIterator(const char * category, const char *name)
{
StringBuffer xpath("storage/planes");
Expand Down
1 change: 1 addition & 0 deletions system/jlib/jfile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ interface IPropertyTreeIterator;
extern jlib_decl IPropertyTree * getHostGroup(const char * name, bool required);
extern jlib_decl IPropertyTree * getStoragePlane(const char * name);
extern jlib_decl IPropertyTree * getRemoteStorage(const char * name);
extern jlib_decl IPropertyTreeIterator * getRemoteStoragesIterator();
extern jlib_decl IPropertyTreeIterator * getPlanesIterator(const char * category, const char *name);

extern jlib_decl IFileIO *createBlockedIO(IFileIO *base, size32_t blockSize);
Expand Down
Loading