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
14d35e84
Unverified
Commit
14d35e84
authored
Dec 28, 2023
by
ZackYoung
Committed by
GitHub
Dec 28, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Optimize] [Gateway] optimize yarn app submit (#2824)
* optimize_yarn_app_submit * optimize_yarn_app_submit * optimize_yarn_app_submit
parent
dd28f44f
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
129 additions
and
12 deletions
+129
-12
YarnClusterDescriptor.java
...ain/java/org/apache/flink/yarn/YarnClusterDescriptor.java
+1
-0
FlinkJsonUtil.java
...ent-base/src/main/java/org/dinky/utils/FlinkJsonUtil.java
+56
-0
FlinkJsonUtilTest.java
...base/src/test/java/org/dinky/utils/FlinkJsonUtilTest.java
+34
-0
YarnApplicationGateway.java
...n/java/org/dinky/gateway/yarn/YarnApplicationGateway.java
+38
-12
No files found.
dinky-client/dinky-client-1.15/src/main/java/org/apache/flink/yarn/YarnClusterDescriptor.java
View file @
14d35e84
...
@@ -134,6 +134,7 @@ import org.slf4j.LoggerFactory;
...
@@ -134,6 +134,7 @@ import org.slf4j.LoggerFactory;
/** The descriptor with deployment information for deploying a Flink cluster on Yarn. */
/** The descriptor with deployment information for deploying a Flink cluster on Yarn. */
public
class
YarnClusterDescriptor
implements
ClusterDescriptor
<
ApplicationId
>
{
public
class
YarnClusterDescriptor
implements
ClusterDescriptor
<
ApplicationId
>
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
YarnClusterDescriptor
.
class
);
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
YarnClusterDescriptor
.
class
);
public
static
final
String
pathSeparator
=
":"
;
public
static
final
String
pathSeparator
=
":"
;
...
...
dinky-client/dinky-client-base/src/main/java/org/dinky/utils/FlinkJsonUtil.java
0 → 100644
View file @
14d35e84
/*
*
* 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
.
dinky
.
utils
;
import
org.apache.flink.runtime.rest.messages.MessageHeaders
;
import
org.apache.flink.runtime.rest.messages.ResponseBody
;
import
org.apache.flink.runtime.rest.util.RestMapperUtils
;
import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser
;
import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType
;
import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper
;
import
java.util.Collection
;
public
class
FlinkJsonUtil
{
private
static
final
ObjectMapper
objectMapper
=
RestMapperUtils
.
getStrictObjectMapper
();
public
static
<
T
extends
ResponseBody
>
T
toBean
(
String
json
,
MessageHeaders
<?,
T
,
?>
messageHeaders
)
{
final
JavaType
responseType
;
final
Collection
<
Class
<?>>
typeParameters
=
messageHeaders
.
getResponseTypeParameters
();
if
(
typeParameters
.
isEmpty
())
{
responseType
=
objectMapper
.
constructType
(
messageHeaders
.
getResponseClass
());
}
else
{
responseType
=
objectMapper
.
getTypeFactory
()
.
constructParametricType
(
messageHeaders
.
getResponseClass
(),
typeParameters
.
toArray
(
new
Class
<?>[
typeParameters
.
size
()]));
}
try
{
JsonParser
jsonParser
=
objectMapper
.
treeAsTokens
(
objectMapper
.
readTree
(
json
));
JavaType
javaType
=
objectMapper
.
constructType
(
responseType
);
return
objectMapper
.
readValue
(
jsonParser
,
javaType
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"json to flink bean exception."
,
e
);
}
}
}
dinky-client/dinky-client-base/src/test/java/org/dinky/utils/FlinkJsonUtilTest.java
0 → 100644
View file @
14d35e84
/*
*
* 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
.
dinky
.
utils
;
import
org.apache.flink.runtime.rest.messages.JobsOverviewHeaders
;
import
org.junit.Test
;
public
class
FlinkJsonUtilTest
{
@Test
public
void
toBeanTest
()
{
// If successful, the validation is successful
FlinkJsonUtil
.
toBean
(
"{\"jobs\":[{\"jid\":\"495c4e271dc64a4b7e78b8b1eb8d75f5\",\"name\":\"datagen\",\"state\":\"RUNNING\",\"start-time\":1703649915151,\"end-time\":-1,\"duration\":78437474,\"last-modification\":1703649915340,\"tasks\":{\"total\":6,\"created\":0,\"scheduled\":0,\"deploying\":0,\"running\":6,\"finished\":0,\"canceling\":0,\"canceled\":0,\"failed\":0,\"reconciling\":0,\"initializing\":0}},{\"jid\":\"214bbbe27dec4272f18fc3f14e9522b6\",\"name\":\"datagen-1\",\"state\":\"RUNNING\",\"start-time\":1703654026497,\"end-time\":-1,\"duration\":74326128,\"last-modification\":1703654026613,\"tasks\":{\"total\":2,\"created\":0,\"scheduled\":0,\"deploying\":0,\"running\":2,\"finished\":0,\"canceling\":0,\"canceled\":0,\"failed\":0,\"reconciling\":0,\"initializing\":0}}]}"
,
JobsOverviewHeaders
.
getInstance
());
}
}
dinky-gateway/src/main/java/org/dinky/gateway/yarn/YarnApplicationGateway.java
View file @
14d35e84
...
@@ -26,6 +26,7 @@ import org.dinky.gateway.config.AppConfig;
...
@@ -26,6 +26,7 @@ import org.dinky.gateway.config.AppConfig;
import
org.dinky.gateway.enums.GatewayType
;
import
org.dinky.gateway.enums.GatewayType
;
import
org.dinky.gateway.result.GatewayResult
;
import
org.dinky.gateway.result.GatewayResult
;
import
org.dinky.gateway.result.YarnResult
;
import
org.dinky.gateway.result.YarnResult
;
import
org.dinky.utils.FlinkJsonUtil
;
import
org.dinky.utils.LogUtil
;
import
org.dinky.utils.LogUtil
;
import
org.apache.flink.client.deployment.ClusterSpecification
;
import
org.apache.flink.client.deployment.ClusterSpecification
;
...
@@ -33,17 +34,23 @@ import org.apache.flink.client.deployment.application.ApplicationConfiguration;
...
@@ -33,17 +34,23 @@ import org.apache.flink.client.deployment.application.ApplicationConfiguration;
import
org.apache.flink.client.program.ClusterClient
;
import
org.apache.flink.client.program.ClusterClient
;
import
org.apache.flink.client.program.ClusterClientProvider
;
import
org.apache.flink.client.program.ClusterClientProvider
;
import
org.apache.flink.configuration.PipelineOptions
;
import
org.apache.flink.configuration.PipelineOptions
;
import
org.apache.flink.runtime.client.JobStatusMessage
;
import
org.apache.flink.runtime.messages.webmonitor.JobDetails
;
import
org.apache.flink.runtime.messages.webmonitor.MultipleJobsDetails
;
import
org.apache.flink.runtime.rest.messages.JobsOverviewHeaders
;
import
org.apache.flink.yarn.YarnClusterDescriptor
;
import
org.apache.flink.yarn.YarnClusterDescriptor
;
import
org.apache.hadoop.yarn.api.records.ApplicationId
;
import
org.apache.hadoop.yarn.api.records.ApplicationId
;
import
org.apache.hadoop.yarn.api.records.ApplicationReport
;
import
org.apache.hadoop.yarn.api.records.YarnApplicationState
;
import
java.io.File
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
cn.hutool.core.util.ReUtil
;
import
cn.hutool.http.HttpUtil
;
/**
/**
* YarnApplicationGateway
* YarnApplicationGateway
*
*
...
@@ -77,34 +84,53 @@ public class YarnApplicationGateway extends YarnGateway {
...
@@ -77,34 +84,53 @@ public class YarnApplicationGateway extends YarnGateway {
new
ApplicationConfiguration
(
userJarParas
,
appConfig
.
getUserJarMainAppClass
());
new
ApplicationConfiguration
(
userJarParas
,
appConfig
.
getUserJarMainAppClass
());
YarnResult
result
=
YarnResult
.
build
(
getType
());
YarnResult
result
=
YarnResult
.
build
(
getType
());
String
webUrl
;
try
(
YarnClusterDescriptor
yarnClusterDescriptor
=
createYarnClusterDescriptorWithJar
(
udfPathContextHolder
))
{
try
(
YarnClusterDescriptor
yarnClusterDescriptor
=
createYarnClusterDescriptorWithJar
(
udfPathContextHolder
))
{
ClusterClientProvider
<
ApplicationId
>
clusterClientProvider
=
yarnClusterDescriptor
.
deployApplicationCluster
(
ClusterClientProvider
<
ApplicationId
>
clusterClientProvider
=
yarnClusterDescriptor
.
deployApplicationCluster
(
clusterSpecificationBuilder
.
createClusterSpecification
(),
applicationConfiguration
);
clusterSpecificationBuilder
.
createClusterSpecification
(),
applicationConfiguration
);
ClusterClient
<
ApplicationId
>
clusterClient
=
clusterClientProvider
.
getClusterClient
();
ClusterClient
<
ApplicationId
>
clusterClient
=
clusterClientProvider
.
getClusterClient
();
Collection
<
JobStatusMessage
>
jobStatusMessages
=
clusterClient
.
listJobs
().
get
();
int
counts
=
SystemConfiguration
.
getInstances
().
getJobIdWait
();
int
counts
=
SystemConfiguration
.
getInstances
().
getJobIdWait
();
while
(
jobStatusMessages
.
size
()
==
0
&&
counts
>
0
)
{
while
(
yarnClient
.
getApplicationReport
(
clusterClient
.
getClusterId
()).
getYarnApplicationState
()
==
YarnApplicationState
.
ACCEPTED
&&
counts
--
>
0
)
{
Thread
.
sleep
(
1000
);
Thread
.
sleep
(
1000
);
counts
--;
}
jobStatusMessages
=
clusterClient
.
listJobs
().
get
();
ApplicationReport
applicationReport
=
yarnClient
.
getApplicationReport
(
clusterClient
.
getClusterId
());
if
(
jobStatusMessages
.
size
()
>
0
)
{
if
(
applicationReport
.
getYarnApplicationState
()
!=
YarnApplicationState
.
RUNNING
)
{
throw
new
RuntimeException
(
"Yarn application state is not running, please check yarn cluster status."
);
}
webUrl
=
applicationReport
.
getOriginalTrackingUrl
();
final
List
<
JobDetails
>
jobDetailsList
=
new
ArrayList
<>();
while
(
jobDetailsList
.
isEmpty
()
&&
counts
--
>
0
)
{
Thread
.
sleep
(
1000
);
String
url
=
ReUtil
.
replaceAll
(
yarnClient
.
getApplicationReport
(
clusterClient
.
getClusterId
())
.
getTrackingUrl
()
+
JobsOverviewHeaders
.
URL
,
"/+"
,
"/"
);
String
json
=
HttpUtil
.
get
(
url
);
MultipleJobsDetails
jobsDetails
=
FlinkJsonUtil
.
toBean
(
json
,
JobsOverviewHeaders
.
getInstance
());
jobDetailsList
.
addAll
(
jobsDetails
.
getJobs
());
if
(!
jobDetailsList
.
isEmpty
())
{
break
;
break
;
}
}
}
}
if
(
jobStatusMessages
.
size
()
>
0
)
{
if
(
!
jobDetailsList
.
isEmpty
()
)
{
List
<
String
>
jobIds
=
new
ArrayList
<>();
List
<
String
>
jobIds
=
new
ArrayList
<>();
for
(
Job
StatusMessage
jobStatusMessage
:
jobStatusMessages
)
{
for
(
Job
Details
jobDetails
:
jobDetailsList
)
{
jobIds
.
add
(
job
StatusMessage
.
getJobId
().
toHexString
());
jobIds
.
add
(
job
Details
.
getJobId
().
toHexString
());
}
}
result
.
setJids
(
jobIds
);
result
.
setJids
(
jobIds
);
}
}
ApplicationId
applicationId
=
clusterClient
.
getClusterId
();
ApplicationId
applicationId
=
clusterClient
.
getClusterId
();
result
.
setId
(
applicationId
.
toString
());
result
.
setId
(
applicationId
.
toString
());
result
.
setWebURL
(
clusterClient
.
getWebInterfaceURL
()
);
result
.
setWebURL
(
webUrl
);
result
.
success
();
result
.
success
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
result
.
fail
(
LogUtil
.
getError
(
e
));
result
.
fail
(
LogUtil
.
getError
(
e
));
...
...
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