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

     1  package aiven
     2  
     3  type (
     4  	// FlinkApplicationQueryHandler aiven go-client handler for Flink Application Queries
     5  	FlinkApplicationQueryHandler struct {
     6  		client *Client
     7  	}
     8  
     9  	// CreateFlinkApplicationQueryRequest Aiven API request
    10  	// POST https://api.aiven.io/v1/project/<project>/service/<service_name>/flink/application/<application_id>/query
    11  	CreateFlinkApplicationQueryRequest struct {
    12  		JobTTL  int `json:"job_ttl"`
    13  		MaxRows int `json:"max_rows"`
    14  		Sinks   []struct {
    15  			CreateTable   string `json:"create_table"`
    16  			IntegrationID string `json:"integration_id"`
    17  		} `json:"sinks"`
    18  		Sources []struct {
    19  			CreateTable   string `json:"create_table"`
    20  			IntegrationID string `json:"integration_id"`
    21  		} `json:"sources"`
    22  		Statement string `json:"statement"`
    23  	}
    24  
    25  	// CreateFlinkApplicationQueryResponse Aiven API response
    26  	// POST https://api.aiven.io/v1/project/<project>/service/<service_name>/flink/application/<application_id>/query
    27  	CreateFlinkApplicationQueryResponse struct {
    28  		APIResponse
    29  
    30  		QueryID string `json:"query_id"`
    31  	}
    32  
    33  	// GetFlinkApplicationQueryResponse Aiven API response
    34  	// GET https://api.aiven.io/v1/project/<project>/service/<service_name>/flink/application/<application_id>/query/<query_id>
    35  	GetFlinkApplicationQueryResponse struct {
    36  		APIResponse
    37  
    38  		flinkApplicationQueryFull
    39  	}
    40  
    41  	flinkApplicationQueryFull struct {
    42  		flinkApplicationQueryBase
    43  		Rows []struct {
    44  			Data  interface{} `json:"data"`
    45  			Index int         `json:"index"`
    46  			Kind  string      `json:"kind"`
    47  		} `json:"rows"`
    48  	}
    49  
    50  	// ListFlinkApplicationQueryResponse Aiven API response
    51  	// GET https://api.aiven.io/v1/project/<project>/service/<service_name>/flink/application/<application_id>/query
    52  	ListFlinkApplicationQueryResponse struct {
    53  		APIResponse
    54  		Queries []flinkApplicationQueryBase `json:"queries"`
    55  	}
    56  
    57  	// shared fields by some responses
    58  	flinkApplicationQueryBase struct {
    59  		Columns []struct {
    60  			DataType  string `json:"data_type"`
    61  			Extras    string `json:"extras"`
    62  			Key       string `json:"key"`
    63  			Name      string `json:"name"`
    64  			Nullable  bool   `json:"nullable"`
    65  			Watermark string `json:"watermark"`
    66  		} `json:"columns"`
    67  		CreateTime    string `json:"create_time"`
    68  		JobExpireTime string `json:"job_expire_time"`
    69  		JobID         string `json:"job_id"`
    70  		JobName       string `json:"job_name"`
    71  		QueryID       string `json:"query_id"`
    72  		QueryParams   struct {
    73  			JobTTL  int `json:"job_ttl"`
    74  			MaxRows int `json:"max_rows"`
    75  			Sinks   []struct {
    76  				CreateTable   string `json:"create_table"`
    77  				IntegrationID string `json:"integration_id"`
    78  			} `json:"sinks"`
    79  			Sources []struct {
    80  				CreateTable   string `json:"create_table"`
    81  				IntegrationID string `json:"integration_id"`
    82  			} `json:"sources"`
    83  			Statement string `json:"statement"`
    84  		} `json:"query_params"`
    85  		QueryType string `json:"query_type"`
    86  	}
    87  
    88  	// CancelJobFlinkApplicationQueryResponse Aiven API response
    89  	// PATCH https://api.aiven.io/v1/project/<project>/service/<service_name>/flink/application/<application_id>/query/<query_id>/cancel_job
    90  	CancelJobFlinkApplicationQueryResponse struct {
    91  		APIResponse
    92  
    93  		Details  string `json:"details"`
    94  		Canceled bool   `json:"canceled"`
    95  	}
    96  )
    97  
    98  // Create creates a Flink query
    99  func (h *FlinkApplicationQueryHandler) Create(project, service, applicationId string, req CreateFlinkApplicationQueryRequest) (*CreateFlinkApplicationQueryResponse, error) {
   100  	path := buildPath("project", project, "service", service, "flink", "application", applicationId, "query")
   101  	bts, err := h.client.doPostRequest(path, req)
   102  	if err != nil {
   103  		return nil, err
   104  	}
   105  
   106  	var r CreateFlinkApplicationQueryResponse
   107  	return &r, checkAPIResponse(bts, &r)
   108  }
   109  
   110  // Get gets a Flink query
   111  func (h *FlinkApplicationQueryHandler) Get(project, service, applicationId, queryId string) (*GetFlinkApplicationQueryResponse, error) {
   112  	path := buildPath("project", project, "service", service, "flink", "application", applicationId, "query", queryId)
   113  	bts, err := h.client.doGetRequest(path, nil)
   114  	if err != nil {
   115  		return nil, err
   116  	}
   117  
   118  	var r GetFlinkApplicationQueryResponse
   119  	return &r, checkAPIResponse(bts, &r)
   120  }
   121  
   122  // Delete deletes a Flink query
   123  func (h *FlinkApplicationQueryHandler) Delete(project, service, applicationId, queryId string) error {
   124  	path := buildPath("project", project, "service", service, "flink", "application", applicationId, "query", queryId)
   125  	bts, err := h.client.doDeleteRequest(path, nil)
   126  	if err != nil {
   127  		return err
   128  	}
   129  
   130  	return checkAPIResponse(bts, nil)
   131  }
   132  
   133  // List lists all Flink queries
   134  func (h *FlinkApplicationQueryHandler) List(project, service, applicationId string) (*ListFlinkApplicationQueryResponse, error) {
   135  	path := buildPath("project", project, "service", service, "flink", "application", applicationId, "query")
   136  	bts, err := h.client.doGetRequest(path, nil)
   137  	if err != nil {
   138  		return nil, err
   139  	}
   140  
   141  	var r ListFlinkApplicationQueryResponse
   142  	return &r, checkAPIResponse(bts, &r)
   143  }
   144  
   145  // CancelJob cancel the Flink job of a Flink query
   146  func (h *FlinkApplicationQueryHandler) CancelJob(project, service, applicationId, queryId string) (*CancelJobFlinkApplicationQueryResponse, error) {
   147  	path := buildPath("project", project, "service", service, "flink", "application", applicationId, "query", queryId, "cancel_job")
   148  	bts, err := h.client.doPatchRequest(path, nil)
   149  	if err != nil {
   150  		return nil, err
   151  	}
   152  
   153  	var r CancelJobFlinkApplicationQueryResponse
   154  	return &r, checkAPIResponse(bts, &r)
   155  }