def test_ProgressPipe_transform_returns_FDReadStreamConnector(bogus_volume):
    task = mock.MagicMock(spec=Task)
    task.job_manager = mock.MagicMock(spec=JobManager)
    with mock.patch('girder_worker.docker.io.os.mkfifo'):

        pp = ProgressPipe(name='test', volume=bogus_volume)
        assert isinstance(pp.transform(task=task), FDReadStreamConnector)
Пример #2
0
def _setup_streams(task_inputs, inputs, task_outputs, outputs, tempdir,
                   job_mgr, progress_pipe):
    """
    Returns a 2 tuple of input and output pipe mappings. The first element is
    a dict mapping input file descriptors to the corresponding stream adapters,
    the second is a dict mapping output file descriptors to the corresponding
    stream adapters. This also handles the special cases of STDIN, STDOUT, and
    STDERR mappings, and in the case of non-streaming standard IO pipes, will
    create default bindings for those as well.
    """
    stream_connectors = []

    def stream_pipe_path(id, spec, bindings):
        """
        Helper to check for a  valid streaming IO specs. If the
        given spec is not a streaming spec, returns None. If it is, returns the
        path.
        """
        if spec.get('stream') and id in bindings and spec.get(
                'target') == 'filepath':
            path = spec.get('path', id)
            if path.startswith('/'):
                raise Exception('Streaming filepaths must be relative.')
            path = os.path.join(tempdir, path)
            return path

        return None

    # handle stream inputs
    for id, spec in task_inputs.iteritems():

        path = stream_pipe_path(id, spec, inputs)
        # We have a streaming input
        if path is not None:
            writer = NamedPipeWriter(NamedPipe(path))
            connector = FDWriteStreamConnector(
                make_stream_fetch_adapter(inputs[id]), writer)
            stream_connectors.append(connector)
            # Don't open from this side, must be opened for reading first!

    # handle stream outputs
    for id, spec in task_outputs.iteritems():
        path = stream_pipe_path(id, spec, outputs)
        if path is not None:
            reader = NamedPipeReader(NamedPipe(path))
            connector = FDReadStreamConnector(
                reader, make_stream_push_adapter(outputs[id]))
            stream_connectors.append(connector)

    # handle special stream output for job progress
    if progress_pipe and job_mgr:
        progress_pipe = ProgressPipe(os.path.join(tempdir, '.girder_progress'))
        stream_connectors.append(progress_pipe.open())

    return stream_connectors
Пример #3
0
    def runInpainting(self, image, mask, folder):
        basename = os.path.splitext(image['name'])[0]
        outPath = VolumePath(basename + '_result.jpg')
        artifactPath = VolumePath('job_artifacts')
        job = docker_run.delay(
            'zachmullen/inpainting:latest',
            container_args=[
                GirderFileIdToVolume(image['_id']),
                GirderFileIdToVolume(mask['_id']), outPath, '--artifacts-dir',
                artifactPath, '--progress-pipe',
                ProgressPipe()
            ],
            girder_job_title='Inpainting: %s' % image['name'],
            girder_result_hooks=[
                GirderUploadVolumePathToFolder(outPath,
                                               folder['_id'],
                                               upload_kwargs={
                                                   'reference':
                                                   json.dumps({
                                                       'inpaintedImage':
                                                       True,
                                                       'folderId':
                                                       str(folder['_id']),
                                                   })
                                               }),
                # GirderUploadVolumePathJobArtifact(artifactPath)
            ]).job

        folder['inpaintingJobId'] = job['_id']
        Folder().save(folder)

        job['inpaintingImageId'] = image['_id']
        job['inpaintingMaskId'] = mask['_id']
        job['inpaintingFolderId'] = folder['_id']
        return Job().save(job)
Пример #4
0
    def test_docker_run_progress_pipe(self, params):
        progressions = params.get('progressions')
        progress_pipe = ProgressPipe()

        result = docker_run.delay(
            TEST_IMAGE, pull_image=True,
            container_args=['progress', '-p', progress_pipe, '--progressions', progressions],
            remove_container=True)

        return result.job