-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HPCC-30809 Add GetVersion/Archive/Restore
Signed-off-by: wangkx <[email protected]>
- Loading branch information
wangkx
committed
Dec 7, 2023
1 parent
c6bbbeb
commit 9399d71
Showing
9 changed files
with
391 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
################################################################################ | ||
# HPCC SYSTEMS software Copyright (C) 2023 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. | ||
################################################################################ | ||
|
||
|
||
# Component: saruncmdlib | ||
##################################################### | ||
# Description: | ||
# ------------ | ||
# Cmake Input File for saruncmdlib | ||
##################################################### | ||
|
||
project( saruncmdlib ) | ||
|
||
set ( SRCS | ||
sacmd.cpp | ||
saruncmd.cpp | ||
) | ||
|
||
include_directories ( | ||
. | ||
${HPCC_SOURCE_DIR}/system/mp | ||
${HPCC_SOURCE_DIR}/system/include | ||
${HPCC_SOURCE_DIR}/system/jlib | ||
) | ||
|
||
ADD_DEFINITIONS ( -D_USRDLL -DSASHACLI_API_EXPORTS ) | ||
|
||
HPCC_ADD_LIBRARY( saruncmdlib SHARED ${SRCS} ) | ||
install ( TARGETS saruncmdlib RUNTIME DESTINATION ${EXEC_DIR} LIBRARY DESTINATION ${LIB_DIR} ) | ||
target_link_libraries ( saruncmdlib | ||
jlib | ||
mp | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#include "platform.h" | ||
#include "jlib.hpp" | ||
#include "mpbase.hpp" | ||
#include "sacmd.hpp" | ||
#include "saruncmd.hpp" | ||
|
||
class CSashaCmdExecutor : implements ISashaCmdExecutor, public CInterface | ||
{ | ||
Linked<INode> node; | ||
unsigned defaultTimeoutMs = 60; | ||
StringBuffer nodeText; | ||
const char *getNodeText() | ||
{ | ||
if (0==nodeText.length()) | ||
node->endpoint().getEndpointHostText(nodeText); | ||
return nodeText; | ||
} | ||
bool restoreWorkunit(const char *wuid, bool dfu, StringBuffer &serverResponse) | ||
{ | ||
Owned<ISashaCommand> cmd = createSashaCommand(); | ||
cmd->setAction(SCA_RESTORE); | ||
if (dfu) | ||
cmd->setDFU(true); | ||
cmd->addId(wuid); | ||
if (!cmd->send(node, defaultTimeoutMs)) | ||
throw makeStringExceptionV(-1, "Could not connect to Sasha server on %s", getNodeText()); | ||
if (cmd->numIds()==0) | ||
{ | ||
// nothing restored | ||
return false; | ||
} | ||
cmd->getId(0, serverResponse); | ||
return true; | ||
} | ||
bool archiveWorkunit(const char *wuid, bool dfu, bool deleteAfterArchiving, StringBuffer &serverResponse) | ||
{ | ||
Owned<ISashaCommand> cmd = createSashaCommand(); | ||
cmd->setAction(SCA_ARCHIVE); | ||
if (dfu) | ||
cmd->setDFU(true); | ||
cmd->addId(wuid); | ||
if (!cmd->send(node, defaultTimeoutMs)) | ||
throw makeStringExceptionV(-1, "Could not connect to Sasha server on %s", getNodeText()); | ||
if (cmd->numIds()==0) | ||
{ | ||
// nothing archived | ||
return false; | ||
} | ||
cmd->getId(0, serverResponse); | ||
return true; | ||
} | ||
|
||
public: | ||
IMPLEMENT_IINTERFACE; | ||
CSashaCmdExecutor(INode *_node, unsigned _defaultTimeoutSecs=60) : node(_node) | ||
{ | ||
defaultTimeoutMs = _defaultTimeoutSecs * 1000; | ||
} | ||
CSashaCmdExecutor(const SocketEndpoint &ep, unsigned _defaultTimeoutSecs = 60) | ||
{ | ||
node.setown(createINode(ep)); | ||
defaultTimeoutMs = _defaultTimeoutSecs * 1000; | ||
} | ||
CSashaCmdExecutor(const char *server, unsigned port=0, unsigned _defaultTimeoutSecs = 60) | ||
{ | ||
SocketEndpoint ep(server, port); | ||
node.setown(createINode(ep)); | ||
defaultTimeoutMs = _defaultTimeoutSecs * 1000; | ||
} | ||
StringBuffer &getVersion(StringBuffer &version) | ||
{ | ||
Owned<ISashaCommand> cmd = createSashaCommand(); | ||
cmd->setAction(SCA_GETVERSION); | ||
if (!cmd->send(node, defaultTimeoutMs)) | ||
throw makeStringExceptionV(-1, "Could not connect to Sasha server on %s", getNodeText()); | ||
if (!cmd->getId(0, version)) | ||
throw makeStringExceptionV(-1, "Sasha server[%s]: Protocol error", getNodeText()); | ||
return version; | ||
} | ||
bool restoreECLWorkUnit(const char *wuid, StringBuffer &serverResponse) | ||
{ | ||
return restoreWorkunit(wuid, false, serverResponse); | ||
} | ||
bool restoreDFUWorkUnit(const char *wuid, StringBuffer &serverResponse) | ||
{ | ||
return restoreWorkunit(wuid, true, serverResponse); | ||
} | ||
bool archiveECLWorkUnit(const char *wuid, StringBuffer &serverResponse) | ||
{ | ||
return archiveWorkunit(wuid, false, true, serverResponse); | ||
} | ||
bool archiveDFUWorkUnit(const char *wuid, StringBuffer &serverResponse) | ||
{ | ||
return archiveWorkunit(wuid, true, true, serverResponse); | ||
} | ||
bool backupECLWorkUnit(const char *wuid, StringBuffer &serverResponse) | ||
{ | ||
return archiveWorkunit(wuid, true, false, serverResponse); | ||
} | ||
bool backupDFUWorkUnit(const char *wuid, StringBuffer &serverResponse) | ||
{ | ||
return archiveWorkunit(wuid, true, false, serverResponse); | ||
} | ||
}; | ||
|
||
ISashaCmdExecutor *createSashaCmdExecutor(INode *node, unsigned defaultTimeoutSecs) | ||
{ | ||
return new CSashaCmdExecutor(node, defaultTimeoutSecs); | ||
} | ||
|
||
ISashaCmdExecutor *createSashaCmdExecutor(const SocketEndpoint &ep, unsigned defaultTimeoutSecs) | ||
{ | ||
return new CSashaCmdExecutor(ep, defaultTimeoutSecs); | ||
} | ||
|
||
ISashaCmdExecutor *createSashaCmdExecutor(const char *server, unsigned port, unsigned defaultTimeoutSecs) | ||
{ | ||
return new CSashaCmdExecutor(server, port, defaultTimeoutSecs); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef SARUNCMD_HPP | ||
#define SARUNCMD_HPP | ||
|
||
#ifdef SARUNCMD_API_EXPORTS | ||
#define SARUNCMD_API DECL_EXPORT | ||
#else | ||
#define SARUNCMD_API DECL_IMPORT | ||
#endif | ||
|
||
interface ISashaCmdExecutor : extends IInterface | ||
{ | ||
virtual StringBuffer &getVersion(StringBuffer &version) = 0; | ||
virtual bool restoreECLWorkUnit(const char *wuid, StringBuffer &serverResponse) = 0; | ||
virtual bool restoreDFUWorkUnit(const char *wuid, StringBuffer &serverResponse) = 0; | ||
virtual bool archiveECLWorkUnit(const char *wuid, StringBuffer &serverResponse) = 0; | ||
virtual bool archiveDFUWorkUnit(const char *wuid, StringBuffer &serverResponse) = 0; | ||
virtual bool backupECLWorkUnit(const char *wuid, StringBuffer &serverResponse) = 0; | ||
virtual bool backupDFUWorkUnit(const char *wuid, StringBuffer &serverResponse) = 0; | ||
}; | ||
|
||
extern SARUNCMD_API ISashaCmdExecutor *createSashaCmdExecutor(INode *node, unsigned defaultTimeoutSecs=60); | ||
extern SARUNCMD_API ISashaCmdExecutor *createSashaCmdExecutor(const SocketEndpoint &ep, unsigned defaultTimeoutSecs=60); | ||
extern SARUNCMD_API ISashaCmdExecutor *createSashaCmdExecutor(const char *server, unsigned port=0, unsigned defaultTimeoutSecs=60); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/*############################################################################## | ||
|
||
HPCC SYSTEMS software Copyright (C) 2023 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. | ||
############################################################################## */ | ||
|
||
EspInclude(common); | ||
|
||
ESPenum WUTypes : string | ||
{ | ||
ECL("ECL"), | ||
DFU("DFU"), | ||
}; | ||
|
||
ESPrequest [nil_remove] GetVersionRequest | ||
{ | ||
}; | ||
|
||
ESPresponse [exceptions_inline, nil_remove] ResultResponse | ||
{ | ||
string Result; | ||
}; | ||
|
||
ESPrequest [nil_remove] BackupWURequest | ||
{ | ||
string Wuid; | ||
ESPenum WUTypes WUType; | ||
}; | ||
|
||
ESPrequest [nil_remove] ArchiveWURequest | ||
{ | ||
string Wuid; | ||
ESPenum WUTypes WUType; | ||
}; | ||
|
||
ESPrequest [nil_remove] RestoreWURequest | ||
{ | ||
string Wuid; | ||
ESPenum WUTypes WUType; | ||
}; | ||
|
||
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 | ||
{ | ||
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 | ||
//The ArchiveWU deletes the workunit from Dali whereas BackupWU leave it in place. | ||
ESPmethod [auth_feature("SashaAccess:FULL")] BackupWU(BackupWURequest, ResultResponse); | ||
}; | ||
|
||
SCMexportdef(WSSasha); | ||
SCMapi(WSSasha) IClientWSSasha *createWSSashaClient(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.