Skip to content

Commit

Permalink
Merge pull request #18172 from wangkx/h30900
Browse files Browse the repository at this point in the history
HPCC-30900 Add ListWU to ESP WSSasha service

Reviewed-by: Jake Smith <[email protected]>
Merged-by: Gavin Halliday <[email protected]>
  • Loading branch information
ghalliday authored Jan 19, 2024
2 parents fd4256f + f78fb65 commit caa7c5c
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 1 deletion.
67 changes: 67 additions & 0 deletions dali/sasha/saruncmd.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "platform.h"
#include "jlib.hpp"
#include "jfile.hpp"
#include "mpbase.hpp"
#include "sacmd.hpp"
#include "saruncmd.hpp"
Expand Down Expand Up @@ -46,6 +47,64 @@ class CSashaCmdExecutor : public CInterfaceOf<ISashaCmdExecutor>
cmd->getId(0, lastServerMessage);
return true;
}
bool listWorkunit(ListWURequests *req, bool dfu) const
{
lastServerMessage.clear();
Owned<ISashaCommand> cmd = createSashaCommand();
cmd->setAction(req->includeDT ? SCA_LISTDT : SCA_LIST);
if (dfu)
cmd->setDFU(true);
cmd->setArchived(req->archived);
cmd->setOnline(req->online);
if (!req->outputFields.isEmpty())
cmd->setOutputFormat(req->outputFields);

cmd->addId(req->wuid.isEmpty() ? "*" : req->wuid.get());
if (!req->cluster.isEmpty())
cmd->setCluster(req->cluster.get());
if (!req->owner.isEmpty())
cmd->setOwner(req->owner.get());
if (!req->jobName.isEmpty())
cmd->setJobName(req->jobName.get());
if (!req->state.isEmpty())
cmd->setState(req->state.get());

if (!req->fromDate.isEmpty())
cmd->setAfter(req->fromDate.str()); //In CArchivedWUReader, the After is used as fromDate.
if (!req->toDate.isEmpty())
cmd->setBefore(req->toDate.str()); //In CArchivedWUReader, the Before is used as toDate.

if (!req->beforeWU.isEmpty())
cmd->setBeforeWU(req->beforeWU.get());
if (!req->afterWU.isEmpty())
cmd->setAfterWU(req->afterWU.get());
cmd->setLimit(req->maxNumberWUs);
cmd->setSortDescending(req->descending);
if (!cmd->send(node, defaultTimeoutMs))
throw makeStringExceptionV(-1, "Could not connect to Sasha server on %s", nodeText.str());

unsigned n = cmd->numIds();
if (n == 0)
{
// no workunit found
return false;
}

for (unsigned i = 0; i < n; i++)
{
cmd->getId(i, lastServerMessage);
if (req->includeDT)
{
CDateTime dt;
cmd->getDT(dt, i);
lastServerMessage.append(",");
dt.getString(lastServerMessage);
}
lastServerMessage.append("\n");
}
lastServerMessage.appendf("%d WUID%s returned\n", n, (n == 1) ? "" : "s");
return true;
}

public:
CSashaCmdExecutor(const SocketEndpoint &ep, unsigned _defaultTimeoutSecs = 60)
Expand Down Expand Up @@ -93,6 +152,14 @@ class CSashaCmdExecutor : public CInterfaceOf<ISashaCmdExecutor>
{
return archiveWorkunit(wuid, true, false);
}
virtual bool listECLWorkUnit(ListWURequests *req) const override
{
return listWorkunit(req, false);
}
virtual bool listDFUWorkUnit(ListWURequests *req) const override
{
return listWorkunit(req, true);
}
};

ISashaCmdExecutor *createSashaCmdExecutor(const SocketEndpoint &ep, unsigned defaultTimeoutSecs)
Expand Down
16 changes: 16 additions & 0 deletions dali/sasha/saruncmd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
#define SARUNCMD_API DECL_IMPORT
#endif

class SARUNCMD_API ListWURequests : public CSimpleInterfaceOf<IInterface>
{
public:
ListWURequests(const char *_outputFields, bool _archived, bool _online)
: outputFields(_outputFields), archived(_archived), online(_online) {};

StringAttr wuid, cluster, owner, jobName, state, outputFields;
StringAttr beforeWU, afterWU;
StringBuffer fromDate, toDate;
bool archived = false, online = false, includeDT = false;
unsigned maxNumberWUs = 500;
bool descending = false;
};

interface ISashaCmdExecutor : extends IInterface
{
virtual StringBuffer &getVersion(StringBuffer &version) const = 0;
Expand All @@ -17,6 +31,8 @@ interface ISashaCmdExecutor : extends IInterface
virtual bool archiveDFUWorkUnit(const char *wuid) const = 0;
virtual bool backupECLWorkUnit(const char *wuid) const = 0;
virtual bool backupDFUWorkUnit(const char *wuid) const = 0;
virtual bool listECLWorkUnit(ListWURequests *req) const = 0;
virtual bool listDFUWorkUnit(ListWURequests *req) const = 0;
};

extern SARUNCMD_API ISashaCmdExecutor *createSashaCmdExecutor(const SocketEndpoint &ep, unsigned defaultTimeoutSecs=60);
Expand Down
25 changes: 24 additions & 1 deletion esp/scm/ws_sasha.ecm
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,35 @@ ESPrequest [nil_remove] RestoreWURequest
ESPenum WUTypes WUType;
};

ESPrequest [nil_remove] ListWURequest
{
ESPenum WUTypes WUType;
string Wuid;
string Cluster;
string Owner;
string JobName;
string State;
string FromDate;
string ToDate;

bool Archived(false);
bool Online(false);

bool IncludeDT(false);
string BeforeWU;
string AfterWU;
unsigned MaxNumberWUs(500);
bool Descending(false);
string OutputFields; //example: Cluster,State
};

ESPservice [auth_feature("DEFERRED"), //This declares that the method logic handles feature level authorization
version("1.00"), default_client_version("1.00"), exceptions_inline("./smc_xslt/exceptions.xslt")] WSSasha
version("1.01"), default_client_version("1.01"), exceptions_inline("./smc_xslt/exceptions.xslt")] WSSasha
{
ESPmethod [auth_feature("SashaAccess:Access")] GetVersion(GetVersionRequest, ResultResponse);
ESPmethod [auth_feature("SashaAccess:FULL")] ArchiveWU(ArchiveWURequest, ResultResponse); //archive ECL WUs or DFU WUs
ESPmethod [auth_feature("SashaAccess:FULL")] RestoreWU(RestoreWURequest, ResultResponse); //restore ECL WUs or DFU WUs
ESPmethod [auth_feature("SashaAccess:READ"), min_ver("1.01")] ListWU(ListWURequest, ResultResponse); //list ECL WUs or DFU WUs in Archive server.
};

SCMexportdef(WSSasha);
Expand Down
61 changes: 61 additions & 0 deletions esp/services/ws_sasha/ws_sashaservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,64 @@ bool CWSSashaEx::onRestoreWU(IEspContext& context, IEspRestoreWURequest& req, IE
}
return true;
}

bool CWSSashaEx::onListWU(IEspContext& context, IEspListWURequest& req, IEspResultResponse& resp)
{
try
{
context.ensureFeatureAccess(FEATURE_URL, SecAccess_Read, ECLWATCH_SASHA_ACCESS_DENIED, "WSSashaEx.ListWU: Permission denied.");

Owned<ListWURequests> listWURequests = new ListWURequests(req.getOutputFields(), req.getArchived(), req.getOnline());
const char* wuid = req.getWuid();
listWURequests->wuid.set(wuid);
listWURequests->cluster.set(req.getCluster());
listWURequests->owner.set(req.getOwner());
listWURequests->jobName.set(req.getJobName());
listWURequests->state.set(req.getState());
normalizeDateReq(req.getFromDate(), listWURequests->fromDate);
normalizeDateReq(req.getToDate(), listWURequests->toDate);
listWURequests->includeDT = req.getIncludeDT();
listWURequests->beforeWU.set(req.getBeforeWU());
listWURequests->afterWU.set(req.getAfterWU());
listWURequests->maxNumberWUs = req.getMaxNumberWUs();
listWURequests->descending = req.getDescending();

CWUTypes wuType = req.getWUType();
ISashaCmdExecutor* executor = querySashaCommandExecutor(wuType);

bool sashaCmdSuccess = false;
if ((wuType == CWUTypes_ECL))
sashaCmdSuccess = executor->listECLWorkUnit(listWURequests);
else
sashaCmdSuccess = executor->listDFUWorkUnit(listWURequests);
if (sashaCmdSuccess)
setSuccess(executor, resp);
else
setFailure(wuid, "found", resp);
}
catch(IException* e)
{
FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
}

return true;
}

void CWSSashaEx::normalizeDateReq(const char* dateString, StringBuffer& date)
{
if (isEmptyString(dateString))
return;

if (strlen(dateString) == 8)
{ //Assuming the dateString is in YYYYMMDD format
date.set(dateString);
return;
}

CDateTime dt;
dt.setString(dateString);

unsigned year, month, day, hour, minute, second, nano;
dt.getDate(year, month, day, true);
date.setf("%04d%02d%02d", year, month, day);
}
2 changes: 2 additions & 0 deletions esp/services/ws_sasha/ws_sashaservice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ class CWSSashaEx : public CWSSasha
ISashaCmdExecutor* querySashaCommandExecutor(CWUTypes wuType);
void setSuccess(ISashaCmdExecutor* executor, IEspResultResponse& resp);
void setFailure(const char* wuid, const char* action, IEspResultResponse& resp);
void normalizeDateReq(const char* dateString, StringBuffer& date);

public:
virtual void init(IPropertyTree* cfg, const char* process, const char* service) override;
virtual bool onGetVersion(IEspContext& context, IEspGetVersionRequest& req, IEspResultResponse& resp) override;
virtual bool onArchiveWU(IEspContext& context, IEspArchiveWURequest& req, IEspResultResponse& resp) override;
virtual bool onRestoreWU(IEspContext& context, IEspRestoreWURequest& req, IEspResultResponse& resp) override;
virtual bool onListWU(IEspContext& context, IEspListWURequest& req, IEspResultResponse& resp) override;
};

#endif //_ESPWIZ_ws_sasha_HPP__

0 comments on commit caa7c5c

Please sign in to comment.