Exemple #1
0
    def _create_launcher_context(self, component_config=None):
        test_dir = self.get_temp_dir()

        connection_config = metadata_store_pb2.ConnectionConfig()
        connection_config.sqlite.SetInParent()

        pipeline_root = os.path.join(test_dir, 'Test')

        input_artifact = test_utils._InputArtifact()
        input_artifact.uri = os.path.join(test_dir, 'input')

        component = test_utils._FakeComponent(
            name='FakeComponent',
            input_channel=channel_utils.as_channel([input_artifact]),
            custom_executor_spec=executor_spec.ExecutorContainerSpec(
                image='gcr://test', args=['{{input_dict["input"][0].uri}}']))

        pipeline_info = data_types.PipelineInfo(pipeline_name='Test',
                                                pipeline_root=pipeline_root,
                                                run_id='123')

        driver_args = data_types.DriverArgs(enable_cache=True)

        launcher = kubernetes_component_launcher.KubernetesComponentLauncher.create(
            component=component,
            pipeline_info=pipeline_info,
            driver_args=driver_args,
            metadata_connection_config=connection_config,
            beam_pipeline_args=[],
            additional_pipeline_args={},
            component_config=component_config)

        return {'launcher': launcher, 'input_artifact': input_artifact}
Exemple #2
0
def resolve_container_template(
        container_spec_tmpl: executor_spec.ExecutorContainerSpec,
        input_dict: Dict[Text, List[types.Artifact]],
        output_dict: Dict[Text, List[types.Artifact]],
        exec_properties: Dict[Text,
                              Any]) -> executor_spec.ExecutorContainerSpec:
    """Resolves Jinja2 template languages from an executor container spec.

  Args:
    container_spec_tmpl: the container spec template to be resolved.
    input_dict: Dictionary of input artifacts consumed by this component.
    output_dict: Dictionary of output artifacts produced by this component.
    exec_properties: Dictionary of execution properties.

  Returns:
    A resolved container spec.
  """
    context = {
        'input_dict': input_dict,
        'output_dict': output_dict,
        'exec_properties': exec_properties,
    }
    return executor_spec.ExecutorContainerSpec(
        image=_render_text(container_spec_tmpl.image, context),
        command=_render_items(container_spec_tmpl.command, context),
        args=_render_items(container_spec_tmpl.args, context))
Exemple #3
0
 def testCanLaunch(self):
     self.assertTrue(
         docker_component_launcher.DockerComponentLauncher.can_launch(
             executor_spec.ExecutorContainerSpec(image='test')))
     self.assertFalse(
         docker_component_launcher.DockerComponentLauncher.can_launch(
             executor_spec.ExecutorClassSpec(base_executor.BaseExecutor)))
Exemple #4
0
    def testFindComponentLaunchInfoReturnConfigOverride(self):
        input_artifact = test_utils._InputArtifact()
        component = test_utils._FakeComponent(
            name='FakeComponent',
            input_channel=channel_utils.as_channel([input_artifact]),
            custom_executor_spec=executor_spec.ExecutorContainerSpec(
                image='gcr://test', args=['{{input_dict["input"][0].uri}}']))
        default_config = docker_component_config.DockerComponentConfig()
        override_config = docker_component_config.DockerComponentConfig(
            name='test')
        p_config = pipeline_config.PipelineConfig(
            supported_launcher_classes=[
                docker_component_launcher.DockerComponentLauncher
            ],
            default_component_configs=[default_config],
            component_config_overrides={
                '_FakeComponent.FakeComponent': override_config
            })

        (launcher_class, c_config) = config_utils.find_component_launch_info(
            p_config, component)

        self.assertEqual(docker_component_launcher.DockerComponentLauncher,
                         launcher_class)
        self.assertEqual(override_config, c_config)
Exemple #5
0
class ByeWorldComponent(BaseComponent):
    """Consumer component."""

    SPEC_CLASS = _ByeWorldSpec
    EXECUTOR_SPEC = executor_spec.ExecutorContainerSpec(
        image='bash:latest',
        command=['echo'],
        args=['received {{input_dict["hearing"][0].value}}'])

    def __init__(self, hearing):
        super(ByeWorldComponent, self).__init__(_ByeWorldSpec(hearing=hearing))
Exemple #6
0
class _HelloWorldComponent(base_component.BaseComponent):

  SPEC_CLASS = _HelloWorldSpec
  EXECUTOR_SPEC = executor_spec.ExecutorContainerSpec(
      # TODO(b/143965964): move the image to private repo if the test is flaky
      # due to docker hub.
      image='alpine:latest',
      command=['echo'],
      args=['hello {{exec_properties.name}}'])

  def __init__(self, name):
    super(_HelloWorldComponent, self).__init__(_HelloWorldSpec(name=name))
Exemple #7
0
class HelloWorldComponent(BaseComponent):
    """Producer component."""

    SPEC_CLASS = _HelloWorldSpec
    EXECUTOR_SPEC = executor_spec.ExecutorContainerSpec(
        # TODO(b/143965964): move the image to private repo if the test is flaky
        # due to docker hub.
        image='google/cloud-sdk:latest',
        command=['sh', '-c'],
        args=[
            'echo "hello {{exec_properties.word}}" | gsutil cp - {{output_dict["greeting"][0].uri}}'
        ])

    def __init__(self, word, greeting=None):
        if not greeting:
            artifact = standard_artifacts.String()
            greeting = channel_utils.as_channel([artifact])
        super(HelloWorldComponent,
              self).__init__(_HelloWorldSpec(word=word, greeting=greeting))
  def testResolveContainerTemplate(self):
    container_spec = executor_spec.ExecutorContainerSpec(
        image='gcr.io/my/trainer:{{exec_properties.version}}',
        command=['{{exec_properties.model}}_trainer'],
        args=[
            '--steps',
            '{{exec_properties.train_args.num_steps}}',
            '--examples',
            '{{input_dict["examples"]|join(",",attribute="uri")}}',
            '--model-path',
            '{{output_dict["model"][0].uri}}',
        ])
    examples_artifact_1 = standard_artifacts.Examples()
    examples_artifact_1.uri = 'gcs://examples/1'
    examples_artifact_2 = standard_artifacts.Examples()
    examples_artifact_2.uri = 'gcs://examples/2'
    model = standard_artifacts.Model()
    model.uri = 'gcs://model'
    input_dict = {'examples': [examples_artifact_1, examples_artifact_2]}
    output_dict = {'model': [model]}
    exec_properties = {
        'version': 'v1',
        'model': 'cnn',
        'train_args': trainer_pb2.TrainArgs(num_steps=10000),
    }

    actual_spec = container_common.resolve_container_template(
        container_spec, input_dict, output_dict, exec_properties)

    self.assertEqual('gcr.io/my/trainer:v1', actual_spec.image)
    self.assertListEqual(['cnn_trainer'], actual_spec.command)
    self.assertListEqual([
        '--steps',
        '10000',
        '--examples',
        'gcs://examples/1,gcs://examples/2',
        '--model-path',
        'gcs://model',
    ], actual_spec.args)