* @param catalog
* @param cc
* @return
*/
public static Catalog updateCatalog(Catalog catalog, ClusterConfiguration cc) {
Cluster catalog_clus = CatalogUtil.getCluster(catalog);
// Add a bunch of hosts and partitions to this mofo
assert (catalog_clus != null);
int host_id = HStoreConstants.FIRST_PARTITION_ID;
int partition_ctr = 0;
catalog_clus.getHosts().clear();
catalog_clus.getSites().clear();
for (String host : cc.getHosts()) {
if (LOCALHOST_TYPOS.contains(host)) {
String msg = String.format("POSSIBLE TYPO IN HOSTNAME '%s'. " +
"DID YOU MEAN 'localhost'?", host);
msg = StringBoxUtil.box(msg);
LOG.warn("");
for (String line : StringUtil.splitLines(msg)) {
LOG.warn(StringUtil.bold(line));
} // FOR
LOG.warn("");
}
String host_name = String.format("host%02d", host_id);
Host catalog_host = catalog_clus.getHosts().add(host_name);
assert (catalog_host != null);
catalog_host.setId(host_id);
catalog_host.setIpaddr(host);
LOG.debug("Created new host " + catalog_host + " on node '" + host + "'");
int proc_port = HStoreConstants.DEFAULT_PORT;
int messenger_port = proc_port + HStoreConstants.MESSENGER_PORT_OFFSET;
// Now create the sites for this host
for (Integer siteid : cc.getSites(host)) {
LOG.debug("Adding Site #" + siteid + " on " + host);
Site catalog_site = catalog_clus.getSites().add(siteid.toString());
assert (catalog_site != null);
catalog_site.setId(siteid);
catalog_site.setHost(catalog_host);
catalog_site.setProc_port(proc_port++);
catalog_site.setMessenger_port(messenger_port++);
// Add all the partitions
for (Integer partition_id : cc.getPartitionIds(host, siteid)) {
Partition catalog_part = catalog_site.getPartitions().add(partition_id.toString());
assert (catalog_part != null);
catalog_part.setId(partition_id);
partition_ctr++;
} // FOR
} // FOR
host_id++;
// LOG.debug("Added " + ctr + " partitions for " + catalog_host);
} // FOR
catalog_clus.setNum_partitions(partition_ctr);
LOG.info(String.format("Updated host information in catalog with %d host%s and %d partitions",
catalog_clus.getHosts().size(),
(catalog_clus.getHosts().size() > 1 ? "s" : ""),
partition_ctr));
return (catalog);
}