YARN-7961. Improve status message for YARN service.
Contributed by Gour Saha
(cherry picked from commit 7fe3214d4b
)
This commit is contained in:
parent
cf46533bca
commit
b09af11117
|
@ -479,6 +479,13 @@ public class ApiServiceClient extends AppAdminClient {
|
||||||
try {
|
try {
|
||||||
ClientResponse response = getApiClient(getServicePath(appName))
|
ClientResponse response = getApiClient(getServicePath(appName))
|
||||||
.get(ClientResponse.class);
|
.get(ClientResponse.class);
|
||||||
|
if (response.getStatus() == 404) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(" Service ");
|
||||||
|
sb.append(appName);
|
||||||
|
sb.append(" not found");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
if (response.getStatus() != 200) {
|
if (response.getStatus() != 200) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append(appName);
|
sb.append(appName);
|
||||||
|
|
|
@ -186,7 +186,7 @@ public class ApiServer {
|
||||||
ServiceStatus serviceStatus = new ServiceStatus();
|
ServiceStatus serviceStatus = new ServiceStatus();
|
||||||
try {
|
try {
|
||||||
if (appName == null) {
|
if (appName == null) {
|
||||||
throw new IllegalArgumentException("Service name can not be null.");
|
throw new IllegalArgumentException("Service name cannot be null.");
|
||||||
}
|
}
|
||||||
UserGroupInformation ugi = getProxyUser(request);
|
UserGroupInformation ugi = getProxyUser(request);
|
||||||
LOG.info("GET: getService for appName = {} user = {}", appName, ugi);
|
LOG.info("GET: getService for appName = {} user = {}", appName, ugi);
|
||||||
|
@ -194,12 +194,16 @@ public class ApiServer {
|
||||||
return Response.ok(app).build();
|
return Response.ok(app).build();
|
||||||
} catch (AccessControlException e) {
|
} catch (AccessControlException e) {
|
||||||
return formatResponse(Status.FORBIDDEN, e.getMessage());
|
return formatResponse(Status.FORBIDDEN, e.getMessage());
|
||||||
} catch (IllegalArgumentException |
|
} catch (IllegalArgumentException e) {
|
||||||
FileNotFoundException e) {
|
|
||||||
serviceStatus.setDiagnostics(e.getMessage());
|
serviceStatus.setDiagnostics(e.getMessage());
|
||||||
serviceStatus.setCode(ERROR_CODE_APP_NAME_INVALID);
|
serviceStatus.setCode(ERROR_CODE_APP_NAME_INVALID);
|
||||||
return Response.status(Status.NOT_FOUND).entity(serviceStatus)
|
return Response.status(Status.NOT_FOUND).entity(serviceStatus)
|
||||||
.build();
|
.build();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
serviceStatus.setDiagnostics("Service " + appName + " not found");
|
||||||
|
serviceStatus.setCode(ERROR_CODE_APP_NAME_INVALID);
|
||||||
|
return Response.status(Status.NOT_FOUND).entity(serviceStatus)
|
||||||
|
.build();
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
LOG.error("Get service failed: {}", e);
|
LOG.error("Get service failed: {}", e);
|
||||||
return formatResponse(Status.INTERNAL_SERVER_ERROR, e.getMessage());
|
return formatResponse(Status.INTERNAL_SERVER_ERROR, e.getMessage());
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.apache.hadoop.yarn.service.client.ServiceClient;
|
||||||
import org.apache.hadoop.yarn.service.utils.ServiceApiUtil;
|
import org.apache.hadoop.yarn.service.utils.ServiceApiUtil;
|
||||||
import org.apache.hadoop.yarn.service.utils.SliderFileSystem;
|
import org.apache.hadoop.yarn.service.utils.SliderFileSystem;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -81,11 +82,11 @@ public class ServiceClientTest extends ServiceClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Service getStatus(String appName) {
|
public Service getStatus(String appName) throws FileNotFoundException {
|
||||||
if (appName != null && appName.equals("jenkins")) {
|
if ("jenkins".equals(appName)) {
|
||||||
return goodServiceStatus;
|
return goodServiceStatus;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException();
|
throw new FileNotFoundException("Service " + appName + " not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ import org.apache.hadoop.yarn.service.api.records.Resource;
|
||||||
import org.apache.hadoop.yarn.service.api.records.Service;
|
import org.apache.hadoop.yarn.service.api.records.Service;
|
||||||
import org.apache.hadoop.yarn.service.api.records.ServiceState;
|
import org.apache.hadoop.yarn.service.api.records.ServiceState;
|
||||||
import org.apache.hadoop.yarn.service.api.records.ServiceStatus;
|
import org.apache.hadoop.yarn.service.api.records.ServiceStatus;
|
||||||
|
import org.apache.hadoop.yarn.service.conf.RestApiConstants;
|
||||||
import org.apache.hadoop.yarn.service.webapp.ApiServer;
|
import org.apache.hadoop.yarn.service.webapp.ApiServer;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -151,10 +152,17 @@ public class TestApiServer {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBadGetService() {
|
public void testBadGetService() {
|
||||||
final Response actual = apiServer.getService(request, "no-jenkins");
|
final String serviceName = "nonexistent-jenkins";
|
||||||
|
final Response actual = apiServer.getService(request, serviceName);
|
||||||
assertEquals("Get service is ",
|
assertEquals("Get service is ",
|
||||||
Response.status(Status.NOT_FOUND).build().getStatus(),
|
Response.status(Status.NOT_FOUND).build().getStatus(),
|
||||||
actual.getStatus());
|
actual.getStatus());
|
||||||
|
ServiceStatus serviceStatus = (ServiceStatus) actual.getEntity();
|
||||||
|
assertEquals("Response code don't match",
|
||||||
|
RestApiConstants.ERROR_CODE_APP_NAME_INVALID, serviceStatus.getCode());
|
||||||
|
assertEquals("Response diagnostics don't match",
|
||||||
|
"Service " + serviceName + " not found",
|
||||||
|
serviceStatus.getDiagnostics());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -163,6 +171,11 @@ public class TestApiServer {
|
||||||
assertEquals("Get service is ",
|
assertEquals("Get service is ",
|
||||||
Response.status(Status.NOT_FOUND).build().getStatus(),
|
Response.status(Status.NOT_FOUND).build().getStatus(),
|
||||||
actual.getStatus());
|
actual.getStatus());
|
||||||
|
ServiceStatus serviceStatus = (ServiceStatus) actual.getEntity();
|
||||||
|
assertEquals("Response code don't match",
|
||||||
|
RestApiConstants.ERROR_CODE_APP_NAME_INVALID, serviceStatus.getCode());
|
||||||
|
assertEquals("Response diagnostics don't match",
|
||||||
|
"Service name cannot be null.", serviceStatus.getDiagnostics());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -59,7 +59,12 @@ public class TestApiServiceClient {
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
System.out.println("Get was called");
|
System.out.println("Get was called");
|
||||||
resp.setStatus(HttpServletResponse.SC_OK);
|
if (req.getPathInfo() != null
|
||||||
|
&& req.getPathInfo().contains("nonexistent-app")) {
|
||||||
|
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||||
|
} else {
|
||||||
|
resp.setStatus(HttpServletResponse.SC_OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -139,6 +144,18 @@ public class TestApiServiceClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStatus() {
|
||||||
|
String appName = "nonexistent-app";
|
||||||
|
try {
|
||||||
|
String result = asc.getStatusString(appName);
|
||||||
|
assertEquals("Status reponse don't match",
|
||||||
|
" Service " + appName + " not found", result);
|
||||||
|
} catch (IOException | YarnException e) {
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStop() {
|
public void testStop() {
|
||||||
String appName = "example-app";
|
String appName = "example-app";
|
||||||
|
|
Loading…
Reference in New Issue