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 {
|
||||
ClientResponse response = getApiClient(getServicePath(appName))
|
||||
.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) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(appName);
|
||||
|
|
|
@ -194,12 +194,16 @@ public class ApiServer {
|
|||
return Response.ok(app).build();
|
||||
} catch (AccessControlException e) {
|
||||
return formatResponse(Status.FORBIDDEN, e.getMessage());
|
||||
} catch (IllegalArgumentException |
|
||||
FileNotFoundException e) {
|
||||
} catch (IllegalArgumentException e) {
|
||||
serviceStatus.setDiagnostics(e.getMessage());
|
||||
serviceStatus.setCode(ERROR_CODE_APP_NAME_INVALID);
|
||||
return Response.status(Status.NOT_FOUND).entity(serviceStatus)
|
||||
.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) {
|
||||
LOG.error("Get service failed: {}", e);
|
||||
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.SliderFileSystem;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -81,11 +82,11 @@ public class ServiceClientTest extends ServiceClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Service getStatus(String appName) {
|
||||
if (appName != null && appName.equals("jenkins")) {
|
||||
public Service getStatus(String appName) throws FileNotFoundException {
|
||||
if ("jenkins".equals(appName)) {
|
||||
return goodServiceStatus;
|
||||
} 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.ServiceState;
|
||||
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.junit.After;
|
||||
import org.junit.Before;
|
||||
|
@ -151,10 +152,17 @@ public class TestApiServer {
|
|||
|
||||
@Test
|
||||
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 ",
|
||||
Response.status(Status.NOT_FOUND).build().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
|
||||
|
@ -163,6 +171,11 @@ public class TestApiServer {
|
|||
assertEquals("Get service is ",
|
||||
Response.status(Status.NOT_FOUND).build().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
|
||||
|
|
|
@ -59,8 +59,13 @@ public class TestApiServiceClient {
|
|||
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
System.out.println("Get was called");
|
||||
if (req.getPathInfo() != null
|
||||
&& req.getPathInfo().contains("nonexistent-app")) {
|
||||
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
} else {
|
||||
resp.setStatus(HttpServletResponse.SC_OK);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
|
||||
|
@ -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
|
||||
public void testStop() {
|
||||
String appName = "example-app";
|
||||
|
|
Loading…
Reference in New Issue