@ -17,18 +17,6 @@
package org.apache.dolphinscheduler.api.python ;
import java.io.IOException ;
import java.net.InetAddress ;
import java.net.UnknownHostException ;
import java.util.Date ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
import java.util.stream.Collectors ;
import javax.annotation.PostConstruct ;
import org.apache.commons.collections.CollectionUtils ;
import org.apache.dolphinscheduler.api.configuration.PythonGatewayConfiguration ;
import org.apache.dolphinscheduler.api.dto.EnvironmentDto ;
import org.apache.dolphinscheduler.api.dto.resources.ResourceComponent ;
@ -72,6 +60,24 @@ import org.apache.dolphinscheduler.dao.mapper.ProjectUserMapper;
import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper ;
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper ;
import org.apache.dolphinscheduler.spi.enums.ResourceType ;
import py4j.GatewayServer ;
import py4j.GatewayServer.GatewayServerBuilder ;
import org.apache.commons.collections.CollectionUtils ;
import org.apache.commons.lang3.StringUtils ;
import java.io.IOException ;
import java.net.InetAddress ;
import java.net.UnknownHostException ;
import java.util.Date ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
import java.util.stream.Collectors ;
import javax.annotation.PostConstruct ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.springframework.beans.factory.annotation.Autowired ;
@ -626,29 +632,27 @@ public class PythonGateway {
@PostConstruct
public void init ( ) {
if ( pythonGatewayConfiguration . get Enabled( ) ) {
if ( pythonGatewayConfiguration . is Enabled( ) ) {
this . start ( ) ;
}
}
private void start ( ) {
GatewayServer server ;
try {
InetAddress gatewayHost = InetAddress . getByName ( pythonGatewayConfiguration . getGatewayServerAddress ( ) ) ;
InetAddress pythonHost = InetAddress . getByName ( pythonGatewayConfiguration . getPythonAddress ( ) ) ;
server = new GatewayServer (
this ,
pythonGatewayConfiguration . getGatewayServerPort ( ) ,
pythonGatewayConfiguration . getPythonPort ( ) ,
gatewayHost ,
pythonHost ,
pythonGatewayConfiguration . getConnectTimeout ( ) ,
pythonGatewayConfiguration . getReadTimeout ( ) ,
null
) ;
GatewayServerBuilder serverBuilder = new GatewayServer . GatewayServerBuilder ( )
. entryPoint ( this )
. javaAddress ( gatewayHost )
. javaPort ( pythonGatewayConfiguration . getGatewayServerPort ( ) )
. connectTimeout ( pythonGatewayConfiguration . getConnectTimeout ( ) )
. readTimeout ( pythonGatewayConfiguration . getReadTimeout ( ) ) ;
if ( ! StringUtils . isEmpty ( pythonGatewayConfiguration . getAuthToken ( ) ) ) {
serverBuilder . authToken ( pythonGatewayConfiguration . getAuthToken ( ) ) ;
}
GatewayServer . turnLoggingOn ( ) ;
logger . info ( "PythonGatewayService started on: " + gatewayHost . toString ( ) ) ;
server . start ( ) ;
serverBuilder . build ( ) . start ( ) ;
} catch ( UnknownHostException e ) {
logger . error ( "exception occurred while constructing PythonGatewayService()." , e ) ;
}