diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java
index e1980c3a7cc..d665f5d213d 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java
@@ -2746,6 +2746,11 @@ public static boolean isAclEnabled(Configuration conf) {
public static final String DEFAULT_HDFS_LOCATION_FLOW_RUN_COPROCESSOR_JAR =
"/hbase/coprocessor/hadoop-yarn-server-timelineservice.jar";
+ public static final String FLOW_NAME_MAX_SIZE =
+ TIMELINE_SERVICE_PREFIX + "flowname.max-size";
+
+ public static final int FLOW_NAME_DEFAULT_MAX_SIZE = 0;
+
/**
* The name for setting that points to an optional HBase configuration
* (hbase-site.xml file) with settings that will override the ones found on
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/timeline/TimelineUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/timeline/TimelineUtils.java
index 800e8cabb27..9a16d200e62 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/timeline/TimelineUtils.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/timeline/TimelineUtils.java
@@ -24,6 +24,8 @@
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Evolving;
import org.apache.hadoop.conf.Configuration;
@@ -182,6 +184,35 @@ public static String generateFlowNameTag(String flowName) {
return FLOW_NAME_TAG_PREFIX + ":" + flowName;
}
+ /**
+ * Shortens the flow name for the configured size by removing UUID if present.
+ *
+ * @param flowName which has to be shortened
+ * @param conf to resize the flow name
+ * @return shortened flowName
+ */
+ public static String shortenFlowName(String flowName, Configuration conf) {
+ if (flowName == null) {
+ return null;
+ }
+ // remove UUID inside flowname if present
+ flowName = removeUUID(flowName);
+ // resize flowname
+ int length = conf.getInt(YarnConfiguration.FLOW_NAME_MAX_SIZE,
+ YarnConfiguration.FLOW_NAME_DEFAULT_MAX_SIZE);
+ if (length <= 0) {
+ length = flowName.length();
+ }
+ return flowName.substring(0, length);
+ }
+
+ @VisibleForTesting
+ static String removeUUID(String flowName) {
+ flowName = StringUtils.replaceAll(flowName, "-?([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-" +
+ "[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}", "");
+ return flowName;
+ }
+
/**
* Generate flow version tag.
*
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml
index fea635b42bc..98ef8b634b1 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml
@@ -2637,6 +2637,17 @@
+
+
+ Removes the UUID if represent and limit the the flowname length with
+ the given value for ATSv2. In case the value is negative or 0,
+ it only removes the UUID and does not limit the flow name.
+
+ yarn.timeline-service.flowname.max-size
+
+ 0
+
+
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/timeline/TestShortenedFlowName.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/timeline/TestShortenedFlowName.java
new file mode 100644
index 00000000000..d6cdad009cc
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/timeline/TestShortenedFlowName.java
@@ -0,0 +1,50 @@
+/**
+ * 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.hadoop.yarn.util.timeline;
+
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.UUID;
+
+
+public class TestShortenedFlowName {
+
+ private static final String TEST_FLOW_NAME = "TestFlowName";
+
+ @Test
+ public void testRemovingUUID() {
+ String flowName = TEST_FLOW_NAME + "-" + UUID.randomUUID();
+ flowName = TimelineUtils.removeUUID(flowName);
+ Assert.assertEquals(TEST_FLOW_NAME, flowName);
+ }
+
+ @Test
+ public void testShortenedFlowName() {
+ YarnConfiguration conf = new YarnConfiguration();
+ String flowName = TEST_FLOW_NAME + UUID.randomUUID();
+ conf.setInt(YarnConfiguration.FLOW_NAME_MAX_SIZE, 8);
+ String shortenedFlowName = TimelineUtils.shortenFlowName(flowName, conf);
+ Assert.assertEquals("TestFlow", shortenedFlowName);
+ conf.setInt(YarnConfiguration.FLOW_NAME_MAX_SIZE,
+ YarnConfiguration.FLOW_NAME_DEFAULT_MAX_SIZE);
+ shortenedFlowName = TimelineUtils.shortenFlowName(flowName, conf);
+ Assert.assertEquals(TEST_FLOW_NAME, shortenedFlowName);
+ }
+}
\ No newline at end of file
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/TimelineContext.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/TimelineContext.java
index 694b709bd76..50e7e48df59 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/TimelineContext.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/TimelineContext.java
@@ -18,6 +18,10 @@
package org.apache.hadoop.yarn.server.timelineservice;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.util.timeline.TimelineUtils;
+
/**
* Encapsulates timeline context information.
*/
@@ -28,6 +32,7 @@
private String flowName;
private Long flowRunId;
private String appId;
+ private static final Configuration DEFAULT_CONF = new YarnConfiguration();
public TimelineContext() {
this(null, null, null, 0L, null);
@@ -99,7 +104,7 @@ public TimelineContext(String clusterId, String userId, String flowName,
Long flowRunId, String appId) {
this.clusterId = clusterId;
this.userId = userId;
- this.flowName = flowName;
+ this.flowName = TimelineUtils.shortenFlowName(flowName, DEFAULT_CONF);
this.flowRunId = flowRunId;
this.appId = appId;
}
@@ -125,7 +130,7 @@ public String getFlowName() {
}
public void setFlowName(String flow) {
- this.flowName = flow;
+ this.flowName = TimelineUtils.shortenFlowName(flow, DEFAULT_CONF);
}
public Long getFlowRunId() {