Skip to content

Commit

Permalink
HPCC-31394 WsSMC send roxie control cmd to ssl port if available
Browse files Browse the repository at this point in the history
Rather than default to port 9876, use the roxie farmer ports configured
for sending control messages to. Prefer an ssl port if available.

Signed-off-by: Terrence Asselin <[email protected]>
  • Loading branch information
asselitx committed Mar 11, 2024
1 parent 5e4061f commit 1484215
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 6 deletions.
14 changes: 8 additions & 6 deletions esp/services/ws_smc/ws_smcService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ void CWsSMCEx::init(IPropertyTree *cfg, const char *process, const char *service

#ifdef _CONTAINERIZED
initContainerRoxieTargets(roxieConnMap);
#else
initBareMetalRoxieTargets(roxieConnMap);
#endif

xpath.setf("Software/EspProcess[@name=\"%s\"]/EspService[@name=\"%s\"]/ActivityInfoCacheSeconds", process, service);
Expand Down Expand Up @@ -2305,18 +2307,18 @@ bool CWsSMCEx::onRoxieControlCmd(IEspContext &context, IEspRoxieControlCmdReques
if (isEmptyString(process))
throw makeStringException(ECLWATCH_MISSING_PARAMS, "Process cluster not specified.");

SocketEndpointArray addrs;
getRoxieProcessServers(process, addrs);
if (!addrs.length())
throw makeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Process cluster not found.");
Owned<IPropertyTree> controlResp = sendRoxieControlAllNodes(addrs.item(0), controlReq, true, req.getWait());
ISmartSocketFactory *conn = roxieConnMap.getValue(process);
if (!conn)
throw makeStringExceptionV(ECLWATCH_CANNOT_GET_ENV_INFO, "Connection info for '%s' process cluster not found.", process);

Owned<IPropertyTree> controlResp = sendRoxieControlAllNodes(conn, controlReq, true, req.getWait(), ROXIECONNECTIONTIMEOUT);
#else
const char *target = req.getTargetCluster();
if (isEmptyString(target))
target = req.getProcessCluster(); //backward compatible
if (isEmptyString(target))
throw makeStringException(ECLWATCH_MISSING_PARAMS, "Target cluster not specified.");

ISmartSocketFactory *conn = roxieConnMap.getValue(target);
if (!conn)
throw makeStringExceptionV(ECLWATCH_CANNOT_GET_ENV_INFO, "roxie target cluster not mapped: %s", target);
Expand Down
5 changes: 5 additions & 0 deletions esp/smc/SMCLib/TpContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,11 @@ extern TPWRAPPER_API void initContainerRoxieTargets(MapStringToMyClass<ISmartSoc
}
}

extern TPWRAPPER_API void initBareMetalRoxieTargets(MapStringToMyClass<ISmartSocketFactory>& connMap)
{
IWARNLOG("UNIMPLEMENTED: CONTAINERIZED(CTpWrapper::initBareMetalRoxieTargets)");
}

extern TPWRAPPER_API void getRoxieTargetsSupportingPublishedQueries(StringArray& names)
{
Owned<IPropertyTreeIterator> queues = getComponentConfigSP()->getElements("queues[@type='roxie']");
Expand Down
79 changes: 79 additions & 0 deletions esp/smc/SMCLib/TpWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2093,6 +2093,85 @@ extern TPWRAPPER_API void initContainerRoxieTargets(MapStringToMyClass<ISmartSoc
}
}

void appendServerAddress(StringBuffer& list, IPropertyTree& env, IPropertyTree& server, const char* farmerPort)
{
//just in case, for backward compatability with old environment.xml files, allow server rather than farmer to specify port
const char *port = server.queryProp("@port");
if (!port)
port = farmerPort;
if (port && streq(port, "0")) //0 == roxie listening on queue rather than port
return;

const char *netAddress = server.queryProp("@netAddress");
if (!netAddress && server.hasProp("@computer"))
{
VStringBuffer xpath("Hardware/Computer[@name='%s']/@netAddress", server.queryProp("@computer"));
netAddress = env.queryProp(xpath.str());
}
if (!netAddress || !*netAddress)
return;
if (list.length())
list.append('|');
list.append(netAddress).append(':').append(port);
}

class TlsSmartSocketFactory : public CSmartSocketFactory
{
public:
TlsSmartSocketFactory(const char *_socklist) : CSmartSocketFactory(_socklist)
{
tlsService = true;
}
};

extern TPWRAPPER_API void initBareMetalRoxieTargets(MapStringToMyClass<ISmartSocketFactory>& connMap)
{
Owned<IEnvironmentFactory> factory = getEnvironmentFactory(false);
Owned<IConstEnvironment> env = factory->openEnvironment();
Owned<IPropertyTree> envRoot = &env->getPTree();

Owned<IPropertyTreeIterator> roxieClusters = envRoot->getElements("Software/RoxieCluster");
ForEach(*roxieClusters)
{
IPropertyTree& roxieCluster = roxieClusters->query();
const char* name = roxieCluster.queryProp("@name");
if (isEmptyString(name))
continue;

StringBuffer addressList;
StringBuffer port("");
bool useTls = false;

Owned<IPropertyTreeIterator> roxieFarms = roxieCluster.getElements("RoxieFarmProcess");
ForEach(*roxieFarms)
{
IPropertyTree& farm = roxieFarms->query();
const char* farmPort = farm.queryProp("@port");
if (!isEmptyString(farmPort) && !streq(farmPort, "0"))
{
const char *protocol = farm.queryProp("@protocol");
if (!isEmptyString(protocol) && strieq(protocol, "ssl"))
{
port.set(farmPort);
useTls = true;
break;
}
else if (isEmptyString(port.str()))
{
port.set(farmPort);
}
}
}

Owned<IPropertyTreeIterator> roxieServers = roxieCluster.getElements("RoxieServerProcess");
ForEach(*roxieServers)
appendServerAddress(addressList, *envRoot, roxieServers->query(), port.str());

Owned<ISmartSocketFactory> sf = useTls ? new TlsSmartSocketFactory(addressList) : createSmartSocketFactory(addressList);
connMap.setValue(name, sf.get());
}
}

extern TPWRAPPER_API void getRoxieTargetsSupportingPublishedQueries(StringArray& names)
{
CConstWUClusterInfoArray clusters;
Expand Down
1 change: 1 addition & 0 deletions esp/smc/SMCLib/TpWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ extern TPWRAPPER_API IConstWUClusterInfo* getWUClusterInfoByName(const char* clu

extern TPWRAPPER_API IStringIterator *getContainerTargetClusters(const char* processType, const char* processName);
extern TPWRAPPER_API void initContainerRoxieTargets(MapStringToMyClass<ISmartSocketFactory>& connMap);
extern TPWRAPPER_API void initBareMetalRoxieTargets(MapStringToMyClass<ISmartSocketFactory>& connMap);
extern TPWRAPPER_API unsigned getThorClusterNames(StringArray& targetNames, StringArray& queueNames);
extern TPWRAPPER_API void getRoxieTargetsSupportingPublishedQueries(StringArray& names);
extern TPWRAPPER_API void validateTargetName(const char* target);
Expand Down

0 comments on commit 1484215

Please sign in to comment.