github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/pkg/ast/pipesearch/listIndicesHandler.go (about)

     1  /*
     2  Copyright 2023.
     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 pipesearch
    18  
    19  import (
    20  	"sort"
    21  
    22  	"github.com/siglens/siglens/pkg/utils"
    23  	vtable "github.com/siglens/siglens/pkg/virtualtable"
    24  	log "github.com/sirupsen/logrus"
    25  	"github.com/valyala/fasthttp"
    26  )
    27  
    28  type IndexInfo struct {
    29  	Name string `json:"index"`
    30  }
    31  
    32  type AllIndicesInfoResponse []*IndexInfo
    33  
    34  func ListIndicesHandler(ctx *fasthttp.RequestCtx, myid uint64) {
    35  	var httpResp AllIndicesInfoResponse
    36  	allVirtualTableNames := vtable.ExpandAndReturnIndexNames("*", myid, false)
    37  	sort.Strings(allVirtualTableNames)
    38  	ctx.SetStatusCode(fasthttp.StatusOK)
    39  	ctx.Response.Header.Set("Content-Type", "application/json")
    40  
    41  	if len(allVirtualTableNames) == 0 {
    42  		noTables := []*IndexInfo{}
    43  		httpResp = noTables
    44  		utils.WriteJsonResponse(ctx, httpResp)
    45  		return
    46  	}
    47  	var listIndices []*IndexInfo
    48  	for _, indexName := range allVirtualTableNames {
    49  		IndexInfo := IndexInfo{}
    50  		if indexName == "" || indexName == "*" {
    51  			log.Debugf("ListIndicesHandler: one of empty/wildcard indexName=%v", indexName)
    52  			continue
    53  		}
    54  		IndexInfo.Name = indexName
    55  		listIndices = append(listIndices, &IndexInfo)
    56  		httpResp = listIndices
    57  	}
    58  	utils.WriteJsonResponse(ctx, httpResp)
    59  }
    60  
    61  type Version struct {
    62  	Number        string `json:"number"`
    63  	BuildFlavor   string `json:"build_flavor"`
    64  	BuildType     string `json:"build_type"`
    65  	BuildHash     string `json:"build_hash"`
    66  	BuildDate     string `json:"build_date"`
    67  	BuildSnap     bool   `json:"build_snapshot"`
    68  	LuceneVersion string `json:"lucene_version"`
    69  	MWCV          string `json:"minimum_wire_compatibility_version"`
    70  	MICV          string `json:"minimum_index_compatibility_version"`
    71  }
    72  
    73  type ESResponse struct {
    74  	Name        string      `json:"name"`
    75  	ClusterName string      `json:"cluster_name"`
    76  	ClusterUUID string      `json:"cluster_uuid"`
    77  	Version     interface{} `json:"version"`
    78  	TagLine     string      `json:"tagline"`
    79  }
    80  
    81  // returns cluster details
    82  func SendClusterDetails(ctx *fasthttp.RequestCtx) {
    83  	// hard coding response for superset
    84  	versionRes := Version{
    85  		Number:        "7.17.10",
    86  		BuildFlavor:   "default",
    87  		BuildType:     "deb",
    88  		BuildHash:     "fecd68e3150eda0c307ab9a9d7557f5d5fd71349",
    89  		BuildDate:     "2023-04-23T05:33:18.138275597Z",
    90  		BuildSnap:     false,
    91  		LuceneVersion: "8.11.1",
    92  		MWCV:          "6.8.0",
    93  		MICV:          "6.0.0-beta1",
    94  	}
    95  
    96  	esRes := ESResponse{
    97  		Name:        "test",
    98  		ClusterName: "elasticsearch",
    99  		ClusterUUID: "mQAvDxlxTkiDGTwojQ_aOg",
   100  		Version:     versionRes,
   101  		TagLine:     "Hey Superset",
   102  	}
   103  
   104  	utils.WriteJsonResponse(ctx, esRes)
   105  }