datatrail-cli 0.7.0__tar.gz → 0.7.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: datatrail-cli
3
- Version: 0.7.0
3
+ Version: 0.7.2
4
4
  Summary: CHIME/FRB Datatrail CLI
5
5
  License: MIT
6
6
  Author: CHIME FRB Project Office
@@ -66,6 +66,18 @@ def ps(
66
66
  except Exception as e:
67
67
  error_console.print(e)
68
68
  return None
69
+
70
+ # Check Canfar status.
71
+ minoc_up, luskan_up = cadcclient.status()
72
+ if not minoc_up:
73
+ error_console.print(
74
+ "Either Minoc is down or certificate is invalid.", style="bold yellow"
75
+ )
76
+ elif not luskan_up:
77
+ error_console.print(
78
+ "Either Luskan is down or certificate is invalid.", style="bold yellow"
79
+ )
80
+
69
81
  try:
70
82
  files, policies = functions.ps(scope, dataset, verbose, quiet)
71
83
  if isinstance(files, str) or isinstance(policies, str):
@@ -10,7 +10,7 @@ from rich.prompt import Confirm
10
10
 
11
11
  from dtcli.config import procure
12
12
  from dtcli.src.functions import find_missing_dataset_files, get_files
13
- from dtcli.utilities.cadcclient import size
13
+ from dtcli.utilities import cadcclient
14
14
  from dtcli.utilities.utilities import set_log_level, validate_scope
15
15
 
16
16
  logger = logging.getLogger("pull")
@@ -42,7 +42,7 @@ error_console = Console(stderr=True, style="bold red")
42
42
  @click.option("-q", "--quiet", is_flag=True, help="Set log level to ERROR.")
43
43
  @click.option("--force", "-f", is_flag=True, help="Do not prompt for confirmation.")
44
44
  @click.pass_context
45
- def pull(
45
+ def pull( # noqa: C901
46
46
  ctx: click.Context,
47
47
  scope: str,
48
48
  dataset: str,
@@ -97,6 +97,17 @@ def pull(
97
97
  error_console.print(e)
98
98
  return None
99
99
 
100
+ # Check Canfar status.
101
+ minoc_up, luskan_up = cadcclient.status()
102
+ if not minoc_up:
103
+ error_console.print(
104
+ "Either Minoc is down or certificate is invalid.", style="bold yellow"
105
+ )
106
+ elif not luskan_up:
107
+ error_console.print(
108
+ "Either Luskan is down or certificate is invalid.", style="bold yellow"
109
+ )
110
+
100
111
  # Find files missing from localhost.
101
112
  console.print(f"\nSearching for files for {dataset} {scope}...\n")
102
113
  files = find_missing_dataset_files(scope, dataset, directory, verbose)
@@ -107,11 +118,10 @@ def pull(
107
118
  console.print("No files found at minoc.", style="bold red")
108
119
  return None
109
120
  files_paths = [f.replace("cadc:CHIMEFRB", "") for f in files["missing"]]
110
- to_download_size = 0.0
111
- if len(files_paths) > 0:
121
+ if len(files_paths) > 0 and luskan_up:
112
122
  common_path = path.commonpath(["/" + f for f in files_paths])
113
123
  try:
114
- to_download_size = size(common_path)
124
+ to_download_size = cadcclient.size(common_path)
115
125
  except SSLError:
116
126
  error_console.print(
117
127
  """
@@ -120,6 +130,10 @@ Create one using 'cadc-get-cert -u <USERNAME>'.
120
130
  """
121
131
  )
122
132
  return None
133
+ elif not luskan_up:
134
+ to_download_size = -1
135
+ else:
136
+ to_download_size = 0
123
137
  console.print(
124
138
  f" - {len(files['existing'])} files found at {site}.",
125
139
  style="green",
@@ -128,10 +142,16 @@ Create one using 'cadc-get-cert -u <USERNAME>'.
128
142
  f" - {len(files['missing'])} files can be downloaded from minoc.",
129
143
  style="yellow",
130
144
  )
131
- console.print(
132
- f" - Size to download: {to_download_size:.2f} GB.\n",
133
- style="yellow",
134
- )
145
+ if luskan_up:
146
+ console.print(
147
+ f" - Size to download: {to_download_size:.2f} GB.\n",
148
+ style="yellow",
149
+ )
150
+ else:
151
+ console.print(
152
+ " - Size to download: [red]Unable to query Luskan[/red].",
153
+ style="yellow",
154
+ )
135
155
 
136
156
  # Confirm download.
137
157
  if force:
@@ -22,15 +22,15 @@ error_console = Console(stderr=True, style="bold red")
22
22
 
23
23
 
24
24
  @click.command(name="scout", help="Scout a dataset.")
25
- @click.argument("dataset", required=True, type=click.STRING, nargs=1)
26
25
  @click.argument("scopes", required=False, type=click.STRING, nargs=-1)
26
+ @click.argument("dataset", required=True, type=click.STRING, nargs=1)
27
27
  @click.option("-v", "--verbose", count=True, help="Verbosity: v=INFO, vv=DEBUG.")
28
28
  @click.option("-q", "--quiet", is_flag=True, help="Set log level to ERROR.")
29
29
  @click.pass_context
30
30
  def scout( # noqa: C901
31
31
  ctx: click.Context,
32
- dataset: str,
33
32
  scopes: List[str],
33
+ dataset: str,
34
34
  verbose: int,
35
35
  quiet: bool,
36
36
  ):
@@ -38,8 +38,8 @@ def scout( # noqa: C901
38
38
 
39
39
  Args:
40
40
  ctx (click.Context): Click context.
41
- dataset (str): Name of dataset.
42
41
  scopes (List[str]): Scopes of dataset.
42
+ dataset (str): Name of dataset.
43
43
  verbose (int): Verbosity: v=INFO, vv=DUBUG.
44
44
  quiet (bool): Set log level to ERROR.
45
45
 
@@ -49,8 +49,8 @@ def scout( # noqa: C901
49
49
  # Set logging level.
50
50
  set_log_level(logger, verbose, quiet)
51
51
  logger.debug("`scout` called with:")
52
- logger.debug(f"dataset: {dataset} [{type(dataset)}]")
53
52
  logger.debug(f"scopes: {scopes} [{type(scopes)}]")
53
+ logger.debug(f"dataset: {dataset} [{type(dataset)}]")
54
54
  logger.debug(f"verbose: {verbose} [{type(verbose)}]")
55
55
  logger.debug(f"quiet: {quiet} [{type(quiet)}]")
56
56
 
@@ -78,6 +78,17 @@ def scout( # noqa: C901
78
78
  )
79
79
  return {"error": "No config. Create one with `datatrail config init`."}
80
80
 
81
+ # Check Canfar status.
82
+ minoc_up, luskan_up = cadcclient.status()
83
+ if not minoc_up:
84
+ error_console.print(
85
+ "Either Minoc is down or certificate is invalid.", style="bold yellow"
86
+ )
87
+ elif not luskan_up:
88
+ error_console.print(
89
+ "Either Luskan is down or certificate is invalid.", style="bold yellow"
90
+ )
91
+
81
92
  # Scout dataset.
82
93
  endpoint = (
83
94
  f"/query/dataset/scout?name={dataset}"
@@ -113,6 +124,10 @@ def scout( # noqa: C901
113
124
  error_console.print("Query failed.")
114
125
  error_console.print(error)
115
126
  return None
127
+ except Exception as error:
128
+ error_console.print("Query failed.")
129
+ error_console.print(error)
130
+ return None
116
131
  data[scope]["observed"]["minoc"] = count
117
132
 
118
133
  keys_missing_in_observed = list(
@@ -9,9 +9,11 @@ from typing import Any, Dict, List, Optional, Tuple
9
9
 
10
10
  import cadcutils
11
11
  import dill
12
+ import requests
12
13
  from cadcdata import StorageInventoryClient
13
14
  from cadctap import CadcTapClient
14
15
  from cadcutils import net
16
+ from requests.exceptions import HTTPError
15
17
  from rich.traceback import install
16
18
 
17
19
  from dtcli.config import procure
@@ -364,3 +366,42 @@ def query(
364
366
  content = buffer.getvalue()
365
367
  sys.stdout = sys.__stdout__
366
368
  return [line.split(",") for line in content.split("\n")]
369
+
370
+
371
+ def status(
372
+ certfile: Optional[str] = None,
373
+ ) -> Tuple[bool, bool]:
374
+ """Check the status of Minoc.
375
+
376
+ Args:
377
+ certfile: Canfar certificate file.
378
+
379
+ Returns:
380
+ bool: True if Minoc is up, False otherwise.
381
+ """
382
+ urls: List[str] = [
383
+ "https://ws-uv.canfar.net/minoc/capabilities",
384
+ "https://ws-uv.canfar.net/luskan/capabilities",
385
+ ]
386
+ if not certfile:
387
+ certfile = procure(key="vospace_certfile")
388
+ minoc_status = False
389
+ luskan_status = False
390
+ for index, url in enumerate(urls):
391
+ response = requests.get(url, cert=certfile, allow_redirects=True)
392
+ try:
393
+ response.raise_for_status()
394
+ authorised = response.headers.get("x-vo-authenticated")
395
+ if isinstance(authorised, str):
396
+ if index == 0:
397
+ minoc_status = True
398
+ else:
399
+ luskan_status = True
400
+ else:
401
+ raise TypeError
402
+ except HTTPError as error:
403
+ logger.error(error)
404
+ logger.error(f"{url.split('/')[3]} is down.")
405
+ except TypeError:
406
+ logger.error("Canfar certificate is not valid.")
407
+ return minoc_status, luskan_status
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "datatrail-cli"
3
- version = "0.7.0"
3
+ version = "0.7.2"
4
4
  description = "CHIME/FRB Datatrail CLI"
5
5
  authors = ["CHIME FRB Project Office"]
6
6
  license = "MIT"
File without changes
File without changes
File without changes