use of org.mockserver.model.JsonBody in project strimzi by strimzi.
the class MockCruiseControl method setupCCStateResponse.
/**
* Setup state responses in mock server.
*/
public static void setupCCStateResponse(ClientAndServer ccServer) throws IOException, URISyntaxException {
// Non-verbose response
JsonBody jsonProposalNotReady = getJsonFromResource("CC-State-proposal-not-ready.json");
ccServer.when(request().withMethod("GET").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true|false")).withQueryStringParameter(Parameter.param(CruiseControlParameters.VERBOSE.key, "true|false")).withPath(CruiseControlEndpoints.STATE.path).withHeaders(header(CruiseControlApi.CC_REST_API_USER_ID_HEADER, STATE_PROPOSAL_NOT_READY), AUTH_HEADER).withSecure(true)).respond(response().withBody(jsonProposalNotReady).withHeaders(header("User-Task-ID", STATE_PROPOSAL_NOT_READY_RESPONSE)).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
// Non-verbose response
JsonBody json = getJsonFromResource("CC-State.json");
ccServer.when(request().withMethod("GET").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.VERBOSE.key, "false")).withPath(CruiseControlEndpoints.STATE.path).withHeader(AUTH_HEADER).withSecure(true)).respond(response().withBody(json).withHeaders(header("User-Task-ID", "cruise-control-state")).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
// Verbose response
JsonBody jsonVerbose = getJsonFromResource("CC-State-verbose.json");
ccServer.when(request().withMethod("GET").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.VERBOSE.key, "true")).withPath(CruiseControlEndpoints.STATE.path).withHeader(AUTH_HEADER).withSecure(true)).respond(response().withBody(jsonVerbose).withHeaders(header("User-Task-ID", "cruise-control-state-verbose")).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
}
use of org.mockserver.model.JsonBody in project strimzi-kafka-operator by strimzi.
the class MockCruiseControl method setupCCBrokerDoesNotExist.
/**
* Setup broker doesn't exist error for add/remove broker response.
*/
public static void setupCCBrokerDoesNotExist(ClientAndServer ccServer, CruiseControlEndpoints endpoint) throws IOException, URISyntaxException {
// Add/remove broker response with no goal that returns an error
JsonBody jsonError = getJsonFromResource("CC-Broker-not-exist.json");
ccServer.when(request().withMethod("POST").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.DRY_RUN.key, "true|false")).withQueryStringParameter(Parameter.param(CruiseControlParameters.VERBOSE.key, "true|false")).withQueryStringParameter(buildBrokerIdParameter(endpoint)).withPath(endpoint.path).withHeader(AUTH_HEADER).withSecure(true)).respond(response().withStatusCode(500).withBody(jsonError).withHeaders(header(CruiseControlApi.CC_REST_API_USER_ID_HEADER, BROKERS_NOT_EXIST_ERROR_RESPONSE_UTID)).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
}
use of org.mockserver.model.JsonBody in project strimzi-kafka-operator by strimzi.
the class MockCruiseControl method setupCCUserTasksResponseNoGoals.
/**
* Sets up the User Tasks endpoint. These endpoints expect the query to contain the user-task-id returned in the header of the response from
* the rebalance endpoints.
*
* @param ccServer The ClientAndServer instance that this endpoint will be added too.
* @param activeCalls The number of calls to the User Tasks endpoint that should return "Active" before "inExecution" is returned as the status.
* @param inExecutionCalls The number of calls to the User Tasks endpoint that should return "InExecution" before "Completed" is returned as the status.
* @throws IOException If there are issues connecting to the network port.
* @throws URISyntaxException If any of the configured end points are invalid.
*/
public static void setupCCUserTasksResponseNoGoals(ClientAndServer ccServer, int activeCalls, int inExecutionCalls) throws IOException, URISyntaxException {
// User tasks response for the rebalance request with no goals set (non-verbose)
JsonBody jsonActive = getJsonFromResource("CC-User-task-rebalance-no-goals-Active.json");
JsonBody jsonInExecution = getJsonFromResource("CC-User-task-rebalance-no-goals-inExecution.json");
JsonBody jsonCompleted = getJsonFromResource("CC-User-task-rebalance-no-goals-completed.json");
// The first activeCalls times respond that with a status of "Active"
ccServer.when(request().withMethod("GET").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.FETCH_COMPLETE.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.USER_TASK_IDS.key, REBALANCE_NO_GOALS_RESPONSE_UTID)).withPath(CruiseControlEndpoints.USER_TASKS.path).withHeader(AUTH_HEADER).withSecure(true), Times.exactly(activeCalls)).respond(response().withBody(jsonActive).withHeaders(header("User-Task-ID", USER_TASK_REBALANCE_NO_GOALS_RESPONSE_UTID)).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
// The next inExecutionCalls times respond that with a status of "InExecution"
ccServer.when(request().withMethod("GET").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.FETCH_COMPLETE.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.USER_TASK_IDS.key, REBALANCE_NO_GOALS_RESPONSE_UTID)).withPath(CruiseControlEndpoints.USER_TASKS.path).withHeader(AUTH_HEADER).withSecure(true), Times.exactly(inExecutionCalls)).respond(response().withBody(jsonInExecution).withHeaders(header("User-Task-ID", USER_TASK_REBALANCE_NO_GOALS_RESPONSE_UTID)).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
// On the N+1 call, respond with a completed rebalance task.
ccServer.when(request().withMethod("GET").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.FETCH_COMPLETE.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.USER_TASK_IDS.key, REBALANCE_NO_GOALS_RESPONSE_UTID)).withPath(CruiseControlEndpoints.USER_TASKS.path).withHeader(AUTH_HEADER).withSecure(true), Times.unlimited()).respond(response().withBody(jsonCompleted).withHeaders(header("User-Task-ID", USER_TASK_REBALANCE_NO_GOALS_RESPONSE_UTID)).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
// User tasks response for the rebalance request with no goals set (verbose)
JsonBody jsonActiveVerbose = getJsonFromResource("CC-User-task-rebalance-no-goals-verbose-Active.json");
JsonBody jsonInExecutionVerbose = getJsonFromResource("CC-User-task-rebalance-no-goals-verbose-inExecution.json");
JsonBody jsonCompletedVerbose = getJsonFromResource("CC-User-task-rebalance-no-goals-verbose-completed.json");
// The first activeCalls times respond that with a status of "Active"
ccServer.when(request().withMethod("GET").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.FETCH_COMPLETE.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.USER_TASK_IDS.key, REBALANCE_NO_GOALS_VERBOSE_RESPONSE_UTID)).withPath(CruiseControlEndpoints.USER_TASKS.path).withHeader(AUTH_HEADER).withSecure(true), Times.exactly(activeCalls)).respond(response().withBody(jsonActiveVerbose).withHeaders(header("User-Task-ID", USER_TASK_REBALANCE_NO_GOALS_VERBOSE_RESPONSE_UTID)).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
ccServer.when(request().withMethod("GET").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.FETCH_COMPLETE.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.USER_TASK_IDS.key, REBALANCE_NO_GOALS_VERBOSE_RESPONSE_UTID)).withPath(CruiseControlEndpoints.USER_TASKS.path).withHeader(AUTH_HEADER).withSecure(true), Times.exactly(inExecutionCalls)).respond(response().withBody(jsonInExecutionVerbose).withHeaders(header("User-Task-ID", USER_TASK_REBALANCE_NO_GOALS_VERBOSE_RESPONSE_UTID)).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
ccServer.when(request().withMethod("GET").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.FETCH_COMPLETE.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.USER_TASK_IDS.key, REBALANCE_NO_GOALS_VERBOSE_RESPONSE_UTID)).withPath(CruiseControlEndpoints.USER_TASKS.path).withHeader(AUTH_HEADER).withSecure(true), Times.unlimited()).respond(response().withBody(jsonCompletedVerbose).withHeaders(header("User-Task-ID", USER_TASK_REBALANCE_NO_GOALS_VERBOSE_RESPONSE_UTID)).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
}
use of org.mockserver.model.JsonBody in project strimzi-kafka-operator by strimzi.
the class MockCruiseControl method getJsonFromResource.
private static JsonBody getJsonFromResource(String resource) throws URISyntaxException, IOException {
URI jsonURI = Objects.requireNonNull(MockCruiseControl.class.getClassLoader().getResource(CC_JSON_ROOT + resource)).toURI();
Optional<String> json = Files.lines(Paths.get(jsonURI), UTF_8).reduce((x, y) -> x + y);
if (!json.isPresent()) {
throw new IOException("File " + resource + " from resources was empty");
}
return new JsonBody(json.get());
}
use of org.mockserver.model.JsonBody in project strimzi-kafka-operator by strimzi.
the class MockCruiseControl method setupCCRebalanceNotEnoughDataError.
/**
* Setup NotEnoughValidWindows error rebalance/add/remove broker response.
*/
public static void setupCCRebalanceNotEnoughDataError(ClientAndServer ccServer, CruiseControlEndpoints endpoint) throws IOException, URISyntaxException {
// Rebalance response with no goal that returns an error
JsonBody jsonError = getJsonFromResource("CC-Rebalance-NotEnoughValidWindows-error.json");
ccServer.when(request().withMethod("POST").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.DRY_RUN.key, "true|false")).withQueryStringParameter(Parameter.param(CruiseControlParameters.VERBOSE.key, "true|false")).withQueryStringParameter(buildBrokerIdParameter(endpoint)).withPath(endpoint.path).withHeader(AUTH_HEADER).withSecure(true)).respond(response().withStatusCode(500).withBody(jsonError).withHeaders(header(CruiseControlApi.CC_REST_API_USER_ID_HEADER, REBALANCE_NOT_ENOUGH_VALID_WINDOWS_ERROR_RESPONSE_UTID)).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
}
Aggregations