use of org.apache.nifi.controller.exception.ValidationException in project nifi by apache.
the class StandardControllerServiceDAO method verifyUpdate.
private void verifyUpdate(final ControllerServiceNode controllerService, final ControllerServiceDTO controllerServiceDTO) {
// validate the new controller service state if appropriate
if (isNotNull(controllerServiceDTO.getState())) {
try {
// attempt to parse the service state
final ControllerServiceState purposedControllerServiceState = ControllerServiceState.valueOf(controllerServiceDTO.getState());
// ensure the state is valid
if (ControllerServiceState.ENABLING.equals(purposedControllerServiceState) || ControllerServiceState.DISABLING.equals(purposedControllerServiceState)) {
throw new IllegalArgumentException();
}
// only attempt an action if it is changing
if (!purposedControllerServiceState.equals(controllerService.getState())) {
if (ControllerServiceState.ENABLED.equals(purposedControllerServiceState)) {
controllerService.verifyCanEnable();
} else if (ControllerServiceState.DISABLED.equals(purposedControllerServiceState)) {
controllerService.verifyCanDisable();
}
}
} catch (final IllegalArgumentException iae) {
throw new IllegalArgumentException("Controller Service state: Value must be one of [ENABLED, DISABLED]");
}
}
boolean modificationRequest = false;
if (isAnyNotNull(controllerServiceDTO.getName(), controllerServiceDTO.getAnnotationData(), controllerServiceDTO.getComments(), controllerServiceDTO.getProperties(), controllerServiceDTO.getBundle())) {
modificationRequest = true;
// validate the request
final List<String> requestValidation = validateProposedConfiguration(controllerService, controllerServiceDTO);
// ensure there was no validation errors
if (!requestValidation.isEmpty()) {
throw new ValidationException(requestValidation);
}
}
final BundleDTO bundleDTO = controllerServiceDTO.getBundle();
if (bundleDTO != null) {
// ensures all nodes in a cluster have the bundle, throws exception if bundle not found for the given type
final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(controllerService.getCanonicalClassName(), bundleDTO);
// ensure we are only changing to a bundle with the same group and id, but different version
controllerService.verifyCanUpdateBundle(bundleCoordinate);
}
if (modificationRequest) {
controllerService.verifyCanUpdate();
}
}
use of org.apache.nifi.controller.exception.ValidationException in project nifi by apache.
the class StandardInputPortDAO method verifyUpdate.
private void verifyUpdate(final Port inputPort, final PortDTO portDTO) {
if (isNotNull(portDTO.getState())) {
final ScheduledState purposedScheduledState = ScheduledState.valueOf(portDTO.getState());
// only attempt an action if it is changing
if (!purposedScheduledState.equals(inputPort.getScheduledState())) {
// perform the appropriate action
switch(purposedScheduledState) {
case RUNNING:
inputPort.verifyCanStart();
break;
case STOPPED:
switch(inputPort.getScheduledState()) {
case RUNNING:
inputPort.verifyCanStop();
break;
case DISABLED:
inputPort.verifyCanEnable();
break;
}
break;
case DISABLED:
inputPort.verifyCanDisable();
break;
}
}
}
// see what's be modified
if (isAnyNotNull(portDTO.getUserAccessControl(), portDTO.getGroupAccessControl(), portDTO.getConcurrentlySchedulableTaskCount(), portDTO.getName(), portDTO.getComments())) {
// validate the request
final List<String> requestValidation = validateProposedConfiguration(portDTO);
// ensure there was no validation errors
if (!requestValidation.isEmpty()) {
throw new ValidationException(requestValidation);
}
// ensure the port can be updated
inputPort.verifyCanUpdate();
}
}
use of org.apache.nifi.controller.exception.ValidationException in project nifi by apache.
the class StandardProcessorDAO method verifyUpdate.
private void verifyUpdate(ProcessorNode processor, ProcessorDTO processorDTO) {
// ensure the state, if specified, is valid
if (isNotNull(processorDTO.getState())) {
try {
final ScheduledState purposedScheduledState = ScheduledState.valueOf(processorDTO.getState());
// only attempt an action if it is changing
if (!purposedScheduledState.equals(processor.getScheduledState())) {
// perform the appropriate action
switch(purposedScheduledState) {
case RUNNING:
processor.verifyCanStart();
break;
case STOPPED:
switch(processor.getScheduledState()) {
case RUNNING:
processor.verifyCanStop();
break;
case DISABLED:
processor.verifyCanEnable();
break;
}
break;
case DISABLED:
processor.verifyCanDisable();
break;
}
}
} catch (IllegalArgumentException iae) {
throw new IllegalArgumentException(String.format("The specified processor state (%s) is not valid. Valid options are 'RUNNING', 'STOPPED', and 'DISABLED'.", processorDTO.getState()));
}
}
boolean modificationRequest = false;
if (isAnyNotNull(processorDTO.getName(), processorDTO.getBundle())) {
modificationRequest = true;
}
final BundleDTO bundleDTO = processorDTO.getBundle();
if (bundleDTO != null) {
// ensures all nodes in a cluster have the bundle, throws exception if bundle not found for the given type
final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(processor.getCanonicalClassName(), bundleDTO);
// ensure we are only changing to a bundle with the same group and id, but different version
processor.verifyCanUpdateBundle(bundleCoordinate);
}
final ProcessorConfigDTO configDTO = processorDTO.getConfig();
if (configDTO != null) {
if (isAnyNotNull(configDTO.getAnnotationData(), configDTO.getAutoTerminatedRelationships(), configDTO.getBulletinLevel(), configDTO.getComments(), configDTO.getConcurrentlySchedulableTaskCount(), configDTO.getPenaltyDuration(), configDTO.getProperties(), configDTO.getSchedulingPeriod(), configDTO.getSchedulingStrategy(), configDTO.getExecutionNode(), configDTO.getYieldDuration())) {
modificationRequest = true;
}
// validate the request
final List<String> requestValidation = validateProposedConfiguration(processor, configDTO);
// ensure there was no validation errors
if (!requestValidation.isEmpty()) {
throw new ValidationException(requestValidation);
}
}
if (modificationRequest) {
processor.verifyCanUpdate();
}
}
use of org.apache.nifi.controller.exception.ValidationException in project nifi by apache.
the class StandardConnectionDAO method verifyUpdate.
private void verifyUpdate(final Connection connection, final ConnectionDTO connectionDTO) {
// determine what the request is attempting
if (isAnyNotNull(connectionDTO.getBackPressureDataSizeThreshold(), connectionDTO.getBackPressureObjectThreshold(), connectionDTO.getDestination(), connectionDTO.getFlowFileExpiration(), connectionDTO.getName(), connectionDTO.getPosition(), connectionDTO.getPrioritizers(), connectionDTO.getSelectedRelationships())) {
// validate the incoming request
final List<String> validationErrors = validateProposedConfiguration(connection.getProcessGroup().getIdentifier(), connectionDTO);
// ensure there was no validation errors
if (!validationErrors.isEmpty()) {
throw new ValidationException(validationErrors);
}
// If destination is changing, ensure that current destination is not running. This check is done here, rather than
// in the Connection object itself because the Connection object itself does not know which updates are to occur and
// we don't want to prevent updating things like the connection name or backpressure just because the destination is running
final Connectable destination = connection.getDestination();
if (destination != null && destination.isRunning() && destination.getConnectableType() != ConnectableType.FUNNEL && destination.getConnectableType() != ConnectableType.INPUT_PORT) {
throw new ValidationException(Collections.singletonList("Cannot change the destination of connection because the current destination is running"));
}
// verify that this connection supports modification
connection.verifyCanUpdate();
}
}
use of org.apache.nifi.controller.exception.ValidationException in project nifi by apache.
the class StandardConnectionDAO method verifyCreate.
@Override
public void verifyCreate(String groupId, ConnectionDTO connectionDTO) {
// validate the incoming request
final List<String> validationErrors = validateProposedConfiguration(groupId, connectionDTO);
// ensure there was no validation errors
if (!validationErrors.isEmpty()) {
throw new ValidationException(validationErrors);
}
// Ensure that both the source and the destination for the connection exist.
// In the case that the source or destination is a port in a Remote Process Group,
// this is necessary because the ports can change in the background. It may still be
// possible for a port to disappear between the 'verify' stage and the creation stage,
// but this prevents the case where some nodes already know about the port while other
// nodes in the cluster do not. This is a more common case, as users may try to connect
// to the port as soon as the port is created.
final ConnectableDTO sourceDto = connectionDTO.getSource();
if (sourceDto == null || sourceDto.getId() == null) {
throw new IllegalArgumentException("Cannot create connection without specifying source");
}
final ConnectableDTO destinationDto = connectionDTO.getDestination();
if (destinationDto == null || destinationDto.getId() == null) {
throw new IllegalArgumentException("Cannot create connection without specifying destination");
}
if (ConnectableType.REMOTE_OUTPUT_PORT.name().equals(sourceDto.getType())) {
final ProcessGroup sourceParentGroup = locateProcessGroup(flowController, groupId);
final RemoteProcessGroup remoteProcessGroup = sourceParentGroup.getRemoteProcessGroup(sourceDto.getGroupId());
if (remoteProcessGroup == null) {
throw new IllegalArgumentException("Unable to find the specified remote process group.");
}
final RemoteGroupPort sourceConnectable = remoteProcessGroup.getOutputPort(sourceDto.getId());
if (sourceConnectable == null) {
throw new IllegalArgumentException("The specified source for the connection does not exist");
} else if (!sourceConnectable.getTargetExists()) {
throw new IllegalArgumentException("The specified remote output port does not exist.");
}
} else {
final ProcessGroup sourceGroup = locateProcessGroup(flowController, sourceDto.getGroupId());
final Connectable sourceConnectable = sourceGroup.getConnectable(sourceDto.getId());
if (sourceConnectable == null) {
throw new IllegalArgumentException("The specified source for the connection does not exist");
}
}
if (ConnectableType.REMOTE_INPUT_PORT.name().equals(destinationDto.getType())) {
final ProcessGroup destinationParentGroup = locateProcessGroup(flowController, groupId);
final RemoteProcessGroup remoteProcessGroup = destinationParentGroup.getRemoteProcessGroup(destinationDto.getGroupId());
if (remoteProcessGroup == null) {
throw new IllegalArgumentException("Unable to find the specified remote process group.");
}
final RemoteGroupPort destinationConnectable = remoteProcessGroup.getInputPort(destinationDto.getId());
if (destinationConnectable == null) {
throw new IllegalArgumentException("The specified destination for the connection does not exist");
} else if (!destinationConnectable.getTargetExists()) {
throw new IllegalArgumentException("The specified remote input port does not exist.");
}
} else {
final ProcessGroup destinationGroup = locateProcessGroup(flowController, destinationDto.getGroupId());
final Connectable destinationConnectable = destinationGroup.getConnectable(destinationDto.getId());
if (destinationConnectable == null) {
throw new IllegalArgumentException("The specified destination for the connection does not exist");
}
}
}
Aggregations