-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudify_references_tape.py
More file actions
executable file
·77 lines (66 loc) · 2.03 KB
/
Copy pathcloudify_references_tape.py
File metadata and controls
executable file
·77 lines (66 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ssl_keyfile="/work/bm0021/k204210/cloudify/workshop/key.pem"
#ssl_certfile="/work/bm0021/k204210/cloudify/workshop/cert.pem"
from cloudify.utils.daskhelper import *
from cloudify.plugins.kerchunk import *
import xarray as xr
import xpublish as xp
import asyncio
import sys
import os
import socket
import fsspec
from contextlib import closing
SO=dict(
remote_protocol="slk",
remote_options=dict(
slk_cache="/scratch/k/k202134/INTAKE_CACHE"
),
lazy=True,
cache_size=0
)
def find_free_port_in_range(start=9000, end=9100):
for port in range(start, end + 1):
try:
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
s.bind(('', port))
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
return port
except:
continue
raise RuntimeError("No free port found in the specified range.")
if __name__ == "__main__": # This avoids infinite subprocess creation
#import dask
#zarrcluster = asyncio.get_event_loop().run_until_complete(get_dask_cluster())
#os.environ["ZARR_ADDRESS"]=zarrcluster.scheduler._address
dsname=sys.argv[1]
glob_inp=sys.argv[2]
dsdict={}
mapper_dict={}
source="reference::/"+glob_inp
fsmap = fsspec.get_mapper(
source,
**SO
)
ds=xr.open_dataset(
fsmap,
engine="zarr",
chunks="auto",
consolidated=False
)
mapper_dict[source]=fsmap
ds=ds.drop_encoding()
ds.encoding["source"]=source
dsdict[dsname]=ds
kp = KerchunkPlugin()
kp.mapper_dict = mapper_dict
collection = xp.Rest(dsdict)
collection.register_plugin(kp)
freeport=find_free_port_in_range()
listen_uri_fn=f"{os.environ['HOSTNAME']}_{freeport}"
with open(listen_uri_fn, "w"):
collection.serve(
host="0.0.0.0",
port=freeport,
#ssl_keyfile=ssl_keyfile,
#ssl_certfile=ssl_certfile
)