@Test public void testAssigns() throws IOException { try (Admin admin = TEST_UTIL.getConnection().getAdmin()) { List<RegionInfo> regions = admin.getRegions(TABLE_NAME); for (RegionInfo ri: regions) { RegionState rs = TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager(). getRegionStates().getRegionState(ri.getEncodedName()); LOG.info("RS: {}", rs.toString()); } String [] regionStrsArray = regions.stream().map(RegionInfo::getEncodedName).toArray(String[]::new); try (ClusterConnection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) { unassigns(regions, regionStrsArray); List<Long> pids = this.hbck2.assigns(hbck, regionStrsArray); waitOnPids(pids); validateOpen(regions); pids = this.hbck2.assigns(hbck, Arrays.stream(new String[]{"a", "some rubbish name"}). collect(Collectors.toList()).toArray(new String[]{})); for (long pid : pids) { assertEquals(org.apache.hadoop.hbase.procedure2.Procedure.NO_PROC_ID, pid); } unassigns(regions, regionStrsArray); File testFile = new File(TEST_UTIL.getDataTestDir().toString(), "inputForAssignsTest"); try (FileOutputStream output = new FileOutputStream(testFile, false)) { for (String regionStr : regionStrsArray) { output.write((regionStr + System.lineSeparator()).getBytes()); } } String result = testRunWithArgs(new String[]{ASSIGNS, "-i", testFile.toString()}); Scanner scanner = new Scanner(result).useDelimiter("[\\D]+"); pids = new ArrayList<>(); while (scanner.hasNext()) { pids.add(scanner.nextLong()); } scanner.close(); waitOnPids(pids); validateOpen(regions); } } }
List<Long> assigns(Hbck hbck, String[] args) throws IOException { Options options = new Options(); Option override = Option.builder("o").longOpt("override").build(); Option inputFile = Option.builder("i").longOpt("inputFiles").build(); options.addOption(override); options.addOption(inputFile); CommandLineParser parser = new DefaultParser(); CommandLine commandLine; try { commandLine = parser.parse(options, args, false); } catch (ParseException e) { showErrorMessage(e.getMessage()); return null; } boolean overrideFlag = commandLine.hasOption(override.getOpt()); List<String> argList = commandLine.getArgList(); if (!commandLine.hasOption(inputFile.getOpt())) { return hbck.assigns(argList, overrideFlag); } List<String> assignmentList = new ArrayList<>(); for (String filePath : argList) { try (InputStream fileStream = new FileInputStream(filePath)){ LineIterator it = IOUtils.lineIterator(fileStream, "UTF-8"); while (it.hasNext()) { assignmentList.add(it.nextLine().trim()); } } } return hbck.assigns(assignmentList, overrideFlag); }
HBCK2 extends Configured implements org.apache.hadoop.util.Tool { List<Long> assigns(Hbck hbck, String[] args) throws IOException { Options options = new Options(); Option override = Option.builder("o").longOpt("override").build(); Option inputFile = Option.builder("i").longOpt("inputFiles").build(); options.addOption(override); options.addOption(inputFile); CommandLineParser parser = new DefaultParser(); CommandLine commandLine; try { commandLine = parser.parse(options, args, false); } catch (ParseException e) { showErrorMessage(e.getMessage()); return null; } boolean overrideFlag = commandLine.hasOption(override.getOpt()); List<String> argList = commandLine.getArgList(); if (!commandLine.hasOption(inputFile.getOpt())) { return hbck.assigns(argList, overrideFlag); } List<String> assignmentList = new ArrayList<>(); for (String filePath : argList) { try (InputStream fileStream = new FileInputStream(filePath)){ LineIterator it = IOUtils.lineIterator(fileStream, "UTF-8"); while (it.hasNext()) { assignmentList.add(it.nextLine().trim()); } } } return hbck.assigns(assignmentList, overrideFlag); } }
HBCK2 extends Configured implements org.apache.hadoop.util.Tool { List<Long> assigns(Hbck hbck, String[] args) throws IOException { Options options = new Options(); Option override = Option.builder("o").longOpt("override").build(); Option inputFile = Option.builder("i").longOpt("inputFiles").build(); options.addOption(override); options.addOption(inputFile); CommandLineParser parser = new DefaultParser(); CommandLine commandLine; try { commandLine = parser.parse(options, args, false); } catch (ParseException e) { showErrorMessage(e.getMessage()); return null; } boolean overrideFlag = commandLine.hasOption(override.getOpt()); List<String> argList = commandLine.getArgList(); if (!commandLine.hasOption(inputFile.getOpt())) { return hbck.assigns(argList, overrideFlag); } List<String> assignmentList = new ArrayList<>(); for (String filePath : argList) { try (InputStream fileStream = new FileInputStream(filePath)){ LineIterator it = IOUtils.lineIterator(fileStream, "UTF-8"); while (it.hasNext()) { assignmentList.add(it.nextLine().trim()); } } } return hbck.assigns(assignmentList, overrideFlag); } HBCK2(Configuration conf); }
HBCK2 extends Configured implements org.apache.hadoop.util.Tool { List<Long> assigns(Hbck hbck, String[] args) throws IOException { Options options = new Options(); Option override = Option.builder("o").longOpt("override").build(); Option inputFile = Option.builder("i").longOpt("inputFiles").build(); options.addOption(override); options.addOption(inputFile); CommandLineParser parser = new DefaultParser(); CommandLine commandLine; try { commandLine = parser.parse(options, args, false); } catch (ParseException e) { showErrorMessage(e.getMessage()); return null; } boolean overrideFlag = commandLine.hasOption(override.getOpt()); List<String> argList = commandLine.getArgList(); if (!commandLine.hasOption(inputFile.getOpt())) { return hbck.assigns(argList, overrideFlag); } List<String> assignmentList = new ArrayList<>(); for (String filePath : argList) { try (InputStream fileStream = new FileInputStream(filePath)){ LineIterator it = IOUtils.lineIterator(fileStream, "UTF-8"); while (it.hasNext()) { assignmentList.add(it.nextLine().trim()); } } } return hbck.assigns(assignmentList, overrideFlag); } HBCK2(Configuration conf); @Override void setConf(Configuration configuration); @Override Configuration getConf(); @Override int run(String[] args); static void main(String [] args); }
HBCK2 extends Configured implements org.apache.hadoop.util.Tool { List<Long> assigns(Hbck hbck, String[] args) throws IOException { Options options = new Options(); Option override = Option.builder("o").longOpt("override").build(); Option inputFile = Option.builder("i").longOpt("inputFiles").build(); options.addOption(override); options.addOption(inputFile); CommandLineParser parser = new DefaultParser(); CommandLine commandLine; try { commandLine = parser.parse(options, args, false); } catch (ParseException e) { showErrorMessage(e.getMessage()); return null; } boolean overrideFlag = commandLine.hasOption(override.getOpt()); List<String> argList = commandLine.getArgList(); if (!commandLine.hasOption(inputFile.getOpt())) { return hbck.assigns(argList, overrideFlag); } List<String> assignmentList = new ArrayList<>(); for (String filePath : argList) { try (InputStream fileStream = new FileInputStream(filePath)){ LineIterator it = IOUtils.lineIterator(fileStream, "UTF-8"); while (it.hasNext()) { assignmentList.add(it.nextLine().trim()); } } } return hbck.assigns(assignmentList, overrideFlag); } HBCK2(Configuration conf); @Override void setConf(Configuration configuration); @Override Configuration getConf(); @Override int run(String[] args); static void main(String [] args);  }