Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
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<HighAvailabilityHosts> highAvailabilityHosts;

/**
* Ordered collection of hosts. This represents all hosts where an upgrade
Expand All @@ -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() {
Copy link
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
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
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
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
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;
}
}

/**
* 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;
}
}
Loading