Ejemplo n.º 1
0
class GeneralConfigAction(workflows.Action):
    job_name = forms.CharField(label=_("Name"))

    job_type = forms.ChoiceField(label=_("Job Type"),
                                 widget=forms.Select(attrs={
                                     'class': 'switchable',
                                     'data-slug': 'jobtype'
                                 }))

    main_binary = forms.DynamicChoiceField(
        label=_("Choose a main binary"),
        required=False,
        help_text=_("Choose the binary which "
                    "should be used in this Job."),
        add_item_link=JOB_BINARY_CREATE_URL,
        widget=fields.DynamicSelectWidget(
            attrs={
                'class': 'switched',
                'data-switch-on': 'jobtype',
                'data-jobtype-pig': _("Choose a main binary"),
                'data-jobtype-hive': _("Choose a main binary"),
                'data-jobtype-spark': _("Choose a main binary"),
                'data-jobtype-mapreduce.streaming': _("Choose a main binary")
            }))

    job_description = forms.CharField(label=_("Description"),
                                      required=False,
                                      widget=forms.Textarea(attrs={'rows': 4}))

    def __init__(self, request, context, *args, **kwargs):
        super(GeneralConfigAction, self).__init__(request, context, *args,
                                                  **kwargs)
        resolver_match = urlresolvers.resolve(request.path)
        if "guide_job_type" in resolver_match.kwargs:
            self.fields["job_type"].initial = (
                resolver_match.kwargs["guide_job_type"].lower())

    def populate_job_type_choices(self, request, context):
        choices = [("pig", _("Pig")), ("hive", _("Hive")),
                   ("spark", _("Spark")), ("mapreduce", _("MapReduce")),
                   ("mapreduce.streaming", _("Streaming MapReduce")),
                   ("java", _("Java Action"))]
        return choices

    def populate_main_binary_choices(self, request, context):
        job_binaries = saharaclient.job_binary_list(request)

        choices = [(job_binary.id, job_binary.name)
                   for job_binary in job_binaries]
        choices.insert(0, ('', _("-- not selected --")))
        return choices

    def clean(self):
        cleaned_data = super(workflows.Action, self).clean()
        job_type = cleaned_data.get("job_type", "")

        if job_type in ["Java", "MapReduce"]:
            cleaned_data['main_binary'] = None

        return cleaned_data

    class Meta(object):
        name = _("Create Job Template")
        help_text_template = (
            "project/data_processing.jobs/_create_job_help.html")
Ejemplo n.º 2
0
class GeneralConfigAction(workflows.Action):
    job_name = forms.CharField(label=_("Name"))

    job_type = forms.ChoiceField(label=_("Job Type"),
                                 widget=forms.Select(attrs={
                                     'class': 'switchable',
                                     'data-slug': 'jobtype'
                                 }))

    main_binary = forms.DynamicChoiceField(
        label=_("Choose a main binary"),
        required=False,
        help_text=_("Choose the binary which "
                    "should be used in this Job."),
        add_item_link=JOB_BINARY_CREATE_URL,
        widget=fields.DynamicSelectWidget(
            attrs={
                'class': 'switched',
                'data-switch-on': 'jobtype',
                'data-jobtype-pig': _("Choose a main binary"),
                'data-jobtype-hive': _("Choose a main binary"),
                'data-jobtype-shell': _("Choose a shell script"),
                'data-jobtype-spark': _("Choose a main binary"),
                'data-jobtype-storm': _("Choose a main binary"),
                'data-jobtype-mapreduce.streaming': _("Choose a main binary")
            }))

    job_description = forms.CharField(label=_("Description"),
                                      required=False,
                                      widget=forms.Textarea(attrs={'rows': 4}))
    is_public = acl_utils.get_is_public_form(_("job"))
    is_protected = acl_utils.get_is_protected_form(_("job"))

    def __init__(self, request, context, *args, **kwargs):
        super(GeneralConfigAction, self).__init__(request, context, *args,
                                                  **kwargs)
        req = request.GET or request.POST
        if req.get("guide_job_type"):
            self.fields["job_type"].initial = (
                req.get("guide_job_type").lower())

    def populate_job_type_choices(self, request, context):
        choices = []
        choices_list = saharaclient.job_types_list(request)

        for choice in choices_list:
            job_type = choice.name.lower()
            if job_type in helpers.JOB_TYPE_MAP:
                choices.append((job_type, helpers.JOB_TYPE_MAP[job_type][0]))
        return choices

    def populate_main_binary_choices(self, request, context):
        job_binaries = saharaclient.job_binary_list(request)

        choices = [(job_binary.id, job_binary.name)
                   for job_binary in job_binaries]
        choices.insert(0, ('', _("-- not selected --")))
        return choices

    def clean(self):
        cleaned_data = super(workflows.Action, self).clean()
        job_type = cleaned_data.get("job_type", "")

        if job_type in ["Java", "MapReduce"]:
            cleaned_data['main_binary'] = None

        return cleaned_data

    class Meta(object):
        name = _("Create Job Template")
        help_text_template = "job_templates/_create_job_help.html"