Search in sources :

Example 6 with ConfigException

use of org.locationtech.geogig.api.porcelain.ConfigException in project GeoGig by boundlessgeo.

the class MeteredCommandHook method pre.

@Override
public <C extends AbstractGeoGigOp<?>> C pre(C command) throws CannotRunGeogigOperationException {
    Boolean enabled;
    if (command.context().repository() == null) {
        return command;
    }
    ConfigDatabase configDb = command.context().configDatabase();
    try {
        enabled = configDb.get(METRICS_ENABLED, Boolean.class).or(Boolean.FALSE);
    } catch (ConfigException e) {
        if (StatusCode.INVALID_LOCATION.equals(e.statusCode)) {
            enabled = Boolean.FALSE;
        } else {
            throw e;
        }
    }
    if (!enabled.booleanValue()) {
        return command;
    }
    final Platform platform = command.context().platform();
    final long startTime = platform.currentTimeMillis();
    final long nanoTime = platform.nanoTime();
    final String name = command.getClass().getSimpleName();
    CallStack stack = CallStack.push(name, startTime, nanoTime);
    command.getClientData().put("metrics.callStack", stack);
    return command;
}
Also used : Platform(org.locationtech.geogig.api.Platform) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) ConfigException(org.locationtech.geogig.api.porcelain.ConfigException)

Example 7 with ConfigException

use of org.locationtech.geogig.api.porcelain.ConfigException in project GeoGig by boundlessgeo.

the class ConfigOpTest method testGetDefaultWithNoLocalRepository.

@Test
public void testGetDefaultWithNoLocalRepository() {
    ConfigDatabase database = mock(ConfigDatabase.class);
    when(database.get(anyString())).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION));
    when(database.getGlobal(anyString())).thenReturn(Optional.of("value"));
    ConfigOp config = new ConfigOp(database);
    config.setScope(ConfigScope.DEFAULT).setAction(ConfigAction.CONFIG_GET).setName("section.key").setValue(null).call();
}
Also used : ConfigOp(org.locationtech.geogig.api.porcelain.ConfigOp) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) ConfigException(org.locationtech.geogig.api.porcelain.ConfigException) Test(org.junit.Test)

Example 8 with ConfigException

use of org.locationtech.geogig.api.porcelain.ConfigException in project GeoGig by boundlessgeo.

the class ConfigOpTest method testListDefaultWithNoLocalRepository.

@Test
public void testListDefaultWithNoLocalRepository() {
    ConfigDatabase database = mock(ConfigDatabase.class);
    when(database.getAll()).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION));
    ConfigOp config = new ConfigOp(database);
    config.setScope(ConfigScope.DEFAULT).setAction(ConfigAction.CONFIG_LIST).setName(null).setValue(null).call();
}
Also used : ConfigOp(org.locationtech.geogig.api.porcelain.ConfigOp) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) ConfigException(org.locationtech.geogig.api.porcelain.ConfigException) Test(org.junit.Test)

Example 9 with ConfigException

use of org.locationtech.geogig.api.porcelain.ConfigException in project GeoGig by boundlessgeo.

the class ConfigOpTest method testListLocalWithNoLocalRepository.

@Test
public void testListLocalWithNoLocalRepository() {
    ConfigDatabase database = mock(ConfigDatabase.class);
    when(database.getAll()).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION));
    ConfigOp config = new ConfigOp(database);
    exception.expect(ConfigException.class);
    config.setScope(ConfigScope.LOCAL).setAction(ConfigAction.CONFIG_LIST).setName(null).setValue(null).call();
}
Also used : ConfigOp(org.locationtech.geogig.api.porcelain.ConfigOp) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) ConfigException(org.locationtech.geogig.api.porcelain.ConfigException) Test(org.junit.Test)

Example 10 with ConfigException

use of org.locationtech.geogig.api.porcelain.ConfigException in project GeoGig by boundlessgeo.

the class ConfigOpTest method testGetLocalWithNoLocalRepository.

@Test
public void testGetLocalWithNoLocalRepository() {
    ConfigDatabase database = mock(ConfigDatabase.class);
    when(database.get(anyString())).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION));
    ConfigOp config = new ConfigOp(database);
    exception.expect(ConfigException.class);
    config.setScope(ConfigScope.LOCAL).setAction(ConfigAction.CONFIG_GET).setName("section.key").setValue(null).call();
}
Also used : ConfigOp(org.locationtech.geogig.api.porcelain.ConfigOp) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) ConfigException(org.locationtech.geogig.api.porcelain.ConfigException) Test(org.junit.Test)

Aggregations

ConfigException (org.locationtech.geogig.api.porcelain.ConfigException)14 ConfigDatabase (org.locationtech.geogig.storage.ConfigDatabase)6 ConfigOp (org.locationtech.geogig.api.porcelain.ConfigOp)5 Test (org.junit.Test)4 File (java.io.File)2 IOException (java.io.IOException)2 GeoGIG (org.locationtech.geogig.api.GeoGIG)2 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)2 MemoryUsage (java.lang.management.MemoryUsage)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Platform (org.locationtech.geogig.api.Platform)1 Remote (org.locationtech.geogig.api.Remote)1 ResolveGeogigDir (org.locationtech.geogig.api.plumbing.ResolveGeogigDir)1 ConfigGet (org.locationtech.geogig.api.porcelain.ConfigGet)1 ConfigAction (org.locationtech.geogig.api.porcelain.ConfigOp.ConfigAction)1 ConfigScope (org.locationtech.geogig.api.porcelain.ConfigOp.ConfigScope)1 InvalidParameterException (org.locationtech.geogig.cli.InvalidParameterException)1