Commit 6e98773e authored by Volodymyr Yurchenko's avatar Volodymyr Yurchenko
Browse files

JAL-80 #comment Try to read JBox host and port from env

parent 81773c66
......@@ -101,12 +101,31 @@ void TJAlienConnectionManager::clearFlags()
//______________________________________________________________________________
void TJAlienConnectionManager::ConnectJBox(TJAlienCredentialsObject c)
{
TJClientFile jcf;
if (jcf.isValid) {
MakeWebsocketConnection(c, (std::string)jcf.fHost, jcf.fWSPort);
} else {
if (gDebug >= 1) Info("TJAlienConnectionManager", "The JClient file is not valid - not connecting to JBox!");
std::string jboxHost = "";
int jboxPort = 0;
// Try to load host and port env vars
std::string envHost = getenv("JALIEN_HOST");
int envPort = atoi(getenv("JALIEN_WSPORT"));
if (envHost != NULL && envHost.length() != 0 && envPort > 0) {
jboxHost = envHost;
jboxPort = envPort;
}
else {
// Try to find jclient_token file
TJClientFile jcf;
if (jcf.isValid) {
jboxHost = (std::string)jcf.fHost;
jboxPort = jcf.fWSPort;
}
else if (gDebug >= 1) Info("TJAlienConnectionManager", "The JClient file is not valid - not connecting to JBox!");
}
if (jboxHost.length() == 0 || envPort == 0) {
if (gDebug >= 1) Info("TJAlienConnectionManager", "Failed to find any local JBox endpoint");
return;
}
MakeWebsocketConnection(c, jboxHost, jboxPort);
}
void TJAlienConnectionManager::ConnectJCentral(TJAlienCredentialsObject c, string host)
......@@ -446,7 +465,7 @@ json_object *TJAlienConnectionManager::CreateJsonCommand(TString *command, TList
//______________________________________________________________________________
TJAlienResult *TJAlienConnectionManager::RunJsonCommand(TString *command, TList *opt)
{
return RunJsonCommand(command, opt, nullptr, nullptr);
return RunJsonCommand(command, opt, nullptr, nullptr);
}
//______________________________________________________________________________
......@@ -490,26 +509,26 @@ TJAlienResult *TJAlienConnectionManager::RunJsonCommand(TString *command, TList
// get response
TJAlienResult *GridResult = this->GetCommandResult(jobj_res, *command == "find");
if (readBuffer)
(*readBuffer) = this->readBuffer;
if (metadata) {
// Extract the username, current directory, host and port
// immediately after each command, since it could change
(*metadata)["fHost"] = fWSHost;
(*metadata)["fPort"] = fWSPort;
if (GridResult) {
TObjString u("user");
TObjString* sUserMetadata = GridResult->GetMetaData(&u);
if (sUserMetadata) {
(*metadata)["fUser"] = sUserMetadata->GetString();
}
TObjString c("currentdir");
TObjString* sPwdMetadata = GridResult->GetMetaData(&c);
if (sPwdMetadata) {
(*metadata)["fPwd"] = sPwdMetadata->GetString();
}
}
}
(*readBuffer) = this->readBuffer;
if (metadata) {
// Extract the username, current directory, host and port
// immediately after each command, since it could change
(*metadata)["fHost"] = fWSHost;
(*metadata)["fPort"] = fWSPort;
if (GridResult) {
TObjString u("user");
TObjString* sUserMetadata = GridResult->GetMetaData(&u);
if (sUserMetadata) {
(*metadata)["fUser"] = sUserMetadata->GetString();
}
TObjString c("currentdir");
TObjString* sPwdMetadata = GridResult->GetMetaData(&c);
if (sPwdMetadata) {
(*metadata)["fPwd"] = sPwdMetadata->GetString();
}
}
}
return GridResult;
}
......
......@@ -73,7 +73,7 @@ bool TJClientFile::loadFile(const char *filepath) {
{
fHost = sValue;
if (fHost == nullptr || fHost.Length() == 0)
if (fHost == NULL || fHost.Length() == 0)
{
Error("TJAlien", "JAliEn connection host field empty");
result = false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment