Skip to content

Commit

Permalink
bloopdeedoop
Browse files Browse the repository at this point in the history
  • Loading branch information
vsoch committed Apr 25, 2018
1 parent 50dbe2b commit ec9f51a
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 45 deletions.
10 changes: 10 additions & 0 deletions run_uwsgi.sh
@@ -1,4 +1,5 @@
#!/bin/bash

python manage.py makemigrations
python manage.py migrate auth
python manage.py makemigrations users
Expand All @@ -8,4 +9,13 @@ python manage.py makemigrations logs
python manage.py migrate
python manage.py collectstatic --noinput
service cron start

if grep -Fxq "PLUGINS_ENABLED+=[\"globus\"]" /code/shub/settings/config.py
then
# When configured, we can start the endpoint
echo "Starting Globus Connect Personal"
export USER="tunel-user"
/opt/globus/globusconnectpersonal -start &
fi

uwsgi uwsgi.ini
2 changes: 1 addition & 1 deletion scripts/globus/globus-install.sh
Expand Up @@ -19,4 +19,4 @@ git clone https://github.com/sirosen/globusconnectpersonal-py3-patched && \

# Create globus user
useradd -ms /bin/bash tunel-user
echo "gtunel-user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
echo "tunel-user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
11 changes: 6 additions & 5 deletions shub/plugins/globus/actions.py
Expand Up @@ -42,7 +42,7 @@ def get_endpoints(user, client=None):
if client is not None:
for scope in ['my-endpoints', 'shared-with-me']:
for ep in client.endpoint_search(filter_scope=scope):
if ep.__dict__['_data']['name'] != settings.GLOBUS_ENDPOINT_ID:
if ep.__dict__['_data']['name'] != settings.PLUGIN_GLOBUS_ENDPOINT:
endpoints.append(ep.__dict__['_data'])
return endpoints

Expand All @@ -56,7 +56,7 @@ def search_endpoints(term, user, client=None):

if client is not None:
for ep in client.endpoint_search(term, filter_scope="all"):
if ep.__dict__['_data']['name'] != settings.GLOBUS_ENDPOINT_ID:
if ep.__dict__['_data']['name'] != settings.PLUGIN_GLOBUS_ENDPOINT:
endpoints.append(ep.__dict__['_data'])

return endpoints
Expand All @@ -66,13 +66,14 @@ def search_endpoints(term, user, client=None):
def do_transfer(user, endpoint, container):

# Use relative paths, we are in container and endpoint is mapped
source = container.get_image_path().replace(settings.MEDIA_ROOT,'').strip('/')
source = container.get_image_path()
client = get_transfer_client(user)
source_endpoint = settings.GLOBUS_ENDPOINT_ID
source_endpoint = settings.PLUGIN_GLOBUS_ENDPOINT
tdata = globus_sdk.TransferData(client, source_endpoint,
endpoint,
label="Singularity Registry Transfer",
sync_level="checksum")
tdata.add_item(source, source)
tdata.add_item(source.replace(settings.MEDIA_ROOT,'/code/images'),
source.replace(settings.MEDIA_ROOT,'').strip('/'))
transfer_result = client.submit_transfer(tdata)
return transfer_result
141 changes: 107 additions & 34 deletions shub/plugins/globus/templates/globus/transfer.html
Expand Up @@ -25,8 +25,9 @@ <h3 class="title">{{ request.user.username }}: </a>
</div>
</div>
</div>
<div class="col-md-6">

{% if endpoints %}
<div class="col-md-8">
<small>Search Endpoints</small>

{% if container %}
Expand All @@ -40,9 +41,11 @@ <h3 class="title">{{ request.user.username }}: </a>
<span class="input-group-btn">
<button class="btn btn-info" type="submit">Go!</button>
</span>
</div>
</form>
</div>
{% endif %}

</div>
</div>

<div class="row" style='margin-top:20px'>
Expand All @@ -53,11 +56,10 @@ <h3 class="title">{{ request.user.username }}: </a>
</ul>
</div>
<div class="col-md-1"></div>
<div class="col-md-8">
<div class="col-md-8" style="padding-left:0px">
<div class="tab-content">
<div id="transfer" class="tab-pane fade in active">

{% if container %}
{% if endpoints|length == 0 %}
<div class="row">
<div class="col-md-12">
Expand All @@ -67,36 +69,68 @@ <h3 class="title">{{ request.user.username }}: </a>
</div>
</div>
{% endif %}
{% for ep in endpoints %}
<div class="row">
<div class="col-md-4" style="margin-top:15px">
<p class="alert alert-info">
<span class="label label-info">From</span> Singularity Hub
</p>
</div>
<div class="col-md-2">
<a class="social-button btn-lg do_transfer transfer"
data-endpoint="{{ ep.name }}"
style="margin:auto; height:200px;cursor:pointer; color: #2e609b">
<i class="fa fa fa-long-arrow-right fa-4x"></i></a>
</div>
<div class="col-md-4" style="margin-top:15px">
<p class="alert alert-warning transfer {{ ep.name }}"
<span class="label label-info">To</span> {{ ep.display_name }}
</p>
</div>
</div>
{% endfor %}
{% else %}
<hr>
<div class="row">
<div class="col-md-12">
<p class="alert alert-info">
You are connected to Globus! Browse <a href="{% url 'collections' %}">container collections</a> and look for the <i class="fa fa-exchange" style="padding:20px"></i> icon to select an endpoint to transfer the image..
</p>
</div>
</div>
{% endif %}

{% if endpoints %}
<div class="row">
<input type="text" id="searchInput" onkeyup="tableSearch()" style="margin-bottom:10px" placeholder="Search names...">
<p class="alert alert-info" id="message-activate" style="display:none;padding: 8px; margin-left: 10px"></p>
<table id="label_table" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>endpoint ID</th>
<th></th>
<th>name</th>
<th>email</th>
<th>organization</th>
<th></th>
</tr>
</thead>
<tfoot>
<tr>
<th>endpoint ID</th>
<th></th>
<th>name</th>
<th>email</th>
<th>organization</th>
<th></th>
</tr>
</tfoot>
<tbody>
{% for endpoint in endpoints %}
<tr class="tableRow">
<td data-search="{{ endpoint.id }}">
{% if endpoint.activated %}{{ endpoint.id }}{% else %}
<a class="makeactive" data-uid="{{ endpoint.id }}"
target="_blank"
href="https://www.globus.org/app/endpoints/{{ endpoint.id }}/activate">ACTIVATE {{ endpoint.id }}</a>{% endif %}
</td>
<td data-search="{{ endpoint.activated }} {{ endpoint.is_globus_connect }}">
{% if endpoint.activated %}<span class="label label-success">activated</span>{% endif %}
{% if endpoint.is_globus_connect %}<span class="label label-primary">globus connect</span>{% endif %}
{% if endpoint.public %}<span class="label label-primary">public</span>{% endif %}
</td>
<td data-search="{{ endpoint.display_name }}">{{ endpoint.display_name }}</td>
<td {% if endpoint.contact_email %}data-search="{{ endpoint.contact_email }}"{% endif %}>{% if endpoint.contact_email %}{{ endpoint.contact_email }}{% endif %}</td>
<td {% if endpoint.organization %}data-search="{{ endpoint.organization }}"{% endif %}>{% if endpoint.organization %}{{ endpoint.organization }}{% endif %}</td>
<td>{% if endpoint.activated %}{% if container.id %}
<button class="btn btn-sm btn-info do_transfer transfer"
data-endpoint="{{ endpoint.id }}">Transfer</button>{% endif %}{% endif %}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<hr>
<div class="row">
<div class="col-md-12">
<p class="alert alert-info">
You are connected to Globus! Browse <a href="{% url 'collections' %}">container collections</a> and look for the <i class="fa fa-exchange" style="padding:20px"></i> icon to select an endpoint to transfer the image..
</p>
</div>
</div>
{% endif %}

</div>
<hr>
<div id="endpoints" style="color:#2e609b" class="tab-pane fade in">
Expand Down Expand Up @@ -179,6 +213,45 @@ <h5 class="mb-0">
}
});
}

{% if needs_update %}
{% else %}

$('.makeactive').click(function(){
uid = $(this).attr('data-uid');
message='Once you have authenticated for the endpoint in the Globus portal,';
{% if container %}
message+='view <a href="/globus/endpoint/' + uid + '{{ container.id }}"> the endpoint details.</a>';
{% else %}
message+='view <a href="/globus/endpoint/' + uid + '"> the endpoint details.</a>';
{% endif %}
$('#message-activate').append(message);
$('#message-activate').show();
});

function tableSearch() {

// https://www.w3schools.com/howto/howto_js_filter_table.asp

var input, filter, table, tr, td, i;
input = document.getElementById("searchInput");
filter = input.value.toUpperCase();
table = document.getElementById("label_table");
tr = table.getElementsByClassName("tableRow");

for (i = 0; i < tr.length; i++) {
$.each(tr[i].children, function(e, child){
text = $(child).attr('data-search');
if (text.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
})
}
}
{% endif %}

{% endif %}

})
Expand Down
3 changes: 2 additions & 1 deletion shub/plugins/globus/urls.py
Expand Up @@ -5,7 +5,8 @@
url(r'^login/$', views.globus_login, name="globus_login"),
url(r'^logout/$', views.globus_logout, name="globus_logout"),
url(r'^transfer$', views.globus_transfer, name="globus_transfer"),
url(r'^endpoint/(?P<endpoint_id>.+?)/(?P<cid>\d+)?$', views.globus_endpoint, name='globus_endpoint'),
url(r'^endpoint/(?P<cid>\d+)/?$', views.globus_endpoint, name='globus_endpoint'),
url(r'^transfer/(?P<cid>\d+)/?$', views.globus_transfer, name='globus_transfer'),
url(r'^transfer/(?P<endpoint>.+?)/container/(?P<cid>\d+)/?$', views.submit_transfer,name='submit_transfer'),
]

38 changes: 36 additions & 2 deletions shub/plugins/globus/views.py
Expand Up @@ -36,9 +36,14 @@
from .decorators import has_globus_association
from shub.plugins.globus.utils import (
get_client,
get_transfer_client,
associate_user
)

from globus_sdk.exc import TransferAPIError



@login_required
@has_globus_association
def globus_logout(request):
Expand Down Expand Up @@ -126,6 +131,31 @@ def globus_transfer(request, cid=None, endpoints=None):
return render(request, 'globus/transfer.html', context)


@login_required
@has_globus_association
def globus_endpoint(request, endpoint_id=None, cid=None):
''' Show information for a single endpoint only.
'''
container = None
if cid is not None:
container = get_container(cid)

context = {'user': request.user,
'container': container,
'endpoint_search_term': "Search for..." }

# Get the endpoint
try:
client = get_transfer_client(request.user)
endpoints = [client.get_endpoint(endpoint_id).data]
except TransferAPIError:
endpoints = get_endpoints(request.user)

context['endpoints'] = endpoints

return render(request, 'globus/transfer.html', context)


@login_required
@has_globus_association
def submit_transfer(request, endpoint, cid):
Expand All @@ -141,7 +171,11 @@ def submit_transfer(request, endpoint, cid):
result = do_transfer(user=request.user,
endpoint=endpoint,
container=container)
message = result['message']

status = {'message': message }

link = "https://globus.org/app/activity/%s" %result['task_id']
m = result['message']
m = "%s: <a target='_blank' href='%s'>view task</a>" %(m, link)

status = {'message': m }
return JsonResponse(status)
2 changes: 0 additions & 2 deletions shub/settings/config.py
Expand Up @@ -108,7 +108,5 @@
# 'ldap_auth'
]
PLUGINS_ENABLED+=["globus"]
ROBOTNAME='crusty-malarkey-2922'
PLUGIN_GLOBUS_ENDPOINT="502635e0-4418-11e8-8e06-0a6d4e044368"
ROBOTNAME='sticky-blackbean-9783'
PLUGIN_GLOBUS_ENDPOINT="ba5b80c2-4798-11e8-8ee0-0a6d4e044368"

0 comments on commit ec9f51a

Please sign in to comment.