Skip to content

Commit b4d3b65

Browse files
authored
Merge pull request #72 from ControlCore-Project/main
Bring dev to upto date.
2 parents 6c28e07 + 28afb1b commit b4d3b65

33 files changed

Lines changed: 2917 additions & 70 deletions

0mq/funcall2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
# ym = concore2.read(concore.iport['Y1'],"ym",init_simtime_ym)
2525
paired_transmitter = PairedTransmitter(
2626
remote_host="localhost", exposed_commands=[],
27+
#remote_host="193.136.132.10", exposed_commands=[],
2728
remote_port=2345, listen_port=2346,)
2829
paired_transmitter.start_background_sync()
2930
ym = paired_transmitter.request_with_immediate_reply(

concore.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,14 @@ def read(port, name, initstr):
7777
try:
7878
infile = open(inpath+str(port)+"/"+name);
7979
ins = infile.read()
80+
infile.close()
8081
except:
8182
ins = initstr
8283
while len(ins)==0:
8384
time.sleep(delay)
85+
infile = open(inpath+str(port)+"/"+name);
8486
ins = infile.read()
87+
infile.close()
8588
retrycount += 1
8689
s += ins
8790
inval = literal_eval(ins)
@@ -110,4 +113,3 @@ def initval(simtime_val):
110113
val = literal_eval(simtime_val)
111114
simtime = val[0]
112115
return val[1:]
113-

fri/DOCKER-README.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
# Install Docker:-
2+
3+
Open Terminal and run the following commands:-
4+
5+
````
6+
$ sudo apt-get update
7+
$ sudo apt-get install curl
8+
$ curl -fsSL https://get.docker.com/ | sh
9+
````
10+
Optional command:- To run docker commands without sudo
11+
````
12+
$ sudo usermod -aG docker <system_username>
13+
````
14+
The above command add the system username in the docker group, Restart the system to complete the process.
15+
16+
After restart run
17+
18+
````
19+
$ sudo service docker start
20+
````
21+
122
# Building FRI Container
223

324
Now, we elaborate on building FRI as a container, together with the Kong API Gateway.
@@ -15,7 +36,7 @@ First build the Docker Container of the FRI.
1536
````
1637
$ git pull
1738
18-
$ sudo docker build -t fri .
39+
$ docker build -t fri .
1940
````
2041

2142
# Running Control-Core FRI with Kong as containers
@@ -67,7 +88,7 @@ $ docker run -d --name kong \
6788

6889
Start FRI container
6990
````
70-
$ nohup sudo docker run --name fri -p 8090:8081 fri > controlcore.out &
91+
$ nohup sudo docker run --name fri -p 8090:8080 fri > controlcore.out &
7192
````
7293

7394
Delete if there is a previously configured Kong service. If not, skip this step. First you need to find the ID-VALUE for the route with a GET command before deleting the route and service.
@@ -107,17 +128,17 @@ $ tail -f controlcore.out
107128
````
108129
or
109130
````
110-
$ sudo docker logs fri -f
131+
$ docker logs fri -f
111132
````
112133
Find the FRI docker container
113134
````
114-
$ sudo docker ps
135+
$ docker ps
115136
````
116137
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
117138
dfdd3b3d3308 fri "python main.py" 38 minutes ago Up 38 minutes 0.0.0.0:80->80/tcp fri
118139

119140
Access the container
120141
````
121-
$ sudo docker exec -it dfdd /bin/bash
142+
$ docker exec -it dfdd /bin/bash
122143
````
123144

fri/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ The Control-Core File Receiving Interface (FRI) is built with is Python-3.10. It
44

55
# Install Dependencies
66

7-
Install Jupyter lab
87
````
9-
$ pip install jupyterlab
8+
$ cd conore/fri
9+
10+
$ pip3 install -r requirements.txt
1011
````
1112

1213
# Running the FRI and a quick test.
@@ -15,8 +16,6 @@ To run the FRI as a server:
1516
````
1617
$ cd conore/fri
1718
18-
$ git checkout dev
19-
2019
$ cd server
2120
2221
$ python3 main.py

fri/docker-compose.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: '3'
2+
3+
services:
4+
fri:
5+
build:
6+
context: .
7+
image: fri
8+
ports:
9+
- 8090:8080
10+
command: tail -f /dev/null
11+
12+
kong-database:
13+
image: cassandra:3
14+
ports:
15+
- 9042:9042
16+
17+
kong:
18+
image: kong
19+
depends_on:
20+
- kong-database
21+
environment:
22+
KONG_DATABASE: cassandra
23+
KONG_PG_HOST: kong-database
24+
KONG_PG_PASSWORD: kong
25+
KONG_CASSANDRA_CONTACT_POINTS: kong-database
26+
KONG_PROXY_ACCESS_LOG: /dev/stdout
27+
KONG_ADMIN_ACCESS_LOG: /dev/stdout
28+
KONG_PROXY_ERROR_LOG: /dev/stderr
29+
KONG_ADMIN_ERROR_LOG: /dev/stderr
30+
KONG_ADMIN_LISTEN: 0.0.0.0:8001, 0.0.0.0:8444 ssl
31+
ports:
32+
- 80:8000
33+
- 8443:8443
34+
- 8001:8001
35+
- 8444:8444
36+
37+

fri/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Flask
22
gunicorn==20.1.0
33
FLASK_CORS
4+
jupyterlab

fri/server/main.py

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from flask import Flask, request, jsonify, send_file, send_from_directory
22
from werkzeug.utils import secure_filename
33
import os
4+
import subprocess
45
from subprocess import call
56
from pathlib import Path
67
import json
7-
import subprocess
8+
import platform
89
from flask_cors import CORS, cross_origin
910

1011
cur_path = os.path.dirname(os.path.abspath(__file__))
@@ -21,8 +22,10 @@
2122
@app.route('/upload/<dir>', methods=['POST'])
2223
def upload(dir):
2324
apikey = request.args.get('apikey')
24-
dirname = secure_filename(dir) + "_" + apikey
25-
25+
if(apikey == None):
26+
dirname = secure_filename(dir)
27+
else:
28+
dirname = secure_filename(dir) + "_" + apikey
2629
if 'files[]' not in request.files:
2730
resp = jsonify({'message': 'No file in the request'})
2831
resp.status_code = 400
@@ -38,7 +41,6 @@ def upload(dir):
3841
if not os.path.isdir(directory_name):
3942
os.mkdir(directory_name)
4043

41-
4244
for file in files:
4345
if file:
4446
filename = secure_filename(file.filename)
@@ -60,32 +62,52 @@ def upload(dir):
6062
return resp
6163

6264

63-
6465
# to download /build/<dir>?fetch=<graphml>. For example, /build/test?fetch=sample1&apikey=xyz
6566
@app.route('/build/<dir>', methods=['POST'])
6667
def build(dir):
6768
graphml_file = request.args.get('fetch')
6869
apikey = request.args.get('apikey')
69-
dirname = secure_filename(dir) + "_" + apikey
70+
out_dir = request.args.get('outdir')
71+
if(apikey == None):
72+
dirname = secure_filename(dir)
73+
else:
74+
dirname = secure_filename(dir) + "_" + apikey
7075
makestudy_dir = dirname + "/" + graphml_file #for makestudy
71-
dir_path = os.path.abspath(os.path.join(concore_path, graphml_file)) #path for ./build
76+
if(out_dir == None or out_dir == ""):
77+
dir_path = os.path.abspath(os.path.join(concore_path, graphml_file)) #path for ./build
78+
else:
79+
dir_path = os.path.abspath(os.path.join(concore_path, out_dir)) #path for ./build
7280
if not os.path.exists(dir_path):
73-
proc = call(["./makestudy", makestudy_dir], cwd=concore_path)
81+
if(platform.uname()[0]=='Windows'):
82+
if(out_dir == None or out_dir == ""):
83+
proc= call(["makestudy", makestudy_dir], shell=True, cwd=concore_path)
84+
else:
85+
proc= call(["makestudy", makestudy_dir, out_dir], shell=True, cwd=concore_path)
86+
else:
87+
if(out_dir == None or out_dir == ""):
88+
proc= call(["./makestudy", makestudy_dir], cwd=concore_path)
89+
else:
90+
proc= call(["./makestudy", makestudy_dir, out_dir], cwd=concore_path)
7491
if(proc == 0):
7592
resp = jsonify({'message': 'Directory successfully created'})
7693
resp.status_code = 201
7794
else:
7895
resp = jsonify({'message': 'There is an Error'})
79-
resp.status_code = 500
80-
call(["./build"], cwd=dir_path)
96+
resp.status_code = 500
97+
if(platform.uname()[0]=='Windows'):
98+
call(["build"], cwd=dir_path, shell=True)
99+
else:
100+
call(["./build"], cwd=dir_path)
81101
return resp
82102

83-
84103
@app.route('/debug/<dir>', methods=['POST'])
85104
def debug(dir):
86-
dir = secure_filename(dir)
87-
dir_path = os.path.abspath(os.path.join(concore_path, dir))
88-
proc = call(["./debug"], cwd=dir_path)
105+
dir_name = secure_filename(dir)
106+
dir_path = os.path.abspath(os.path.join(concore_path, dir_name))
107+
if(platform.uname()[0]=='Windows'):
108+
proc=call(["debug"],shell=True, cwd=dir_path)
109+
else:
110+
proc = call(["./debug"], cwd=dir_path)
89111
if(proc == 0):
90112
resp = jsonify({'message': 'Close the pop window after obtaining result'})
91113
resp.status_code = 201
@@ -95,12 +117,14 @@ def debug(dir):
95117
resp.status_code = 500
96118
return resp
97119

98-
99120
@app.route('/run/<dir>', methods=['POST'])
100121
def run(dir):
101-
dir = secure_filename(dir)
102-
dir_path = os.path.abspath(os.path.join(concore_path, dir))
103-
proc = call(["./run"], cwd=dir_path)
122+
dir_name = secure_filename(dir)
123+
dir_path = os.path.abspath(os.path.join(concore_path, dir_name))
124+
if(platform.uname()[0]=='Windows'):
125+
proc=call(["run"],shell=True, cwd=dir_path)
126+
else:
127+
proc = call(["./run"], cwd=dir_path)
104128
if(proc == 0):
105129
resp = jsonify({'message': 'result prepared'})
106130
resp.status_code = 201
@@ -112,9 +136,12 @@ def run(dir):
112136

113137
@app.route('/stop/<dir>', methods=['POST'])
114138
def stop(dir):
115-
dir = secure_filename(dir)
116-
dir_path = os.path.abspath(os.path.join(concore_path, dir))
117-
proc = call(["./stop"], cwd=dir_path)
139+
dir_name = secure_filename(dir)
140+
dir_path = os.path.abspath(os.path.join(concore_path, dir_name))
141+
if(platform.uname()[0]=='Windows'):
142+
proc=call(["stop"],shell=True, cwd=dir_path)
143+
else:
144+
proc = call(["./stop"], cwd=dir_path)
118145
if(proc == 0):
119146
resp = jsonify({'message': 'resources cleaned'})
120147
resp.status_code = 201
@@ -127,9 +154,12 @@ def stop(dir):
127154

128155
@app.route('/clear/<dir>', methods=['POST'])
129156
def clear(dir):
130-
dir = secure_filename(dir)
131-
dir_path = os.path.abspath(os.path.join(concore_path, dir))
132-
proc = call(["./clear"], cwd=dir_path)
157+
dir_name = secure_filename(dir)
158+
dir_path = os.path.abspath(os.path.join(concore_path, dir_name))
159+
if(platform.uname()[0]=='Windows'):
160+
proc=call(["clear"],shell=True, cwd=dir_path)
161+
else:
162+
proc = call(["./clear"], cwd=dir_path)
133163
if(proc == 0):
134164
resp = jsonify({'message': 'result deleted'})
135165
resp.status_code = 201
@@ -157,11 +187,13 @@ def download(dir):
157187
resp.status_code = 400
158188
return resp
159189

160-
161190
@app.route('/destroy/<dir>', methods=['DELETE'])
162191
def destroy(dir):
163192
dir = secure_filename(dir)
164-
proc = call(["./destroy", dir], cwd=concore_path)
193+
if(platform.uname()[0]=='Windows'):
194+
proc=call(["destroy", dir],shell=True, cwd=concore_path)
195+
else:
196+
proc = call(["./destroy", dir], cwd=concore_path)
165197
if(proc == 0):
166198
resp = jsonify({'message': 'Successfuly deleted Dirctory'})
167199
resp.status_code = 201
@@ -181,7 +213,6 @@ def getFilesList(dir):
181213
res = json.dumps(res)
182214
return res
183215

184-
185216
@app.route('/openJupyter/', methods=['POST'])
186217
def openJupyter():
187218
proc = subprocess.Popen(['jupyter', 'lab'], shell=False, stdout=subprocess.PIPE, cwd=concore_path)
@@ -195,6 +226,5 @@ def openJupyter():
195226
return resp
196227

197228

198-
199229
if __name__ == "__main__":
200230
app.run(host="0.0.0.0", port=5000)

0 commit comments

Comments
 (0)