Fix job launching with cluster in any state

Now we can launch job only on clusters that in Active or Error state.
* added 'in {state} state' phrase to cluster selection field for
  clusters that in the state that differs from 'Active' state.
* added warning message for the choice of the cluster in the state
  that differs from 'Active' state.
* added 'No clusters available' message if there are no suitable
  clusters for a job launching.

Change-Id: I949b81290f94370eb0709f0a04e4d2ce39855323
bp: cluster-choice-for-jobs
closes-bug: 1430232
This commit is contained in:
Michael Ionkin 2016-03-29 17:58:49 +03:00
parent eb627941d0
commit ab99844e0b
6 changed files with 82 additions and 5 deletions

View File

@ -31,6 +31,7 @@ import sahara_dashboard.content.data_processing.jobs.job_templates \
.workflows.create as create_flow
import sahara_dashboard.content.data_processing.jobs.job_templates \
.workflows.launch as launch_flow
from sahara_dashboard.content.data_processing.utils import helpers
class CreateJobView(workflows.WorkflowView):
@ -78,6 +79,7 @@ class LaunchJobView(workflows.WorkflowView):
workflow_class = launch_flow.LaunchJob
success_url = "horizon:project:data_processing.jobs"
classes = ("ajax-modal",)
ajax_template_name = "job_templates/launch_ajax.html"
template_name = "job_templates/launch.html"
page_title = _("Launch Job")
@ -92,8 +94,22 @@ class LaunchJobView(workflows.WorkflowView):
def get_context_data(self, **kwargs):
context = super(LaunchJobView, self).get_context_data(**kwargs)
context["cl_name_state_map"] = self.get_cluster_choices(self.request)
context["status_message_map"] = json.dumps(helpers.STATUS_MESSAGE_MAP)
return context
def get_cluster_choices(self, request):
choices = []
try:
clusters = saharaclient.cluster_list(request)
choices = [
("%s %s" % (cl.name, helpers.ALLOWED_STATUSES.get(cl.status)),
cl.status)
for cl in clusters if (cl.status in helpers.ALLOWED_STATUSES)]
except Exception:
exceptions.handle(request, _("Unable to fetch clusters."))
return choices
class LaunchJobNewClusterView(workflows.WorkflowView):
workflow_class = launch_flow.LaunchJobNewCluster

View File

@ -27,6 +27,7 @@ import sahara_dashboard.content.data_processing. \
clusters.clusters.workflows.create as c_flow
from sahara_dashboard.content.data_processing.utils \
import acl as acl_utils
from sahara_dashboard.content.data_processing.utils import helpers
import sahara_dashboard.content.data_processing. \
utils.workflow_helpers as whelpers
@ -119,10 +120,11 @@ class JobExecutionExistingGeneralConfigAction(JobExecutionGeneralConfigAction):
clusters = []
exceptions.handle(request,
_("Unable to fetch clusters."))
choices = [(cluster.id, cluster.name)
for cluster in clusters]
choices = [(cl.id, "%s %s" % (cl.name,
helpers.ALLOWED_STATUSES.get(cl.status)))
for cl in clusters if cl.status in helpers.ALLOWED_STATUSES]
if not choices:
choices = [(None, _("No clusters available"))]
return choices
class Meta(object):

View File

@ -0,0 +1,22 @@
{% load i18n %}
{% include 'horizon/common/_workflow.html' %}
<script type="text/javascript">
$(function() {
var cl_name_status_map = {};
{% for name, status in cl_name_state_map %}
cl_name_status_map["{{ name }}"] = "{{ status }}";
{% endfor %}
var status_message_map = {{ status_message_map | safe }};
$('.cluster_choice').ready(function(){
horizon.job_launching_warning.show_warning(cl_name_status_map, status_message_map);
});
$(document).on('change', '.cluster_choice', function(){
horizon.job_launching_warning.show_warning(cl_name_status_map, status_message_map);
});
});
</script>

View File

@ -0,0 +1,21 @@
horizon.job_launching_warning = {
show_warning: function(cl_name_status_map, status_message_map) {
var cl_choice_elem = $('.cluster_choice').parent();
var current_cl_name = $('.cluster_choice option:selected').text();
var current_cl_status = cl_name_status_map[current_cl_name];
var warning_msg = status_message_map[current_cl_status];
var warning_elem = "<div class=\"not_active_state_warning alert alert-dismissable alert-warning\">" +
"<h4>" + gettext("Warning!") + "</h4>" +
"<p>" + warning_msg + "</p>" +
"</div>";
if ($.isEmptyObject(cl_name_status_map) || current_cl_status === 'Active') {
$('.not_active_state_warning').remove();
} else {
cl_choice_elem.append(warning_elem);
$('.not_active_state_warning').css('margin-top', '5px');
}
}
}

View File

@ -16,6 +16,7 @@ import six
from django.template import defaultfilters as filters
from django.utils import timezone
from django.utils.translation import ugettext
from django.utils.translation import ugettext_lazy as _
from oslo_utils import timeutils
@ -190,3 +191,17 @@ JOB_TYPE_MAP = {"pig": [_("Pig"), "Pig"],
"MapReduce.Streaming"],
"java": [_("Java"), "Java"],
"shell": [_("Shell"), "Shell"]}
# Statuses of clusters that we can choose for job execution and
# suitable messages that will be displayed next to the cluster name
ALLOWED_STATUSES = {
"Active": "",
"Error": "(in error state)",
}
# Cluster status and suitable warning message that will be displayed
# in the Job Launch form
STATUS_MESSAGE_MAP = {
"Error": ugettext("You\'ve chosen a cluster that is in \'Error\' state. "
"Appropriate execution of the job can't be guaranteed."),
}

View File

@ -27,7 +27,8 @@ ADD_PANEL = ('sahara_dashboard.content.data_processing.jobs.panel.JobsPanel')
ADD_JS_FILES = [
'dashboard/project/data_processing/'
'data_processing.job_interface_arguments.js'
'data_processing.job_interface_arguments.js',
'dashboard/project/data_processing/data_processing.job_launching.js'
]
ADD_EXCEPTIONS = {