Skip to content

Commit

Permalink
resource_id -> resource_path
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnBe committed Feb 7, 2024
1 parent 6fec3b5 commit 54c5dc5
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 59 deletions.
44 changes: 23 additions & 21 deletions .github/scripts/s3_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,23 @@ def load_file(self, path) -> str:
# response = requests.get(url)
# return response.content

def check_versions(self, resource_id: str) -> Iterator[VersionStatus]:
def check_versions(self, resource_path: str) -> Iterator[VersionStatus]:
"""
Check model repository for version of model-name.
Returns dictionary of version-status pairs.
"""
logger.debug("Checking versions for {}", resource_id)
version_folders = self.ls(f"{resource_id}/", only_folders=True)
logger.debug("Checking versions for {}", resource_path)
version_folders = self.ls(f"{resource_path}/", only_folders=True)

# For each folder get the contents of status.json
for version in version_folders:

yield self.get_version_status(resource_id, version)
yield self.get_version_status(resource_path, version)

def get_unpublished_version(self, resource_id: str) -> str:
def get_unpublished_version(self, resource_path: str) -> str:
"""Get the unpublisted version"""
versions = list(self.check_versions(resource_id))
versions = list(self.check_versions(resource_path))
if len(versions) == 0:
return "1"
unpublished = [version for version in versions if version.status == "staging"]
Expand All @@ -155,49 +155,51 @@ def get_unpublished_version(self, resource_id: str) -> str:
raise ValueError("Opps! We seem to have > 1 staging versions!!")
return unpublished[0].version

def get_version_status(self, resource_id: str, version: str) -> VersionStatus:
status = self.get_status(resource_id, version)
def get_version_status(self, resource_path: str, version: str) -> VersionStatus:
status = self.get_status(resource_path, version)
status_str = status.get("status", "status-field-unset")
version_path = f"{resource_id}/{version}"
version_path = f"{resource_path}/{version}"
return VersionStatus(version, status_str, version_path)

def get_status(self, resource_id: str, version: str) -> dict:
version_path = f"{resource_id}/{version}"
logger.debug("resource_id: {}, version: {}", resource_id, version)
def get_status(self, resource_path: str, version: str) -> dict:
version_path = f"{resource_path}/{version}"
logger.debug("resource_path: {}, version: {}", resource_path, version)
status_path = f"{version_path}/status.json"
logger.debug("Getting status using path {}", status_path)
status = self.load_file(status_path)
status = json.loads(status)
return status

def put_status(self, resource_id: str, version: str, status: dict):
logger.debug("Updating status for {}-{}, with {}", resource_id, version, status)
def put_status(self, resource_path: str, version: str, status: dict):
logger.debug(
"Updating status for {}-{}, with {}", resource_path, version, status
)
contents = json.dumps(status).encode()
file_object = io.BytesIO(contents)

self.put(
f"{resource_id}/{version}/status.json",
f"{resource_path}/{version}/status.json",
file_object,
length=len(contents),
content_type="application/json",
)

def get_log(self, resource_id: str, version: str) -> dict:
version_path = f"{resource_id}/{version}"
logger.debug("resource_id: {}, version: {}", resource_id, version)
def get_log(self, resource_path: str, version: str) -> dict:
version_path = f"{resource_path}/{version}"
logger.debug("resource_path: {}, version: {}", resource_path, version)
path = f"{version_path}/log.json"
logger.debug("Getting log using path {}", path)
log = self.load_file(path)
log = json.loads(log)
return log

def put_log(self, resource_id: str, version: str, log: dict):
logger.debug("Updating log for {}-{}, with {}", resource_id, version, log)
def put_log(self, resource_path: str, version: str, log: dict):
logger.debug("Updating log for {}-{}, with {}", resource_path, version, log)
contents = json.dumps(log).encode()
file_object = io.BytesIO(contents)

self.put(
f"{resource_id}/{version}/log.json",
f"{resource_path}/{version}/log.json",
file_object,
length=len(contents),
content_type="application/json",
Expand Down
10 changes: 5 additions & 5 deletions .github/scripts/update_status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
# S3_FOLDER
# S3_ACCESS_KEY_ID
# S3_SECRET_ACCESS_KEY
# First arg is now resource_id
# First arg is now resource_path

FILENAME=status.json

RESOURCE_ID=$1
resource_path=$1
STATUS=$2

if [ -z "$RESOURCE_ID" ]; then
printf '%s\n' "RESOURCE_ID is unset or empty" >&2;
if [ -z "$resource_path" ]; then
printf '%s\n' "resource_path is unset or empty" >&2;
exit 1
fi
if [ -z "$S3_HOST" ]; then
Expand All @@ -40,7 +40,7 @@ fi

#curl -X PUT -H 'Content-Type: application/json' -d '{"status": "'"$2"'"}' "$1"

RESOURCE="/${S3_BUCKET}/${S3_FOLDER}/${RESOURCE_ID}/${FILENAME}"
RESOURCE="/${S3_BUCKET}/${S3_FOLDER}/${resource_path}/${FILENAME}"
CONTENT_TYPE="application/json"
DATE=`date -R`
_SIGNATURE="PUT\n\n${CONTENT_TYPE}\n${DATE}\n${RESOURCE}"
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/ci_runner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: CI Runner
on:
workflow_dispatch:
inputs:
resource_id:
description: 'Bioimageio ID - to be used to access the resource on S3'
resource_path:
description: 'Bioimageio wide, version specific resource identifier "resource_path/version"'
required: true
type: string
package_url:
Expand Down Expand Up @@ -38,19 +38,19 @@ jobs:
python -m pip install "minio==7.2.3" "ruamel.yaml==0.18.5" "bioimageio.spec==0.4.9.post5" "typer"
- name: Unzip model file
run: |
python .github/scripts/update_status.py "${{ inputs.resource_id }}" "Unzipping package" "1"
python .github/scripts/unzip_model.py "${{inputs.resource_id}}" "${{inputs.package_url}}"
python .github/scripts/update_status.py "${{ inputs.resource_path }}" "Unzipping package" "1"
python .github/scripts/unzip_model.py "${{inputs.resource_path}}" "${{inputs.package_url}}"
- name: Validate format
id: validate
run: |
python .github/scripts/update_status.py "${{ inputs.resource_id }}" "Starting validation" "2"
python .github/scripts/validate_format.py "${{ inputs.resource_id }}" "${{inputs.package_url}}"
python .github/scripts/update_status.py "${{ inputs.resource_path }}" "Starting validation" "2"
python .github/scripts/validate_format.py "${{ inputs.resource_path }}" "${{inputs.package_url}}"
- run: |
python .github/scripts/update_status.py "${{ inputs.resource_id }}" "Starting additional tests" "3"
python .github/scripts/update_status.py "${{ inputs.resource_path }}" "Starting additional tests" "3"
if: steps.validate.outputs.has_dynamic_test_cases == 'yes'
- run: |
python .github/scripts/update_status.py "${{ inputs.resource_id }}" "Validation done" "3"
python .github/scripts/update_status.py "${{ inputs.resource_path }}" "Validation done" "3"
if: steps.validate.outputs.has_dynamic_test_cases == 'no'
Expand Down Expand Up @@ -90,4 +90,4 @@ jobs:
steps:
- uses: actions/checkout@v4
- run: |
python .github/scripts/update_status.py "${{ inputs.resource_id }}" "Awaiting review" "4"
python .github/scripts/update_status.py "${{ inputs.resource_path }}" "Awaiting review" "4"
8 changes: 4 additions & 4 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: publish
on:
workflow_dispatch:
inputs:
resource_id:
resource_path:
description: 'Bioimageio ID of the resource - to be used to access the resource on S3'
required: true
type: string
Expand Down Expand Up @@ -33,6 +33,6 @@ jobs:
python -m pip install "minio==7.2.3" "loguru==0.7.2" "packaging==23.2" "spdx-license-list==3.22" "ruamel.yaml==0.18.5" "typer"
- name: Publish to Zenodo
run: |
python .github/scripts/update_status.py "${{ inputs.resource_id }}" "Publishing to Zenodo" "5"
python .github/scripts/upload_model_to_zenodo.py --resource_id "${{inputs.resource_id}}"
python .github/scripts/update_status.py "${{ inputs.resource_id }}" "Publishing complete" "6"
python .github/scripts/update_status.py "${{ inputs.resource_path }}" "Publishing to Zenodo" "5"
python .github/scripts/upload_model_to_zenodo.py --resource_path "${{inputs.resource_path}}"
python .github/scripts/update_status.py "${{ inputs.resource_path }}" "Publishing complete" "6"
2 changes: 1 addition & 1 deletion functions/create_status.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default async (event, context) => {
//'ref': 'main',
//'inputs':{
//'status_url': data.status_url,
//'resource_id': data.resource_id,
//'resource_path': data.resource_path,
//}
//})
//};
Expand Down
6 changes: 3 additions & 3 deletions functions/notify_ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const headers = {

export default async (event, context) => {
const data = await event.json();
if (!data.resource_id) {
const error_message = "Failed: resource_id not found in request json";
if (!data.resource_path) {
const error_message = "Failed: resource_path not found in request json";
console.error()
const res = Response.json({ 'message': error_message, 'status': 500 });
res.headers.set("Access-Control-Allow-Origin", "*");
Expand All @@ -38,7 +38,7 @@ export default async (event, context) => {
body: JSON.stringify({
'ref': GITHUB_BRANCH,
'inputs': {
'resource_id': data.resource_id,
'resource_path': data.resource_path,
'package_url': data.package_url,
}
})
Expand Down
10 changes: 5 additions & 5 deletions src/components/Uploader/Review.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import JSONTree from 'svelte-json-tree';
let model_name_message = "";
let resource_id = uploader.resource_id;
let resource_path = uploader.resource_path;
let rdf = uploader.rdf;
let ready_to_publish = uploader.ready_to_publish();
Expand All @@ -24,14 +24,14 @@
async function regenerate_nickname(){
await uploader.regenerate_nickname();
resource_id = uploader.resource_id;
resource_path = uploader.resource_path;
ready_to_publish = uploader.ready_to_publish();
console.log("Ready to publish?", ready_to_publish);
rdf = uploader.rdf;
//rerender = !rerender;
}
if(!resource_id) regenerate_nickname();
if(!resource_path) regenerate_nickname();
</script>

Expand All @@ -44,9 +44,9 @@
<!--{#key rerender}-->
<p class="level">
{#if model_name_message }({model_name_message}){/if}
{#if resource_id}
{#if resource_path}
Your model nickname is:
<code style="min-width:10em;">{resource_id.name} {resource_id.icon}&nbsp;</code>
<code style="min-width:10em;">{resource_path.name} {resource_path.icon}&nbsp;</code>
{/if}
<button on:click={regenerate_nickname}>Regenerate nickname</button>
</p>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Uploader/UploadStatus.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
let error_element: Object;
let last_error_object: Error;
let step: UploaderStep = uploader.status.step;
let model_name = uploader.resource_id.name;
let model_name = uploader.resource_path.name;
const dispatch = createEventDispatcher();
function copy_error_to_clipboard(text: string){
Expand Down Expand Up @@ -76,7 +76,7 @@
<h4>Almost there,</h4>

<p><b>There's nothing you need to do right now. Your model is uploaded and the CI-bots have started their work!</b><p>
<p>You can check the status of the CI at any point from <a href="#/status/{uploader.resource_id.name}">here</a></p>
<p>You can check the status of the CI at any point from <a href="#/status/{uploader.resource_path.name}">here</a></p>


<button on:click={restart}>Upload another model</button>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Uploader/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
{:else if step == "uploading"}
<UploadStatus {uploader} on:done={()=>{step="add"}} />
<!--{:else if step == "done"}-->
<!--<a href="/status/{uploader.resource_id.name}">Go to status page</a>-->
<!--<a href="/status/{uploader.resource_path.name}">Go to status page</a>-->
{:else}
<Notification>
Opps! something went wrong 😬
Expand Down
16 changes: 8 additions & 8 deletions src/lib/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class Uploader {
error_object: Error | null = null;
files: File[] = [];
login_url: string | null = null;
resource_id: ResourceId | null = null;
resource_path: ResourceId | null = null;
package_url: string | null = null;
rdf: any = null;
render_callbacks: (() => void)[] = [];
Expand Down Expand Up @@ -92,7 +92,7 @@ export class Uploader {
}

reset() {
this.resource_id = null;
this.resource_path = null;
this.rdf = null;
this.status.reset();
}
Expand Down Expand Up @@ -251,7 +251,7 @@ export class Uploader {

ready_to_publish() {
if (!this.ready_for_review()) return false;
if (!this.resource_id) return false;
if (!this.resource_path) return false;
return true;
}

Expand All @@ -266,7 +266,7 @@ export class Uploader {
const model_name = Object.assign(new ResourceId, await (await fetch(generate_name_url)).json());
console.log("Generated name:", model_name);
const error = "";
this.resource_id = model_name;
this.resource_path = model_name;
this.rdf.nickname = model_name.name;
return { model_name, error };
} catch (err) {
Expand All @@ -278,13 +278,13 @@ export class Uploader {
}

async upload_file(file: File, progress_callback: null | ((val: string, tot: string) => null)) {
if (!this.resource_id) {
throw new Error("Unable to upload, resource_id not set");
if (!this.resource_path) {
throw new Error("Unable to upload, resource_path not set");
};
this.status.message = "Uploading";
this.status.step = UploaderStep.UPLOADING;
this.render();
const filename = `${this.resource_id.id}/${file.name}`;
const filename = `${this.resource_path.id}/${file.name}`;
const url_put = await this.storage.generate_presigned_url(
this.storage_info.bucket,
this.storage_info.prefix + filename,
Expand Down Expand Up @@ -422,7 +422,7 @@ export class Uploader {
const resp = await fetch(notify_ci_url, {
method: 'POST',
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ 'resource_id': this.resource_id!.id, 'package_url': this.zip_urls!.get })
body: JSON.stringify({ 'resource_path': this.resource_path!.id, 'package_url': this.zip_urls!.get })
});
if (resp.status === 200) {
const ci_resp = (await resp.json());
Expand Down

0 comments on commit 54c5dc5

Please sign in to comment.