You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@streampark.apache.org by "Al-assad (via GitHub)" <gi...@apache.org> on 2023/09/12 19:32:06 UTC

[GitHub] [incubator-streampark] Al-assad commented on a diff in pull request #3041: [Feature] [Flink-K8s-V2] Refactor the lifecycle control of Flink session-mode jobs on Kubernetes

Al-assad commented on code in PR #3041:
URL: https://github.com/apache/incubator-streampark/pull/3041#discussion_r1323470604


##########
streampark-flink/streampark-flink-client/streampark-flink-client-core/src/main/scala/org/apache/streampark/flink/client/impl/KubernetesSessionClientV2.scala:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.streampark.flink.client.impl
+
+import org.apache.streampark.common.util.Logger
+import org.apache.streampark.common.zio.ZIOExt.IOOps
+import org.apache.streampark.flink.client.`trait`.KubernetesClientV2Trait
+import org.apache.streampark.flink.client.bean._
+import org.apache.streampark.flink.kubernetes.v2.model.{FlinkSessionJobDef, JobManagerDef, TaskManagerDef}
+import org.apache.streampark.flink.kubernetes.v2.operator.FlinkK8sOperator
+import org.apache.streampark.flink.packer.pipeline.K8sAppModeBuildResponse
+
+import org.apache.commons.lang3.StringUtils
+import org.apache.flink.client.deployment.application.ApplicationConfiguration
+import org.apache.flink.configuration._
+import org.apache.flink.kubernetes.configuration.KubernetesConfigOptions
+import org.apache.flink.runtime.jobgraph.SavepointConfigOptions
+
+import scala.collection.mutable
+import scala.jdk.CollectionConverters.mapAsScalaMapConverter
+import scala.util.{Failure, Success, Try}
+
+object KubernetesSessionClientV2 extends KubernetesClientV2Trait with Logger {
+  @throws[Exception]
+  override def doSubmit(
+      submitRequest: SubmitRequest,
+      flinkConfig: Configuration): SubmitResponse = {
+
+    val richMsg: String => String = s"[flink-submit][appId=${submitRequest.id}] " + _
+
+    submitRequest.checkBuildResult()
+    val buildResult = submitRequest.buildResult.asInstanceOf[K8sAppModeBuildResponse]

Review Comment:
   should be ShadedBuildResponse



##########
streampark-flink/streampark-flink-client/streampark-flink-client-core/src/main/scala/org/apache/streampark/flink/client/impl/KubernetesSessionClientV2.scala:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.streampark.flink.client.impl
+
+import org.apache.streampark.common.util.Logger
+import org.apache.streampark.common.zio.ZIOExt.IOOps
+import org.apache.streampark.flink.client.`trait`.KubernetesClientV2Trait
+import org.apache.streampark.flink.client.bean._
+import org.apache.streampark.flink.kubernetes.v2.model.{FlinkSessionJobDef, JobManagerDef, TaskManagerDef}
+import org.apache.streampark.flink.kubernetes.v2.operator.FlinkK8sOperator
+import org.apache.streampark.flink.packer.pipeline.K8sAppModeBuildResponse
+
+import org.apache.commons.lang3.StringUtils
+import org.apache.flink.client.deployment.application.ApplicationConfiguration
+import org.apache.flink.configuration._
+import org.apache.flink.kubernetes.configuration.KubernetesConfigOptions
+import org.apache.flink.runtime.jobgraph.SavepointConfigOptions
+
+import scala.collection.mutable
+import scala.jdk.CollectionConverters.mapAsScalaMapConverter
+import scala.util.{Failure, Success, Try}
+
+object KubernetesSessionClientV2 extends KubernetesClientV2Trait with Logger {
+  @throws[Exception]
+  override def doSubmit(
+      submitRequest: SubmitRequest,
+      flinkConfig: Configuration): SubmitResponse = {
+
+    val richMsg: String => String = s"[flink-submit][appId=${submitRequest.id}] " + _
+
+    submitRequest.checkBuildResult()
+    val buildResult = submitRequest.buildResult.asInstanceOf[K8sAppModeBuildResponse]
+
+    // Convert to FlinkSessionJobDef CR definition
+    val flinkSessionJobDef = genFlinkSessionJobDef(submitRequest, flinkConfig, buildResult) match {
+      case Right(result) => result
+      case Left(errMsg) =>
+        throw new IllegalArgumentException(
+          richMsg(s"Error occurred while parsing parameters: $errMsg"))
+    }
+
+    // Submit FlinkSessionJobDef CR to Kubernetes
+    FlinkK8sOperator.deploySessionJob(submitRequest.id, flinkSessionJobDef).runIOAsTry match {
+      case Success(_) =>
+        logInfo(richMsg("Flink job has been submitted successfully."))
+      case Failure(err) =>
+        logError(
+          richMsg(s"Submit Flink job fail in ${submitRequest.executionMode.getName}_V2 mode!"),
+          err)
+        throw err
+    }
+
+    SubmitResponse(
+      clusterId = submitRequest.k8sSubmitParam.clusterId,
+      flinkConfig = flinkConfig.toMap,
+      jobId = submitRequest.jobId,
+      jobManagerUrl = null
+    )
+  }
+
+  // Generate FlinkSessionJobDef CR definition, it is a pure effect function.
+  private def genFlinkSessionJobDef(
+      submitReq: SubmitRequest,
+      originFlinkConfig: Configuration,
+      buildResult: K8sAppModeBuildResponse): Either[FailureMessage, FlinkSessionJobDef] = {
+
+    val flinkConfObj = originFlinkConfig.clone()
+
+    val namespace = Option(submitReq.k8sSubmitParam.kubernetesNamespace)
+      .getOrElse("default")
+
+    val name = Option(submitReq.k8sSubmitParam.clusterId)

Review Comment:
   cluster-id is the deployName of FlinkSessionJob CR, not the name of the CR.



-- 
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@streampark.apache.org

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