コード例 #1
0
    def post(self):
        try:
            job = LagopusJob.create(**api.payload)
        except JobCreateError as e:
            errors.abort(code=400,
                         message="Job creation failed: {}".format(str(e)))

        app.logger.info("Created job {}".format(job))
        return job
コード例 #2
0
    def get(self, job_id):
        try:
            args = parser_stats.parse_args()
            since = args["since"] if "since" in args else None
            app.logger.warning("Requesting since: {}".format(since))
            results = LagopusJob.get_stats(job_id, since)
        except ConnectionError as e:
            app.logger.warning("Could not connect to InfluxDB")
            errors.abort(code=503, message="Could not connect to InfluxDB")

        return results
コード例 #3
0
    def post(self, job_id):
        job = LagopusJob.get(job_id)

        response = {
            "job_id": job_id,
            "status": "",
        }
        if not job:
            errors.abort(code=404, message="No such job {}".format(job_id))

        if api.payload["action"] == "kill":
            try:
                lr = LagopusJob.kill(job_id)
            except Exception as e:
                app.logger.exception(e)
                app.logger.warning("k8s kill failed for job {}".format(job_id))
                errors.abort(code=500,
                             message="Failed to kill job {}".format(job_id))

            if lr:
                response["status"] = "success"
                response["info"] = "killed job"
                return response, 200
            else:
                app.logger.warning("k8s kill failed for job {}".format(job_id))
                errors.abort(code=500,
                             message="Failed to kill job {}".format(job_id))

        errors.abort(code=400, message="Unknown action")
コード例 #4
0
    def post(self, role_id: int):
        role = Role.get(id=role_id)
        if not role:
            raise abort(404)
        args = self.parser.parse_args()
        entity = Entity.get(id=args.pop("entity_id"))
        if not entity:
            raise InvalidUsage.custom_error("invalid entity", 401)
        role.add_entity(entity, **args)

        return role
コード例 #5
0
    def abort(self, code=500, message=None, **kwargs):
        """
        Properly abort the current request

        See: :func:`~flask_restx.errors.abort`
        """
        if message and not isinstance(message, str):
            try:
                message = json.dumps(message)  # pragma: no cover
            except:
                message = None
        # Add extra logs when raising abort exception
        (frm, filename, line_no, func, source_code,
         source_index) = inspect.stack()[1]
        mod = inspect.getmodule(frm)
        self.logger.debug('Abort in {}:{}'.format(filename, line_no))
        self.logger.warning('[{}] {}: {}{}'.format(
            mod.__name__, code, message,
            ' - {}'.format(kwargs) if kwargs else ''))
        # This raises a Flask Exception
        abort(code, message, **kwargs)
コード例 #6
0
 def put(self, role_id: int):
     role = Role.get(id=role_id)
     if not role:
         raise abort(404)
     args = self.parser.parse_args()
     entity_id = args.pop("entity_id")
     entity: List[Entity] = [
         ent for ent in role.entity_permissions
         if ent.entity_id == entity_id
     ]
     if len(entity) != 1:
         raise InvalidUsage.custom_error("invalid entity", 401)
     entity[0].update(ignore_none=True, **args)
     return role
コード例 #7
0
    def post(self, role_id: int):
        role_ = Role.get(role_id)
        if not role_:
            raise abort(404)

        args = user_ids_parser.parse_args()
        if User.query.filter(User.id.in_(args.get("users"))).count() != len(
                args.get("users")):
            raise InvalidUsage.custom_error("Can't add these users", 401)
        db.session.add_all([
            UserRoles(user_id=user_id, role=role_) for user_id in args["users"]
        ])

        db.session.commit()

        return role_
コード例 #8
0
 def get(self, customer_id):
     customer = Customer.query.get(customer_id)
     if customer:
         return customer
     else:
         abort(404, "Customer ID Not Found")
コード例 #9
0
 def get(self, job_id, sample_name):
     sample = LagopusCrash.get_sample(job_id, sample_name)
     if sample:
         return send_file(sample, as_attachment=True)
     else:
         errors.abort(code=404, message="Sample not found")
コード例 #10
0
 def get(self, job_id):
     result = LagopusJob.get_result(job_id)
     if result:
         return send_file(result, as_attachment=True)
     else:
         errors.abort(code=404, message="Result not found")
コード例 #11
0
 def get(self, role_id: int):
     role_ = Role.get(role_id)
     if not role_:
         raise abort(404)
     return role_