Example #1
0
func (s *SchedulerServer) createConfig(configFactory *factory.ConfigFactory) (*scheduler.Config, error) {
	var policy schedulerapi.Policy
	var configData []byte

	if _, err := os.Stat(s.PolicyConfigFile); err == nil {
		configData, err = ioutil.ReadFile(s.PolicyConfigFile)
		if err != nil {
			return nil, fmt.Errorf("Unable to read policy config: %v", err)
		}
		err = latestschedulerapi.Codec.DecodeInto(configData, &policy)
		if err != nil {
			return nil, fmt.Errorf("Invalid configuration: %v", err)
		}

		return configFactory.CreateFromConfig(policy)
	}

	// if the config file isn't provided, use the specified (or default) provider
	// check of algorithm provider is registered and fail fast
	_, err := factory.GetAlgorithmProvider(s.AlgorithmProvider)
	if err != nil {
		return nil, err
	}

	return configFactory.CreateFromProvider(s.AlgorithmProvider)
}
Example #2
0
func TestDefaultConfigExists(t *testing.T) {
	p, err := factory.GetAlgorithmProvider(factory.DefaultProvider)
	if err != nil {
		t.Errorf("error retrieving default provider: %v", err)
	}
	if p == nil {
		t.Error("algorithm provider config should not be nil")
	}
	if len(p.FitPredicateKeys) == 0 {
		t.Error("default algorithm provider shouldn't have 0 fit predicates")
	}
}
Example #3
0
func TestAlgorithmProviders(t *testing.T) {
	for _, pn := range algorithmProviderNames {
		p, err := factory.GetAlgorithmProvider(pn)
		if err != nil {
			t.Errorf("error retrieving '%s' provider: %v", pn, err)
			break
		}
		if len(p.PriorityFunctionKeys) == 0 {
			t.Errorf("%s algorithm provider shouldn't have 0 priority functions", pn)
		}
		for _, pf := range p.PriorityFunctionKeys.List() {
			if !factory.IsPriorityFunctionRegistered(pf) {
				t.Errorf("priority function %s is not registered but is used in the %s algorithm provider", pf, pn)
			}
		}
		for _, fp := range p.FitPredicateKeys.List() {
			if !factory.IsFitPredicateRegistered(fp) {
				t.Errorf("fit predicate %s is not registered but is used in the %s algorithm provider", fp, pn)
			}
		}
	}
}