Search in sources :

Example 26 with BulletinDTO

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);
    }
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ClientErrorException(javax.ws.rs.ClientErrorException) BulletinDTO(org.apache.nifi.web.api.dto.BulletinDTO)

Aggregations

BulletinDTO (org.apache.nifi.web.api.dto.BulletinDTO)26 BulletinEntity (org.apache.nifi.web.api.entity.BulletinEntity)24 ArrayList (java.util.ArrayList)23 Date (java.util.Date)22 HashMap (java.util.HashMap)22 List (java.util.List)22 Map (java.util.Map)22 Collectors (java.util.stream.Collectors)22 Sets (com.google.common.collect.Sets)21 IOException (java.io.IOException)21 StandardCharsets (java.nio.charset.StandardCharsets)21 Arrays (java.util.Arrays)21 Collection (java.util.Collection)21 Collections (java.util.Collections)21 Comparator (java.util.Comparator)21 HashSet (java.util.HashSet)21 LinkedHashMap (java.util.LinkedHashMap)21 LinkedHashSet (java.util.LinkedHashSet)21 ListIterator (java.util.ListIterator)21 Objects (java.util.Objects)21