use of com.google.common.base.Predicate in project cdap by caskdata.
the class ExplodeJarHttpHandler method init.
@Override
public void init(HandlerContext context) {
super.init(context);
// Setup program jar for serving
try {
File jarFile = new File(jarLocation.toURI());
baseDir = Files.createTempDir();
cannonicalBaseDir = baseDir.getCanonicalPath();
int numFiles = JarExploder.explode(jarFile, baseDir, EXPLODE_FILTER);
File serveDir = new File(baseDir, Constants.Webapp.WEBAPP_DIR);
Predicate<String> fileExists = new Predicate<String>() {
@Override
public boolean apply(@Nullable String file) {
return file != null && new File(file).exists();
}
};
servePathGenerator = new ServePathGenerator(serveDir.getAbsolutePath(), fileExists);
LOG.info("Exploded {} files from jar {}", numFiles, jarFile.getAbsolutePath());
} catch (Throwable t) {
LOG.error("Got exception: ", t);
throw Throwables.propagate(t);
}
}
use of com.google.common.base.Predicate in project cdap by caskdata.
the class IntactJarHttpHandler method init.
@Override
public void init(HandlerContext context) {
super.init(context);
try {
jarFile = new JarFile(new File(jarLocation.toURI()));
Predicate<String> fileExists = new Predicate<String>() {
@Override
public boolean apply(String file) {
return file != null && jarFile.getJarEntry(file) != null;
}
};
servePathGenerator = new ServePathGenerator(Constants.Webapp.WEBAPP_DIR, fileExists);
} catch (IOException e) {
LOG.error("Got exception: ", e);
throw Throwables.propagate(e);
}
}
use of com.google.common.base.Predicate in project hbase by apache.
the class NamespaceTableCfWALEntryFilter method filterCell.
@Override
public Cell filterCell(final Entry entry, Cell cell) {
final Map<TableName, List<String>> tableCfs = getTableCfs();
if (tableCfs == null)
return cell;
TableName tabName = entry.getKey().getTablename();
List<String> cfs = tableCfs.get(tabName);
// (empty cfs means all cfs of this table are replicable)
if (CellUtil.matchingColumn(cell, WALEdit.METAFAMILY, WALEdit.BULK_LOAD)) {
cell = bulkLoadFilter.filterCell(cell, new Predicate<byte[]>() {
@Override
public boolean apply(byte[] fam) {
if (tableCfs != null) {
List<String> cfs = tableCfs.get(entry.getKey().getTablename());
if (cfs != null && !cfs.contains(Bytes.toString(fam))) {
return true;
}
}
return false;
}
});
} else {
if ((cfs != null) && !cfs.contains(Bytes.toString(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength()))) {
return null;
}
}
return cell;
}
use of com.google.common.base.Predicate in project cassandra by apache.
the class TrackerTest method testApply.
@Test
public void testApply() {
final ColumnFamilyStore cfs = MockSchema.newCFS();
final Tracker tracker = new Tracker(null, false);
final View resultView = ViewTest.fakeView(0, 0, cfs);
final AtomicInteger count = new AtomicInteger();
tracker.apply(new Predicate<View>() {
public boolean apply(View view) {
// confound the CAS by swapping the view, and check we retry
if (count.incrementAndGet() < 3)
tracker.view.set(ViewTest.fakeView(0, 0, cfs));
return true;
}
}, new Function<View, View>() {
@Nullable
public View apply(View view) {
return resultView;
}
});
Assert.assertEquals(3, count.get());
Assert.assertEquals(resultView, tracker.getView());
count.set(0);
// check that if the predicate returns false, we stop immediately and return null
Assert.assertNull(tracker.apply(new Predicate<View>() {
public boolean apply(View view) {
count.incrementAndGet();
return false;
}
}, null));
Assert.assertEquals(1, count.get());
Assert.assertEquals(resultView, tracker.getView());
}
use of com.google.common.base.Predicate in project cassandra by apache.
the class CassandraAuthorizer method convertLegacyData.
/**
* Copy legacy authz data from the system_auth.permissions table to the new system_auth.role_permissions table and
* also insert entries into the reverse lookup table.
* In theory, we could simply rename the existing table as the schema is structurally the same, but this would
* break mixed clusters during a rolling upgrade.
* This setup is not performed if AllowAllAuthenticator is configured (see Auth#setup).
*/
private void convertLegacyData() {
try {
if (Schema.instance.getTableMetadata("system_auth", "permissions") != null) {
logger.info("Converting legacy permissions data");
CQLStatement insertStatement = QueryProcessor.getStatement(String.format("INSERT INTO %s.%s (role, resource, permissions) " + "VALUES (?, ?, ?)", SchemaConstants.AUTH_KEYSPACE_NAME, AuthKeyspace.ROLE_PERMISSIONS), ClientState.forInternalCalls()).statement;
CQLStatement indexStatement = QueryProcessor.getStatement(String.format("INSERT INTO %s.%s (resource, role) VALUES (?,?)", SchemaConstants.AUTH_KEYSPACE_NAME, AuthKeyspace.RESOURCE_ROLE_INDEX), ClientState.forInternalCalls()).statement;
UntypedResultSet permissions = process("SELECT * FROM system_auth.permissions");
for (UntypedResultSet.Row row : permissions) {
final IResource resource = Resources.fromName(row.getString("resource"));
Predicate<String> isApplicable = new Predicate<String>() {
public boolean apply(String s) {
return resource.applicablePermissions().contains(Permission.valueOf(s));
}
};
SetSerializer<String> serializer = SetSerializer.getInstance(UTF8Serializer.instance, UTF8Type.instance);
Set<String> originalPerms = serializer.deserialize(row.getBytes("permissions"));
Set<String> filteredPerms = ImmutableSet.copyOf(Iterables.filter(originalPerms, isApplicable));
insertStatement.execute(QueryState.forInternalCalls(), QueryOptions.forInternalCalls(ConsistencyLevel.ONE, Lists.newArrayList(row.getBytes("username"), row.getBytes("resource"), serializer.serialize(filteredPerms))), System.nanoTime());
indexStatement.execute(QueryState.forInternalCalls(), QueryOptions.forInternalCalls(ConsistencyLevel.ONE, Lists.newArrayList(row.getBytes("resource"), row.getBytes("username"))), System.nanoTime());
}
logger.info("Completed conversion of legacy permissions");
}
} catch (Exception e) {
logger.info("Unable to complete conversion of legacy permissions data (perhaps not enough nodes are upgraded yet). " + "Conversion should not be considered complete");
logger.trace("Conversion error", e);
}
}
Aggregations