KarmaGYZ commented on a change in pull request #11854:
URL: https://github.com/apache/flink/pull/11854#discussion_r425548306



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/externalresource/ExternalResourceUtils.java
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.runtime.externalresource;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigUtils;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.ExternalResourceOptions;
+import org.apache.flink.util.StringUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+import static org.apache.flink.configuration.ConfigOptions.key;
+
+/**
+ * Utility class for external resource framework.
+ */
+public class ExternalResourceUtils {
+
+       private static final Logger LOG = 
LoggerFactory.getLogger(ExternalResourceUtils.class);
+
+       private ExternalResourceUtils() {
+               throw new UnsupportedOperationException("This class should 
never be instantiated.");
+       }
+
+       /**
+        * Get the enabled external resource list from configuration.
+        */
+       private static Set<String> getExternalResourceSet(Configuration config) 
{
+               return new HashSet<>(ConfigUtils.decodeListFromConfig(config, 
ExternalResourceOptions.EXTERNAL_RESOURCE_LIST, x -> x));
+       }
+
+       /**
+        * Get the external resources map for Kubernetes. The key should be 
used for deployment specific container request,
+        * and values should be the amount of that resource.
+        */
+       public static Map<String, Long> 
getExternalResourcesForKubernetes(Configuration config) {
+               return getExternalResources(config, 
ExternalResourceOptions.EXTERNAL_RESOURCE_KUBERNETES_CONFIG_KEY_SUFFIX);
+       }
+
+       /**
+        * Get the external resources map for Yarn. The key should be used for 
deployment specific container request,
+        * and values should be the amount of that resource.
+        */
+       public static Map<String, Long> 
getExternalResourcesForYarn(Configuration config) {
+               return getExternalResources(config, 
ExternalResourceOptions.EXTERNAL_RESOURCE_YARN_CONFIG_KEY_SUFFIX);
+       }
+
+       /**
+        * Get the external resources map.
+        */
+       @VisibleForTesting
+       static Map<String, Long> getExternalResources(Configuration config, 
String suffix) {

Review comment:
       I would keep this method for deduplication. But I agreed that 
`getExternalResourcesForYarn` and `getExternalResourcesForKubernetes` should 
belong into the specific modules.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to