File size: 2,751 Bytes
4021124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
#     http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Pipeline parameters and conditions for workflow."""
from __future__ import absolute_import

from typing import List
from sagemaker.workflow.entities import (
    RequestType,
    PipelineVariable,
)


class ExecutionVariable(PipelineVariable):
    """Pipeline execution variables for workflow."""

    def __init__(self, name: str):
        """Create a pipeline execution variable.

        Args:
            name (str): The name of the execution variable.
        """
        self.name = name

    def __eq__(self, other):
        """Override default equals method"""
        if not isinstance(other, ExecutionVariable):
            return NotImplemented
        return self.name == other.name

    def to_string(self) -> PipelineVariable:
        """Prompt the pipeline to convert the pipeline variable to String in runtime

        As ExecutionVariable is treated as String in runtime, no extra actions are needed.
        """
        return self

    @property
    def expr(self) -> RequestType:
        """The 'Get' expression dict for an `ExecutionVariable`."""
        return {"Get": f"Execution.{self.name}"}

    @property
    def _referenced_steps(self) -> List[str]:
        """List of step names that this function depends on."""
        return []


class ExecutionVariables:
    """Provide access to all available execution variables:

    - ExecutionVariables.START_DATETIME
    - ExecutionVariables.CURRENT_DATETIME
    - ExecutionVariables.PIPELINE_NAME
    - ExecutionVariables.PIPELINE_ARN
    - ExecutionVariables.PIPELINE_EXECUTION_ID
    - ExecutionVariables.PIPELINE_EXECUTION_ARN
    - ExecutionVariables.TRAINING_JOB_NAME
    - ExecutionVariables.PROCESSING_JOB_NAME
    """

    START_DATETIME = ExecutionVariable("StartDateTime")
    CURRENT_DATETIME = ExecutionVariable("CurrentDateTime")
    PIPELINE_NAME = ExecutionVariable("PipelineName")
    PIPELINE_ARN = ExecutionVariable("PipelineArn")
    PIPELINE_EXECUTION_ID = ExecutionVariable("PipelineExecutionId")
    PIPELINE_EXECUTION_ARN = ExecutionVariable("PipelineExecutionArn")
    TRAINING_JOB_NAME = ExecutionVariable("TrainingJobName")
    PROCESSING_JOB_NAME = ExecutionVariable("ProcessingJobName")