Пример #1
0
    def create(self, gid, sid, jid):
        """
        This function will update the data for the selected schedule node.

        Args:
            gid: Server Group ID
            sid: Server ID
            jid: Job ID
        """
        data = {}
        if request.args:
            for k, v in request.args.items():
                try:
                    data[k] = json.loads(
                        v.decode('utf-8') if hasattr(v, 'decode') else v)
                except ValueError:
                    data[k] = v
        else:
            data = json.loads(request.data.decode())
            # convert python list literal to postgres array literal.
            format_schedule_data(data)

        sql = render_template("/".join([self.template_path, 'create.sql']),
                              jid=jid,
                              data=data,
                              fetch_id=True)

        status, res = self.conn.execute_void('BEGIN')
        if not status:
            return internal_server_error(errormsg=res)

        status, res = self.conn.execute_scalar(sql)
        if not status:
            if self.conn.connected():
                self.conn.execute_void('END')
            return internal_server_error(errormsg=res)

        self.conn.execute_void('END')
        sql = render_template("/".join([self.template_path, 'properties.sql']),
                              jscid=res,
                              jid=jid)
        status, res = self.conn.execute_2darray(sql)

        if not status:
            return internal_server_error(errormsg=res)

        if len(res['rows']) == 0:
            return gone(errormsg=gettext("Job schedule creation failed."))
        row = res['rows'][0]

        return jsonify(node=self.blueprint.generate_browser_node(
            row['jscid'],
            row['jscjobid'],
            row['jscname'],
            icon="icon-pga_schedule"
            if row['jscenabled'] else "icon-pga_schedule-disabled",
            enabled=row['jscenabled']))
Пример #2
0
    def create(self, gid, sid, jid):
        """
        This function will update the data for the selected schedule node.

        Args:
            gid: Server Group ID
            sid: Server ID
            jid: Job ID
        """
        data = json.loads(request.data, encoding='utf-8')
        # convert python list literal to postgres array literal.
        format_schedule_data(data)

        sql = render_template(
            "/".join([self.template_path, self._CREATE_SQL]),
            jid=jid,
            data=data,
            fetch_id=True
        )

        status, res = self.conn.execute_void('BEGIN')
        if not status:
            return internal_server_error(errormsg=res)

        status, res = self.conn.execute_scalar(sql)
        if not status:
            if self.conn.connected():
                self.conn.execute_void('END')
            return internal_server_error(errormsg=res)

        self.conn.execute_void('END')
        sql = render_template(
            "/".join([self.template_path, self._PROPERTIES_SQL]),
            jscid=res,
            jid=jid
        )
        status, res = self.conn.execute_2darray(sql)

        if not status:
            return internal_server_error(errormsg=res)

        if len(res['rows']) == 0:
            return gone(
                errormsg=gettext("Job schedule creation failed.")
            )
        row = res['rows'][0]

        return jsonify(
            node=self.blueprint.generate_browser_node(
                row['jscid'],
                row['jscjobid'],
                row['jscname'],
                icon="icon-pga_schedule" if row['jscenabled'] else
                "icon-pga_schedule-disabled",
                enabled=row['jscenabled']
            )
        )
Пример #3
0
    def format_schedule_step_data(self, data):
        """
        This function is used to format the schedule and step data.
        :param data:
        :return:
        """
        # Format the schedule data. Convert the boolean array
        if 'jschedules' in data:
            if 'added' in data['jschedules']:
                for added_schedule in data['jschedules']['added']:
                    format_schedule_data(added_schedule)
            if 'changed' in data['jschedules']:
                for changed_schedule in data['jschedules']['changed']:
                    format_schedule_data(changed_schedule)

        has_connection_str = self.manager.db_info['pgAgent']['has_connstr']
        if 'jsteps' in data and has_connection_str:
            if 'changed' in data['jsteps']:
                for changed_step in data['jsteps']['changed']:

                    if 'jstconntype' not in changed_step and (
                        'jstdbname' in changed_step or
                            'jstconnstr' in changed_step):
                        status, rset = self.conn.execute_dict(
                            render_template(
                                "/".join([self.template_path, 'steps.sql']),
                                jid=data['jobid'],
                                jstid=changed_step['jstid'],
                                conn=self.conn,
                                has_connstr=has_connection_str
                            )
                        )
                        if not status:
                            return internal_server_error(errormsg=rset)

                        row = rset['rows'][0]
                        changed_step['jstconntype'] = row['jstconntype']
                        if row['jstconntype']:
                            if not ('jstdbname' in changed_step):
                                changed_step['jstdbname'] = row['jstdbname']
                        else:
                            if not ('jstconnstr' in changed_step):
                                changed_step['jstconnstr'] = row['jstconnstr']
Пример #4
0
    def format_schedule_step_data(self, data):
        """
        This function is used to format the schedule and step data.
        :param data:
        :return:
        """
        # Format the schedule data. Convert the boolean array
        jschedules = data.get('jschedules', {})
        if type(jschedules) == dict:
            for schedule in jschedules.get('added', []):
                format_schedule_data(schedule)
            for schedule in jschedules.get('changed', []):
                format_schedule_data(schedule)

        has_connection_str = self.manager.db_info['pgAgent']['has_connstr']
        jssteps = data.get('jsteps', {})
        if type(jssteps) == dict:
            for changed_step in jssteps.get('changed', []):
                status, res = format_step_data(
                    data['jobid'], changed_step, has_connection_str,
                    self.conn, self.template_path)
                if not status:
                    internal_server_error(errormsg=res)