github.com/aiven/aiven-go-client@v1.36.0/flink_job.go (about)

     1  package aiven
     2  
     3  type (
     4  	// FlinkJobHandler aiven go-client handler for Flink Jobs
     5  	FlinkJobHandler struct {
     6  		client *Client
     7  	}
     8  
     9  	// CreateFlinkJobRequest Aiven API request
    10  	// POST https://api.aiven.io/v1/project/<project>/service/<service_name>/flink/job
    11  	CreateFlinkJobRequest struct {
    12  		JobName   string   `json:"job_name,omitempty"`
    13  		Statement string   `json:"statement"`
    14  		TablesIds []string `json:"table_ids"`
    15  	}
    16  
    17  	// CreateFlinkJobResponse Aiven API response
    18  	// POST https://api.aiven.io/v1/project/<project>/service/<service_name>/flink/job
    19  	CreateFlinkJobResponse struct {
    20  		APIResponse
    21  
    22  		JobName string `json:"job_name"`
    23  		JobId   string `json:"job_id"`
    24  	}
    25  
    26  	// PatchFlinkJobRequest Aiven API request
    27  	// PATCH https://api.aiven.io/v1/project/<project>/service/<service_name>/flink/proxy/v1/jobs/<job_id>
    28  	PatchFlinkJobRequest struct {
    29  		JobId string `json:"job_id"`
    30  	}
    31  
    32  	// GetFlinkJobRequest Aiven API request
    33  	// GET https://api.aiven.io/v1/project/<project>/service/<service_name>/flink/job/<job_id>
    34  	GetFlinkJobRequest struct {
    35  		JobId string `json:"job_id"`
    36  	}
    37  
    38  	// ListFlinkApplicationDeploymentResponse Aiven API response
    39  	// GET https://api.aiven.io/v1/project/<project>/service/<service_name>/flink/job
    40  	ListFlinkJobResponse struct {
    41  		APIResponse
    42  		Jobs []struct {
    43  			ID     string `json:"id"`
    44  			Status string `json:"status"`
    45  		} `json:"jobs"`
    46  	}
    47  
    48  	// GetFlinkJobResponse Aiven API response
    49  	// GET https://api.aiven.io/v1/project/<project>/service/<service_name>/flink/proxy/v1/jobs/<job_id>
    50  	GetFlinkJobResponse struct {
    51  		APIResponse
    52  
    53  		Name           string `json:"name"`
    54  		JID            string `json:"jid"`
    55  		IsStoppable    bool   `json:"isStoppable"`
    56  		Duration       int    `json:"duration"`
    57  		Now            int    `json:"now"`
    58  		EndTime        int    `json:"end-time"`
    59  		StartTime      int    `json:"start-time"`
    60  		MaxParallelism int    `json:"maxParallelism"`
    61  		State          string `json:"state"`
    62  		Plan           struct {
    63  			JID   string `json:"jid"`
    64  			Name  string `json:"name"`
    65  			Nodes []struct {
    66  				Description         string      `json:"description"`
    67  				Id                  string      `json:"id"`
    68  				Operator            string      `json:"operator"`
    69  				OperatorStrategy    string      `json:"operator_strategy"`
    70  				OptimizerProperties interface{} `json:"optimizer_properties"`
    71  				Parallelism         int         `json:"parallelism"`
    72  			} `json:"nodes"`
    73  		} `json:"plan"`
    74  		StatusCounts struct {
    75  			Canceled     int `json:"CANCELED"`
    76  			Canceling    int `json:"CANCELING"`
    77  			Created      int `json:"CREATED"`
    78  			Deploying    int `json:"DEPLOYING"`
    79  			Failed       int `json:"FAILED"`
    80  			Finished     int `json:"FINISHED"`
    81  			Initializing int `json:"INITIALIZING"`
    82  			Reconciling  int `json:"RECONCILING"`
    83  			Running      int `json:"RUNNING"`
    84  			Scheduled    int `json:"SCHEDULED"`
    85  		} `json:"status-counts"`
    86  		Timestamps struct {
    87  			Canceled     int `json:"CANCELED"`
    88  			Canceling    int `json:"CANCELING"`
    89  			Created      int `json:"CREATED"`
    90  			Deploying    int `json:"DEPLOYING"`
    91  			Failed       int `json:"FAILED"`
    92  			Finished     int `json:"FINISHED"`
    93  			Initializing int `json:"INITIALIZING"`
    94  			Reconciling  int `json:"RECONCILING"`
    95  			Running      int `json:"RUNNING"`
    96  			Scheduled    int `json:"SCHEDULED"`
    97  		} `json:"timestamps"`
    98  
    99  		Vertices []interface{} `json:"vertices"`
   100  	}
   101  
   102  	// ValidateFlinkJobRequest Aiven API request
   103  	// POST https://api.aiven.io/v1/project/<project>/service/<service_name>/flink/job/validate
   104  	ValidateFlinkJobRequest struct {
   105  		Statement string   `json:"statement"`
   106  		TableIDs  []string `json:"table_ids"`
   107  	}
   108  
   109  	// ValidateFlinkJobResponse Aiven API response
   110  	// POST https://api.aiven.io/v1/project/<project>/service/<service_name>/flink/job/validate
   111  	ValidateFlinkJobResponse struct {
   112  		APIResponse
   113  
   114  		JobValidateError struct {
   115  			Message  string        `json:"message"`
   116  			Position flinkPosition `json:"position"`
   117  		} `json:"job_validate_error"`
   118  	}
   119  )
   120  
   121  // Create creates a flink job
   122  func (h *FlinkJobHandler) Create(project, service string, req CreateFlinkJobRequest) (*CreateFlinkJobResponse, error) {
   123  	path := buildPath("project", project, "service", service, "flink", "job")
   124  	bts, err := h.client.doPostRequest(path, req)
   125  	if err != nil {
   126  		return nil, err
   127  	}
   128  
   129  	var r CreateFlinkJobResponse
   130  	return &r, checkAPIResponse(bts, &r)
   131  }
   132  
   133  // List lists a flink job
   134  func (h *FlinkJobHandler) List(project, service string) (*ListFlinkJobResponse, error) {
   135  	path := buildPath("project", project, "service", service, "flink", "job")
   136  	bts, err := h.client.doGetRequest(path, nil)
   137  	if err != nil {
   138  		return nil, err
   139  	}
   140  
   141  	var r ListFlinkJobResponse
   142  	return &r, checkAPIResponse(bts, &r)
   143  }
   144  
   145  // Get gets a flink job
   146  func (h *FlinkJobHandler) Get(project, service string, req GetFlinkJobRequest) (*GetFlinkJobResponse, error) {
   147  	path := buildPath("project", project, "service", service, "flink", "proxy", "v1", "jobs", req.JobId)
   148  	bts, err := h.client.doGetRequest(path, nil)
   149  	if err != nil {
   150  		return nil, err
   151  	}
   152  
   153  	var r GetFlinkJobResponse
   154  	return &r, checkAPIResponse(bts, &r)
   155  }
   156  
   157  // Patch patches a flink job
   158  func (h *FlinkJobHandler) Patch(project, service string, req PatchFlinkJobRequest) error {
   159  	path := buildPath("project", project, "service", service, "flink", "proxy", "v1", "jobs", req.JobId)
   160  	bts, err := h.client.doPatchRequest(path, nil)
   161  	if err != nil {
   162  		return err
   163  	}
   164  
   165  	return checkAPIResponse(bts, nil)
   166  }
   167  
   168  // Validate validates a flink job
   169  func (h *FlinkJobHandler) Validate(project, service string, req ValidateFlinkJobRequest) (*ValidateFlinkJobResponse, error) {
   170  	path := buildPath("project", project, "service", service, "flink", "job", "validate")
   171  	bts, err := h.client.doPostRequest(path, req)
   172  	if err != nil {
   173  		return nil, err
   174  	}
   175  
   176  	var r ValidateFlinkJobResponse
   177  	return &r, checkAPIResponse(bts, &r)
   178  }