use of org.apache.nifi.components.ValidationResult in project nifi by apache.
the class StandardNiFiServiceFacade method validateSnippetContents.
private void validateSnippetContents(final FlowSnippetDTO flow) {
// validate any processors
if (flow.getProcessors() != null) {
for (final ProcessorDTO processorDTO : flow.getProcessors()) {
final ProcessorNode processorNode = processorDAO.getProcessor(processorDTO.getId());
final Collection<ValidationResult> validationErrors = processorNode.getValidationErrors();
if (validationErrors != null && !validationErrors.isEmpty()) {
final List<String> errors = new ArrayList<>();
for (final ValidationResult validationResult : validationErrors) {
errors.add(validationResult.toString());
}
processorDTO.setValidationErrors(errors);
}
}
}
if (flow.getInputPorts() != null) {
for (final PortDTO portDTO : flow.getInputPorts()) {
final Port port = inputPortDAO.getPort(portDTO.getId());
final Collection<ValidationResult> validationErrors = port.getValidationErrors();
if (validationErrors != null && !validationErrors.isEmpty()) {
final List<String> errors = new ArrayList<>();
for (final ValidationResult validationResult : validationErrors) {
errors.add(validationResult.toString());
}
portDTO.setValidationErrors(errors);
}
}
}
if (flow.getOutputPorts() != null) {
for (final PortDTO portDTO : flow.getOutputPorts()) {
final Port port = outputPortDAO.getPort(portDTO.getId());
final Collection<ValidationResult> validationErrors = port.getValidationErrors();
if (validationErrors != null && !validationErrors.isEmpty()) {
final List<String> errors = new ArrayList<>();
for (final ValidationResult validationResult : validationErrors) {
errors.add(validationResult.toString());
}
portDTO.setValidationErrors(errors);
}
}
}
// get any remote process group issues
if (flow.getRemoteProcessGroups() != null) {
for (final RemoteProcessGroupDTO remoteProcessGroupDTO : flow.getRemoteProcessGroups()) {
final RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupDTO.getId());
if (remoteProcessGroup.getAuthorizationIssue() != null) {
remoteProcessGroupDTO.setAuthorizationIssues(Arrays.asList(remoteProcessGroup.getAuthorizationIssue()));
}
}
}
}
use of org.apache.nifi.components.ValidationResult in project nifi by apache.
the class DtoFactory method createRemoteProcessGroupDto.
/**
* Creates a RemoteProcessGroupDTO from the specified RemoteProcessGroup.
*
* @param group group
* @return dto
*/
public RemoteProcessGroupDTO createRemoteProcessGroupDto(final RemoteProcessGroup group) {
if (group == null) {
return null;
}
final Set<RemoteProcessGroupPortDTO> inputPorts = new HashSet<>();
final Set<RemoteProcessGroupPortDTO> outputPorts = new HashSet<>();
int activeRemoteInputPortCount = 0;
int inactiveRemoteInputPortCount = 0;
for (final Port port : group.getInputPorts()) {
inputPorts.add(createRemoteProcessGroupPortDto((RemoteGroupPort) port));
if (port.hasIncomingConnection()) {
if (port.isRunning()) {
activeRemoteInputPortCount++;
} else {
inactiveRemoteInputPortCount++;
}
}
}
int activeRemoteOutputPortCount = 0;
int inactiveRemoteOutputPortCount = 0;
for (final Port port : group.getOutputPorts()) {
outputPorts.add(createRemoteProcessGroupPortDto((RemoteGroupPort) port));
if (!port.getConnections().isEmpty()) {
if (port.isRunning()) {
activeRemoteOutputPortCount++;
} else {
inactiveRemoteOutputPortCount++;
}
}
}
final RemoteProcessGroupContentsDTO contents = new RemoteProcessGroupContentsDTO();
contents.setInputPorts(inputPorts);
contents.setOutputPorts(outputPorts);
final RemoteProcessGroupDTO dto = new RemoteProcessGroupDTO();
dto.setId(group.getIdentifier());
dto.setName(group.getName());
dto.setPosition(createPositionDto(group.getPosition()));
dto.setComments(group.getComments());
dto.setTransmitting(group.isTransmitting());
dto.setCommunicationsTimeout(group.getCommunicationsTimeout());
dto.setYieldDuration(group.getYieldDuration());
dto.setParentGroupId(group.getProcessGroup().getIdentifier());
dto.setTargetUris(group.getTargetUris());
dto.setFlowRefreshed(group.getLastRefreshTime());
dto.setContents(contents);
dto.setTransportProtocol(group.getTransportProtocol().name());
dto.setProxyHost(group.getProxyHost());
dto.setProxyPort(group.getProxyPort());
dto.setProxyUser(group.getProxyUser());
if (!StringUtils.isEmpty(group.getProxyPassword())) {
dto.setProxyPassword(SENSITIVE_VALUE_MASK);
}
// only specify the secure flag if we know the target system has site to site enabled
if (group.isSiteToSiteEnabled()) {
dto.setTargetSecure(group.getSecureFlag());
}
if (group.getAuthorizationIssue() != null) {
dto.setAuthorizationIssues(Arrays.asList(group.getAuthorizationIssue()));
}
final Collection<ValidationResult> validationErrors = group.validate();
if (validationErrors != null && !validationErrors.isEmpty()) {
final List<String> errors = new ArrayList<>();
for (final ValidationResult validationResult : validationErrors) {
errors.add(validationResult.toString());
}
dto.setValidationErrors(errors);
}
dto.setLocalNetworkInterface(group.getNetworkInterface());
dto.setActiveRemoteInputPortCount(activeRemoteInputPortCount);
dto.setInactiveRemoteInputPortCount(inactiveRemoteInputPortCount);
dto.setActiveRemoteOutputPortCount(activeRemoteOutputPortCount);
dto.setInactiveRemoteOutputPortCount(inactiveRemoteOutputPortCount);
dto.setVersionedComponentId(group.getVersionedComponentId().orElse(null));
final RemoteProcessGroupCounts counts = group.getCounts();
if (counts != null) {
dto.setInputPortCount(counts.getInputPortCount());
dto.setOutputPortCount(counts.getOutputPortCount());
}
return dto;
}
use of org.apache.nifi.components.ValidationResult in project nifi by apache.
the class DtoFactory method createProcessorDto.
/**
* Creates a ProcessorDTO from the specified ProcessorNode.
*
* @param node node
* @return dto
*/
public ProcessorDTO createProcessorDto(final ProcessorNode node) {
if (node == null) {
return null;
}
final BundleCoordinate bundleCoordinate = node.getBundleCoordinate();
final List<Bundle> compatibleBundles = ExtensionManager.getBundles(node.getCanonicalClassName()).stream().filter(bundle -> {
final BundleCoordinate coordinate = bundle.getBundleDetails().getCoordinate();
return bundleCoordinate.getGroup().equals(coordinate.getGroup()) && bundleCoordinate.getId().equals(coordinate.getId());
}).collect(Collectors.toList());
final ProcessorDTO dto = new ProcessorDTO();
dto.setId(node.getIdentifier());
dto.setPosition(createPositionDto(node.getPosition()));
dto.setStyle(node.getStyle());
dto.setParentGroupId(node.getProcessGroup().getIdentifier());
dto.setInputRequirement(node.getInputRequirement().name());
dto.setPersistsState(node.getProcessor().getClass().isAnnotationPresent(Stateful.class));
dto.setRestricted(node.isRestricted());
dto.setDeprecated(node.isDeprecated());
dto.setExtensionMissing(node.isExtensionMissing());
dto.setMultipleVersionsAvailable(compatibleBundles.size() > 1);
dto.setVersionedComponentId(node.getVersionedComponentId().orElse(null));
dto.setType(node.getCanonicalClassName());
dto.setBundle(createBundleDto(bundleCoordinate));
dto.setName(node.getName());
dto.setState(node.getScheduledState().toString());
// build the relationship dtos
final List<RelationshipDTO> relationships = new ArrayList<>();
for (final Relationship rel : node.getRelationships()) {
final RelationshipDTO relationshipDTO = new RelationshipDTO();
relationshipDTO.setDescription(rel.getDescription());
relationshipDTO.setName(rel.getName());
relationshipDTO.setAutoTerminate(node.isAutoTerminated(rel));
relationships.add(relationshipDTO);
}
// sort the relationships
Collections.sort(relationships, new Comparator<RelationshipDTO>() {
@Override
public int compare(final RelationshipDTO r1, final RelationshipDTO r2) {
return Collator.getInstance(Locale.US).compare(r1.getName(), r2.getName());
}
});
// set the relationships
dto.setRelationships(relationships);
dto.setDescription(getCapabilityDescription(node.getClass()));
dto.setSupportsParallelProcessing(!node.isTriggeredSerially());
dto.setSupportsEventDriven(node.isEventDrivenSupported());
dto.setSupportsBatching(node.isSessionBatchingSupported());
dto.setConfig(createProcessorConfigDto(node));
final Collection<ValidationResult> validationErrors = node.getValidationErrors();
if (validationErrors != null && !validationErrors.isEmpty()) {
final List<String> errors = new ArrayList<>();
for (final ValidationResult validationResult : validationErrors) {
errors.add(validationResult.toString());
}
dto.setValidationErrors(errors);
}
return dto;
}
use of org.apache.nifi.components.ValidationResult in project nifi by apache.
the class DtoFactory method createControllerServiceReferencingComponentDTO.
public ControllerServiceReferencingComponentDTO createControllerServiceReferencingComponentDTO(final ConfiguredComponent component) {
final ControllerServiceReferencingComponentDTO dto = new ControllerServiceReferencingComponentDTO();
dto.setId(component.getIdentifier());
dto.setName(component.getName());
String processGroupId = null;
List<PropertyDescriptor> propertyDescriptors = null;
Collection<ValidationResult> validationErrors = null;
if (component instanceof ProcessorNode) {
final ProcessorNode node = ((ProcessorNode) component);
dto.setGroupId(node.getProcessGroup().getIdentifier());
dto.setState(node.getScheduledState().name());
dto.setActiveThreadCount(node.getActiveThreadCount());
dto.setType(node.getComponentType());
dto.setReferenceType(Processor.class.getSimpleName());
propertyDescriptors = node.getProcessor().getPropertyDescriptors();
validationErrors = node.getValidationErrors();
processGroupId = node.getProcessGroup().getIdentifier();
} else if (component instanceof ControllerServiceNode) {
final ControllerServiceNode node = ((ControllerServiceNode) component);
dto.setState(node.getState().name());
dto.setType(node.getComponentType());
dto.setReferenceType(ControllerService.class.getSimpleName());
propertyDescriptors = node.getControllerServiceImplementation().getPropertyDescriptors();
validationErrors = node.getValidationErrors();
processGroupId = node.getProcessGroup() == null ? null : node.getProcessGroup().getIdentifier();
} else if (component instanceof ReportingTaskNode) {
final ReportingTaskNode node = ((ReportingTaskNode) component);
dto.setState(node.getScheduledState().name());
dto.setActiveThreadCount(node.getActiveThreadCount());
dto.setType(node.getComponentType());
dto.setReferenceType(ReportingTask.class.getSimpleName());
propertyDescriptors = node.getReportingTask().getPropertyDescriptors();
validationErrors = node.getValidationErrors();
processGroupId = null;
}
if (propertyDescriptors != null && !propertyDescriptors.isEmpty()) {
final Map<PropertyDescriptor, String> sortedProperties = new TreeMap<>(new Comparator<PropertyDescriptor>() {
@Override
public int compare(final PropertyDescriptor o1, final PropertyDescriptor o2) {
return Collator.getInstance(Locale.US).compare(o1.getName(), o2.getName());
}
});
sortedProperties.putAll(component.getProperties());
final Map<PropertyDescriptor, String> orderedProperties = new LinkedHashMap<>();
for (final PropertyDescriptor descriptor : propertyDescriptors) {
orderedProperties.put(descriptor, null);
}
orderedProperties.putAll(sortedProperties);
// build the descriptor and property dtos
dto.setDescriptors(new LinkedHashMap<String, PropertyDescriptorDTO>());
dto.setProperties(new LinkedHashMap<String, String>());
for (final Map.Entry<PropertyDescriptor, String> entry : orderedProperties.entrySet()) {
final PropertyDescriptor descriptor = entry.getKey();
// store the property descriptor
dto.getDescriptors().put(descriptor.getName(), createPropertyDescriptorDto(descriptor, processGroupId));
// determine the property value - don't include sensitive properties
String propertyValue = entry.getValue();
if (propertyValue != null && descriptor.isSensitive()) {
propertyValue = SENSITIVE_VALUE_MASK;
}
// set the property value
dto.getProperties().put(descriptor.getName(), propertyValue);
}
}
if (validationErrors != null && !validationErrors.isEmpty()) {
final List<String> errors = new ArrayList<>();
for (final ValidationResult validationResult : validationErrors) {
errors.add(validationResult.toString());
}
dto.setValidationErrors(errors);
}
return dto;
}
use of org.apache.nifi.components.ValidationResult in project nifi by apache.
the class DtoFactory method createReportingTaskDto.
public ReportingTaskDTO createReportingTaskDto(final ReportingTaskNode reportingTaskNode) {
final BundleCoordinate bundleCoordinate = reportingTaskNode.getBundleCoordinate();
final List<Bundle> compatibleBundles = ExtensionManager.getBundles(reportingTaskNode.getCanonicalClassName()).stream().filter(bundle -> {
final BundleCoordinate coordinate = bundle.getBundleDetails().getCoordinate();
return bundleCoordinate.getGroup().equals(coordinate.getGroup()) && bundleCoordinate.getId().equals(coordinate.getId());
}).collect(Collectors.toList());
final ReportingTaskDTO dto = new ReportingTaskDTO();
dto.setId(reportingTaskNode.getIdentifier());
dto.setName(reportingTaskNode.getName());
dto.setType(reportingTaskNode.getCanonicalClassName());
dto.setBundle(createBundleDto(bundleCoordinate));
dto.setSchedulingStrategy(reportingTaskNode.getSchedulingStrategy().name());
dto.setSchedulingPeriod(reportingTaskNode.getSchedulingPeriod());
dto.setState(reportingTaskNode.getScheduledState().name());
dto.setActiveThreadCount(reportingTaskNode.getActiveThreadCount());
dto.setAnnotationData(reportingTaskNode.getAnnotationData());
dto.setComments(reportingTaskNode.getComments());
dto.setPersistsState(reportingTaskNode.getReportingTask().getClass().isAnnotationPresent(Stateful.class));
dto.setRestricted(reportingTaskNode.isRestricted());
dto.setDeprecated(reportingTaskNode.isDeprecated());
dto.setExtensionMissing(reportingTaskNode.isExtensionMissing());
dto.setMultipleVersionsAvailable(compatibleBundles.size() > 1);
final Map<String, String> defaultSchedulingPeriod = new HashMap<>();
defaultSchedulingPeriod.put(SchedulingStrategy.TIMER_DRIVEN.name(), SchedulingStrategy.TIMER_DRIVEN.getDefaultSchedulingPeriod());
defaultSchedulingPeriod.put(SchedulingStrategy.CRON_DRIVEN.name(), SchedulingStrategy.CRON_DRIVEN.getDefaultSchedulingPeriod());
dto.setDefaultSchedulingPeriod(defaultSchedulingPeriod);
// sort a copy of the properties
final Map<PropertyDescriptor, String> sortedProperties = new TreeMap<>(new Comparator<PropertyDescriptor>() {
@Override
public int compare(final PropertyDescriptor o1, final PropertyDescriptor o2) {
return Collator.getInstance(Locale.US).compare(o1.getName(), o2.getName());
}
});
sortedProperties.putAll(reportingTaskNode.getProperties());
// get the property order from the reporting task
final ReportingTask reportingTask = reportingTaskNode.getReportingTask();
final Map<PropertyDescriptor, String> orderedProperties = new LinkedHashMap<>();
final List<PropertyDescriptor> descriptors = reportingTask.getPropertyDescriptors();
if (descriptors != null && !descriptors.isEmpty()) {
for (final PropertyDescriptor descriptor : descriptors) {
orderedProperties.put(descriptor, null);
}
}
orderedProperties.putAll(sortedProperties);
// build the descriptor and property dtos
dto.setDescriptors(new LinkedHashMap<String, PropertyDescriptorDTO>());
dto.setProperties(new LinkedHashMap<String, String>());
for (final Map.Entry<PropertyDescriptor, String> entry : orderedProperties.entrySet()) {
final PropertyDescriptor descriptor = entry.getKey();
// store the property descriptor
dto.getDescriptors().put(descriptor.getName(), createPropertyDescriptorDto(descriptor, null));
// determine the property value - don't include sensitive properties
String propertyValue = entry.getValue();
if (propertyValue != null && descriptor.isSensitive()) {
propertyValue = SENSITIVE_VALUE_MASK;
}
// set the property value
dto.getProperties().put(descriptor.getName(), propertyValue);
}
// add the validation errors
final Collection<ValidationResult> validationErrors = reportingTaskNode.getValidationErrors();
if (validationErrors != null && !validationErrors.isEmpty()) {
final List<String> errors = new ArrayList<>();
for (final ValidationResult validationResult : validationErrors) {
errors.add(validationResult.toString());
}
dto.setValidationErrors(errors);
}
return dto;
}
Aggregations