@@ -1,3 +1,4 | |||||
1 | MADROOT=/madrigal |
|
1 | MADROOT=/madrigal | |
2 |
EXP_DIR=/ |
|
2 | EXP_DIR=/data/madrigal/experiments | |
3 | MAD_PORT=8080 |
|
3 | META_DIR=/data/madrigal/metadata | |
|
4 | MAD_PORT=80 |
@@ -1,27 +1,28 | |||||
1 | version: '3' |
|
1 | version: '3' | |
2 |
|
2 | |||
3 | services: |
|
3 | services: | |
4 | web: |
|
4 | web: | |
5 | container_name: 'madrigal' |
|
5 | container_name: 'madrigal' | |
6 | build: . |
|
6 | build: . | |
7 | restart: always |
|
7 | restart: always | |
8 | image: madrigal |
|
8 | image: madrigal | |
9 | working_dir: /madrigal/source/madpy/djangoMad |
|
9 | working_dir: /madrigal/source/madpy/djangoMad | |
10 | command: gunicorn djangoMad.wsgi --bind 0.0.0.0:8000 |
|
10 | command: gunicorn djangoMad.wsgi --timeout 600 --bind 0.0.0.0:8000 | |
11 | env_file: .env |
|
11 | env_file: .env | |
12 | volumes: |
|
12 | volumes: | |
13 | - '${EXP_DIR}:/madrigal/experiments' |
|
13 | - '${EXP_DIR}:/madrigal/experiments' | |
|
14 | - '${META_DIR}:/madrigal/metadata' | |||
14 | - './source/madpy/djangoMad:/madrigal/source/madpy/djangoMad' |
|
15 | - './source/madpy/djangoMad:/madrigal/source/madpy/djangoMad' | |
15 |
|
16 | |||
16 | nginx: |
|
17 | nginx: | |
17 | container_name: 'madrigal-nginx' |
|
18 | container_name: 'madrigal-nginx' | |
18 | image: nginx:1.15-alpine |
|
19 | image: nginx:1.15-alpine | |
19 | volumes: |
|
20 | volumes: | |
20 | - ./source/madpy/djangoMad/static_files:/static |
|
21 | - ./source/madpy/djangoMad/static_files:/static | |
21 | - ./nginx:/etc/nginx/conf.d |
|
22 | - ./nginx:/etc/nginx/conf.d | |
22 | ports: |
|
23 | ports: | |
23 | - "${MAD_PORT}:8080" |
|
24 | - "${MAD_PORT}:8080" | |
24 | depends_on: |
|
25 | depends_on: | |
25 | - web |
|
26 | - web | |
26 | command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'" |
|
27 | command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'" | |
27 |
|
28 |
@@ -1,22 +1,26 | |||||
1 | # configuration |
|
1 | # configuration | |
2 |
|
2 | |||
3 | upstream djangomad { |
|
3 | upstream djangomad { | |
4 | server web:8000; |
|
4 | server web:8000; | |
5 | } |
|
5 | } | |
6 |
|
6 | |||
7 | server { |
|
7 | server { | |
8 | listen 8080; |
|
8 | listen 8080; | |
9 |
client_max_body_size |
|
9 | client_max_body_size 100M; | |
10 |
|
10 | |||
11 | location /madrigal { |
|
11 | location /madrigal { | |
12 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|
12 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
13 | proxy_set_header Host $host; |
|
13 | proxy_set_header Host $host; | |
14 | proxy_redirect off; |
|
14 | proxy_redirect off; | |
15 | proxy_set_header X-Script-Name /madrigal; |
|
15 | proxy_set_header X-Script-Name /madrigal; | |
16 | proxy_pass http://djangomad; |
|
16 | proxy_pass http://djangomad; | |
17 | } |
|
17 | } | |
18 |
|
18 | |||
19 | location /madrigal/static/ { |
|
19 | location /madrigal/static/ { | |
20 | alias /static/; |
|
20 | alias /static/; | |
21 | } |
|
21 | } | |
|
22 | proxy_connect_timeout 600; | |||
|
23 | proxy_send_timeout 600; | |||
|
24 | proxy_read_timeout 600; | |||
|
25 | send_timeout 600; | |||
22 | } |
|
26 | } |
@@ -1,115 +1,115 | |||||
1 |
|
1 | |||
2 | from django.contrib.auth.decorators import login_required |
|
2 | from django.contrib.auth.decorators import login_required | |
3 | from django.shortcuts import render |
|
3 | from django.shortcuts import render | |
4 | from apps.updata.forms import UpdataForm, ExpForm |
|
4 | from apps.updata.forms import UpdataForm, ExpForm | |
5 | from django.core.files.storage import FileSystemStorage |
|
5 | from django.core.files.storage import FileSystemStorage | |
6 | from django.contrib import messages |
|
6 | from django.contrib import messages | |
7 |
|
7 | |||
8 | import os |
|
8 | import os | |
9 |
|
9 | |||
10 | # madrigal imports |
|
10 | # madrigal imports | |
11 | import madrigal.metadata |
|
11 | import madrigal.metadata | |
12 | import madrigal.ui.web |
|
12 | import madrigal.ui.web | |
13 | import madrigal.admin |
|
13 | import madrigal.admin | |
14 |
|
14 | |||
15 | @login_required(login_url='/madrigal/accounts/login/') |
|
15 | @login_required(login_url='/madrigal/accounts/login/') | |
16 | def index(request): |
|
16 | def index(request): | |
17 | ''' |
|
17 | ''' | |
18 | Uploading experiments data view. Allows user to upload experiment files |
|
18 | Uploading experiments data view. Allows user to upload experiment files | |
19 |
|
19 | |||
20 | ''' |
|
20 | ''' | |
21 | dbAdminObj = madrigal.admin.MadrigalDBAdmin() |
|
21 | dbAdminObj = madrigal.admin.MadrigalDBAdmin() | |
22 | madDB = madrigal.metadata.MadrigalDB() |
|
22 | madDB = madrigal.metadata.MadrigalDB() | |
23 | madWebObj = madrigal.ui.web.MadrigalWeb(madDB) |
|
23 | madWebObj = madrigal.ui.web.MadrigalWeb(madDB) | |
24 | siteName, siteList = madWebObj.getSiteInfo() |
|
24 | siteName, siteList = madWebObj.getSiteInfo() | |
25 | err = False |
|
25 | err = False | |
26 | if request.method == 'POST': |
|
26 | if request.method == 'POST': | |
27 | form = UpdataForm(request.POST, request.FILES) |
|
27 | form = UpdataForm(request.POST, request.FILES) | |
28 | files = request.FILES.getlist('file') |
|
28 | files = request.FILES.getlist('file') | |
29 | files.sort() |
|
29 | #files.sort() | |
30 | filenames = [] |
|
30 | filenames = [] | |
31 |
|
31 | |||
32 | choose = request.POST.get('choose') |
|
32 | choose = request.POST.get('choose') | |
33 | if choose == 'new': |
|
33 | if choose == 'new': | |
34 | instCode = int(request.POST.get('inst')) |
|
34 | instCode = int(request.POST.get('inst')) | |
35 | expTitle = request.POST.get('exp') |
|
35 | expTitle = request.POST.get('exp') | |
36 | else: |
|
36 | else: | |
37 | instCode = int(request.POST.get('instruments')) |
|
37 | instCode = int(request.POST.get('instruments')) | |
38 | expId = request.POST.get('experiments') |
|
38 | expId = request.POST.get('experiments') | |
39 | madExp = madrigal.metadata.MadrigalExperiment() |
|
39 | madExp = madrigal.metadata.MadrigalExperiment() | |
40 | expTitle = madExp.getExpNameByExpId(expId) |
|
40 | expTitle = madExp.getExpNameByExpId(expId) | |
41 |
|
41 | |||
42 | description = request.POST.get('description') |
|
42 | description = request.POST.get('description') | |
43 | perm = int(request.POST.get('permission')) |
|
43 | perm = int(request.POST.get('permission')) | |
44 | optchar = request.POST.get('optchar').strip() |
|
44 | optchar = request.POST.get('optchar').strip() | |
45 | first = True |
|
45 | first = True | |
46 | for f in files: |
|
46 | for f in files: | |
47 | fs = FileSystemStorage(location='/tmp') |
|
47 | fs = FileSystemStorage(location='/tmp') | |
48 | fs.save(f.name, f) |
|
48 | fs.save(f.name, f) | |
49 | filename = os.path.join('/tmp', f.name) |
|
49 | filename = os.path.join('/tmp', f.name) | |
50 | ext = filename.split('.')[-1] |
|
50 | ext = filename.split('.')[-1] | |
51 | if ext not in ('hdf5', 'h5'): |
|
51 | if ext not in ('hdf5', 'h5'): | |
52 | convert = True |
|
52 | convert = True | |
53 | else: |
|
53 | else: | |
54 | convert = False |
|
54 | convert = False | |
55 |
|
55 | |||
56 | if first: |
|
56 | if first: | |
57 | first = False |
|
57 | first = False | |
58 | try: |
|
58 | try: | |
59 | expDir = dbAdminObj.createMadrigalExperiment(filename, expTitle, perm, description, |
|
59 | expDir = dbAdminObj.createMadrigalExperiment(filename, expTitle, perm, description, | |
60 | instCode, optChar=optchar, updateToMad3=convert) |
|
60 | instCode, optChar=optchar, updateToMad3=convert) | |
61 | except Exception as e: |
|
61 | except Exception as e: | |
62 | err = True |
|
62 | err = True | |
63 | messages.error(request, |
|
63 | messages.error(request, | |
64 | 'An error occur creating the experiment {}: {}'.format(expTitle, e) |
|
64 | 'An error occur creating the experiment {}: {}'.format(expTitle, e) | |
65 | ) |
|
65 | ) | |
66 | break |
|
66 | break | |
67 | else: |
|
67 | else: | |
68 | try: |
|
68 | try: | |
69 | dbAdminObj.addMadrigalFile(expDir, filename, perm, description, updateToMad3=convert) |
|
69 | dbAdminObj.addMadrigalFile(expDir, filename, perm, description, updateToMad3=convert) | |
70 | except Exception as e: |
|
70 | except Exception as e: | |
71 | err = True |
|
71 | err = True | |
72 | messages.error(request, |
|
72 | messages.error(request, | |
73 | 'An error occur adding file {}: {}'.format(filename.split('/')[-1], e) |
|
73 | 'An error occur adding file {}: {}'.format(filename.split('/')[-1], e) | |
74 | ) |
|
74 | ) | |
75 |
|
75 | |||
76 | filenames.append(filename.split('/')[-1]) |
|
76 | filenames.append(filename.split('/')[-1]) | |
77 | os.remove(filename) |
|
77 | os.remove(filename) | |
78 |
|
78 | |||
79 | if not err: |
|
79 | if not err: | |
80 | messages.success(request, |
|
80 | messages.success(request, | |
81 | 'Experiment {} created succesfully with files: {}'.format(expTitle, filenames) |
|
81 | 'Experiment {} created succesfully with files: {}'.format(expTitle, filenames) | |
82 | ) |
|
82 | ) | |
83 |
|
83 | |||
84 | madInstParams = madrigal.metadata.MadrigalInstrumentParameters() |
|
84 | madInstParams = madrigal.metadata.MadrigalInstrumentParameters() | |
85 | madInstKindats = madrigal.metadata.MadrigalInstrumentKindats() |
|
85 | madInstKindats = madrigal.metadata.MadrigalInstrumentKindats() | |
86 |
|
86 | |||
87 | print('*** Updating local metadata ***') |
|
87 | print('*** Updating local metadata ***') | |
88 | dbAdminObj.__updateLocalMetadata__() |
|
88 | dbAdminObj.__updateLocalMetadata__() | |
89 | print('*** Rebuilding instParmTab.txt ***') |
|
89 | print('*** Rebuilding instParmTab.txt ***') | |
90 | madInstParams.rebuildInstParmTable() |
|
90 | madInstParams.rebuildInstParmTable() | |
91 | print('*** Rebuilding instKindatTab.txt ***') |
|
91 | print('*** Rebuilding instKindatTab.txt ***') | |
92 | madInstKindats.rebuildInstKindatTable() |
|
92 | madInstKindats.rebuildInstKindatTable() | |
93 |
|
93 | |||
94 | form = UpdataForm() |
|
94 | form = UpdataForm() | |
95 |
|
95 | |||
96 | else: |
|
96 | else: | |
97 | form = UpdataForm() |
|
97 | form = UpdataForm() | |
98 |
|
98 | |||
99 | return render(request, 'updata/index.html', { |
|
99 | return render(request, 'updata/index.html', { | |
100 | 'form': form, |
|
100 | 'form': form, | |
101 | 'site_name': siteName, |
|
101 | 'site_name': siteName, | |
102 | 'site_list': siteList, |
|
102 | 'site_list': siteList, | |
103 | }) |
|
103 | }) | |
104 |
|
104 | |||
105 |
|
105 | |||
106 | def get_experiments(request): |
|
106 | def get_experiments(request): | |
107 | """get_experiments is a Ajax call that returns the experiments select html to support the |
|
107 | """get_experiments is a Ajax call that returns the experiments select html to support the | |
108 | updata UI. Called when a user modifies the intruments select field. |
|
108 | updata UI. Called when a user modifies the intruments select field. | |
109 |
|
109 | |||
110 | Inputs: |
|
110 | Inputs: | |
111 | request |
|
111 | request | |
112 | """ |
|
112 | """ | |
113 | form = ExpForm(request.GET) |
|
113 | form = ExpForm(request.GET) | |
114 |
|
114 | |||
115 | return render(request, 'updata/experiments.html', {'form': form}) |
|
115 | return render(request, 'updata/experiments.html', {'form': form}) |
General Comments 0
You need to be logged in to leave comments.
Login now