Exemplo n.º 1
0
 def updateStatus(self, majorStatus, minorStatus, **kwargs):
     """ passes status """
     my_dict = {"t_id": self.jobId, "inst_id": self.instanceId, "major_status": majorStatus,
                "minor_status": minorStatus}
     if 'resources' in kwargs:
         if kwargs['resources']:
             RM = kwargs['resources']
             if not isinstance(RM, ResourceMonitor):
                 raise Exception("resource must be of type resource monitor")
             my_dict['memory'] = RM.getMemory(unit='Mb')
             my_dict['cpu'] = RM.getCpuTime()
             del kwargs['resources']
     my_dict.update(kwargs)
     if majorStatus in FINAL_STATII:
         # keep only NUMLINES of log file.
         theLog = self.error_log.splitlines()
         if len(theLog) > NUMLINES_LOG:
             self.error_log = "\n".join(theLog[-(NUMLINES_LOG-1):-1])
         my_dict['log']=self.error_log
     # print '*DEBUG* my_dict: %s'%str(my_dict)
     res = Rpost("%s/jobstatus/" % DAMPE_WORKFLOW_URL, data={"args": dumps(my_dict)})
     res.raise_for_status()
     if not res.json().get("result", "nok") == "ok":
         raise Exception(res.json().get("error", "ErrorMissing"))
     if majorStatus in ["Done", "Failed", "Terminated"]:
         witness = open(oPath.join(self.wd, "%s" % majorStatus.upper()), 'w')
         witness.write(self.getJobName())
         witness.close()
     return
Exemplo n.º 2
0
 def postmark_spamcheck(self, message, options):
     data = {'email': message, 'options': options}
     result = POST(self.postmark_spamcheck_url, data)
     result.raise_for_status()
     content = loads(result.content)
     if 'error' in content:
         raise Exception(content['message'])
     return content
 def postmark_spamcheck(self, message, options):
     data = {'email': message, 'options': options}
     result = POST(self.postmark_spamcheck_url, data)
     result.raise_for_status()
     content = loads(result.content)
     if 'error' in content:
         raise Exception(content['message'])
     return content
Exemplo n.º 4
0
 def registerDS(self, filename=None, overwrite=False):
     site = cfg.get("site", "name")
     if filename is None:
         files = [fi['target'] for fi in self.OutputFiles]
     else:
         files = [filename]
     for fi in files:
         tg = oPath.expandvars(fi)
         res = Rpost("%s/datacat/" % DAMPE_WORKFLOW_URL, data={"filename": tg, "site": site,
                                                               "action": "register",
                                                               "overwrite": str(overwrite)})
         res.raise_for_status()
         if not res.json().get("result", "nok") == "ok":
             raise Exception(res.json().get("error", "No error provided."))
Exemplo n.º 5
0
    def test_genbank_extension(self):
        headers = self.headers
        url = self.run_url

        block1 = {
            "metadata": {
                "authors": [],
                "version": "0.0.0",
                "tags": {}
            },
            "options": [],
            "components": [],
            "rules": {},
            "notes": {}
        }
        res = POST(self.api_url + "block", data=json(block1), headers=headers)
        block_id = res.json()["id"]

        input1 = {
            "genbank": "extensions/compute/genbank_to_block/sequence.gb",
            "sequence": "/api/file/block/" + block_id + "/sequence"
        }

        res = POST(url + "genbank_to_block",
                   data=json(input1),
                   headers=headers)
        self.assertTrue(res.status_code == 200)

        res = res.json()
        self.assertTrue("block" in res)

        block = parse(res["block"])
        block["sequence"]["url"] = input1["sequence"]

        res = PUT(self.api_url + "block/" + block_id,
                  data=json(block),
                  headers=headers)
        self.assertTrue(res.status_code == 200)

        res = GET(self.api_url + "block/" + block_id, headers=headers)
        self.assertTrue(res.status_code == 200)
        self.assertTrue(res.json()["id"] == block_id)
        self.assertTrue(res.json()["sequence"]["url"] == input1["sequence"])

        res = GET(self.api_url + "file/block%2f" + block_id + "%2fsequence",
                  headers=headers)
        self.assertTrue(res.status_code == 200)
        self.assertTrue(len(res.text) > 1000)
  def test_cloning(self):
    headers = self.headers
    url  = self.api_url

    proj1 = {
     "metadata": {
        "authors": [],
        "version": "0.0.0",
        "tags": {}
      },
      "components": [
      ],
      "settings": {}
    }

    res = POST(url + "project", data = json(proj1), headers=headers)
    pid1 = res.json()['id']

    res = POST(url + "clone/" + pid1, headers=headers)
    pid2 = res.json()['id']

    res = POST(url + "clone/" + pid2, headers=headers)
    pid3 = res.json()['id']

    res = POST(url + "clone/" + pid3, headers=headers)
    pid4 = res.json()['id']

    res = GET(url + "project/" + pid4, headers=headers)

    hist = GET(url + "ancestors/" + pid4, headers=headers)
    self.assertTrue(hist.status_code==200)

    hist = hist.json()
    self.assertTrue(len(hist)==3)
    self.assertTrue(hist[0]==pid3)
    self.assertTrue(hist[1]==pid2)
    self.assertTrue(hist[2]==pid1)

    child = GET(url + "descendants/" + pid1, headers=headers)
    self.assertTrue(child.status_code==200)
    child = child.json()

    self.assertTrue(len(child)==5)
    self.assertTrue(len(child['leaves'])==1)
Exemplo n.º 7
0
    def test_cloning(self):
        headers = self.headers
        url = self.api_url

        proj1 = {
            "metadata": {
                "authors": [],
                "version": "0.0.0",
                "tags": {}
            },
            "components": [],
            "settings": {}
        }

        res = POST(url + "project", data=json(proj1), headers=headers)
        pid1 = res.json()['id']

        res = POST(url + "clone/" + pid1, headers=headers)
        pid2 = res.json()['id']

        res = POST(url + "clone/" + pid2, headers=headers)
        pid3 = res.json()['id']

        res = POST(url + "clone/" + pid3, headers=headers)
        pid4 = res.json()['id']

        res = GET(url + "project/" + pid4, headers=headers)

        hist = GET(url + "ancestors/" + pid4, headers=headers)
        self.assertTrue(hist.status_code == 200)

        hist = hist.json()
        self.assertTrue(len(hist) == 3)
        self.assertTrue(hist[0] == pid3)
        self.assertTrue(hist[1] == pid2)
        self.assertTrue(hist[2] == pid1)

        child = GET(url + "descendants/" + pid1, headers=headers)
        self.assertTrue(child.status_code == 200)
        child = child.json()

        self.assertTrue(len(child) == 5)
        self.assertTrue(len(child['leaves']) == 1)
  def test_genbank_extension(self):
    headers = self.headers
    url = self.run_url

    block1 = {
      "metadata": {
        "authors": [],
        "version": "0.0.0",
        "tags": {}  },
      "options":[],
      "components":[],
      "rules": {},
      "notes": {}
    }
    res = POST(self.api_url + "block", data = json(block1), headers=headers)
    block_id = res.json()["id"]

    input1 = {
      "genbank":"extensions/compute/genbank_to_block/sequence.gb", 
      "sequence":"/api/file/block/"+block_id+"/sequence"
    }

    res = POST(url + "genbank_to_block", data = json(input1), headers=headers)
    self.assertTrue(res.status_code==200)

    res = res.json()
    self.assertTrue("block" in res)

    block = parse(res["block"])
    block["sequence"]["url"] = input1["sequence"]

    res = PUT(self.api_url + "block/" + block_id, data = json(block), headers=headers)
    self.assertTrue(res.status_code==200)

    res = GET(self.api_url + "block/" + block_id, headers=headers)
    self.assertTrue(res.status_code==200)
    self.assertTrue(res.json()["id"] == block_id)
    self.assertTrue(res.json()["sequence"]["url"] == input1["sequence"])

    res = GET(self.api_url + "file/block%2f"+block_id+"%2fsequence", headers=headers)
    self.assertTrue(res.status_code==200)
    self.assertTrue(len(res.text) > 1000)
  def test_running_extensions(self):
    headers = self.headers
    url = self.run_url

    res = POST(self.api_url + "file/DNA", data="ACGTACGACTACGACTGACGACTACGAGCT", headers=headers)
    input1 = {"DNA":res.text}
    res = POST(url + "translate_dna_example", data = json(input1), headers=headers)
    self.assertTrue(res.status_code==200)
    self.assertTrue(list(res.json().keys())[0]=='Protein')
    self.assertTrue(res.json()["Protein"]=="TYDYD*RLRA")

    input1["Protein"] = "/api/file/myDir/Prot"
    res = POST(url + "translate_dna_example", data = json(input1), headers=headers)
    self.assertTrue(res.status_code==200)
    self.assertTrue(res.json()["Protein"]=='/api/file/myDir/Prot')
Exemplo n.º 10
0
    def test_running_extensions(self):
        headers = self.headers
        url = self.run_url

        res = POST(self.api_url + "file/DNA",
                   data="ACGTACGACTACGACTGACGACTACGAGCT",
                   headers=headers)
        input1 = {"DNA": res.text}
        res = POST(url + "translate_dna_example",
                   data=json(input1),
                   headers=headers)
        self.assertTrue(res.status_code == 200)
        self.assertTrue(list(res.json().keys())[0] == 'Protein')
        self.assertTrue(res.json()["Protein"] == "TYDYD*RLRA")

        input1["Protein"] = "/api/file/myDir/Prot"
        res = POST(url + "translate_dna_example",
                   data=json(input1),
                   headers=headers)
        self.assertTrue(res.status_code == 200)
        self.assertTrue(res.json()["Protein"] == '/api/file/myDir/Prot')
Exemplo n.º 11
0
    def test_block_creation(self):
        headers = self.headers
        url = self.api_url

        block1 = {
            "metadata": {
                "authors": [],
                "version": "0.0.0",
                "tags": {}
            },
            "options": [],
            "components": [],
            "rules": {},
            "notes": {},
            "sequence": {
                "url":
                "/some/location",
                "annotations": [{
                    "id": str(uuid4()),
                    "description": "bla bla",
                    "tags": {},
                    "sequence": "ACGT",
                    "start": 5,
                    "end": 58,
                    "strand": "-"
                }]
            }
        }

        res = POST(url + "block", data=json(block1), headers=headers)
        id1 = res.json()['id']

        self.assertTrue(res.status_code == 200)
        self.assertTrue(len(id1) == 36)

        block2 = {
            "metadata": {
                "authors": [],
                "version": "0.0.0",
                "tags": {}
            },
            "options": [],
            "components": [],
            "rules": {},
            "notes": {}
        }
        res = POST(url + "block", data=json(block2), headers=headers)
        id2 = res.json()['id']

        self.assertTrue(res.status_code == 200)
        self.assertTrue(len(id2) == 36)

        block3 = {
            "metadata": {
                "authors": [],
                "version": "0.0.0",
                "tags": {}
            },
            "components": [id1, id2],
            "options": [],
            "rules": {},
            "notes": {}
        }

        block4 = {
            "metadata": {
                "authors": [],
                "version": "0.0.0",
                "tags": {}
            },
            "options": [id1, id2],
            "components": [],
            "rules": {},
            "notes": {}
        }

        res = POST(url + "block", data=json(block3), headers=headers)
        id3 = res.json()['id']

        self.assertTrue(res.status_code == 200)
        self.assertTrue(len(id3) == 36)

        res = POST(url + "block", data=json(block4), headers=headers)
        id4 = res.json()['id']

        self.assertTrue(res.status_code == 200)
        self.assertTrue(len(id4) == 36)

        proj1 = {
            "metadata": {
                "authors": [],
                "version": "0.0.0",
                "tags": {}
            },
            "components": [id3, id4],
            "settings": {}
        }

        res = POST(url + "project", data=json(proj1), headers=headers)
        pid1 = res.json()['id']

        self.assertTrue(res.status_code == 200)
        self.assertTrue(len(pid1) == 36)

        proj1["settings"] = {"SBOLv-version": "1.2.0"}

        res = PUT(url + "project/" + pid1, data=json(proj1), headers=headers)
        pid1 = res.json()['id']

        self.assertTrue(res.status_code == 200)
        self.assertTrue(len(pid1) == 36)

        res = GET(url + "project/" + pid1,
                  params={"tree": True},
                  headers=headers)

        self.assertTrue(res.status_code == 200)

        res = res.json()

        self.assertTrue(len(res['components']) == 5)
        self.assertTrue(len(res['components']['leaves']) == 3)
Exemplo n.º 12
0
data1 = '{rateLimit{cost limit remaining resetAt}}'

chain = Chain("search")\
        (type = Type("REPOSITORY"), query = "a sort:forks", first = 100)\
        .get("repositoryCount")\
        .get(Chain("pageInfo")\
             .get("endCursor"))\
        .nodes\
        .on("Repository")\
        .get("forkCount")\
        .get(Chain("watchers")\
             (last = 1).\
             get("totalCount"))\
        .get(Chain("stargazers")\
             (last = 1).\
             get("totalCount"))
print("chain = ", chain.to_dict())

logger.info(generate_query(data))
generate_query(data)
resp = Post("https://api.github.com/graphql",
            json=generate_query(data1),
            headers=header)
print(chain.to_dict())
resp = Post("https://api.github.com/graphql",
            json=chain.to_dict(),
            headers=header)

logger.info(resp.json())
  def test_block_creation(self):
    headers = self.headers
    url  = self.api_url

    block1 = {
      "metadata": {
        "authors": [],
        "version": "0.0.0",
        "tags": {}  },
      "options":[],
      "components":[],
      "rules": {},
      "notes": {},
      "sequence": {
        "url": "/some/location",
        "annotations": [
          {
            "id": str(uuid4()),
            "description" : "bla bla",
            "tags" : {},
            "sequence" : "ACGT",
            "start" : 5,
            "end" : 58,
            "strand" : "-"
          }
        ]
      }
    }

    res = POST(url + "block", data = json(block1), headers=headers)
    id1 = res.json()['id']

    self.assertTrue(res.status_code==200)
    self.assertTrue(len(id1)==36)

    block2 = {
      "metadata": {
        "authors": [],
        "version": "0.0.0",
        "tags": {}
      },
      "options":[],
      "components":[],
      "rules": {},
      "notes": {}
    }
    res = POST(url + "block", data = json(block2), headers=headers)
    id2 = res.json()['id']

    self.assertTrue(res.status_code==200)
    self.assertTrue(len(id2)==36)

    block3 = {
     "metadata": {
        "authors": [],
        "version": "0.0.0",
        "tags": {}
      },
      "components": [
        id1,
        id2
      ],
      "options":[],
      "rules": {},
      "notes": {}
    }

    block4 = {
     "metadata": {
        "authors": [],
        "version": "0.0.0",
        "tags": {}
      },
      "options": [
        id1,
        id2
      ],
      "components":[],
      "rules": {},
      "notes": {}
    }

    res = POST(url + "block", data = json(block3), headers=headers)
    id3 = res.json()['id']

    self.assertTrue(res.status_code==200)
    self.assertTrue(len(id3)==36)

    res = POST(url + "block", data = json(block4), headers=headers)
    id4 = res.json()['id']

    self.assertTrue(res.status_code==200)
    self.assertTrue(len(id4)==36)

    proj1 = {
     "metadata": {
        "authors": [],
        "version": "0.0.0",
        "tags": {}
      },
      "components": [
        id3,
        id4
      ],
      "settings": {}
    }

    res = POST(url + "project", data = json(proj1), headers=headers)
    pid1 = res.json()['id']

    self.assertTrue(res.status_code==200)
    self.assertTrue(len(pid1)==36)

    proj1["settings"] = { "SBOLv-version": "1.2.0" }

    res = PUT(url + "project/" + pid1, data = json(proj1), headers=headers)
    pid1 = res.json()['id']

    self.assertTrue(res.status_code==200)
    self.assertTrue(len(pid1)==36)

    res = GET(url + "project/" + pid1, params = {"tree":True}, headers=headers)

    self.assertTrue(res.status_code==200)

    res = res.json()

    self.assertTrue(len(res['components'])==5)
    self.assertTrue(len(res['components']['leaves'])==3)