use of org.apache.nifi.web.api.dto.BulletinDTO in project kylo by Teradata.
the class AbstractNiFiControllerServicesRestClient method updateStateByIdWithRetries.
/**
* Sends a request to update the state of the specified controller service and waits for it to finish updating.
*
* @param id the controller service id
* @param state the new state
* @param retries number of retries, at least 0; will try {@code retries} + 1 times
* @param timeout duration to wait between retries
* @param timeUnit unit of time for {@code timeout}
* @return the controller service, if updated
* @throws NifiClientRuntimeException if the state cannot be changed
* @throws NifiComponentNotFoundException if the controller service does not exist
*/
protected ControllerServiceDTO updateStateByIdWithRetries(@Nonnull final String id, @Nonnull final String state, final int retries, final int timeout, @Nonnull final TimeUnit timeUnit) {
// Mark the Service as DISABLED
ControllerServiceDTO controllerService = new ControllerServiceDTO();
controllerService.setId(id);
controllerService.setState(state);
controllerService = update(controllerService);
// Wait for finished
for (int count = 0; isPendingState(controllerService.getState(), state) && count < retries; ++count) {
log.debug("Waiting for controller service {} to exit pending state {}. Try {} of {}.", id, controllerService.getState(), count + 1, retries);
Uninterruptibles.sleepUninterruptibly(timeout, timeUnit);
controllerService = findById(id).orElseThrow(() -> new NifiComponentNotFoundException(id, NifiConstants.NIFI_COMPONENT_TYPE.CONTROLLER_SERVICE, null));
}
// Verify state change or throw bulletin message
if (state.equals(controllerService.getState())) {
return controllerService;
} else {
String msg = id;
try {
final List<BulletinDTO> bulletins = getClient().getBulletins(id);
if (!bulletins.isEmpty()) {
msg = bulletins.get(0).getMessage();
}
} catch (final ClientErrorException e) {
// ignored
}
throw new NifiClientRuntimeException("Timeout waiting for controller service to be " + state + ": " + msg);
}
}
Aggregations