GOODBOY008 commented on code in PR #2862: URL: https://github.com/apache/incubator-streampark/pull/2862#discussion_r1285479745
########## streampark-test-utils/streampark-testcontainer/src/main/java/org/apache/streampark/testcontainer/flink/FlinkStandaloneSessionCluster.java: ########## @@ -0,0 +1,184 @@ +/* + * 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.testcontainer.flink; + +import org.apache.streampark.common.util.Utils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.Network; +import org.testcontainers.containers.output.Slf4jLogConsumer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.lifecycle.Startable; +import org.testcontainers.utility.DockerImageName; + +import javax.annotation.Nullable; + +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; + +import static org.apache.streampark.testcontainer.flink.FlinkComponent.JOBMANAGER; +import static org.apache.streampark.testcontainer.flink.FlinkComponent.TASKMANAGER; + +/** + * Class to start a couple of flink 1-jobmanager & n-taskmanagers. The priority of flinkYamlConfStr + * is the highest. But: The 'jobmanager.rpc.address' is always 'jobmanager'. The 'rest.port' always + * is 8081. + */ +public class FlinkStandaloneSessionCluster implements Startable { + + public static final Logger LOG = LoggerFactory.getLogger(FlinkStandaloneSessionCluster.class); + + public static final Network NETWORK = Network.newNetwork(); + + public static final String JM_RPC_ADDR_KEY = "jobmanager.rpc.address"; + public static final String SLOT_CONF_KEY = "taskmanager.numberOfTaskSlots"; + public static final String SLOT_CONF_FORMAT = String.format("%s: %%s", SLOT_CONF_KEY); + + public static final int BLOB_SERVER_PORT = 6123; + public static final int WEB_PORT = 8081; + + private String yamlConfStr = String.format("%s: %s", JM_RPC_ADDR_KEY, JOBMANAGER.getName()); + + private final FlinkContainer jobManagerContainer; + + private final List<FlinkContainer> taskManagerContainers = new ArrayList<>(); + + private FlinkStandaloneSessionCluster( + DockerImageName dockerImageName, + int taskManagerNum, + int slotsNumPerTm, + @Nullable String yamlConfStr, + Slf4jLogConsumer slf4jLogConsumer) { + + renderJmRpcConfIfNeeded(yamlConfStr); + + renderSlotNumIfNeeded(slotsNumPerTm); + + // Set for JM. + this.jobManagerContainer = + new FlinkContainer( + dockerImageName, JOBMANAGER, NETWORK, this.yamlConfStr, slf4jLogConsumer); + this.jobManagerContainer.addRequiredFixedExposedPorts(BLOB_SERVER_PORT, BLOB_SERVER_PORT); Review Comment: Use fixed port expose will occur port conflicts. Use `addExposedPort` to add expose port and `getMappedPort` get mapped expose port. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
