-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[AMBARI-22913]. Add ability to MasterHostResolver to resolve by namespa… #269
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * | ||
| * * Licensed to the Apache Software Foundation (ASF) under one | ||
| * * or more contributor license agreements. See the NOTICE file | ||
| * * distributed with this work for additional information | ||
| * * regarding copyright ownership. The ASF licenses this file | ||
| * * to you 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 org.apache.ambari.server.stack; | ||
|
|
||
| public class ClassifyNameNodeException extends RuntimeException { | ||
| public ClassifyNameNodeException(NameService nameService) { | ||
| super("Could not classify some of the NameNodes in namespace: " + nameService.nameServiceId); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,17 @@ | |
|
|
||
| package org.apache.ambari.server.stack; | ||
|
|
||
| import static java.util.Arrays.asList; | ||
| import static java.util.Collections.emptyList; | ||
| import static java.util.Collections.singletonList; | ||
| import static java.util.stream.Collectors.toCollection; | ||
| import static java.util.stream.Collectors.toList; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import org.apache.ambari.server.state.ServiceComponentHost; | ||
|
|
||
|
|
@@ -29,16 +37,10 @@ | |
| * also have master/secondary designators. | ||
| */ | ||
| public class HostsType { | ||
|
|
||
| /** | ||
| * The master host, if any. | ||
| */ | ||
| public String master = null; | ||
|
|
||
| /** | ||
| * The secondary host, if any. | ||
| * List of HA hosts (master - secondaries pairs), if any. | ||
| */ | ||
| public String secondary = null; | ||
| private final List<HighAvailabilityHosts> highAvailabilityHosts; | ||
|
|
||
| /** | ||
| * Ordered collection of hosts. This represents all hosts where an upgrade | ||
|
|
@@ -47,15 +49,145 @@ public class HostsType { | |
| * That is to say, a downgrade only occurs where the current version is not | ||
| * the target version. | ||
| */ | ||
| public LinkedHashSet<String> hosts = new LinkedHashSet<>(); | ||
| private LinkedHashSet<String> hosts; | ||
|
|
||
| /** | ||
| * Unhealthy hosts are those which are explicitely put into maintenance mode. | ||
| * Unhealthy hosts are those which are explicitly put into maintenance mode. | ||
| * If there is a host which is not heartbeating (or is generally unhealthy) | ||
| * but not in maintenance mode, then the prerequisite upgrade checks will let | ||
| * the administrator know that it must be put into maintenance mode before an | ||
| * upgrade can begin. | ||
| */ | ||
| public List<ServiceComponentHost> unhealthy = new ArrayList<>(); | ||
|
|
||
| /** | ||
| * @return true if master components list is not empty | ||
| */ | ||
| public boolean hasMasters() { | ||
| return !getMasters().isEmpty(); | ||
| } | ||
|
|
||
| public List<HighAvailabilityHosts> getHighAvailabilityHosts() { | ||
| return highAvailabilityHosts; | ||
| } | ||
|
|
||
| /** | ||
| * Order the hosts so that for each HA host the secondaries come first. | ||
| * For example: [sec1, sec2, master1, sec3, sec4, master2] | ||
| */ | ||
| public void arrangeHostSecondariesFirst() { | ||
| this.hosts = getHighAvailabilityHosts().stream() | ||
| .flatMap(each -> Stream.concat(each.getSecondaries().stream(), Stream.of(each.getMaster()))) | ||
| .collect(toCollection(LinkedHashSet::new)); | ||
| } | ||
|
|
||
| /** | ||
| * @return true if both master and secondary components lists are not empty | ||
| */ | ||
| public boolean hasMastersAndSecondaries() { | ||
| return !getMasters().isEmpty() && !getSecondaries().isEmpty(); | ||
| } | ||
|
|
||
| /** | ||
| * A master and secondary host(s). In HA mode there is one master and one secondary host, | ||
| * in federated mode there can be more than one secondaries. | ||
| */ | ||
| public static class HighAvailabilityHosts { | ||
| private final String master; | ||
| private final List<String> secondaries; | ||
|
|
||
| public HighAvailabilityHosts(String master, List<String> secondaries) { | ||
| if (master == null) { | ||
| throw new IllegalArgumentException("Master host is missing"); | ||
| } | ||
| this.master = master; | ||
| this.secondaries = secondaries; | ||
| } | ||
|
|
||
| public String getMaster() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible that in an "HA" setup, there could potentially be multiple masters? Should we plan for that? We should try to make this class as non-HDFS specific as possible. In fact, we shouldn't use any HDFS terms in here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's possible and the user can use our REST API or the config editor on the UI to create such setup, even if our wizards don't support it. The 1 master + 1 secondary setup is a special case of the more general multiple master+secondaries setup.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So do you think that we'd need to account for that here then by having the Masters also be a collection.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I think that would be speculative generality. We might or might not need that in the future, but we already need to have multiple secondaries.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. |
||
| return master; | ||
| } | ||
|
|
||
| public List<String> getSecondaries() { | ||
| return secondaries; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Creates an instance from the optional master and secondary components and with the given host set | ||
| */ | ||
| public static HostsType from(String master, String secondary, LinkedHashSet<String> hosts) { | ||
| return master == null | ||
| ? normal(hosts) | ||
| : new HostsType(singletonList(new HighAvailabilityHosts(master, secondary != null ? singletonList(secondary) : emptyList())), hosts); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Create an instance with exactly one high availability host (master-secondary pair) and with the given host set | ||
| */ | ||
| public static HostsType highAvailability(String master, String secondary, LinkedHashSet<String> hosts) { | ||
| return new HostsType(singletonList(new HighAvailabilityHosts(master, singletonList(secondary))), hosts); | ||
| } | ||
|
|
||
| /** | ||
| * Create an instance with an arbitrary chosen high availability host. | ||
| */ | ||
| public static HostsType guessHighAvailability(LinkedHashSet<String> hosts) { | ||
| if (hosts.isEmpty()) { | ||
| throw new IllegalArgumentException("Cannot guess HA, empty hosts."); | ||
| } | ||
| String master = hosts.iterator().next(); | ||
| List<String> secondaries = hosts.stream().skip(1).collect(toList()); | ||
| return new HostsType(singletonList(new HighAvailabilityHosts(master, secondaries)), hosts); | ||
| } | ||
|
|
||
| /** | ||
| * Create an instance with multiple high availability hosts. | ||
| */ | ||
| public static HostsType federated(List<HighAvailabilityHosts> highAvailabilityHosts, LinkedHashSet<String> hosts) { | ||
| return new HostsType(highAvailabilityHosts, hosts); | ||
| } | ||
|
|
||
| /** | ||
| * Create an instance without high availability hosts. | ||
| */ | ||
| public static HostsType normal(LinkedHashSet<String> hosts) { | ||
| return new HostsType(emptyList(), hosts); | ||
| } | ||
|
|
||
| /** | ||
| * Create an instance without high availability hosts. | ||
| */ | ||
| public static HostsType normal(String... hosts) { | ||
| return new HostsType(emptyList(), new LinkedHashSet<>(asList(hosts))); | ||
| } | ||
|
|
||
| /** | ||
| * Create an instance with a single (non high availability) host. | ||
| */ | ||
| public static HostsType single(String host) { | ||
| return HostsType.normal(host); | ||
| } | ||
|
|
||
| private HostsType(List<HighAvailabilityHosts> highAvailabilityHosts, LinkedHashSet<String> hosts) { | ||
| this.highAvailabilityHosts = highAvailabilityHosts; | ||
| this.hosts = hosts; | ||
| } | ||
|
|
||
| public LinkedHashSet<String> getMasters() { | ||
| return highAvailabilityHosts.stream().map(each -> each.getMaster()).collect(toCollection(LinkedHashSet::new)); | ||
| } | ||
|
|
||
| public LinkedHashSet<String> getSecondaries() { | ||
| return highAvailabilityHosts.stream().flatMap(each -> each.getSecondaries().stream()).collect(toCollection(LinkedHashSet::new)); | ||
| } | ||
|
|
||
| public Set<String> getHosts() { | ||
| return hosts; | ||
| } | ||
|
|
||
| public void setHosts(LinkedHashSet<String> hosts) { | ||
| this.hosts = hosts; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this BSD license is compatible. Just wanted to mention it for a double-check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's BSD, also used in logsearch.