aipmodel 0.2.69__tar.gz → 0.2.71__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aipmodel
3
- Version: 0.2.69
3
+ Version: 0.2.71
4
4
  Summary: SDK for model registration, versioning, and storage
5
5
  Home-page: https://github.com/AIP-MLOPS/model-registry
6
6
  Author: AIP MLOPS Team
@@ -81,17 +81,32 @@ class CephS3Manager:
81
81
  print(f"[SDK_INFO] Bucket: {self.bucket_name}")
82
82
  print("[SDK_DEBUG] Creating S3 client...")
83
83
 
84
+ _cfg = {
85
+ "retries": {
86
+ "max_attempts": int(os.environ.get("S3_BOTO_MAX_ATTEMPTS", 10)),
87
+ "mode": "adaptive",
88
+ }
89
+ }
90
+ try:
91
+ # boto3 >= 1.36 defaults to CRC32 checksums, which MinIO/Ceph RGW
92
+ # reject on DeleteObjects ("MissingContentMD5"). "when_required"
93
+ # restores the classic Content-MD5 behavior those backends expect.
94
+ client_config = Config(
95
+ request_checksum_calculation="when_required",
96
+ response_checksum_validation="when_required",
97
+ **_cfg,
98
+ )
99
+ except TypeError:
100
+ # older botocore (< 1.36) doesn't know the checksum params — and
101
+ # doesn't need them (it already sends Content-MD5).
102
+ client_config = Config(**_cfg)
103
+
84
104
  self.s3 = boto3.client(
85
105
  "s3",
86
106
  endpoint_url=CEPH_ENDPOINT_URL,
87
107
  aws_access_key_id=CEPH_ADMIN_ACCESS_KEY,
88
108
  aws_secret_access_key=CEPH_ADMIN_SECRET_KEY,
89
- config=Config(
90
- retries={
91
- "max_attempts": int(os.environ.get("S3_BOTO_MAX_ATTEMPTS", 10)),
92
- "mode": "adaptive",
93
- }
94
- ),
109
+ config=client_config,
95
110
  )
96
111
 
97
112
  if self.verbose:
@@ -832,7 +847,18 @@ class CephS3Manager:
832
847
 
833
848
  for i in range(0, len(objs), 1000):
834
849
  chunk = objs[i:i+1000]
835
- self.s3.delete_objects(Bucket=self.bucket_name, Delete={"Objects": chunk})
850
+ try:
851
+ self.s3.delete_objects(Bucket=self.bucket_name, Delete={"Objects": chunk})
852
+ except ClientError as e:
853
+ # boto3 >= 1.36 sends CRC32 checksums that MinIO/Ceph RGW
854
+ # reject on the batch API ("MissingContentMD5"). Fall back
855
+ # to per-object deletes, which need no checksum header.
856
+ if e.response.get("Error", {}).get("Code") != "MissingContentMD5":
857
+ raise
858
+ if self.verbose:
859
+ print("[SDK_WARN] Batch delete rejected (MissingContentMD5); falling back to per-object deletes")
860
+ for obj in chunk:
861
+ self.s3.delete_object(Bucket=self.bucket_name, Key=obj["Key"])
836
862
 
837
863
  if self.verbose:
838
864
  print("[SDK_SUCCESS] Folder deleted")
@@ -11,5 +11,5 @@ if _os.environ.get("AIPMODEL_UPDATE_CHECK", "").lower() in ("1", "true", "yes"):
11
11
 
12
12
  __all__ = ["MLOpsManager", "CephS3Manager"]
13
13
 
14
- __version__ = "0.2.69"
14
+ __version__ = "0.2.71"
15
15
  __description__ = "SDK for model registration, versioning, and storage"
@@ -1772,6 +1772,70 @@ class MLOpsManager:
1772
1772
  pass
1773
1773
  return None
1774
1774
 
1775
+ def remove_missing_version(self, model_name, version):
1776
+ """
1777
+ Sync-repair for a ZOMBIE version: the registry references `version` but
1778
+ its S3 files are gone (e.g. deleted by hand in Ceph). Removes the version
1779
+ from the registry so registry and storage agree again. Refuses to run if
1780
+ the files actually still exist (use delete_model for a real delete).
1781
+ """
1782
+ report = self.verify_model_integrity(model_name=model_name)
1783
+ entry = next((v for v in report["versions"] if v["version"] == version), None)
1784
+ if entry is None:
1785
+ raise ModelNotFoundError(f"Version '{version}' not found for model '{model_name}'")
1786
+ if entry["files_exist"]:
1787
+ raise ValueError(
1788
+ f"Files for version '{version}' of '{model_name}' still exist in storage — "
1789
+ f"this is not a zombie. Use delete_model to actually delete it."
1790
+ )
1791
+ # delete_model is metadata-first and its S3 delete is a no-op for an
1792
+ # already-empty prefix, so it is exactly the sync we need.
1793
+ self.delete_model(model_name=model_name, version=version)
1794
+ print(f"[SDK_SUCCESS] Synced: removed zombie version '{version}' of '{model_name}' from registry.")
1795
+
1796
+ def purge_orphan_folders(self, model_name=None, model_id=None):
1797
+ """
1798
+ Sync-repair for ORPHAN folders inside a registered model: S3 folders
1799
+ under the model that no registry version references (leftovers from an
1800
+ interrupted operation). Deletes those folders. Returns the list purged.
1801
+ """
1802
+ report = self.verify_model_integrity(model_name=model_name, model_id=model_id)
1803
+ mid = report["model_id"]
1804
+ data = self.models.get_by_id(mid)
1805
+ is_public = self._extract_metadata_value(data.get("metadata", {}), "public", "false").lower() == "true"
1806
+ mgr = self._get_ceph_manager(is_public)
1807
+ purged = []
1808
+ for folder in report["orphan_folders"]:
1809
+ prefix = f"_models/{mid}/{folder}/"
1810
+ try:
1811
+ mgr.delete_folder(prefix)
1812
+ purged.append(folder)
1813
+ except Exception as e:
1814
+ print(f"[SDK_WARN] Could not purge orphan folder {prefix}: {e}")
1815
+ print(f"[SDK_SUCCESS] Purged {len(purged)} orphan folder(s) for model '{report['model_name']}'.")
1816
+ return purged
1817
+
1818
+ def purge_orphan_model(self, model_id):
1819
+ """
1820
+ Sync-repair for an ORPHAN model: an S3 model folder the registry does
1821
+ not know about (e.g. the registry entry was deleted while storage
1822
+ survived). Deletes the whole `_models/{model_id}/` folder. Refuses to
1823
+ run if the id IS known to the registry (that would be a real delete —
1824
+ use delete_model).
1825
+ """
1826
+ registry_ids = {m.get("id") for m in (self.models.get_all(self.project_id) or [])}
1827
+ if model_id in registry_ids:
1828
+ raise ValueError(
1829
+ f"Model id '{model_id}' exists in the registry — not an orphan. "
1830
+ f"Use delete_model to delete a registered model."
1831
+ )
1832
+ mgr = self._get_ceph_manager(False)
1833
+ base = f"_models/{model_id}/"
1834
+ if not mgr.check_if_exists(base):
1835
+ raise ModelNotFoundError(f"No storage folder found at {base}")
1836
+ mgr.delete_folder(base)
1837
+ print(f"[SDK_SUCCESS] Purged orphan storage folder {base}.")
1838
+
1775
1839
  def recover_model_from_storage(self, model_id):
1776
1840
  """
1777
1841
  Rebuild a registry (Mlops-Core) entry for a model that exists in S3 but
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aipmodel
3
- Version: 0.2.69
3
+ Version: 0.2.71
4
4
  Summary: SDK for model registration, versioning, and storage
5
5
  Home-page: https://github.com/AIP-MLOPS/model-registry
6
6
  Author: AIP MLOPS Team
@@ -31,7 +31,7 @@ version, description = read_meta()
31
31
 
32
32
  setup(
33
33
  name="aipmodel",
34
- version="0.2.69",
34
+ version="0.2.71",
35
35
  description=description,
36
36
  author="AIP MLOPS Team",
37
37
  author_email="mohmmadweb@gmail.com",
File without changes
File without changes
File without changes
File without changes