Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions ambari-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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.

<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions ambari-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,11 @@
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
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
Expand Up @@ -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;

Expand All @@ -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<HaHosts> haHosts;

/**
* Ordered collection of hosts. This represents all hosts where an upgrade
Expand All @@ -47,15 +49,118 @@ 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<>();

public boolean hasMasters() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javadoc for these methods would be helpful

return !getMasters().isEmpty();
}

public List<HaHosts> getHaHosts() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as below - maybe just call this getHighAvailabilityHosts() so there's no ambiguity. HaHosts is just kind of odd.

return haHosts;
}

/**
* 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 = getHaHosts().stream()
.flatMap(each -> Stream.concat(each.getSecondaries().stream(), Stream.of(each.getMaster())))
.collect(toCollection(LinkedHashSet::new));
}

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 HaHosts {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HaHosts is kind of a funny name - maybe just call it HighAvailabilityHosts

private final String master;
private final List<String> secondaries;

public HaHosts(String master, List<String> secondaries) {
if (master == null) {
throw new IllegalArgumentException("Master host is missing");
}
this.master = master;
this.secondaries = secondaries;
}

public String getMaster() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

return master;
}

public List<String> getSecondaries() {
return secondaries;
}
}

public static HostsType from(String master, String secondary, LinkedHashSet<String> hosts) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javadoc on these statics would be helpful

return master == null
? normal(hosts)
: new HostsType(singletonList(new HaHosts(master, secondary != null ? singletonList(secondary) : emptyList())), hosts);

}

public static HostsType highAvailability(String master, String secondary, LinkedHashSet<String> hosts) {
return new HostsType(singletonList(new HaHosts(master, singletonList(secondary))), hosts);
}

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 HaHosts(master, secondaries)), hosts);
}

public static HostsType federated(List<HaHosts> haHosts, LinkedHashSet<String> hosts) {
return new HostsType(haHosts, hosts);
}

public static HostsType normal(LinkedHashSet<String> hosts) {
return new HostsType(emptyList(), hosts);
}

public static HostsType normal(String... hosts) {
return new HostsType(emptyList(), new LinkedHashSet<>(asList(hosts)));
}

public static HostsType single(String host) {
return HostsType.normal(host);
}

private HostsType(List<HaHosts> haHosts, LinkedHashSet<String> hosts) {
this.haHosts = haHosts;
this.hosts = hosts;
}

public LinkedHashSet<String> getMasters() {
return haHosts.stream().map(each -> each.getMaster()).collect(toCollection(LinkedHashSet::new));
}

public LinkedHashSet<String> getSecondaries() {
return haHosts.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;
}
}
Loading