Search in sources :

Example 1 with ConfigServerException

use of com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerException in project vespa by vespa-engine.

the class ApplicationApiTest method testErrorResponses.

@Test
public void testErrorResponses() throws Exception {
    ContainerTester tester = new ContainerTester(container, responseFiles);
    tester.updateSystemVersion();
    createAthenzDomainWithAdmin(ATHENZ_TENANT_DOMAIN, USER_ID);
    // PUT (update) non-existing tenant
    tester.assertResponse(request("/application/v4/tenant/tenant1", PUT).userIdentity(USER_ID).data("{\"athensDomain\":\"domain1\", \"property\":\"property1\"}"), "{\"error-code\":\"NOT_FOUND\",\"message\":\"Tenant 'tenant1' does not exist\"}", 404);
    // GET non-existing tenant
    tester.assertResponse(request("/application/v4/tenant/tenant1", GET).userIdentity(USER_ID), "{\"error-code\":\"NOT_FOUND\",\"message\":\"Tenant 'tenant1' does not exist\"}", 404);
    // GET non-existing application
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1", GET).userIdentity(USER_ID), "{\"error-code\":\"NOT_FOUND\",\"message\":\"tenant1.application1 not found\"}", 404);
    // GET non-existing deployment
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1/environment/prod/region/us-east/instance/default", GET).userIdentity(USER_ID), "{\"error-code\":\"NOT_FOUND\",\"message\":\"tenant1.application1 not found\"}", 404);
    // POST (add) a tenant
    tester.assertResponse(request("/application/v4/tenant/tenant1", POST).userIdentity(USER_ID).data("{\"athensDomain\":\"domain1\", \"property\":\"property1\"}").nToken(N_TOKEN), new File("tenant-without-applications.json"));
    // POST (add) another tenant under the same domain
    tester.assertResponse(request("/application/v4/tenant/tenant2", POST).userIdentity(USER_ID).data("{\"athensDomain\":\"domain1\", \"property\":\"property1\"}").nToken(N_TOKEN), "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Could not create tenant 'tenant2': The Athens domain 'domain1' is already connected to tenant 'tenant1'\"}", 400);
    // Add the same tenant again
    tester.assertResponse(request("/application/v4/tenant/tenant1", POST).userIdentity(USER_ID).nToken(N_TOKEN).data("{\"athensDomain\":\"domain1\", \"property\":\"property1\"}"), "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Tenant 'tenant1' already exists\"}", 400);
    // POST (create) an (empty) application
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1", POST).userIdentity(USER_ID).nToken(N_TOKEN), new File("application-reference.json"));
    // Create the same application again
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1", POST).userIdentity(USER_ID), "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Could not create 'tenant1.application1': Application already exists\"}", 400);
    ConfigServerClientMock configServer = (ConfigServerClientMock) container.components().getComponent("com.yahoo.vespa.hosted.controller.ConfigServerClientMock");
    configServer.throwOnNextPrepare(new ConfigServerException(new URI("server-url"), "Failed to prepare application", ConfigServerException.ErrorCode.INVALID_APPLICATION_PACKAGE, null));
    // POST (deploy) an application with an invalid application package
    HttpEntity entity = createApplicationDeployData(applicationPackage, Optional.empty());
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1/environment/dev/region/us-west-1/instance/default/deploy", POST).data(entity).userIdentity(USER_ID), new File("deploy-failure.json"), 400);
    // POST (deploy) an application without available capacity
    configServer.throwOnNextPrepare(new ConfigServerException(new URI("server-url"), "Failed to prepare application", ConfigServerException.ErrorCode.OUT_OF_CAPACITY, null));
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1/environment/dev/region/us-west-1/instance/default/deploy", POST).data(entity).userIdentity(USER_ID), new File("deploy-out-of-capacity.json"), 400);
    // POST (deploy) an application where activation fails
    configServer.throwOnNextPrepare(new ConfigServerException(new URI("server-url"), "Failed to activate application", ConfigServerException.ErrorCode.ACTIVATION_CONFLICT, null));
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1/environment/dev/region/us-west-1/instance/default/deploy", POST).data(entity).userIdentity(USER_ID), new File("deploy-activation-conflict.json"), 409);
    // POST (deploy) an application where we get an internal server error
    configServer.throwOnNextPrepare(new ConfigServerException(new URI("server-url"), "Internal server error", ConfigServerException.ErrorCode.INTERNAL_SERVER_ERROR, null));
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1/environment/dev/region/us-west-1/instance/default/deploy", POST).data(entity).userIdentity(USER_ID), new File("deploy-internal-server-error.json"), 500);
    // DELETE tenant which has an application
    tester.assertResponse(request("/application/v4/tenant/tenant1", DELETE).userIdentity(USER_ID), "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Could not delete tenant 'tenant1': This tenant has active applications\"}", 400);
    // DELETE application
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1", DELETE).userIdentity(USER_ID).nToken(N_TOKEN), "");
    // DELETE application again - should produce 404
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1", DELETE).userIdentity(USER_ID), "{\"error-code\":\"NOT_FOUND\",\"message\":\"Could not delete application 'tenant1.application1': Application not found\"}", 404);
    // DELETE tenant
    tester.assertResponse(request("/application/v4/tenant/tenant1", DELETE).userIdentity(USER_ID).nToken(N_TOKEN), new File("tenant-without-applications.json"));
    // DELETE tenant again - should produce 404
    tester.assertResponse(request("/application/v4/tenant/tenant1", DELETE).userIdentity(USER_ID), "{\"error-code\":\"NOT_FOUND\",\"message\":\"Could not delete tenant 'tenant1': Tenant not found\"}", 404);
    // Promote application chef env for nonexistent tenant/application
    tester.assertResponse(request("/application/v4/tenant/dontexist/application/dontexist/environment/prod/region/us-west-1/instance/default/promote", POST).userIdentity(USER_ID), "{\"error-code\":\"INTERNAL_SERVER_ERROR\",\"message\":\"Unable to promote Chef environments for application\"}", 500);
}
Also used : HttpEntity(org.apache.http.HttpEntity) ContainerTester(com.yahoo.vespa.hosted.controller.restapi.ContainerTester) ConfigServerException(com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerException) File(java.io.File) URI(java.net.URI) ConfigServerClientMock(com.yahoo.vespa.hosted.controller.ConfigServerClientMock) ControllerContainerTest(com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest) Test(org.junit.Test)

Aggregations

ConfigServerClientMock (com.yahoo.vespa.hosted.controller.ConfigServerClientMock)1 ConfigServerException (com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerException)1 ContainerTester (com.yahoo.vespa.hosted.controller.restapi.ContainerTester)1 ControllerContainerTest (com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest)1 File (java.io.File)1 URI (java.net.URI)1 HttpEntity (org.apache.http.HttpEntity)1 Test (org.junit.Test)1