Search in sources :

Example 6 with ResolveGeogigDir

use of org.locationtech.geogig.api.plumbing.ResolveGeogigDir in project GeoGig by boundlessgeo.

the class SaveMergeCommitMessageOp method _call.

@Override
protected Void _call() {
    URL envHome = new ResolveGeogigDir(platform()).call().get();
    try {
        File file = new File(envHome.toURI());
        file = new File(file, "MERGE_MSG");
        Files.write(message, file, Charsets.UTF_8);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    return null;
}
Also used : ResolveGeogigDir(org.locationtech.geogig.api.plumbing.ResolveGeogigDir) File(java.io.File) URL(java.net.URL)

Example 7 with ResolveGeogigDir

use of org.locationtech.geogig.api.plumbing.ResolveGeogigDir in project GeoGig by boundlessgeo.

the class Logging method tryConfigureLogging.

static void tryConfigureLogging(Platform platform) {
    // instantiate and call ResolveGeogigDir directly to avoid calling getGeogig() and hence get
    // some logging events before having configured logging
    final Optional<URL> geogigDirUrl = new ResolveGeogigDir(platform).call();
    if (!geogigDirUrl.isPresent() || !"file".equalsIgnoreCase(geogigDirUrl.get().getProtocol())) {
        // redirect java.util.logging to SLF4J anyways
        SLF4JBridgeHandler.removeHandlersForRootLogger();
        SLF4JBridgeHandler.install();
        return;
    }
    final File geogigDir;
    try {
        geogigDir = new File(geogigDirUrl.get().toURI());
    } catch (URISyntaxException e) {
        throw Throwables.propagate(e);
    }
    if (geogigDir.equals(geogigDirLoggingConfiguration)) {
        return;
    }
    if (!geogigDir.exists() || !geogigDir.isDirectory()) {
        return;
    }
    final URL loggingFile = getOrCreateLoggingConfigFile(geogigDir);
    if (loggingFile == null) {
        return;
    }
    try {
        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
        loggerContext.reset();
        /*
             * Set the geogigdir variable for the config file can resolve the default location
             * ${geogigdir}/log/geogig.log
             */
        loggerContext.putProperty("geogigdir", geogigDir.getAbsolutePath());
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(loggerContext);
        configurator.doConfigure(loggingFile);
        // redirect java.util.logging to SLF4J
        SLF4JBridgeHandler.removeHandlersForRootLogger();
        SLF4JBridgeHandler.install();
        geogigDirLoggingConfiguration = geogigDir;
    } catch (JoranException e) {
        LOGGER.error("Error configuring logging from file {}. '{}'", loggingFile, e.getMessage(), e);
    }
}
Also used : JoranException(ch.qos.logback.core.joran.spi.JoranException) JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator) URISyntaxException(java.net.URISyntaxException) ResolveGeogigDir(org.locationtech.geogig.api.plumbing.ResolveGeogigDir) File(java.io.File) LoggerContext(ch.qos.logback.classic.LoggerContext) URL(java.net.URL)

Example 8 with ResolveGeogigDir

use of org.locationtech.geogig.api.plumbing.ResolveGeogigDir in project GeoGig by boundlessgeo.

the class EnvironmentBuilder method get.

/**
     * @return
     * @see com.google.inject.Provider#get()
     */
@Override
public synchronized Environment get() {
    final Optional<URL> repoUrl = new ResolveGeogigDir(platform).call();
    if (!repoUrl.isPresent() && absolutePath == null) {
        throw new IllegalStateException("Can't find geogig repository home");
    }
    final File storeDirectory;
    if (absolutePath != null) {
        storeDirectory = absolutePath;
    } else {
        File currDir;
        try {
            currDir = new File(repoUrl.get().toURI());
        } catch (URISyntaxException e) {
            throw Throwables.propagate(e);
        }
        File dir = currDir;
        for (String subdir : path) {
            dir = new File(dir, subdir);
        }
        storeDirectory = dir;
    }
    if (!storeDirectory.exists() && !storeDirectory.mkdirs()) {
        throw new IllegalStateException("Unable to create Environment directory: '" + storeDirectory.getAbsolutePath() + "'");
    }
    EnvironmentConfig envCfg;
    if (this.forceConfig == null) {
        File conf = new File(storeDirectory, "je.properties");
        if (!conf.exists()) {
            String resource = stagingDatabase ? "je.properties.staging" : "je.properties.objectdb";
            ByteSource from = Resources.asByteSource((getClass().getResource(resource)));
            try {
                from.copyTo(Files.asByteSink(conf));
            } catch (IOException e) {
                Throwables.propagate(e);
            }
        }
        // use the default settings
        envCfg = new EnvironmentConfig();
        envCfg.setAllowCreate(true);
        envCfg.setCacheMode(CacheMode.MAKE_COLD);
        envCfg.setLockTimeout(5, TimeUnit.SECONDS);
        envCfg.setDurability(Durability.COMMIT_SYNC);
    // envCfg.setReadOnly(readOnly);
    } else {
        envCfg = this.forceConfig;
    }
    // // envCfg.setSharedCache(true);
    // //
    // final boolean transactional = false;
    // envCfg.setTransactional(transactional);
    // envCfg.setCachePercent(75);// Use up to 50% of the heap size for the shared db cache
    // envCfg.setConfigParam(EnvironmentConfig.LOG_FILE_MAX, String.valueOf(256 * 1024 * 1024));
    // // check <http://www.oracle.com/technetwork/database/berkeleydb/je-faq-096044.html#35>
    // envCfg.setConfigParam("je.evictor.lruOnly", "false");
    // envCfg.setConfigParam("je.evictor.nodesPerScan", "100");
    //
    // envCfg.setConfigParam(EnvironmentConfig.CLEANER_MIN_UTILIZATION, "25");
    // envCfg.setConfigParam(EnvironmentConfig.CHECKPOINTER_HIGH_PRIORITY, "true");
    //
    // envCfg.setConfigParam(EnvironmentConfig.CLEANER_THREADS, "4");
    // // TODO: check whether we can set is locking to false
    // envCfg.setConfigParam(EnvironmentConfig.ENV_IS_LOCKING, String.valueOf(transactional));
    //
    // envCfg.setConfigParam(EnvironmentConfig.ENV_RUN_CHECKPOINTER,
    // String.valueOf(!transactional));
    // envCfg.setConfigParam(EnvironmentConfig.ENV_RUN_CLEANER, String.valueOf(!transactional));
    //
    // // envCfg.setConfigParam(EnvironmentConfig.ENV_RUN_EVICTOR, "false");
    Environment env;
    try {
        env = new Environment(storeDirectory, envCfg);
    } catch (RuntimeException lockedEx) {
        // lockedEx.printStackTrace();
        if (readOnly) {
            // this happens when trying to open the env in read only mode when its already open
            // in read/write mode inside the same process. So we re-open it read-write but the
            // database itself will be open read-only by JEObjectDatabase.
            envCfg.setReadOnly(true);
            env = new Environment(storeDirectory, envCfg);
        } else {
            throw lockedEx;
        }
    }
    return env;
}
Also used : EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) ByteSource(com.google.common.io.ByteSource) Environment(com.sleepycat.je.Environment) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ResolveGeogigDir(org.locationtech.geogig.api.plumbing.ResolveGeogigDir) File(java.io.File) URL(java.net.URL)

Example 9 with ResolveGeogigDir

use of org.locationtech.geogig.api.plumbing.ResolveGeogigDir in project GeoGig by boundlessgeo.

the class JEStagingDatabase method open.

@Override
public void open() {
    super.open();
    Optional<URL> repoPath = new ResolveGeogigDir(platform).call();
    try {
        File repoLocation = new File(repoPath.get().toURI());
        this.repositoryDirectory = repoLocation;
    } catch (URISyntaxException e1) {
        Throwables.propagate(e1);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) ResolveGeogigDir(org.locationtech.geogig.api.plumbing.ResolveGeogigDir) File(java.io.File) URL(java.net.URL)

Example 10 with ResolveGeogigDir

use of org.locationtech.geogig.api.plumbing.ResolveGeogigDir in project GeoGig by boundlessgeo.

the class FileRefDatabase method getAll.

/**
     * @return all references under the specified namespace
     */
@Override
public Map<String, String> getAll(String namespace) {
    Preconditions.checkNotNull(namespace);
    File refsRoot;
    try {
        Optional<URL> envHome = new ResolveGeogigDir(platform).call();
        refsRoot = new File(envHome.get().toURI());
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    if (namespace.endsWith("/")) {
        namespace = namespace.substring(0, namespace.length() - 1);
    }
    Map<String, String> refs = Maps.newTreeMap();
    findRefs(refsRoot, namespace, refs);
    return ImmutableMap.copyOf(refs);
}
Also used : ResolveGeogigDir(org.locationtech.geogig.api.plumbing.ResolveGeogigDir) File(java.io.File) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) RepositoryConnectionException(org.locationtech.geogig.repository.RepositoryConnectionException)

Aggregations

URL (java.net.URL)14 ResolveGeogigDir (org.locationtech.geogig.api.plumbing.ResolveGeogigDir)14 File (java.io.File)12 URISyntaxException (java.net.URISyntaxException)10 IOException (java.io.IOException)4 RepositoryConnectionException (org.locationtech.geogig.repository.RepositoryConnectionException)3 LoggerContext (ch.qos.logback.classic.LoggerContext)1 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)1 JoranException (ch.qos.logback.core.joran.spi.JoranException)1 ByteSource (com.google.common.io.ByteSource)1 Environment (com.sleepycat.je.Environment)1 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)1 FileNotFoundException (java.io.FileNotFoundException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 Platform (org.locationtech.geogig.api.Platform)1 ConfigException (org.locationtech.geogig.api.porcelain.ConfigException)1 Repository (org.locationtech.geogig.repository.Repository)1 ConfigDatabase (org.locationtech.geogig.storage.ConfigDatabase)1 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)1