Add get cluster-config command (#123) · oracle/coherence-cli@7aab069 · GitHub
Skip to content

Commit 7aab069

Browse files
author
Tim Middleton
authored
Add get cluster-config command (#123)
1 parent ddc797a commit 7aab069

7 files changed

Lines changed: 70 additions & 2 deletions

File tree

‎docs/reference/05_clusters.adoc‎

Lines changed: 13 additions & 0 deletions

‎pkg/cmd/cluster.go‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,40 @@ NOTE: This is an experimental feature and my be altered or removed in the future
12491249
},
12501250
}
12511251

1252+
// getClusterConfigCmd represents the get cluster-config command.
1253+
var getClusterConfigCmd = &cobra.Command{
1254+
Use: "cluster-config",
1255+
Short: "display the cluster operational config",
1256+
Long: `The 'get cluster-config' displays the cluster operational config for a
1257+
cluster using the current context or a cluster specified by using '-c'. Only available
1258+
in most recent Coherence versions`,
1259+
Args: cobra.ExactArgs(0),
1260+
RunE: func(cmd *cobra.Command, args []string) error {
1261+
var (
1262+
err error
1263+
connection string
1264+
dataFetcher fetcher.Fetcher
1265+
data []byte
1266+
)
1267+
1268+
connection, dataFetcher, err = GetConnectionAndDataFetcher()
1269+
if err != nil {
1270+
return err
1271+
}
1272+
1273+
cmd.Println(FormatCurrentCluster(connection))
1274+
1275+
data, err = dataFetcher.GetClusterConfig()
1276+
if err != nil {
1277+
return err
1278+
}
1279+
1280+
cmd.Println(string(data))
1281+
1282+
return nil
1283+
},
1284+
}
1285+
12521286
// startClusterCmd represents the start cluster command.
12531287
var startClusterCmd = &cobra.Command{
12541288
Use: "cluster",

‎pkg/cmd/root.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ func Initialize(command *cobra.Command) *cobra.Command {
498498
getCmd.AddCommand(getP2PStatsCmd)
499499
getCmd.AddCommand(getConfigCmd)
500500
getCmd.AddCommand(getServiceDistributionsCmd)
501+
getCmd.AddCommand(getClusterConfigCmd)
501502

502503
// set command
503504
command.AddCommand(setCmd)

‎pkg/fetcher/fetcher.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ type Fetcher interface {
146146
// GetEnvironment returns the environment for a member.
147147
GetEnvironment(memberID string) ([]byte, error)
148148

149+
// GetClusterConfig returns the cluster operational config.
150+
GetClusterConfig() ([]byte, error)
151+
149152
// SetMemberAttribute sets the given attribute for a member.
150153
SetMemberAttribute(memberID, attribute string, value interface{}) ([]byte, error)
151154

‎pkg/fetcher/http_fetcher.go‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,15 @@ func (h HTTPFetcher) DumpClusterHeap(role string) ([]byte, error) {
522522
return result, nil
523523
}
524524

525+
// GetClusterConfig returns the cluster operational config.
526+
func (h HTTPFetcher) GetClusterConfig() ([]byte, error) {
527+
result, err := httpGetRequest(h, "/getClusterConfig")
528+
if err != nil {
529+
return constants.EmptyByte, utils.GetError("cannot get cluster config", err)
530+
}
531+
return result, nil
532+
}
533+
525534
// ConfigureTracing instructs the cluster to configure tracing for the role or all members
526535
func (h HTTPFetcher) ConfigureTracing(role string, tracingRatio float32) ([]byte, error) {
527536
var (
@@ -1102,6 +1111,7 @@ func httpRequest(h HTTPFetcher, requestType, urlAppend string, absolute bool, co
11021111
URL = url.URL{}
11031112
httpProxy = os.Getenv("HTTP_PROXY")
11041113
proxy *url.URL
1114+
isJSON = true
11051115
)
11061116

11071117
// if the username and password was sent in then use it
@@ -1187,6 +1197,12 @@ func httpRequest(h HTTPFetcher, requestType, urlAppend string, absolute bool, co
11871197
req.Header.Set("Content-Type", "application/json")
11881198
}
11891199

1200+
// special case for getClusterConfig
1201+
if strings.Contains(urlAppend, "getClusterConfig") {
1202+
isJSON = false
1203+
req.Header.Set("Content-Type", "application/xml")
1204+
}
1205+
11901206
resp, err = client.Do(req)
11911207
if err != nil {
11921208
return empty, err
@@ -1216,7 +1232,7 @@ func httpRequest(h HTTPFetcher, requestType, urlAppend string, absolute bool, co
12161232
}
12171233

12181234
body = buffer.Bytes()
1219-
if len(body) > 0 && !isValidJSON(body) {
1235+
if len(body) > 0 && isJSON && !isValidJSON(body) {
12201236
return empty, errors.New("invalid JSON body")
12211237
}
12221238

‎scripts/generate-doc-snippets.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ create_doc $DOCS_DIR/remove_cluster "${COHCTL} remove cluster --help"
4545
create_doc $DOCS_DIR/get_clusters "${COHCTL} get clusters --help"
4646
create_doc $DOCS_DIR/describe_cluster "${COHCTL} describe cluster --help"
4747
create_doc $DOCS_DIR/discover_clusters "${COHCTL} discover clusters --help"
48+
create_doc $DOCS_DIR/get_cluster_config "${COHCTL} get cluster-config --help"
4849

4950
# Create Cluster
5051
create_doc $DOCS_DIR/create_cluster "${COHCTL} create cluster --help"

‎scripts/startup-clusters.sh‎

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)