Ejemplo n.º 1
0
 def get(self, id=None):
     queryData = request.args.to_dict()
     if id:
         link = LinkModel.find_by_id(id)
         if link: return link.json(), 200
         else: return {'error': 'link not found'}, 404
     link = LinkModel.find(**queryData)
     return {'links': list(map(lambda x: x.json(), link))}, 200
Ejemplo n.º 2
0
 def post(self, **somedata):
     data = json.loads(request.data)
     link = LinkModel(**data)
     try:
         link.save_to_db()
     except:
         return {"error": "An error occurred creating the link."}, 500
     return link.json(), 201
Ejemplo n.º 3
0
 def processLink(self, links, data, workflow_id):
     link_node = None
     for link in links:
         links[link]["src_node"] = self.saveJobToDb(links[link]["src_node"],
                                                    data, workflow_id)
         links[link]["dst_node"] = self.saveJobToDb(links[link]["dst_node"],
                                                    data, workflow_id)
         links[link]["link_type"] = links[link]["link_type"]
         links[link]["workflow_id"] = workflow_id
         link_node = LinkModel(**links[link])
         try:
             link_node.save_to_db(commit=True)
         except:
             return {"error": "An error occurred inserting the link."}, 500
     return link_node
Ejemplo n.º 4
0
 def delete(self, name):
     link = LinkModel.find_by_id(id)
     if link:
         link.delete_from_db()
     else:
         return {'error': 'Group not found'}, 404
     return {'success': 'link deleted'}, 202
Ejemplo n.º 5
0
 def put(self, id):
     data = json.loads(request.data)
     link = LinkModel.find_by_id(id)
     if link:
         link.update(**data)
     else:
         return {'error': 'Group not found'}, 404
     return link.json(), 201
Ejemplo n.º 6
0
    def sendToNextNode(self, element_id, workflow_id, element_type, status):
        workflow = WorkflowModel.findById(workflow_id)
        links = LinkModel.find(**{
            "workflow_id": workflow_id,
            "link_type": status,
        })
        if element_type == "job":
            self.rootLogger.debug(
                'Searching for the next node for the job {0}.'.format(
                    element_id))
            for link in links:
                if link.src_node["uid"] == element_id and link.src_node[
                        "node_type"] == element_type and link.link_type == status:
                    next_node_id = link.dst_node["uid"]
                    next_node_type = link.dst_node["node_type"]

                    if link.dst_node["uid"] == "success":
                        self.rootLogger.info('Setting the job on SUCCESSFUL.')
                        workflow.status = "SUCCESSFUL"
                        return

                    if link.dst_node["uid"] == "fail":
                        self.rootLogger.info('Setting the job on FAILED.')
                        workflow.status = "FAILED"
                        return

                    if link.dst_node["node_type"] == "job":
                        self.sendNode(next_node_id, next_node_type,
                                      workflow.hosts["host_list"])

                    if link.dst_node["node_type"] == "eval":
                        self.sendNode(next_node_id, next_node_type)

                    if link.dst_node == "manual action":
                        return
                    self.rootLogger.info('Sending to next node')

        if element_type == "manual action":
            self.manualAction(element_id, workflow_id, element_type, status)
            self.rootLogger.info(
                'The workflow is waiting for a manual action from the user.')
            return

        if element_type == "eval":
            return
        return
Ejemplo n.º 7
0
 def sendEval(self, eval_id):
     """
 """
     eval = self.evalApplication(eval_id)
     links = LinkModel.find(**{
         "workflow_id": self.workflow_id,
         "link_type": eval.status,
     })
     for link in links:
         if link.src_node["uid"] == eval.id and link.src_node[
                 "node_type"] == "eval":
             if link.dst_node["node_type"] == "job":
                 next_node_type = link.dst_node["node_type"]
                 next_node_id = link.dst_node["uid"]
                 next_node_type = link.dst_node["node_type"]
                 workflow = WorkflowModel.findById(self.workflow_id)
                 self.sendNode(next_node_id, next_node_type,
                               workflow.hosts["host_list"])
     return