Search in sources :

Example 6 with ConfigurationException

use of org.elasticsearch.common.inject.ConfigurationException in project crate by crate.

the class InjectionPoint method forConstructorOf.

/**
 * Returns a new injection point for the injectable constructor of {@code type}.
 *
 * @param type a concrete type with exactly one constructor annotated {@literal @}{@link Inject},
 *             or a no-arguments constructor that is not private.
 * @throws ConfigurationException if there is no injectable constructor, more than one injectable
 *                                constructor, or if parameters of the injectable constructor are malformed, such as a
 *                                parameter with multiple binding annotations.
 */
public static InjectionPoint forConstructorOf(TypeLiteral<?> type) {
    Class<?> rawType = getRawType(type.getType());
    Errors errors = new Errors(rawType);
    Constructor<?> injectableConstructor = null;
    for (Constructor<?> constructor : rawType.getConstructors()) {
        Inject inject = constructor.getAnnotation(Inject.class);
        if (inject != null) {
            if (inject.optional()) {
                errors.optionalConstructor(constructor);
            }
            if (injectableConstructor != null) {
                errors.tooManyConstructors(rawType);
            }
            injectableConstructor = constructor;
            checkForMisplacedBindingAnnotations(injectableConstructor, errors);
        }
    }
    errors.throwConfigurationExceptionIfErrorsExist();
    if (injectableConstructor != null) {
        return new InjectionPoint(type, injectableConstructor);
    }
    // If no annotated constructor is found, look for a no-arg constructor instead.
    try {
        Constructor<?> noArgConstructor = rawType.getConstructor();
        // Disallow private constructors on non-private classes (unless they have @Inject)
        if (Modifier.isPrivate(noArgConstructor.getModifiers()) && !Modifier.isPrivate(rawType.getModifiers())) {
            errors.missingConstructor(rawType);
            throw new ConfigurationException(errors.getMessages());
        }
        checkForMisplacedBindingAnnotations(noArgConstructor, errors);
        return new InjectionPoint(type, noArgConstructor);
    } catch (NoSuchMethodException e) {
        errors.missingConstructor(rawType);
        throw new ConfigurationException(errors.getMessages());
    }
}
Also used : Inject(org.elasticsearch.common.inject.Inject) Errors(org.elasticsearch.common.inject.internal.Errors) ConfigurationException(org.elasticsearch.common.inject.ConfigurationException)

Example 7 with ConfigurationException

use of org.elasticsearch.common.inject.ConfigurationException in project crate by crate.

the class SQLIntegrationTestCase method systemExecute.

/**
 * Execute a SQL statement as system query on a specific node in the cluster
 *
 * @param stmt      the SQL statement
 * @param schema    the schema that should be used for this statement
 *                  schema is nullable, which means the default schema ("doc") is used
 * @param node      the name of the node on which the stmt is executed
 * @return          the SQL Response
 */
public SQLResponse systemExecute(String stmt, @Nullable String schema, String node) {
    SQLOperations sqlOperations = internalCluster().getInstance(SQLOperations.class, node);
    UserLookup userLookup;
    try {
        userLookup = internalCluster().getInstance(UserLookup.class, node);
    } catch (ConfigurationException ignored) {
        // If enterprise is not enabled there is no UserLookup instance bound in guice
        userLookup = userName -> User.CRATE_USER;
    }
    try (Session session = sqlOperations.createSession(schema, userLookup.findUser("crate"))) {
        response = sqlExecutor.exec(stmt, session);
    }
    return response;
}
Also used : ParamTypeHints(io.crate.analyze.ParamTypeHints) SessionContext(io.crate.action.sql.SessionContext) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) SessionSettings(io.crate.metadata.settings.SessionSettings) Matchers.not(org.hamcrest.Matchers.not) Inherited(java.lang.annotation.Inherited) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Analyzer(io.crate.analyze.Analyzer) NodeLimits(io.crate.execution.jobs.NodeLimits) DependencyCarrier(io.crate.planner.DependencyCarrier) Functions(io.crate.metadata.Functions) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) SQLTransportExecutor(io.crate.testing.SQLTransportExecutor) RandomStrings(com.carrotsearch.randomizedtesting.generators.RandomStrings) TableInfo(io.crate.metadata.table.TableInfo) RandomizedContext(com.carrotsearch.randomizedtesting.RandomizedContext) TasksService(io.crate.execution.jobs.TasksService) Logger(org.apache.logging.log4j.Logger) Row(io.crate.data.Row) SubQueryResults(io.crate.planner.operators.SubQueryResults) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) Matchers.is(org.hamcrest.Matchers.is) XContentFactory(org.elasticsearch.common.xcontent.XContentFactory) ClusterService(org.elasticsearch.cluster.service.ClusterService) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) Metadata(org.elasticsearch.cluster.metadata.Metadata) TestName(org.junit.rules.TestName) Timeout(org.junit.rules.Timeout) IndicesService(org.elasticsearch.indices.IndicesService) Nullable(javax.annotation.Nullable) PSQL_PORT_SETTING(io.crate.protocols.postgres.PostgresNetty.PSQL_PORT_SETTING) Before(org.junit.Before) Identifiers(io.crate.sql.Identifiers) Client(org.elasticsearch.client.Client) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IOException(java.io.IOException) Planner(io.crate.planner.Planner) Field(java.lang.reflect.Field) RoutingProvider(io.crate.metadata.RoutingProvider) Literal(io.crate.expression.symbol.Literal) PlannerContext(io.crate.planner.PlannerContext) Matcher(org.hamcrest.Matcher) Plan(io.crate.planner.Plan) PostgresNetty(io.crate.protocols.postgres.PostgresNetty) KillableCallable(io.crate.execution.jobs.kill.KillableCallable) Schemas(io.crate.metadata.Schemas) UseJdbc(io.crate.testing.UseJdbc) Randomness(org.elasticsearch.common.Randomness) TransportShardAction(io.crate.execution.dml.TransportShardAction) TransportShardUpsertAction(io.crate.execution.dml.upsert.TransportShardUpsertAction) RelationName(io.crate.metadata.RelationName) UseRandomizedSchema(io.crate.testing.UseRandomizedSchema) Random(java.util.Random) RootTask(io.crate.execution.jobs.RootTask) UseHashJoins(io.crate.testing.UseHashJoins) Settings(org.elasticsearch.common.settings.Settings) TestGroup(com.carrotsearch.randomizedtesting.annotations.TestGroup) Locale(java.util.Locale) After(org.junit.After) Documented(java.lang.annotation.Documented) ThreadPool(org.elasticsearch.threadpool.ThreadPool) Method(java.lang.reflect.Method) SQLOperations(io.crate.action.sql.SQLOperations) NodeContext(io.crate.metadata.NodeContext) User(io.crate.user.User) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UUID(java.util.UUID) Netty4Plugin(org.elasticsearch.transport.Netty4Plugin) InetSocketAddress(java.net.InetSocketAddress) Lists2(io.crate.common.collections.Lists2) List(java.util.List) Session(io.crate.action.sql.Session) ESIntegTestCase(org.elasticsearch.test.ESIntegTestCase) Symbol(io.crate.expression.symbol.Symbol) FunctionImplementation(io.crate.metadata.FunctionImplementation) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Annotation(java.lang.annotation.Annotation) TimeValue(io.crate.common.unit.TimeValue) Paging(io.crate.data.Paging) TestingRowConsumer(io.crate.testing.TestingRowConsumer) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) UserLookup(io.crate.user.UserLookup) SQLResponse(io.crate.testing.SQLResponse) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) TransportShardDeleteAction(io.crate.execution.dml.delete.TransportShardDeleteAction) SearchPath(io.crate.metadata.SearchPath) Index(org.elasticsearch.index.Index) SETTING_HTTP_COMPRESSION(org.elasticsearch.http.HttpTransportSettings.SETTING_HTTP_COMPRESSION) TaskId(org.elasticsearch.tasks.TaskId) Retention(java.lang.annotation.Retention) Strings(org.elasticsearch.common.Strings) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException) Constants(io.crate.Constants) Symbols(io.crate.expression.symbol.Symbols) SqlParser(io.crate.sql.parser.SqlParser) Requests(org.elasticsearch.client.Requests) Listeners(com.carrotsearch.randomizedtesting.annotations.Listeners) TestExecutionConfig(io.crate.testing.TestExecutionConfig) ColumnIdent(io.crate.metadata.ColumnIdent) Plugin(org.elasticsearch.plugins.Plugin) Matchers(org.hamcrest.Matchers) DataType(io.crate.types.DataType) TimeUnit(java.util.concurrent.TimeUnit) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) Rule(org.junit.Rule) SystemPropsTestLoggingListener(io.crate.test.integration.SystemPropsTestLoggingListener) LogManager(org.apache.logging.log4j.LogManager) ConfigurationException(org.elasticsearch.common.inject.ConfigurationException) RetentionPolicy(java.lang.annotation.RetentionPolicy) ConfigurationException(org.elasticsearch.common.inject.ConfigurationException) UserLookup(io.crate.user.UserLookup) SQLOperations(io.crate.action.sql.SQLOperations) Session(io.crate.action.sql.Session)

Aggregations

ConfigurationException (org.elasticsearch.common.inject.ConfigurationException)7 Errors (org.elasticsearch.common.inject.internal.Errors)6 HashSet (java.util.HashSet)4 Inject (org.elasticsearch.common.inject.Inject)2 RandomizedContext (com.carrotsearch.randomizedtesting.RandomizedContext)1 Listeners (com.carrotsearch.randomizedtesting.annotations.Listeners)1 TestGroup (com.carrotsearch.randomizedtesting.annotations.TestGroup)1 RandomStrings (com.carrotsearch.randomizedtesting.generators.RandomStrings)1 Constants (io.crate.Constants)1 SQLOperations (io.crate.action.sql.SQLOperations)1 Session (io.crate.action.sql.Session)1 SessionContext (io.crate.action.sql.SessionContext)1 Analyzer (io.crate.analyze.Analyzer)1 ParamTypeHints (io.crate.analyze.ParamTypeHints)1 Lists2 (io.crate.common.collections.Lists2)1 TimeValue (io.crate.common.unit.TimeValue)1 Paging (io.crate.data.Paging)1 Row (io.crate.data.Row)1 TransportShardAction (io.crate.execution.dml.TransportShardAction)1 TransportShardDeleteAction (io.crate.execution.dml.delete.TransportShardDeleteAction)1