Ejemplo n.º 1
0
class DauphinAsset(dauphin.ObjectType):
    class Meta:
        name = "Asset"

    key = dauphin.NonNull("AssetKey")
    assetMaterializations = dauphin.Field(
        dauphin.non_null_list("AssetMaterialization"),
        partitions=dauphin.List(dauphin.String),
        cursor=dauphin.String(),
        limit=dauphin.Int(),
    )
    runs = dauphin.Field(
        dauphin.non_null_list("PipelineRun"), cursor=dauphin.String(), limit=dauphin.Int(),
    )

    def resolve_assetMaterializations(self, graphene_info, **kwargs):
        return [
            graphene_info.schema.type_named("AssetMaterialization")(event=event)
            for event in get_asset_events(
                graphene_info,
                self.key,
                kwargs.get("partitions"),
                kwargs.get("cursor"),
                kwargs.get("limit"),
            )
        ]

    def resolve_runs(self, graphene_info, **kwargs):
        cursor = kwargs.get("cursor")
        limit = kwargs.get("limit")

        run_ids = get_asset_run_ids(graphene_info, self.key)

        if not run_ids:
            return []

        # for now, handle cursor/limit here instead of in the DB layer
        if cursor:
            try:
                idx = run_ids.index(cursor)
                run_ids = run_ids[idx:]
            except ValueError:
                return []

        if limit:
            run_ids = run_ids[:limit]

        return [
            graphene_info.schema.type_named("PipelineRun")(r)
            for r in graphene_info.context.instance.get_runs(
                filters=PipelineRunsFilter(run_ids=run_ids)
            )
        ]
Ejemplo n.º 2
0
class DauphinPipeline(DauphinIPipelineSnapshotMixin, dauphin.ObjectType):
    class Meta:
        name = "Pipeline"
        interfaces = (DauphinSolidContainer, DauphinIPipelineSnapshot)

    id = dauphin.NonNull(dauphin.ID)
    presets = dauphin.non_null_list("PipelinePreset")
    runs = dauphin.Field(
        dauphin.non_null_list("PipelineRun"), cursor=dauphin.String(), limit=dauphin.Int(),
    )

    def __init__(self, external_pipeline):
        self._external_pipeline = check.inst_param(
            external_pipeline, "external_pipeline", ExternalPipeline
        )

    def resolve_id(self, _graphene_info):
        return self._external_pipeline.get_external_origin_id()

    def get_represented_pipeline(self):
        return self._external_pipeline

    def resolve_presets(self, _graphene_info):
        return [
            DauphinPipelinePreset(preset, self._external_pipeline.name)
            for preset in sorted(self._external_pipeline.active_presets, key=lambda item: item.name)
        ]
Ejemplo n.º 3
0
class DauphinPartitionSet(dauphin.ObjectType):
    class Meta:
        name = "PartitionSet"

    id = dauphin.NonNull(dauphin.ID)
    name = dauphin.NonNull(dauphin.String)
    pipeline_name = dauphin.NonNull(dauphin.String)
    solid_selection = dauphin.List(dauphin.NonNull(dauphin.String))
    mode = dauphin.NonNull(dauphin.String)
    partitionsOrError = dauphin.Field(
        dauphin.NonNull("PartitionsOrError"),
        cursor=dauphin.String(),
        limit=dauphin.Int(),
        reverse=dauphin.Boolean(),
    )
    partition = dauphin.Field("Partition",
                              partition_name=dauphin.NonNull(dauphin.String))
    partitionStatusesOrError = dauphin.NonNull("PartitionStatusesOrError")

    def __init__(self, external_repository_handle, external_partition_set):
        self._external_repository_handle = check.inst_param(
            external_repository_handle, "external_respository_handle",
            RepositoryHandle)
        self._external_partition_set = check.inst_param(
            external_partition_set, "external_partition_set",
            ExternalPartitionSet)

        super(DauphinPartitionSet, self).__init__(
            name=external_partition_set.name,
            pipeline_name=external_partition_set.pipeline_name,
            solid_selection=external_partition_set.solid_selection,
            mode=external_partition_set.mode,
        )

    def resolve_id(self, _graphene_info):
        return self._external_partition_set.get_external_origin_id()

    def resolve_partitionsOrError(self, graphene_info, **kwargs):
        return get_partitions(
            graphene_info,
            self._external_repository_handle,
            self._external_partition_set,
            cursor=kwargs.get("cursor"),
            limit=kwargs.get("limit"),
            reverse=kwargs.get("reverse"),
        )

    def resolve_partition(self, graphene_info, partition_name):
        return get_partition_by_name(
            graphene_info,
            self._external_repository_handle,
            self._external_partition_set,
            partition_name,
        )

    def resolve_partitionStatusesOrError(self, graphene_info):
        return get_partition_set_partition_statuses(
            graphene_info, self._external_repository_handle,
            self._external_partition_set.name)
Ejemplo n.º 4
0
class DauphinPartitionSet(dauphin.ObjectType):
    class Meta(object):
        name = 'PartitionSet'

    name = dauphin.NonNull(dauphin.String)
    pipeline_name = dauphin.NonNull(dauphin.String)
    solid_selection = dauphin.List(dauphin.NonNull(dauphin.String))
    mode = dauphin.NonNull(dauphin.String)
    partitions = dauphin.Field(
        dauphin.NonNull('Partitions'),
        cursor=dauphin.String(),
        limit=dauphin.Int(),
        reverse=dauphin.Boolean(),
    )
    partition = dauphin.Field('Partition',
                              partition_name=dauphin.NonNull(dauphin.String))

    def __init__(self, external_repository_handle, external_partition_set):
        self._external_repository_handle = check.inst_param(
            external_repository_handle, 'external_respository_handle',
            RepositoryHandle)
        self._external_partition_set = check.inst_param(
            external_partition_set, 'external_partition_set',
            ExternalPartitionSet)

        super(DauphinPartitionSet, self).__init__(
            name=external_partition_set.name,
            pipeline_name=external_partition_set.pipeline_name,
            solid_selection=external_partition_set.solid_selection,
            mode=external_partition_set.mode,
        )

    def resolve_partitions(self, graphene_info, **kwargs):
        return get_partitions(
            graphene_info,
            self._external_repository_handle,
            self._external_partition_set,
            cursor=kwargs.get("cursor"),
            limit=kwargs.get("limit"),
            reverse=kwargs.get('reverse'),
        )

    def resolve_partition(self, graphene_info, partition_name):
        return get_partition_by_name(
            graphene_info,
            self._external_repository_handle,
            self._external_partition_set,
            partition_name,
        )
Ejemplo n.º 5
0
class DauphinPipelineRuns(dauphin.ObjectType):
    class Meta:
        name = "PipelineRuns"

    def __init__(self, filters, cursor, limit):
        self._filters = filters
        self._cursor = cursor
        self._limit = limit

    results = dauphin.non_null_list("PipelineRun")
    count = dauphin.Int()

    def resolve_results(self, graphene_info):
        return get_runs(graphene_info, self._filters, self._cursor, self._limit)

    def resolve_count(self, graphene_info):
        return get_runs_count(graphene_info, self._filters)
Ejemplo n.º 6
0
class DauphinPartitionSet(dauphin.ObjectType):
    class Meta(object):
        name = 'PartitionSet'

    name = dauphin.NonNull(dauphin.String)
    pipeline_name = dauphin.NonNull(dauphin.String)
    solid_subset = dauphin.List(dauphin.NonNull(dauphin.String))
    mode = dauphin.NonNull(dauphin.String)
    partitions = dauphin.Field(
        dauphin.NonNull('Partitions'),
        cursor=dauphin.String(),
        limit=dauphin.Int(),
    )

    def __init__(self, partition_set):
        self._partition_set = check.inst_param(partition_set, 'partition_set',
                                               PartitionSetDefinition)

        super(DauphinPartitionSet, self).__init__(
            name=partition_set.name,
            pipeline_name=partition_set.pipeline_name,
            solid_subset=partition_set.solid_subset,
            mode=partition_set.mode,
        )

    def resolve_partitions(self, graphene_info, **kwargs):
        partitions = self._partition_set.get_partitions()

        cursor = kwargs.get("cursor")
        limit = kwargs.get("limit")
        if cursor and limit:
            index = next(
                (idx for (idx, partition) in enumerate(partitions)
                 if partition.name == cursor),
                None,
            )
            partitions = partitions[index:min(len(partitions), index + limit)]
        elif limit:
            partitions = partitions[:min(len(partitions), limit)]

        return graphene_info.schema.type_named('Partitions')(results=[
            graphene_info.schema.type_named('Partition')(
                partition=partition, partition_set=self._partition_set)
            for partition in partitions
        ])
Ejemplo n.º 7
0
class DauphinQuery(dauphin.ObjectType):
    class Meta(object):
        name = 'Query'

    version = dauphin.NonNull(dauphin.String)
    reloadSupported = dauphin.NonNull(dauphin.Boolean)

    pipelineOrError = dauphin.Field(
        dauphin.NonNull('PipelineOrError'),
        params=dauphin.NonNull('ExecutionSelector'))
    pipeline = dauphin.Field(dauphin.NonNull('Pipeline'),
                             params=dauphin.NonNull('ExecutionSelector'))
    pipelinesOrError = dauphin.NonNull('PipelinesOrError')
    pipelines = dauphin.Field(dauphin.NonNull('PipelineConnection'))

    pipelineSnapshot = dauphin.Field(
        dauphin.NonNull('PipelineSnapshot'),
        snapshotId=dauphin.Argument(dauphin.NonNull(dauphin.String)),
    )

    pipelineSnapshotOrError = dauphin.Field(
        dauphin.NonNull('PipelineSnapshotOrError'),
        snapshotId=dauphin.String(),
        activePipelineName=dauphin.String(),
    )

    scheduler = dauphin.Field(dauphin.NonNull('SchedulerOrError'))
    scheduleOrError = dauphin.Field(
        dauphin.NonNull('ScheduleOrError'),
        schedule_name=dauphin.NonNull(dauphin.String),
        limit=dauphin.Int(),
    )

    partitionSetsOrError = dauphin.Field(
        dauphin.NonNull('PartitionSetsOrError'), pipelineName=dauphin.String())
    partitionSetOrError = dauphin.Field(dauphin.NonNull('PartitionSetOrError'),
                                        partitionSetName=dauphin.String())

    pipelineRunsOrError = dauphin.Field(
        dauphin.NonNull('PipelineRunsOrError'),
        filter=dauphin.Argument('PipelineRunsFilter'),
        cursor=dauphin.String(),
        limit=dauphin.Int(),
    )

    pipelineRunOrError = dauphin.Field(dauphin.NonNull('PipelineRunOrError'),
                                       runId=dauphin.NonNull(dauphin.ID))

    pipelineRunTags = dauphin.non_null_list('PipelineTagAndValues')

    usedSolids = dauphin.Field(dauphin.non_null_list('UsedSolid'))
    usedSolid = dauphin.Field('UsedSolid',
                              name=dauphin.NonNull(dauphin.String))

    isPipelineConfigValid = dauphin.Field(
        dauphin.NonNull('PipelineConfigValidationResult'),
        args={
            'pipeline': dauphin.Argument(dauphin.NonNull('ExecutionSelector')),
            'environmentConfigData': dauphin.Argument('EnvironmentConfigData'),
            'mode': dauphin.Argument(dauphin.NonNull(dauphin.String)),
        },
    )

    executionPlan = dauphin.Field(
        dauphin.NonNull('ExecutionPlanResult'),
        args={
            'pipeline': dauphin.Argument(dauphin.NonNull('ExecutionSelector')),
            'environmentConfigData': dauphin.Argument('EnvironmentConfigData'),
            'mode': dauphin.Argument(dauphin.NonNull(dauphin.String)),
        },
    )

    environmentSchemaOrError = dauphin.Field(
        dauphin.NonNull('EnvironmentSchemaOrError'),
        args={
            'selector': dauphin.Argument(dauphin.NonNull('ExecutionSelector')),
            'mode': dauphin.Argument(dauphin.String),
        },
        description=
        '''Fetch an environment schema given an execution selection and a mode.
        See the descripton on EnvironmentSchema for more information.''',
    )

    instance = dauphin.NonNull('Instance')

    def resolve_pipelineSnapshot(self, graphene_info, **kwargs):
        return get_pipeline_snapshot(graphene_info, kwargs['snapshotId'])

    def resolve_pipelineSnapshotOrError(self, graphene_info, **kwargs):
        snapshot_id_arg = kwargs.get('snapshotId')
        pipeline_name_arg = kwargs.get('activePipelineName')
        check.invariant(
            not (snapshot_id_arg and pipeline_name_arg),
            'Cannot pass both snapshotId and activePipelineName',
        )
        check.invariant(snapshot_id_arg or pipeline_name_arg,
                        'Must set one of snapshotId or activePipelineName')

        if pipeline_name_arg:
            return get_pipeline_snapshot_or_error_from_pipeline_name(
                graphene_info, pipeline_name_arg)
        else:
            return get_pipeline_snapshot_or_error_from_snapshot_id(
                graphene_info, snapshot_id_arg)

    def resolve_version(self, graphene_info):
        return graphene_info.context.version

    def resolve_reloadSupported(self, graphene_info):
        if isinstance(graphene_info.context, DagsterSnapshotGraphQLContext):
            return False
        return graphene_info.context.reloader.is_reload_supported

    def resolve_scheduler(self, graphene_info):
        return get_scheduler_or_error(graphene_info)

    def resolve_scheduleOrError(self, graphene_info, schedule_name):
        return get_schedule_or_error(graphene_info, schedule_name)

    def resolve_pipelineOrError(self, graphene_info, **kwargs):
        return get_pipeline_or_error(graphene_info,
                                     kwargs['params'].to_selector())

    def resolve_pipeline(self, graphene_info, **kwargs):
        return get_pipeline_or_raise(graphene_info,
                                     kwargs['params'].to_selector())

    def resolve_pipelinesOrError(self, graphene_info):
        return get_pipelines_or_error(graphene_info)

    def resolve_pipelines(self, graphene_info):
        return get_pipelines_or_raise(graphene_info)

    def resolve_pipelineRunsOrError(self, graphene_info, **kwargs):
        filters = kwargs.get('filter')
        if filters is not None:
            filters = filters.to_selector()

        return graphene_info.schema.type_named('PipelineRuns')(
            results=get_runs(graphene_info, filters, kwargs.get('cursor'),
                             kwargs.get('limit')))

    def resolve_pipelineRunOrError(self, graphene_info, runId):
        return get_run_by_id(graphene_info, runId)

    def resolve_partitionSetsOrError(self, graphene_info, **kwargs):
        pipeline_name = kwargs.get('pipelineName')

        return get_partition_sets_or_error(graphene_info, pipeline_name)

    def resolve_partitionSetOrError(self, graphene_info, partitionSetName):
        return get_partition_set(graphene_info, partitionSetName)

    def resolve_pipelineRunTags(self, graphene_info):
        return get_run_tags(graphene_info)

    def resolve_usedSolid(self, graphene_info, name):
        return get_solid(graphene_info, name)

    def resolve_usedSolids(self, graphene_info):
        return get_solids(graphene_info)

    def resolve_isPipelineConfigValid(self, graphene_info, pipeline, **kwargs):
        return validate_pipeline_config(
            graphene_info,
            pipeline.to_selector(),
            kwargs.get('environmentConfigData'),
            kwargs.get('mode'),
        )

    def resolve_executionPlan(self, graphene_info, pipeline, **kwargs):
        return get_execution_plan(
            graphene_info,
            pipeline.to_selector(),
            kwargs.get('environmentConfigData'),
            kwargs.get('mode'),
        )

    def resolve_environmentSchemaOrError(self, graphene_info, **kwargs):
        return resolve_environment_schema_or_error(
            graphene_info, kwargs['selector'].to_selector(),
            kwargs.get('mode'))

    def resolve_instance(self, graphene_info):
        return graphene_info.schema.type_named('Instance')(
            graphene_info.context.instance)
Ejemplo n.º 8
0
class DauphinRunningSchedule(dauphin.ObjectType):
    class Meta(object):
        name = 'RunningSchedule'

    schedule_definition = dauphin.NonNull('ScheduleDefinition')
    python_path = dauphin.Field(dauphin.String)
    repository_path = dauphin.Field(dauphin.String)
    status = dauphin.NonNull('ScheduleStatus')
    runs = dauphin.Field(dauphin.non_null_list('PipelineRun'),
                         limit=dauphin.Int())
    runs_count = dauphin.NonNull(dauphin.Int)
    ticks = dauphin.Field(dauphin.non_null_list('ScheduleTick'),
                          limit=dauphin.Int())
    ticks_count = dauphin.NonNull(dauphin.Int)
    stats = dauphin.NonNull('ScheduleTickStatsSnapshot')
    # TODO: Delete attempts and attempts_count in 0.8.0 release
    # https://github.com/dagster-io/dagster/issues/228
    attempts = dauphin.Field(dauphin.non_null_list('ScheduleAttempt'),
                             limit=dauphin.Int())
    attempts_count = dauphin.NonNull(dauphin.Int)
    logs_path = dauphin.NonNull(dauphin.String)

    def __init__(self, graphene_info, schedule):
        self._schedule = check.inst_param(schedule, 'schedule', Schedule)

        super(DauphinRunningSchedule, self).__init__(
            schedule_definition=graphene_info.schema.type_named(
                'ScheduleDefinition')(
                    graphene_info=graphene_info,
                    schedule_def=get_dagster_schedule_def(
                        graphene_info, schedule.name),
                ),
            status=schedule.status,
            python_path=schedule.python_path,
            repository_path=schedule.repository_path,
        )

    # TODO: Delete in 0.8.0 release
    # https://github.com/dagster-io/dagster/issues/228
    def resolve_attempts(self, graphene_info, **kwargs):
        limit = kwargs.get('limit')

        results = get_schedule_attempt_filenames(graphene_info,
                                                 self._schedule.name)
        if limit is None:
            limit = len(results)
        latest_results = heapq.nlargest(limit, results, key=os.path.getctime)

        attempts = []
        for result_path in latest_results:
            with open(result_path, 'r') as f:
                line = f.readline()
                if not line:
                    continue  # File is empty

                start_scheduled_execution_response = json.loads(line)
                run = None

                if 'errors' in start_scheduled_execution_response:
                    status = DauphinScheduleAttemptStatus.ERROR
                    json_result = start_scheduled_execution_response['errors']
                else:
                    json_result = start_scheduled_execution_response['data'][
                        'startScheduledExecution']
                    typename = json_result['__typename']

                    if (typename == 'StartPipelineRunSuccess'
                            or typename == 'LaunchPipelineRunSuccess'):
                        status = DauphinScheduleAttemptStatus.SUCCESS
                        run_id = json_result['run']['runId']
                        if graphene_info.context.instance.has_run(run_id):
                            run = graphene_info.schema.type_named(
                                'PipelineRun')(graphene_info.context.instance.
                                               get_run_by_id(run_id))
                    elif typename == 'ScheduledExecutionBlocked':
                        status = DauphinScheduleAttemptStatus.SKIPPED
                    else:
                        status = DauphinScheduleAttemptStatus.ERROR

                attempts.append(
                    graphene_info.schema.type_named('ScheduleAttempt')(
                        time=os.path.getctime(result_path),
                        json_result=json.dumps(json_result),
                        status=status,
                        run=run,
                    ))

        return attempts

    # TODO: Delete in 0.8.0 release
    # https://github.com/dagster-io/dagster/issues/228
    def resolve_attempts_count(self, graphene_info):
        attempt_files = get_schedule_attempt_filenames(graphene_info,
                                                       self._schedule.name)
        return len(attempt_files)

    # TODO: Delete in 0.8.0 release
    # https://github.com/dagster-io/dagster/issues/228
    def resolve_logs_path(self, graphene_info):
        instance = graphene_info.context.instance
        repository = graphene_info.context.get_repository_definition()
        return instance.log_path_for_schedule(repository, self._schedule.name)

    def resolve_stats(self, graphene_info):
        repository = graphene_info.context.get_repository_definition()
        stats = graphene_info.context.instance.get_schedule_tick_stats_by_schedule(
            repository, self._schedule.name)
        return graphene_info.schema.type_named('ScheduleTickStatsSnapshot')(
            stats)

    def resolve_ticks(self, graphene_info, limit=None):

        repository = graphene_info.context.get_repository_definition()

        # TODO: Add cursor limit argument to get_schedule_ticks_by_schedule
        # https://github.com/dagster-io/dagster/issues/2291
        ticks = graphene_info.context.instance.get_schedule_ticks_by_schedule(
            repository, self._schedule.name)

        if not limit:
            tick_subset = ticks
        else:
            tick_subset = ticks[:limit]

        return [
            graphene_info.schema.type_named('ScheduleTick')(
                tick_id=tick.tick_id,
                status=tick.status,
                timestamp=tick.timestamp,
                tick_specific_data=tick_specific_data_from_dagster_tick(
                    graphene_info, tick),
            ) for tick in tick_subset
        ]

    def resolve_ticks_count(self, graphene_info):
        repository = graphene_info.context.get_repository_definition()
        ticks = graphene_info.context.instance.get_schedule_ticks_by_schedule(
            repository, self._schedule.name)
        return len(ticks)

    def resolve_runs(self, graphene_info, **kwargs):
        return [
            graphene_info.schema.type_named('PipelineRun')(r)
            for r in graphene_info.context.instance.get_runs(
                filters=PipelineRunsFilter.for_schedule(self._schedule),
                limit=kwargs.get('limit'),
            )
        ]

    def resolve_runs_count(self, graphene_info):
        return graphene_info.context.instance.get_runs_count(
            filters=PipelineRunsFilter.for_schedule(self._schedule))
Ejemplo n.º 9
0
class DauphinScheduleState(dauphin.ObjectType):
    class Meta(object):
        name = 'ScheduleState'

    schedule_origin_id = dauphin.NonNull(dauphin.String)
    schedule_name = dauphin.NonNull(dauphin.String)
    cron_schedule = dauphin.NonNull(dauphin.String)
    status = dauphin.NonNull('ScheduleStatus')

    runs = dauphin.Field(dauphin.non_null_list('PipelineRun'),
                         limit=dauphin.Int())
    runs_count = dauphin.NonNull(dauphin.Int)
    ticks = dauphin.Field(dauphin.non_null_list('ScheduleTick'),
                          limit=dauphin.Int())
    ticks_count = dauphin.NonNull(dauphin.Int)
    stats = dauphin.NonNull('ScheduleTickStatsSnapshot')
    logs_path = dauphin.NonNull(dauphin.String)
    running_schedule_count = dauphin.NonNull(dauphin.Int)
    repository_origin_id = dauphin.NonNull(dauphin.String)
    id = dauphin.NonNull(dauphin.ID)

    def __init__(self, _graphene_info, schedule_state):
        self._schedule_state = check.inst_param(schedule_state, 'schedule',
                                                ScheduleState)
        self._external_schedule_origin_id = self._schedule_state.schedule_origin_id

        super(DauphinScheduleState, self).__init__(
            schedule_origin_id=schedule_state.schedule_origin_id,
            schedule_name=schedule_state.name,
            cron_schedule=schedule_state.cron_schedule,
            status=schedule_state.status,
        )

    def resolve_id(self, _graphene_info):
        return self._external_schedule_origin_id

    def resolve_running_schedule_count(self, graphene_info):
        running_schedule_count = graphene_info.context.instance.running_schedule_count(
            self._external_schedule_origin_id)
        return running_schedule_count

    def resolve_stats(self, graphene_info):
        stats = graphene_info.context.instance.get_schedule_tick_stats(
            self._external_schedule_origin_id)
        return graphene_info.schema.type_named('ScheduleTickStatsSnapshot')(
            stats)

    def resolve_ticks(self, graphene_info, limit=None):

        # TODO: Add cursor limit argument to get_schedule_ticks_by_schedule
        # https://github.com/dagster-io/dagster/issues/2291
        ticks = graphene_info.context.instance.get_schedule_ticks(
            self._external_schedule_origin_id)

        if not limit:
            tick_subset = ticks
        else:
            tick_subset = ticks[:limit]

        return [
            graphene_info.schema.type_named('ScheduleTick')(
                tick_id=tick.tick_id,
                status=tick.status,
                timestamp=tick.timestamp,
                tick_specific_data=tick_specific_data_from_dagster_tick(
                    graphene_info, tick),
            ) for tick in tick_subset
        ]

    def resolve_ticks_count(self, graphene_info):
        ticks = graphene_info.context.instance.get_schedule_ticks(
            self._external_schedule_origin_id)
        return len(ticks)

    def resolve_runs(self, graphene_info, **kwargs):
        return [
            graphene_info.schema.type_named('PipelineRun')(r)
            for r in graphene_info.context.instance.get_runs(
                filters=PipelineRunsFilter.for_schedule(self._schedule_state),
                limit=kwargs.get('limit'),
            )
        ]

    def resolve_runs_count(self, graphene_info):
        return graphene_info.context.instance.get_runs_count(
            filters=PipelineRunsFilter.for_schedule(self._schedule_state))

    def resolve_repository_origin_id(self, _graphene_info):
        return self._schedule_state.repository_origin_id
Ejemplo n.º 10
0
class DauphinRunningSchedule(dauphin.ObjectType):
    class Meta(object):
        name = 'RunningSchedule'

    id = dauphin.NonNull(dauphin.String)
    schedule_definition = dauphin.NonNull('ScheduleDefinition')
    python_path = dauphin.Field(dauphin.String)
    repository_path = dauphin.Field(dauphin.String)
    status = dauphin.NonNull('ScheduleStatus')
    runs = dauphin.Field(dauphin.non_null_list('PipelineRun'), limit=dauphin.Int())
    runs_count = dauphin.NonNull(dauphin.Int)
    attempts = dauphin.Field(dauphin.non_null_list('ScheduleAttempt'), limit=dauphin.Int())
    attempts_count = dauphin.NonNull(dauphin.Int)
    logs_path = dauphin.NonNull(dauphin.String)

    def __init__(self, graphene_info, schedule):
        self._schedule = check.inst_param(schedule, 'schedule', Schedule)

        super(DauphinRunningSchedule, self).__init__(
            id=schedule.schedule_id,
            schedule_definition=graphene_info.schema.type_named('ScheduleDefinition')(
                graphene_info=graphene_info,
                schedule_def=get_dagster_schedule_def(graphene_info, schedule.name),
            ),
            status=schedule.status,
            python_path=schedule.python_path,
            repository_path=schedule.repository_path,
        )

    def resolve_attempts(self, graphene_info, **kwargs):
        limit = kwargs.get('limit')

        results = get_schedule_attempt_filenames(graphene_info, self._schedule.name)
        if limit is None:
            limit = len(results)
        latest_results = heapq.nlargest(limit, results, key=os.path.getctime)

        attempts = []
        for result_path in latest_results:
            with open(result_path, 'r') as f:
                line = f.readline()
                if not line:
                    continue  # File is empty

                start_scheduled_execution_response = json.loads(line)
                run = None

                if 'errors' in start_scheduled_execution_response:
                    status = DauphinScheduleAttemptStatus.ERROR
                    json_result = start_scheduled_execution_response['errors']
                else:
                    json_result = start_scheduled_execution_response['data'][
                        'startScheduledExecution'
                    ]
                    typename = json_result['__typename']

                    if typename == 'StartPipelineExecutionSuccess':
                        status = DauphinScheduleAttemptStatus.SUCCESS
                        run_id = json_result['run']['runId']
                        run = graphene_info.schema.type_named('PipelineRun')(
                            graphene_info.context.instance.get_run_by_id(run_id)
                        )
                    elif typename == 'ScheduleExecutionBlocked':
                        status = DauphinScheduleAttemptStatus.SKIPPED
                    else:
                        status = DauphinScheduleAttemptStatus.ERROR

                attempts.append(
                    graphene_info.schema.type_named('ScheduleAttempt')(
                        time=os.path.getctime(result_path),
                        json_result=json.dumps(json_result),
                        status=status,
                        run=run,
                    )
                )

        return attempts

    def resolve_attempts_count(self, graphene_info):
        attempt_files = get_schedule_attempt_filenames(graphene_info, self._schedule.name)
        return len(attempt_files)

    def resolve_logs_path(self, graphene_info):
        scheduler = graphene_info.context.get_scheduler()
        return scheduler.log_path_for_schedule(self._schedule.name)

    def resolve_runs(self, graphene_info, **kwargs):
        return [
            graphene_info.schema.type_named('PipelineRun')(r)
            for r in graphene_info.context.instance.get_runs(
                filters=PipelineRunsFilter(
                    tags={'dagster/schedule_id': self._schedule.schedule_id}
                ),
                limit=kwargs.get('limit'),
            )
        ]

    def resolve_runs_count(self, graphene_info):
        return graphene_info.context.instance.get_runs_count(
            filter=PipelineRunsFilter(tags=[("dagster/schedule_id", self._schedule.schedule_id)])
        )
Ejemplo n.º 11
0
class DauphinRunningSchedule(dauphin.ObjectType):
    class Meta(object):
        name = 'RunningSchedule'

    schedule_definition = dauphin.NonNull('ScheduleDefinition')
    python_path = dauphin.Field(dauphin.String)
    repository_path = dauphin.Field(dauphin.String)
    status = dauphin.NonNull('ScheduleStatus')
    runs = dauphin.Field(dauphin.non_null_list('PipelineRun'), limit=dauphin.Int())
    runs_count = dauphin.NonNull(dauphin.Int)
    ticks = dauphin.Field(dauphin.non_null_list('ScheduleTick'), limit=dauphin.Int())
    ticks_count = dauphin.NonNull(dauphin.Int)
    stats = dauphin.NonNull('ScheduleTickStatsSnapshot')
    logs_path = dauphin.NonNull(dauphin.String)
    running_schedule_count = dauphin.NonNull(dauphin.Int)

    def __init__(self, graphene_info, schedule):
        self._schedule = check.inst_param(schedule, 'schedule', Schedule)
        external_repository = graphene_info.context.legacy_external_repository
        external_schedule = external_repository.get_external_schedule(schedule.name)
        super(DauphinRunningSchedule, self).__init__(
            schedule_definition=graphene_info.schema.type_named('ScheduleDefinition')(
                schedule_def=get_dagster_schedule_def(graphene_info, schedule.name),
                external_schedule=external_schedule,
            ),
            status=schedule.status,
            python_path=schedule.python_path,
            repository_path=schedule.repository_path,
        )

    def resolve_running_schedule_count(self, graphene_info):
        external_repository = graphene_info.context.legacy_external_repository
        running_schedule_count = graphene_info.context.instance.running_schedule_count(
            external_repository.name, self._schedule.name
        )
        return running_schedule_count

    def resolve_stats(self, graphene_info):
        external_repository = graphene_info.context.legacy_external_repository
        stats = graphene_info.context.instance.get_schedule_tick_stats_by_schedule(
            external_repository.name, self._schedule.name
        )
        return graphene_info.schema.type_named('ScheduleTickStatsSnapshot')(stats)

    def resolve_ticks(self, graphene_info, limit=None):
        external_repository = graphene_info.context.legacy_external_repository

        # TODO: Add cursor limit argument to get_schedule_ticks_by_schedule
        # https://github.com/dagster-io/dagster/issues/2291
        ticks = graphene_info.context.instance.get_schedule_ticks_by_schedule(
            external_repository.name, self._schedule.name
        )

        if not limit:
            tick_subset = ticks
        else:
            tick_subset = ticks[:limit]

        return [
            graphene_info.schema.type_named('ScheduleTick')(
                tick_id=tick.tick_id,
                status=tick.status,
                timestamp=tick.timestamp,
                tick_specific_data=tick_specific_data_from_dagster_tick(graphene_info, tick),
            )
            for tick in tick_subset
        ]

    def resolve_ticks_count(self, graphene_info):
        external_repository = graphene_info.context.legacy_external_repository
        ticks = graphene_info.context.instance.get_schedule_ticks_by_schedule(
            external_repository.name, self._schedule.name
        )
        return len(ticks)

    def resolve_runs(self, graphene_info, **kwargs):
        return [
            graphene_info.schema.type_named('PipelineRun')(r)
            for r in graphene_info.context.instance.get_runs(
                filters=PipelineRunsFilter.for_schedule(self._schedule), limit=kwargs.get('limit'),
            )
        ]

    def resolve_runs_count(self, graphene_info):
        return graphene_info.context.instance.get_runs_count(
            filters=PipelineRunsFilter.for_schedule(self._schedule)
        )
Ejemplo n.º 12
0
class DauphinJobState(dauphin.ObjectType):
    class Meta:
        name = "JobState"

    id = dauphin.NonNull(dauphin.ID)
    name = dauphin.NonNull(dauphin.String)
    jobType = dauphin.NonNull("JobType")
    status = dauphin.NonNull("JobStatus")
    repositoryOrigin = dauphin.NonNull("RepositoryOrigin")
    jobSpecificData = dauphin.Field("JobSpecificData")
    runs = dauphin.Field(dauphin.non_null_list("PipelineRun"),
                         limit=dauphin.Int())
    runsCount = dauphin.NonNull(dauphin.Int)
    ticks = dauphin.Field(
        dauphin.non_null_list("JobTick"),
        dayRange=dauphin.Int(),
        dayOffset=dauphin.Int(),
        limit=dauphin.Int(),
    )
    nextTick = dauphin.Field("FutureJobTick")
    runningCount = dauphin.NonNull(dauphin.Int)  # remove with cron scheduler

    def __init__(self, job_state):
        self._job_state = check.inst_param(job_state, "job_state", JobState)
        super(DauphinJobState, self).__init__(
            id=job_state.job_origin_id,
            name=job_state.name,
            jobType=job_state.job_type,
            status=job_state.status,
        )

    def resolve_repositoryOrigin(self, graphene_info):
        origin = self._job_state.origin.external_repository_origin
        return graphene_info.schema.type_named("RepositoryOrigin")(origin)

    def resolve_jobSpecificData(self, graphene_info):
        if not self._job_state.job_specific_data:
            return None

        if self._job_state.job_type == JobType.SENSOR:
            return graphene_info.schema.type_named("SensorJobData")(
                self._job_state.job_specific_data)

        if self._job_state.job_type == JobType.SCHEDULE:
            return graphene_info.schema.type_named("ScheduleJobData")(
                self._job_state.job_specific_data)

        return None

    def resolve_runs(self, graphene_info, **kwargs):
        if self._job_state.job_type == JobType.SENSOR:
            filters = PipelineRunsFilter.for_sensor(self._job_state)
        else:
            filters = PipelineRunsFilter.for_schedule(self._job_state)
        return [
            graphene_info.schema.type_named("PipelineRun")(r)
            for r in graphene_info.context.instance.get_runs(
                filters=filters,
                limit=kwargs.get("limit"),
            )
        ]

    def resolve_runsCount(self, graphene_info):
        if self._job_state.job_type == JobType.SENSOR:
            filters = PipelineRunsFilter.for_sensor(self._job_state)
        else:
            filters = PipelineRunsFilter.for_schedule(self._job_state)
        return graphene_info.context.instance.get_runs_count(filters=filters)

    def resolve_ticks(self,
                      graphene_info,
                      dayRange=None,
                      dayOffset=None,
                      limit=None):
        before = pendulum.now("UTC").subtract(
            days=dayOffset).timestamp() if dayOffset else None
        after = (pendulum.now("UTC").subtract(
            days=dayRange +
            (dayOffset or 0)).timestamp() if dayRange else None)
        return [
            graphene_info.schema.type_named("JobTick")(graphene_info, tick)
            for tick in graphene_info.context.instance.get_job_ticks(
                self._job_state.job_origin_id,
                before=before,
                after=after,
                limit=limit)
        ]

    def resolve_nextTick(self, graphene_info):
        # sensor
        if self._job_state.job_type == JobType.SENSOR:
            return get_sensor_next_tick(graphene_info, self._job_state)
        else:
            return get_schedule_next_tick(graphene_info, self._job_state)

    def resolve_runningCount(self, graphene_info):
        if self._job_state.job_type == JobType.SENSOR:
            return 1 if self._job_state.status == JobStatus.RUNNING else 0
        else:
            return graphene_info.context.instance.running_schedule_count(
                self._job_state.job_origin_id)
Ejemplo n.º 13
0
class DauphinQuery(dauphin.ObjectType):
    class Meta:
        name = 'Query'

    version = dauphin.NonNull(dauphin.String)
    reloadSupported = dauphin.NonNull(dauphin.Boolean)

    pipelineOrError = dauphin.Field(
        dauphin.NonNull('PipelineOrError'), params=dauphin.NonNull('ExecutionSelector')
    )
    pipeline = dauphin.Field(
        dauphin.NonNull('Pipeline'), params=dauphin.NonNull('ExecutionSelector')
    )
    pipelinesOrError = dauphin.NonNull('PipelinesOrError')
    pipelines = dauphin.Field(dauphin.NonNull('PipelineConnection'))

    configTypeOrError = dauphin.Field(
        dauphin.NonNull('ConfigTypeOrError'),
        pipelineName=dauphin.Argument(dauphin.NonNull(dauphin.String)),
        configTypeName=dauphin.Argument(dauphin.NonNull(dauphin.String)),
        mode=dauphin.Argument(dauphin.NonNull(dauphin.String)),
    )

    runtimeTypeOrError = dauphin.Field(
        dauphin.NonNull('RuntimeTypeOrError'),
        pipelineName=dauphin.Argument(dauphin.NonNull(dauphin.String)),
        runtimeTypeName=dauphin.Argument(dauphin.NonNull(dauphin.String)),
    )

    scheduler = dauphin.Field(dauphin.NonNull('SchedulerOrError'))

    pipelineRunsOrError = dauphin.Field(
        dauphin.NonNull('PipelineRunsOrError'),
        filter=dauphin.Argument(dauphin.NonNull('PipelineRunsFilter')),
        cursor=dauphin.String(),
        limit=dauphin.Int(),
    )

    pipelineRunOrError = dauphin.Field(
        dauphin.NonNull('PipelineRunOrError'), runId=dauphin.NonNull(dauphin.ID)
    )

    pipelineRunTags = dauphin.non_null_list('PipelineTagAndValues')

    isPipelineConfigValid = dauphin.Field(
        dauphin.NonNull('PipelineConfigValidationResult'),
        args={
            'pipeline': dauphin.Argument(dauphin.NonNull('ExecutionSelector')),
            'environmentConfigData': dauphin.Argument('EnvironmentConfigData'),
            'mode': dauphin.Argument(dauphin.NonNull(dauphin.String)),
        },
    )

    executionPlan = dauphin.Field(
        dauphin.NonNull('ExecutionPlanResult'),
        args={
            'pipeline': dauphin.Argument(dauphin.NonNull('ExecutionSelector')),
            'environmentConfigData': dauphin.Argument('EnvironmentConfigData'),
            'mode': dauphin.Argument(dauphin.NonNull(dauphin.String)),
        },
    )

    environmentSchemaOrError = dauphin.Field(
        dauphin.NonNull('EnvironmentSchemaOrError'),
        args={
            'selector': dauphin.Argument(dauphin.NonNull('ExecutionSelector')),
            'mode': dauphin.Argument(dauphin.String),
        },
        description='''Fetch an environment schema given an execution selection and a mode.
        See the descripton on EnvironmentSchema for more information.''',
    )

    instance = dauphin.NonNull('Instance')

    def resolve_configTypeOrError(self, graphene_info, **kwargs):
        return get_config_type(
            graphene_info, kwargs['pipelineName'], kwargs['configTypeName'], kwargs.get('mode')
        )

    def resolve_runtimeTypeOrError(self, graphene_info, **kwargs):
        return get_runtime_type(graphene_info, kwargs['pipelineName'], kwargs['runtimeTypeName'])

    def resolve_version(self, graphene_info):
        return graphene_info.context.version

    def resolve_reloadSupported(self, graphene_info):
        return graphene_info.context.reloader.is_reload_supported

    def resolve_scheduler(self, graphene_info):
        return get_scheduler_or_error(graphene_info)

    def resolve_pipelineOrError(self, graphene_info, **kwargs):
        return get_pipeline_or_error(graphene_info, kwargs['params'].to_selector())

    def resolve_pipeline(self, graphene_info, **kwargs):
        return get_pipeline_or_raise(graphene_info, kwargs['params'].to_selector())

    def resolve_pipelinesOrError(self, graphene_info):
        return get_pipelines_or_error(graphene_info)

    def resolve_pipelines(self, graphene_info):
        return get_pipelines_or_raise(graphene_info)

    def resolve_pipelineRunsOrError(self, graphene_info, **kwargs):
        filters = kwargs['filter'].to_selector()
        provided = [
            i for i in [filters.run_id, filters.pipeline, filters.tag_key, filters.status] if i
        ]

        if len(provided) > 1:
            return graphene_info.schema.type_named('InvalidPipelineRunsFilterError')(
                message="You may only provide one of the filter options."
            )

        return graphene_info.schema.type_named('PipelineRuns')(
            results=get_runs(graphene_info, filters, kwargs.get('cursor'), kwargs.get('limit'))
        )

    def resolve_pipelineRunOrError(self, graphene_info, runId):
        return get_run(graphene_info, runId)

    def resolve_pipelineRunTags(self, graphene_info):
        return get_run_tags(graphene_info)

    def resolve_isPipelineConfigValid(self, graphene_info, pipeline, **kwargs):
        return validate_pipeline_config(
            graphene_info,
            pipeline.to_selector(),
            kwargs.get('environmentConfigData'),
            kwargs.get('mode'),
        )

    def resolve_executionPlan(self, graphene_info, pipeline, **kwargs):
        return get_execution_plan(
            graphene_info,
            pipeline.to_selector(),
            kwargs.get('environmentConfigData'),
            kwargs.get('mode'),
        )

    def resolve_environmentSchemaOrError(self, graphene_info, **kwargs):
        return resolve_environment_schema_or_error(
            graphene_info, kwargs['selector'].to_selector(), kwargs.get('mode')
        )

    def resolve_instance(self, graphene_info):
        return graphene_info.schema.type_named('Instance')(graphene_info.context.instance)
Ejemplo n.º 14
0
class DauphinIPipelineSnapshotMixin(object):
    # Mixin this class to implement IPipelineSnapshot
    #
    # Graphene has some strange properties that make it so that you cannot
    # implement ABCs nor use properties in an overridable way. So the way
    # the mixin works is that the target classes have to have a method
    # get_represented_pipeline()
    #

    def get_represented_pipeline(self):
        raise NotImplementedError()

    name = dauphin.NonNull(dauphin.String)
    description = dauphin.String()
    pipeline_snapshot_id = dauphin.NonNull(dauphin.String)
    dagster_types = dauphin.non_null_list('DagsterType')
    dagster_type_or_error = dauphin.Field(
        dauphin.NonNull('DagsterTypeOrError'),
        dagsterTypeName=dauphin.Argument(dauphin.NonNull(dauphin.String)),
    )
    solids = dauphin.non_null_list('Solid')
    modes = dauphin.non_null_list('Mode')
    solid_handles = dauphin.Field(dauphin.non_null_list('SolidHandle'),
                                  parentHandleID=dauphin.String())
    solid_handle = dauphin.Field(
        'SolidHandle',
        handleID=dauphin.Argument(dauphin.NonNull(dauphin.String)),
    )
    tags = dauphin.non_null_list('PipelineTag')
    runs = dauphin.Field(
        dauphin.non_null_list('PipelineRun'),
        cursor=dauphin.String(),
        limit=dauphin.Int(),
    )
    schedules = dauphin.non_null_list('RunningSchedule')

    def resolve_pipeline_snapshot_id(self, _):
        return self.get_represented_pipeline().identifying_pipeline_snapshot_id

    def resolve_name(self, _):
        return self.get_represented_pipeline().name

    def resolve_description(self, _):
        return self.get_represented_pipeline().description

    def resolve_dagster_types(self, _graphene_info):
        represented_pipeline = self.get_represented_pipeline()
        return sorted(
            list(
                map(
                    lambda dt: to_dauphin_dagster_type(
                        represented_pipeline.pipeline_snapshot, dt.key),
                    [
                        t for t in represented_pipeline.dagster_type_snaps
                        if t.name
                    ],
                )),
            key=lambda dagster_type: dagster_type.name,
        )

    @capture_dauphin_error
    def resolve_dagster_type_or_error(self, _, **kwargs):
        type_name = kwargs['dagsterTypeName']

        represented_pipeline = self.get_represented_pipeline()

        if not represented_pipeline.has_dagster_type_named(type_name):
            from .errors import DauphinDagsterTypeNotFoundError

            raise UserFacingGraphQLError(
                DauphinDagsterTypeNotFoundError(dagster_type_name=type_name))

        return to_dauphin_dagster_type(
            represented_pipeline.pipeline_snapshot,
            represented_pipeline.get_dagster_type_by_name(type_name).key,
        )

    def resolve_solids(self, _graphene_info):
        represented_pipeline = self.get_represented_pipeline()
        return build_dauphin_solids(
            represented_pipeline,
            represented_pipeline.dep_structure_index,
        )

    def resolve_modes(self, _):
        represented_pipeline = self.get_represented_pipeline()
        return [
            DauphinMode(represented_pipeline.config_schema_snapshot,
                        mode_def_snap)
            for mode_def_snap in sorted(represented_pipeline.mode_def_snaps,
                                        key=lambda item: item.name)
        ]

    def resolve_solid_handle(self, _graphene_info, handleID):
        return _get_solid_handles(
            self.get_represented_pipeline()).get(handleID)

    def resolve_solid_handles(self, _graphene_info, **kwargs):
        handles = _get_solid_handles(self.get_represented_pipeline())
        parentHandleID = kwargs.get('parentHandleID')

        if parentHandleID == "":
            handles = {
                key: handle
                for key, handle in handles.items() if not handle.parent
            }
        elif parentHandleID is not None:
            handles = {
                key: handle
                for key, handle in handles.items() if handle.parent
                and handle.parent.handleID.to_string() == parentHandleID
            }

        return [handles[key] for key in sorted(handles)]

    def resolve_tags(self, graphene_info):
        represented_pipeline = self.get_represented_pipeline()
        return [
            graphene_info.schema.type_named('PipelineTag')(key=key,
                                                           value=value) for
            key, value in represented_pipeline.pipeline_snapshot.tags.items()
        ]

    def resolve_solidSubset(self, _graphene_info):
        return self.get_represented_pipeline().solid_subset

    def resolve_runs(self, graphene_info, **kwargs):
        runs_filter = PipelineRunsFilter(
            pipeline_name=self.get_represented_pipeline().name)
        return get_runs(graphene_info, runs_filter, kwargs.get('cursor'),
                        kwargs.get('limit'))

    def resolve_schedules(self, graphene_info):
        external_repository = graphene_info.context.legacy_external_repository
        schedules = graphene_info.context.instance.all_schedules(
            external_repository.name)
        return [
            graphene_info.schema.type_named('RunningSchedule')(
                graphene_info, schedule=schedule) for schedule in schedules
            if get_dagster_schedule_def(graphene_info, schedule.name).name ==
            self.get_represented_pipeline().name
        ]
Ejemplo n.º 15
0
class DauphinJobState(dauphin.ObjectType):
    class Meta:
        name = "JobState"

    id = dauphin.NonNull(dauphin.ID)
    name = dauphin.NonNull(dauphin.String)
    jobType = dauphin.NonNull("JobType")
    status = dauphin.NonNull("JobStatus")
    repositoryOrigin = dauphin.NonNull("RepositoryOrigin")
    jobSpecificData = dauphin.Field("JobSpecificData")
    runs = dauphin.Field(dauphin.non_null_list("PipelineRun"), limit=dauphin.Int())
    runsCount = dauphin.NonNull(dauphin.Int)
    ticks = dauphin.Field(dauphin.non_null_list("JobTick"), limit=dauphin.Int())
    runningCount = dauphin.NonNull(dauphin.Int)  # remove with cron scheduler

    def __init__(self, job_state):
        self._job_state = check.inst_param(job_state, "job_state", JobState)
        super(DauphinJobState, self).__init__(
            id=job_state.job_origin_id,
            name=job_state.name,
            jobType=job_state.job_type,
            status=job_state.status,
        )

    def resolve_repositoryOrigin(self, graphene_info):
        origin = self._job_state.origin.external_repository_origin
        return graphene_info.schema.type_named("RepositoryOrigin")(origin)

    def resolve_jobSpecificData(self, graphene_info):
        if not self._job_state.job_specific_data:
            return None

        if self._job_state.job_type == JobType.SENSOR:
            return graphene_info.schema.type_named("SensorJobData")(
                self._job_state.job_specific_data
            )

        if self._job_state.job_type == JobType.SCHEDULE:
            return graphene_info.schema.type_named("ScheduleJobData")(
                self._job_state.job_specific_data
            )

        return None

    def resolve_runs(self, graphene_info, **kwargs):
        if self._job_state.job_type == JobType.SENSOR:
            filters = PipelineRunsFilter.for_sensor(self._job_state)
        else:
            filters = PipelineRunsFilter.for_schedule(self._job_state)
        return [
            graphene_info.schema.type_named("PipelineRun")(r)
            for r in graphene_info.context.instance.get_runs(
                filters=filters, limit=kwargs.get("limit"),
            )
        ]

    def resolve_runsCount(self, graphene_info):
        if self._job_state.job_type == JobType.SENSOR:
            filters = PipelineRunsFilter.for_sensor(self._job_state)
        else:
            filters = PipelineRunsFilter.for_schedule(self._job_state)
        return graphene_info.context.instance.get_runs_count(filters=filters)

    def resolve_ticks(self, graphene_info, limit=None):
        ticks = graphene_info.context.instance.get_job_ticks(self._job_state.job_origin_id)

        if limit:
            ticks = ticks[:limit]

        return [graphene_info.schema.type_named("JobTick")(graphene_info, tick) for tick in ticks]

    def resolve_runningCount(self, graphene_info):
        if self._job_state.job_type == JobType.SENSOR:
            return 1 if self._job_state.status == JobStatus.RUNNING else 0
        else:
            return graphene_info.context.instance.running_schedule_count(
                self._job_state.job_origin_id
            )
Ejemplo n.º 16
0
class DauphinSensor(dauphin.ObjectType):
    class Meta:
        name = "Sensor"

    id = dauphin.NonNull(dauphin.ID)
    name = dauphin.NonNull(dauphin.String)
    pipelineName = dauphin.NonNull(dauphin.String)
    solidSelection = dauphin.List(dauphin.String)
    mode = dauphin.NonNull(dauphin.String)

    status = dauphin.NonNull("JobStatus")
    runs = dauphin.Field(dauphin.non_null_list("PipelineRun"),
                         limit=dauphin.Int())
    runsCount = dauphin.NonNull(dauphin.Int)
    ticks = dauphin.Field(dauphin.non_null_list("JobTick"),
                          limit=dauphin.Int())

    def resolve_id(self, _):
        return "%s:%s" % (self.name, self.pipelineName)

    def __init__(self, graphene_info, external_sensor):
        self._external_sensor = check.inst_param(external_sensor,
                                                 "external_sensor",
                                                 ExternalSensor)
        self._sensor_state = graphene_info.context.instance.get_job_state(
            self._external_sensor.get_external_origin_id())

        if not self._sensor_state:
            # Also include a SensorState for a stopped sensor that may not
            # have a stored database row yet
            self._sensor_state = self._external_sensor.get_default_job_state()

        super(DauphinSensor, self).__init__(
            name=external_sensor.name,
            pipelineName=external_sensor.pipeline_name,
            solidSelection=external_sensor.solid_selection,
            mode=external_sensor.mode,
        )

    def resolve_status(self, _graphene_info):
        return self._sensor_state.status

    def resolve_runs(self, graphene_info, **kwargs):
        return [
            graphene_info.schema.type_named("PipelineRun")(r)
            for r in graphene_info.context.instance.get_runs(
                filters=PipelineRunsFilter.for_sensor(self._external_sensor),
                limit=kwargs.get("limit"),
            )
        ]

    def resolve_runsCount(self, graphene_info):
        return graphene_info.context.instance.get_runs_count(
            filters=PipelineRunsFilter.for_sensor(self._external_sensor))

    def resolve_ticks(self, graphene_info, limit=None):
        ticks = graphene_info.context.instance.get_job_ticks(
            self._external_sensor.get_external_origin_id())

        if limit:
            ticks = ticks[:limit]

        return [
            graphene_info.schema.type_named("JobTick")(graphene_info, tick)
            for tick in ticks
        ]
Ejemplo n.º 17
0
class DauphinQuery(dauphin.ObjectType):
    class Meta(object):
        name = 'Query'

    version = dauphin.NonNull(dauphin.String)
    reloadSupported = dauphin.NonNull(dauphin.Boolean)

    pipelineOrError = dauphin.Field(
        dauphin.NonNull('PipelineOrError'),
        params=dauphin.NonNull('ExecutionSelector'))
    pipeline = dauphin.Field(dauphin.NonNull('Pipeline'),
                             params=dauphin.NonNull('ExecutionSelector'))
    pipelinesOrError = dauphin.NonNull('PipelinesOrError')
    pipelines = dauphin.Field(dauphin.NonNull('PipelineConnection'))

    runtimeTypeOrError = dauphin.Field(
        dauphin.NonNull('RuntimeTypeOrError'),
        pipelineName=dauphin.Argument(dauphin.NonNull(dauphin.String)),
        runtimeTypeName=dauphin.Argument(dauphin.NonNull(dauphin.String)),
    )

    scheduler = dauphin.Field(dauphin.NonNull('SchedulerOrError'))
    scheduleOrError = dauphin.Field(
        dauphin.NonNull('ScheduleOrError'),
        schedule_name=dauphin.NonNull(dauphin.String),
        limit=dauphin.Int(),
    )

    partitionSetsOrError = dauphin.Field(
        dauphin.NonNull('PartitionSetsOrError'), pipelineName=dauphin.String())
    partitionSetOrError = dauphin.Field(dauphin.NonNull('PartitionSetOrError'),
                                        partitionSetName=dauphin.String())

    pipelineRunsOrError = dauphin.Field(
        dauphin.NonNull('PipelineRunsOrError'),
        filter=dauphin.Argument('PipelineRunsFilter'),
        cursor=dauphin.String(),
        limit=dauphin.Int(),
    )

    pipelineRunOrError = dauphin.Field(dauphin.NonNull('PipelineRunOrError'),
                                       runId=dauphin.NonNull(dauphin.ID))

    pipelineRunTags = dauphin.non_null_list('PipelineTagAndValues')

    usedSolids = dauphin.Field(dauphin.non_null_list('UsedSolid'))
    usedSolid = dauphin.Field('UsedSolid',
                              name=dauphin.NonNull(dauphin.String))

    isPipelineConfigValid = dauphin.Field(
        dauphin.NonNull('PipelineConfigValidationResult'),
        args={
            'pipeline': dauphin.Argument(dauphin.NonNull('ExecutionSelector')),
            'environmentConfigData': dauphin.Argument('EnvironmentConfigData'),
            'mode': dauphin.Argument(dauphin.NonNull(dauphin.String)),
        },
    )

    executionPlan = dauphin.Field(
        dauphin.NonNull('ExecutionPlanResult'),
        args={
            'pipeline': dauphin.Argument(dauphin.NonNull('ExecutionSelector')),
            'environmentConfigData': dauphin.Argument('EnvironmentConfigData'),
            'mode': dauphin.Argument(dauphin.NonNull(dauphin.String)),
        },
    )

    environmentSchemaOrError = dauphin.Field(
        dauphin.NonNull('EnvironmentSchemaOrError'),
        args={
            'selector': dauphin.Argument(dauphin.NonNull('ExecutionSelector')),
            'mode': dauphin.Argument(dauphin.String),
        },
        description=
        '''Fetch an environment schema given an execution selection and a mode.
        See the descripton on EnvironmentSchema for more information.''',
    )

    instance = dauphin.NonNull('Instance')

    def resolve_runtimeTypeOrError(self, graphene_info, **kwargs):
        return get_dagster_type(graphene_info, kwargs['pipelineName'],
                                kwargs['runtimeTypeName'])

    def resolve_version(self, graphene_info):
        return graphene_info.context.version

    def resolve_reloadSupported(self, graphene_info):
        return graphene_info.context.reloader.is_reload_supported

    def resolve_scheduler(self, graphene_info):
        return get_scheduler_or_error(graphene_info)

    def resolve_scheduleOrError(self, graphene_info, schedule_name):
        return get_schedule_or_error(graphene_info, schedule_name)

    def resolve_pipelineOrError(self, graphene_info, **kwargs):
        return get_pipeline_or_error(graphene_info,
                                     kwargs['params'].to_selector())

    def resolve_pipeline(self, graphene_info, **kwargs):
        return get_pipeline_or_raise(graphene_info,
                                     kwargs['params'].to_selector())

    def resolve_pipelinesOrError(self, graphene_info):
        return get_pipelines_or_error(graphene_info)

    def resolve_pipelines(self, graphene_info):
        return get_pipelines_or_raise(graphene_info)

    def resolve_pipelineRunsOrError(self, graphene_info, **kwargs):
        filters = kwargs.get('filter')
        if filters is not None:
            filters = filters.to_selector()

        return graphene_info.schema.type_named('PipelineRuns')(
            results=get_runs(graphene_info, filters, kwargs.get('cursor'),
                             kwargs.get('limit')))

    def resolve_pipelineRunOrError(self, graphene_info, runId):
        return get_run(graphene_info, runId)

    def resolve_partitionSetsOrError(self, graphene_info, **kwargs):
        pipeline_name = kwargs.get('pipelineName')

        return get_partition_sets_or_error(graphene_info, pipeline_name)

    def resolve_partitionSetOrError(self, graphene_info, partitionSetName):
        return get_partition_set(graphene_info, partitionSetName)

    def resolve_pipelineRunTags(self, graphene_info):
        return get_run_tags(graphene_info)

    def resolve_usedSolid(self, graphene_info, name):
        repository = graphene_info.context.repository_definition
        invocations = []
        definition = None

        for pipeline in repository.get_all_pipelines():
            for handle in build_dauphin_solid_handles(
                    pipeline.get_pipeline_snapshot(), pipeline):
                if handle.handleID.definition_name == name:
                    if definition is None:
                        definition = handle.solid.resolve_definition(
                            graphene_info)
                    invocations.append(
                        DauphinSolidInvocationSite(pipeline=pipeline,
                                                   solidHandle=handle))

        return DauphinUsedSolid(definition=definition, invocations=invocations)

    def resolve_usedSolids(self, graphene_info):
        repository = graphene_info.context.repository_definition
        inv_by_def_name = defaultdict(list)
        definitions = []

        for pipeline in repository.get_all_pipelines():
            for handle in build_dauphin_solid_handles(
                    pipeline.get_pipeline_snapshot(), pipeline):
                definition = handle.solid.resolve_definition(graphene_info)
                if definition.name not in inv_by_def_name:
                    definitions.append(definition)
                inv_by_def_name[definition.name].append(
                    DauphinSolidInvocationSite(pipeline=pipeline,
                                               solidHandle=handle))

        return map(
            lambda d: DauphinUsedSolid(
                definition=d,
                invocations=sorted(inv_by_def_name[d.name],
                                   key=lambda i: i.solidHandle.handleID),
            ),
            sorted(definitions, key=lambda d: d.name),
        )

    def resolve_isPipelineConfigValid(self, graphene_info, pipeline, **kwargs):
        return validate_pipeline_config(
            graphene_info,
            pipeline.to_selector(),
            kwargs.get('environmentConfigData'),
            kwargs.get('mode'),
        )

    def resolve_executionPlan(self, graphene_info, pipeline, **kwargs):
        return get_execution_plan(
            graphene_info,
            pipeline.to_selector(),
            kwargs.get('environmentConfigData'),
            kwargs.get('mode'),
        )

    def resolve_environmentSchemaOrError(self, graphene_info, **kwargs):
        return resolve_environment_schema_or_error(
            graphene_info, kwargs['selector'].to_selector(),
            kwargs.get('mode'))

    def resolve_instance(self, graphene_info):
        return graphene_info.schema.type_named('Instance')(
            graphene_info.context.instance)
Ejemplo n.º 18
0
class DauphinQuery(dauphin.ObjectType):
    class Meta(object):
        name = "Query"

    version = dauphin.NonNull(dauphin.String)

    repositoriesOrError = dauphin.NonNull("RepositoriesOrError")
    repositoryOrError = dauphin.Field(
        dauphin.NonNull("RepositoryOrError"),
        repositorySelector=dauphin.NonNull("RepositorySelector"),
    )

    pipelineOrError = dauphin.Field(dauphin.NonNull("PipelineOrError"),
                                    params=dauphin.NonNull("PipelineSelector"))

    pipelineSnapshotOrError = dauphin.Field(
        dauphin.NonNull("PipelineSnapshotOrError"),
        snapshotId=dauphin.String(),
        activePipelineSelector=dauphin.Argument("PipelineSelector"),
    )

    scheduler = dauphin.Field(dauphin.NonNull("SchedulerOrError"))

    scheduleDefinitionOrError = dauphin.Field(
        dauphin.NonNull("ScheduleDefinitionOrError"),
        schedule_selector=dauphin.NonNull("ScheduleSelector"),
    )
    scheduleDefinitionsOrError = dauphin.Field(
        dauphin.NonNull("ScheduleDefinitionsOrError"),
        repositorySelector=dauphin.NonNull("RepositorySelector"),
    )
    scheduleStatesOrError = dauphin.Field(
        dauphin.NonNull("ScheduleStatesOrError"),
        repositorySelector=dauphin.Argument("RepositorySelector"),
        withNoScheduleDefinition=dauphin.Boolean(),
    )

    partitionSetsOrError = dauphin.Field(
        dauphin.NonNull("PartitionSetsOrError"),
        repositorySelector=dauphin.NonNull("RepositorySelector"),
        pipelineName=dauphin.NonNull(dauphin.String),
    )
    partitionSetOrError = dauphin.Field(
        dauphin.NonNull("PartitionSetOrError"),
        repositorySelector=dauphin.NonNull("RepositorySelector"),
        partitionSetName=dauphin.String(),
    )

    pipelineRunsOrError = dauphin.Field(
        dauphin.NonNull("PipelineRunsOrError"),
        filter=dauphin.Argument("PipelineRunsFilter"),
        cursor=dauphin.String(),
        limit=dauphin.Int(),
    )

    pipelineRunOrError = dauphin.Field(dauphin.NonNull("PipelineRunOrError"),
                                       runId=dauphin.NonNull(dauphin.ID))

    pipelineRunTags = dauphin.non_null_list("PipelineTagAndValues")

    runGroupOrError = dauphin.Field(dauphin.NonNull("RunGroupOrError"),
                                    runId=dauphin.NonNull(dauphin.ID))

    runGroupsOrError = dauphin.Field(
        dauphin.NonNull("RunGroupsOrError"),
        filter=dauphin.Argument("PipelineRunsFilter"),
        cursor=dauphin.String(),
        limit=dauphin.Int(),
    )

    isPipelineConfigValid = dauphin.Field(
        dauphin.NonNull("PipelineConfigValidationResult"),
        args={
            "pipeline": dauphin.Argument(dauphin.NonNull("PipelineSelector")),
            "runConfigData": dauphin.Argument("RunConfigData"),
            "mode": dauphin.Argument(dauphin.NonNull(dauphin.String)),
        },
    )

    executionPlanOrError = dauphin.Field(
        dauphin.NonNull("ExecutionPlanOrError"),
        args={
            "pipeline": dauphin.Argument(dauphin.NonNull("PipelineSelector")),
            "runConfigData": dauphin.Argument("RunConfigData"),
            "mode": dauphin.Argument(dauphin.NonNull(dauphin.String)),
        },
    )

    runConfigSchemaOrError = dauphin.Field(
        dauphin.NonNull("RunConfigSchemaOrError"),
        args={
            "selector": dauphin.Argument(dauphin.NonNull("PipelineSelector")),
            "mode": dauphin.Argument(dauphin.String),
        },
        description=
        """Fetch an environment schema given an execution selection and a mode.
        See the descripton on RunConfigSchema for more information.""",
    )

    instance = dauphin.NonNull("Instance")
    assetsOrError = dauphin.Field(dauphin.NonNull("AssetsOrError"))
    assetOrError = dauphin.Field(
        dauphin.NonNull("AssetOrError"),
        assetKey=dauphin.Argument(dauphin.NonNull("AssetKeyInput")),
    )

    def resolve_repositoriesOrError(self, graphene_info):
        return fetch_repositories(graphene_info)

    def resolve_repositoryOrError(self, graphene_info, **kwargs):
        return fetch_repository(
            graphene_info,
            RepositorySelector.from_graphql_input(
                kwargs.get("repositorySelector")),
        )

    def resolve_pipelineSnapshotOrError(self, graphene_info, **kwargs):
        snapshot_id_arg = kwargs.get("snapshotId")
        pipeline_selector_arg = kwargs.get("activePipelineSelector")
        check.invariant(
            not (snapshot_id_arg and pipeline_selector_arg),
            "Must only pass one of snapshotId or activePipelineSelector",
        )
        check.invariant(
            snapshot_id_arg or pipeline_selector_arg,
            "Must set one of snapshotId or activePipelineSelector",
        )

        if pipeline_selector_arg:
            pipeline_selector = pipeline_selector_from_graphql(
                graphene_info.context, kwargs["activePipelineSelector"])
            return get_pipeline_snapshot_or_error_from_pipeline_selector(
                graphene_info, pipeline_selector)
        else:
            return get_pipeline_snapshot_or_error_from_snapshot_id(
                graphene_info, snapshot_id_arg)

    def resolve_version(self, graphene_info):
        return graphene_info.context.version

    def resolve_scheduler(self, graphene_info):
        return get_scheduler_or_error(graphene_info)

    def resolve_scheduleDefinitionOrError(self, graphene_info,
                                          schedule_selector):
        return get_schedule_definition_or_error(
            graphene_info,
            ScheduleSelector.from_graphql_input(schedule_selector))

    def resolve_scheduleDefinitionsOrError(self, graphene_info, **kwargs):
        return get_schedule_definitions_or_error(
            graphene_info,
            RepositorySelector.from_graphql_input(
                kwargs.get("repositorySelector")))

    def resolve_scheduleStatesOrError(self, graphene_info, **kwargs):
        return get_schedule_states_or_error(
            graphene_info,
            RepositorySelector.from_graphql_input(kwargs["repositorySelector"])
            if kwargs.get("repositorySelector") else None,
            kwargs.get("withNoScheduleDefinition"),
        )

    def resolve_pipelineOrError(self, graphene_info, **kwargs):
        return get_pipeline_or_error(
            graphene_info,
            pipeline_selector_from_graphql(graphene_info.context,
                                           kwargs["params"]),
        )

    def resolve_pipelineRunsOrError(self, graphene_info, **kwargs):
        filters = kwargs.get("filter")
        if filters is not None:
            filters = filters.to_selector()

        return graphene_info.schema.type_named("PipelineRuns")(
            results=get_runs(graphene_info, filters, kwargs.get("cursor"),
                             kwargs.get("limit")))

    def resolve_pipelineRunOrError(self, graphene_info, runId):
        return get_run_by_id(graphene_info, runId)

    def resolve_runGroupsOrError(self, graphene_info, **kwargs):
        filters = kwargs.get("filter")
        if filters is not None:
            filters = filters.to_selector()

        return graphene_info.schema.type_named("RunGroupsOrError")(
            results=get_run_groups(graphene_info, filters, kwargs.get(
                "cursor"), kwargs.get("limit")))

    def resolve_partitionSetsOrError(self, graphene_info, **kwargs):
        return get_partition_sets_or_error(
            graphene_info,
            RepositorySelector.from_graphql_input(
                kwargs.get("repositorySelector")),
            kwargs.get("pipelineName"),
        )

    def resolve_partitionSetOrError(self, graphene_info, **kwargs):
        return get_partition_set(
            graphene_info,
            RepositorySelector.from_graphql_input(
                kwargs.get("repositorySelector")),
            kwargs.get("partitionSetName"),
        )

    def resolve_pipelineRunTags(self, graphene_info):
        return get_run_tags(graphene_info)

    def resolve_runGroupOrError(self, graphene_info, runId):
        return get_run_group(graphene_info, runId)

    def resolve_isPipelineConfigValid(self, graphene_info, pipeline, **kwargs):
        return validate_pipeline_config(
            graphene_info,
            pipeline_selector_from_graphql(graphene_info.context, pipeline),
            kwargs.get("runConfigData"),
            kwargs.get("mode"),
        )

    def resolve_executionPlanOrError(self, graphene_info, pipeline, **kwargs):
        return get_execution_plan(
            graphene_info,
            pipeline_selector_from_graphql(graphene_info.context, pipeline),
            kwargs.get("runConfigData"),
            kwargs.get("mode"),
        )

    def resolve_runConfigSchemaOrError(self, graphene_info, **kwargs):
        return resolve_run_config_schema_or_error(
            graphene_info,
            pipeline_selector_from_graphql(graphene_info.context,
                                           kwargs["selector"]),
            kwargs.get("mode"),
        )

    def resolve_instance(self, graphene_info):
        return graphene_info.schema.type_named("Instance")(
            graphene_info.context.instance)

    def resolve_assetsOrError(self, graphene_info):
        return get_assets(graphene_info)

    def resolve_assetOrError(self, graphene_info, **kwargs):
        return get_asset(graphene_info,
                         AssetKey.from_graphql_input(kwargs["assetKey"]))
Ejemplo n.º 19
0
class DauphinPartitionSet(dauphin.ObjectType):
    class Meta(object):
        name = 'PartitionSet'

    name = dauphin.NonNull(dauphin.String)
    pipeline_name = dauphin.NonNull(dauphin.String)
    solid_selection = dauphin.List(dauphin.NonNull(dauphin.String))
    mode = dauphin.NonNull(dauphin.String)
    partitions = dauphin.Field(
        dauphin.NonNull('Partitions'),
        cursor=dauphin.String(),
        limit=dauphin.Int(),
        reverse=dauphin.Boolean(),
    )

    def __init__(self, partition_set_def, external_partition_set):
        self._partition_set_def = check.inst_param(partition_set_def,
                                                   'partition_set_def',
                                                   PartitionSetDefinition)
        self._external_partition_set = check.inst_param(
            external_partition_set, 'external_partition_set',
            ExternalPartitionSet)

        super(DauphinPartitionSet, self).__init__(
            name=external_partition_set.name,
            pipeline_name=external_partition_set.pipeline_name,
            solid_selection=external_partition_set.solid_selection,
            mode=external_partition_set.mode,
        )

    def resolve_partitions(self, graphene_info, **kwargs):
        partition_names = self._external_partition_set.partition_names

        cursor = kwargs.get("cursor")
        limit = kwargs.get("limit")
        reverse = kwargs.get('reverse')

        start = 0
        end = len(partition_names)
        index = 0

        if cursor:
            index = next(
                (idx for (idx, partition_name) in enumerate(partition_names)
                 if partition_name == cursor),
                None,
            )

            if reverse:
                end = index
            else:
                start = index + 1

        if limit:
            if reverse:
                start = end - limit
            else:
                end = start + limit

        partition_names = partition_names[start:end]

        return graphene_info.schema.type_named('Partitions')(results=[
            graphene_info.schema.type_named('Partition')(
                partition_name=partition_name,
                partition_set_def=self._partition_set_def,
                external_partition_set=self._external_partition_set,
            ) for partition_name in partition_names
        ])
Ejemplo n.º 20
0
class DauphinPartition(dauphin.ObjectType):
    class Meta:
        name = "Partition"

    name = dauphin.NonNull(dauphin.String)
    partition_set_name = dauphin.NonNull(dauphin.String)
    solid_selection = dauphin.List(dauphin.NonNull(dauphin.String))
    mode = dauphin.NonNull(dauphin.String)
    runConfigOrError = dauphin.NonNull("PartitionRunConfigOrError")
    tagsOrError = dauphin.NonNull("PartitionTagsOrError")
    runs = dauphin.Field(
        dauphin.non_null_list("PipelineRun"),
        filter=dauphin.Argument("PipelineRunsFilter"),
        cursor=dauphin.String(),
        limit=dauphin.Int(),
    )
    status = dauphin.Field("PipelineRunStatus")

    def __init__(self, external_repository_handle, external_partition_set,
                 partition_name):
        self._external_repository_handle = check.inst_param(
            external_repository_handle, "external_respository_handle",
            RepositoryHandle)
        self._external_partition_set = check.inst_param(
            external_partition_set, "external_partition_set",
            ExternalPartitionSet)
        self._partition_name = check.str_param(partition_name,
                                               "partition_name")

        super(DauphinPartition, self).__init__(
            name=partition_name,
            partition_set_name=external_partition_set.name,
            solid_selection=external_partition_set.solid_selection,
            mode=external_partition_set.mode,
        )

    def resolve_runConfigOrError(self, graphene_info):
        return get_partition_config(
            graphene_info,
            self._external_repository_handle,
            self._external_partition_set.name,
            self._partition_name,
        )

    def resolve_tagsOrError(self, graphene_info):
        return get_partition_tags(
            graphene_info,
            self._external_repository_handle,
            self._external_partition_set.name,
            self._partition_name,
        )

    def resolve_runs(self, graphene_info, **kwargs):
        filters = kwargs.get("filter")
        partition_tags = {
            PARTITION_SET_TAG: self._external_partition_set.name,
            PARTITION_NAME_TAG: self._partition_name,
        }
        if filters is not None:
            filters = filters.to_selector()
            runs_filter = PipelineRunsFilter(
                run_ids=filters.run_ids,
                pipeline_name=filters.pipeline_name,
                statuses=filters.statuses,
                tags=merge_dicts(filters.tags, partition_tags),
            )
        else:
            runs_filter = PipelineRunsFilter(tags=partition_tags)

        return get_runs(graphene_info,
                        runs_filter,
                        cursor=kwargs.get("cursor"),
                        limit=kwargs.get("limit"))
Ejemplo n.º 21
0
class DauphinIPipelineSnapshotMixin:
    # Mixin this class to implement IPipelineSnapshot
    #
    # Graphene has some strange properties that make it so that you cannot
    # implement ABCs nor use properties in an overridable way. So the way
    # the mixin works is that the target classes have to have a method
    # get_represented_pipeline()
    #

    def get_represented_pipeline(self):
        raise NotImplementedError()

    name = dauphin.NonNull(dauphin.String)
    description = dauphin.String()
    id = dauphin.NonNull(dauphin.ID)
    pipeline_snapshot_id = dauphin.NonNull(dauphin.String)
    dagster_types = dauphin.non_null_list("DagsterType")
    dagster_type_or_error = dauphin.Field(
        dauphin.NonNull("DagsterTypeOrError"),
        dagsterTypeName=dauphin.Argument(dauphin.NonNull(dauphin.String)),
    )
    solids = dauphin.non_null_list("Solid")
    modes = dauphin.non_null_list("Mode")
    solid_handles = dauphin.Field(dauphin.non_null_list("SolidHandle"),
                                  parentHandleID=dauphin.String())
    solid_handle = dauphin.Field(
        "SolidHandle",
        handleID=dauphin.Argument(dauphin.NonNull(dauphin.String)),
    )
    tags = dauphin.non_null_list("PipelineTag")
    runs = dauphin.Field(
        dauphin.non_null_list("PipelineRun"),
        cursor=dauphin.String(),
        limit=dauphin.Int(),
    )
    schedules = dauphin.non_null_list("ScheduleDefinition")
    parent_snapshot_id = dauphin.String()

    def resolve_pipeline_snapshot_id(self, _):
        return self.get_represented_pipeline().identifying_pipeline_snapshot_id

    def resolve_id(self, _):
        return self.get_represented_pipeline().identifying_pipeline_snapshot_id

    def resolve_name(self, _):
        return self.get_represented_pipeline().name

    def resolve_description(self, _):
        return self.get_represented_pipeline().description

    def resolve_dagster_types(self, _graphene_info):
        represented_pipeline = self.get_represented_pipeline()
        return sorted(
            list(
                map(
                    lambda dt: to_dauphin_dagster_type(
                        represented_pipeline.pipeline_snapshot, dt.key),
                    [
                        t for t in represented_pipeline.dagster_type_snaps
                        if t.name
                    ],
                )),
            key=lambda dagster_type: dagster_type.name,
        )

    @capture_dauphin_error
    def resolve_dagster_type_or_error(self, _, **kwargs):
        type_name = kwargs["dagsterTypeName"]

        represented_pipeline = self.get_represented_pipeline()

        if not represented_pipeline.has_dagster_type_named(type_name):
            from .errors import DauphinDagsterTypeNotFoundError

            raise UserFacingGraphQLError(
                DauphinDagsterTypeNotFoundError(dagster_type_name=type_name))

        return to_dauphin_dagster_type(
            represented_pipeline.pipeline_snapshot,
            represented_pipeline.get_dagster_type_by_name(type_name).key,
        )

    def resolve_solids(self, _graphene_info):
        represented_pipeline = self.get_represented_pipeline()
        return build_dauphin_solids(
            represented_pipeline,
            represented_pipeline.dep_structure_index,
        )

    def resolve_modes(self, _):
        represented_pipeline = self.get_represented_pipeline()
        return [
            DauphinMode(represented_pipeline.config_schema_snapshot,
                        mode_def_snap)
            for mode_def_snap in sorted(represented_pipeline.mode_def_snaps,
                                        key=lambda item: item.name)
        ]

    def resolve_solid_handle(self, _graphene_info, handleID):
        return _get_solid_handles(
            self.get_represented_pipeline()).get(handleID)

    def resolve_solid_handles(self, _graphene_info, **kwargs):
        handles = _get_solid_handles(self.get_represented_pipeline())
        parentHandleID = kwargs.get("parentHandleID")

        if parentHandleID == "":
            handles = {
                key: handle
                for key, handle in handles.items() if not handle.parent
            }
        elif parentHandleID is not None:
            handles = {
                key: handle
                for key, handle in handles.items() if handle.parent
                and handle.parent.handleID.to_string() == parentHandleID
            }

        return [handles[key] for key in sorted(handles)]

    def resolve_tags(self, graphene_info):
        represented_pipeline = self.get_represented_pipeline()
        return [
            graphene_info.schema.type_named("PipelineTag")(key=key,
                                                           value=value) for
            key, value in represented_pipeline.pipeline_snapshot.tags.items()
        ]

    def resolve_solidSelection(self, _graphene_info):
        return self.get_represented_pipeline().solid_selection

    def resolve_runs(self, graphene_info, **kwargs):
        runs_filter = PipelineRunsFilter(
            pipeline_name=self.get_represented_pipeline().name)
        return get_runs(graphene_info, runs_filter, kwargs.get("cursor"),
                        kwargs.get("limit"))

    def resolve_schedules(self, graphene_info):
        represented_pipeline = self.get_represented_pipeline()
        if not isinstance(represented_pipeline, ExternalPipeline):
            # this is an historical pipeline snapshot, so there are not any associated running
            # schedules
            return []

        pipeline_selector = represented_pipeline.handle.to_selector()
        schedules = get_schedule_definitions_for_pipeline(
            graphene_info, pipeline_selector)
        return schedules

    def resolve_parent_snapshot_id(self, _graphene_info):
        lineage_snapshot = self.get_represented_pipeline(
        ).pipeline_snapshot.lineage_snapshot
        if lineage_snapshot:
            return lineage_snapshot.parent_snapshot_id
        else:
            return None
Ejemplo n.º 22
0
class DauphinRetriesPreviousAttempts(dauphin.InputObjectType):
    class Meta(object):
        name = 'RetriesPreviousAttempts'

    key = dauphin.String()
    count = dauphin.Int()
Ejemplo n.º 23
0
class DauphinSchedule(dauphin.ObjectType):
    class Meta:
        name = "Schedule"

    id = dauphin.NonNull(dauphin.ID)
    name = dauphin.NonNull(dauphin.String)
    cron_schedule = dauphin.NonNull(dauphin.String)
    pipeline_name = dauphin.NonNull(dauphin.String)
    solid_selection = dauphin.List(dauphin.String)
    mode = dauphin.NonNull(dauphin.String)
    execution_timezone = dauphin.Field(dauphin.String)
    scheduleState = dauphin.NonNull("JobState")
    partition_set = dauphin.Field("PartitionSet")

    futureTicks = dauphin.NonNull("FutureJobTicks",
                                  cursor=dauphin.Float(),
                                  limit=dauphin.Int())
    futureTick = dauphin.NonNull("FutureJobTick",
                                 tick_timestamp=dauphin.NonNull(dauphin.Int))

    def resolve_id(self, _):
        return "%s:%s" % (self.name, self.pipeline_name)

    def resolve_partition_set(self, graphene_info):
        if self._external_schedule.partition_set_name is None:
            return None

        repository = graphene_info.context.get_repository_location(
            self._external_schedule.handle.location_name).get_repository(
                self._external_schedule.handle.repository_name)
        external_partition_set = repository.get_external_partition_set(
            self._external_schedule.partition_set_name)

        return graphene_info.schema.type_named("PartitionSet")(
            external_repository_handle=repository.handle,
            external_partition_set=external_partition_set,
        )

    def resolve_futureTicks(self, graphene_info, **kwargs):
        cursor = kwargs.get(
            "cursor",
            get_timestamp_from_utc_datetime(get_current_datetime_in_utc()))
        limit = kwargs.get("limit", 10)

        tick_times = []
        time_iter = self._external_schedule.execution_time_iterator(cursor)

        for _ in range(limit):
            tick_times.append(next(time_iter).timestamp())

        future_ticks = [
            graphene_info.schema.type_named("FutureJobTick")(
                self._schedule_state, tick_time) for tick_time in tick_times
        ]

        return graphene_info.schema.type_named("FutureJobTicks")(
            results=future_ticks, cursor=tick_times[-1] + 1)

    def resolve_futureTick(self, graphene_info, tick_timestamp):
        return graphene_info.schema.type_named("FutureJobTick")(
            self._schedule_state, float(tick_timestamp))

    def __init__(self, graphene_info, external_schedule):
        self._external_schedule = check.inst_param(external_schedule,
                                                   "external_schedule",
                                                   ExternalSchedule)
        self._schedule_state = graphene_info.context.instance.get_job_state(
            self._external_schedule.get_external_origin_id())

        if not self._schedule_state:
            # Also include a ScheduleState for a stopped schedule that may not
            # have a stored database row yet
            self._schedule_state = self._external_schedule.get_default_job_state(
                graphene_info.context.instance)

        super(DauphinSchedule, self).__init__(
            name=external_schedule.name,
            cron_schedule=external_schedule.cron_schedule,
            pipeline_name=external_schedule.pipeline_name,
            solid_selection=external_schedule.solid_selection,
            mode=external_schedule.mode,
            scheduleState=graphene_info.schema.type_named("JobState")(
                self._schedule_state),
            execution_timezone=(self._external_schedule.execution_timezone
                                if self._external_schedule.execution_timezone
                                else pendulum.now().timezone.name),
        )
Ejemplo n.º 24
0
class DauphinQuery(dauphin.ObjectType):
    class Meta(object):
        name = 'Query'

    version = dauphin.NonNull(dauphin.String)

    repositoriesOrError = dauphin.NonNull('RepositoriesOrError')
    repositoryOrError = dauphin.Field(
        dauphin.NonNull('RepositoryOrError'),
        repositorySelector=dauphin.NonNull('RepositorySelector'),
    )

    pipelineOrError = dauphin.Field(dauphin.NonNull('PipelineOrError'),
                                    params=dauphin.NonNull('PipelineSelector'))

    pipelineSnapshotOrError = dauphin.Field(
        dauphin.NonNull('PipelineSnapshotOrError'),
        snapshotId=dauphin.String(),
        activePipelineSelector=dauphin.Argument('PipelineSelector'),
    )

    scheduler = dauphin.Field(dauphin.NonNull('SchedulerOrError'))

    scheduleDefinitionOrError = dauphin.Field(
        dauphin.NonNull('ScheduleDefinitionOrError'),
        schedule_selector=dauphin.NonNull('ScheduleSelector'),
    )
    scheduleDefinitionsOrError = dauphin.Field(
        dauphin.NonNull('ScheduleDefinitionsOrError'),
        repositorySelector=dauphin.NonNull('RepositorySelector'),
    )
    scheduleStatesOrError = dauphin.Field(
        dauphin.NonNull('ScheduleStatesOrError'),
        repositorySelector=dauphin.NonNull('RepositorySelector'),
        withNoScheduleDefinition=dauphin.Boolean(),
    )

    partitionSetsOrError = dauphin.Field(
        dauphin.NonNull('PartitionSetsOrError'),
        repositorySelector=dauphin.NonNull('RepositorySelector'),
        pipelineName=dauphin.NonNull(dauphin.String),
    )
    partitionSetOrError = dauphin.Field(
        dauphin.NonNull('PartitionSetOrError'),
        repositorySelector=dauphin.NonNull('RepositorySelector'),
        partitionSetName=dauphin.String(),
    )

    pipelineRunsOrError = dauphin.Field(
        dauphin.NonNull('PipelineRunsOrError'),
        filter=dauphin.Argument('PipelineRunsFilter'),
        cursor=dauphin.String(),
        limit=dauphin.Int(),
    )

    pipelineRunOrError = dauphin.Field(dauphin.NonNull('PipelineRunOrError'),
                                       runId=dauphin.NonNull(dauphin.ID))

    pipelineRunTags = dauphin.non_null_list('PipelineTagAndValues')

    runGroupOrError = dauphin.Field(dauphin.NonNull('RunGroupOrError'),
                                    runId=dauphin.NonNull(dauphin.ID))

    runGroupsOrError = dauphin.Field(
        dauphin.NonNull('RunGroupsOrError'),
        filter=dauphin.Argument('PipelineRunsFilter'),
        cursor=dauphin.String(),
        limit=dauphin.Int(),
    )

    isPipelineConfigValid = dauphin.Field(
        dauphin.NonNull('PipelineConfigValidationResult'),
        args={
            'pipeline': dauphin.Argument(dauphin.NonNull('PipelineSelector')),
            'runConfigData': dauphin.Argument('RunConfigData'),
            'mode': dauphin.Argument(dauphin.NonNull(dauphin.String)),
        },
    )

    executionPlanOrError = dauphin.Field(
        dauphin.NonNull('ExecutionPlanOrError'),
        args={
            'pipeline': dauphin.Argument(dauphin.NonNull('PipelineSelector')),
            'runConfigData': dauphin.Argument('RunConfigData'),
            'mode': dauphin.Argument(dauphin.NonNull(dauphin.String)),
        },
    )

    runConfigSchemaOrError = dauphin.Field(
        dauphin.NonNull('RunConfigSchemaOrError'),
        args={
            'selector': dauphin.Argument(dauphin.NonNull('PipelineSelector')),
            'mode': dauphin.Argument(dauphin.String),
        },
        description=
        '''Fetch an environment schema given an execution selection and a mode.
        See the descripton on RunConfigSchema for more information.''',
    )

    instance = dauphin.NonNull('Instance')
    assetsOrError = dauphin.Field(dauphin.NonNull('AssetsOrError'))
    assetOrError = dauphin.Field(
        dauphin.NonNull('AssetOrError'),
        assetKey=dauphin.Argument(dauphin.NonNull('AssetKeyInput')),
    )

    def resolve_repositoriesOrError(self, graphene_info):
        return fetch_repositories(graphene_info)

    def resolve_repositoryOrError(self, graphene_info, **kwargs):
        return fetch_repository(
            graphene_info,
            RepositorySelector.from_graphql_input(
                kwargs.get('repositorySelector')),
        )

    def resolve_pipelineSnapshotOrError(self, graphene_info, **kwargs):
        snapshot_id_arg = kwargs.get('snapshotId')
        pipeline_selector_arg = kwargs.get('activePipelineSelector')
        check.invariant(
            not (snapshot_id_arg and pipeline_selector_arg),
            'Must only pass one of snapshotId or activePipelineSelector',
        )
        check.invariant(
            snapshot_id_arg or pipeline_selector_arg,
            'Must set one of snapshotId or activePipelineSelector',
        )

        if pipeline_selector_arg:
            pipeline_selector = pipeline_selector_from_graphql(
                graphene_info.context, kwargs['activePipelineSelector'])
            return get_pipeline_snapshot_or_error_from_pipeline_selector(
                graphene_info, pipeline_selector)
        else:
            return get_pipeline_snapshot_or_error_from_snapshot_id(
                graphene_info, snapshot_id_arg)

    def resolve_version(self, graphene_info):
        return graphene_info.context.version

    def resolve_scheduler(self, graphene_info):
        return get_scheduler_or_error(graphene_info)

    def resolve_scheduleDefinitionOrError(self, graphene_info,
                                          schedule_selector):
        return get_schedule_definition_or_error(
            graphene_info,
            ScheduleSelector.from_graphql_input(schedule_selector))

    def resolve_scheduleDefinitionsOrError(self, graphene_info, **kwargs):
        return get_schedule_definitions_or_error(
            graphene_info,
            RepositorySelector.from_graphql_input(
                kwargs.get('repositorySelector')))

    def resolve_scheduleStatesOrError(self, graphene_info, **kwargs):
        return get_schedule_states_or_error(
            graphene_info,
            RepositorySelector.from_graphql_input(
                kwargs.get('repositorySelector')),
            kwargs.get('withNoScheduleDefinition'),
        )

    def resolve_pipelineOrError(self, graphene_info, **kwargs):
        return get_pipeline_or_error(
            graphene_info,
            pipeline_selector_from_graphql(graphene_info.context,
                                           kwargs['params']),
        )

    def resolve_pipelineRunsOrError(self, graphene_info, **kwargs):
        filters = kwargs.get('filter')
        if filters is not None:
            filters = filters.to_selector()

        return graphene_info.schema.type_named('PipelineRuns')(
            results=get_runs(graphene_info, filters, kwargs.get('cursor'),
                             kwargs.get('limit')))

    def resolve_pipelineRunOrError(self, graphene_info, runId):
        return get_run_by_id(graphene_info, runId)

    def resolve_runGroupsOrError(self, graphene_info, **kwargs):
        filters = kwargs.get('filter')
        if filters is not None:
            filters = filters.to_selector()

        return graphene_info.schema.type_named('RunGroupsOrError')(
            results=get_run_groups(graphene_info, filters, kwargs.get(
                'cursor'), kwargs.get('limit')))

    def resolve_partitionSetsOrError(self, graphene_info, **kwargs):
        return get_partition_sets_or_error(
            graphene_info,
            RepositorySelector.from_graphql_input(
                kwargs.get('repositorySelector')),
            kwargs.get('pipelineName'),
        )

    def resolve_partitionSetOrError(self, graphene_info, **kwargs):
        return get_partition_set(
            graphene_info,
            RepositorySelector.from_graphql_input(
                kwargs.get('repositorySelector')),
            kwargs.get('partitionSetName'),
        )

    def resolve_pipelineRunTags(self, graphene_info):
        return get_run_tags(graphene_info)

    def resolve_runGroupOrError(self, graphene_info, runId):
        return get_run_group(graphene_info, runId)

    def resolve_isPipelineConfigValid(self, graphene_info, pipeline, **kwargs):
        return validate_pipeline_config(
            graphene_info,
            pipeline_selector_from_graphql(graphene_info.context, pipeline),
            kwargs.get('runConfigData'),
            kwargs.get('mode'),
        )

    def resolve_executionPlanOrError(self, graphene_info, pipeline, **kwargs):
        return get_execution_plan(
            graphene_info,
            pipeline_selector_from_graphql(graphene_info.context, pipeline),
            kwargs.get('runConfigData'),
            kwargs.get('mode'),
        )

    def resolve_runConfigSchemaOrError(self, graphene_info, **kwargs):
        return resolve_run_config_schema_or_error(
            graphene_info,
            pipeline_selector_from_graphql(graphene_info.context,
                                           kwargs['selector']),
            kwargs.get('mode'),
        )

    def resolve_instance(self, graphene_info):
        return graphene_info.schema.type_named('Instance')(
            graphene_info.context.instance)

    def resolve_assetsOrError(self, graphene_info):
        return get_assets(graphene_info)

    def resolve_assetOrError(self, graphene_info, **kwargs):
        return get_asset(graphene_info,
                         AssetKey.from_graphql_input(kwargs['assetKey']))