def get_registry(self): registry_proto = RegistryProto() if self._filepath.exists(): registry_proto.ParseFromString(self._filepath.read_bytes()) else: registry_proto.registry_schema_version = REGISTRY_SCHEMA_VERSION return registry_proto
def get_registry_proto(self): file_obj = TemporaryFile() registry_proto = RegistryProto() try: from botocore.exceptions import ClientError except ImportError as e: from feast.errors import FeastExtrasDependencyImportError raise FeastExtrasDependencyImportError("aws", str(e)) try: bucket = self.s3_client.Bucket(self._bucket) self.s3_client.meta.client.head_bucket(Bucket=bucket.name) except ClientError as e: # If a client error is thrown, then check that it was a 404 error. # If it was a 404 error, then the bucket does not exist. error_code = int(e.response["Error"]["Code"]) if error_code == 404: raise S3RegistryBucketNotExist(self._bucket) else: raise S3RegistryBucketForbiddenAccess(self._bucket) from e try: obj = bucket.Object(self._key) obj.download_fileobj(file_obj) file_obj.seek(0) registry_proto.ParseFromString(file_obj.read()) return registry_proto except ClientError as e: raise FileNotFoundError( f"Error while trying to locate Registry at path {self._uri.geturl()}" ) from e
def get_registry_proto(self): registry_proto = RegistryProto() if self._filepath.exists(): registry_proto.ParseFromString(self._filepath.read_bytes()) return registry_proto raise FileNotFoundError( f'Registry not found at path "{self._filepath}". Have you run "feast apply"?' )
def _initialize_registry(self): """Explicitly initializes the registry with an empty proto if it doesn't exist.""" try: self._get_registry_proto() except FileNotFoundError: registry_proto = RegistryProto() registry_proto.registry_schema_version = REGISTRY_SCHEMA_VERSION self._registry_store.update_registry_proto(registry_proto)
def clone(self) -> "Registry": new_registry = Registry(None, None) new_registry.cached_registry_proto_ttl = timedelta(seconds=0) new_registry.cached_registry_proto = ( self.cached_registry_proto.__deepcopy__() if self.cached_registry_proto else RegistryProto()) new_registry.cached_registry_proto_created = datetime.utcnow() new_registry._registry_store = NoopRegistryStore() return new_registry
def update_registry_proto(self, updater: Callable[[RegistryProto], RegistryProto]): try: registry_proto = self.get_registry_proto() except FileNotFoundError: registry_proto = RegistryProto() registry_proto.registry_schema_version = REGISTRY_SCHEMA_VERSION registry_proto = updater(registry_proto) self._write_registry(registry_proto) return
def _prepare_registry_for_changes(self): """Prepares the Registry for changes by refreshing the cache if necessary.""" try: self._get_registry_proto(allow_cache=True) except FileNotFoundError: registry_proto = RegistryProto() registry_proto.registry_schema_version = REGISTRY_SCHEMA_VERSION self.cached_registry_proto = registry_proto self.cached_registry_proto_created = datetime.now() return self.cached_registry_proto
def to_registry_proto(self) -> RegistryProto: registry_proto = RegistryProto() registry_proto.data_sources.extend( [e.to_proto() for e in self.data_sources]) registry_proto.entities.extend([e.to_proto() for e in self.entities]) registry_proto.feature_views.extend( [fv.to_proto() for fv in self.feature_views]) registry_proto.on_demand_feature_views.extend( [fv.to_proto() for fv in self.on_demand_feature_views]) registry_proto.request_feature_views.extend( [fv.to_proto() for fv in self.request_feature_views]) registry_proto.feature_services.extend( [fs.to_proto() for fs in self.feature_services]) return registry_proto
def get_registry(self): from google.cloud import storage from google.cloud.exceptions import NotFound file_obj = TemporaryFile() registry_proto = RegistryProto() try: bucket = self.gcs_client.get_bucket(self._bucket) except NotFound: raise Exception( f"No bucket named {self._bucket} exists; please create it first." ) if storage.Blob(bucket=bucket, name=self._blob).exists(self.gcs_client): self.gcs_client.download_blob_to_file(self._uri.geturl(), file_obj) file_obj.seek(0) registry_proto.ParseFromString(file_obj.read()) else: registry_proto.registry_schema_version = REGISTRY_SCHEMA_VERSION return registry_proto
def get_registry_proto(self): from google.cloud import storage from google.cloud.exceptions import NotFound file_obj = TemporaryFile() registry_proto = RegistryProto() try: bucket = self.gcs_client.get_bucket(self._bucket) except NotFound: raise Exception( f"No bucket named {self._bucket} exists; please create it first." ) if storage.Blob(bucket=bucket, name=self._blob).exists(self.gcs_client): self.gcs_client.download_blob_to_file( self._uri.geturl(), file_obj, timeout=30 ) file_obj.seek(0) registry_proto.ParseFromString(file_obj.read()) return registry_proto raise FileNotFoundError( f'Registry not found at path "{self._uri.geturl()}". Have you run "feast apply"?' )
def get_registry_proto(self) -> RegistryProto: registry_proto = RegistryProto() try: with _get_conn(self.db_config) as conn, conn.cursor() as cur: cur.execute( sql.SQL( """ SELECT registry FROM {} WHERE version = (SELECT max(version) FROM {}) """ ).format( sql.Identifier(self.table_name), sql.Identifier(self.table_name), ) ) row = cur.fetchone() if row: registry_proto = registry_proto.FromString(row[0]) except psycopg2.errors.UndefinedTable: pass return registry_proto
def __init__(self, registry_config: RegistryConfig, repo_path: Path) -> None: super().__init__() self.registry_proto = RegistryProto()
def _initialize_registry(self): """Explicitly initializes the registry with an empty proto.""" registry_proto = RegistryProto() registry_proto.registry_schema_version = REGISTRY_SCHEMA_VERSION self._registry_store.update_registry_proto(registry_proto)