Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YUNIKORN-1984] Expose other config value in the REST response #652

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/webservice/dao/config_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@

package dao

import "github.com/apache/yunikorn-core/pkg/common/configs"

type ValidateConfResponse struct {
Allowed bool `json:"allowed"` // no omitempty, a false value gives a quick way to understand the result.
Reason string `json:"reason,omitempty"`
}

type ConfigDAOInfo struct {
*configs.SchedulerConfig
Extra map[string]string `yaml:",omitempty" json:",omitempty"`
}
10 changes: 9 additions & 1 deletion pkg/webservice/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,17 @@ func getContainerHistory(w http.ResponseWriter, r *http.Request) {
func getClusterConfig(w http.ResponseWriter, r *http.Request) {
writeHeaders(w)

conf := configs.ConfigContext.Get(schedulerContext.GetPolicyGroup())
var marshalledConf []byte
var err error

// merge core config with extra config
schedulerConf := configs.ConfigContext.Get(schedulerContext.GetPolicyGroup())
extraConfig := configs.GetConfigMap()
conf := dao.ConfigDAOInfo{
SchedulerConfig: schedulerConf,
Extra: extraConfig,
}

// check if we have a request for json output
if r.Header.Get("Accept") == "application/json" {
marshalledConf, err = json.Marshal(&conf)
Expand Down
23 changes: 21 additions & 2 deletions pkg/webservice/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ const queueName = "root.default"
const nodeID = "node-1"
const instType = "itype-1"

var (
updatedExtraConf = map[string]string{
"log.level": "info",
"service.schedulingInterval": "1s",
"admissionController.accessControl.bypassAuth": "false",
}
)

// setup To take care of setting up config, cluster, partitions etc
func setup(t *testing.T, config string, partitionCount int) *scheduler.PartitionContext {
var err error
Expand Down Expand Up @@ -481,7 +489,7 @@ func TestGetConfigYAML(t *testing.T) {
resp := &MockResponseWriter{}
getClusterConfig(resp, req)
// yaml unmarshal handles the checksum add the end automatically in this implementation
conf := &configs.SchedulerConfig{}
conf := &dao.ConfigDAOInfo{}
err = yaml.Unmarshal(resp.outputBytes, conf)
assert.NilError(t, err, "failed to unmarshal config from response body")
assert.Equal(t, conf.Partitions[0].NodeSortPolicy.Type, "fair", "node sort policy set incorrectly, not fair")
Expand All @@ -492,13 +500,19 @@ func TestGetConfigYAML(t *testing.T) {
// change the config
err = schedulerContext.UpdateRMSchedulerConfig(rmID, []byte(updatedConf))
assert.NilError(t, err, "Error when updating clusterInfo from config")
configs.SetConfigMap(updatedExtraConf)

// check that we return yaml by default, unmarshal will error when we don't
req.Header.Set("Accept", "unknown")
getClusterConfig(resp, req)
err = yaml.Unmarshal(resp.outputBytes, conf)
assert.NilError(t, err, "failed to unmarshal config from response body (updated config)")
assert.Equal(t, conf.Partitions[0].NodeSortPolicy.Type, "binpacking", "node sort policy not updated")
assert.Assert(t, startConfSum != conf.Checksum, "checksums did not change in output")
assert.Assert(t, reflect.DeepEqual(conf.Extra, updatedExtraConf), "extra config did not change")

// reset extra config map
configs.SetConfigMap(map[string]string{})
}

func TestGetConfigJSON(t *testing.T) {
Expand All @@ -510,7 +524,7 @@ func TestGetConfigJSON(t *testing.T) {
resp := &MockResponseWriter{}
getClusterConfig(resp, req)

conf := &configs.SchedulerConfig{}
conf := &dao.ConfigDAOInfo{}
err := json.Unmarshal(resp.outputBytes, conf)
assert.NilError(t, err, "failed to unmarshal config from response body (json)")
startConfSum := conf.Checksum
Expand All @@ -519,12 +533,17 @@ func TestGetConfigJSON(t *testing.T) {
// change the config
err = schedulerContext.UpdateRMSchedulerConfig(rmID, []byte(updatedConf))
assert.NilError(t, err, "Error when updating clusterInfo from config")
configs.SetConfigMap(updatedExtraConf)

getClusterConfig(resp, req)
err = json.Unmarshal(resp.outputBytes, conf)
assert.NilError(t, err, "failed to unmarshal config from response body (json, updated config)")
assert.Assert(t, startConfSum != conf.Checksum, "checksums did not change in json output: %s, %s", startConfSum, conf.Checksum)
assert.Equal(t, conf.Partitions[0].NodeSortPolicy.Type, "binpacking", "node sort policy not updated (json)")
assert.Assert(t, reflect.DeepEqual(conf.Extra, updatedExtraConf), "extra config did not change")

// reset extra config map
configs.SetConfigMap(map[string]string{})
}

func TestBuildUpdateResponseSuccess(t *testing.T) {
Expand Down