NIFI-5279: Allow components up to 50 milliseconds to complete validation before returning from update request

This closes #2770.

Signed-off-by: Andy LoPresto <alopresto@apache.org>
This commit is contained in:
Mark Payne 2018-06-07 13:26:49 -04:00 committed by Andy LoPresto
parent 7b9d779a4b
commit 729f8aa246
No known key found for this signature in database
GPG Key ID: 6EC293152D90B61D
1 changed files with 15 additions and 2 deletions

View File

@ -303,6 +303,7 @@ import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
@ -314,6 +315,7 @@ import java.util.stream.Stream;
*/
public class StandardNiFiServiceFacade implements NiFiServiceFacade {
private static final Logger logger = LoggerFactory.getLogger(StandardNiFiServiceFacade.class);
private static final int VALIDATION_WAIT_MILLIS = 50;
// nifi core components
private ControllerFacade controllerFacade;
@ -660,7 +662,10 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
final RevisionUpdate<ProcessorDTO> snapshot = updateComponent(revision,
processorNode,
() -> processorDAO.updateProcessor(processorDTO),
proc -> dtoFactory.createProcessorDto(proc));
proc -> {
awaitValidationCompletion(proc);
return dtoFactory.createProcessorDto(proc);
});
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(processorNode);
final ProcessorStatusDTO status = dtoFactory.createProcessorStatusDto(controllerFacade.getProcessorStatus(processorNode.getIdentifier()));
@ -669,6 +674,10 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
return entityFactory.createProcessorEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, status, bulletinEntities);
}
private void awaitValidationCompletion(final ComponentNode component) {
component.getValidationStatus(VALIDATION_WAIT_MILLIS, TimeUnit.MILLISECONDS);
}
@Override
public LabelEntity updateLabel(final Revision revision, final LabelDTO labelDTO) {
final Label labelNode = labelDAO.getLabel(labelDTO.getId());
@ -2192,6 +2201,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
controllerService,
() -> controllerServiceDAO.updateControllerService(controllerServiceDTO),
cs -> {
awaitValidationCompletion(cs);
final ControllerServiceDTO dto = dtoFactory.createControllerServiceDto(cs);
final ControllerServiceReference ref = controllerService.getReferences();
final ControllerServiceReferencingComponentsEntity referencingComponentsEntity =
@ -2582,7 +2592,10 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
final RevisionUpdate<ReportingTaskDTO> snapshot = updateComponent(revision,
reportingTask,
() -> reportingTaskDAO.updateReportingTask(reportingTaskDTO),
rt -> dtoFactory.createReportingTaskDto(rt));
rt -> {
awaitValidationCompletion(rt);
return dtoFactory.createReportingTaskDto(rt);
});
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(reportingTask);
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(reportingTask.getIdentifier()));