use of alluxio.exception.status.InvalidArgumentException in project alluxio by Alluxio.
the class CapacityCommand method getOptions.
/**
* Gets the worker info options.
*
* @param cl CommandLine that contains the client options
* @return GetWorkerReportOptions to get worker information
*/
private GetWorkerReportOptions getOptions(CommandLine cl) throws IOException {
if (cl.getOptions().length > 1) {
System.out.println(getUsage());
throw new InvalidArgumentException("Too many arguments passed in.");
}
GetWorkerReportOptions workerOptions = GetWorkerReportOptions.defaults();
Set<WorkerInfoField> fieldRange = new HashSet<>(Arrays.asList(WorkerInfoField.ADDRESS, WorkerInfoField.WORKER_CAPACITY_BYTES, WorkerInfoField.WORKER_CAPACITY_BYTES_ON_TIERS, WorkerInfoField.LAST_CONTACT_SEC, WorkerInfoField.WORKER_USED_BYTES, WorkerInfoField.WORKER_USED_BYTES_ON_TIERS));
workerOptions.setFieldRange(fieldRange);
if (cl.hasOption(ReportCommand.LIVE_OPTION_NAME)) {
workerOptions.setWorkerRange(WorkerRange.LIVE);
} else if (cl.hasOption(ReportCommand.LOST_OPTION_NAME)) {
workerOptions.setWorkerRange(WorkerRange.LOST);
} else if (cl.hasOption(ReportCommand.SPECIFIED_OPTION_NAME)) {
workerOptions.setWorkerRange(WorkerRange.SPECIFIED);
String addressString = cl.getOptionValue(ReportCommand.SPECIFIED_OPTION_NAME);
String[] addressArray = addressString.split(",");
// Addresses in GetWorkerReportOptions is only used when WorkerRange is SPECIFIED
workerOptions.setAddresses(new HashSet<>(Arrays.asList(addressArray)));
}
return workerOptions;
}
use of alluxio.exception.status.InvalidArgumentException in project alluxio by Alluxio.
the class CancelCommand method validateArgs.
@Override
public void validateArgs(CommandLine cl) throws InvalidArgumentException {
CommandUtils.checkNumOfArgsEquals(this, cl, 1);
String arg = cl.getArgs()[0];
try {
Long.parseLong(arg);
} catch (Exception e) {
throw new InvalidArgumentException(ExceptionMessage.INVALID_ARG_TYPE.getMessage(arg, "long"));
}
}
use of alluxio.exception.status.InvalidArgumentException in project alluxio by Alluxio.
the class QuorumCommand method stringToAddress.
/**
* @param serverAddress the string containing the hostname and port separated by a ':
* @return a NetAddress object composed of a hostname and a port
* @throws InvalidArgumentException
*/
public static NetAddress stringToAddress(String serverAddress) throws InvalidArgumentException {
String hostName;
int port;
try {
hostName = serverAddress.substring(0, serverAddress.indexOf(":"));
port = Integer.parseInt(serverAddress.substring(serverAddress.indexOf(":") + 1));
} catch (Exception e) {
throw new InvalidArgumentException(ExceptionMessage.INVALID_ADDRESS_VALUE.getMessage());
}
return NetAddress.newBuilder().setHost(hostName).setRpcPort(port).build();
}
use of alluxio.exception.status.InvalidArgumentException in project alluxio by Alluxio.
the class QuorumInfoCommand method run.
@Override
public int run(CommandLine cl) throws IOException {
JournalMasterClient jmClient = mMasterJournalMasterClient;
String domainVal = cl.getOptionValue(DOMAIN_OPTION_NAME);
try {
JournalDomain domain = JournalDomain.valueOf(domainVal);
if (domain == JournalDomain.JOB_MASTER) {
jmClient = mJobMasterJournalMasterClient;
}
} catch (IllegalArgumentException e) {
throw new InvalidArgumentException(ExceptionMessage.INVALID_OPTION_VALUE.getMessage(DOMAIN_OPTION_NAME, Arrays.toString(JournalDomain.values())));
}
GetQuorumInfoPResponse quorumInfo = jmClient.getQuorumInfo();
Optional<QuorumServerInfo> leadingMasterInfoOpt = quorumInfo.getServerInfoList().stream().filter(QuorumServerInfo::getIsLeader).findFirst();
String leadingMasterAddr = leadingMasterInfoOpt.isPresent() ? netAddressToString(leadingMasterInfoOpt.get().getServerAddress()) : "UNKNOWN";
List<String[]> table = quorumInfo.getServerInfoList().stream().map(info -> new String[] { info.getServerState().toString(), Integer.toString(info.getPriority()), netAddressToString(info.getServerAddress()) }).collect(Collectors.toList());
table.add(0, new String[] { "STATE", "PRIORITY", "SERVER ADDRESS" });
mPrintStream.println(String.format(OUTPUT_HEADER_DOMAIN, quorumInfo.getDomain()));
mPrintStream.println(String.format(OUTPUT_HEADER_QUORUM_SIZE, quorumInfo.getServerInfoList().size()));
mPrintStream.println(String.format(OUTPUT_HEADER_LEADING_MASTER, leadingMasterAddr));
mPrintStream.println();
for (String[] output : table) {
mPrintStream.printf(OUTPUT_SERVER_INFO, output);
}
return 0;
}
use of alluxio.exception.status.InvalidArgumentException in project alluxio by Alluxio.
the class GetBlockInfoCommand method run.
@Override
public int run(CommandLine cl) throws IOException {
if (cl.hasOption(HELP_OPTION_NAME)) {
System.out.println(getUsage());
System.out.println(getDescription());
return 0;
}
FileSystemAdminShellUtils.checkMasterClientService(mConf);
long blockId;
String arg = cl.getArgs()[0];
try {
blockId = Long.parseLong(arg);
} catch (NumberFormatException e) {
throw new InvalidArgumentException(arg + " is not a valid block id.");
}
BlockInfo info = null;
try {
info = mBlockClient.getBlockInfo(blockId);
} catch (Exception e) {
// ignore
}
long fileId = BlockId.getFileId(blockId);
String path = null;
try {
path = mFsClient.getFilePath(fileId);
} catch (Exception e) {
// ignore
}
if (info != null) {
System.out.println(info);
} else {
System.out.println("BlockMeta is not available for blockId: " + blockId);
}
if (path != null) {
System.out.printf("This block belongs to file {id=%s, path=%s}%n", fileId, path);
} else {
System.out.printf("This block belongs to file {id=%s}%n", fileId);
}
return 0;
}
Aggregations