Ejemplo n.º 1
0
 def get_data(self, request, instance_id):
     try:
         return saharaclient.cluster_get(request, instance_id)
     except api_base.APIException as e:
         if e.error_code == 404:
             raise Http404
         else:
             messages.error(request, _("Unable to update row"))
Ejemplo n.º 2
0
 def get_data(self, request, instance_id):
     try:
         return saharaclient.cluster_get(request, instance_id)
     except api_base.APIException as e:
         if e.error_code == 404:
             raise Http404
         else:
             messages.error(request, _("Unable to update row"))
Ejemplo n.º 3
0
 def get_object(self):
     cl_id = self.kwargs["cluster_id"]
     try:
         return saharaclient.cluster_get(self.request, cl_id)
     except Exception:
         msg = _('Unable to retrieve details for cluster "%s".') % cl_id
         redirect = reverse(
             "horizon:project:data_processing.clusters:clusters")
         exceptions.handle(self.request, msg, redirect=redirect)
Ejemplo n.º 4
0
    def handle(self, request, context):
        cluster_id = request.GET["cluster_id"]
        try:
            cluster = saharaclient.cluster_get(request, cluster_id)
            existing_node_groups = set([])
            for ng in cluster.node_groups:
                existing_node_groups.add(ng["name"])

            scale_object = dict()

            ids = json.loads(context["ng_forms_ids"])

            for _id in ids:
                name = context["ng_group_name_%s" % _id]
                template_id = context["ng_template_id_%s" % _id]
                count = context["ng_count_%s" % _id]

                if name not in existing_node_groups:
                    if "add_node_groups" not in scale_object:
                        scale_object["add_node_groups"] = []

                    scale_object["add_node_groups"].append(
                        {"name": name,
                         "node_group_template_id": template_id,
                         "count": int(count)})
                else:
                    old_count = None
                    for ng in cluster.node_groups:
                        if name == ng["name"]:
                            old_count = ng["count"]
                            break

                    if old_count != count:
                        if "resize_node_groups" not in scale_object:
                            scale_object["resize_node_groups"] = []

                        scale_object["resize_node_groups"].append(
                            {"name": name,
                             "count": int(count)}
                        )
        except Exception:
            scale_object = {}
            exceptions.handle(request,
                              _("Unable to fetch cluster to scale."))

        try:
            saharaclient.cluster_scale(request, cluster_id, scale_object)
            return True
        except api_base.APIException as e:
            self.error_description = str(e)
            return False
        except Exception:
            exceptions.handle(request,
                              _("Scale cluster operation failed"))
            return False
Ejemplo n.º 5
0
    def __init__(self, request, context_seed, entry_point, *args, **kwargs):
        ScaleCluster._cls_registry = set([])

        self.success_message = _("Scaled cluster successfully started.")

        cluster_id = context_seed["cluster_id"]
        try:
            cluster = saharaclient.cluster_get(request, cluster_id)
            plugin = cluster.plugin_name
            hadoop_version = cluster.hadoop_version

            #init deletable nodegroups
            deletable = dict()
            for group in cluster.node_groups:
                deletable[group["name"]] = "false"
            request.GET = request.GET.copy()
            request.GET.update({
                "cluster_id": cluster_id,
                "plugin_name": plugin,
                "hadoop_version": hadoop_version,
                "deletable": deletable
            })

            super(ScaleCluster, self).__init__(request, context_seed,
                                           entry_point, *args,
                                           **kwargs)

            #init Node Groups

            for step in self.steps:
                if isinstance(step, clt_create_flow.ConfigureNodegroups):
                    ng_action = step.action
                    template_ngs = cluster.node_groups

                    if 'forms_ids' not in request.POST:
                        ng_action.groups = []
                        for id in range(0, len(template_ngs), 1):
                            group_name = "group_name_" + str(id)
                            template_id = "template_id_" + str(id)
                            count = "count_" + str(id)
                            templ_ng = template_ngs[id]
                            ng_action.groups.append(
                                {"name": templ_ng["name"],
                                 "template_id": templ_ng["node_group_template_id"],
                                 "count": templ_ng["count"],
                                 "id": id,
                                 "deletable": "false"})

                            whelpers.build_node_group_fields(ng_action,
                                                             group_name,
                                                             template_id,
                                                             count)
        except Exception:
            exceptions.handle(request,
                              _("Unable to fetch cluster to scale"))
Ejemplo n.º 6
0
    def __init__(self, request, context_seed, entry_point, *args, **kwargs):
        ScaleCluster._cls_registry = set([])

        self.success_message = _("Scaled cluster successfully started.")

        cluster_id = context_seed["cluster_id"]
        try:
            cluster = saharaclient.cluster_get(request, cluster_id)
            plugin = cluster.plugin_name
            hadoop_version = cluster.hadoop_version

            # Initialize deletable node groups.
            deletable = dict()
            for group in cluster.node_groups:
                deletable[group["name"]] = "false"
            request.GET = request.GET.copy()
            request.GET.update({
                "cluster_id": cluster_id,
                "plugin_name": plugin,
                "hadoop_version": hadoop_version,
                "deletable": deletable
            })

            super(ScaleCluster, self).__init__(request, context_seed,
                                           entry_point, *args,
                                           **kwargs)
            # Initialize node groups.
            for step in self.steps:
                if not isinstance(step, clt_create_flow.ConfigureNodegroups):
                    continue
                ng_action = step.action
                template_ngs = cluster.node_groups

                if 'forms_ids' in request.POST:
                    continue
                ng_action.groups = []
                for i, templ_ng in enumerate(template_ngs):
                    group_name = "group_name_%d" % i
                    template_id = "template_id_%d" % i
                    count = "count_%d" % i
                    ng_action.groups.append({
                        "name": templ_ng["name"],
                        "template_id": templ_ng["node_group_template_id"],
                        "count": templ_ng["count"],
                        "id": i,
                        "deletable": "false",
                    })
                    workflow_helpers.build_node_group_fields(
                        ng_action, group_name, template_id, count)
        except Exception:
            exceptions.handle(request,
                              _("Unable to fetch cluster to scale"))
Ejemplo n.º 7
0
    def __init__(self, request, context_seed, entry_point, *args, **kwargs):
        ScaleCluster._cls_registry = set([])

        self.success_message = _("Scaled cluster successfully started.")

        cluster_id = context_seed["cluster_id"]
        try:
            cluster = saharaclient.cluster_get(request, cluster_id)
            plugin = cluster.plugin_name
            hadoop_version = cluster.hadoop_version

            # Initialize deletable node groups.
            deletable = dict()
            for group in cluster.node_groups:
                deletable[group["name"]] = "false"
            request.GET = request.GET.copy()
            request.GET.update({
                "cluster_id": cluster_id,
                "plugin_name": plugin,
                "hadoop_version": hadoop_version,
                "deletable": deletable
            })

            super(ScaleCluster, self).__init__(request, context_seed,
                                           entry_point, *args,
                                           **kwargs)
            # Initialize node groups.
            for step in self.steps:
                if not isinstance(step, clt_create_flow.ConfigureNodegroups):
                    continue
                ng_action = step.action
                template_ngs = cluster.node_groups

                if 'forms_ids' in request.POST:
                    continue
                ng_action.groups = []
                for i, templ_ng in enumerate(template_ngs):
                    group_name = "group_name_%d" % i
                    template_id = "template_id_%d" % i
                    count = "count_%d" % i
                    serialized = "serialized_%d" % i

                    serialized_val = base64.urlsafe_b64encode(json.dumps(
                        workflow_helpers.clean_node_group(templ_ng)))

                    ng_action.groups.append({
                        "name": templ_ng["name"],
                        "template_id": templ_ng["node_group_template_id"],
                        "count": templ_ng["count"],
                        "id": i,
                        "deletable": "false",
                        "serialized": serialized_val
                    })
                    workflow_helpers.build_node_group_fields(ng_action,
                                                             group_name,
                                                             template_id,
                                                             count,
                                                             serialized)
        except Exception:
            exceptions.handle(request,
                              _("Unable to fetch cluster to scale"))
Ejemplo n.º 8
0
 def get_data(self, request, instance_id):
     instance = saharaclient.cluster_get(request, instance_id)
     return instance
Ejemplo n.º 9
0
    def get(self, request, *args, **kwargs):

        cluster_id = kwargs.get("cluster_id")

        try:
            cluster = saharaclient.cluster_get(request, cluster_id,
                                               show_progress=True)
            node_group_mapping = {}
            for node_group in cluster.node_groups:
                node_group_mapping[node_group["id"]] = node_group["name"]

            provision_steps = cluster.provision_progress

            # Sort by create time
            provision_steps = sorted(provision_steps,
                                     key=ClusterEventsView._created_at_key,
                                     reverse=True)

            for step in provision_steps:
                # Sort events of the steps also
                step["events"] = sorted(step["events"],
                                        key=ClusterEventsView._created_at_key,
                                        reverse=True)

                successful_events_count = 0

                for event in step["events"]:
                    if event["node_group_id"]:
                        event["node_group_name"] = node_group_mapping[
                            event["node_group_id"]]

                    event_result = _("Unknown")
                    if event["successful"] is True:
                        successful_events_count += 1
                        event_result = _("Completed Successfully")
                    elif event["successful"] is False:
                        event_result = _("Failed")

                    event["result"] = event_result

                    if not event["event_info"]:
                        event["event_info"] = _("No info available")

                start_time = datetime.strptime(step["created_at"],
                                               self._date_format)
                end_time = datetime.now()
                # Clear out microseconds. There is no need for that precision.
                end_time = end_time.replace(microsecond=0)
                if step["successful"] is not None:
                    updated_at = step["updated_at"]
                    end_time = datetime.strptime(updated_at,
                                                 self._date_format)
                step["duration"] = six.text_type(end_time - start_time)

                result = _("In progress")
                step["completed"] = successful_events_count

                if step["successful"] is True:
                    step["completed"] = step["total"]
                    result = _("Completed Successfully")
                elif step["successful"] is False:
                    result = _("Failed")

                step["result"] = result

            status = cluster.status.lower()
            need_update = status not in ("active", "error")
        except APIException:
            # Cluster is not available. Returning empty event log.
            need_update = False
            provision_steps = []

        context = {"provision_steps": provision_steps,
                   "need_update": need_update}

        return HttpResponse(json.dumps(context),
                            content_type='application/json')