NCBI C++ ToolKit
misc_cmds.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: misc_cmds.cpp 80544 2017-12-19 17:13:23Z sadyrovr $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Dmitry Kazimirov
27  *
28  * File Description: Miscellaneous commands of the grid_cli application
29  * (the ones that are not specific to NetCache, NetSchedule,
30  * or worker nodes).
31  *
32  */
33 
34 #include <ncbi_pch.hpp>
35 
36 #include "ns_cmd_impl.hpp"
37 #include "util.hpp"
38 
40 
42 {
43  if (m_Opts.output_format == eJSON) {
45 
46  if (result) {
47  g_PrintJSON(stdout, result);
48  return 0;
49  }
50  } else {
51  try {
53 
54  CJsonNode object_loc_info(CJsonNode::NewObjectNode());
55 
56  object_loc_info.SetString("type", TOKEN_TYPE__NETSTORAGEOBJECT_LOC);
57 
58  object_loc.ToJSON(object_loc_info);
59 
60  g_PrintJSON(stdout, object_loc_info);
61 
62  return 0;
63  }
64  catch (CCompoundIDException&) {
65  }
66  catch (CNetStorageException&) {
67  }
68 
69  CNetCacheKey nc_key;
70  CNetScheduleKey ns_key;
71 
73  m_Opts.id.length(), &nc_key, m_CompoundIDPool)) {
74  printf("type: " TOKEN_TYPE__NETCACHE_BLOB_KEY "\nkey_version: %u\n",
75  nc_key.GetVersion());
76  PrintBlobMeta(nc_key);
77 
79  printf("\nTo retrieve blob attributes from the server, use\n"
80  GRID_APP_NAME " blobinfo %s\n", m_Opts.id.c_str());
81  return 0;
82 
83  // Ignoring version 0 as it means any string with a leading digit
84  } else if (ns_key.ParseJobKey(m_Opts.id, m_CompoundIDPool) && ns_key.version) {
85  printf("type: " TOKEN_TYPE__NETSCHEDULE_JOB_KEY "\n"
86  "key_version: %u\n",
87  ns_key.version);
88 
89  CPrintJobInfo print_job_info;
90 
91  print_job_info.ProcessJobMeta(ns_key);
92 
93  printf("\nTo retrieve job attributes from the server, use\n"
94  GRID_APP_NAME " jobinfo %s\n", m_Opts.id.c_str());
95  return 0;
96  }
97  }
98 
99  fprintf(stderr, "Unable to recognize the specified token.\n");
100  return 3;
101 }
102 
104 {
105  if (m_Opts.app_uid.empty()) {
106  fputs("Application UID cannot be empty.\n", stderr);
107  return 2;
108  }
109  if (m_Opts.app_uid == DEFAULT_APP_UID) {
110  fputs("Application UID '" DEFAULT_APP_UID
111  "' is reserved and cannot be used.\n", stderr);
112  return 2;
113  }
114 
116 
119 
120  if (IsOptionSet(eAuth)) {
122  cid.AppendString(m_Opts.auth);
123  }
124 
126  cid.AppendString(GetDiagContext().GetUsername());
129 
130  if (IsOptionSet(eNetCache)) {
133  }
134  if (IsOptionSet(eCache)) {
137  }
140  cid.AppendBoolean(true);
141  }
142 
143  if (IsOptionSet(eNetSchedule)) {
146  }
147  if (IsOptionSet(eQueue)) {
150  }
151 
154 
156  cid.AppendCurrentTime();
157 
159  cid.AppendString(GetDiagContext().GetStringUID());
160 
161 #ifdef NCBI_GRID_XSITE_CONN_SUPPORT
162  if (IsOptionSet(eAllowXSiteConn)) {
164  cid.AppendBoolean(true);
165  }
166 #endif
167 
170  cid.AppendBoolean(true);
171  }
172 
176  }
180  }
181 
182  PrintLine(cid.ToString());
183 
184  return 0;
185 }
void g_PrintJSON(FILE *output_stream, CJsonNode node, const char *indent)
Definition: util.cpp:738
CJsonNode g_WhatIs(const string &id, CCompoundIDPool id_pool)
Definition: util.cpp:876
#define GRID_APP_NAME
Definition: cgi2rcgi.cpp:63
Exception class for use by CCompoundIDPool, CCompoundID, and CCompoundIDField.
Definition: compound_id.hpp:91
CCompoundID NewID(ECompoundIDClass new_id_class)
Create and return a new CCompoundID objects.
Base64-encoded ID string that contains extractable typed fields.
void AppendDatabaseName(const string &db_name)
Append an eCIT_DatabaseName field at the end of this compound ID.
void AppendString(const string &string_value)
Append an eCIT_String field at the end of this compound ID.
void AppendCurrentTime()
Get the current time and append it as an eCIT_Timestamp field at the end of this compound ID.
void AppendLabel(const string &tag)
Append an eCIT_Label field at the end of this compound ID.
string ToString()
Pack the ID and return its string representation.
void AppendID(Uint8 id)
Append an eCIT_ID field at the end of this compound ID.
void AppendHost(const string &host)
Append an eCIT_Host field at the end of this compound ID.
void AppendBoolean(bool boolean_value)
Append an eCIT_Boolean field at the end of this compound ID.
void AppendServiceName(const string &service_name)
Append an eCIT_ServiceName field at the end of this compound ID.
CCompoundIDPool m_CompoundIDPool
Definition: grid_cli.hpp:457
bool IsOptionSet(int option) const
Definition: grid_cli.hpp:421
struct CGridCommandLineInterfaceApp::SOptions m_Opts
static void PrintLine(const string &line)
Definition: grid_cli.cpp:1775
static void PrintBlobMeta(const CNetCacheKey &key)
Definition: nc_cmds.cpp:129
JSON node abstraction.
void SetString(const string &key, const string &value)
Set a JSON object element to the specified string value.
static CJsonNode NewObjectNode()
Create a new JSON object node.
Exception class for use by CNetStorage, CNetStorageByKey, and CNetStorageObject.
Definition: netstorage.hpp:67
void ToJSON(CJsonNode &root) const
virtual void ProcessJobMeta(const CNetScheduleKey &key)
@ eCIC_GenericID
Definition: compound_id.hpp:51
#define LOGIN_TOKEN_HOST_FIELD
Definition: grid_cli.hpp:55
#define LOGIN_TOKEN_FILETRACK_SITE
Definition: grid_cli.hpp:66
#define LOGIN_TOKEN_SESSION_PID_FIELD
Definition: grid_cli.hpp:61
#define LOGIN_TOKEN_QUEUE_FIELD
Definition: grid_cli.hpp:60
@ eHumanReadable
Definition: grid_cli.hpp:277
#define LOGIN_TOKEN_FILETRACK_TOKEN
Definition: grid_cli.hpp:67
#define LOGIN_TOKEN_SESSION_TIMESTAMP_FIELD
Definition: grid_cli.hpp:62
#define LOGIN_TOKEN_ENABLE_MIRRORING
Definition: grid_cli.hpp:58
#define LOGIN_TOKEN_USER_FIELD
Definition: grid_cli.hpp:54
#define LOGIN_TOKEN_NO_CONN_RETRIES
Definition: grid_cli.hpp:65
#define LOGIN_TOKEN_NETCACHE_FIELD
Definition: grid_cli.hpp:56
#define DEFAULT_APP_UID
Definition: grid_cli.hpp:50
#define LOGIN_TOKEN_ICACHE_NAME_FIELD
Definition: grid_cli.hpp:57
#define LOGIN_TOKEN_ALLOW_XSITE_CONN
Definition: grid_cli.hpp:64
#define LOGIN_TOKEN_AUTH_FIELD
Definition: grid_cli.hpp:53
#define LOGIN_TOKEN_SESSION_UID_FIELD
Definition: grid_cli.hpp:63
@ eCache
Definition: grid_cli.hpp:172
@ eAuth
Definition: grid_cli.hpp:162
@ eNoConnRetries
Definition: grid_cli.hpp:160
@ eNetCache
Definition: grid_cli.hpp:171
@ eFileTrackToken
Definition: grid_cli.hpp:254
@ eNetSchedule
Definition: grid_cli.hpp:190
@ eEnableMirroring
Definition: grid_cli.hpp:178
@ eQueue
Definition: grid_cli.hpp:191
@ eFileTrackSite
Definition: grid_cli.hpp:253
#define LOGIN_TOKEN_NETSCHEDULE_FIELD
Definition: grid_cli.hpp:59
#define LOGIN_TOKEN_APP_UID_FIELD
Definition: grid_cli.hpp:52
CDiagContext & GetDiagContext(void)
Get diag context instance.
Definition: logging.cpp:818
static TPID GetPID(void)
Get cached PID (read real PID if not cached yet).
Definition: ncbidiag.cpp:1526
static bool ParseBlobKey(const char *key_str, size_t key_len, CNetCacheKey *key_obj, CCompoundIDPool::TInstance id_pool=NULL)
Parse blob key string into a CNetCacheKey structure.
unsigned GetVersion() const
bool ParseJobKey(const string &key_str, CCompoundIDPool::TInstance id_pool=NULL)
unsigned version
Key version.
USING_NCBI_SCOPE
Definition: misc_cmds.cpp:39
Uint4 GetHost(TEndpointKey key)
#define TOKEN_TYPE__NETCACHE_BLOB_KEY
Definition: util.hpp:118
#define TOKEN_TYPE__NETSTORAGEOBJECT_LOC
Definition: util.hpp:120
#define TOKEN_TYPE__NETSCHEDULE_JOB_KEY
Definition: util.hpp:119
Meaningful information encoded in the NetCache key.
Meaningful information encoded in the NetSchedule key.
else result
Definition: token2.c:20
Modified on Thu Feb 29 12:19:03 2024 by modify_doxy.py rev. 669887