Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions fri/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

The Control-Core File Receiving Interface (FRI) is built with is Python-3.10. It is the core component that makes the distributed executions a reality in the Control-Core framework.

# Install Dependencies

Install Jupyter lab
````
$ pip install jupyterlab
````

# Building FRI Container

Expand Down
40 changes: 28 additions & 12 deletions fri/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ def upload(dir):
errors = {}
success = False

if not os.path.exists(secure_filename(dirname)):
os.makedirs(secure_filename(dirname))
cur_path = os.path.dirname(os.path.abspath(__file__))
concore_path = os.path.abspath(os.path.join(cur_path, '../../'))
directory_name = os.path.abspath(os.path.join(concore_path, secure_filename(dirname)))

if not os.path.isdir(directory_name):
os.mkdir(directory_name)


for file in files:
if file:
filename = secure_filename(file.filename)
file.save(secure_filename(dirname)+"/"+filename)
file.save(directory_name+"/"+filename)
success = True

if success and errors:
Expand Down Expand Up @@ -95,9 +100,11 @@ def execute(dir):
# to download /build/<dir>?fetch=<graphml>. For example, /build/test?fetch=sample1
@app.route('/build/<dir>', methods=['POST'])
def build(dir):
graphml_file = request.args.get('fetch')
makestudy_dir = dir+ "/" + graphml_file #for makestudy
cur_path = os.getcwd()
graphml_file = request.args.get('fetch')
apikey = request.args.get('apikey')
dirname = dir + "_" + apikey
makestudy_dir = dirname + "/" + graphml_file #for makestudy
cur_path = os.path.dirname(os.path.abspath(__file__))
concore_path = os.path.abspath(os.path.join(cur_path, '../../'))
dir_path = os.path.abspath(os.path.join(concore_path, graphml_file)) #path for ./build
if not os.path.exists(secure_filename(dir_path)):
Expand All @@ -114,12 +121,12 @@ def build(dir):

@app.route('/debug/<dir>', methods=['POST'])
def debug(dir):
cur_path = os.getcwd()
cur_path = os.path.dirname(os.path.abspath(__file__))
concore_path = os.path.abspath(os.path.join(cur_path, '../../'))
dir_path = os.path.abspath(os.path.join(concore_path, dir))
proc = call(["./debug"], cwd=dir_path)
if(proc == 0):
resp = jsonify({'message': 'Close the pop window after obtaing result'})
resp = jsonify({'message': 'Close the pop window after obtaining result'})
resp.status_code = 201
return resp
else:
Expand All @@ -134,13 +141,18 @@ def download(dir):
apikey = request.args.get('apikey')
Comment thread
pradeeban marked this conversation as resolved.
dirname = dir + "_" + apikey

cur_path = os.path.dirname(os.path.abspath(__file__))
concore_path = os.path.abspath(os.path.join(cur_path, '../../'))
directory_name = os.path.abspath(os.path.join(concore_path, secure_filename(dirname)))


if not os.path.exists(secure_filename(dirname)):
resp = jsonify({'message': 'Directory not found'})
resp.status_code = 400
return resp

try:
return send_from_directory(secure_filename(dirname), download_file, as_attachment=True)
return send_from_directory(directory_name, download_file, as_attachment=True)
except:
resp = jsonify({'message': 'file not found'})
resp.status_code = 400
Expand All @@ -149,7 +161,8 @@ def download(dir):

@app.route('/destroy/<dir>', methods=['DELETE'])
def destroy(dir):
cur_path = os.getcwd()
# cur_path = os.getcwd()
cur_path = os.path.dirname(os.path.abspath(__file__))
concore_path = os.path.abspath(os.path.join(cur_path, '../../'))
proc = call(["./destroy", dir], cwd=concore_path)
if(proc == 0):
Expand All @@ -163,7 +176,8 @@ def destroy(dir):

@app.route('/getFilesList/<dir>', methods=['POST'])
def getFilesList(dir):
cur_path = os.getcwd()
# cur_path = os.getcwd()
cur_path = os.path.dirname(os.path.abspath(__file__))
concore_path = os.path.abspath(os.path.join(cur_path, '../../'))
dir_path = os.path.abspath(os.path.join(concore_path, dir))
res = []
Expand All @@ -174,7 +188,9 @@ def getFilesList(dir):

@app.route('/openJupyter/', methods=['POST'])
def openJupyter():
cur_path = os.getcwd()
# cur_path = os.getcwd()
cur_path = os.path.dirname(os.path.abspath(__file__))
print(cur_path)
Comment thread
amit-62 marked this conversation as resolved.
Outdated
concore_path = os.path.abspath(os.path.join(cur_path, '../../'))
proc = subprocess.Popen(['jupyter', 'lab'], shell=False, stdout=subprocess.PIPE, cwd=concore_path)
if proc.poll() is None:
Expand Down
59 changes: 32 additions & 27 deletions fri/test.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from cgi import test
import requests
import os
import urllib.request

# function to test upload() method.
def upload():
url = "http://127.0.0.1:5000/upload/test?apikey=xyz"

path = os.path.abspath("example.py")
def upload(files):
url = "http://127.0.0.1:5000/upload/test?apikey=xyz"

payload={}
files=[
('files[]',('example.py',open(path,'rb'),'application/octet-stream'))
]
# files=[

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these commented out?

# ('files[]',('example.py',open(path,'rb'),'application/octet-stream'))
# ]
headers = {}

response = requests.request("POST", url, headers=headers, data=payload, files=files)
Expand All @@ -37,34 +37,28 @@ def execute():

print(response.text)

# function to test download() method.
def download():
url = "http://127.0.0.1:5000/download/test?fetch=f1.txt&apikey=xyz"
urllib.request.urlretrieve(url, "f1.txt")


# function to check build
def build():
url = "http://127.0.0.1:5000/build/test?fetch=sample1"
def build(dir, graphml, apikey):
url = "http://127.0.0.1:5000/build/"+dir+"?"+"fetch="+graphml+"&"+"apikey="+apikey
response = requests.request("POST", url)
print(response.text)

# function to debug
def debug():
url = "http://127.0.0.1:5000/debug/sample1"
def debug(graphml):
url = "http://127.0.0.1:5000/debug/"+graphml
response = requests.request("POST", url)
print(response.text)


#function to destroy dir.
def destroy():
url = "http://127.0.0.1:5000/destroy/sample1"
def destroy(dir):
url = "http://127.0.0.1:5000/destroy/" + dir
response = requests.request("DELETE", url)

print(response.text)

def getFilesList():
url = "http://127.0.0.1:5000/getFilesList/test"
def getFilesList(dir):
url = "http://127.0.0.1:5000/getFilesList/" + dir
response = requests.request("POST", url)
print(response.text)

Expand All @@ -73,13 +67,24 @@ def openJupyter():
response = requests.request("POST", url)
print(response.text)

# function to test download() method.
def download():
url = "http://127.0.0.1:5000/download/test?fetch=f1.txt&apikey=xyz"
urllib.request.urlretrieve(url, "f1.txt")

# file list to be uploaded
files=[
#('files[]',(file_name,open(file_path,'rb'),'application/octet-stream'))

]

# upload()
# execute()
# download()
# build()
# debug()
# destroy()
getFilesList()

upload(files)
execute()
build("test", "sample1", "xyz")
debug("sample1")
destroy("sample1")
# getFilesList("fri")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these two lines commented out?

# openJupyter()
# download()