github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/mrs/v1/job/Create.go (about)

     1  package job
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/openstack"
     7  )
     8  
     9  type CreateOpts struct {
    10  	// Job type code
    11  	// 1: MapReduce
    12  	// 2: Spark
    13  	// 3: Hive Script
    14  	// 4: HiveQL (not supported currently)
    15  	// 5: DistCp, importing and exporting data. For details, see CreateDistCpOpts.
    16  	// 6: Spark Script
    17  	// 7: Spark SQL, submitting Spark SQL statements. For details, see CreateSparkOpts. (Not supported in this API currently.)
    18  	// NOTE:
    19  	// Spark and Hive jobs can be added to only clusters that include Spark and Hive components.
    20  	JobType int `json:"job_type" required:"true"`
    21  	// Job name
    22  	// Contains only 1 to 64 letters, digits, hyphens (-), and underscores (_).
    23  	// NOTE:
    24  	// Identical job names are allowed but not recommended.
    25  	JobName string `json:"job_name" required:"true"`
    26  	// Cluster ID
    27  	ClusterId string `json:"cluster_id" required:"true"`
    28  	// Path of the JAR or SQL file for program execution
    29  	// The parameter must meet the following requirements:
    30  	// Contains a maximum of 1,023 characters, excluding special characters such as ;|&><'$.
    31  	// The address cannot be empty or full of spaces.
    32  	// Starts with / or s3a://. The OBS path does not support files or programs encrypted by KMS.
    33  	// Spark Script must end with .sql while MapReduce and Spark Jar must end with .jar.sql and jar are case-insensitive.
    34  	JarPath string `json:"jar_path" required:"true"`
    35  	// Key parameter for program execution. The parameter is specified by the function of the user's program.
    36  	// MRS is only responsible for loading the parameter.
    37  	// The parameter contains a maximum of 2,047 characters, excluding special characters such as ;|&>'<$, and can be left blank.
    38  	// NOTE:
    39  	// When entering a parameter containing sensitive information (for example, login password),
    40  	// you can add an at sign (@) before the parameter name to encrypt the parameter value.
    41  	// This prevents the sensitive information from being persisted in plaintext.
    42  	// Therefore, when you view job information on the MRS, sensitive information will be displayed as asterisks (*).
    43  	// For example, username=admin @password=admin_123.
    44  	Arguments string `json:"arguments,omitempty"`
    45  	// Path for inputting data, which must start with / or s3a://. Set this parameter to a correct OBS path.
    46  	// The OBS path does not support files or programs encrypted by KMS.
    47  	// The parameter contains a maximum of 1,023 characters, excluding special characters such as ;|&>'<$, and can be left blank.
    48  	Input string `json:"input,omitempty"`
    49  	// Path for outputting data, which must start with / or s3a://. A correct OBS path is required.
    50  	// If the path does not exist, the system automatically creates it.
    51  	// The parameter contains a maximum of 1,023 characters, excluding special characters such as ;|&>'<$, and can be left blank.
    52  	Output string `json:"output,omitempty"`
    53  	// Path for storing job logs that record job running status. The path must start with / or s3a://. A correct OBS path is required.
    54  	// The parameter contains a maximum of 1,023 characters, excluding special characters such as ;|&>'<$, and can be left blank.
    55  	JobLog string `json:"job_log,omitempty"`
    56  	// SQL program path
    57  	// This parameter is needed by Spark Script and Hive Script jobs only, and must meet the following requirements:
    58  	// Contains a maximum of 1,023 characters, excluding special characters such as ;|&><'$. The address cannot be empty or full of spaces.
    59  	// The path must start with / or s3a://. The OBS path does not support files or programs encrypted by KMS.
    60  	// The path must end with .sql.sql is case-insensitive.
    61  	HiveScriptPath string `json:"hive_script_path,omitempty"`
    62  
    63  	IsProtected bool `json:"is_protected,omitempty"`
    64  	IsPublic    bool `json:"is_public,omitempty"`
    65  }
    66  
    67  type CreateDistCpOpts struct {
    68  	// 5: DistCp, importing and exporting data.
    69  	JobType int `json:"job_type"`
    70  	// Job name
    71  	// Contains only 1 to 64 letters, digits, hyphens (-), and underscores (_).
    72  	// NOTE:
    73  	// Identical job names are allowed but not recommended.
    74  	JobName   string `json:"job_name"`
    75  	ClusterId string `json:"cluster_id"`
    76  	// Data source path
    77  	// When you import data, the parameter is set to an OBS path. Files or programs encrypted by KMS are not supported.
    78  	// When you export data, the parameter is set to an HDFS path.
    79  	Input string `json:"input"`
    80  	// Data receiving path
    81  	// When you import data, the parameter is set to an HDFS path.
    82  	// When you export data, the parameter is set to an OBS path.
    83  	Output string `json:"output"`
    84  	// Types of file operations, including:
    85  	// export: Export data from HDFS to OBS.
    86  	// import: Import data from OBS to HDFS.
    87  	FileAction string `json:"file_action"`
    88  }
    89  
    90  type CreateSparkOpts struct {
    91  	JobType    int    `json:"job_type"`
    92  	JobName    string `json:"job_name"`
    93  	ClusterId  string `json:"cluster_id"`
    94  	JarPath    string `json:"jar_path"`
    95  	Arguments  string `json:"arguments"`
    96  	Input      string `json:"input"`
    97  	Output     string `json:"output"`
    98  	JobLog     string `json:"job_log"`
    99  	FileAction string `json:"file_action"`
   100  	// Spark SQL statement, which needs Base64 encoding and decoding. ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
   101  	// is a standard encoding table. MRS uses ABCDEFGHILKJMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ for Base64 encoding.
   102  	// The value of the hql parameter is generated by adding any letter to the beginning of the encoded character string.
   103  	// The Spark SQL statement is generated by decoding the value in the background.
   104  	// Example:
   105  	// Obtain the Base64 encoding tool.
   106  	// Enter the show tables; Spark SQL statement in the encoding tool to perform Base64 encoding.
   107  	// Obtain the encoded character string c2hvdyB0YWLsZXM7.
   108  	// At the beginning of c2hvdyB0YWLsZXM7, add any letter, for example, g. Then, the character string becomes
   109  	// gc2hvdyB0YWLsZXM7, that is, the value of the hql parameter.
   110  	Hql            string `json:"hql"`
   111  	HiveScriptPath string `json:"hive_script_path"`
   112  }
   113  
   114  // Create Use CreateOpts or CreateDistCpOpts or CreateSparkOpts
   115  func Create(c *golangsdk.ServiceClient, opts interface{}) (*JobExecution, error) {
   116  	b, err := build.RequestBody(opts, "")
   117  	if err != nil {
   118  		return nil, err
   119  	}
   120  
   121  	// POST /v1.1/{project_id}/jobs/submit-job
   122  	raw, err := c.Post(c.ServiceURL("jobs", "submit-job"), b, nil, &golangsdk.RequestOpts{
   123  		OkCodes:     []int{200},
   124  		MoreHeaders: openstack.StdRequestOpts().MoreHeaders,
   125  	})
   126  
   127  	return extra(err, raw)
   128  }