forked from litmuschaos/litmusctl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add get/list probe command (litmuschaos#204)
* fix Signed-off-by: Shivam Purohit <[email protected]> * add get/list probe command Signed-off-by: Shivam Purohit <[email protected]> * fix:fmt Signed-off-by: Shivam Purohit <[email protected]> * get-probes:add non-interactivte flag support Signed-off-by: Shivam Purohit <[email protected]> * fix:non-iteractive mode Signed-off-by: Shivam Purohit <[email protected]> * add probe-id flag for probe details Signed-off-by: Shivam Purohit <[email protected]> * improve logic for probe-id flag Signed-off-by: Shivam Purohit <[email protected]> * fix:filter query on listprobe command Signed-off-by: Shivam Purohit <[email protected]> * fix:fmt Signed-off-by: Shivam Purohit <[email protected]> * get probe:add more details Signed-off-by: Shivam Purohit <[email protected]> * refactor get probe command into smaller funcs Signed-off-by: Shivam Purohit <[email protected]> * fix:double printing of break statement get probe Signed-off-by: Shivam Purohit <[email protected]> * fix:fmt Signed-off-by: Shivam Purohit <[email protected]> * remove toolchain Signed-off-by: Shivam Purohit <[email protected]> * fix swap created by/at Signed-off-by: Shivam Purohit <[email protected]> * refactor the get probe cmd Signed-off-by: Shivam Purohit <[email protected]> * remove unnecessary fields from get probe query Signed-off-by: Shivam Purohit <[email protected]> * add referencedBy in output get probe Signed-off-by: Shivam Purohit <[email protected]> --------- Signed-off-by: Shivam Purohit <[email protected]>
- Loading branch information
1 parent
1a69cc5
commit 6b276da
Showing
7 changed files
with
577 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package probe | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"io" | ||
"net/http" | ||
|
||
models "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" | ||
"github.com/litmuschaos/litmusctl/pkg/apis" | ||
"github.com/litmuschaos/litmusctl/pkg/types" | ||
"github.com/litmuschaos/litmusctl/pkg/utils" | ||
) | ||
|
||
func GetProbeRequest(pid string, probeID string, cred types.Credentials) (GetProbeResponse, error) { | ||
var gqlReq GetProbeGQLRequest | ||
gqlReq.Query = GetProbeQuery | ||
gqlReq.Variables.ProjectID = pid | ||
gqlReq.Variables.ProbeName = probeID | ||
|
||
query, err := json.Marshal(gqlReq) | ||
if err != nil { | ||
return GetProbeResponse{}, errors.New("Error in getting requested probe" + err.Error()) | ||
} | ||
|
||
resp, err := apis.SendRequest( | ||
apis.SendRequestParams{ | ||
Endpoint: cred.ServerEndpoint + utils.GQLAPIPath, | ||
Token: cred.Token, | ||
}, | ||
query, | ||
string(types.Post), | ||
) | ||
|
||
if err != nil { | ||
return GetProbeResponse{}, errors.New("Error in getting requested probe" + err.Error()) | ||
} | ||
|
||
bodyBytes, err := io.ReadAll(resp.Body) | ||
defer resp.Body.Close() | ||
if err != nil { | ||
return GetProbeResponse{}, errors.New("Error in getting requested probe" + err.Error()) | ||
} | ||
|
||
if resp.StatusCode == http.StatusOK { | ||
var getProbeResponse GetProbeResponse | ||
err = json.Unmarshal(bodyBytes, &getProbeResponse) | ||
if err != nil { | ||
return GetProbeResponse{}, errors.New("Error in getting requested probe" + err.Error()) | ||
} | ||
if len(getProbeResponse.Errors) > 0 { | ||
return GetProbeResponse{}, errors.New(getProbeResponse.Errors[0].Message) | ||
} | ||
return getProbeResponse, nil | ||
|
||
} else { | ||
return GetProbeResponse{}, errors.New("Unmatched status code:" + string(bodyBytes)) | ||
} | ||
|
||
} | ||
|
||
func ListProbeRequest(pid string, probetypes []*models.ProbeType, cred types.Credentials) (ListProbeResponse, error) { | ||
var gqlReq ListProbeGQLRequest | ||
gqlReq.Query = ListProbeQuery | ||
gqlReq.Variables.ProjectID = pid | ||
gqlReq.Variables.Filter = models.ProbeFilterInput{ | ||
Type: probetypes, | ||
} | ||
|
||
query, err := json.Marshal(gqlReq) | ||
if err != nil { | ||
return ListProbeResponse{}, errors.New("Error in listing probes" + err.Error()) | ||
} | ||
resp, err := apis.SendRequest( | ||
apis.SendRequestParams{ | ||
Endpoint: cred.ServerEndpoint + utils.GQLAPIPath, | ||
Token: cred.Token, | ||
}, | ||
query, | ||
string(types.Post), | ||
) | ||
|
||
if err != nil { | ||
return ListProbeResponse{}, errors.New("Error in listing probes" + err.Error()) | ||
} | ||
|
||
bodyBytes, err := io.ReadAll(resp.Body) | ||
defer resp.Body.Close() | ||
if err != nil { | ||
return ListProbeResponse{}, errors.New("Error in listing probes" + err.Error()) | ||
} | ||
|
||
if resp.StatusCode == http.StatusOK { | ||
var listProbeResponse ListProbeResponse | ||
err = json.Unmarshal(bodyBytes, &listProbeResponse) | ||
if err != nil { | ||
return ListProbeResponse{}, errors.New("Error in listing probes" + err.Error()) | ||
} | ||
if len(listProbeResponse.Errors) > 0 { | ||
return ListProbeResponse{}, errors.New(listProbeResponse.Errors[0].Message) | ||
} | ||
return listProbeResponse, nil | ||
|
||
} else { | ||
return ListProbeResponse{}, errors.New("Unmatched status code:" + string(bodyBytes)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package probe | ||
|
||
const ( | ||
ListProbeQuery = `query ListProbes($projectID: ID!, $probeNames: [ID!], $filter: ProbeFilterInput) { | ||
listProbes(projectID: $projectID, probeNames: $probeNames, filter: $filter) { | ||
name | ||
type | ||
createdAt | ||
createdBy{ | ||
username | ||
} | ||
} | ||
} | ||
` | ||
GetProbeQuery = `query getProbe($projectID: ID!, $probeName: ID!) { | ||
getProbe(projectID: $projectID, probeName: $probeName) { | ||
name | ||
description | ||
type | ||
infrastructureType | ||
kubernetesHTTPProperties{ | ||
probeTimeout | ||
interval | ||
retry | ||
attempt | ||
probePollingInterval | ||
initialDelay | ||
evaluationTimeout | ||
stopOnFailure | ||
} | ||
kubernetesCMDProperties{ | ||
probeTimeout | ||
interval | ||
retry | ||
attempt | ||
probePollingInterval | ||
initialDelay | ||
evaluationTimeout | ||
stopOnFailure | ||
} | ||
k8sProperties { | ||
probeTimeout | ||
interval | ||
retry | ||
attempt | ||
probePollingInterval | ||
initialDelay | ||
evaluationTimeout | ||
stopOnFailure | ||
} | ||
promProperties { | ||
probeTimeout | ||
interval | ||
retry | ||
attempt | ||
probePollingInterval | ||
initialDelay | ||
evaluationTimeout | ||
stopOnFailure | ||
} | ||
createdAt | ||
createdBy{ | ||
username | ||
} | ||
updatedAt | ||
updatedBy{ | ||
username | ||
} | ||
tags | ||
} | ||
} | ||
` | ||
DeleteProbeQuery = `mutation deleteProbe($probeName: ID!, $projectID: ID!) { | ||
deleteProbe(probeName: $probeName, projectID: $projectID) | ||
} | ||
` | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package probe | ||
|
||
import model "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" | ||
|
||
type GetProbeGQLRequest struct { | ||
Query string `json:"query"` | ||
Variables struct { | ||
ProjectID string `json:"projectID"` | ||
ProbeName string `json:"probeName"` | ||
} `json:"variables"` | ||
} | ||
|
||
type GetProbeResponse struct { | ||
Errors []struct { | ||
Message string `json:"message"` | ||
Path []string `json:"path"` | ||
} `json:"errors"` | ||
Data GetProbeResponseData `json:"data"` | ||
} | ||
|
||
type GetProbeResponseData struct { | ||
GetProbe model.Probe `json:"getProbe"` | ||
} | ||
|
||
type ListProbeGQLRequest struct { | ||
Query string `json:"query"` | ||
Variables struct { | ||
ProjectID string `json:"projectID"` | ||
Filter model.ProbeFilterInput `json:"filter"` | ||
} `json:"variables"` | ||
} | ||
|
||
type ListProbeResponse struct { | ||
Errors []struct { | ||
Message string `json:"message"` | ||
Path []string `json:"path"` | ||
} `json:"errors"` | ||
Data ListProbeResponseData `json:"data"` | ||
} | ||
|
||
type ListProbeResponseData struct { | ||
Probes []model.Probe `json:"listProbes"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.