diff --git a/Makefile b/Makefile index 6054a348..5b7cb399 100644 --- a/Makefile +++ b/Makefile @@ -80,20 +80,6 @@ endif TEST_NET := --net=host -SPACE := -TABV4 := $(SPACE) $(SPACE) $(SPACE) $(SPACE) -ifdef DUMP_AGENCY_ON_FAILURE - $(info Checking for jq...) - CHECK_JQ_INSTALLTION := $(shell jq --version 2>&1 >/dev/null | cat) - ifneq ($(CHECK_JQ_INSTALLTION),) - $(info ) - $(info Error: 'jq' is not installed. This check happens because DUMP_AGENCY_ON_FAILURE is set, and 'jq' is used during the creation of the agency dump. Verified for version jq==1.6. ) - $(info Try installing it with:) - $(info $(TABV4) sudo apt install jq) - $(info ) - $(error $(CHECK_JQ_INSTALLTION)) - endif -endif # Installation of jq is required for processing AGENCY_DUMP # ifdef DUMP_AGENCY_ON_FAILURE # CHECK_JQ_INSTALLTION := $(shell command -v jq >/dev/null 2>&1 || ( diff --git a/collection.go b/collection.go index c40922e5..c019d82e 100644 --- a/collection.go +++ b/collection.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2017-2021 ArangoDB GmbH, Cologne, Germany +// Copyright 2017-2025 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -183,7 +183,7 @@ type CollectionProperties struct { IsSmartChild bool `json:"isSmartChild,omitempty"` - InternalValidatorType *int `json:"internalValidatorType, omitempty"` + InternalValidatorType *int `json:"internalValidatorType,omitempty"` // Set to create a smart edge or vertex collection. // This requires ArangoDB Enterprise Edition. diff --git a/test/json_agency_config_parse_leader_id/json_agency_config_parse_leader_id.go b/test/json_agency_config_parse_leader_id/json_agency_config_parse_leader_id.go new file mode 100644 index 00000000..2c8968ba --- /dev/null +++ b/test/json_agency_config_parse_leader_id/json_agency_config_parse_leader_id.go @@ -0,0 +1,69 @@ +// +// DISCLAIMER +// +// Copyright 2025 ArangoDB GmbH, Cologne, Germany +// +// 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. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package main + +import ( + "encoding/json" + "fmt" + "io" + "os" +) + +func ExtractValue(input io.Reader) error { + var data map[string]interface{} + + decoder := json.NewDecoder(input) + if err := decoder.Decode(&data); err != nil { + return fmt.Errorf("failed to decode JSON: %w", err) + } + + configuration, ok := data["configuration"].(map[string]interface{}) + if !ok { + return fmt.Errorf("key 'configuration' not found or not an object") + } + pool, ok := configuration["pool"].(map[string]interface{}) + if !ok { + return fmt.Errorf("key 'pool' not found or not an array") + } + + leaderId, ok := data["leaderId"].(string) + if !ok { + return fmt.Errorf("key 'leaderId' not found or not a str") + } + if leaderId == "" { + return fmt.Errorf("key 'leaderId' not set") + } + + endpoint, ok := pool[leaderId].(string) + if !ok { + return fmt.Errorf("key '%s' not found or not a str", leaderId) + } + fmt.Println(endpoint) + + return nil +} + +func main() { + if err := ExtractValue(os.Stdin); err != nil { + fmt.Fprintf(os.Stderr, "JsonAgencyConfigParseError: %v\n and as a result the agency dump could not be created.\n", err) + + } +} diff --git a/test/on_failure.sh b/test/on_failure.sh index 22100a60..d43f1f62 100644 --- a/test/on_failure.sh +++ b/test/on_failure.sh @@ -30,16 +30,19 @@ if [ -n "${DUMP_AGENCY_ON_FAILURE}" ] && [ "${TEST_MODE}" = "cluster" ]; then # _api/agency/config returns leader endpoint with protocol that is usually not supported by curl AGENCY_CONFIG=$(bash -c "curl -k --no-progress-meter ${AUTH} ${ANY_ENDPOINT}/_api/agency/config") - LEADER_ENDPOINT_WITH_UNSUPPORTED_PROTOCOL=$(echo $AGENCY_CONFIG | jq -r '.configuration.pool[.leaderId]' | cat) + # same as: jq -r '.configuration.pool[.leaderId]' + LEADER_ENDPOINT_WITH_UNSUPPORTED_PROTOCOL=$(echo $AGENCY_CONFIG | go run ./test/json_agency_config_parse_leader_id/json_agency_config_parse_leader_id.go | cat) SED_UNSUPPORTED_PROTOCOL_ENDPOINT_TO_ENDPOINT="s/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//${PROTOCOL}:\/\//" LEADER_ENDPOINT=$(echo $LEADER_ENDPOINT_WITH_UNSUPPORTED_PROTOCOL | sed $SED_UNSUPPORTED_PROTOCOL_ENDPOINT_TO_ENDPOINT) - echo "Leader agent endpoint: $LEADER_ENDPOINT" - DUMP_FILE_PATH=$DUMP_AGENCY_ON_FAILURE - mkdir -p $(dirname ${DUMP_FILE_PATH}) - AGENCY_DUMP=$(bash -c "curl -Lk --no-progress-meter ${AUTH} ${LEADER_ENDPOINT}/_api/agency/state") - echo $AGENCY_DUMP > $DUMP_FILE_PATH - echo "Agency dump created at $(realpath $DUMP_FILE_PATH)" + if expr "$LEADER_ENDPOINT" : "^$PROTOCOL" > /dev/null; then + echo "Leader agent endpoint: $LEADER_ENDPOINT" + DUMP_FILE_PATH=$DUMP_AGENCY_ON_FAILURE + mkdir -p $(dirname ${DUMP_FILE_PATH}) + AGENCY_DUMP=$(bash -c "curl -Lk --no-progress-meter ${AUTH} ${LEADER_ENDPOINT}/_api/agency/state") + echo $AGENCY_DUMP > $DUMP_FILE_PATH + echo "Agency dump created at $(realpath $DUMP_FILE_PATH)" + fi fi echo "\nV${MAJOR_VERSION} Tests with ARGS: TEST_MODE=${TEST_MODE} TEST_AUTH=${TEST_AUTH} TEST_CONTENT_TYPE=${TEST_CONTENT_TYPE} TEST_SSL=${TEST_SSL} TEST_CONNECTION=${TEST_CONNECTION} TEST_CVERSION=${TEST_CVERSION}";