wangyang0918 commented on a change in pull request #9965: 
[FLINK-10935][kubernetes]Implement KubeClient with Faric8 Kubernetes clients
URL: https://github.com/apache/flink/pull/9965#discussion_r352455574
 
 

 ##########
 File path: 
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/utils/KubernetesUtils.java
 ##########
 @@ -0,0 +1,291 @@
+/*
+ * 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.kubernetes.utils;
+
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.CoreOptions;
+import org.apache.flink.kubernetes.configuration.KubernetesConfigOptions;
+import org.apache.flink.runtime.clusterframework.BootstrapTools;
+import 
org.apache.flink.runtime.clusterframework.ContaineredTaskManagerParameters;
+
+import io.fabric8.kubernetes.api.model.ConfigMapVolumeSourceBuilder;
+import io.fabric8.kubernetes.api.model.KeyToPath;
+import io.fabric8.kubernetes.api.model.Quantity;
+import io.fabric8.kubernetes.api.model.ResourceRequirements;
+import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder;
+import io.fabric8.kubernetes.api.model.Volume;
+import io.fabric8.kubernetes.api.model.VolumeMount;
+import io.fabric8.kubernetes.api.model.VolumeMountBuilder;
+import org.apache.commons.lang3.StringUtils;
+
+import javax.annotation.Nullable;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.flink.configuration.GlobalConfiguration.FLINK_CONF_FILENAME;
+import static 
org.apache.flink.kubernetes.utils.Constants.CONFIG_FILE_LOG4J_NAME;
+import static 
org.apache.flink.kubernetes.utils.Constants.CONFIG_FILE_LOGBACK_NAME;
+import static org.apache.flink.kubernetes.utils.Constants.CONFIG_MAP_PREFIX;
+import static org.apache.flink.kubernetes.utils.Constants.FLINK_CONF_VOLUME;
+
+/**
+ * Common utils for Kubernetes.
+ */
+public class KubernetesUtils {
+
+       /**
+        * Read file content to string.
+        * @param filePath file path
+        * @return content
+        */
+       public static String getContentFromFile(String filePath) throws 
FileNotFoundException {
+               File file = new File(filePath);
+               if (file.exists()) {
+                       StringBuilder content = new StringBuilder();
+                       String line;
+                       try (BufferedReader reader = new BufferedReader(new 
InputStreamReader(new FileInputStream(file)))){
+                               while ((line = reader.readLine()) != null) {
+                                       
content.append(line).append(System.lineSeparator());
+                               }
+                       } catch (IOException e) {
+                               throw new RuntimeException("Error read file 
content.", e);
+                       }
+                       return content.toString();
+               }
+               throw new FileNotFoundException("File " + filePath + " not 
exists.");
+       }
+
+       /**
+        * Generates the shell command to start a job manager for kubernetes.
+        * @param flinkConfig The Flink configuration.
+        * @param jobManagerMemoryMb JobManager heap size.
+        * @param configDirectory The configuration directory for the 
flink-conf.yaml
+        * @param logDirectory The log directory.
+        * @param hasLogback Uses logback?
+        * @param hasLog4j Uses log4j?
+        * @param mainClass The main class to start with.
+        * @param mainArgs The args for main class.
+        * @return A String containing the job manager startup command.
+        */
+       public static String getJobManagerStartCommand(
 
 Review comment:
   I will try to extract more common codes to a separate method.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to