use of org.folio.rest.jaxrs.model.TenantJob in project raml-module-builder by folio-org.
the class TenantAPIIT method postTenantWithLoadFailAsync.
@Test
public void postTenantWithLoadFailAsync(TestContext context) {
TenantAPI tenantAPI = new TenantAPI() {
@Override
Future<Integer> loadData(TenantAttributes attributes, String tenantId, Map<String, String> headers, Context ctx) {
return Future.failedFuture("Load Failure");
}
};
String id = tenantPost(tenantAPI, context, new TenantAttributes());
tenantAPI.getTenantByOperationId(id, 0, okapiHeaders, onSuccess(context, result -> {
assertThat(result.getStatus(), is(200));
TenantJob job = (TenantJob) result.getEntity();
assertThat(job.getComplete(), is(true));
assertThat(job.getError(), is("Load Failure"));
}), vertx.getOrCreateContext());
}
use of org.folio.rest.jaxrs.model.TenantJob in project raml-module-builder by folio-org.
the class TenantInit method exec.
/**
* Perform tenant post, wait for result and delete job.
* @param client Tenant Client.
* @param tenantAttributes attributes for tenant post.
* @param waitMs number of milliseconds to wait for job completion (0=no wait).
* @return async result.
*/
public static Future<Void> exec(TenantClient client, TenantAttributes tenantAttributes, int waitMs) {
Promise<Void> promise = Promise.promise();
client.postTenant(tenantAttributes, res1 -> {
if (res1.failed()) {
promise.fail(res1.cause());
return;
}
int status1 = res1.result().statusCode();
if (status1 == 204) {
promise.complete();
return;
} else if (status1 != 201) {
promise.fail("tenant post returned " + status1 + " " + res1.result().bodyAsString());
return;
}
try {
TenantJob job = res1.result().bodyAsJson(TenantJob.class);
execGet(client, job.getId(), waitMs, promise);
} catch (Exception e) {
log.error(e.getMessage(), e);
promise.fail(e);
}
});
return promise.future();
}
use of org.folio.rest.jaxrs.model.TenantJob in project raml-module-builder by folio-org.
the class TenantInit method execGet.
static void execGet(TenantClient client, String id, int waitMs, Promise<Void> promise) {
client.getTenantByOperationId(id, waitMs, res2 -> {
if (res2.failed()) {
promise.fail(res2.cause());
return;
}
int status2 = res2.result().statusCode();
if (status2 != 200) {
promise.fail("tenant get returned " + status2 + " " + res2.result().bodyAsString());
return;
}
try {
TenantJob job2 = res2.result().bodyAsJson(TenantJob.class);
client.deleteTenantByOperationId(id, res3 -> {
// we don't care about errors returned by delete
String error = job2.getError();
if (!Boolean.TRUE.equals(job2.getComplete())) {
promise.fail("tenant job did not complete");
} else if (error != null) {
promise.fail(error);
} else {
promise.complete();
}
});
} catch (Exception e) {
log.error(e.getMessage(), e);
promise.fail(e);
}
});
}
use of org.folio.rest.jaxrs.model.TenantJob in project raml-module-builder by folio-org.
the class TenantAPI method getJob.
Future<TenantJob> getJob(String tenantId, UUID jobId, Context context) {
String table = PostgresClient.convertToPsqlStandard(tenantId) + ".rmb_job";
String sql = "SELECT jsonb FROM " + table + " WHERE id = $1";
return postgresClient(context).selectSingle(sql, Tuple.of(jobId)).compose(reply -> {
if (reply == null) {
return Future.failedFuture("Job not found " + jobId);
}
JsonObject o = reply.getJsonObject(0);
return Future.succeededFuture(o.mapTo(TenantJob.class));
});
}
use of org.folio.rest.jaxrs.model.TenantJob in project raml-module-builder by folio-org.
the class TenantAPIIT method postTenantWithSqlErrorAsync.
@Test
public void postTenantWithSqlErrorAsync(TestContext context) {
TenantAPI tenantAPI = new TenantAPI();
TenantJob job = new TenantJob();
tenantAPI.runAsync(null, "SELECT (", job, okapiHeaders, vertx.getOrCreateContext()).onComplete(context.asyncAssertFailure(cause -> {
assertThat(job.getError(), is("SQL error"));
// for some bizarre reason a space is put in front the returned stmt
assertThat(job.getMessages(), containsInAnyOrder(CoreMatchers.startsWith(" SELECT (\n")));
}));
}
Aggregations