You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/05/31 08:18:33 UTC

[GitHub] [flink] fsk119 opened a new pull request, #19849: [FLINK-27767][sql-gateway] Introduce Endpoint API and utils

fsk119 opened a new pull request, #19849:
URL: https://github.com/apache/flink/pull/19849

   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   *Introdue Endpoint API and utils to create endpoint.*
   
   
   ## Brief change log
   
     - *Introduce the Endpoint API*
     - *Introduce the Factory to create the endpoint*
     - *Introduce the FactoryUtils to find the EndpointFactory.*
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - *Added tests to create the Mocked endpoint.*
     - *Added negative tests to create the endpoint.*
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (yes / **no**)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (**yes** / no)
     - The serializers: (yes / **no** / don't know)
     - The runtime per-record code paths (performance sensitive): (yes / **no** / don't know)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (yes / **no** / don't know)
     - The S3 file system connector: (yes / **no** / don't know)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (**yes** / no)
     - If yes, how is the feature documented? (not applicable / docs / **JavaDocs** / not documented)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] fsk119 merged pull request #19849: [FLINK-27767][sql-gateway] Introduce Endpoint API and utils

Posted by GitBox <gi...@apache.org>.
fsk119 merged PR #19849:
URL: https://github.com/apache/flink/pull/19849


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wuchong commented on a diff in pull request #19849: [FLINK-27767][sql-gateway] Introduce Endpoint API and utils

Posted by GitBox <gi...@apache.org>.
wuchong commented on code in PR #19849:
URL: https://github.com/apache/flink/pull/19849#discussion_r913715882


##########
flink-table/flink-sql-gateway-api/src/main/java/org/apache/flink/table/gateway/api/endpoint/SqlGatewayEndpointFactoryUtils.java:
##########
@@ -0,0 +1,153 @@
+/*
+ *  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.flink.table.gateway.api.endpoint;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.DelegatingConfiguration;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.factories.FactoryUtil;
+import org.apache.flink.table.factories.FactoryUtil.FactoryHelper;
+import org.apache.flink.table.gateway.api.SqlGatewayService;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/** Util to discover the {@link SqlGatewayEndpoint}. */
+@PublicEvolving
+public class SqlGatewayEndpointFactoryUtils {
+
+    private static final String GATEWAY_ENDPOINT_PREFIX = "sql-gateway.endpoint";
+
+    public static final ConfigOption<List<String>> SQL_GATEWAY_ENDPOINT_TYPE =
+            ConfigOptions.key(String.format("%s.type", GATEWAY_ENDPOINT_PREFIX))
+                    .stringType()
+                    .asList()
+                    .noDefaultValue()
+                    .withDescription("Specify the endpoints that are used.");
+
+    /**
+     * Attempts to discover the appropriate endpoint factory and creates the instance of the
+     * endpoints.
+     */
+    public static List<SqlGatewayEndpoint> createSqlGatewayEndpoint(
+            SqlGatewayService service, Configuration configuration) {
+        List<String> identifiers = configuration.get(SQL_GATEWAY_ENDPOINT_TYPE);
+
+        if (identifiers == null || identifiers.isEmpty()) {
+            throw new ValidationException(
+                    String.format(
+                            "Endpoint options do not contain an option key '%s' for discovering an endpoint.",
+                            SQL_GATEWAY_ENDPOINT_TYPE.key()));
+        }
+        validateSpecifiedEndpointsAreUnique(identifiers);
+
+        List<SqlGatewayEndpoint> endpoints = new ArrayList<>();
+        for (String identifier : identifiers) {
+            final SqlGatewayEndpointFactory factory =
+                    FactoryUtil.discoverFactory(
+                            Thread.currentThread().getContextClassLoader(),
+                            SqlGatewayEndpointFactory.class,
+                            identifier);
+            Configuration endpointConfig =
+                    new DelegatingConfiguration(
+                            configuration,
+                            String.format("%s.%s.", GATEWAY_ENDPOINT_PREFIX, identifier));
+            endpoints.add(
+                    factory.createSqlGatewayEndpoint(
+                            new DefaultSqlGatewayEndpointFactoryContext(service, endpointConfig)));
+        }
+        return endpoints;
+    }
+
+    /**
+     * Creates a utility that helps to validate options for a {@link SqlGatewayEndpointFactory}.
+     *
+     * <p>Note: This utility checks for left-over options in the final step.
+     */
+    public static SqlGatewayEndpointFactoryHelper createSqlGatewayEndpointFactoryHelper(

Review Comment:
   nit: Maybe we can simplify the name to `EndpointFactoryHelper`.



##########
flink-table/flink-sql-gateway-api/src/main/java/org/apache/flink/table/gateway/api/endpoint/SqlGatewayEndpointFactoryUtils.java:
##########
@@ -0,0 +1,153 @@
+/*
+ *  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.flink.table.gateway.api.endpoint;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.DelegatingConfiguration;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.factories.FactoryUtil;
+import org.apache.flink.table.factories.FactoryUtil.FactoryHelper;
+import org.apache.flink.table.gateway.api.SqlGatewayService;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/** Util to discover the {@link SqlGatewayEndpoint}. */
+@PublicEvolving
+public class SqlGatewayEndpointFactoryUtils {
+
+    private static final String GATEWAY_ENDPOINT_PREFIX = "sql-gateway.endpoint";
+
+    public static final ConfigOption<List<String>> SQL_GATEWAY_ENDPOINT_TYPE =
+            ConfigOptions.key(String.format("%s.type", GATEWAY_ENDPOINT_PREFIX))
+                    .stringType()
+                    .asList()
+                    .noDefaultValue()
+                    .withDescription("Specify the endpoints that are used.");
+
+    /**
+     * Attempts to discover the appropriate endpoint factory and creates the instance of the
+     * endpoints.
+     */
+    public static List<SqlGatewayEndpoint> createSqlGatewayEndpoint(
+            SqlGatewayService service, Configuration configuration) {
+        List<String> identifiers = configuration.get(SQL_GATEWAY_ENDPOINT_TYPE);
+
+        if (identifiers == null || identifiers.isEmpty()) {
+            throw new ValidationException(
+                    String.format(
+                            "Endpoint options do not contain an option key '%s' for discovering an endpoint.",
+                            SQL_GATEWAY_ENDPOINT_TYPE.key()));
+        }
+        validateSpecifiedEndpointsAreUnique(identifiers);
+
+        List<SqlGatewayEndpoint> endpoints = new ArrayList<>();
+        for (String identifier : identifiers) {
+            final SqlGatewayEndpointFactory factory =
+                    FactoryUtil.discoverFactory(
+                            Thread.currentThread().getContextClassLoader(),
+                            SqlGatewayEndpointFactory.class,
+                            identifier);
+            Configuration endpointConfig =
+                    new DelegatingConfiguration(
+                            configuration,
+                            String.format("%s.%s.", GATEWAY_ENDPOINT_PREFIX, identifier));
+            endpoints.add(
+                    factory.createSqlGatewayEndpoint(
+                            new DefaultSqlGatewayEndpointFactoryContext(service, endpointConfig)));
+        }
+        return endpoints;
+    }
+
+    /**
+     * Creates a utility that helps to validate options for a {@link SqlGatewayEndpointFactory}.
+     *
+     * <p>Note: This utility checks for left-over options in the final step.
+     */
+    public static SqlGatewayEndpointFactoryHelper createSqlGatewayEndpointFactoryHelper(
+            SqlGatewayEndpointFactory endpointFactory, SqlGatewayEndpointFactory.Context context) {
+        return new SqlGatewayEndpointFactoryHelper(endpointFactory, context.getOptions());
+    }
+
+    // ----------------------------------------------------------------------------------------
+
+    /**
+     * Helper utility for validating all options for a {@link SqlGatewayEndpointFactory}.
+     *
+     * @see #createSqlGatewayEndpointFactoryHelper(SqlGatewayEndpointFactory,
+     *     SqlGatewayEndpointFactory.Context)
+     */
+    public static class SqlGatewayEndpointFactoryHelper
+            extends FactoryHelper<SqlGatewayEndpointFactory> {
+
+        private SqlGatewayEndpointFactoryHelper(
+                SqlGatewayEndpointFactory factory, Map<String, String> configOptions) {
+            super(factory, configOptions);
+        }
+    }
+
+    private static class DefaultSqlGatewayEndpointFactoryContext
+            implements SqlGatewayEndpointFactory.Context {
+
+        private final SqlGatewayService service;
+        private final Configuration configuration;
+
+        public DefaultSqlGatewayEndpointFactoryContext(
+                SqlGatewayService service, Configuration configuration) {
+            this.service = service;
+            this.configuration = configuration;
+        }
+
+        @Override
+        public SqlGatewayService getSqlGatewayService() {
+            return service;
+        }
+
+        @Override
+        public ReadableConfig getConfiguration() {
+            return configuration;
+        }
+
+        @Override
+        public Map<String, String> getOptions() {
+            return configuration.toMap();
+        }
+    }
+
+    private static void validateSpecifiedEndpointsAreUnique(List<String> identifiers) {
+        Set<String> uniqueIdentifiers = new HashSet<>();
+
+        for (String identifier : identifiers) {
+            if (uniqueIdentifiers.contains(identifier)) {
+                throw new ValidationException(
+                        String.format(
+                                "Get the duplicate endpoint identifier: %s. Please keep the specified endpoint identifier unique.",

Review Comment:
   nit: please also mention the configuration in the exception message, otherwise, it's hard for users to figure out what's wrong. 



##########
flink-table/flink-sql-gateway-api/pom.xml:
##########
@@ -46,6 +46,11 @@
             <artifactId>flink-table-api-java-bridge</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.flink</groupId>
+            <artifactId>flink-test-utils-junit</artifactId>
+            <version>${project.version}</version>

Review Comment:
   test scope is enough for the module. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wuchong commented on a diff in pull request #19849: [FLINK-27767][sql-gateway] Introduce Endpoint API and utils

Posted by GitBox <gi...@apache.org>.
wuchong commented on code in PR #19849:
URL: https://github.com/apache/flink/pull/19849#discussion_r913726636


##########
flink-table/flink-sql-gateway-api/src/main/java/org/apache/flink/table/gateway/api/endpoint/SqlGatewayEndpointFactoryUtils.java:
##########
@@ -0,0 +1,153 @@
+/*
+ *  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.flink.table.gateway.api.endpoint;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.DelegatingConfiguration;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.factories.FactoryUtil;
+import org.apache.flink.table.factories.FactoryUtil.FactoryHelper;
+import org.apache.flink.table.gateway.api.SqlGatewayService;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/** Util to discover the {@link SqlGatewayEndpoint}. */
+@PublicEvolving
+public class SqlGatewayEndpointFactoryUtils {
+
+    private static final String GATEWAY_ENDPOINT_PREFIX = "sql-gateway.endpoint";
+
+    public static final ConfigOption<List<String>> SQL_GATEWAY_ENDPOINT_TYPE =
+            ConfigOptions.key(String.format("%s.type", GATEWAY_ENDPOINT_PREFIX))
+                    .stringType()
+                    .asList()
+                    .noDefaultValue()
+                    .withDescription("Specify the endpoints that are used.");
+
+    /**
+     * Attempts to discover the appropriate endpoint factory and creates the instance of the
+     * endpoints.
+     */
+    public static List<SqlGatewayEndpoint> createSqlGatewayEndpoint(
+            SqlGatewayService service, Configuration configuration) {
+        List<String> identifiers = configuration.get(SQL_GATEWAY_ENDPOINT_TYPE);
+
+        if (identifiers == null || identifiers.isEmpty()) {
+            throw new ValidationException(
+                    String.format(
+                            "Endpoint options do not contain an option key '%s' for discovering an endpoint.",
+                            SQL_GATEWAY_ENDPOINT_TYPE.key()));
+        }
+        validateSpecifiedEndpointsAreUnique(identifiers);
+
+        List<SqlGatewayEndpoint> endpoints = new ArrayList<>();
+        for (String identifier : identifiers) {
+            final SqlGatewayEndpointFactory factory =
+                    FactoryUtil.discoverFactory(
+                            Thread.currentThread().getContextClassLoader(),
+                            SqlGatewayEndpointFactory.class,
+                            identifier);
+            Configuration endpointConfig =
+                    new DelegatingConfiguration(

Review Comment:
   Shall we need to delegate all configurations with the endpoint prefix? This disallows the endpoint to access session configurations, such as options in `SqlGatewayServiceConfigOptions` which might be helpful in some cases. 



##########
flink-table/flink-sql-gateway-api/src/main/java/org/apache/flink/table/gateway/api/endpoint/SqlGatewayEndpointFactoryUtils.java:
##########
@@ -0,0 +1,153 @@
+/*
+ *  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.flink.table.gateway.api.endpoint;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.DelegatingConfiguration;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.factories.FactoryUtil;
+import org.apache.flink.table.factories.FactoryUtil.FactoryHelper;
+import org.apache.flink.table.gateway.api.SqlGatewayService;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/** Util to discover the {@link SqlGatewayEndpoint}. */
+@PublicEvolving
+public class SqlGatewayEndpointFactoryUtils {
+
+    private static final String GATEWAY_ENDPOINT_PREFIX = "sql-gateway.endpoint";
+
+    public static final ConfigOption<List<String>> SQL_GATEWAY_ENDPOINT_TYPE =
+            ConfigOptions.key(String.format("%s.type", GATEWAY_ENDPOINT_PREFIX))
+                    .stringType()
+                    .asList()
+                    .noDefaultValue()
+                    .withDescription("Specify the endpoints that are used.");
+
+    /**
+     * Attempts to discover the appropriate endpoint factory and creates the instance of the
+     * endpoints.
+     */
+    public static List<SqlGatewayEndpoint> createSqlGatewayEndpoint(
+            SqlGatewayService service, Configuration configuration) {
+        List<String> identifiers = configuration.get(SQL_GATEWAY_ENDPOINT_TYPE);
+
+        if (identifiers == null || identifiers.isEmpty()) {
+            throw new ValidationException(
+                    String.format(
+                            "Endpoint options do not contain an option key '%s' for discovering an endpoint.",
+                            SQL_GATEWAY_ENDPOINT_TYPE.key()));
+        }
+        validateSpecifiedEndpointsAreUnique(identifiers);
+
+        List<SqlGatewayEndpoint> endpoints = new ArrayList<>();
+        for (String identifier : identifiers) {
+            final SqlGatewayEndpointFactory factory =
+                    FactoryUtil.discoverFactory(
+                            Thread.currentThread().getContextClassLoader(),
+                            SqlGatewayEndpointFactory.class,
+                            identifier);
+            Configuration endpointConfig =
+                    new DelegatingConfiguration(
+                            configuration,
+                            String.format("%s.%s.", GATEWAY_ENDPOINT_PREFIX, identifier));
+            endpoints.add(
+                    factory.createSqlGatewayEndpoint(
+                            new DefaultSqlGatewayEndpointFactoryContext(service, endpointConfig)));
+        }
+        return endpoints;
+    }
+
+    /**
+     * Creates a utility that helps to validate options for a {@link SqlGatewayEndpointFactory}.
+     *
+     * <p>Note: This utility checks for left-over options in the final step.
+     */
+    public static SqlGatewayEndpointFactoryHelper createSqlGatewayEndpointFactoryHelper(
+            SqlGatewayEndpointFactory endpointFactory, SqlGatewayEndpointFactory.Context context) {
+        return new SqlGatewayEndpointFactoryHelper(endpointFactory, context.getOptions());
+    }
+
+    // ----------------------------------------------------------------------------------------
+
+    /**
+     * Helper utility for validating all options for a {@link SqlGatewayEndpointFactory}.
+     *
+     * @see #createSqlGatewayEndpointFactoryHelper(SqlGatewayEndpointFactory,
+     *     SqlGatewayEndpointFactory.Context)
+     */
+    public static class SqlGatewayEndpointFactoryHelper
+            extends FactoryHelper<SqlGatewayEndpointFactory> {
+
+        private SqlGatewayEndpointFactoryHelper(
+                SqlGatewayEndpointFactory factory, Map<String, String> configOptions) {
+            super(factory, configOptions);
+        }
+    }
+
+    private static class DefaultSqlGatewayEndpointFactoryContext
+            implements SqlGatewayEndpointFactory.Context {
+
+        private final SqlGatewayService service;
+        private final Configuration configuration;
+
+        public DefaultSqlGatewayEndpointFactoryContext(
+                SqlGatewayService service, Configuration configuration) {
+            this.service = service;
+            this.configuration = configuration;
+        }
+
+        @Override
+        public SqlGatewayService getSqlGatewayService() {
+            return service;
+        }
+
+        @Override
+        public ReadableConfig getConfiguration() {
+            return configuration;
+        }
+
+        @Override
+        public Map<String, String> getOptions() {
+            return configuration.toMap();
+        }

Review Comment:
   This looks like a design flaw that if `getConfiguration` and `getOptions` are equivalent, then why do we need to provide both of them? 
   
   In DynamicTableFactory, the configuration represents the configs of the session, and options represent the table WITH options. I think we can change the methods to `getFlinkConfiguration()` and `getEndpointOptions()` to make it clear. 
   
   
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] fsk119 commented on a diff in pull request #19849: [FLINK-27767][sql-gateway] Introduce Endpoint API and utils

Posted by GitBox <gi...@apache.org>.
fsk119 commented on code in PR #19849:
URL: https://github.com/apache/flink/pull/19849#discussion_r904573975


##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/session/SessionManagerTest.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.flink.table.gateway.service.session;
+
+import org.apache.flink.api.common.time.Deadline;
+import org.apache.flink.client.cli.DefaultCLI;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.table.gateway.common.config.SqlGatewayServiceConfigOptions;
+import org.apache.flink.table.gateway.common.session.SessionEnvironment;
+import org.apache.flink.table.gateway.common.session.SessionHandle;
+import org.apache.flink.table.gateway.common.utils.MockedEndpointVersion;
+import org.apache.flink.table.gateway.common.utils.SqlGatewayException;
+import org.apache.flink.table.gateway.service.context.DefaultContext;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.time.Duration;
+import java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/** Test for {@link SessionManager}. */
+public class SessionManagerTest {

Review Comment:
   Thanks for your suggestions. I use Junit5 in the current implementation. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] flinkbot commented on pull request #19849: [FLINK-27767][sql-gateway] Introduce Endpoint API and utils

Posted by GitBox <gi...@apache.org>.
flinkbot commented on PR #19849:
URL: https://github.com/apache/flink/pull/19849#issuecomment-1141816879

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "6dc1f60d73da05dddd6cc86f3a88de17c86fc562",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "6dc1f60d73da05dddd6cc86f3a88de17c86fc562",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 6dc1f60d73da05dddd6cc86f3a88de17c86fc562 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wuchong commented on a diff in pull request #19849: [FLINK-27767][sql-gateway] Introduce Endpoint API and utils

Posted by GitBox <gi...@apache.org>.
wuchong commented on code in PR #19849:
URL: https://github.com/apache/flink/pull/19849#discussion_r913847524


##########
flink-table/flink-sql-gateway-api/src/test/java/org/apache/flink/table/gateway/api/utils/MockedSqlGatewayEndpointFactory.java:
##########
@@ -41,12 +40,14 @@ public class MockedSqlGatewayEndpointFactory implements SqlGatewayEndpointFactor
 
     @Override
     public SqlGatewayEndpoint createSqlGatewayEndpoint(Context context) {
-        ReadableConfig config = context.getConfiguration();
-        SqlGatewayEndpointFactoryUtils.createSqlGatewayEndpointFactoryHelper(this, context)
-                .validate();
+        SqlGatewayEndpointFactoryUtils.EndpointFactoryHelper helper =
+                SqlGatewayEndpointFactoryUtils.createEndpointFactoryHelper(this, context);
+        helper.validate();
 
         return new MockedSqlGatewayEndpoint(
-                config.get(HOST), config.get(PORT), config.getOptional(DESCRIPTION).orElse(null));
+                helper.getOptions().get(HOST),
+                helper.getOptions().get(PORT),
+                helper.getOptions().getOptional(DESCRIPTION).orElse(null));

Review Comment:
   minor: should be `helper.getOptions().get(DESCRIPTION)` to use default value if not present. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] fsk119 commented on a diff in pull request #19849: [FLINK-27767][sql-gateway] Introduce Endpoint API and utils

Posted by GitBox <gi...@apache.org>.
fsk119 commented on code in PR #19849:
URL: https://github.com/apache/flink/pull/19849#discussion_r913804622


##########
flink-table/flink-sql-gateway-api/src/main/java/org/apache/flink/table/gateway/api/endpoint/SqlGatewayEndpointFactoryUtils.java:
##########
@@ -0,0 +1,153 @@
+/*
+ *  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.flink.table.gateway.api.endpoint;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.DelegatingConfiguration;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.factories.FactoryUtil;
+import org.apache.flink.table.factories.FactoryUtil.FactoryHelper;
+import org.apache.flink.table.gateway.api.SqlGatewayService;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/** Util to discover the {@link SqlGatewayEndpoint}. */
+@PublicEvolving
+public class SqlGatewayEndpointFactoryUtils {
+
+    private static final String GATEWAY_ENDPOINT_PREFIX = "sql-gateway.endpoint";
+
+    public static final ConfigOption<List<String>> SQL_GATEWAY_ENDPOINT_TYPE =
+            ConfigOptions.key(String.format("%s.type", GATEWAY_ENDPOINT_PREFIX))
+                    .stringType()
+                    .asList()
+                    .noDefaultValue()
+                    .withDescription("Specify the endpoints that are used.");
+
+    /**
+     * Attempts to discover the appropriate endpoint factory and creates the instance of the
+     * endpoints.
+     */
+    public static List<SqlGatewayEndpoint> createSqlGatewayEndpoint(
+            SqlGatewayService service, Configuration configuration) {
+        List<String> identifiers = configuration.get(SQL_GATEWAY_ENDPOINT_TYPE);
+
+        if (identifiers == null || identifiers.isEmpty()) {
+            throw new ValidationException(
+                    String.format(
+                            "Endpoint options do not contain an option key '%s' for discovering an endpoint.",
+                            SQL_GATEWAY_ENDPOINT_TYPE.key()));
+        }
+        validateSpecifiedEndpointsAreUnique(identifiers);
+
+        List<SqlGatewayEndpoint> endpoints = new ArrayList<>();
+        for (String identifier : identifiers) {
+            final SqlGatewayEndpointFactory factory =
+                    FactoryUtil.discoverFactory(
+                            Thread.currentThread().getContextClassLoader(),
+                            SqlGatewayEndpointFactory.class,
+                            identifier);
+            Configuration endpointConfig =
+                    new DelegatingConfiguration(

Review Comment:
   Yes. Currently we have `getFlinkConfiguration` and `getEndpointOptions`now. Users are able to get SqlGatewayService config from `getFlinkConfiguration.`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] fsk119 commented on pull request #19849: [FLINK-27767][sql-gateway] Introduce Endpoint API and utils

Posted by GitBox <gi...@apache.org>.
fsk119 commented on PR #19849:
URL: https://github.com/apache/flink/pull/19849#issuecomment-1176118848

   @flinkbot run azure


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] fsk119 commented on pull request #19849: [FLINK-27767][sql-gateway] Introduce Endpoint API and utils

Posted by GitBox <gi...@apache.org>.
fsk119 commented on PR #19849:
URL: https://github.com/apache/flink/pull/19849#issuecomment-1175985849

   @flinkbot run azure


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] reswqa commented on a diff in pull request #19849: [FLINK-27767][sql-gateway] Introduce Endpoint API and utils

Posted by GitBox <gi...@apache.org>.
reswqa commented on code in PR #19849:
URL: https://github.com/apache/flink/pull/19849#discussion_r896357754


##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/session/SessionManagerTest.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.flink.table.gateway.service.session;
+
+import org.apache.flink.api.common.time.Deadline;
+import org.apache.flink.client.cli.DefaultCLI;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.table.gateway.common.config.SqlGatewayServiceConfigOptions;
+import org.apache.flink.table.gateway.common.session.SessionEnvironment;
+import org.apache.flink.table.gateway.common.session.SessionHandle;
+import org.apache.flink.table.gateway.common.utils.MockedEndpointVersion;
+import org.apache.flink.table.gateway.common.utils.SqlGatewayException;
+import org.apache.flink.table.gateway.service.context.DefaultContext;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.time.Duration;
+import java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/** Test for {@link SessionManager}. */
+public class SessionManagerTest {

Review Comment:
   A small suggestion: I think we should now use Junit5 and assertj in newly introduced tests.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org