Skip to content

Commit 54f79ce

Browse files
committed
fix junit test.
1 parent c264409 commit 54f79ce

File tree

15 files changed

+647
-12
lines changed

15 files changed

+647
-12
lines changed

BUILDING.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Maven build goals:
163163
YARN Application Timeline Service V2 build options:
164164

165165
YARN Timeline Service v.2 chooses Apache HBase as the primary backing storage. The supported
166-
version of Apache HBase is 2.5.8.
166+
version of Apache HBase is 2.6.1.
167167

168168
Snappy build options:
169169

hadoop-project/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@
222222
<swagger-annotations-version>1.5.4</swagger-annotations-version>
223223
<snakeyaml.version>2.0</snakeyaml.version>
224224
<sshd.version>2.11.0</sshd.version>
225-
<hbase.version>2.5.8-hadoop3</hbase.version>
225+
<hbase.version>2.6.1-hadoop3</hbase.version>
226226
<junit.version>4.13.2</junit.version>
227227
<junit.jupiter.version>5.8.2</junit.jupiter.version>
228228
<junit.vintage.version>5.8.2</junit.vintage.version>

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/FlowRunEntity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import javax.xml.bind.annotation.XmlElement;
2121

22+
import com.fasterxml.jackson.annotation.JsonInclude;
2223
import org.apache.hadoop.classification.InterfaceAudience;
2324
import org.apache.hadoop.classification.InterfaceStability;
2425

@@ -27,6 +28,7 @@
2728
*/
2829
@InterfaceAudience.Public
2930
@InterfaceStability.Unstable
31+
@JsonInclude(JsonInclude.Include.NON_NULL)
3032
public class FlowRunEntity extends HierarchicalTimelineEntity {
3133
public static final String USER_INFO_KEY =
3234
TimelineEntity.SYSTEM_INFO_KEY_PREFIX + "USER";

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineEntity.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.apache.hadoop.yarn.api.records.timelineservice;
1919

20+
import java.time.Instant;
2021
import java.util.HashMap;
2122
import java.util.HashSet;
2223
import java.util.Map;
@@ -31,6 +32,7 @@
3132

3233
import com.fasterxml.jackson.annotation.JsonIgnore;
3334
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
35+
import com.fasterxml.jackson.annotation.JsonInclude;
3436
import org.apache.hadoop.classification.InterfaceAudience;
3537
import org.apache.hadoop.classification.InterfaceStability;
3638
import org.apache.hadoop.yarn.util.TimelineServiceHelper;
@@ -150,7 +152,7 @@ public boolean equals(Object obj) {
150152
private NavigableSet<TimelineEvent> events = new TreeSet<>();
151153
private HashMap<String, Set<String>> isRelatedToEntities = new HashMap<>();
152154
private HashMap<String, Set<String>> relatesToEntities = new HashMap<>();
153-
private Long createdTime;
155+
private Long createdTime = Instant.EPOCH.toEpochMilli();
154156
private long idPrefix;
155157

156158
public TimelineEntity() {

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/writer/TimelineEntitySetWriter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@
4343
public class TimelineEntitySetWriter implements MessageBodyWriter<Set<TimelineEntity>> {
4444

4545
private ObjectMapper objectMapper = new ObjectMapper();
46+
private String timelineEntityType =
47+
"java.util.Set<org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity>";
4648

4749
@Override
4850
public boolean isWriteable(Class<?> type, Type genericType,
4951
Annotation[] annotations, MediaType mediaType) {
50-
return true;
52+
return timelineEntityType.equals(genericType.getTypeName());
5153
}
5254

5355
@Override

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,12 @@
496496
<artifactId>mockito-inline</artifactId>
497497
<scope>test</scope>
498498
</dependency>
499+
500+
<dependency>
501+
<groupId>org.glassfish.jersey.media</groupId>
502+
<artifactId>jersey-media-json-jettison</artifactId>
503+
<scope>test</scope>
504+
</dependency>
499505
</dependencies>
500506

501507
<build>

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/AbstractTimelineReaderHBaseTestBase.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.hadoop.conf.Configuration;
3939
import org.apache.hadoop.hbase.HBaseTestingUtility;
4040
import org.apache.hadoop.yarn.api.records.timelineservice.FlowActivityEntity;
41+
import org.apache.hadoop.yarn.api.records.timelineservice.reader.TimelineEntityReader;
4142
import org.apache.hadoop.yarn.conf.YarnConfiguration;
4243
import org.apache.hadoop.yarn.server.timelineservice.storage.DataGeneratorForTest;
4344
import org.glassfish.jersey.client.ClientConfig;
@@ -107,7 +108,14 @@ protected void addFilters(Configuration conf) {
107108
protected Client createClient() {
108109
final ClientConfig cc = new ClientConfig();
109110
cc.connectorProvider(getHttpURLConnectionFactory());
110-
return ClientBuilder.newClient(cc);
111+
return ClientBuilder.newClient(cc)
112+
.register(TimelineEntityReader.class)
113+
.register(TimelineEntitySetReader.class)
114+
.register(TimelineEntityListReader.class)
115+
.register(FlowActivityEntityReader.class)
116+
.register(FlowRunEntityReader.class)
117+
.register(FlowActivityEntitySetReader.class)
118+
.register(FlowActivityEntityListReader.class);
111119
}
112120

113121
protected Response getResponse(Client client, URI uri)
@@ -130,7 +138,7 @@ protected void verifyHttpResponse(Client client, URI uri, Response.Status status
130138
Response resp = client.target(uri).request(MediaType.APPLICATION_JSON).get();
131139
assertNotNull(resp);
132140
assertTrue("Response from server should have been " + status,
133-
resp.getStatusInfo().getStatusCode() == HttpURLConnection.HTTP_OK);
141+
resp.getStatusInfo().getStatusCode() == status.getStatusCode());
134142
System.out.println("Response is: " + resp.readEntity(String.class));
135143
}
136144

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.yarn.server.timelineservice.reader;
19+
20+
import com.fasterxml.jackson.databind.JsonNode;
21+
import com.fasterxml.jackson.databind.ObjectMapper;
22+
import org.apache.hadoop.yarn.api.records.timelineservice.FlowActivityEntity;
23+
import org.apache.hadoop.yarn.api.records.timelineservice.FlowRunEntity;
24+
import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity;
25+
26+
import javax.ws.rs.Consumes;
27+
import javax.ws.rs.WebApplicationException;
28+
import javax.ws.rs.core.MediaType;
29+
import javax.ws.rs.core.MultivaluedMap;
30+
import javax.ws.rs.ext.MessageBodyReader;
31+
import javax.ws.rs.ext.Provider;
32+
import java.io.IOException;
33+
import java.io.InputStream;
34+
import java.lang.annotation.Annotation;
35+
import java.lang.reflect.Type;
36+
import java.util.ArrayList;
37+
import java.util.List;
38+
import java.util.Map;
39+
40+
/**
41+
* We have defined a dedicated Reader for `List<FlowActivityEntity>`,
42+
* aimed at adapting to the Jersey2 framework
43+
* to ensure that JSON can be converted into `List<FlowActivityEntity>`.
44+
*/
45+
@Provider
46+
@Consumes(MediaType.APPLICATION_JSON)
47+
public class FlowActivityEntityListReader implements MessageBodyReader<List<FlowActivityEntity>> {
48+
49+
private ObjectMapper objectMapper = new ObjectMapper();
50+
private String timelineEntityType =
51+
"java.util.List<org.apache.hadoop.yarn.api.records.timelineservice.FlowActivityEntity>";
52+
53+
@Override
54+
public boolean isReadable(Class<?> type, Type genericType,
55+
Annotation[] annotations, MediaType mediaType) {
56+
return timelineEntityType.equals(genericType.getTypeName());
57+
}
58+
59+
@Override
60+
public List<FlowActivityEntity> readFrom(Class<List<FlowActivityEntity>> type,
61+
Type genericType, Annotation[] annotations, MediaType mediaType,
62+
MultivaluedMap<String, String> httpHeaders,
63+
InputStream entityStream) throws IOException, WebApplicationException {
64+
List<FlowActivityEntity> flowActivityEntityList = new ArrayList<>();
65+
66+
JsonNode jsonNode = objectMapper.readTree(entityStream);
67+
if (jsonNode.isArray()) {
68+
for (JsonNode jNode : jsonNode) {
69+
FlowActivityEntity entity = new FlowActivityEntity();
70+
71+
// Get Identifier
72+
JsonNode jnIdentifier = jNode.get("identifier");
73+
JsonNode jnType = jnIdentifier.get("type");
74+
JsonNode jnId = jnIdentifier.get("id");
75+
TimelineEntity.Identifier identifier = new TimelineEntity.Identifier(jnType.asText(), jnId.asText());
76+
entity.setIdentifier(identifier);
77+
78+
// Get Type
79+
JsonNode jnAppType = jNode.get("type");
80+
entity.setType(jnAppType.asText());
81+
82+
// Get Createdtime
83+
JsonNode jnCreatedTime = jNode.get("createdtime");
84+
entity.setCreatedTime(jnCreatedTime.asLong());
85+
86+
// Get configs
87+
JsonNode jnConfigs = jNode.get("configs");
88+
if (jnConfigs != null) {
89+
Map<String, String> configInfos =
90+
objectMapper.treeToValue(jnConfigs, Map.class);
91+
entity.setConfigs(configInfos);
92+
}
93+
94+
// Get info
95+
JsonNode jnInfos = jNode.get("info");
96+
if (jnInfos != null) {
97+
Map<String, Object> entityInfos =
98+
objectMapper.treeToValue(jnInfos, Map.class);
99+
entity.setInfo(entityInfos);
100+
}
101+
102+
// Get BasicInfo
103+
entity.setDate(jNode.get("date").asLong());
104+
entity.setCluster(jNode.get("cluster").asText());
105+
entity.setUser(jNode.get("user").asText());
106+
entity.setFlowName(jNode.get("flowName").asText());
107+
108+
// Get flowRuns
109+
JsonNode jnflowRuns = jNode.get("flowRuns");
110+
if (jnflowRuns != null) {
111+
for (JsonNode jnflow : jnflowRuns) {
112+
FlowRunEntity flowRunEntity = objectMapper.treeToValue(jnflow, FlowRunEntity.class);
113+
entity.addFlowRun(flowRunEntity);
114+
}
115+
}
116+
flowActivityEntityList.add(entity);
117+
}
118+
}
119+
120+
return flowActivityEntityList;
121+
}
122+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.yarn.server.timelineservice.reader;
19+
20+
import com.fasterxml.jackson.databind.ObjectMapper;
21+
import org.apache.hadoop.yarn.api.records.timelineservice.FlowActivityEntity;
22+
23+
import javax.ws.rs.Consumes;
24+
import javax.ws.rs.WebApplicationException;
25+
import javax.ws.rs.core.MediaType;
26+
import javax.ws.rs.core.MultivaluedMap;
27+
import javax.ws.rs.ext.MessageBodyReader;
28+
import javax.ws.rs.ext.Provider;
29+
import java.io.IOException;
30+
import java.io.InputStream;
31+
import java.lang.annotation.Annotation;
32+
import java.lang.reflect.Type;
33+
34+
/**
35+
* We have defined a dedicated Reader for FlowActivityEntity,
36+
* aimed at adapting to the Jersey2 framework
37+
* to ensure that JSON can be converted into FlowActivityEntity.
38+
*/
39+
@Provider
40+
@Consumes(MediaType.APPLICATION_JSON)
41+
public class FlowActivityEntityReader implements MessageBodyReader<FlowActivityEntity> {
42+
43+
private ObjectMapper objectMapper = new ObjectMapper();
44+
45+
@Override
46+
public boolean isReadable(Class<?> type, Type genericType,
47+
Annotation[] annotations, MediaType mediaType) {
48+
return type == FlowActivityEntity.class;
49+
}
50+
51+
@Override
52+
public FlowActivityEntity readFrom(Class<FlowActivityEntity> type, Type genericType,
53+
Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders,
54+
InputStream entityStream) throws IOException, WebApplicationException {
55+
try {
56+
FlowActivityEntity timelineEntity = objectMapper.readValue(entityStream, FlowActivityEntity.class);
57+
return timelineEntity;
58+
} catch (Exception e) {
59+
return new FlowActivityEntity();
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)