/*
 * 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.
 */
package com.facebook.presto.router.spec;

import com.facebook.presto.router.scheduler.SchedulerType;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;

import java.util.HashSet;
import java.util.List;

import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;

public class RouterSpec
{
    private final List<GroupSpec> groups;
    private final List<SelectorRuleSpec> selectors;
    private final SchedulerType schedulerType;

    @JsonCreator
    public RouterSpec(
            @JsonProperty("groups") List<GroupSpec> groups,
            @JsonProperty("selectors") List<SelectorRuleSpec> selectors,
            @JsonProperty("scheduler") SchedulerType schedulerType)
    {
        this.groups = ImmutableList.copyOf(requireNonNull(groups, "groups is null"));
        this.selectors = ImmutableList.copyOf(requireNonNull(selectors, "selectors is null"));
        this.schedulerType = requireNonNull(schedulerType, "scheduler is null");

        // make sure no duplicate names in group definition
        checkArgument(groups.stream()
                .map(GroupSpec::getName)
                .allMatch(new HashSet<>()::add));
    }

    @JsonProperty
    public List<GroupSpec> getGroups()
    {
        return groups;
    }

    @JsonProperty
    public List<SelectorRuleSpec> getSelectors()
    {
        return selectors;
    }

    @JsonProperty
    public SchedulerType getSchedulerType()
    {
        return schedulerType;
    }
}

@@ -858,24 +858,104 @@
 util.List;%0A%0A
+import static com.facebook.presto.router.scheduler.SchedulerType.RANDOM_CHOICE;%0A
 import stati
@@ -1661,21 +1661,20 @@
         
-this.
+if (
 schedule
@@ -1684,60 +1684,148 @@
 pe =
- requireNonNull(schedulerType, %22scheduler is null%22);
+= null) %7B%0A            this.schedulerType = RANDOM_CHOICE;%0A        %7D%0A        else %7B%0A            this.schedulerType = schedulerType;%0A        %7D
 %0A%0A  

Set random choice as the default scheduler in the router