Skip to content

Commit

Permalink
12.0.3.0-r2 (#178)
Browse files Browse the repository at this point in the history
* 12.0.3.0-r2 update

* add compile
  • Loading branch information
IBMRob authored Mar 30, 2022
1 parent a84721a commit 3e0bd61
Show file tree
Hide file tree
Showing 26 changed files with 1,139 additions and 52 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

**Updates**

* Ability to override Statistics->Resource in server.conf.yaml
* Improved the logging for metrics when authentication is not enabled
* Includes IT39515
* Includes IT39573
* Includes IT39917
* Remove need for python
* Fix for CVE-2022-21698

## 12.0.3.0-r1

Expand Down
33 changes: 8 additions & 25 deletions ace_config_setdbparms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,6 @@
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v20.html

function argStrings {
shlex() {
python -c $'import sys, shlex\nfor arg in shlex.split(sys.stdin):\n\tsys.stdout.write(arg)\n\tsys.stdout.write(\"\\0\")'
}
args=()
while IFS='' read -r -d ''; do
args+=( "$REPLY" )
done < <(shlex <<<$1)

log "${args[0]}"
log "${args[1]}"
log "${args[2]}"

}

if [ -z "$MQSI_VERSION" ]; then
source /opt/ibm/ace-12/server/bin/mqsiprofile
fi
Expand All @@ -41,19 +26,17 @@ if [ -s "/home/aceuser/initial-config/setdbparms/setdbparms.txt" ]; then
continue
fi
IFS=${OLDIFS}
if [[ $line == mqsisetdbparms* ]]; then
if [[ $line == mqsisetdbparms* ]]; then
log "Running suppplied mqsisetdbparms command"
OUTPUT=`eval "$line"`
else
shlex() {
python -c $'import sys, shlex\nfor arg in shlex.split(sys.stdin):\n\tsys.stdout.write(arg)\n\tsys.stdout.write(\"\\0\")'
}
args=()
while IFS='' read -r -d ''; do
args+=( "$REPLY" )
done < <(shlex <<<$line)
log "Setting user and password for resource: ${args[0]}"
cmd="mqsisetdbparms -w /home/aceuser/ace-server -n \"${args[0]}\" -u \"${args[1]}\" -p \"${args[2]}\" 2>&1"

printf "%s" "$line" | xargs -n 1 printf "%s\n" > /tmp/creds
IFS=$'\n' read -d '' -r -a lines < /tmp/creds


log "Setting user and password for resource: ${lines[0]}"
cmd="mqsisetdbparms -w /home/aceuser/ace-server -n \"${lines[0]}\" -u \"${lines[1]}\" -p \"${lines[2]}\" 2>&1"
OUTPUT=`eval "$cmd"`
echo $OUTPUT
fi
Expand Down
1 change: 1 addition & 0 deletions cmd/chkacehealthy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chkacehealthy
128 changes: 122 additions & 6 deletions cmd/chkacehealthy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,97 @@ limitations under the License.
package main

import (
"context"
"fmt"
"log"
"net"
"net/http"
"os"
"time"

"k8s.io/apimachinery/pkg/api/errors"
)

var checkACE = checkACElocal
var httpCheck = httpChecklocal
var socketCheck = socketChecklocal
var osExit = os.Exit

const restartIsTimeoutInSeconds = 60

var netDial = net.Dial
var httpGet = http.Get

func main() {

err := checkACE()
if err != nil {
log.Fatal(err)
}

// If knative service also check FDR is up
knative := os.Getenv("KNATIVESERVICE")
if knative == "true" || knative == "1" {
fmt.Println("KNATIVESERVICE set so checking FDR container")
err := checkDesignerHealth()
if err != nil {
log.Fatal(err)
}
} else {
fmt.Println("KNATIVESERVICE is not set so skipping FDR checks")
}

}

func checkDesignerHealth() error {
// HTTP LMAP endpoint
err := httpCheck("LMAP Port", "http://localhost:3002/admin/ready")
if err != nil {
return err
}

isConnectorService := os.Getenv("CONNECTOR_SERVICE")
if isConnectorService == "true" || isConnectorService == "1" {
// HTTP LCP Connector service endpoint
err = httpCheck("LCP Port", "http://localhost:3001/admin/ready")
if err != nil {
return err
}
}

// LCP api flow endpoint
lcpsocket := "/tmp/lcp.socket"
if value, ok := os.LookupEnv("LCP_IPC_PATH"); ok {
lcpsocket = value
}
err = socketCheck("LCP socket", lcpsocket)
if err != nil {
return err
}

// LMAP endpoint
lmapsocket := "/tmp/lmap.socket"
if value, ok := os.LookupEnv("LMAP_IPC_PATH"); ok {
lmapsocket = value
}
err = socketCheck("LMAP socket", lmapsocket)
if err != nil {
return err
}

return nil
}

func isEnvExist(key string) bool {
if _, ok := os.LookupEnv(key); ok {
return true
}
return false
}

func checkACElocal() error {
// Check if the integration server has started the admin REST endpoint
conn, err := net.Dial("tcp", "127.0.0.1:7600")
conn, err := netDial("tcp", "127.0.0.1:7600")

if err != nil {

Expand All @@ -38,24 +118,60 @@ func main() {

if os.IsNotExist(statErr) {
fmt.Println("Integration server is not active")
os.Exit(1)
} else if statErr != nil {
return errors.NewBadRequest("Integration server is not active")
} else if statErr != nil {
fmt.Println(statErr)
os.Exit(1)
return errors.NewBadRequest("stat error " + statErr.Error())
} else {
fmt.Println("Integration server restart file found")
timeNow := time.Now()
timeDiff := timeNow.Sub(fileInfo.ModTime())

if timeDiff.Seconds() < restartIsTimeoutInSeconds {
fmt.Println("Integration server is restarting")
os.Exit(0)
} else {
fmt.Println("Integration restart time elapsed")
os.Exit(1)
return errors.NewBadRequest("Integration restart time elapsed")
}
}
} else {
fmt.Println("ACE ready check passed")
}
conn.Close()
return nil
}

func httpChecklocal(name string, addr string) error {
resp, err := httpGet(addr)
if err != nil {
return err
}
if resp.StatusCode != 200 {
fmt.Println(name + " ready check failed - HTTP Status is not 200 range")
return errors.NewBadRequest(name + " ready check failed - HTTP Status is not 200 range")
} else {
fmt.Println(name + " ready check passed")
}
return nil
}

func socketChecklocal(name string, socket string) error {
httpc := http.Client{
Transport: &http.Transport{
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
return net.Dial("unix", socket)
},
},
}
response, err := httpc.Get("http://dummyHostname/admin/ready")
if err != nil {
return err
}
if response.StatusCode != 200 {
log.Fatal(name + " ready check failed - HTTP Status is not 200 range")
return errors.NewBadRequest(name + " ready check failed - HTTP Status is not 200 range")
} else {
fmt.Println(name + " ready check passed")
}
return nil
}
134 changes: 134 additions & 0 deletions cmd/chkacehealthy/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
© Copyright IBM Corporation 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// chkacelively checks that ACE is still runing, by checking if the admin REST endpoint port is available.
package main

import (
"net/http"
"os"
"testing"

"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/api/errors"
)

func Test_httpChecklocal(t *testing.T) {

t.Run("http get succeeds", func(t *testing.T) {

oldhttpGet := httpGet
defer func() { httpGet = oldhttpGet }()
httpGet = func(string) (resp *http.Response, err error) {
response := &http.Response{
StatusCode: 200,
}
return response, nil
}

err := httpChecklocal("LMAP Port", "http://localhost:3002/admin/ready")
assert.Nil(t, err)
})

t.Run("http get fails with err on get", func(t *testing.T) {

oldhttpGet := httpGet
defer func() { httpGet = oldhttpGet }()
httpGet = func(string) (resp *http.Response, err error) {
response := &http.Response{}
return response, errors.NewBadRequest("mock err")
}

err := httpChecklocal("LMAP Port", "http://localhost:3002/admin/ready")
assert.Error(t, err, "mock err")
})

t.Run("http get fails with non 200", func(t *testing.T) {

oldhttpGet := httpGet
defer func() { httpGet = oldhttpGet }()
httpGet = func(string) (resp *http.Response, err error) {
response := &http.Response{
StatusCode: 404,
}
return response, nil
}

err := httpChecklocal("Test", "http://localhost:3002/admin/ready")
assert.Error(t, err, "Test ready check failed - HTTP Status is not 200 range")
})
}

func Test_checkDesignerHealth(t *testing.T) {
t.Run("connector service enabled and health check is successful", func(t *testing.T) {
os.Setenv("CONNECTOR_SERVICE", "true")
defer os.Unsetenv("CONNECTOR_SERVICE")
oldhttpGet := httpGet
defer func() { httpGet = oldhttpGet }()
httpGet = func(string) (resp *http.Response, err error) {
response := &http.Response{
StatusCode: 200,
}
return response, nil
}

oldSocketCheck := socketCheck
defer func() { socketCheck = oldSocketCheck }()
socketCheck = func(string, string) (err error) {
return nil
}
err := checkDesignerHealth()
assert.Nil(t, err)
})

t.Run("connector service enabled and health check fails", func(t *testing.T) {
os.Setenv("CONNECTOR_SERVICE", "true")
defer os.Unsetenv("CONNECTOR_SERVICE")
oldhttpGet := httpGet
defer func() { httpGet = oldhttpGet }()
httpGet = func(string) (resp *http.Response, err error) {
response := &http.Response{}
return response, errors.NewBadRequest("mock err")
}

oldSocketCheck := socketCheck
defer func() { socketCheck = oldSocketCheck }()
socketCheck = func(string, string) (err error) {
return nil
}
err := checkDesignerHealth()
assert.Error(t, err, "mock err")
})

t.Run("health check fails for socket http server", func(t *testing.T) {
oldhttpGet := httpGet
defer func() { httpGet = oldhttpGet }()
httpGet = func(string) (resp *http.Response, err error) {
response := &http.Response{
StatusCode: 200,
}
return response, nil
}

oldSocketCheck := socketCheck
defer func() { socketCheck = oldSocketCheck }()
socketCheck = func(string, string) (err error) {
return errors.NewBadRequest("mock err")
}
err := checkDesignerHealth()
assert.Error(t, err, "mock err")
})
}
Loading

0 comments on commit 3e0bd61

Please sign in to comment.