Esempio n. 1
0
    def get_data(self, context):
        username = self.request.user.username
        try:
            if session_is_okay(self.request.session, "user_clusters"):
                self.logger.info("Updating clusters in database")
                return self.cluster_service.update_by_user(username)
            else:
                self.logger.info("Getting clusters from database")
                return self.cluster_service.get_by_user(username)

        except Exception as e:
            self.logger.exception(e)
            raise
Esempio n. 2
0
    def get_object(self, queryset=None):
        try:
            if session_is_okay(self.request.session, "single_instance"):
                self.instance_service.update_single_instance(self.kwargs['pk'])
        except Exception as e:
            self.logger.exception(e)

        obj = super(generic.DetailView, self).get_object(queryset)

        if has_permission(self.request.user, obj.userid):
            return obj
        else:
            raise PermissionDenied
Esempio n. 3
0
    def get_data(self, context):
        cluster_id = self.kwargs['pk']

        try:
            if session_is_okay(self.request.session, "user_clusters"):
                self.logger.info("Updating clusters in database")
                return self.cluster_service.update_single_cluster(cluster_id)
            else:
                self.logger.info("Getting clusters from database")
                return self.cluster_service.get_single_cluster(cluster_id)

        except Exception as e:
            self.logger.exception(e)
            raise
Esempio n. 4
0
    def get_data(self, context):
        try:
            username = self.request.user.username

            # Limit updates since it calls the AWS API and could get throttled.
            if session_is_okay(self.request.session, "user_instances"):
                self.logger.info('Updating instances in database.')
                return self.instance_service.update_by_user(username)
            else:
                self.logger.info('Retrieving instances from database.')
                return self.instance_service.get_by_user(username)

        except Exception as e:
            self.logger.exception(e)
            return HttpResponse(status=500)
Esempio n. 5
0
    def get_data(self, context):
        try:
            instance_id = self.kwargs['pk']

            # Limit updates since it calls the AWS API and could get throttled.
            if session_is_okay(self.request.session, "user_instances"):
                self.logger.info('Updating instances in database.')
                return self.instance_service.update_single_instance(
                    instance_id)
            else:
                self.logger.info('Retrieving instances from database.')
                return self.instance_service.get_single_instance(instance_id)

        except Exception as e:
            self.logger.exception(e)

        return []
Esempio n. 6
0
    def get_data(self, context):
        logger = self.logger
        try:
            if session_is_okay(self.request.session, "user_instances"):
                self.logger.info('Updating instances in database.')
                return self.instance_service.update_by_user_group(
                    self.request.user)
            else:
                self.logger.info('Retrieving instances from database.')
                return self.instance_service.get_by_user_group(
                    self.request.user)

        except Instance.DoesNotExist:
            response = []
        except Exception as e:
            logger.exception(e)
            response = []
        return response
Esempio n. 7
0
    def get_context_data(self, **kwargs):
        self.logger.info("User {} accessed {}".format(
            self.request.user, reverse("clusterview", kwargs=self.kwargs)),
                         extra={
                             "log_type": "user_activity",
                             "user": self.request.user,
                             "path": reverse("clusterview", kwargs=self.kwargs)
                         })
        context = super().get_context_data()

        # Cluster information for getting the instance type
        try:
            if session_is_okay(self.request.session, "user_clusters"):
                cluster = self.cluster_service.update_single_cluster(
                    self.kwargs['pk'])
            else:
                cluster = self.cluster_service.get_single_cluster(
                    self.kwargs['pk'])
            instance_type = cluster[0]['type']
            self.logger.debug("instance type: " + str(instance_type))

        except Exception as e:
            self.logger.exception(e)
            instance_type = ""
        context['instance_type'] = instance_type

        # Cluster Group Name
        try:
            emr_client = boto3.client('emr', region_name=AWS_REGION)
            cluster = emr_client.describe_cluster(ClusterId=self.kwargs['pk'])
            tags = cluster['Cluster']['Tags']
            for tag in tags:
                if tag['Key'] == 'UserGroup':
                    context['UserGroup'] = tag['Value']
                    return context
        except Exception as e:
            self.logger.exception(e)

        context['UserGroup'] = '--'

        return context