Last active
June 14, 2019 17:44
-
-
Save TakahisaShiratori/6c45b7383f3d8f86cd1237208689ba31 to your computer and use it in GitHub Desktop.
Submit OpenFOAM Job with Rescale API and CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "OpenFOAM Buoyant Cavity", | |
"jobanalyses": [ | |
{ | |
"analysis": { | |
"code": "openfoam_plus", | |
"version": "v1712+-intelmpi" | |
}, | |
"hardware": { | |
"coresPerSlot": 1, | |
"coreType": "hpc-3" | |
}, | |
"command": "cd buoyantCavity/\n./Allrun", | |
"inputFiles": [ | |
{ | |
"id": "hoge" | |
} | |
] | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
import subprocess | |
import sys | |
import time | |
from datetime import datetime | |
api_token = "a0************************************4b" | |
token_in_header = "Token " + api_token | |
platform = "platform.rescale.com" | |
job_configuration_file = "openfoam_jobconfig.json" | |
job_configuration = json.load(open(job_configuration_file, "r")) | |
input_filename = "buoyantCavity.zip" | |
print("# Uploading " + input_filename) | |
cmd = "java -jar ./rescale.jar -X https://{platform}/ upload -p {api_token} -f {input_filename} -e".format(platform=platform, api_token=api_token, input_filename=input_filename) | |
raw_reply = subprocess.check_output(cmd, shell=True) | |
stdout_list = raw_reply.splitlines() | |
uploaded_file = json.loads(stdout_list[len(stdout_list)-1])["files"][0] | |
print("- File ID: " + uploaded_file["id"]) | |
print("# Creating Job") | |
job_configuration["jobanalyses"][0]["inputFiles"][0]["id"] = uploaded_file["id"] | |
raw_reply = requests.post( | |
"https://" + platform + "/api/v2/jobs/", | |
headers={"Authorization": token_in_header}, | |
json=job_configuration | |
) | |
created_job = json.loads(raw_reply.text) | |
print("- Job ID: " + created_job["id"]) | |
print("# Submitting the Job") | |
requests.post( | |
"https://" + platform + "/api/v2/jobs/" + created_job["id"] + "/submit/", | |
headers={"Authorization": token_in_header} | |
) | |
print("# Executing the Job") | |
while True: | |
time.sleep(5) | |
raw_reply = requests.get( | |
"https://" + platform + "/api/v2/jobs/" + created_job["id"] + "/statuses/", | |
headers={'Authorization': token_in_header} | |
) | |
job_status = json.loads(raw_reply.text)["results"][0]["status"] | |
current_time = datetime.now().strftime("%Y/%m/%d %H:%M:%S") | |
sys.stdout.write("\r- [" + current_time + "] Job Status: " + job_status) | |
sys.stdout.flush() | |
if job_status == "Completed": | |
break | |
print("\n# Done!!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
import subprocess | |
import sys | |
import time | |
from datetime import datetime | |
api_token = "a0************************************4b" | |
token_in_header = "Token " + api_token | |
platform = "platform.rescale.jp" | |
job_configuration_file = "openfoam_jobconfig.json" | |
job_configuration = json.load(open(job_configuration_file, "r")) | |
input_filename = "buoyantCavity.zip" | |
print("# Uploading " + input_filename) | |
cmd = "java -jar ./rescale.jar -X https://{platform}/ upload -p {api_token} -f {input_filename} -e".format(platform=platform, api_token=api_token, input_filename=input_filename) | |
raw_reply = subprocess.check_output(cmd, shell=True) | |
stdout_list = raw_reply.splitlines() | |
uploaded_file = json.loads(stdout_list[len(stdout_list)-1])["files"][0] | |
print("- File ID: " + uploaded_file["id"]) | |
print("# Creating Job") | |
job_configuration["jobanalyses"][0]["inputFiles"][0]["id"] = uploaded_file["id"] | |
raw_reply = requests.post( | |
"https://" + platform + "/api/v2/jobs/", | |
headers={"Authorization": token_in_header}, | |
json=job_configuration | |
) | |
created_job = json.loads(raw_reply.text) | |
print("- Job ID: " + created_job["id"]) | |
print("# Submitting the Job") | |
requests.post( | |
"https://" + platform + "/api/v2/jobs/" + created_job["id"] + "/submit/", | |
headers={"Authorization": token_in_header} | |
) | |
print("# Executing the Job") | |
while True: | |
time.sleep(5) | |
raw_reply = requests.get( | |
"https://" + platform + "/api/v2/jobs/" + created_job["id"] + "/statuses/", | |
headers={'Authorization': token_in_header} | |
) | |
job_status = json.loads(raw_reply.text)["results"][0]["status"] | |
current_time = datetime.now().strftime("%Y/%m/%d %H:%M:%S") | |
sys.stdout.write("\r- [" + current_time + "] Job Status: " + job_status) | |
sys.stdout.flush() | |
if job_status == "Completed": | |
break | |
print("\n# Done!!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
import subprocess | |
import sys | |
import time | |
from datetime import datetime | |
api_token = "a0************************************4b" | |
token_in_header = "Token " + api_token | |
platform = "kr.rescale.com" | |
job_configuration_file = "openfoam_jobconfig.json" | |
job_configuration = json.load(open(job_configuration_file, "r")) | |
input_filename = "buoyantCavity.zip" | |
print("# Uploading " + input_filename) | |
cmd = "java -jar ./rescale.jar -X https://{platform}/ upload -p {api_token} -f {input_filename} -e".format(platform=platform, api_token=api_token, input_filename=input_filename) | |
raw_reply = subprocess.check_output(cmd, shell=True) | |
stdout_list = raw_reply.splitlines() | |
uploaded_file = json.loads(stdout_list[len(stdout_list)-1])["files"][0] | |
print("- File ID: " + uploaded_file["id"]) | |
print("# Creating Job") | |
job_configuration["jobanalyses"][0]["inputFiles"][0]["id"] = uploaded_file["id"] | |
raw_reply = requests.post( | |
"https://" + platform + "/api/v2/jobs/", | |
headers={"Authorization": token_in_header}, | |
json=job_configuration | |
) | |
created_job = json.loads(raw_reply.text) | |
print("- Job ID: " + created_job["id"]) | |
print("# Submitting the Job") | |
requests.post( | |
"https://" + platform + "/api/v2/jobs/" + created_job["id"] + "/submit/", | |
headers={"Authorization": token_in_header} | |
) | |
print("# Executing the Job") | |
while True: | |
time.sleep(5) | |
raw_reply = requests.get( | |
"https://" + platform + "/api/v2/jobs/" + created_job["id"] + "/statuses/", | |
headers={'Authorization': token_in_header} | |
) | |
job_status = json.loads(raw_reply.text)["results"][0]["status"] | |
current_time = datetime.now().strftime("%Y/%m/%d %H:%M:%S") | |
sys.stdout.write("\r- [" + current_time + "] Job Status: " + job_status) | |
sys.stdout.flush() | |
if job_status == "Completed": | |
break | |
print("\n# Done!!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使い方はこちらに書きました
RescaleでOpenFOAMのBuoyant Cavityを実行するTutorial - Qiita
https://qiita.com/takashiratori/items/fe6e8344aa2d1b2e7eb5