Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move network topology location segment names to config
- Loading branch information
Showing
8 changed files
with
123 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...-main/src/main/java/io/prestosql/execution/scheduler/TopologyAwareNodeSelectorConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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 io.prestosql.execution.scheduler; | ||
|
||
import com.google.common.base.Splitter; | ||
import com.google.common.collect.ImmutableList; | ||
import io.airlift.configuration.Config; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class TopologyAwareNodeSelectorConfig | ||
{ | ||
private List<String> locationSegmentNames = ImmutableList.of("machine"); | ||
|
||
@NotNull | ||
public List<String> getLocationSegmentNames() | ||
{ | ||
return locationSegmentNames; | ||
} | ||
|
||
public TopologyAwareNodeSelectorConfig setLocationSegmentNames(List<String> locationSegmentNames) | ||
{ | ||
this.locationSegmentNames = requireNonNull(locationSegmentNames, "locationSegmentNames is null"); | ||
return this; | ||
} | ||
|
||
@Config("node-scheduler.network-topology-segments") | ||
public TopologyAwareNodeSelectorConfig setLocationSegmentNames(String locationSegmentNames) | ||
{ | ||
this.locationSegmentNames = Splitter.on(",") | ||
.trimResults() | ||
.omitEmptyStrings() | ||
.splitToList(locationSegmentNames); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...n/src/test/java/io/prestosql/execution/scheduler/TestTopologyAwareNodeSelectorConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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 io.prestosql.execution.scheduler; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import io.airlift.configuration.testing.ConfigAssertions; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.Map; | ||
|
||
public class TestTopologyAwareNodeSelectorConfig | ||
{ | ||
@Test | ||
public void testDefaults() | ||
{ | ||
ConfigAssertions.assertRecordedDefaults(ConfigAssertions.recordDefaults(TopologyAwareNodeSelectorConfig.class) | ||
.setLocationSegmentNames("machine")); | ||
} | ||
|
||
@Test | ||
public void testExplicitPropertyMappings() | ||
{ | ||
Map<String, String> properties = new ImmutableMap.Builder<String, String>() | ||
.put("node-scheduler.network-topology-segments", "rack,machine") | ||
.build(); | ||
|
||
TopologyAwareNodeSelectorConfig expected = new TopologyAwareNodeSelectorConfig() | ||
.setLocationSegmentNames(ImmutableList.of("rack", "machine")); | ||
|
||
ConfigAssertions.assertFullMapping(properties, expected); | ||
} | ||
} |