-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a containerized mode to the ECM service (#5201)
* Add a containerized mode to the ECM service, which allows assigning specific IPs and ports for communication with the outside world to particular engines in this mode. For instance, a Spark engine requires at least two ports: spark.driver.port and spark.driver.blockManager.port. * Supplement the SQL for database modification * remove code that may cause compilation to fail * improve the linkis_ddl.sql in configmap-init-sql.yaml * Add all parameters from SparkConf.getConf to sparkLauncher. * Add a method addAllConf to SparkConf. * formatted code * Fix the missing ticketId field in the linkis_cg_manager_service_instance within the configmap-init-sql.yaml file. * Fix the missing observe_info field in the linkis_ps_job_history_group_history within the configmap-init-sql.yaml file. * print lm log * add debug log * Add fields(mapping_host, mapping_ports) to the linkis_cg_manager_service_instance for ddl file. * remove debug action --------- Co-authored-by: peacewong <[email protected]>
- Loading branch information
Showing
24 changed files
with
500 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
.../main/java/org/apache/linkis/ecm/core/containerization/enums/MappingPortStrategyName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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.linkis.ecm.core.containerization.enums; | ||
|
||
public enum MappingPortStrategyName { | ||
STATIC("static"); | ||
private String name; | ||
|
||
MappingPortStrategyName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public static MappingPortStrategyName toEnum(String name) { | ||
return MappingPortStrategyName.valueOf(name.toUpperCase()); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...rc/main/java/org/apache/linkis/ecm/core/containerization/strategy/MappingPortContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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.linkis.ecm.core.containerization.strategy; | ||
|
||
import org.apache.linkis.ecm.core.containerization.enums.MappingPortStrategyName; | ||
|
||
public class MappingPortContext { | ||
|
||
public static MappingPortStrategy getInstance(MappingPortStrategyName strategyName) { | ||
switch (strategyName) { | ||
case STATIC: | ||
return new StaticMappingPortStrategy(); | ||
default: | ||
return new StaticMappingPortStrategy(); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...c/main/java/org/apache/linkis/ecm/core/containerization/strategy/MappingPortStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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.linkis.ecm.core.containerization.strategy; | ||
|
||
import java.io.IOException; | ||
|
||
public interface MappingPortStrategy { | ||
int availablePort() throws IOException; | ||
} |
79 changes: 79 additions & 0 deletions
79
.../java/org/apache/linkis/ecm/core/containerization/strategy/StaticMappingPortStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* 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.linkis.ecm.core.containerization.strategy; | ||
|
||
import org.apache.linkis.ecm.core.conf.ContainerizationConf; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
|
||
import java.io.IOException; | ||
import java.net.ServerSocket; | ||
import java.util.Arrays; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class StaticMappingPortStrategy implements MappingPortStrategy { | ||
|
||
private static final AtomicInteger currentIndex = new AtomicInteger(0); | ||
|
||
@Override | ||
public int availablePort() throws IOException { | ||
return getNewPort(10); | ||
} | ||
|
||
public int getNewPort(int retryNum) throws IOException { | ||
int[] portRange = getPortRange(); | ||
if (retryNum == 0) { | ||
throw new IOException( | ||
"No available port in the portRange: " | ||
+ ContainerizationConf.ENGINE_CONN_CONTAINERIZATION_MAPPING_STATTIC_PORT_RANGE() | ||
.getValue()); | ||
} | ||
moveIndex(); | ||
int minPort = portRange[0]; | ||
int newPort = minPort + currentIndex.get() - 1; | ||
ServerSocket socket = null; | ||
try { | ||
socket = new ServerSocket(newPort); | ||
} catch (Exception e) { | ||
return getNewPort(--retryNum); | ||
} finally { | ||
IOUtils.close(socket); | ||
} | ||
return newPort; | ||
} | ||
|
||
private synchronized void moveIndex() { | ||
int poolSize = getPoolSize(); | ||
currentIndex.set(currentIndex.get() % poolSize + 1); | ||
} | ||
|
||
private int[] getPortRange() { | ||
String portRange = | ||
ContainerizationConf.ENGINE_CONN_CONTAINERIZATION_MAPPING_STATTIC_PORT_RANGE().getValue(); | ||
|
||
return Arrays.stream(portRange.split("-")).mapToInt(Integer::parseInt).toArray(); | ||
} | ||
|
||
private int getPoolSize() { | ||
int[] portRange = getPortRange(); | ||
int minPort = portRange[0]; | ||
int maxPort = portRange[1]; | ||
|
||
return maxPort - minPort + 1; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...nn-manager-core/src/main/scala/org/apache/linkis/ecm/core/conf/ContainerizationConf.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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.linkis.ecm.core.conf | ||
|
||
import org.apache.linkis.common.conf.CommonVars | ||
|
||
object ContainerizationConf { | ||
|
||
val ENGINE_CONN_CONTAINERIZATION_MAPPING_STATTIC_PORT_RANGE = | ||
CommonVars("linkis.engine.containerization.static.port.range", "1-65535") | ||
|
||
val ENGINE_CONN_CONTAINERIZATION_ENABLE = | ||
CommonVars("linkis.engine.containerization.enable", false).getValue | ||
|
||
val ENGINE_CONN_CONTAINERIZATION_MAPPING_HOST = | ||
CommonVars("linkis.engine.containerization.mapping.host", "") | ||
|
||
val ENGINE_CONN_CONTAINERIZATION_MAPPING_PORTS = | ||
CommonVars("linkis.engine.containerization.mapping.ports", "") | ||
|
||
val ENGINE_CONN_CONTAINERIZATION_MAPPING_STRATEGY = | ||
CommonVars("linkis.engine.containerization.mapping.strategy", "static") | ||
|
||
// 引擎类型-需要开启的端口数量 | ||
// Engine Type - Number of Ports Required to Be Opened | ||
val ENGINE_CONN_CONTAINERIZATION_ENGINE_LIST = | ||
CommonVars("linkis.engine.containerization.engine.list", "spark-2,") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.