<%doc>

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.
</%doc>
<%args>
HMaster master;
</%args>
<%import>
java.util.*;
org.apache.hadoop.hbase.ServerName;
org.apache.hadoop.hbase.ClusterStatus;
org.apache.hadoop.hbase.master.HMaster;
</%import>
<%java>
Collection<ServerName> masters = null;

if (master.isActiveMaster()) {
  ClusterStatus status = master.getClusterStatus();
  masters = status.getBackupMasters();
} else{
  ServerName sn = master.getMasterAddressTracker().getMasterAddress();
  assert sn != null : "Failed to retreive master's ServerName!";
  masters = Collections.singletonList(sn);
}
</%java>

<%java>
ServerName [] serverNames = masters.toArray(new ServerName[masters.size()]);
</%java>
<%if (!master.isActiveMaster()) %>
    <%if serverNames[0] != null %>
        <h2>Master</h2>
        <a href="//<% serverNames[0].getHostname() %>:<% master.getConfiguration().getInt("hbase.master.info.port", 60010) %>/master-status" target="_blank"><% serverNames[0].getHostname() %></a>
    <%else>
        Unable to parse master hostname.
    </%if>
<%else>
    <h2>Backup Masters</h2>

    <table class="table table-striped">
    <tr>
        <th>ServerName</th>
        <th>Port</th>
        <th>Start Time</th>
    </tr>
    <%java>
    Arrays.sort(serverNames);
    for (ServerName serverName : serverNames) {
    </%java>
    <tr>
        <td><a href="//<% serverName.getHostname() %>:<% master.getConfiguration().getInt("hbase.master.info.port", 60010) %>/master-status" target="_blank"><% serverName.getHostname() %></a></td>
        <td><% serverName.getPort() %></td>
        <td><% new Date(serverName.getStartcode()) %></td>
    </tr>
    <%java>
    }
    </%java>
    <tr><td>Total:<% (masters != null) ? masters.size() : 0 %></td>
    </table>
</%if>
