-
Notifications
You must be signed in to change notification settings - Fork 1k
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
KSQL-12955 | Introduce KsqlResourceExtensions for plugins configured externally. #10665
base: 7.6.x
Are you sure you want to change the base?
Changes from all commits
f712e96
8ae966b
986b773
c039955
2189e60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2018 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (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.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.rest.extensions; | ||
|
||
import io.confluent.ksql.rest.server.KsqlRestConfig; | ||
import io.confluent.ksql.util.KsqlConfig; | ||
|
||
public interface KsqlResourceContext { | ||
|
||
KsqlConfig ksqlConfig(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
|
||
KsqlRestConfig ksqlRestConfig(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2018 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (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.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.rest.extensions; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import io.confluent.ksql.rest.server.KsqlRestConfig; | ||
import io.confluent.ksql.util.KsqlConfig; | ||
|
||
public class KsqlResourceContextImpl implements KsqlResourceContext { | ||
|
||
private final KsqlConfig ksqlConfig; | ||
private final KsqlRestConfig ksqlRestConfig; | ||
|
||
@SuppressFBWarnings(value = "EI_EXPOSE_REP2") | ||
public KsqlResourceContextImpl( | ||
final KsqlConfig ksqlConfig, | ||
final KsqlRestConfig restConfig) { | ||
this.ksqlConfig = ksqlConfig; | ||
this.ksqlRestConfig = restConfig; | ||
} | ||
|
||
@Override | ||
@SuppressFBWarnings(value = "EI_EXPOSE_REP") | ||
public KsqlConfig ksqlConfig() { | ||
return ksqlConfig; | ||
} | ||
|
||
@Override | ||
@SuppressFBWarnings(value = "EI_EXPOSE_REP") | ||
public KsqlRestConfig ksqlRestConfig() { | ||
return ksqlRestConfig; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2018 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (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.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.rest.extensions; | ||
|
||
import io.confluent.ksql.util.KsqlException; | ||
import java.io.Closeable; | ||
|
||
public interface KsqlResourceExtension extends Closeable { | ||
|
||
void register(KsqlResourceContext ksqlResourceContext) throws KsqlException; | ||
hrishabhg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,9 @@ | |
import io.confluent.ksql.rest.entity.KsqlEntityList; | ||
import io.confluent.ksql.rest.entity.SourceInfo; | ||
import io.confluent.ksql.rest.entity.StreamsList; | ||
import io.confluent.ksql.rest.extensions.KsqlResourceContext; | ||
import io.confluent.ksql.rest.extensions.KsqlResourceContextImpl; | ||
import io.confluent.ksql.rest.extensions.KsqlResourceExtension; | ||
import io.confluent.ksql.rest.server.HeartbeatAgent.Builder; | ||
import io.confluent.ksql.rest.server.computation.Command; | ||
import io.confluent.ksql.rest.server.computation.CommandRunner; | ||
|
@@ -125,6 +128,7 @@ | |
import io.vertx.ext.dropwizard.Match; | ||
import java.io.Console; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.OutputStreamWriter; | ||
import java.io.PrintWriter; | ||
import java.net.MalformedURLException; | ||
|
@@ -211,6 +215,7 @@ public final class KsqlRestApplication implements Executable { | |
private KafkaTopicClient internalTopicClient; | ||
private final Instant ksqlRestAppStartTime; | ||
private final KsqlRestApplicationMetrics restApplicationMetrics; | ||
private final List<KsqlResourceExtension> ksqlResourceExtensions; | ||
|
||
// The startup thread that can be interrupted if necessary during shutdown. This should only | ||
// happen if startup hangs. | ||
|
@@ -279,7 +284,8 @@ public static SourceName getCommandsStreamName() { | |
this.vertx = requireNonNull(vertx, "vertx"); | ||
this.denyListPropertyValidator = | ||
requireNonNull(denyListPropertyValidator, "denyListPropertyValidator"); | ||
|
||
this.ksqlResourceExtensions = new KsqlRestConfig(ksqlConfigNoPort.originals()) | ||
.getKsqlResourceExtensions(); | ||
this.serverInfoResource = | ||
new ServerInfoResource(serviceContext, ksqlConfigNoPort, commandRunner); | ||
if (heartbeatAgent.isPresent()) { | ||
|
@@ -313,6 +319,24 @@ public static SourceName getCommandsStreamName() { | |
@Override | ||
public void startAsync() { | ||
log.debug("Starting the ksqlDB API server"); | ||
|
||
final KsqlResourceContext ksqlResourceContext | ||
= new KsqlResourceContextImpl(ksqlConfigNoPort, restConfig); | ||
|
||
boolean isFipsValidatorConfigured = false; | ||
for (KsqlResourceExtension resourceExtension : ksqlResourceExtensions) { | ||
resourceExtension.register(ksqlResourceContext); | ||
if (KsqlConstants.FIPS_VALIDATOR | ||
.equals(resourceExtension.getClass().getCanonicalName())) { | ||
isFipsValidatorConfigured = true; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can get rid of FIPS Specific checks. We can move tests related to that to confluent-security-plugins itself. |
||
} | ||
if (ksqlConfigNoPort.enableFips() && !isFipsValidatorConfigured) { | ||
throw new KsqlException("Error enabling the FIPS resource extension: `enable.fips` is set" | ||
+ " to true but the `ksql.resource.extension.class` config is either not configured" | ||
+ " or does not contain \"" + KsqlConstants.FIPS_VALIDATOR + "\""); | ||
} | ||
|
||
this.serverMetadataResource = ServerMetadataResource.create(serviceContext, ksqlConfigNoPort); | ||
final StatementParser statementParser = new StatementParser(ksqlEngine); | ||
final Optional<KsqlAuthorizationValidator> authorizationValidator = | ||
|
@@ -509,6 +533,14 @@ public void shutdown() { | |
} | ||
}); | ||
|
||
ksqlResourceExtensions.forEach(resourceExtension -> { | ||
try { | ||
resourceExtension.close(); | ||
} catch (IOException e) { | ||
log.error("Exception while closing resource extension", e); | ||
} | ||
}); | ||
|
||
try { | ||
ksqlEngine.close(); | ||
} catch (final Exception e) { | ||
|
@@ -612,9 +644,9 @@ public static KsqlRestApplication buildApplication( | |
final FunctionRegistry functionRegistry, | ||
final Instant ksqlRestAppStartTime | ||
) { | ||
|
||
final Map<String, Object> updatedRestProps = restConfig.getOriginals(); | ||
final KsqlConfig ksqlConfig = new KsqlConfig(restConfig.getKsqlConfigProperties()); | ||
|
||
final Vertx vertx = Vertx.vertx( | ||
new VertxOptions() | ||
.setMaxWorkerExecuteTimeUnit(TimeUnit.MILLISECONDS) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ | |
import io.confluent.ksql.services.KafkaTopicClient; | ||
import io.confluent.ksql.services.ServiceContext; | ||
import io.confluent.ksql.util.KsqlConfig; | ||
import io.confluent.ksql.util.KsqlException; | ||
import io.confluent.ksql.version.metrics.VersionCheckerAgent; | ||
import io.vertx.core.Handler; | ||
import io.vertx.core.Vertx; | ||
|
@@ -76,6 +77,7 @@ | |
import org.apache.kafka.common.metrics.MetricsReporter; | ||
import org.apache.kafka.streams.StreamsConfig; | ||
import org.junit.Before; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.ArgumentCaptor; | ||
|
@@ -379,6 +381,17 @@ public void shouldConfigureRocksDBConfigSetter() { | |
verify(rocksDBConfigSetterHandler).accept(ksqlConfig); | ||
} | ||
|
||
@Ignore | ||
@Test(expected = KsqlException.class) | ||
public void shouldFailIfFipsValidationEnabledButNotConfigured() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can make a generic test.
|
||
// When: | ||
when(ksqlConfig.enableFips()).thenReturn(true); | ||
app.startKsql(ksqlConfig); | ||
|
||
// Then: | ||
// KsqlException | ||
} | ||
|
||
@Test | ||
public void shouldConfigureIQWithInterNodeListenerIfSet() { | ||
// Given: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any benefit of building an interface? Avoid if there is exactly one implementation and in future also, there is no rationale for multiple implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea behind this is to encapsulate a collection of objects that are useful to the ResourceExtension in future.