/
http_server.go
109 lines (96 loc) · 2.84 KB
/
http_server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* Copyright (c) 2021, 2023 Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
*/
package cmd
import (
"encoding/json"
"fmt"
"github.com/oracle/coherence-cli/pkg/config"
"github.com/oracle/coherence-cli/pkg/fetcher"
"github.com/oracle/coherence-cli/pkg/utils"
"github.com/spf13/cobra"
)
const httpString = "http"
// getHTTPProxiesCmd represents the get http-servers command.
var getHTTPProxiesCmd = &cobra.Command{
Use: "http-servers",
Short: "display http proxy services for a cluster",
Long: `The 'get http-servers' command displays the list of http proxy servers for a cluster.`,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
var (
err error
dataFetcher fetcher.Fetcher
connection string
)
connection, dataFetcher, err = GetConnectionAndDataFetcher()
if err != nil {
return err
}
details, err := returnGetProxiesDetails(cmd, httpString, dataFetcher, connection)
if err != nil {
return err
}
if !isWatchEnabled() {
// don't display the value if watch was enabled as it was already output
cmd.Println(details)
}
return nil
},
}
// describeHTTPProxyCmd represents the describe http-proxy command.
var describeHTTPProxyCmd = &cobra.Command{
Use: "http-server service-name",
Short: "describe a http server",
Long: `The 'describe http-server' command shows information related to http servers.`,
ValidArgsFunction: completionHTTPServers,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
displayErrorAndExit(cmd, "you must provide a service name")
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
var (
serviceResult []byte
proxiesSummary = config.ProxiesSummary{}
err error
dataFetcher fetcher.Fetcher
connection string
)
serviceName := args[0]
connection, dataFetcher, err = GetConnectionAndDataFetcher()
if err != nil {
return err
}
proxyResults, err := dataFetcher.GetProxySummaryJSON()
if err != nil {
return err
}
err = json.Unmarshal(proxyResults, &proxiesSummary)
if err != nil {
return utils.GetError("unable to decode proxy details", err)
}
found := false
for _, value := range proxiesSummary.Proxies {
if value.ServiceName == serviceName && value.Protocol == httpString {
found = true
}
}
if !found {
return fmt.Errorf("unable to find Http Server with service name '%s'", serviceName)
}
// we have valid service name so issue queries
serviceResult, err = dataFetcher.GetSingleServiceDetailsJSON(serviceName)
if err != nil {
return err
}
err = displayProxyDetails(cmd, dataFetcher, connection, httpString, serviceResult, proxyResults)
if err != nil {
return err
}
return nil
},
}