-
Notifications
You must be signed in to change notification settings - Fork 376
NoSQL: CDI / Quarkus #3135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
NoSQL: CDI / Quarkus #3135
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
persistence/nosql/persistence/cdi/quarkus/build.gradle.kts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| plugins { | ||
| id("org.kordamp.gradle.jandex") | ||
| id("polaris-server") | ||
| } | ||
|
|
||
| description = "Polaris NoSQL persistence, providers for Quarkus." | ||
|
|
||
| dependencies { | ||
| implementation(project(":polaris-persistence-nosql-cdi-common")) | ||
| implementation(project(":polaris-persistence-nosql-api")) | ||
| implementation(project(":polaris-persistence-nosql-inmemory")) | ||
| implementation(project(":polaris-persistence-nosql-mongodb")) | ||
| implementation(project(":polaris-idgen-api")) | ||
| runtimeOnly(project(":polaris-nodes-impl")) | ||
| runtimeOnly(project(":polaris-nodes-store-nosql")) | ||
| runtimeOnly(project(":polaris-persistence-nosql-realms-impl")) | ||
| runtimeOnly(project(":polaris-persistence-nosql-realms-store-nosql")) | ||
| runtimeOnly(project(":polaris-async-vertx")) | ||
| runtimeOnly(project(":polaris-idgen-impl")) | ||
| runtimeOnly(project(":polaris-persistence-nosql-authz-impl")) | ||
| runtimeOnly(project(":polaris-persistence-nosql-authz-store-nosql")) | ||
|
|
||
| compileOnly(platform(libs.micrometer.bom)) | ||
| compileOnly("io.micrometer:micrometer-core") | ||
| compileOnly(platform(libs.opentelemetry.instrumentation.bom.alpha)) | ||
| compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-annotations") | ||
|
|
||
| compileOnly(libs.smallrye.config.core) | ||
|
|
||
| compileOnly(project(":polaris-immutables")) | ||
| annotationProcessor(project(":polaris-immutables", configuration = "processor")) | ||
|
|
||
| implementation(platform(libs.quarkus.bom)) | ||
| implementation("io.quarkus:quarkus-core") | ||
| implementation("io.quarkus:quarkus-mongodb-client") | ||
| runtimeOnly("io.quarkus:quarkus-micrometer") | ||
|
|
||
| implementation(libs.jakarta.ws.rs.api) | ||
|
|
||
| implementation(libs.guava) | ||
| implementation(libs.slf4j.api) | ||
|
|
||
| compileOnly(libs.jakarta.annotation.api) | ||
| compileOnly(libs.jakarta.validation.api) | ||
| compileOnly(libs.jakarta.inject.api) | ||
| compileOnly(libs.jakarta.enterprise.cdi.api) | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
...us/src/main/java/org/apache/polaris/persistence/nosql/quarkus/backend/BackendBuilder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.polaris.persistence.nosql.quarkus.backend; | ||
|
|
||
| import org.apache.polaris.persistence.nosql.api.backend.Backend; | ||
|
|
||
| interface BackendBuilder { | ||
| Backend buildBackend(); | ||
| } |
105 changes: 105 additions & 0 deletions
105
...s/src/main/java/org/apache/polaris/persistence/nosql/quarkus/backend/BackendProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.polaris.persistence.nosql.quarkus.backend; | ||
|
|
||
| import static java.lang.String.format; | ||
|
|
||
| import jakarta.enterprise.context.ApplicationScoped; | ||
| import jakarta.enterprise.inject.Any; | ||
| import jakarta.enterprise.inject.Instance; | ||
| import jakarta.enterprise.inject.Produces; | ||
| import java.util.Optional; | ||
| import org.apache.polaris.persistence.nosql.api.backend.Backend; | ||
| import org.apache.polaris.persistence.nosql.api.backend.BackendConfiguration; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| @ApplicationScoped | ||
| class BackendProvider { | ||
| private static final Logger LOGGER = LoggerFactory.getLogger(BackendProvider.class); | ||
|
|
||
| @Produces | ||
| @ApplicationScoped | ||
| @NotObserved | ||
| Backend backend( | ||
| BackendConfiguration backendConfiguration, @Any Instance<BackendBuilder> backendBuilders) { | ||
|
|
||
| var backendName = | ||
| backendConfiguration | ||
| .backend() | ||
| .orElseThrow( | ||
| () -> | ||
| new IllegalStateException( | ||
| "Mandatory configuration option polaris.persistence.nosql.backend is missing!")); | ||
|
|
||
| var backendBuilder = backendBuilders.select(BackendType.Literal.of(backendName)); | ||
| if (!backendBuilder.isResolvable()) { | ||
| throw new IllegalStateException( | ||
| format( | ||
| "Backend '%s' provided in configuration polaris.persistence.nosql.backend is not available. Available backends: %s", | ||
| backendName, | ||
| backendBuilders | ||
| .handlesStream() | ||
| .map( | ||
| h -> | ||
| h.getBean().getQualifiers().stream() | ||
| .filter(q -> q instanceof BackendType) | ||
| .map(BackendType.class::cast) | ||
| .findFirst() | ||
| .map(BackendType::value)) | ||
| .filter(Optional::isPresent) | ||
| .map(Optional::get) | ||
| .toList())); | ||
| } | ||
| if (backendBuilder.isAmbiguous()) { | ||
| throw new IllegalStateException( | ||
| format( | ||
| "Multiple implementations match the backend name '%s' provided in configuration polaris.persistence.nosql.backend is not available. All available backends: %s", | ||
| backendName, | ||
| backendBuilders | ||
| .handlesStream() | ||
| .map( | ||
| h -> | ||
| h.getBean().getQualifiers().stream() | ||
| .filter(q -> q instanceof BackendType) | ||
| .map(BackendType.class::cast) | ||
| .findFirst() | ||
| .map(BackendType::value)) | ||
| .filter(Optional::isPresent) | ||
| .map(Optional::get) | ||
| .toList())); | ||
| } | ||
| var builder = backendBuilder.get(); | ||
|
|
||
| var backend = builder.buildBackend(); | ||
| try { | ||
| var setupSchemaResult = backend.setupSchema().orElse(""); | ||
| LOGGER.info("Opened new persistence backend '{}' {}", backend.type(), setupSchemaResult); | ||
|
|
||
| return builder.buildBackend(); | ||
| } catch (Exception e) { | ||
| try { | ||
| backend.close(); | ||
| } catch (Exception e2) { | ||
| e.addSuppressed(e2); | ||
| } | ||
| throw e; | ||
| } | ||
| } | ||
| } |
59 changes: 59 additions & 0 deletions
59
...arkus/src/main/java/org/apache/polaris/persistence/nosql/quarkus/backend/BackendType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.polaris.persistence.nosql.quarkus.backend; | ||
|
|
||
| import static java.lang.annotation.ElementType.FIELD; | ||
| import static java.lang.annotation.ElementType.METHOD; | ||
| import static java.lang.annotation.ElementType.PARAMETER; | ||
| import static java.lang.annotation.ElementType.TYPE; | ||
| import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
|
||
| import jakarta.enterprise.util.AnnotationLiteral; | ||
| import jakarta.inject.Qualifier; | ||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Target({TYPE, METHOD, PARAMETER, FIELD}) | ||
| @Retention(RUNTIME) | ||
| @Documented | ||
| @Qualifier | ||
| public @interface BackendType { | ||
| /** Gets the store type. */ | ||
| String value(); | ||
|
|
||
| /** Supports inline instantiation of the {@link BackendType} qualifier. */ | ||
| final class Literal extends AnnotationLiteral<BackendType> implements BackendType { | ||
|
|
||
| private final String value; | ||
|
|
||
| private Literal(String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public static Literal of(String value) { | ||
| return new Literal(value); | ||
| } | ||
|
|
||
| @Override | ||
| public String value() { | ||
| return value; | ||
| } | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
...ain/java/org/apache/polaris/persistence/nosql/quarkus/backend/InMemoryBackendBuilder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.polaris.persistence.nosql.quarkus.backend; | ||
|
|
||
| import jakarta.enterprise.context.ApplicationScoped; | ||
| import org.apache.polaris.persistence.nosql.api.backend.Backend; | ||
| import org.apache.polaris.persistence.nosql.inmemory.InMemoryBackendFactory; | ||
| import org.apache.polaris.persistence.nosql.inmemory.InMemoryConfiguration; | ||
|
|
||
| @BackendType(InMemoryBackendFactory.NAME) | ||
| @ApplicationScoped | ||
| class InMemoryBackendBuilder implements BackendBuilder { | ||
| @Override | ||
| public Backend buildBackend() { | ||
| var factory = new InMemoryBackendFactory(); | ||
| return factory.buildBackend(factory.buildConfiguration(new InMemoryConfiguration() {})); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.