Search in sources :

Example 16 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project jackrabbit-oak by apache.

the class DataStoreCheckCommand method execute.

@Override
public void execute(String... args) throws Exception {
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    String helpStr = "datastorecheck [--id] [--ref] [--consistency] [--store <path>|<mongo_uri>] " + "[--s3ds <s3ds_config>|--fds <fds_config>|--azureblobds <azureblobds_config>] [--dump <path>]";
    Closer closer = Closer.create();
    try {
        // Options for operations requested
        OptionSpecBuilder idOp = parser.accepts("id", "Get ids");
        OptionSpecBuilder refOp = parser.accepts("ref", "Get references");
        OptionSpecBuilder consistencyOp = parser.accepts("consistency", "Check consistency");
        // Node Store - needed for --ref, --consistency
        ArgumentAcceptingOptionSpec<String> store = parser.accepts("store", "Node Store").requiredIf(refOp, consistencyOp).withRequiredArg().ofType(String.class);
        // Optional argument to specify the dump path
        ArgumentAcceptingOptionSpec<String> dump = parser.accepts("dump", "Dump Path").withRequiredArg().ofType(String.class);
        // Optional argument to specify tracking
        ArgumentAcceptingOptionSpec<String> track = parser.accepts("track", "Local repository home folder").withRequiredArg().ofType(String.class);
        OptionSpec<?> help = parser.acceptsAll(asList("h", "?", "help"), "show help").forHelp();
        // Required rules (any one of --id, --ref, --consistency)
        idOp.requiredUnless(refOp, consistencyOp);
        refOp.requiredUnless(idOp, consistencyOp);
        consistencyOp.requiredUnless(idOp, refOp);
        OptionSet options = null;
        try {
            options = parser.parse(args);
        } catch (Exception e) {
            System.err.println(e);
            parser.printHelpOn(System.err);
            return;
        }
        if (options.has(help)) {
            parser.printHelpOn(System.out);
            return;
        }
        String dumpPath = JAVA_IO_TMPDIR.value();
        if (options.has(dump)) {
            dumpPath = options.valueOf(dump);
        }
        GarbageCollectableBlobStore blobStore = null;
        BlobReferenceRetriever marker = null;
        if (options.has(store)) {
            String source = options.valueOf(store);
            if (source.startsWith(MongoURI.MONGODB_PREFIX)) {
                MongoClientURI uri = new MongoClientURI(source);
                MongoClient client = new MongoClient(uri);
                DocumentNodeStore nodeStore = new DocumentMK.Builder().setMongoDB(client.getDB(uri.getDatabase())).getNodeStore();
                closer.register(Utils.asCloseable(nodeStore));
                blobStore = (GarbageCollectableBlobStore) nodeStore.getBlobStore();
                marker = new DocumentBlobReferenceRetriever(nodeStore);
            } else {
                marker = SegmentTarUtils.newBlobReferenceRetriever(source, closer);
            }
        }
        // Initialize S3/FileDataStore if configured
        GarbageCollectableBlobStore dataStore = Utils.bootstrapDataStore(args, closer);
        if (dataStore != null) {
            blobStore = dataStore;
        }
        // blob store still not initialized means configuration not supported
        if (blobStore == null) {
            System.err.println("Operation not defined for SegmentNodeStore without external datastore");
            parser.printHelpOn(System.err);
            return;
        }
        FileRegister register = new FileRegister(options);
        closer.register(register);
        if (options.has(idOp) || options.has(consistencyOp)) {
            File dumpFile = register.createFile(idOp, dumpPath);
            retrieveBlobIds(blobStore, dumpFile);
            // If track path specified copy the file to the location
            if (options.has(track)) {
                String trackPath = options.valueOf(track);
                File trackingFileParent = new File(FilenameUtils.concat(trackPath, "blobids"));
                File trackingFile = new File(trackingFileParent, "blob-" + String.valueOf(System.currentTimeMillis()) + ".gen");
                FileUtils.copyFile(dumpFile, trackingFile);
            }
        }
        if (options.has(refOp) || options.has(consistencyOp)) {
            retrieveBlobReferences(blobStore, marker, register.createFile(refOp, dumpPath));
        }
        if (options.has(consistencyOp)) {
            checkConsistency(register.get(idOp), register.get(refOp), register.createFile(consistencyOp, dumpPath));
        }
    } catch (Throwable t) {
        t.printStackTrace();
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) MongoClientURI(com.mongodb.MongoClientURI) OptionSpecBuilder(joptsimple.OptionSpecBuilder) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) OptionParser(joptsimple.OptionParser) IOException(java.io.IOException) MongoClient(com.mongodb.MongoClient) OptionSpecBuilder(joptsimple.OptionSpecBuilder) DocumentBlobReferenceRetriever(org.apache.jackrabbit.oak.plugins.document.DocumentBlobReferenceRetriever) BlobReferenceRetriever(org.apache.jackrabbit.oak.plugins.blob.BlobReferenceRetriever) GarbageCollectableBlobStore(org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore) OptionSet(joptsimple.OptionSet) DocumentBlobReferenceRetriever(org.apache.jackrabbit.oak.plugins.document.DocumentBlobReferenceRetriever) File(java.io.File)

Example 17 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project jackrabbit-oak by apache.

the class RevisionsCommand method execute.

@Override
public void execute(String... args) throws Exception {
    Closer closer = Closer.create();
    try {
        RevisionsOptions options = new RevisionsOptions(USAGE).parse(args);
        setupLoggers(options.isVerbose());
        String subCmd = options.getSubCmd();
        if (RevisionsOptions.CMD_INFO.equals(subCmd)) {
            info(options, closer);
        } else if (RevisionsOptions.CMD_COLLECT.equals(subCmd)) {
            collect(options, closer);
        } else if (RevisionsOptions.CMD_RESET.equals(subCmd)) {
            reset(options, closer);
        } else if (RevisionsOptions.CMD_SWEEP.equals(subCmd)) {
            sweep(options, closer);
        } else {
            System.err.println("unknown revisions command: " + subCmd);
        }
    } catch (Throwable e) {
        LOG.error("Command failed", e);
        throw closer.rethrow(e);
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) Utils.timestampToString(org.apache.jackrabbit.oak.plugins.document.util.Utils.timestampToString)

Example 18 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project jackrabbit-oak by apache.

the class JdbcFactory method hasExternalBlobReferences.

@Override
public boolean hasExternalBlobReferences() throws IOException {
    Closer closer = Closer.create();
    try {
        DataSource ds = getDataSource(closer);
        RDBBlobStore blobStore = new RDBBlobStore(ds);
        return !blobStore.getAllChunkIds(0).hasNext();
    } catch (Throwable e) {
        throw closer.rethrow(e);
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) RDBBlobStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStore) DataSource(javax.sql.DataSource)

Example 19 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project zipkin by openzipkin.

the class DefaultSessionFactory method create.

/**
   * Creates a session and ensures schema if configured. Closes the cluster and session if any
   * exception occurred.
   */
@Override
public Session create(Cassandra3Storage cassandra) {
    Closer closer = Closer.create();
    try {
        Cluster cluster = closer.register(buildCluster(cassandra));
        cluster.register(new QueryLogger.Builder().build());
        Session session;
        if (cassandra.ensureSchema) {
            session = closer.register(cluster.connect());
            Schema.ensureExists(cassandra.keyspace, session);
            session.execute("USE " + cassandra.keyspace);
        } else {
            session = cluster.connect(cassandra.keyspace);
        }
        initializeUDTs(session);
        return session;
    } catch (RuntimeException e) {
        try {
            closer.close();
        } catch (IOException ignored) {
        }
        throw e;
    }
}
Also used : Closer(com.google.common.io.Closer) Cluster(com.datastax.driver.core.Cluster) IOException(java.io.IOException) Session(com.datastax.driver.core.Session)

Example 20 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project presto by prestodb.

the class LocalQueryRunner method executeInternal.

private MaterializedResult executeInternal(Session session, @Language("SQL") String sql) {
    lock.readLock().lock();
    try (Closer closer = Closer.create()) {
        AtomicReference<MaterializedResult.Builder> builder = new AtomicReference<>();
        PageConsumerOutputFactory outputFactory = new PageConsumerOutputFactory(types -> {
            builder.compareAndSet(null, MaterializedResult.resultBuilder(session, types));
            return builder.get()::page;
        });
        TaskContext taskContext = createTaskContext(executor, session);
        List<Driver> drivers = createDrivers(session, sql, outputFactory, taskContext);
        drivers.forEach(closer::register);
        boolean done = false;
        while (!done) {
            boolean processed = false;
            for (Driver driver : drivers) {
                if (!driver.isFinished()) {
                    driver.process();
                    processed = true;
                }
            }
            done = !processed;
        }
        verify(builder.get() != null, "Output operator was not created");
        return builder.get().build();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    } finally {
        lock.readLock().unlock();
    }
}
Also used : Closer(com.google.common.io.Closer) TaskContext(com.facebook.presto.operator.TaskContext) TestingTaskContext.createTaskContext(com.facebook.presto.testing.TestingTaskContext.createTaskContext) PageConsumerOutputFactory(com.facebook.presto.testing.PageConsumerOperator.PageConsumerOutputFactory) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) Driver(com.facebook.presto.operator.Driver) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException)

Aggregations

Closer (com.google.common.io.Closer)200 IOException (java.io.IOException)94 File (java.io.File)22 Test (org.junit.Test)18 Test (org.testng.annotations.Test)18 Closer (org.apache.flink.shaded.guava30.com.google.common.io.Closer)16 Path (org.apache.hadoop.fs.Path)16 ArrayList (java.util.ArrayList)15 Properties (java.util.Properties)14 FileOutputStream (java.io.FileOutputStream)13 FileInputStream (java.io.FileInputStream)12 InputStream (java.io.InputStream)12 Map (java.util.Map)12 OutputStream (java.io.OutputStream)11 UncheckedIOException (java.io.UncheckedIOException)10 NettyShuffleEnvironment (org.apache.flink.runtime.io.network.NettyShuffleEnvironment)9 WorkUnit (org.apache.gobblin.source.workunit.WorkUnit)9 AlluxioException (alluxio.exception.AlluxioException)8 InputStreamReader (java.io.InputStreamReader)8 HashMap (java.util.HashMap)8