func()

in pkg/mgmapi/mgmapi.go [618:691]


func (mci *mgmClientImpl) getConfig(
	nodeId int, sectionFilter cfgSectionType, configKey uint32, getConfigFromConnectedMgmd bool) (configValue, error) {

	// command : (note : version is mandatory but ignored by the Management Server)
	// get config_v2
	// version: <Configuration version number>
	// node: <communication sections of the node to send back in reply>
	// nodetype: <Type of requesting node>
	// from_node: <Node to get config from>

	// reply :
	// get config reply
	// result: Ok
	// Content-Length: 4588
	// Content-Type: ndbconfig/octet-stream
	// Content-Transfer-Encoding: base64
	// <newline>
	// <config as octet stream>

	// build args
	args := map[string]interface{}{
		// version args is ignored by Mgm Server, but they are mandatory so just send 0
		"version": 0,
		// this client is not exactly an API node but should be okay to mimic one.
		"nodetype": NodeTypeAPI,
		// The 'node' arg can be set to one of the following value :
		// 0 - to receive all the communication sections in the config (or)
		// node id - to receive all communication sections related to node with the given id.
		// The management node seems to accept even a node id that doesn't exist in the config
		// and in that case, there are no communication sections as the node is non-existent.
		// In any case, the sent back communication sections will be ignored by this client.
		// So, set this arg to the maximum possible API node id, which has the least chance of
		// appearing in the config, to reduce the amount of data sent back.
		"node": 255,
	}

	if !getConfigFromConnectedMgmd {
		// Get the config directly from the node with 'nodeId'.
		args["from_node"] = nodeId
	}

	expectedReply := []string{
		"get config reply",
		"result",
		"Content-Length",
		"Content-Type",
		"Content-Transfer-Encoding",
		"Content",
	}

	// send the command and read the reply
	reply, err := mci.executeCommand("get config_v2", args, false, expectedReply)
	if err != nil {
		return nil, err
	}

	if reply["result"] != "Ok" {
		// get config
		return nil, errors.New(reply["result"])
	}

	if reply["Content-Type"] != "ndbconfig/octet-stream" ||
		reply["Content-Transfer-Encoding"] != "base64" {
		return nil, debug.InternalError("unexpected content in get config reply")
	}

	// extract the required config value from the base64 encoded config data
	value := readConfigFromBase64EncodedData(reply["Content"], sectionFilter, uint32(nodeId), configKey)
	if value == nil {
		return nil, debug.InternalError("getConfig failed")
	}

	return value, nil
}