Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jettison</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.xml.bind.annotation.XmlAccessType;
Expand Down Expand Up @@ -52,8 +53,11 @@ public class WeightedPolicyInfo {
private static final Logger LOG =
LoggerFactory.getLogger(WeightedPolicyInfo.class);
private static ObjectMapper mapper = new ObjectMapper();
@JsonProperty("routerPolicyWeights")
private Map<SubClusterIdInfo, Float> routerPolicyWeights = new HashMap<>();
@JsonProperty("amrmPolicyWeights")
private Map<SubClusterIdInfo, Float> amrmPolicyWeights = new HashMap<>();
@JsonProperty("headroomAlpha")
private float headroomAlpha;

public WeightedPolicyInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.hadoop.yarn.server.federation.store.records;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.hadoop.classification.InterfaceAudience;
Expand Down Expand Up @@ -55,6 +56,7 @@ public SubClusterIdInfo(SubClusterId subClusterId) {
* Get the sub-cluster identifier as {@link SubClusterId}.
* @return the sub-cluster id.
*/
@JsonProperty("id")
public SubClusterId toId() {
return SubClusterId.newInstance(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.StandbyException;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.yarn.client.ClientRMProxy;
import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
Expand Down Expand Up @@ -86,7 +85,6 @@ public class DefaultRMAdminRequestInterceptor
private static final Logger LOG =
LoggerFactory.getLogger(DefaultRMAdminRequestInterceptor.class);
private ResourceManagerAdministrationProtocol rmAdminProxy;
private UserGroupInformation user = null;

@Override
public void init(String userName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
import org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo;
import org.apache.hadoop.yarn.server.webapp.dao.ContainersInfo;
import org.apache.hadoop.yarn.util.LRUCacheHashMap;
import org.apache.hadoop.yarn.webapp.ForbiddenException;
import org.apache.hadoop.yarn.webapp.dao.ConfInfo;
import org.apache.hadoop.yarn.webapp.dao.SchedConfUpdateInfo;
import org.apache.hadoop.yarn.util.Clock;
Expand Down Expand Up @@ -1001,8 +1002,8 @@ private SubClusterInfo getNodeSubcluster(String nodeId) throws NotFoundException
NodeInfo nodeInfo = null;
for (Entry<SubClusterInfo, NodeInfo> entry : results.entrySet()) {
NodeInfo nodeResponse = entry.getValue();
if (nodeInfo == null || nodeInfo.getLastHealthUpdate() <
nodeResponse.getLastHealthUpdate()) {
if (nodeInfo == null || (nodeResponse != null &&
nodeInfo.getLastHealthUpdate() < nodeResponse.getLastHealthUpdate())) {
subcluster = entry.getKey();
nodeInfo = nodeResponse;
}
Expand Down Expand Up @@ -1137,6 +1138,7 @@ public AppState getAppState(HttpServletRequest hsr, String appId)
}
} catch (YarnException | IllegalArgumentException e) {
LOG.error("getHomeSubClusterInfoByAppId error, applicationId = {}.", appId, e);
return null;
}
return new AppState();
}
Expand Down Expand Up @@ -1385,8 +1387,8 @@ public ActivitiesInfo getActivities(HttpServletRequest hsr, String nodeId,
String groupBy) {
try {
// Check the parameters to ensure that the parameters are not empty
// Validate.checkNotNullAndNotEmpty(nodeId, "nodeId");
// Validate.checkNotNullAndNotEmpty(groupBy, "groupBy");
Validate.checkNotNullAndNotEmpty(nodeId, "nodeId");
Validate.checkNotNullAndNotEmpty(groupBy, "groupBy");

// Query SubClusterInfo according to id,
// if the nodeId cannot get SubClusterInfo, an exception will be thrown directly.
Expand Down Expand Up @@ -3356,11 +3358,22 @@ private <R> Map<SubClusterInfo, R> invokeConcurrent(Collection<SubClusterInfo> c
} catch (Exception e) {
LOG.error("SubCluster {} failed to call {} method.",
info.getSubClusterId(), request.getMethodName(), e);
Throwable cause = e.getCause();
if (cause instanceof YarnException) {
return new SubClusterResult<>(info, null, (YarnException) cause);
}
if (cause instanceof IllegalArgumentException) {
return new SubClusterResult<>(info, null, (IllegalArgumentException) cause);
}
if(cause instanceof ForbiddenException) {
return new SubClusterResult<>(info, null, (ForbiddenException) cause);
}
return new SubClusterResult<>(info, null, e);
}
});
}

Exception lastException = null;
for (int i = 0; i < clusterIds.size(); i++) {
SubClusterInfo subClusterInfo = null;
try {
Expand All @@ -3375,6 +3388,7 @@ private <R> Map<SubClusterInfo, R> invokeConcurrent(Collection<SubClusterInfo> c

Exception exception = result.getException();
if (exception != null) {
lastException = exception;
throw exception;
}
} catch (Throwable e) {
Expand All @@ -3390,6 +3404,13 @@ private <R> Map<SubClusterInfo, R> invokeConcurrent(Collection<SubClusterInfo> c
}
}

if (results.isEmpty() && lastException != null) {
Throwable cause = lastException.getCause();
if (cause != null) {
throw new YarnRuntimeException(cause.getMessage());
}
throw new YarnRuntimeException(lastException.getMessage());
}
return results;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
*/
package org.apache.hadoop.yarn.server.router;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
Expand All @@ -34,9 +36,7 @@
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.webapp.WebAppContext;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import org.junit.jupiter.api.Test;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
Expand Down Expand Up @@ -107,7 +107,7 @@ private void verifyServiceACLsRefresh(ServiceAuthorizationManager manager,
for (Class<?> protocolClass : manager.getProtocolsWithAcls()) {
AccessControlList accessList = manager.getProtocolsAcls(protocolClass);
if (protocolClass == protocol) {
Assert.assertEquals(accessList.getAclString(), aclString);
assertEquals(accessList.getAclString(), aclString);
}
}
}
Expand Down Expand Up @@ -149,42 +149,42 @@ public void testRouterSupportCrossOrigin() throws ServletException, IOException
CrossOriginFilter filter = (CrossOriginFilter) holder.getFilter();

// 1. Simulate [example.com] for access
HttpServletRequest mockReq = Mockito.mock(HttpServletRequest.class);
Mockito.when(mockReq.getHeader("Origin")).thenReturn("example.com");
Mockito.when(mockReq.getHeader("Access-Control-Request-Method")).thenReturn("GET");
Mockito.when(mockReq.getHeader("Access-Control-Request-Headers"))
HttpServletRequest mockReq = mock(HttpServletRequest.class);
when(mockReq.getHeader("Origin")).thenReturn("example.com");
when(mockReq.getHeader("Access-Control-Request-Method")).thenReturn("GET");
when(mockReq.getHeader("Access-Control-Request-Headers"))
.thenReturn("X-Requested-With");

// Objects to verify interactions based on request
HttpServletResponseForRouterTest mockRes = new HttpServletResponseForRouterTest();
FilterChain mockChain = Mockito.mock(FilterChain.class);
FilterChain mockChain = mock(FilterChain.class);

// Object under test
filter.doFilter(mockReq, mockRes, mockChain);

// Why is 5, because when Filter passes,
// CrossOriginFilter will set 5 values to Map
Assert.assertEquals(5, mockRes.getHeaders().size());
assertEquals(5, mockRes.getHeaders().size());
String allowResult = mockRes.getHeader("Access-Control-Allow-Credentials");
Assert.assertEquals("true", allowResult);
assertEquals("true", allowResult);

// 2. Simulate [example.org] for access
HttpServletRequest mockReq2 = Mockito.mock(HttpServletRequest.class);
Mockito.when(mockReq2.getHeader("Origin")).thenReturn("example.org");
Mockito.when(mockReq2.getHeader("Access-Control-Request-Method")).thenReturn("GET");
Mockito.when(mockReq2.getHeader("Access-Control-Request-Headers"))
HttpServletRequest mockReq2 = mock(HttpServletRequest.class);
when(mockReq2.getHeader("Origin")).thenReturn("example.org");
when(mockReq2.getHeader("Access-Control-Request-Method")).thenReturn("GET");
when(mockReq2.getHeader("Access-Control-Request-Headers"))
.thenReturn("X-Requested-With");

// Objects to verify interactions based on request
HttpServletResponseForRouterTest mockRes2 = new HttpServletResponseForRouterTest();
FilterChain mockChain2 = Mockito.mock(FilterChain.class);
FilterChain mockChain2 = mock(FilterChain.class);

// Object under test
filter.doFilter(mockReq2, mockRes2, mockChain2);

// Why is 0, because when the Filter fails,
// CrossOriginFilter will not set any value
Assert.assertEquals(0, mockRes2.getHeaders().size());
assertEquals(0, mockRes2.getHeaders().size());

router.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

package org.apache.hadoop.yarn.server.router;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -37,9 +38,8 @@
import org.apache.hadoop.thirdparty.protobuf.ServiceException;
import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.net.InetAddress;
import java.net.InetSocketAddress;
Expand All @@ -56,7 +56,8 @@ public class TestRouterAuditLogger {
private static final ApplicationId APPID = mock(ApplicationId.class);
private static final SubClusterId SUBCLUSTERID = mock(SubClusterId.class);

@Before public void setUp() throws Exception {
@BeforeEach
public void setUp() throws Exception {
when(APPID.toString()).thenReturn("app_1");
when(SUBCLUSTERID.toString()).thenReturn("sc0");
}
Expand Down Expand Up @@ -202,8 +203,8 @@ public TestProtos.EmptyResponseProto ping(
throws ServiceException {
// Ensure clientId is received
byte[] clientId = Server.getClientId();
Assert.assertNotNull(clientId);
Assert.assertEquals(ClientId.BYTE_LENGTH, clientId.length);
assertNotNull(clientId);
assertEquals(ClientId.BYTE_LENGTH, clientId.length);
// test with ip set
testSuccessLogFormat(true);
testFailureLogFormat(true);
Expand Down
Loading