Skip to content

Commit

Permalink
ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
korikuzma committed Sep 23, 2024
1 parent 21ef8d7 commit 51d867d
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 118 deletions.
53 changes: 20 additions & 33 deletions codebuild/deploy_eb_env.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,37 @@
"""Module for deploying MetaKB EB environment."""

import boto3
import time
elasticbeanstalk = boto3.client('elasticbeanstalk')
servicecatalog = boto3.client('servicecatalog')

elasticbeanstalk = boto3.client("elasticbeanstalk")
servicecatalog = boto3.client("servicecatalog")
terminate_time = 12
eb_app_name = "Seqrepo"
eb_env_name = "Seqrepo-staging-env"
sc_product_id = "prod-qg2twc66t544g"
print(f'Launching new Service Catalog Product for staging environment: '
f'{eb_app_name}')
sc_product_artifacts =\
servicecatalog.list_provisioning_artifacts(ProductId=sc_product_id)
for artifact in sc_product_artifacts['ProvisioningArtifactDetails']:
if artifact['Active']:
provisioning_artifact_id = artifact['Id']
print(f"Launching new Service Catalog Product for staging environment: " f"{eb_app_name}")
sc_product_artifacts = servicecatalog.list_provisioning_artifacts(ProductId=sc_product_id)
for artifact in sc_product_artifacts["ProvisioningArtifactDetails"]:
if artifact["Active"]:
provisioning_artifact_id = artifact["Id"]
try:
eb_provisioned_product = servicecatalog.provision_product(
ProductId=sc_product_id,
ProvisioningArtifactId=provisioning_artifact_id,
ProvisionedProductName=eb_env_name,
ProvisioningParameters=[
{
'Key': 'Env',
'Value': eb_app_name
},
{
'Key': 'EnvType',
'Value': 'staging'
},
{
'Key': 'TerminateTime',
'Value': str(terminate_time)
}
])
eb_provisioned_product_Id = \
eb_provisioned_product['RecordDetail']['ProvisionedProductId']
product_status = servicecatalog.describe_provisioned_product(
Id=eb_provisioned_product_Id)
eb_provisioned_product_status =\
product_status['ProvisionedProductDetail']['Status']
{"Key": "Env", "Value": eb_app_name},
{"Key": "EnvType", "Value": "staging"},
{"Key": "TerminateTime", "Value": str(terminate_time)},
],
)
eb_provisioned_product_Id = eb_provisioned_product["RecordDetail"]["ProvisionedProductId"]
product_status = servicecatalog.describe_provisioned_product(Id=eb_provisioned_product_Id)
eb_provisioned_product_status = product_status["ProvisionedProductDetail"]["Status"]
while eb_provisioned_product_status == "UNDER_CHANGE":
time.sleep(10)
product_status = servicecatalog.describe_provisioned_product(
Id=eb_provisioned_product_Id)
eb_provisioned_product_status = \
product_status['ProvisionedProductDetail']['Status']
product_status = servicecatalog.describe_provisioned_product(Id=eb_provisioned_product_Id)
eb_provisioned_product_status = product_status["ProvisionedProductDetail"]["Status"]
print(eb_provisioned_product_status)
except Exception as e:
print(str(e))
print(str(e))
51 changes: 19 additions & 32 deletions codebuild/deploy_eb_env_dev.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,37 @@
"""Module for deploying MetaKB EB environment."""

import boto3
import time
elasticbeanstalk = boto3.client('elasticbeanstalk')
servicecatalog = boto3.client('servicecatalog')

elasticbeanstalk = boto3.client("elasticbeanstalk")
servicecatalog = boto3.client("servicecatalog")
terminate_time = 12
eb_app_name = "Seqrepo"
eb_env_name = "Seqrepo-dev-env"
sc_product_id = "prod-qg2twc66t544g"
print(f'Launching new Service Catalog Product for staging environment: '
f'{eb_app_name}')
sc_product_artifacts =\
servicecatalog.list_provisioning_artifacts(ProductId=sc_product_id)
for artifact in sc_product_artifacts['ProvisioningArtifactDetails']:
if artifact['Active']:
provisioning_artifact_id = artifact['Id']
print(f"Launching new Service Catalog Product for staging environment: " f"{eb_app_name}")
sc_product_artifacts = servicecatalog.list_provisioning_artifacts(ProductId=sc_product_id)
for artifact in sc_product_artifacts["ProvisioningArtifactDetails"]:
if artifact["Active"]:
provisioning_artifact_id = artifact["Id"]
try:
eb_provisioned_product = servicecatalog.provision_product(
ProductId=sc_product_id,
ProvisioningArtifactId=provisioning_artifact_id,
ProvisionedProductName=eb_env_name,
ProvisioningParameters=[
{
'Key': 'Env',
'Value': eb_app_name
},
{
'Key': 'EnvType',
'Value': 'dev'
},
{
'Key': 'TerminateTime',
'Value': str(terminate_time)
}
])
eb_provisioned_product_Id = \
eb_provisioned_product['RecordDetail']['ProvisionedProductId']
product_status = servicecatalog.describe_provisioned_product(
Id=eb_provisioned_product_Id)
eb_provisioned_product_status =\
product_status['ProvisionedProductDetail']['Status']
{"Key": "Env", "Value": eb_app_name},
{"Key": "EnvType", "Value": "dev"},
{"Key": "TerminateTime", "Value": str(terminate_time)},
],
)
eb_provisioned_product_Id = eb_provisioned_product["RecordDetail"]["ProvisionedProductId"]
product_status = servicecatalog.describe_provisioned_product(Id=eb_provisioned_product_Id)
eb_provisioned_product_status = product_status["ProvisionedProductDetail"]["Status"]
while eb_provisioned_product_status == "UNDER_CHANGE":
time.sleep(10)
product_status = servicecatalog.describe_provisioned_product(
Id=eb_provisioned_product_Id)
eb_provisioned_product_status = \
product_status['ProvisionedProductDetail']['Status']
product_status = servicecatalog.describe_provisioned_product(Id=eb_provisioned_product_Id)
eb_provisioned_product_status = product_status["ProvisionedProductDetail"]["Status"]
print(eb_provisioned_product_status)
except Exception as e:
print(str(e))
29 changes: 12 additions & 17 deletions codebuild/terminate_eb_env.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
"""Module for terminating MetaKB EB environment."""

import boto3
import json
import time
client = boto3.client('lambda')
servicecatalog = boto3.client('servicecatalog')

client = boto3.client("lambda")
servicecatalog = boto3.client("servicecatalog")
eb_env_name = "Seqrepo-staging-env"
data = {"sc_provisioned_name": eb_env_name}
client.invoke(FunctionName='igm-inf-terminate-provisioned-product',
Payload=json.dumps(data))
client.invoke(FunctionName="igm-inf-terminate-provisioned-product", Payload=json.dumps(data))
time.sleep(10)
provisioned_product =\
servicecatalog.describe_provisioned_product(Name=eb_env_name)
eb_provisioned_product_Id = \
provisioned_product['ProvisionedProductDetail']['Id']
product_status = servicecatalog.describe_provisioned_product(
Id=eb_provisioned_product_Id)
eb_provisioned_product_status = \
product_status['ProvisionedProductDetail']['Status']
provisioned_product = servicecatalog.describe_provisioned_product(Name=eb_env_name)
eb_provisioned_product_Id = provisioned_product["ProvisionedProductDetail"]["Id"]
product_status = servicecatalog.describe_provisioned_product(Id=eb_provisioned_product_Id)
eb_provisioned_product_status = product_status["ProvisionedProductDetail"]["Status"]
while eb_provisioned_product_status == "UNDER_CHANGE":
time.sleep(10)
try:
product_status = servicecatalog.describe_provisioned_product(
Id=eb_provisioned_product_Id)
eb_provisioned_product_status = \
product_status['ProvisionedProductDetail']['Status']
product_status = servicecatalog.describe_provisioned_product(Id=eb_provisioned_product_Id)
eb_provisioned_product_status = product_status["ProvisionedProductDetail"]["Status"]
except: # noqa: E722
eb_provisioned_product_status = "PRODUCT NOT FOUND"
print(eb_provisioned_product_status)
print(eb_provisioned_product_status)
29 changes: 12 additions & 17 deletions codebuild/terminate_eb_env_dev.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
"""Module for terminating MetaKB EB environment."""

import boto3
import json
import time
client = boto3.client('lambda')
servicecatalog = boto3.client('servicecatalog')

client = boto3.client("lambda")
servicecatalog = boto3.client("servicecatalog")
eb_env_name = "Seqrepo-dev-env"
data = {"sc_provisioned_name": eb_env_name}
client.invoke(FunctionName='igm-inf-terminate-provisioned-product',
Payload=json.dumps(data))
client.invoke(FunctionName="igm-inf-terminate-provisioned-product", Payload=json.dumps(data))
time.sleep(10)
provisioned_product =\
servicecatalog.describe_provisioned_product(Name=eb_env_name)
eb_provisioned_product_Id = \
provisioned_product['ProvisionedProductDetail']['Id']
product_status = servicecatalog.describe_provisioned_product(
Id=eb_provisioned_product_Id)
eb_provisioned_product_status = \
product_status['ProvisionedProductDetail']['Status']
provisioned_product = servicecatalog.describe_provisioned_product(Name=eb_env_name)
eb_provisioned_product_Id = provisioned_product["ProvisionedProductDetail"]["Id"]
product_status = servicecatalog.describe_provisioned_product(Id=eb_provisioned_product_Id)
eb_provisioned_product_status = product_status["ProvisionedProductDetail"]["Status"]
while eb_provisioned_product_status == "UNDER_CHANGE":
time.sleep(10)
try:
product_status = servicecatalog.describe_provisioned_product(
Id=eb_provisioned_product_Id)
eb_provisioned_product_status = \
product_status['ProvisionedProductDetail']['Status']
product_status = servicecatalog.describe_provisioned_product(Id=eb_provisioned_product_Id)
eb_provisioned_product_status = product_status["ProvisionedProductDetail"]["Status"]
except: # noqa: E722
eb_provisioned_product_status = "PRODUCT NOT FOUND"
print(eb_provisioned_product_status)
print(eb_provisioned_product_status)
25 changes: 14 additions & 11 deletions misc/load-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
continuously but rather stabilize at a relatively low level on the order of tens of files.
"""


import argparse
import pathlib
import random
Expand All @@ -56,12 +55,8 @@ def log(log_queue: multiprocessing.Queue, line: str):


def lsof_count(dirname: str) -> int:
lsof_cmd = [
"bash", "-c",
f"lsof +D {dirname} | wc -l"]
lsof_p = subprocess.Popen(
lsof_cmd,
stdout=subprocess.PIPE)
lsof_cmd = ["bash", "-c", f"lsof +D {dirname} | wc -l"]
lsof_p = subprocess.Popen(lsof_cmd, stdout=subprocess.PIPE)
(stdout, _) = lsof_p.communicate()
stdout = stdout.decode("utf-8").strip()
return int(stdout)
Expand Down Expand Up @@ -106,7 +101,8 @@ def run(self):
print(f"{self}: Done; processed {self.n} accessions", flush=True)
break
self.seqrepo_dataproxy.get_sequence(
ac, self.query_bound_start, self.query_bound_end)
ac, self.query_bound_start, self.query_bound_end
)
self.n += 1
except queue.Empty:
pass
Expand Down Expand Up @@ -151,8 +147,13 @@ def stop(self):
def parse_args(argv):
ap = argparse.ArgumentParser(description=__doc__)
ap.add_argument("-n", "--num-workers", type=int, default=1)
ap.add_argument("-s", "--seqrepo-path", type=pathlib.Path, required=True,
help="Local SeqRepo instance to get input values from, and to monitor open file count in")
ap.add_argument(
"-s",
"--seqrepo-path",
type=pathlib.Path,
required=True,
help="Local SeqRepo instance to get input values from, and to monitor open file count in",
)
ap.add_argument("-u", "--seqrepo-rest-uri", type=str, default="http://localhost:5000/seqrepo")
ap.add_argument("-m", "--max-accessions", type=int, required=True)
ap.add_argument("-f", "--fd-cache-size", type=int, default=0)
Expand All @@ -175,7 +176,8 @@ def main(argv):
# log_worker.start()

t_filler = multiprocessing.Process(
target=queue_filler_target, args=(input_queue, acs, opts.num_workers))
target=queue_filler_target, args=(input_queue, acs, opts.num_workers)
)
t_filler.start()

workers = []
Expand Down Expand Up @@ -213,5 +215,6 @@ def main(argv):

if __name__ == "__main__":
import coloredlogs

coloredlogs.install(level="INFO")
main(argv=sys.argv[1:])
4 changes: 1 addition & 3 deletions src/seqrepo_rest_service/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import coloredlogs
import connexion
from biocommons.seqrepo import SeqRepo
from flask import Flask, redirect

from . import __version__
from flask import redirect

WAIT_POLL_PERIOD = 15 # seconds between polling for SEQREPO PATH

Expand Down
7 changes: 6 additions & 1 deletion src/seqrepo_rest_service/refget/routes/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
from connexion import NoContent, request

from seqrepo_rest_service.threadglobals import get_seqrepo
from seqrepo_rest_service.utils import get_sequence_id, base64url_to_hex, problem, valid_content_types
from seqrepo_rest_service.utils import (
get_sequence_id,
base64url_to_hex,
problem,
valid_content_types,
)


_logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion src/seqrepo_rest_service/refget/routes/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get(id, start=None, end=None):
start, end = int(m.group(1)), int(m.group(2)) + 1
_logger.debug(f"Parsed `{range_header}` as ({start}, {end})")
if start > end:
return problem(416, f"Range queries may specify start > end")
return problem(416, "Range queries may specify start > end")

sr = get_seqrepo()
seq_id = get_sequence_id(sr, id)
Expand Down
3 changes: 0 additions & 3 deletions src/seqrepo_rest_service/refget/routes/serviceInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import biocommons.seqrepo
import bioutils

from ... import __version__
from ...threadglobals import get_seqrepo


def get():
sr = get_seqrepo()
Expand Down

0 comments on commit 51d867d

Please sign in to comment.