Search in sources :

Example 6 with SafeIllegalStateException

use of com.palantir.logsafe.exceptions.SafeIllegalStateException in project atlasdb by palantir.

the class SplittingPaxosStateLog method createWithMigration.

public static <V extends Persistable & Versionable> PaxosStateLog<V> createWithMigration(PaxosStorageParameters params, Persistable.Hydrator<V> hydrator, LegacyOperationMarkers legacyOperationMarkers, OptionalLong migrateFrom) {
    String logDirectory = params.fileBasedLogDirectory().orElseThrow(() -> new SafeIllegalStateException("We currently need to have file-based storage"));
    NamespaceAndUseCase namespaceUseCase = params.namespaceAndUseCase();
    PaxosStateLogMigrator.MigrationContext<V> migrationContext = ImmutableMigrationContext.<V>builder().sourceLog(PaxosStateLogImpl.createFileBacked(logDirectory)).destinationLog(SqlitePaxosStateLog.create(namespaceUseCase, params.sqliteDataSource())).hydrator(hydrator).migrationState(SqlitePaxosStateLogMigrationState.create(namespaceUseCase, params.sqliteDataSource())).migrateFrom(migrateFrom).namespaceAndUseCase(namespaceUseCase).skipValidationAndTruncateSourceIfMigrated(params.skipConsistencyCheckAndTruncateOldPaxosLog()).build();
    long cutoff = PaxosStateLogMigrator.migrateAndReturnCutoff(migrationContext);
    if (params.skipConsistencyCheckAndTruncateOldPaxosLog()) {
        return migrationContext.destinationLog();
    }
    SplittingParameters<V> splittingParameters = ImmutableSplittingParameters.<V>builder().legacyLog(migrationContext.sourceLog()).currentLog(migrationContext.destinationLog()).cutoffInclusive(cutoff).legacyOperationMarkers(legacyOperationMarkers).build();
    return SplittingPaxosStateLog.create(splittingParameters);
}
Also used : SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException)

Example 7 with SafeIllegalStateException

use of com.palantir.logsafe.exceptions.SafeIllegalStateException in project atlasdb by palantir.

the class AtlasDbServicesConnector method connect.

public AtlasDbServices connect() {
    if (services != null) {
        throw new SafeIllegalStateException("connect() has already been called");
    }
    DockerizedDatabaseUri dburi = DockerizedDatabaseUri.fromUriString(uri);
    KeyValueServiceConfig config = dburi.getKeyValueServiceInstrumentation().getKeyValueServiceConfig(dburi.getAddress());
    Optional<KeyValueServiceRuntimeConfig> runtimeConfig = dburi.getKeyValueServiceInstrumentation().getKeyValueServiceRuntimeConfig(dburi.getAddress());
    ImmutableAtlasDbConfig atlasDbConfig = ImmutableAtlasDbConfig.builder().keyValueService(config).build();
    ImmutableAtlasDbRuntimeConfig atlasDbRuntimeConfig = ImmutableAtlasDbRuntimeConfig.defaultRuntimeConfig().withKeyValueService(runtimeConfig);
    ServicesConfigModule servicesConfigModule = ServicesConfigModule.create(atlasDbConfig, atlasDbRuntimeConfig);
    services = DaggerAtlasDbServices.builder().servicesConfigModule(servicesConfigModule).build();
    return services;
}
Also used : KeyValueServiceConfig(com.palantir.atlasdb.spi.KeyValueServiceConfig) ImmutableAtlasDbRuntimeConfig(com.palantir.atlasdb.config.ImmutableAtlasDbRuntimeConfig) ImmutableAtlasDbConfig(com.palantir.atlasdb.config.ImmutableAtlasDbConfig) ServicesConfigModule(com.palantir.atlasdb.services.ServicesConfigModule) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) KeyValueServiceRuntimeConfig(com.palantir.atlasdb.spi.KeyValueServiceRuntimeConfig)

Example 8 with SafeIllegalStateException

use of com.palantir.logsafe.exceptions.SafeIllegalStateException in project atlasdb by palantir.

the class TimeLockAgent method verifyTimestampBoundPersisterConfiguration.

@VisibleForTesting
static void verifyTimestampBoundPersisterConfiguration(HikariDataSource sqliteDataSource, TsBoundPersisterConfiguration currentUserConfiguration, boolean reseedPersistedPersisterConfiguration, ObjectMapper objectMapper) {
    PersistenceConfigStore store = new PersistenceConfigStore(objectMapper, SqliteBlobStore.create(sqliteDataSource));
    if (reseedPersistedPersisterConfiguration) {
        log.info("As configured, updating the configuration persisted in the SQLite database.", SafeArg.of("ourConfiguration", currentUserConfiguration));
        store.storeConfig(currentUserConfiguration);
        return;
    }
    Optional<TsBoundPersisterConfiguration> configInDatabase = store.getPersistedConfig();
    if (!configInDatabase.isPresent()) {
        log.info("There is no config in the SQLite database indicating where timestamps are being stored. We are" + " thus assuming that your current configuration is indeed correct, and using that as a" + " future reference.", SafeArg.of("configuration", currentUserConfiguration));
        store.storeConfig(currentUserConfiguration);
        return;
    }
    TsBoundPersisterConfiguration presentConfig = configInDatabase.get();
    if (currentUserConfiguration.isLocationallyIncompatible(presentConfig)) {
        log.error("Configuration in the SQLite database does not agree with what the user has provided!", SafeArg.of("ourConfiguration", currentUserConfiguration), SafeArg.of("persistedConfiguration", presentConfig));
        throw new SafeIllegalStateException("Configuration in the SQLite database does not agree with the" + " configuration the user has provided, in a way that is known to be incompatible. For integrity" + " of the service, we will shut down and cannot serve any user requests. If you have" + " accidentally changed the DB configs, please revert them. If this is intentional, you can" + " update the config stored in the database by setting the relevant override flag.");
    } else {
        log.info("Passed consistency check: the config in the SQLite database agrees with our config.");
    }
}
Also used : TsBoundPersisterConfiguration(com.palantir.timelock.config.TsBoundPersisterConfiguration) DatabaseTsBoundPersisterConfiguration(com.palantir.timelock.config.DatabaseTsBoundPersisterConfiguration) PaxosTsBoundPersisterConfiguration(com.palantir.timelock.config.PaxosTsBoundPersisterConfiguration) PersistenceConfigStore(com.palantir.timelock.store.PersistenceConfigStore) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 9 with SafeIllegalStateException

use of com.palantir.logsafe.exceptions.SafeIllegalStateException in project conjure by palantir.

the class ConjureParserUtils method innerParseImportObjects.

private static Map<TypeName, TypeDefinition> innerParseImportObjects(Map<Namespace, ConjureImports> conjureImports, Map<String, AnnotatedConjureSourceFile> externalTypes, Set<String> loadedFiles) {
    Map<TypeName, TypeDefinition> allDefinitions = new HashMap<>();
    conjureImports.values().forEach(conjureImport -> {
        String pathKey = conjureImport.absoluteFile().orElseThrow(() -> new SafeIllegalStateException("Absolute file MUST be resolved as part of parsing stage")).getAbsolutePath();
        // These structures are potentially recursive; load in any given conjure file once
        if (loadedFiles.contains(pathKey)) {
            return;
        }
        loadedFiles.add(pathKey);
        AnnotatedConjureSourceFile annotatedConjureSourceFile = externalTypes.get(pathKey);
        Preconditions.checkNotNull(annotatedConjureSourceFile, "Couldn't find import", UnsafeArg.of("file", conjureImport.file()));
        ConjureSourceFile conjureDef = annotatedConjureSourceFile.conjureSourceFile();
        Map<Namespace, String> importProviders = annotatedConjureSourceFile.importProviders();
        ReferenceTypeResolver importTypeResolver = new ConjureTypeParserVisitor.ByParsedRepresentationTypeNameResolver(conjureDef.types(), importProviders, externalTypes);
        allDefinitions.putAll(parseObjects(conjureDef.types(), importTypeResolver));
        allDefinitions.putAll(innerParseImportObjects(conjureDef.types().conjureImports(), externalTypes, loadedFiles));
    });
    return allDefinitions;
}
Also used : TypeName(com.palantir.conjure.spec.TypeName) AnnotatedConjureSourceFile(com.palantir.conjure.parser.AnnotatedConjureSourceFile) ConjureSourceFile(com.palantir.conjure.parser.ConjureSourceFile) ReferenceTypeResolver(com.palantir.conjure.defs.ConjureTypeParserVisitor.ReferenceTypeResolver) HashMap(java.util.HashMap) AnnotatedConjureSourceFile(com.palantir.conjure.parser.AnnotatedConjureSourceFile) PathString(com.palantir.conjure.parser.services.PathString) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) Namespace(com.palantir.conjure.parser.types.names.Namespace) ErrorNamespace(com.palantir.conjure.spec.ErrorNamespace) TypeDefinition(com.palantir.conjure.spec.TypeDefinition)

Example 10 with SafeIllegalStateException

use of com.palantir.logsafe.exceptions.SafeIllegalStateException in project conjure-java-runtime by palantir.

the class AsyncSerializableErrorCallAdapterFactory method get.

@Override
public CallAdapter<?, ?> get(Type returnType, Annotation[] _annotations, Retrofit _retrofit) {
    Type outerType = getRawType(returnType);
    if (outerType != CompletableFuture.class && outerType != ListenableFuture.class) {
        return null;
    }
    if (!(returnType instanceof ParameterizedType)) {
        throw new SafeIllegalStateException("CompletableFuture/ListenableFuture return type must be parameterized" + " as <Foo> or <? extends Foo>");
    }
    Type innerType = getParameterUpperBound(0, (ParameterizedType) returnType);
    if (getRawType(innerType) != Response.class) {
        // Generic type is not Response<T>. Use it for body-only adapter.
        return getCallAdapter(outerType, innerType);
    }
    return null;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) CompletableFuture(java.util.concurrent.CompletableFuture) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException)

Aggregations

SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)24 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 ImmutableSet (com.google.common.collect.ImmutableSet)5 Set (java.util.Set)5 ImmutableList (com.google.common.collect.ImmutableList)4 Iterables (com.google.common.collect.Iterables)4 SafeArg (com.palantir.logsafe.SafeArg)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 Suppliers (com.google.common.base.Suppliers)3 RangeMap (com.google.common.collect.RangeMap)3 Sets (com.google.common.collect.Sets)3 CassandraKeyValueServiceConfig (com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig)3 Refreshable (com.palantir.refreshable.Refreshable)3 Map (java.util.Map)3 RetryException (com.github.rholder.retry.RetryException)2 ImmutableMap (com.google.common.collect.ImmutableMap)2