diff options
author | Raoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk> | 2018-12-05 10:14:25 +0000 |
---|---|---|
committer | Raoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk> | 2018-12-05 11:18:16 +0000 |
commit | 03ab479e625d6765184490ec93d6e86cbe9f7ccc (patch) | |
tree | a3cd4f9c4b2b28ed5699347833767c1d045eeca1 | |
parent | 73362448289e55106c9700a716f638b476ab8a76 (diff) | |
download | buildstream-03ab479e625d6765184490ec93d6e86cbe9f7ccc.tar.gz |
_sandboxremote.py: Add action-service endpoint
The endpoint may not necessarily be the same as execution-service endpoint.
Part of #628
-rw-r--r-- | buildstream/sandbox/_sandboxremote.py | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/buildstream/sandbox/_sandboxremote.py b/buildstream/sandbox/_sandboxremote.py index 2bb5e5592..ef6c71866 100644 --- a/buildstream/sandbox/_sandboxremote.py +++ b/buildstream/sandbox/_sandboxremote.py @@ -26,6 +26,7 @@ from functools import partial import grpc +from buildstream._message import Message, MessageType from buildstream import utils from . import Sandbox, SandboxCommandError from .sandbox import _SandboxBatch @@ -40,7 +41,7 @@ from .._protos.google.longrunning import operations_pb2, operations_pb2_grpc from .._artifactcache.cascache import CASRemote, CASRemoteSpec -class RemoteExecutionSpec(namedtuple('RemoteExecutionSpec', 'exec_service storage_service')): +class RemoteExecutionSpec(namedtuple('RemoteExecutionSpec', 'exec_service storage_service action_service')): pass @@ -60,6 +61,10 @@ class SandboxRemote(Sandbox): self.storage_url = config.storage_service['url'] self.exec_url = config.exec_service['url'] + if config.action_service: + self.action_url = config.action_service['url'] + else: + self.action_url = None self.storage_remote_spec = CASRemoteSpec(self.storage_url, push=True, server_cert=config.storage_service['server-cert'], @@ -67,6 +72,9 @@ class SandboxRemote(Sandbox): client_cert=config.storage_service['client-cert']) self.operation_name = None + def info(self, msg): + self._get_context().message(Message(None, MessageType.INFO, msg)) + @staticmethod def specs_from_config_node(config_node, basedir): @@ -89,12 +97,17 @@ class SandboxRemote(Sandbox): tls_keys = ['client-key', 'client-cert', 'server-cert'] - _yaml.node_validate(remote_config, ['execution-service', 'storage-service', 'url']) + _yaml.node_validate(remote_config, ['execution-service', 'storage-service', 'url', 'action-service']) remote_exec_service_config = require_node(remote_config, 'execution-service') remote_exec_storage_config = require_node(remote_config, 'storage-service') + remote_exec_action_config = remote_config.get('action-service') _yaml.node_validate(remote_exec_service_config, ['url']) _yaml.node_validate(remote_exec_storage_config, ['url'] + tls_keys) + if remote_exec_action_config: + _yaml.node_validate(remote_exec_action_config, ['url']) + else: + remote_config['action-service'] = None if 'url' in remote_config: if 'execution-service' not in remote_config: @@ -115,7 +128,9 @@ class SandboxRemote(Sandbox): "remote-execution configuration. Your config is missing '{}'." .format(str(provenance), tls_keys, key)) - spec = RemoteExecutionSpec(remote_config['execution-service'], remote_config['storage-service']) + spec = RemoteExecutionSpec(remote_config['execution-service'], + remote_config['storage-service'], + remote_config['action-service']) return spec def run_remote_command(self, channel, action_digest): @@ -277,7 +292,7 @@ class SandboxRemote(Sandbox): "and '{}' was supplied.".format(url.scheme)) # check action cache download and download if there - action_result = self._check_action_cache(channel, action_digest) + action_result = self._check_action_cache(action_digest) if not action_result: casremote = CASRemote(self.storage_remote_spec) @@ -318,21 +333,28 @@ class SandboxRemote(Sandbox): return 0 - def _check_action_cache(self, channel, action_digest): + def _check_action_cache(self, action_digest): # Checks the action cache to see if this artifact has already been built # # Should return either the action response or None if not found, raise # Sandboxerror if other grpc error was raised + if not self.action_url: + return None + url = urlparse(self.action_url) + channel = grpc.insecure_channel('{}:{}'.format(url.hostname, url.port)) request = remote_execution_pb2.GetActionResultRequest(action_digest=action_digest) stub = remote_execution_pb2_grpc.ActionCacheStub(channel) try: - return stub.GetActionResult(request) + result = stub.GetActionResult(request) except grpc.RpcError as e: if e.code() != grpc.StatusCode.NOT_FOUND: raise SandboxError("Failed to query action cache: {} ({})" .format(e.code(), e.details())) else: return None + else: + self.info("Action result found in action cache") + return result def _create_command(self, command, working_directory, environment): # Creates a command proto |