Skip to content

Commit 3682ced

Browse files
Add script to initialize Niagara
1 parent 0ec0c52 commit 3682ced

File tree

1 file changed

+40
-14
lines changed

1 file changed

+40
-14
lines changed

ush/python/pygfs/task/globus_hpss.py

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import os
44
from logging import getLogger
5-
from pathlib import Path
5+
import shutil
66
from time import sleep
77
from typing import Any, Dict, List
88
import re
@@ -54,6 +54,8 @@ def __init__(self, config: Dict[str, Any]) -> None:
5454
# Disable strict host key checking by default
5555
# This auto-accepts changes to keys
5656
self.scp.add_default_arg("-oStrictHostKeyChecking=no")
57+
# Force using publickey login
58+
self.scp.add_default_arg("-oPreferredAuthentication=publickey")
5759

5860
# Get the user's server username from their ~/.ssh/config file
5961
server_name = self.task_config.SERVER_NAME
@@ -74,7 +76,7 @@ def __init__(self, config: Dict[str, Any]) -> None:
7476

7577
# Update the home directory on the server with the username
7678
server_home = self.task_config.SERVER_HOME.replace(
77-
"{{LOGNAME}}", server_username
79+
"{{SERVER_USERNAME}}", server_username
7880
)
7981

8082
logger.debug(f"Server username detected as {server_username}")
@@ -162,7 +164,10 @@ def configure(self, globus_dict: Dict[str, Any]) -> (Dict[str, Any], List[Dict[s
162164
dm_conf = f'export dropbox="{globus_dict.sven_dropbox}"'
163165

164166
# Make the dropbox and clean it out
165-
Path(globus_dict.sven_dropbox).mkdir(exist_ok=True)
167+
if os.path.exists(globus_dict.sven_dropbox):
168+
shutil.rmtree(globus_dict.sven_dropbox)
169+
170+
os.mkdir(globus_dict.sven_dropbox)
166171

167172
# Parse the return script
168173
return_jinja = os.path.join(globus_parm, "return.sh.j2")
@@ -187,11 +192,8 @@ def configure(self, globus_dict: Dict[str, Any]) -> (Dict[str, Any], List[Dict[s
187192
transfer_sets[transfer_set]["dm.conf"] = dm_conf
188193
transfer_sets[transfer_set]["return"] = return_script
189194
transfer_sets[transfer_set]["verify"] = vrfy_script
190-
transfer_sets[transfer_set]["sven_dropbox"] = globus_dict.sven_dropbox
191-
transfer_sets[transfer_set]["server_name"] = globus_dict.SERVER_NAME
192-
transfer_sets[transfer_set]["server_homedir"] = (
193-
f"{globus_dict.server_home}/doorman/{globus_dict.jobid}/"
194-
f"{transfer_set}"
195+
transfer_sets[transfer_set]["server_job_dir"] = (
196+
f"{globus_dict.server_home}/doorman/globus.{globus_dict.jobid}/{transfer_set}"
195197
)
196198

197199
return transfer_sets
@@ -220,20 +222,25 @@ def execute_transfer_data(self, transfer_set: Dict[str, Any], has_rstprod: bool)
220222
return_f.write(transfer_set["return"])
221223
with open("run_doorman.sh", "w") as doorman_f:
222224
doorman_f.write(transfer_set["run_doorman.sh"])
225+
with open("init_xfer.sh", "w") as init_f:
226+
init_f.write(transfer_set["init_xfer.sh"])
227+
228+
server_job_dir = transfer_set["server_job_dir"]
229+
230+
# Initialize the server
231+
self._init_server(server_job_dir)
223232

224233
# Make run_doorman.sh executable
225234
os.chmod("run_doorman.sh", 0o740)
226235

227-
server_homedir = transfer_set["server_homedir"]
228-
server_name = transfer_set["server_name"]
236+
server_name = self.task_config.SERVER_NAME
229237

230238
# Initialize a list of status files.
231239
transfer_set["statuses"] = []
232240
transfer_set["completed"] = []
233241

234242
# Tell Sven we have files to send, one at a time
235243
for location in transfer_set["locations"]:
236-
print(location)
237244
with open("location", "w") as location_f:
238245
location_f.write(location + "\n")
239246
try:
@@ -245,7 +252,7 @@ def execute_transfer_data(self, transfer_set: Dict[str, Any], has_rstprod: bool)
245252

246253
# Parse Sven's output to get the name of the return status file
247254
match = re.search("\"(status_.*)\" in your dropbox", sven_output)
248-
transfer_set["status_files"].append(os.path.join(transfer_set["sven_dropbox"], match.group(1)))
255+
transfer_set["status_files"].append(os.path.join(self.task_config.sven_dropbox, match.group(1)))
249256

250257
# Initialize 'completed' to false for each file
251258
transfer_set["completed"].append(False)
@@ -254,7 +261,7 @@ def execute_transfer_data(self, transfer_set: Dict[str, Any], has_rstprod: bool)
254261
# Note, this assumes we have unattended transfer capability.
255262
try:
256263
# Now transfer and rename the script
257-
server_run_script = f"{server_homedir}/doorman_rundir/run_doorman.sh"
264+
server_run_script = f"{server_job_dir}/run_doorman.sh"
258265
logger.debug(f"Transfer run_doorman.sh to {server_name}:{server_run_script}")
259266
self.scp(
260267
"run_doorman.sh", f"{server_name}:{server_run_script}",
@@ -313,7 +320,7 @@ def execute_transfer_data(self, transfer_set: Dict[str, Any], has_rstprod: bool)
313320

314321
# Retrieve and print the Doorman log file from the server
315322
try:
316-
self.scp(f"{server_name}:{server_homedir}/run_doorman.log", '.')
323+
self.scp(f"{server_name}:{server_job_dir}/run_doorman.log", '.')
317324
with open('run_doorman.log', 'r') as doorman_log:
318325
logger.info(doorman_log.read())
319326

@@ -326,6 +333,25 @@ def execute_transfer_data(self, transfer_set: Dict[str, Any], has_rstprod: bool)
326333

327334
return
328335

336+
@logit(logger)
337+
def _init_server(job_dir: str):
338+
# This method sends a request to create a working directory and transfers
339+
# the initialization script.
340+
341+
req_file = f"req_mkdir.{self.task_config.jobid}"
342+
with open(f"req_mkdir.{self.task_config.jobid}") as mkdir_f:
343+
mkdir_f.write(f"{job_dir}")
344+
345+
self.scp(req_file, f"{self.task_config.SERVER_NAME}:{self.task_config.server_home}/{req_file}")
346+
347+
self.scp(
348+
"init_xfer.sh",
349+
f"{self.task_config.SERVER_NAME}:{self.task_config.server_home}/init_xfer_{self.task_config.PSLOT}.sh"
350+
)
351+
352+
logger.info("Sleeping 1 minute to let the server initialize")
353+
sleep(300)
354+
329355
@logit(logger)
330356
def clean(self):
331357
"""

0 commit comments

Comments
 (0)