Merge pull request #349 from mq-cloudpak/amf-dedup-ready-cmd
Dedup subcommand calls for readiness check
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
© Copyright IBM Corporation 2017, 2022
|
© Copyright IBM Corporation 2017, 2023
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -44,7 +44,12 @@ func doMain() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the queue manager has a running listener
|
// Check if the queue manager has a running listener
|
||||||
if active, _ := ready.IsRunningAsActiveQM(ctx, name); active {
|
status, err := ready.Status(ctx, name)
|
||||||
|
if err != nil {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
switch status {
|
||||||
|
case ready.StatusActiveQM:
|
||||||
conn, err := net.Dial("tcp", "127.0.0.1:1414")
|
conn, err := net.Dial("tcp", "127.0.0.1:1414")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
@@ -54,16 +59,16 @@ func doMain() int {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
} else if standby, _ := ready.IsRunningAsStandbyQM(ctx, name); standby {
|
return 0
|
||||||
|
case ready.StatusStandbyQM:
|
||||||
fmt.Printf("Detected queue manager running in standby mode")
|
fmt.Printf("Detected queue manager running in standby mode")
|
||||||
return 10
|
return 10
|
||||||
} else if replica, _ := ready.IsRunningAsReplicaQM(ctx, name); replica {
|
case ready.StatusReplicaQM:
|
||||||
fmt.Printf("Detected queue manager running in replica mode")
|
fmt.Printf("Detected queue manager running in replica mode")
|
||||||
return 20
|
return 20
|
||||||
} else {
|
default:
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
@@ -164,11 +164,12 @@ func startQueueManager(name string) error {
|
|||||||
func stopQueueManager(name string) error {
|
func stopQueueManager(name string) error {
|
||||||
log.Println("Stopping queue manager")
|
log.Println("Stopping queue manager")
|
||||||
qmGracePeriod := os.Getenv("MQ_GRACE_PERIOD")
|
qmGracePeriod := os.Getenv("MQ_GRACE_PERIOD")
|
||||||
isStandby, err := ready.IsRunningAsStandbyQM(context.Background(), name)
|
status, err := ready.Status(context.Background(), name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error getting status for queue manager %v: %v", name, err.Error())
|
log.Printf("Error getting status for queue manager %v: %v", name, err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
isStandby := status.StandbyQM()
|
||||||
args := []string{"-w", "-r", "-tp", qmGracePeriod, name}
|
args := []string{"-w", "-r", "-tp", qmGracePeriod, name}
|
||||||
if os.Getenv("MQ_MULTI_INSTANCE") == "true" {
|
if os.Getenv("MQ_MULTI_INSTANCE") == "true" {
|
||||||
if isStandby {
|
if isStandby {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
© Copyright IBM Corporation 2018, 2022
|
© Copyright IBM Corporation 2018, 2023
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -43,8 +43,8 @@ func GatherMetrics(qmName string, log *logger.Logger) {
|
|||||||
|
|
||||||
// If running in standby mode - wait until the queue manager becomes active
|
// If running in standby mode - wait until the queue manager becomes active
|
||||||
for {
|
for {
|
||||||
active, _ := ready.IsRunningAsActiveQM(context.Background(), qmName)
|
status, _ := ready.Status(context.Background(), qmName)
|
||||||
if active {
|
if status.ActiveQM() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
time.Sleep(requestTimeout * time.Second)
|
time.Sleep(requestTimeout * time.Second)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
© Copyright IBM Corporation 2018, 2022
|
© Copyright IBM Corporation 2018, 2023
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -67,28 +67,38 @@ func Check() (bool, error) {
|
|||||||
return exists, nil
|
return exists, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsRunningAsActiveQM returns true if the queue manager is running in active mode
|
// Status returns an enum representing the current running status of the queue manager
|
||||||
func IsRunningAsActiveQM(ctx context.Context, name string) (bool, error) {
|
func Status(ctx context.Context, name string) (QMStatus, error) {
|
||||||
return isRunningQM(ctx, name, "(RUNNING)")
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsRunningAsStandbyQM returns true if the queue manager is running in standby mode
|
|
||||||
func IsRunningAsStandbyQM(ctx context.Context, name string) (bool, error) {
|
|
||||||
return isRunningQM(ctx, name, "(RUNNING AS STANDBY)")
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsRunningAsReplicaQM returns true if the queue manager is running in replica mode
|
|
||||||
func IsRunningAsReplicaQM(ctx context.Context, name string) (bool, error) {
|
|
||||||
return isRunningQM(ctx, name, "(REPLICA)")
|
|
||||||
}
|
|
||||||
|
|
||||||
func isRunningQM(ctx context.Context, name string, status string) (bool, error) {
|
|
||||||
out, _, err := command.RunContext(ctx, "dspmq", "-n", "-m", name)
|
out, _, err := command.RunContext(ctx, "dspmq", "-n", "-m", name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return StatusUnknown, err
|
||||||
}
|
}
|
||||||
if strings.Contains(string(out), status) {
|
if strings.Contains(string(out), "(RUNNING)") {
|
||||||
return true, nil
|
return StatusActiveQM, nil
|
||||||
}
|
}
|
||||||
return false, nil
|
if strings.Contains(string(out), "(RUNNING AS STANDBY)") {
|
||||||
|
return StatusStandbyQM, nil
|
||||||
|
}
|
||||||
|
if strings.Contains(string(out), "(REPLICA)") {
|
||||||
|
return StatusStandbyQM, nil
|
||||||
|
}
|
||||||
|
return StatusUnknown, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type QMStatus int
|
||||||
|
|
||||||
|
const (
|
||||||
|
StatusUnknown QMStatus = iota
|
||||||
|
StatusActiveQM
|
||||||
|
StatusStandbyQM
|
||||||
|
StatusReplicaQM
|
||||||
|
)
|
||||||
|
|
||||||
|
// ActiveQM returns true if the queue manager is running in active mode
|
||||||
|
func (s QMStatus) ActiveQM() bool { return s == StatusActiveQM }
|
||||||
|
|
||||||
|
// StandbyQM returns true if the queue manager is running in standby mode
|
||||||
|
func (s QMStatus) StandbyQM() bool { return s == StatusStandbyQM }
|
||||||
|
|
||||||
|
// ReplicaQM returns true if the queue manager is running in replica mode
|
||||||
|
func (s QMStatus) ReplicaQM() bool { return s == StatusReplicaQM }
|
||||||
|
|||||||
Reference in New Issue
Block a user