Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dinky
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangpeng
dinky
Commits
71f6bb92
Unverified
Commit
71f6bb92
authored
Jan 18, 2024
by
gaoyan
Committed by
GitHub
Jan 18, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Fix]Fix yarn application issue (#3025)
Co-authored-by:
gaoyan1998
<
gaoyan1998@users.noreply.github.com
>
parent
ad2b82f5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
17 deletions
+60
-17
Submitter.java
...-base/src/main/java/org/dinky/app/flinksql/Submitter.java
+28
-9
FlinkAppUtil.java
...p-base/src/main/java/org/dinky/app/util/FlinkAppUtil.java
+30
-3
YarnGateway.java
...way/src/main/java/org/dinky/gateway/yarn/YarnGateway.java
+2
-5
No files found.
dinky-app/dinky-app-base/src/main/java/org/dinky/app/flinksql/Submitter.java
View file @
71f6bb92
...
@@ -48,10 +48,12 @@ import org.apache.commons.io.FileUtils;
...
@@ -48,10 +48,12 @@ import org.apache.commons.io.FileUtils;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.flink.configuration.PipelineOptions
;
import
org.apache.flink.configuration.PipelineOptions
;
import
org.apache.flink.configuration.ReadableConfig
;
import
org.apache.flink.configuration.ReadableConfig
;
import
org.apache.flink.core.execution.JobClient
;
import
org.apache.flink.python.PythonOptions
;
import
org.apache.flink.python.PythonOptions
;
import
org.apache.flink.runtime.jobgraph.SavepointConfigOptions
;
import
org.apache.flink.runtime.jobgraph.SavepointConfigOptions
;
import
org.apache.flink.runtime.jobgraph.SavepointRestoreSettings
;
import
org.apache.flink.runtime.jobgraph.SavepointRestoreSettings
;
import
org.apache.flink.streaming.api.graph.StreamGraph
;
import
org.apache.flink.streaming.api.graph.StreamGraph
;
import
org.apache.flink.table.api.TableResult
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.FileOutputStream
;
...
@@ -70,6 +72,7 @@ import java.util.Arrays;
...
@@ -70,6 +72,7 @@ import java.util.Arrays;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -129,15 +132,21 @@ public class Submitter {
...
@@ -129,15 +132,21 @@ public class Submitter {
String
[]
statements
=
String
[]
statements
=
SqlUtil
.
getStatements
(
sql
,
SystemConfiguration
.
getInstances
().
getSqlSeparator
());
SqlUtil
.
getStatements
(
sql
,
SystemConfiguration
.
getInstances
().
getSqlSeparator
());
Optional
<
JobClient
>
jobClient
=
Optional
.
empty
();
try
{
try
{
if
(
Dialect
.
FLINK_JAR
==
appTask
.
getDialect
())
{
if
(
Dialect
.
FLINK_JAR
==
appTask
.
getDialect
())
{
executeJarJob
(
appTask
.
getType
(),
executor
,
statements
);
jobClient
=
executeJarJob
(
appTask
.
getType
(),
executor
,
statements
);
}
else
{
}
else
{
executeJob
(
executor
,
statements
);
jobClient
=
executeJob
(
executor
,
statements
);
}
}
}
finally
{
}
finally
{
log
.
info
(
"Start Monitor Job"
);
log
.
info
(
"Start Monitor Job"
);
FlinkAppUtil
.
monitorFlinkTask
(
Submitter
.
executor
,
config
.
getTaskId
());
if
(
jobClient
.
isPresent
())
{
FlinkAppUtil
.
monitorFlinkTask
(
jobClient
.
get
(),
config
.
getTaskId
());
}
else
{
log
.
error
(
"jobClient is empty, can not monitor job"
);
// FlinkAppUtil.monitorFlinkTask(Submitter.executor, config.getTaskId());
}
}
}
}
}
...
@@ -251,7 +260,9 @@ public class Submitter {
...
@@ -251,7 +260,9 @@ public class Submitter {
}
}
@SneakyThrows
@SneakyThrows
public
static
void
executeJarJob
(
String
type
,
Executor
executor
,
String
[]
statements
)
{
public
static
Optional
<
JobClient
>
executeJarJob
(
String
type
,
Executor
executor
,
String
[]
statements
)
{
Optional
<
JobClient
>
jobClient
=
Optional
.
empty
();
for
(
int
i
=
0
;
i
<
statements
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
statements
.
length
;
i
++)
{
String
sqlStatement
=
executor
.
pretreatStatement
(
statements
[
i
]);
String
sqlStatement
=
executor
.
pretreatStatement
(
statements
[
i
]);
if
(
ExecuteJarParseStrategy
.
INSTANCE
.
match
(
sqlStatement
))
{
if
(
ExecuteJarParseStrategy
.
INSTANCE
.
match
(
sqlStatement
))
{
...
@@ -269,7 +280,8 @@ public class Submitter {
...
@@ -269,7 +280,8 @@ public class Submitter {
streamGraph
.
setSavepointRestoreSettings
(
SavepointRestoreSettings
.
forPath
(
streamGraph
.
setSavepointRestoreSettings
(
SavepointRestoreSettings
.
forPath
(
savePointPath
,
configuration
.
get
(
SavepointConfigOptions
.
SAVEPOINT_IGNORE_UNCLAIMED_STATE
)));
savePointPath
,
configuration
.
get
(
SavepointConfigOptions
.
SAVEPOINT_IGNORE_UNCLAIMED_STATE
)));
}
}
executor
.
getStreamExecutionEnvironment
().
executeAsync
(
streamGraph
);
JobClient
client
=
executor
.
getStreamExecutionEnvironment
().
executeAsync
(
streamGraph
);
jobClient
=
Optional
.
of
(
client
);
break
;
break
;
}
}
if
(
Operations
.
getOperationType
(
sqlStatement
)
==
SqlType
.
ADD
)
{
if
(
Operations
.
getOperationType
(
sqlStatement
)
==
SqlType
.
ADD
)
{
...
@@ -280,9 +292,11 @@ public class Submitter {
...
@@ -280,9 +292,11 @@ public class Submitter {
}
}
}
}
}
}
return
jobClient
;
}
}
public
static
void
executeJob
(
Executor
executor
,
String
[]
statements
)
{
public
static
Optional
<
JobClient
>
executeJob
(
Executor
executor
,
String
[]
statements
)
{
Optional
<
JobClient
>
jobClient
=
Optional
.
empty
();
ExecutorConfig
executorConfig
=
executor
.
getExecutorConfig
();
ExecutorConfig
executorConfig
=
executor
.
getExecutorConfig
();
List
<
StatementParam
>
ddl
=
new
ArrayList
<>();
List
<
StatementParam
>
ddl
=
new
ArrayList
<>();
...
@@ -326,12 +340,15 @@ public class Submitter {
...
@@ -326,12 +340,15 @@ public class Submitter {
}
}
}
}
log
.
info
(
"Executing FlinkSQL statement set: {}"
,
String
.
join
(
FlinkSQLConstant
.
SEPARATOR
,
inserts
));
log
.
info
(
"Executing FlinkSQL statement set: {}"
,
String
.
join
(
FlinkSQLConstant
.
SEPARATOR
,
inserts
));
executor
.
executeStatementSet
(
inserts
);
TableResult
tableResult
=
executor
.
executeStatementSet
(
inserts
);
jobClient
=
tableResult
.
getJobClient
();
log
.
info
(
"Execution succeeded."
);
log
.
info
(
"Execution succeeded."
);
}
else
{
}
else
{
// UseStatementSet defaults to true, where the logic is never executed
StatementParam
item
=
trans
.
get
(
0
);
StatementParam
item
=
trans
.
get
(
0
);
log
.
info
(
"Executing FlinkSQL: {}"
,
item
.
getValue
());
log
.
info
(
"Executing FlinkSQL: {}"
,
item
.
getValue
());
executor
.
executeSql
(
item
.
getValue
());
TableResult
tableResult
=
executor
.
executeSql
(
item
.
getValue
());
jobClient
=
tableResult
.
getJobClient
();
log
.
info
(
"Execution succeeded."
);
log
.
info
(
"Execution succeeded."
);
}
}
}
}
...
@@ -350,12 +367,14 @@ public class Submitter {
...
@@ -350,12 +367,14 @@ public class Submitter {
"The FlinkSQL statement set is being executed: {}"
,
"The FlinkSQL statement set is being executed: {}"
,
String
.
join
(
FlinkSQLConstant
.
SEPARATOR
,
executes
));
String
.
join
(
FlinkSQLConstant
.
SEPARATOR
,
executes
));
try
{
try
{
executor
.
executeAsync
(
executorConfig
.
getJobName
());
JobClient
client
=
executor
.
executeAsync
(
executorConfig
.
getJobName
());
jobClient
=
Optional
.
of
(
client
);
log
.
info
(
"The execution was successful"
);
log
.
info
(
"The execution was successful"
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"Execution failed, {}"
,
e
.
getMessage
(),
e
);
log
.
error
(
"Execution failed, {}"
,
e
.
getMessage
(),
e
);
}
}
}
}
log
.
info
(
"{} The task is successfully submitted"
,
LocalDateTime
.
now
());
log
.
info
(
"{} The task is successfully submitted"
,
LocalDateTime
.
now
());
return
jobClient
;
}
}
}
}
dinky-app/dinky-app-base/src/main/java/org/dinky/app/util/FlinkAppUtil.java
View file @
71f6bb92
...
@@ -28,6 +28,7 @@ import org.apache.flink.client.deployment.StandaloneClusterId;
...
@@ -28,6 +28,7 @@ import org.apache.flink.client.deployment.StandaloneClusterId;
import
org.apache.flink.client.program.rest.RestClusterClient
;
import
org.apache.flink.client.program.rest.RestClusterClient
;
import
org.apache.flink.configuration.Configuration
;
import
org.apache.flink.configuration.Configuration
;
import
org.apache.flink.configuration.ReadableConfig
;
import
org.apache.flink.configuration.ReadableConfig
;
import
org.apache.flink.core.execution.JobClient
;
import
org.apache.flink.runtime.client.JobStatusMessage
;
import
org.apache.flink.runtime.client.JobStatusMessage
;
import
java.util.Collection
;
import
java.util.Collection
;
...
@@ -75,6 +76,28 @@ public class FlinkAppUtil {
...
@@ -75,6 +76,28 @@ public class FlinkAppUtil {
}
}
}
}
public
static
void
monitorFlinkTask
(
JobClient
jobClient
,
int
taskId
)
{
boolean
isRun
=
true
;
String
jobId
=
jobClient
.
getJobID
().
toHexString
();
try
{
while
(
isRun
)
{
String
jobStatus
=
jobClient
.
getJobStatus
().
get
().
toString
();
JobStatus
status
=
JobStatus
.
get
(
jobStatus
);
if
(
status
.
isDone
())
{
sendHook
(
taskId
,
jobId
,
0
);
log
.
info
(
"refesh job status finished, status is {}"
,
status
);
isRun
=
false
;
}
Thread
.
sleep
(
5000
);
}
}
catch
(
Exception
e
)
{
// If an exception is thrown, it will cause the k8s pod to trigger a restart,
// resulting in an inability to exit normally
log
.
error
(
"refesh status failed:"
,
e
);
}
}
/**
/**
* The sendHook method is used to send a Hook request.
* The sendHook method is used to send a Hook request.
* This method sends an HTTP request to notify a specific address about the completion status of a task.
* This method sends an HTTP request to notify a specific address about the completion status of a task.
...
@@ -82,9 +105,9 @@ public class FlinkAppUtil {
...
@@ -82,9 +105,9 @@ public class FlinkAppUtil {
* If sending the request fails, it will be retried up to 30 times with a 1-second interval between each retry.
* If sending the request fails, it will be retried up to 30 times with a 1-second interval between each retry.
* If the retry limit is exceeded, an exception is thrown.
* If the retry limit is exceeded, an exception is thrown.
*/
*/
private
static
void
sendHook
(
int
taskId
,
String
jobId
,
int
reTryCount
)
throws
InterruptedException
{
private
static
void
sendHook
(
int
taskId
,
String
jobId
,
int
reTryCount
)
{
try
{
String
dinkyAddr
=
SystemConfiguration
.
getInstances
().
getDinkyAddr
().
getValue
();
String
dinkyAddr
=
SystemConfiguration
.
getInstances
().
getDinkyAddr
().
getValue
();
try
{
String
url
=
StrFormatter
.
format
(
String
url
=
StrFormatter
.
format
(
"http://{}/api/jobInstance/hookJobDone?taskId={}&jobId={}"
,
dinkyAddr
,
taskId
,
jobId
);
"http://{}/api/jobInstance/hookJobDone?taskId={}&jobId={}"
,
dinkyAddr
,
taskId
,
jobId
);
String
resultStr
=
HttpUtil
.
get
(
url
);
String
resultStr
=
HttpUtil
.
get
(
url
);
...
@@ -97,10 +120,14 @@ public class FlinkAppUtil {
...
@@ -97,10 +120,14 @@ public class FlinkAppUtil {
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
if
(
reTryCount
<
30
)
{
if
(
reTryCount
<
30
)
{
log
.
error
(
"send hook failed,retry later taskId:{},jobId:{},{}"
,
taskId
,
jobId
,
e
.
getMessage
());
log
.
error
(
"send hook failed,retry later taskId:{},jobId:{},{}"
,
taskId
,
jobId
,
e
.
getMessage
());
try
{
Thread
.
sleep
(
1000
);
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
sendHook
(
taskId
,
jobId
,
reTryCount
+
1
);
sendHook
(
taskId
,
jobId
,
reTryCount
+
1
);
}
else
{
}
else
{
throw
new
RuntimeException
(
"Hook Job Done failed, The retry limit is exceeded: "
+
e
.
getMessage
());
log
.
error
(
"Hook Job Done failed to {}, The retry limit is exceeded: {}"
,
dinkyAddr
,
e
.
getMessage
());
}
}
}
}
}
}
...
...
dinky-gateway/src/main/java/org/dinky/gateway/yarn/YarnGateway.java
View file @
71f6bb92
...
@@ -42,7 +42,6 @@ import org.apache.flink.client.program.ClusterClient;
...
@@ -42,7 +42,6 @@ import org.apache.flink.client.program.ClusterClient;
import
org.apache.flink.configuration.CoreOptions
;
import
org.apache.flink.configuration.CoreOptions
;
import
org.apache.flink.configuration.DeploymentOptions
;
import
org.apache.flink.configuration.DeploymentOptions
;
import
org.apache.flink.configuration.GlobalConfiguration
;
import
org.apache.flink.configuration.GlobalConfiguration
;
import
org.apache.flink.configuration.RestOptions
;
import
org.apache.flink.configuration.SecurityOptions
;
import
org.apache.flink.configuration.SecurityOptions
;
import
org.apache.flink.runtime.messages.webmonitor.JobDetails
;
import
org.apache.flink.runtime.messages.webmonitor.JobDetails
;
import
org.apache.flink.runtime.messages.webmonitor.MultipleJobsDetails
;
import
org.apache.flink.runtime.messages.webmonitor.MultipleJobsDetails
;
...
@@ -105,10 +104,8 @@ public abstract class YarnGateway extends AbstractGateway {
...
@@ -105,10 +104,8 @@ public abstract class YarnGateway extends AbstractGateway {
private
void
initConfig
()
{
private
void
initConfig
()
{
final
ClusterConfig
clusterConfig
=
config
.
getClusterConfig
();
final
ClusterConfig
clusterConfig
=
config
.
getClusterConfig
();
configuration
=
GlobalConfiguration
.
loadConfiguration
(
clusterConfig
.
getFlinkConfigPath
());
configuration
=
GlobalConfiguration
.
loadConfiguration
(
if
(!
configuration
.
contains
(
RestOptions
.
PORT
))
{
clusterConfig
.
getFlinkConfigPath
().
trim
());
configuration
.
set
(
RestOptions
.
PORT
,
RestOptions
.
PORT
.
defaultValue
());
}
configuration
.
set
(
CoreOptions
.
CLASSLOADER_RESOLVE_ORDER
,
"parent-first"
);
configuration
.
set
(
CoreOptions
.
CLASSLOADER_RESOLVE_ORDER
,
"parent-first"
);
final
FlinkConfig
flinkConfig
=
config
.
getFlinkConfig
();
final
FlinkConfig
flinkConfig
=
config
.
getFlinkConfig
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment