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;
}
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);
}
}
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;
}
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);
}
}
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);
}
Aggregations