Ejemplo n.º 1
0
    def launch_run(self, instance, run):
        self.validate()
        variables = {'runId': run.run_id}
        response = requests.post(
            urljoin(self._address, '/graphql'),
            params={
                'query': START_PIPELINE_EXECUTION_FOR_CREATED_RUN_MUTATION,
                'variables': seven.json.dumps(variables),
            },
            timeout=self._timeout,
        )
        response.raise_for_status()
        result = response.json()['data']['startPipelineExecutionForCreatedRun']

        if result['__typename'] == 'StartPipelineRunSuccess':
            return run.with_status(PipelineRunStatus(result['run']['status']))

        if result['__typename'] == 'PipelineConfigValidationInvalid':
            return run.run_with_status(PipelineRunStatus.FAILURE)

        raise DagsterLaunchFailedError(
            'Failed to launch run with {cls} targeting {address}:\n{result}'.
            format(cls=self.__class__.__name__,
                   address=self._address,
                   result=result))
Ejemplo n.º 2
0
    def launch_run(self, instance, run):
        self.validate()
        execution_params = execution_params_from_pipeline_run(run)
        variables = {'executionParams': execution_params.to_graphql_input()}
        instance.create_run(run)
        response = requests.post(
            urljoin(self._address, '/graphql'),
            params={
                'query': START_PIPELINE_EXECUTION_MUTATION,
                'variables': seven.json.dumps(variables),
            },
            timeout=self._timeout,
        )
        response.raise_for_status()
        result = response.json()['data']['startPipelineExecution']

        if result['__typename'] == 'StartPipelineExecutionSuccess':
            return run.run_with_status(
                PipelineRunStatus(result['run']['status']))

        raise DagsterLaunchFailedError(
            'Failed to launch run with {cls} targeting {address}:\n{result}'.
            format(cls=self.__class__.__name__,
                   address=self._address,
                   result=result))
Ejemplo n.º 3
0
    def launch_run(self, instance, run, external_pipeline):
        check.inst_param(external_pipeline, 'external_pipeline',
                         ExternalPipeline)
        self.validate()

        variables = {
            'repositoryLocationName': external_pipeline.handle.location_name,
            'repositoryName': external_pipeline.handle.repository_name,
            'runId': run.run_id,
        }
        response = requests.post(
            urljoin(self._address, '/graphql'),
            params={
                'query': EXECUTE_RUN_IN_PROCESS_MUTATION,
                'variables': seven.json.dumps(variables),
            },
            timeout=self._timeout,
        )
        response.raise_for_status()
        result = response.json()['data']['executeRunInProcess']

        if result['__typename'] in [
                'LaunchPipelineRunSuccess', 'PipelineConfigValidationInvalid'
        ]:
            return self._instance.get_run_by_id(run.run_id)

        raise DagsterLaunchFailedError(
            'Failed to launch run with {cls} targeting {address}:\n{result}'.
            format(cls=self.__class__.__name__,
                   address=self._address,
                   result=result))
Ejemplo n.º 4
0
    def launch_run(self, instance, run, external_pipeline):
        check.inst_param(external_pipeline, "external_pipeline", ExternalPipeline)
        self.validate()

        variables = {
            "repositoryLocationName": external_pipeline.handle.location_name,
            "repositoryName": external_pipeline.handle.repository_name,
            "runId": run.run_id,
        }
        response = requests.post(
            urljoin(self._address, "/graphql"),
            params={
                "query": EXECUTE_RUN_IN_PROCESS_MUTATION,
                "variables": seven.json.dumps(variables),
            },
            timeout=self._timeout,
        )
        response.raise_for_status()
        result = response.json()["data"]["executeRunInProcess"]

        if result["__typename"] in ["LaunchPipelineRunSuccess", "PipelineConfigValidationInvalid"]:
            return self._instance.get_run_by_id(run.run_id)

        raise DagsterLaunchFailedError(
            "Failed to launch run with {cls} targeting {address}:\n{result}".format(
                cls=self.__class__.__name__, address=self._address, result=result
            )
        )
Ejemplo n.º 5
0
def execute_query_against_remote(host, query, variables):
    parsed_url = urlparse(host)
    if not (parsed_url.scheme and parsed_url.netloc):
        raise click.UsageError(
            'Host {host} is not a valid URL. Host URL should include scheme ie http://localhost'.format(
                host=host
            )
        )

    sanity_check = requests.get(urljoin(host, '/dagit_info'))
    sanity_check.raise_for_status()
    if 'dagit' not in sanity_check.text:
        raise click.UsageError(
            'Host {host} failed sanity check. It is not a dagit server.'.format(host=host)
        )

    response = requests.post(
        urljoin(host, '/graphql'), params={'query': query, 'variables': variables}
    )
    response.raise_for_status()
    str_res = response.json()
    return str_res
Ejemplo n.º 6
0
 def _check_for_version_066_migration_and_perform(self):
     old_conn_string = 'sqlite://' + urljoin(
         urlparse(self._conn_string).path, '../runs.db')
     path_to_old_db = urlparse(old_conn_string).path
     # sqlite URLs look like `sqlite:///foo/bar/baz on Unix/Mac` but on Windows they look like
     # `sqlite:///D:/foo/bar/baz` (or `sqlite:///D:\foo\bar\baz`)
     if os.name == 'nt':
         path_to_old_db = path_to_old_db.lstrip('/')
     if os.path.exists(path_to_old_db):
         old_storage = SqliteRunStorage(old_conn_string)
         old_runs = old_storage.get_runs()
         for run in old_runs:
             self.add_run(run)
         os.unlink(path_to_old_db)
Ejemplo n.º 7
0
    def validate(self):
        if self._validated:
            return
        try:
            sanity_check = requests.get(urljoin(self._address, '/dagit_info'),
                                        timeout=self._timeout)
            self._validated = sanity_check.status_code = 200 and 'dagit' in sanity_check.text
        except RequestException:
            self._validated = False

        if not self._validated:
            raise DagsterLaunchFailedError(
                'Host {host} failed sanity check. It is not a dagit server.'.
                format(host=self._address), )