vitess.io/vitess@v0.16.2/go/vt/vtadmin/http/workflows.go (about)

     1  /*
     2  Copyright 2021 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package http
    18  
    19  import (
    20  	"context"
    21  
    22  	vtadminpb "vitess.io/vitess/go/vt/proto/vtadmin"
    23  )
    24  
    25  // GetWorkflow implements the http wrapper for the VTAdminServer.GetWorkflow
    26  // method.
    27  //
    28  // Its route is /workflow/{cluster_id}/{keyspace}/{name}[?active_only=].
    29  func GetWorkflow(ctx context.Context, r Request, api *API) *JSONResponse {
    30  	vars := r.Vars()
    31  
    32  	activeOnly, err := r.ParseQueryParamAsBool("active_only", false)
    33  	if err != nil {
    34  		return NewJSONResponse(nil, err)
    35  	}
    36  
    37  	workflow, err := api.server.GetWorkflow(ctx, &vtadminpb.GetWorkflowRequest{
    38  		ClusterId:  vars["cluster_id"],
    39  		Keyspace:   vars["keyspace"],
    40  		Name:       vars["name"],
    41  		ActiveOnly: activeOnly,
    42  	})
    43  
    44  	return NewJSONResponse(workflow, err)
    45  }
    46  
    47  // GetWorkflows implements the http wrapper for the VTAdminServer.GetWorkflows
    48  // method.
    49  //
    50  // Its route is /workflows, with query params:
    51  // - cluster: repeated, cluster IDs
    52  // - active_only
    53  // - keyspace: repeated
    54  // - ignore_keyspace: repeated
    55  func GetWorkflows(ctx context.Context, r Request, api *API) *JSONResponse {
    56  	query := r.URL.Query()
    57  
    58  	activeOnly, err := r.ParseQueryParamAsBool("active_only", false)
    59  	if err != nil {
    60  		return NewJSONResponse(nil, err)
    61  	}
    62  
    63  	workflows, err := api.server.GetWorkflows(ctx, &vtadminpb.GetWorkflowsRequest{
    64  		ClusterIds:      query["cluster"],
    65  		Keyspaces:       query["keyspace"],
    66  		IgnoreKeyspaces: query["ignore_keyspace"],
    67  		ActiveOnly:      activeOnly,
    68  	})
    69  
    70  	return NewJSONResponse(workflows, err)
    71  }