Search in sources :

Example 96 with Predicate

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);
    }
}
Also used : File(java.io.File) Nullable(javax.annotation.Nullable) Predicate(com.google.common.base.Predicate)

Example 97 with Predicate

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);
    }
}
Also used : IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) Predicate(com.google.common.base.Predicate)

Example 98 with Predicate

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;
}
Also used : TableName(org.apache.hadoop.hbase.TableName) List(java.util.List) Predicate(com.google.common.base.Predicate)

Example 99 with Predicate

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Nullable(javax.annotation.Nullable) Predicate(com.google.common.base.Predicate) Test(org.junit.Test)

Example 100 with Predicate

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);
    }
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Predicate(com.google.common.base.Predicate)

Aggregations

Predicate (com.google.common.base.Predicate)180 ArrayList (java.util.ArrayList)29 Nullable (javax.annotation.Nullable)29 Test (org.junit.Test)29 List (java.util.List)28 UUID (java.util.UUID)21 IOException (java.io.IOException)20 Map (java.util.Map)20 File (java.io.File)15 Test (org.testng.annotations.Test)14 ImmutableList (com.google.common.collect.ImmutableList)12 HashMap (java.util.HashMap)12 Set (java.util.Set)9 DateTime (org.joda.time.DateTime)9 BigDecimal (java.math.BigDecimal)8 Path (javax.ws.rs.Path)8 PaymentTransactionModelDao (org.killbill.billing.payment.dao.PaymentTransactionModelDao)8 Account (org.killbill.billing.account.api.Account)7 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)7 PaymentModelDao (org.killbill.billing.payment.dao.PaymentModelDao)7