TJAlien.cxx 36.4 KB
Newer Older
Nikola Hardi's avatar
Nikola Hardi committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// @(#)root/net:$Id$
// Author: Volodymyr Yurchenko 01/12/2016

/*************************************************************************
 * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TJAlien.h"

ClassImp(TJAlien)

16
TString TJAlien::fPwd = TString("");
Nikola Hardi's avatar
Nikola Hardi committed
17

Nikola Hardi's avatar
Nikola Hardi committed
18
19
//______________________________________________________________________________
TJAlien::TJAlien (const char* gridUrl, const char* uId, const char* passwd,
20
                  const char* options)
Nikola Hardi's avatar
Nikola Hardi committed
21
{
22
23
24
25
    fGridUrl = gridUrl;
    fUser = uId;
    fPw = passwd;
    fOptions = options;
26

Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
27
28
29
    fGrid = "alien";
    gGrid = this;

30
    if (getenv("TMPDIR") != nullptr)
31
        tmpdir = getenv("TMPDIR");
32
    else if (getenv("TMP") != nullptr)
33
        tmpdir = getenv("TMP");
34
    else if (getenv("TEMP") != nullptr)
35
36
37
38
        tmpdir = getenv("TEMP");
    else
        tmpdir = P_tmpdir;

39
40
41
42
43
44
45
    Connect();
}

//______________________________________________________________________________
void TJAlien::Connect()
{
    TString oldfPwd(fPwd);
46
47
    int connection_mode = connection.CreateConnection();
    if (connection_mode == -1)
48
49
50
51
52
    {
        // Failed to connect
        // TJAlienConnectionManager will produce an error message
        return;
    }
53
    else if (connection_mode == 1)
54
55
56
    {
        // Connected to JCentral with full grid certificate
        // Immediately ask for the token
57
58
        Token("", false);
    }
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
59

60
    // Run a command to initialize gGrid variables from the metadata
61
    SetSite(gSystem->Getenv("ALIEN_SITE"));
62
63
64
65
66
67
    fHome = fPwd;

    // Change to the last known location
    if (oldfPwd.Length() != 0)
        Cd(oldfPwd.Data());
}
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
68
69
70
71

//______________________________________________________________________________
TJAlien::~TJAlien()
{
72
73
    if (gDebug > 1)
        Info("TJAlien", "Destructor called");
Nikola Hardi's avatar
Nikola Hardi committed
74
75
76
77
78
}

//______________________________________________________________________________
void TJAlien::Stderr()
{
79
80
    if (connection.readBuffer != nullptr) {
        json_object * jobj_res = json_tokener_parse(connection.readBuffer.c_str());
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
81
        // get metadata
82
        json_object *js_results;
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
83
        json_object_object_get_ex(jobj_res, "metadata", &js_results);
84

85
        if (js_results != nullptr && json_object_is_type(js_results, json_type_object))
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
86
        {
87
            TString error_stream = json_object_get_string(json_object_object_get(js_results, "error"));
88
            if (error_stream != nullptr && error_stream.Length() != 0)
89
                printf("%s\n", error_stream.Data());
90
91
        }
    }
Nikola Hardi's avatar
Nikola Hardi committed
92
93
94
95
96
}

//______________________________________________________________________________
void TJAlien::Stdout()
{
97
98
    if (connection.readBuffer != nullptr) {
        json_object * jobj_res = json_tokener_parse(connection.readBuffer.c_str());
99
        //Info("Stdout",  "%s", TJAlien::readBuffer.c_str());
100
101
102
        // get data from results
        json_object *js_results;
        json_object_object_get_ex(jobj_res, "results", &js_results);
103
        if (js_results != nullptr && json_object_is_type(js_results, json_type_array))
104
105
106
        {
            int arraylen = json_object_array_length(js_results);
            int i;
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
107
            for (i = 0; i < arraylen; i++)
108
109
            {
                json_object *jvalue = json_object_array_get_idx(js_results, i);
110
111
112
113
114
115
                json_object_object_foreach(jvalue, key, val)
                {
                    printf("%s\t", json_object_get_string(val));
                    UNUSED(key);
                }
                printf("\n");
116
117
118
            }
        }
    }
Nikola Hardi's avatar
Nikola Hardi committed
119
120
}

121
122
123
124
125
126
127
128
129
//______________________________________________________________________________
unsigned int TJAlien::ReadTags(int column, std::map<std::string, std::string> &tags) const
{
    /** Fills the key-value pairs of a response from the server into the
    the associative array @tags. @column is the column of the
    response you are interested in.
    The return value is the number of tags found.
    */
    UNUSED(column);
130
131
    if (connection.readBuffer != nullptr) {
        json_object * jobj_res = json_tokener_parse(connection.readBuffer.c_str());
132
133
134
        // get data from results
        json_object *js_results;
        json_object_object_get_ex(jobj_res, "results", &js_results);
135
        if (js_results != nullptr && json_object_is_type(js_results, json_type_array))
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
        {
            int arraylen = json_object_array_length(js_results);
            int i;
            for (i = 0; i < arraylen; i++)
            {
                Info("TJAlien", "===================");

                json_object *jvalue = json_object_array_get_idx(js_results, i);
                json_object_object_foreach(jvalue, key, val)
                {
                    tags[key] = json_object_get_string(val);
                }
            }
        }
    }

    return tags.size();
}

Nikola Hardi's avatar
Nikola Hardi committed
155
156
157
158
159
160
//______________________________________________________________________________
TGridResult *TJAlien::Command(const char *command, bool interactive, UInt_t stream)
{
    // TGrid Command method implementation
    // Command can be called directly by the user
    // Command format is one line, ex : ls -la
161
    // For internal usage follow RunJsonCommand method
Nikola Hardi's avatar
Nikola Hardi committed
162
    // Do not forget to delete the result after usage
163

164
    if (command == nullptr || std::string(command).find_first_not_of(' ') == std::string::npos)
165
166
    {
        Error("Command", "Please, specify the command");
167
        return nullptr;
168
169
    }

170
    if (interactive) Info("Command", "Received full command =\"%s\"", command);
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
171
    UNUSED(stream);
172

Nikola Hardi's avatar
Nikola Hardi committed
173
174
175
176
    TString *sCmd = new TString(command);
    TObjArray *tokens = sCmd->Tokenize(" ");
    TJAlienResult *result;

177
    connection.readBuffer = "";
Nikola Hardi's avatar
Nikola Hardi committed
178
179
180

    if (tokens->GetEntries() == 1)
    {
181
        if (interactive) Info("Command", "Received only command");
182
        result = (TJAlienResult*) connection.RunJsonCommand(sCmd, 0);
183
184
        if (result)
			TJAlienResultRewriter().Rewrite((std::string)*sCmd, result);
Nikola Hardi's avatar
Nikola Hardi committed
185
    }
186
187
    else
    {
Nikola Hardi's avatar
Nikola Hardi committed
188
189
190
        TList *options = new TList();
        TObjString *sCommand = (TObjString *) tokens->At(0);

191
192
193
        if (interactive) Info("Command", "Command = \"%s\"", sCommand->GetString().Data());
        TString opt;
        bool append = false;
194
        for (int i = 1; i < tokens->GetEntries(); i++)
Nikola Hardi's avatar
Nikola Hardi committed
195
        {
196
197
198
199
200
201
202
203
204
205
206
            TObjString *token = (TObjString *) tokens->At(i);
            if (token->GetString().Contains('\"'))
            {
                if (append) {
                    opt.Append(" ");
                    opt.Append(Strip(token->GetString().Data(), '\"'));
                    append = false;
                }
                else {
                    opt = Strip(token->GetString().Data(), '\"');
                    append = true;
207
208
209
210
                    if (i == tokens->GetEntries() - 1) {
                        Error("Command", "Invalid command. Check if you miss a matching quote");
                        return nullptr;
                    }
211
212
213
214
215
216
217
218
                    continue;
                }
            }
            else
            {
                if (append) {
                    opt.Append(" ");
                    opt.Append(token->GetString().Data());
219
220
221
222
                    if (i == tokens->GetEntries() - 1) {
                        Error("Command", "Invalid command. Check if you miss a matching quote");
                        return nullptr;
                    }
223
224
225
226
227
228
229
                    continue;
                }
                else
                    opt = token->GetString();
            }
            if (interactive) Info("Command", "Option = \"%s\"", opt.Data());
            options->Add(new TObjString(opt));
Nikola Hardi's avatar
Nikola Hardi committed
230
        }
231

Nikola Hardi's avatar
Nikola Hardi committed
232
        TString *s = new TString(sCommand->GetString());
233
        result = (TJAlienResult*) connection.RunJsonCommand(s, options);
234
235
        if (result)
			TJAlienResultRewriter().Rewrite(sCommand->GetString().Data(), result);
236

237
        if (interactive)
Nikola Hardi's avatar
Nikola Hardi committed
238
239
240
241
242
243
244
245
246
247
248
249
        {
            Stdout();
            Stderr();
        }
        delete s;

        delete options;
    }

    delete tokens;
    delete sCmd;

250
251
    if (result)
    {
252
253
        // Extract the username, current directory, host and port
        // immediately after each command, since it could change
254
255
256
        TObjString p("user");
        TObjString *sUserMetadata = result->GetMetaData(&p);
        if (sUserMetadata) {
257
258
259
260
261
262
            fUser = sUserMetadata->GetString();
        }
        TObjString k("currentdir");
        TObjString *sPwdMetadata = result->GetMetaData(&k);
        if (sPwdMetadata) {
            fPwd = result->GetMetaData(&k)->GetString();
263
        }
264
        connection.GetHostAndPort(fHost, fPort);
265
    }
266

Nikola Hardi's avatar
Nikola Hardi committed
267
268
269
    return result;
}

Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
270
//______________________________________________________________________________
271
void TJAlien::Token(Option_t* options, bool force_restart)
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
272
{
273
274
    if (force_restart)
    {
275
        connection.ForceRestart();
276
    }
277

Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
278
    TString sCmd("token");
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
279
    TString sOptions(options);
280

Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
281
    if (sOptions.Length() > 0)
282
283
        sCmd += TString(" ") + sOptions;

284
    if (gDebug > 1) Info("Token", "Full command = \"%s\"", sCmd.Data());
285

Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
286
    TJAlienResult *result = (TJAlienResult*) Command(sCmd.Data());
287

Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
288
289
290
291
    if (result)
    {
        TObjString *errorMessage = 0;
        Int_t exitcode = GetExitCode(result, errorMessage);
292
        if (exitcode != 0)
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
293
        {
294
295
            Error("Token", "%s", errorMessage->GetString().Data());
            delete result;
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
296
        }
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
297

Nikola Hardi's avatar
Nikola Hardi committed
298
299
300
301
302
303
304
305
306
307
        std::stringstream tokencert_s, tokenkey_s, tokenlock_s;

        tokencert_s << tmpdir << "/tokencert_" << getuid() << ".pem";
        tokenkey_s << tmpdir << "/tokenkey_" << getuid() << ".pem";
        tokenlock_s << tmpdir << "/jalien_token_" << getuid() << ".lock";

        std::string tokencert = tokencert_s.str();
        std::string tokenkey = tokenkey_s.str();
        std::string tokenlock = tokenlock_s.str();

308
309
        std::string tokencertpath = std::getenv("JALIEN_TOKEN_CERT") ? : tokencert;
        std::string tokenkeypath = std::getenv("JALIEN_TOKEN_KEY") ? : tokenkey;
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
310
311

        {
312
313
314
            // Create a lock file to block other TJAlien-ROOT instances from writing to tokencert file
            // If a lock exists that is older than 300 seconds, the file is removed and created again.
            TLockFile lock(tokenlock.c_str(), 300);
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
315

316
317
            FILE *tokencertfile = nullptr;
            FILE *tokenkeyfile = nullptr;
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
318

319
320
321
322
323
            // First modify permissions if files already exist
            if ((tokencertfile = fopen(tokencertpath.c_str(), "r")) &&
                (tokenkeyfile = fopen(tokenkeypath.c_str(), "r")) )
            {
                // TODO: add a validity check here
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
324

325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
                if (system(("chmod 755 " + tokencertpath).c_str()))
                    Error("Token", "Error while accessing token files");
                if (system(("chmod 755 " + tokenkeypath).c_str()))
                    Error("Token", "Error while accessing token files");

                fclose(tokencertfile);
                fclose(tokenkeyfile);
            }

            // Write files and restrict permissions back
            if ((tokencertfile = fopen(tokencertpath.c_str(), "w")) &&
                (tokenkeyfile = fopen(tokenkeypath.c_str(), "w")) )
            {
                fprintf(tokencertfile, "%s", result->GetKey(0, "tokencert"));
                fprintf(tokenkeyfile, "%s", result->GetKey(0, "tokenkey"));
                if (system(("chmod 440 " + tokencertpath).c_str()))
                    Error("Token", "Error while accessing token files");
                if (system(("chmod 400 " + tokenkeypath).c_str()))
                    Error("Token", "Error while accessing token files");

                fclose(tokencertfile);
                fclose(tokenkeyfile);
            }
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
348
        }
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
349
350
351
    }
    else
    {
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
352
        Error("Token", "RequestTokenCert: error while running command, no return result");
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
353
    }
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
354
    return;
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
355
}
Nikola Hardi's avatar
Nikola Hardi committed
356
357
358
359

//______________________________________________________________________________
TGridResult *TJAlien::Ls(const char* lfn, Option_t* options, Bool_t verbose)
{
360
    if (verbose) Info("Ls", "Ls command received with lfn = \"%s\" and options = \"%s\"", lfn, options);
361

362
    TString cmdline("ls");
Nikola Hardi's avatar
Nikola Hardi committed
363
364
365
    TString sLfn(lfn);
    TString sOptions(options);

366
367
    if (sLfn.Length() > 0 && std::string(lfn).find_first_not_of(' ') != std::string::npos)
        cmdline += TString(" ") + sLfn;
Nikola Hardi's avatar
Nikola Hardi committed
368
369

    if (sOptions.Length() > 0)
370
        cmdline += TString(" ") + sOptions;
Nikola Hardi's avatar
Nikola Hardi committed
371

372
    if (gDebug > 1) Info("Ls", "Full command = \"%s\"", cmdline.Data());
373

374
    TJAlienResult *result = (TJAlienResult*) Command(cmdline.Data());
375
    if (verbose)
Nikola Hardi's avatar
Nikola Hardi committed
376
377
378
379
    {
        Stdout();
        Stderr();
    }
380

Nikola Hardi's avatar
Nikola Hardi committed
381
382
383
384
    if (result)
    {
        TObjString *errorMessage = 0;
        Int_t exitcode = GetExitCode(result, errorMessage);
385
        if (exitcode != 0)
Nikola Hardi's avatar
Nikola Hardi committed
386
        {
387
           if (gDebug > 1) Error("Ls", "%s", errorMessage->GetString().Data());
Nikola Hardi's avatar
Nikola Hardi committed
388
           delete result;
389
           return nullptr;
Nikola Hardi's avatar
Nikola Hardi committed
390
391
392
393
        }
    }
    else
    {
394
        if (gDebug > 1) Error("Ls", "Ls: error while running command, no return result");
395
        return nullptr;
Nikola Hardi's avatar
Nikola Hardi committed
396
    }
397
    if (gDebug > 1) Info("Ls", "Ls command successful");
Nikola Hardi's avatar
Nikola Hardi committed
398
399
400
401
402
403
    return result;
}

//______________________________________________________________________________
Bool_t TJAlien::Cd(const char* lfn, Bool_t verbose)
{
404
    if (verbose) Info("Cd", "\"Cd\" command with argument = \"%s\"", lfn);
Nikola Hardi's avatar
Nikola Hardi committed
405

406
    TString cmdline("cd");
Nikola Hardi's avatar
Nikola Hardi committed
407
408
    TString sLfn(lfn);

409
    if (sLfn == nullptr || sLfn.Length() == 0 || std::string(lfn).find_first_not_of(' ') == std::string::npos)
410
411
412
        sLfn = GetHomeDirectory();

    cmdline += TString(" ") + sLfn;
Nikola Hardi's avatar
Nikola Hardi committed
413

414
    TJAlienResult *result = (TJAlienResult*) Command(cmdline.Data(), kFALSE);
415
    if (verbose)
Nikola Hardi's avatar
Nikola Hardi committed
416
417
418
419
    {
        Stdout();
        Stderr();
    }
420

Nikola Hardi's avatar
Nikola Hardi committed
421
422
423
424
    if (result)
    {
        TObjString *errorMessage = new TObjString();
        Int_t exitcode = GetExitCode(result, errorMessage);
425
        if (exitcode != 0)
Nikola Hardi's avatar
Nikola Hardi committed
426
        {
427
            if (gDebug > 1) Error("Cd", "%s", errorMessage->GetString().Data());
428
            delete result;
429
            return kFALSE;
430
431
        }
        else
Nikola Hardi's avatar
Nikola Hardi committed
432
        {
433
            if (gDebug > 1) Info("Cd", "Cd command successful, changed to \"%s\"", sLfn.Data());
434
            delete result;
435
            return kTRUE;
Nikola Hardi's avatar
Nikola Hardi committed
436
437
438
439
440
        }
    }
    else
    {
        Error("Cd", "Cd: error while running command, no return result");
441
        return kFALSE;
Nikola Hardi's avatar
Nikola Hardi committed
442
443
444
445
446
447
448
449
450
    }
}

//______________________________________________________________________________
Int_t  TJAlien::Mkdir(const char* ldn, Option_t* option, Bool_t verbose)
{
    // returns exitcode, what means:
    // 0 - if success
    // not 0 with error message - if sth went wrong
451

452
    if (ldn == nullptr || std::string(ldn).find_first_not_of(' ') == std::string::npos)
453
454
455
456
457
458
    {
        Error("Mkdir", "Command requires an argument");
        return -1;
    }

    TString cmdline("mkdir");
Nikola Hardi's avatar
Nikola Hardi committed
459
    TString sOption(option);
460

461
    if (sOption.Length() > 0)
462
        cmdline += TString(" ") + sOption;
Nikola Hardi's avatar
Nikola Hardi committed
463
464
465
466
467

    cmdline += (TString(" ") + TString(ldn));

    TGridResult *result = Command(cmdline, kFALSE);

468
    if (verbose)
Nikola Hardi's avatar
Nikola Hardi committed
469
470
471
472
473
    {
        Stdout();
        Stderr();
    }

474
    if (result)
Nikola Hardi's avatar
Nikola Hardi committed
475
476
477
478
    {
        TJAlienResult * jalienresult = (TJAlienResult*) result;
        TObjString *errorMessage = 0;
        Int_t exitcode = GetExitCode(jalienresult, errorMessage);
479
        if (exitcode != 0)
Nikola Hardi's avatar
Nikola Hardi committed
480
        {
481
            if (gDebug > 1) Error("Mkdir", "Mkdir command failed with error message \"%s\"", errorMessage->GetString().Data());
482
483
            delete result;
            return exitcode;
Nikola Hardi's avatar
Nikola Hardi committed
484
        }
485
        if (gDebug > 1) Info("Mkdir", "Mkdir command successful, created directory \"%s\"", ldn);
Nikola Hardi's avatar
Nikola Hardi committed
486
487
488
489
        delete result;
        return exitcode;
    }

490
    Error("Mkdir", "Cannot create directory %s", ldn);
Nikola Hardi's avatar
Nikola Hardi committed
491
    if (!verbose) Stdout();
492

Nikola Hardi's avatar
Nikola Hardi committed
493
494
495
496
497
498
    return 1;
}

//______________________________________________________________________________
Bool_t TJAlien::Rmdir(const char* ldn, Option_t* options, Bool_t verbose)
{
499
    if (ldn == nullptr || std::string(ldn).find_first_not_of(' ') == std::string::npos)
500
501
502
503
504
    {
        Error("Rmdir", "Command requires an argument");
        return -1;
    }

Nikola Hardi's avatar
Nikola Hardi committed
505
    TString cmdline = TString("rmdir ");
506
    if (strlen(options))
Nikola Hardi's avatar
Nikola Hardi committed
507
508
    {
        cmdline += TString(options);
509
510
    }
    else
Nikola Hardi's avatar
Nikola Hardi committed
511
512
513
514
515
516
    {
        cmdline += TString(ldn);
    }

    TGridResult *result = Command(cmdline, kFALSE);

517
    if (verbose)
Nikola Hardi's avatar
Nikola Hardi committed
518
519
520
521
522
523
524
525
526
    {
        Stdout();
        Stderr();
    }

    if (result) {
        TJAlienResult *jalienresult = (TJAlienResult *) result;
        TObjString *errorMessage = 0;
        Int_t exitcode = GetExitCode(jalienresult, errorMessage);
527
        if (exitcode != 0)
Nikola Hardi's avatar
Nikola Hardi committed
528
        {
529
530
531
            if (gDebug > 1) Error("Rmdir", "Rmdir command failed with error message \"%s\"", errorMessage->GetString().Data());
            delete result;
            return kFALSE;
532
533
        }
        else
Nikola Hardi's avatar
Nikola Hardi committed
534
        {
535
536
537
            if (gDebug > 1) Info("Rmdir", "Rmdir command successful, removed directory \"%s\"", ldn);
            delete result;
            return kTRUE;
Nikola Hardi's avatar
Nikola Hardi committed
538
539
540
        }
    }

541
    if (gDebug > 1) Error("Rmdir","Cannot remove directory %s",ldn);
Nikola Hardi's avatar
Nikola Hardi committed
542
543
544
545
546
547
    return kFALSE;
}

//______________________________________________________________________________
Bool_t TJAlien::Register(const char* lfn, const char* turl, Long_t size, const char* se, const char* guid, Bool_t verbose)
{
548
549
550
551
552
553
554
555
556
    UNUSED(lfn);
    UNUSED(turl);
    UNUSED(size);
    UNUSED(se);
    UNUSED(guid);
    UNUSED(verbose);
    (dynamic_cast<TJAlien*> (gGrid))->NotImplemented(__func__, __FILE__, __LINE__);
    return kFALSE;
    /*
557
    if (lfn == nullptr || std::string(lfn).find_first_not_of(' ') == std::string::npos)
558
559
560
561
562
    {
        Error("Register", "Command requires an argument");
        return -1;
    }

Nikola Hardi's avatar
Nikola Hardi committed
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
    TString cmdline = TString("register ") + TString(lfn) + TString(" ") + TString(turl);
    if (se) {
        cmdline += (TString(" ") + size + TString(" ") + TString(se));
        if (guid) {
           cmdline += (TString(" ") + TString(guid));
        }
    }

    TGridResult *result = Command(cmdline, kFALSE);

    if (verbose) {
        Stdout();
        Stderr();
    }

    if (result) {
579
580
581
582
583
584
585
586
587
588
589
590
        TJAlienResult *jalienresult = (TJAlienResult *) result;
        TObjString *errorMessage = 0;
        Int_t exitcode = GetExitCode(jalienresult, errorMessage);
        if (exitcode != 0) {
            if (gDebug > 1) Error("Register", "Register command failed with error message \"%s\"", errorMessage->GetString().Data());
            delete result;
            return kFALSE;
        } else {
            if (gDebug > 1) Info("Register", "Register command successful, registered file \"%s\"", lfn);
            delete result;
            return kTRUE;
        }
Nikola Hardi's avatar
Nikola Hardi committed
591
    }
592
593
594
595
596
597
598
599
600
601

    if (gDebug > 1) Error("Register", "Unable to register file %s", lfn);
    return kFALSE;*/
}

//______________________________________________________________________________
TGridResult* TJAlien::ListPackages(const char* alienpackagedir)
{
    if (!alienpackagedir) {
        alienpackagedir = "/alice/packages";
Nikola Hardi's avatar
Nikola Hardi committed
602
603
    }

604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
    TGridResult* gr = (TGridResult*) new TJAlienResult();

    TGridResult* result = Ls(alienpackagedir);
    if (result)
    {
        Int_t i = 0;
        while (result->GetFileName(i))
        {
            TString pname=result->GetFileName(i);
            TGridResult* version = Ls(Form("%s/%s",alienpackagedir,pname.Data()));
            if (version)
            {
                Int_t j=0;
                while (version->GetFileName(j))
                {
                    TString pversion=version->GetFileName(j);
                    if (!pversion.Contains("post_"))
                    {
                        TGridResult* platform = Ls(Form("%s/%s/%s", alienpackagedir, pname.Data(), pversion.Data()));
                        if (platform)
                        {
                            Int_t k = 0;
                            TString allplatform = "";
                            while (platform->GetFileName(k))
                            {
                                TString pplatform = platform->GetFileName(k);
                                allplatform += pplatform;
                                allplatform += " ";
                                TMap* grmap = new TMap();
                                grmap->Add((TObject*) new TObjString("name"), (TObject*) new TObjString(pplatform.Data()));
                                grmap->Add((TObject*) new TObjString("path"), new TObjString( Form ( "%s/%s/%s/%s" , alienpackagedir, pname.Data(), pversion.Data(), pplatform.Data())));
                                gr->Add(grmap);
                                k++;
                            }
                            Info("ListPackages","Package: %-16s Version: %-20s Platform:  [ %s ]", pname.Data(), pversion.Data(), allplatform.Data());
                            delete platform;
                        }
                    }
                    j++;
                }
                delete version;
            }
            i++;
        }
        delete result;
    }
    return gr;
Nikola Hardi's avatar
Nikola Hardi committed
651
652
653
654
655
}

//______________________________________________________________________________
Bool_t TJAlien::Rm(const char* lfn, Option_t* options, Bool_t verbose)
{
656
    if (lfn == nullptr || std::string(lfn).find_first_not_of(' ') == std::string::npos)
657
658
659
660
661
    {
        Error("Rm", "Command requires an argument");
        return kFALSE;
    }

Nikola Hardi's avatar
Nikola Hardi committed
662
663
664
665
666
667
668
669
670
    TString cmdline;
    TString sOption(options);
    if (sOption.Length() > 0)
        cmdline = TString("rm ") + sOption + TString(" ") + TString(lfn);
    else
        cmdline = TString("rm ") + TString(lfn);

    TGridResult *result = Command(cmdline, kFALSE);

671
    if (verbose)
Nikola Hardi's avatar
Nikola Hardi committed
672
673
674
675
676
    {
        Stdout();
        Stderr();
    }

677
    if (result)
Nikola Hardi's avatar
Nikola Hardi committed
678
679
680
681
    {
        TJAlienResult *jalienresult = (TJAlienResult *) result;
        TObjString *errorMessage = 0;
        Int_t exitcode = GetExitCode(jalienresult, errorMessage);
682
        if (exitcode != 0)
Nikola Hardi's avatar
Nikola Hardi committed
683
        {
684
685
686
            if (gDebug > 1) Error("Rm", "Rm command failed with error message \"%s\"", errorMessage->GetString().Data());
            delete result;
            return kFALSE;
687
688
        }
        else
Nikola Hardi's avatar
Nikola Hardi committed
689
        {
690
691
692
            if (gDebug > 1) Info("Rm", "Rm command successful");
            delete result;
            return kTRUE;
Nikola Hardi's avatar
Nikola Hardi committed
693
694
695
        }
    }

696
    if (gDebug > 1) Error("Rm", "Cannot remove %s", lfn);
Nikola Hardi's avatar
Nikola Hardi committed
697
698
699
    return kFALSE;
}

Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
700
//______________________________________________________________________________
Nikola Hardi's avatar
Nikola Hardi committed
701
702
703
TJAlien::CatalogType TJAlien::Type(const char* lfn, Option_t* option, Bool_t verbose)
{
    // returns the type of the given lfn
704
    if (lfn == nullptr || std::string(lfn).find_first_not_of(' ') == std::string::npos)
705
706
707
708
    {
        Error("Type", "Command requires an argument");
        return kFailed;
    }
Nikola Hardi's avatar
Nikola Hardi committed
709
710
711

    TString cmdline;
    TString sOption(option);
712
    if (sOption.Length() > 0)
Nikola Hardi's avatar
Nikola Hardi committed
713
714
    {
        cmdline = TString("type ") + sOption + TString(" ") + TString(lfn);
715
716
    }
    else
Nikola Hardi's avatar
Nikola Hardi committed
717
718
719
720
721
722
    {
        cmdline = TString("type ") + TString(lfn);
    }

    TJAlienResult *result = (TJAlienResult*) Command(cmdline, kFALSE);

723
    if (verbose)
Nikola Hardi's avatar
Nikola Hardi committed
724
725
726
727
728
    {
        Stdout();
        Stderr();
    }

729
    if (!result)
Nikola Hardi's avatar
Nikola Hardi committed
730
731
732
733
734
735
736
    {
        Error("Type", "Did not receive TGridResult from query %s", cmdline.Data());
        return kFailed;
    }
    //check exitcode, if command was executed successfully
    TObjString *errorMessage = 0;
    Int_t exitcode = GetExitCode(result, errorMessage);
737
    if (exitcode != 0)
Nikola Hardi's avatar
Nikola Hardi committed
738
739
740
741
742
743
744
    {
        Error("Type", "Type command failed with error message \"%s\"", errorMessage->GetString().Data());
        delete result;
        return kFailed;
    }

    const char* typeStr = result->GetKey(0, "type");
745
    if (!typeStr || strlen(typeStr) == 0)
Nikola Hardi's avatar
Nikola Hardi committed
746
747
748
749
750
751
752
753
    {
        Error("Type", "Could not get type of %s", lfn);
        delete result;
        return kFailed;
    }

    TJAlien::CatalogType type = kFailed;

754
    if (strcmp(typeStr, "file") == 0)
Nikola Hardi's avatar
Nikola Hardi committed
755
756
    {
        type =  kFile;
757
758
    }
    else if (strcmp(typeStr, "directory") == 0)
Nikola Hardi's avatar
Nikola Hardi committed
759
760
    {
        type = kDirectory;
761
762
    }
    else if (strcmp(typeStr, "collection") == 0)
Nikola Hardi's avatar
Nikola Hardi committed
763
764
    {
        type = kCollection;
765
    }
Nikola Hardi's avatar
Nikola Hardi committed
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
    else
        Error("Type", "Unknown type %s", typeStr);

    delete result;

    return type;
}

//______________________________________________________________________________
TGridJob *TJAlien::Submit(const char *jdl)
{
    // Submit a command to JAliEn. Returns 0 in case of error.

    if (!jdl)
        return 0;

    TString command = TString("submit ");
    command += jdl;

785
    if (gDebug > 1) Info("TJAlien", "command: %s", command.Data());
Nikola Hardi's avatar
Nikola Hardi committed
786

787
788
789
    TGridResult* result = Command(command, kFALSE, kOUTPUT);
    TJAlienResult* jalienResult = dynamic_cast<TJAlienResult*> (result);
    TList* list = dynamic_cast<TList*> (jalienResult);
790
    if (!list)
Nikola Hardi's avatar
Nikola Hardi committed
791
792
    {
        if (result)
793
            delete result;
794

Nikola Hardi's avatar
Nikola Hardi committed
795
796
797
        return 0;
    }
    //check exitcode, if command was executed successfully
798
    if (jalienResult)
Nikola Hardi's avatar
Nikola Hardi committed
799
800
801
    {
        TObjString *errorMessage = 0;
        Int_t exitcode = GetExitCode(jalienResult, errorMessage);
802
        if (exitcode != 0)
Nikola Hardi's avatar
Nikola Hardi committed
803
        {
804
805
806
            Error("Submit", "Submit command failed with error message \"%s\"", errorMessage->GetString().Data());
            delete result;
            return 0;
Nikola Hardi's avatar
Nikola Hardi committed
807
808
809
810
811
812
813
814
815
        }
    }

    jalienResult->DumpResult();

    TString jobID = "0";

    TIterator* iter = list->MakeIterator();
    TObject* object = 0;
816
    while ((object = iter->Next()) != 0)
Nikola Hardi's avatar
Nikola Hardi committed
817
818
819
820
    {
        TMap* map = dynamic_cast<TMap*>(object);

        TObject* jobIDObject = map->GetValue("jobId");
821
        TObjString* jobIDStr = dynamic_cast<TObjString*> (jobIDObject);
822
        if (jobIDStr)
823
            jobID = jobIDStr->GetString();
Nikola Hardi's avatar
Nikola Hardi committed
824
825
826
827
    }
    delete iter;
    delete result;

828
    if (jobID == "0")
Nikola Hardi's avatar
Nikola Hardi committed
829
    {
830
        Error("Submit", "Error submitting job");
Nikola Hardi's avatar
Nikola Hardi committed
831
832
833
        return 0;
    }

834
    Info("Submit", "Your job was submitted with the ID = %s", jobID.Data());
Nikola Hardi's avatar
Nikola Hardi committed
835

836
837
838
839
840
841
842
    return dynamic_cast<TGridJob*> (new TJAlienJob(jobID));
}

//______________________________________________________________________________
TGridJDL *TJAlien::GetJDLGenerator()
{
    return new TJAlienJDL();
Nikola Hardi's avatar
Nikola Hardi committed
843
844
}

845
846
847
848
849
850
851
852
853
//______________________________________________________________________________
const char *TJAlien::GetHomeDirectory()
{
    if (!IsConnected())
        Connect();

    return fHome.Data();
}

Nikola Hardi's avatar
Nikola Hardi committed
854
855
856
857
858
859
860
861
// TODO not implemented in java, TEST!!!!
//______________________________________________________________________________
Bool_t TJAlien::ResubmitById(TString jobid)
{
    // Resubmit a specific job.
    TString cmdline = TString("resubmit ") + jobid;

    TGridResult *result = Command(cmdline, kFALSE);
862
    if (result)
Nikola Hardi's avatar
Nikola Hardi committed
863
864
865
866
    {
        TJAlienResult *jalienresult = (TJAlienResult *) result;
        TObjString *errorMessage = 0;
        Int_t exitcode = GetExitCode(jalienresult, errorMessage);
867
        if (exitcode != 0)
Nikola Hardi's avatar
Nikola Hardi committed
868
        {
869
870
871
            Error("ResubmitById", "ResubmitByIt command failed with error message \"%s\"", errorMessage->GetString().Data());
            delete result;
            return kFALSE;
872
873
        }
        else
Nikola Hardi's avatar
Nikola Hardi committed
874
        {
875
876
877
            Info("ResubmitById", "ResubmitById command successful, submited job \"%s\"", jobid.Data());
            delete result;
            return kTRUE;
Nikola Hardi's avatar
Nikola Hardi committed
878
879
880
881
882
883
884
885
886
887
888
889
890
        }
    }
    return kFALSE;
}

// TODO not implemented in java, TEST!!!!
//______________________________________________________________________________
Bool_t TJAlien::KillById(TString jobid)
{
    // Kill a specific job.
    TString cmdline = TString("kill ") + jobid;

    TGridResult *result = Command(cmdline, kFALSE);
891
    if (result)
Nikola Hardi's avatar
Nikola Hardi committed
892
893
894
895
    {
        TJAlienResult *jalienresult = (TJAlienResult *) result;
        TObjString *errorMessage = 0;
        Int_t exitcode = GetExitCode(jalienresult, errorMessage);
896
        if (exitcode != 0)
Nikola Hardi's avatar
Nikola Hardi committed
897
        {
898
899
900
            Error("KillById", "KillById command failed with error message \"%s\"", errorMessage->GetString().Data());
            delete result;
            return kFALSE;
901
902
        }
        else
Nikola Hardi's avatar
Nikola Hardi committed
903
        {
904
905
906
            Info("KillById", "KillById command successful, killed job \"%s\"", jobid.Data());
            delete result;
            return kTRUE;
Nikola Hardi's avatar
Nikola Hardi committed
907
908
909
910
911
912
913
914
        }
    }
    return kFALSE;
}

//______________________________________________________________________________
TGridJobStatusList *TJAlien::Ps(const char* options, Bool_t verbose)
{
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
915
    UNUSED(verbose);
Nikola Hardi's avatar
Nikola Hardi committed
916
917
    TString cmdline("ps");

918
    if (options != nullptr && std::string(options).find_first_not_of(' ') != std::string::npos)
Nikola Hardi's avatar
Nikola Hardi committed
919
    {
920
921
        TString sOptions(options);
        cmdline += TString(" ") + sOptions;
Nikola Hardi's avatar
Nikola Hardi committed
922
923
    }

924
925
926
927
928
    TJAlienResult *jalienresult = (TJAlienResult*) Command(cmdline, kFALSE);

    Stdout();
    Stderr();

Nikola Hardi's avatar
Nikola Hardi committed
929
930
931
932
    if (jalienresult)
    {
        TObjString *errorMessage = 0;
        Int_t exitcode = GetExitCode(jalienresult, errorMessage);
933
        if (exitcode != 0)
Nikola Hardi's avatar
Nikola Hardi committed
934
        {
935
            Error("Ps", "%s", errorMessage->GetString().Data());
Nikola Hardi's avatar
Nikola Hardi committed
936
            delete jalienresult;
937
            return nullptr;
Nikola Hardi's avatar
Nikola Hardi committed
938
939
940
941
942
        }
    }
    else
    {
        Error("Ps", "Ps: error while running command, no return result");
943
        return nullptr;
Nikola Hardi's avatar
Nikola Hardi committed
944
945
    }

946
947
    //jalienresult->DumpResult();
    TList *list = dynamic_cast<TList*> (jalienresult);
948
    if (!list)
Nikola Hardi's avatar
Nikola Hardi committed
949
    {
950
        if (jalienresult)
Nikola Hardi's avatar
Nikola Hardi committed
951
952
            delete jalienresult;

953
        Error("Ps", "Ps: error while running command, no empty result returned");
954
        return nullptr;
Nikola Hardi's avatar
Nikola Hardi committed
955
956
957
    }

    TJAlienJobStatusList *joblist = new TJAlienJobStatusList();
958
959
    TIterator *it = list->MakeIterator();
    TObject *object = it->Next();
960
    while (object != 0)
Nikola Hardi's avatar
Nikola Hardi committed
961
    {
962
        TMap *status = dynamic_cast<TMap*> (object);
Nikola Hardi's avatar
Nikola Hardi committed
963
        TJAlienJobStatus *jobstatus = new TJAlienJobStatus(status);
964
        //if (verbose) jobstatus->Print("");
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
965
        joblist->Add((TGridJobStatus*)jobstatus);
Nikola Hardi's avatar
Nikola Hardi committed
966
967
968
969
970
        object = it->Next();
    }
    delete jalienresult;
    return joblist;
}
971

972
973
974
975
976
977
978
979
980
//______________________________________________________________________________
const char *TJAlien::Pwd(Bool_t verbose)
{
    if (!IsConnected())
        Connect();

    return fPwd.Data();
};

Nikola Hardi's avatar
Nikola Hardi committed
981
982
983
//______________________________________________________________________________
TGridResult* TJAlien::GetCollection(const char* lfn, Option_t* option, Bool_t verbose)
{
984
    if (lfn == nullptr || std::string(lfn).find_first_not_of(' ') == std::string::npos)
985
        lfn = GetHomeDirectory();
Nikola Hardi's avatar
Nikola Hardi committed
986
987
988

    TString cmdline;
    TString sOption(option);
989
    if (sOption != 0 && sOption.Length() > 0)
Nikola Hardi's avatar
Nikola Hardi committed
990
991
    {
        cmdline = TString("listFilesFromCollection ") + sOption + TString(" ") + TString(lfn);
992
993
    }
    else
Nikola Hardi's avatar
Nikola Hardi committed
994
995
996
997
998
999
    {
        cmdline = TString("listFilesFromCollection ") + TString(lfn);
    }

    TGridResult* gridResult = Command(cmdline, kFALSE);

1000
    if (verbose)
Nikola Hardi's avatar
Nikola Hardi committed
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
    {
        Stdout();
        Stderr();
    }

    return gridResult;
}

//______________________________________________________________________________
TGridCollection *TJAlien::OpenCollection(const char *collectionfile, UInt_t maxentries)
{
    // Factory function for a TJAlienCollection based on an XML file.

    TString path(collectionfile);
1015
    if (path.BeginsWith("alien://", TString::kIgnoreCase))
Nikola Hardi's avatar
Nikola Hardi committed
1016
1017
    {
        TJAlien* jalien = dynamic_cast<TJAlien*> (gGrid);
1018
        if (!jalien)
Nikola Hardi's avatar
Nikola Hardi committed
1019
1020
1021
1022
        {
           Error("OpenCollection", "Trying to read a collection, but gGrid is not initialized with JAliEn");
           return 0;
        }
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
1023
        TString lfn = path(strlen("alien://"), path.Length());
1024
        if (jalien->Type(lfn) == kCollection)
Nikola Hardi's avatar
Nikola Hardi committed
1025
1026
1027
        {
           // it is a collection
           TGridResult* gridResult = jalien->GetCollection(lfn, 0, kFALSE);
1028
           if (!gridResult)
Nikola Hardi's avatar
Nikola Hardi committed
1029
1030
1031
1032
1033
1034
1035
1036
           {
                Error("OpenCollection", "Could not retrieve collection %s from the catalog", collectionfile);
                return 0;
           }
           //check exitcode, if command was executed successfully
           TJAlienResult *jalienresult = (TJAlienResult *) gridResult;
           TObjString *errorMessage = 0;
           Int_t exitcode = GetExitCode(jalienresult, errorMessage);
1037
           if (exitcode != 0)
Nikola Hardi's avatar
Nikola Hardi committed
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
           {
                Error("OpenCollection", "OpenCollection command failed with error message \"%s\"", errorMessage->GetString().Data());
                delete gridResult;
                return 0;
           }

           return TJAlienCollection::OpenJAliEnCollection(gridResult);
        }
    }

    return TJAlienCollection::Open(collectionfile, maxentries);
}

//______________________________________________________________________________
TGridCollection *TJAlien::OpenCollectionQuery(TGridResult *queryresult, Bool_t nogrouping)
{
    // Factory function fo a TJAlienCollection based on a gGrid Query.

    return (TGridCollection*)TJAlienCollection::OpenQuery(queryresult, nogrouping);
}

1059
1060
1061
1062
1063
1064
//______________________________________________________________________________
TGridResult *TJAlien::OpenDataset(const char *lfn, const char *options)
{
    UNUSED(lfn);
    UNUSED(options);
    (dynamic_cast<TJAlien*> (gGrid))->NotImplemented(__func__, __FILE__, __LINE__);
1065
    return nullptr;
1066
1067
1068
1069
1070
1071
1072
1073
}

//______________________________________________________________________________
TMap *TJAlien::GetColumn(UInt_t stream, UInt_t column)
{
    UNUSED(stream);
    UNUSED(column);
    (dynamic_cast<TJAlien*> (gGrid))->NotImplemented(__func__, __FILE__, __LINE__);
1074
    return nullptr;
1075
1076
1077
1078
1079
1080
1081
1082
1083
}

//______________________________________________________________________________
const char *TJAlien::GetStreamFieldValue(UInt_t stream, UInt_t column, UInt_t row)
{
    UNUSED(stream);
    UNUSED(column);
    UNUSED(row);
    (dynamic_cast<TJAlien*> (gGrid))->NotImplemented(__func__, __FILE__, __LINE__);
1084
    return nullptr;
1085
1086
1087
1088
1089
1090
1091
1092
1093
}

//______________________________________________________________________________
const char *TJAlien::GetStreamFieldKey(UInt_t stream, UInt_t column, UInt_t row)
{
    UNUSED(stream);
    UNUSED(column);
    UNUSED(row);
    (dynamic_cast<TJAlien*> (gGrid))->NotImplemented(__func__, __FILE__, __LINE__);
1094
    return nullptr;
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
}

//______________________________________________________________________________
UInt_t TJAlien::GetNColumns(UInt_t stream)
{
    UNUSED(stream);
    (dynamic_cast<TJAlien*> (gGrid))->NotImplemented(__func__, __FILE__, __LINE__);
    return -1;
}

Nikola Hardi's avatar
Nikola Hardi committed
1105
1106
1107
1108
1109
1110
1111
//______________________________________________________________________________
TGridResult *TJAlien::Query(const char *path, const char *pattern,
        const char *conditions, const char *options)
{
    // this command should create collection using 'find -c'
    // in TJAlienResult should be path to this created collection
    // BUT change of java part is needed, this does not work now TODO
1112
    TString cmdline = TString("find");
Nikola Hardi's avatar
Nikola Hardi committed
1113
1114
1115
1116
1117
1118
    TString sPath(path);
    TString sPattern(pattern);
    TString sConditions(conditions);
    TString sOptions(options);

    if (sOptions.Length() > 0)
1119
        cmdline += TString(" ") + sOptions;
Nikola Hardi's avatar
Nikola Hardi committed
1120
    if (sPath.Length() > 0)
1121
        cmdline += TString(" ") +  sPath;
Nikola Hardi's avatar
Nikola Hardi committed
1122
    if (sPattern.Length() > 0)
1123
        cmdline += TString(" ") +  sPattern;
Nikola Hardi's avatar
Nikola Hardi committed
1124
    if (sConditions.Length() > 0)
1125
        cmdline += TString(" ") +  sConditions;
Nikola Hardi's avatar
Nikola Hardi committed
1126
1127
1128
1129
    return Command(cmdline);
}

//______________________________________________________________________________
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
1130
Int_t TJAlien::GetExitCode(TJAlienResult *result, TObjString* &message)
Nikola Hardi's avatar
Nikola Hardi committed
1131
{
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
1132
    // Extracting the exit code and error message from a TJAlien result
Nikola Hardi's avatar
Nikola Hardi committed
1133
1134
    if (!result)
    {
1135
        Error("GetExitCode", "Could not retrieve the exit code, the result is nullptr");
Nikola Hardi's avatar
Nikola Hardi committed
1136
1137
1138
        return -1;
    }

Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
1139
    TObjString *key = new TObjString();
Nikola Hardi's avatar
Nikola Hardi committed
1140
1141
1142
    key->SetString("exitcode");

    TObjString *ecStr = result->GetMetaData(key);
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
1143
    Int_t exitcode = 0;
1144
    if (ecStr != nullptr)
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
1145
        exitcode = ecStr->GetString().Atoi();
Nikola Hardi's avatar
Nikola Hardi committed
1146
1147

    if (exitcode != 0) {
Volodymyr Yurchenko's avatar
Volodymyr Yurchenko committed
1148
1149
1150
        key->SetString("error");
        //message->SetString(result->GetMetaData(key)->GetString().Data());
        message = result->GetMetaData(key);
Nikola Hardi's avatar
Nikola Hardi committed
1151
1152
1153
1154
1155
1156
1157
    }

    delete key;

    return exitcode;
}

1158
//______________________________________________________________________________
1159
1160
1161
1162
1163
1164
1165
const char* TJAlien::Whoami()
{
    if (!IsConnected())
        Connect();

    return fUser.Data();
};