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/07/05 13:33:58 UTC

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

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