package com.cloudera.flume.master;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.cloudera.flume.conf.FlumeConfigData;
import com.cloudera.flume.conf.FlumeConfiguration;
import com.google.common.base.Preconditions;
import com.google.common.collect.Multimap;
static final Logger LOG = LoggerFactory.getLogger(MasterAdminServer.class);
final protected FlumeMaster master;
private RPCServer stubServer;
throws IOException {
Preconditions.checkArgument(master != null,
"FlumeConfigMaster is null in MasterAdminServer!");
this.master = master;
String rpcType = config.getMasterHeartbeatRPC();
this.stubServer = null;
if (FlumeConfiguration.RPC_TYPE_AVRO.equals(rpcType)) {
stubServer = new MasterAdminServerAvro(this);
} else if (FlumeConfiguration.RPC_TYPE_THRIFT.equals(rpcType)) {
stubServer = new MasterAdminServerThrift(this);
} else {
throw new IOException("No valid RPC framework specified in config");
}
}
return master.getCmdMan().isFailure(cmdid);
}
return master.getCmdMan().isSuccess(cmdid);
}
public long submit(Command command) {
return master.submit(command);
}
public void serve()
throws IOException {
this.stubServer.serve();
}
public void stop()
throws IOException {
this.stubServer.stop();
}
Map<String, StatusManager.NodeStatus> statuses = master.getStatMan()
.getNodeStatuses();
Map<String, StatusManager.NodeStatus> ret = new HashMap<String, StatusManager.NodeStatus>();
for (Entry<String, StatusManager.NodeStatus> e : statuses.entrySet()) {
ret.put(e.getKey(), e.getValue());
}
return ret;
}
public Map<String, FlumeConfigData>
getConfigs() {
return master.getSpecMan().getAllConfigs();
}
public Map<String, List<String>>
getMappings(String physicalNode) {
Map<String, List<String>> resultMap = new HashMap<String, List<String>>();
if (physicalNode != null) {
List<String> logicalNodes = master.getSpecMan().getLogicalNode(
physicalNode);
if (logicalNodes != null && logicalNodes.size() > 0) {
resultMap.put(physicalNode, master.getSpecMan().getLogicalNode(
physicalNode));
}
} else {
Multimap<String, String> m = master.getSpecMan().getLogicalNodeMap();
for (Entry<String, String> entry : m.entries()) {
if (!resultMap.containsKey(entry.getKey())) {
resultMap.put(entry.getKey(), new LinkedList<String>());
}
resultMap.get(entry.getKey()).add(entry.getValue());
}
}
return resultMap;
}
return master.getCmdMan().getStatus(cmdid) != null;
}
return master.getCmdMan().getStatus(cmdId);
}
}