use of java.util.regex.Matcher in project hbase by apache.
the class WALSplitter method getSplitEditFilesSorted.
/**
* Returns sorted set of edit files made by splitter, excluding files
* with '.temp' suffix.
*
* @param fs
* @param regiondir
* @return Files in passed <code>regiondir</code> as a sorted set.
* @throws IOException
*/
public static NavigableSet<Path> getSplitEditFilesSorted(final FileSystem fs, final Path regiondir) throws IOException {
NavigableSet<Path> filesSorted = new TreeSet<>();
Path editsdir = getRegionDirRecoveredEditsDir(regiondir);
if (!fs.exists(editsdir))
return filesSorted;
FileStatus[] files = FSUtils.listStatus(fs, editsdir, new PathFilter() {
@Override
public boolean accept(Path p) {
boolean result = false;
try {
// Return files and only files that match the editfile names pattern.
// There can be other files in this directory other than edit files.
// In particular, on error, we'll move aside the bad edit file giving
// it a timestamp suffix. See moveAsideBadEditsFile.
Matcher m = EDITFILES_NAME_PATTERN.matcher(p.getName());
result = fs.isFile(p) && m.matches();
// because it means splitwal thread is writting this file.
if (p.getName().endsWith(RECOVERED_LOG_TMPFILE_SUFFIX)) {
result = false;
}
// Skip SeqId Files
if (isSequenceIdFile(p)) {
result = false;
}
} catch (IOException e) {
LOG.warn("Failed isFile check on " + p);
}
return result;
}
});
if (files == null) {
return filesSorted;
}
for (FileStatus status : files) {
filesSorted.add(status.getPath());
}
return filesSorted;
}
use of java.util.regex.Matcher in project hbase by apache.
the class CoprocessorWhitelistMasterObserver method verifyCoprocessors.
/**
* Perform the validation checks for a coprocessor to determine if the path
* is white listed or not.
* @throws IOException if path is not included in whitelist or a failure
* occurs in processing
* @param ctx as passed in from the coprocessor
* @param htd as passed in from the coprocessor
*/
private void verifyCoprocessors(ObserverContext<MasterCoprocessorEnvironment> ctx, HTableDescriptor htd) throws IOException {
MasterServices services = ctx.getEnvironment().getMasterServices();
Configuration conf = services.getConfiguration();
Collection<String> paths = conf.getStringCollection(CP_COPROCESSOR_WHITELIST_PATHS_KEY);
List<String> coprocs = htd.getCoprocessors();
for (int i = 0; i < coprocs.size(); i++) {
String coproc = coprocs.get(i);
String coprocSpec = Bytes.toString(htd.getValue(Bytes.toBytes("coprocessor$" + (i + 1))));
if (coprocSpec == null) {
continue;
}
// File path is the 1st field of the coprocessor spec
Matcher matcher = HConstants.CP_HTD_ATTR_VALUE_PATTERN.matcher(coprocSpec);
if (matcher == null || !matcher.matches()) {
continue;
}
String coprocPathStr = matcher.group(1).trim();
// Check if coprocessor is being loaded via the classpath (i.e. no file path)
if (coprocPathStr.equals("")) {
break;
}
Path coprocPath = new Path(coprocPathStr);
String coprocessorClass = matcher.group(2).trim();
boolean foundPathMatch = false;
for (String pathStr : paths) {
Path wlPath = new Path(pathStr);
try {
foundPathMatch = validatePath(coprocPath, wlPath, conf);
if (foundPathMatch == true) {
LOG.debug(String.format("Coprocessor %s found in directory %s", coprocessorClass, pathStr));
break;
}
} catch (IOException e) {
LOG.warn(String.format("Failed to validate white list path %s for coprocessor path %s", pathStr, coprocPathStr));
}
}
if (!foundPathMatch) {
throw new IOException(String.format("Loading %s DENIED in %s", coprocessorClass, CP_COPROCESSOR_WHITELIST_PATHS_KEY));
}
}
}
use of java.util.regex.Matcher in project hive by apache.
the class QTestUtil method normalizeNames.
public void normalizeNames(File path) throws Exception {
if (path.isDirectory()) {
File[] files = path.listFiles();
for (File file : files) {
normalizeNames(file);
}
} else {
Matcher m = reduceTok.matcher(path.getName());
if (m.matches()) {
String name = m.group(1) + "reduce" + m.group(3);
path.renameTo(new File(path.getParent(), name));
} else {
m = mapTok.matcher(path.getName());
if (m.matches()) {
String name = m.group(1) + "map_" + m.group(3);
path.renameTo(new File(path.getParent(), name));
}
}
}
}
use of java.util.regex.Matcher in project hive by apache.
the class QTestUtil method checkNeedJavaSpecificOutput.
private boolean checkNeedJavaSpecificOutput(String fileName, String query) {
Pattern pattern = Pattern.compile("-- JAVA_VERSION_SPECIFIC_OUTPUT");
Matcher matcher = pattern.matcher(query);
if (matcher.find()) {
System.out.println("Test is flagged to generate Java version specific " + "output. Since we are using Java version " + javaVersion + ", we will generated Java " + javaVersion + " specific " + "output file for query file " + fileName);
return true;
}
return false;
}
use of java.util.regex.Matcher in project zeppelin by apache.
the class LensInterpreter method getProgress.
@Override
public int getProgress(InterpreterContext context) {
if (s_paraToQH.containsKey(context.getParagraphId())) {
s_logger.info("number of items for which progress can be reported :" + s_paraToQH.size());
s_logger.info("number of open lensclient :" + s_clientMap.size());
Bootstrap bs = createBootstrap();
JLineShell shell = getJLineShell(bs);
LensClient lensClient = null;
String qh = s_paraToQH.get(context.getParagraphId()).getQueryHandle();
try {
s_logger.info("fetch query status for : (" + context.getParagraphId() + ") :" + qh);
lensClient = createAndSetLensClient(bs);
s_clientMap.put(lensClient, true);
CommandResult res = shell.executeCommand("query status " + qh);
s_logger.info(context.getParagraphId() + " --> " + res.getResult().toString());
//change to debug
Pattern pattern = Pattern.compile(".*(Progress : (\\d\\.\\d)).*");
Matcher matcher = pattern.matcher(res.getResult().toString().replaceAll("\\n", " "));
if (matcher.find(2)) {
Double d = Double.parseDouble(matcher.group(2)) * 100;
if (d.intValue() == 100) {
s_paraToQH.remove(context.getParagraphId());
}
return d.intValue();
} else {
return 1;
}
} catch (Exception e) {
s_logger.error("unable to get progress for (" + context.getParagraphId() + ") :" + qh, e);
s_paraToQH.remove(context.getParagraphId());
return 0;
} finally {
if (lensClient != null) {
closeLensClient(lensClient);
s_clientMap.remove(lensClient);
}
if (shell != null) {
closeShell(shell);
}
}
}
return 0;
}
Aggregations