@Override public TenantWriteRequest deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); TenantSpecification tenantSpec = context.deserialize(jsonObj.get("tenant"), TenantSpecification.class); Boolean bootstrap = context.deserialize(jsonObj.get("bootstrap"), Boolean.class); return new TenantWriteRequest(tenantSpec, bootstrap); } }
TenantSpecification tenantSpecification = tenantWriteRequest.getTenant(); String name = tenantSpecification.getName(); if (tenantProvisionerService.getTenantSpecification(name) != null) { if (tenantWriteRequest.isBootstrap()) { tenantProvisionerService.bootstrapTenant(tenantId);
TenantSpecification tenantSpecification = tenantWriteRequest.getTenant(); if (tenantSpecification.getName() == null || !tenantSpecification.getName().equals(tenantName)) { responder.sendError(HttpResponseStatus.BAD_REQUEST, "tenant name in body does not match name in path.");
@Test public void testCreateTenantWithTooManyWorkersReturnsConflict() throws Exception { TenantSpecification requestedTenant = new TenantSpecification("companyX", 10000, 100, 1000); TenantWriteRequest addRequest = new TenantWriteRequest(requestedTenant); HttpResponse response = doPostExternalAPI("/tenants", gson.toJson(addRequest), SUPERADMIN_HEADERS); // perform create request assertResponseStatus(response, HttpResponseStatus.CONFLICT); }
@Test public void testDuplicateTenantNameNotAllowed() throws Exception { String name = "companyX"; TenantSpecification requestedTenant = new TenantSpecification(name, 10, 100, 1000); TenantWriteRequest addRequest = new TenantWriteRequest(requestedTenant); assertResponseStatus(doPostExternalAPI("/tenants", gson.toJson(addRequest), SUPERADMIN_HEADERS), HttpResponseStatus.OK); assertResponseStatus(doPostExternalAPI("/tenants", gson.toJson(addRequest), SUPERADMIN_HEADERS), HttpResponseStatus.CONFLICT); }
@Test public void testWriteTenantWithTooManyWorkersReturnsConflict() throws Exception { // write tenant to store String id = UUID.randomUUID().toString(); String name = "companyX"; Tenant actualTenant = new Tenant(id, new TenantSpecification(name, 10, 100, 1000)); tenantStore.writeTenant(actualTenant); // perform request to write tenant TenantSpecification updatedFields = new TenantSpecification(name, 100000, 100, 500); TenantWriteRequest writeRequest = new TenantWriteRequest(updatedFields); HttpResponse response = doPutExternalAPI("/tenants/" + name, gson.toJson(writeRequest), SUPERADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.CONFLICT); }
@Test public void testWriteTenant() throws Exception { // write tenant to store String id = UUID.randomUUID().toString(); Tenant actualTenant = new Tenant(id, new TenantSpecification("companyX", 10, 100, 1000)); tenantStore.writeTenant(actualTenant); // perform request to write tenant TenantSpecification updatedTenant = new TenantSpecification("companyX", 10, 100, 500); TenantWriteRequest writeRequest = new TenantWriteRequest(updatedTenant); HttpResponse response = doPutExternalAPI("/tenants/" + updatedTenant.getName(), gson.toJson(writeRequest), SUPERADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals(updatedTenant, tenantStore.getTenantByID(actualTenant.getId()).getSpecification()); }
TenantWriteRequest tenantWriteRequest = new TenantWriteRequest(requestedTenant, true); HttpResponse response = doPostExternalAPI("/tenants", gson.toJson(tenantWriteRequest), SUPERADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK);
@Test public void testCreateTenant() throws Exception { String name = "companyX"; TenantSpecification requestedTenant = new TenantSpecification(name, 10, 100, 1000); TenantWriteRequest tenantWriteRequest = new TenantWriteRequest(requestedTenant); HttpResponse response = doPostExternalAPI("/tenants", gson.toJson(tenantWriteRequest), SUPERADMIN_HEADERS); // perform create request assertResponseStatus(response, HttpResponseStatus.OK); // make sure tenant was actually written TenantSpecification actualTenant = tenantStore.getTenantByName(name).getSpecification(); Assert.assertEquals(requestedTenant.getName(), actualTenant.getName()); Assert.assertEquals(requestedTenant.getWorkers(), actualTenant.getWorkers()); Assert.assertEquals(requestedTenant.getMaxClusters(), actualTenant.getMaxClusters()); Assert.assertEquals(requestedTenant.getMaxNodes(), actualTenant.getMaxNodes()); }