diff options
author | James Ennis <james.ennis@codethink.co.uk> | 2019-08-22 15:40:35 +0100 |
---|---|---|
committer | James Ennis <james.ennis@codethink.co.uk> | 2019-08-27 15:21:34 +0100 |
commit | bf6ca6615bb5b69defcc41f33625cbfc2b300f1a (patch) | |
tree | ae2d990b5f60997b494a5b18ff3fa82081d2be65 /src/buildstream/_artifactcache.py | |
parent | 6c7a2eeec7b648870ffb8384a794208b05661c9a (diff) | |
download | buildstream-bf6ca6615bb5b69defcc41f33625cbfc2b300f1a.tar.gz |
_artifactcache.py: Add remote support to bst artifact show
If remotes exist, each remote will be checked for the target
artifacts. If an artifact is cached remotely, we make a
record of this.
Diffstat (limited to 'src/buildstream/_artifactcache.py')
-rw-r--r-- | src/buildstream/_artifactcache.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/buildstream/_artifactcache.py b/src/buildstream/_artifactcache.py index f92a7c84f..3357f986a 100644 --- a/src/buildstream/_artifactcache.py +++ b/src/buildstream/_artifactcache.py @@ -383,6 +383,31 @@ class ArtifactCache(BaseCache): return remote_missing_blobs_list + # check_remotes_for_element() + # + # Check if the element is available in any of the remotes + # + # Args: + # element (Element): The element to check + # + # Returns: + # (bool): True if the element is available remotely + # + def check_remotes_for_element(self, element): + # If there are no remotes + if not self._remotes: + return False + + project = element._get_project() + ref = element.get_artifact_name() + for remote in self._remotes[project]: + remote.init() + + if self._query_remote(ref, remote): + return True + + return False + ################################################ # Local Private Methods # ################################################ @@ -520,3 +545,25 @@ class ArtifactCache(BaseCache): f.write(artifact.SerializeToString()) return True + + # _query_remote() + # + # Args: + # ref (str): The artifact ref + # remote (ArtifactRemote): The remote we want to check + # + # Returns: + # (bool): True if the ref exists in the remote, False otherwise. + # + def _query_remote(self, ref, remote): + request = artifact_pb2.GetArtifactRequest() + request.cache_key = ref + try: + artifact_service = artifact_pb2_grpc.ArtifactServiceStub(remote.channel) + artifact_service.GetArtifact(request) + except grpc.RpcError as e: + if e.code() != grpc.StatusCode.NOT_FOUND: + raise ArtifactError("Error when querying: {}".format(e.details())) + return False + + return True |