Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added model status field #108

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/generate-build-metadata.bash
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ model=$(jq \
release_url: $release_url,
spack_packages: $spack_packages_version,
spack_config: $spack_config_version,
status: "active",
spack_version: $spack
}' "$json_dir/spack.lock"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"release_url": "http://example.org/releases",
"spack_packages": "2023.11.23",
"spack_config": "2024.01.01",
"status": "active",
"spack_version": {
"version": "0.20.3",
"commit": "6812713cf470b473a607f0de0e8e1cf53f804fb7"
Expand Down
16 changes: 16 additions & 0 deletions tools/release_provenance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

# Save release data to database
`save_release.py` is used to save release data to the database. It takes a release data JSON file as input in the format described in `test_release_data.json`.
To save the release data to the database, run the following command:

```
python save_release.py test_release_data.json
```

## Update Model Status
To update the model status, run the following command:

```
python update_model_status.py <spack_hash_of_model> <status>
```
The `status` can be `active`, `retracted`, `eol` or `deleted`.
12 changes: 10 additions & 2 deletions tools/release_provenance/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
from sqlalchemy import (
DateTime, Text, String, Column, ForeignKey, Table, UniqueConstraint, Integer )
DateTime, Text, String, Column, ForeignKey, Table, UniqueConstraint, Integer, Enum )
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, sessionmaker
import enum

Base = declarative_base()

Expand All @@ -27,10 +28,17 @@ class ComponentBuild(Base):
install_path = Column(String, nullable=False, unique=True)
model_build = relationship('ModelBuild', secondary="model_component", back_populates='component_build')

class ModelStatusEnum(enum.Enum):
active = "active"
retracted = "retracted"
eol = "eol"
deleted = "deleted"

class ModelBuild(Base):
__tablename__ = "model_build"

spack_hash = Column(String, primary_key=True, index=True)
status = Column(Enum(ModelStatusEnum, name="model_status_type"))
spec = Column(String, nullable=False)
spack_version = Column(String, ForeignKey("spack_version.commit"))
spack_packages = Column(String)
Expand Down
1 change: 1 addition & 0 deletions tools/release_provenance/save_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def get_model_build(model_build_data):
model_build.spec = model_build_data["spec"]
model_build.release_url = model_build_data["release_url"]
model_build.created_at = model_build_data["created_at"]
model_build.status = model_build_data["status"]
session.add(model_build)

return model_build
Expand Down
1 change: 1 addition & 0 deletions tools/release_provenance/test_release_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"release_url": "https://github.com/ACCESS-NRI/ACCESS-OM3/releases",
"spack_packages": "0.20.3",
"spack_config": "0.20.3",
"status": "active",
"spack_version": {
"commit": "6812713cf470b473a607f0de0e8e1cf53f804fb8",
"version": "0.20.3"
Expand Down
22 changes: 22 additions & 0 deletions tools/release_provenance/update_model_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys
from models import *

def update_model_status(model, status):
try:
session = create_session()
model = session.query(ModelBuild).filter(ModelBuild.spack_hash == model).update({
"status": status
})
session.commit()
print("model status updated successfully")
except Exception as e:
print(e)
session.rollback()
raise

finally:
session.close()


if __name__ == "__main__":
update_model_status(sys.argv[1], sys.argv[2])