use of org.apache.nifi.controller.ReportingTaskNode in project nifi by apache.
the class StandardNiFiServiceFacade method getReportingTaskPropertyDescriptor.
@Override
public PropertyDescriptorDTO getReportingTaskPropertyDescriptor(final String id, final String property) {
final ReportingTaskNode reportingTask = reportingTaskDAO.getReportingTask(id);
PropertyDescriptor descriptor = reportingTask.getReportingTask().getPropertyDescriptor(property);
// return an invalid descriptor if the reporting task doesn't support this property
if (descriptor == null) {
descriptor = new PropertyDescriptor.Builder().name(property).addValidator(Validator.INVALID).dynamic(true).build();
}
return dtoFactory.createPropertyDescriptorDto(descriptor, null);
}
use of org.apache.nifi.controller.ReportingTaskNode in project nifi by apache.
the class StandardNiFiServiceFacade method updateReportingTask.
@Override
public ReportingTaskEntity updateReportingTask(final Revision revision, final ReportingTaskDTO reportingTaskDTO) {
// get the component, ensure we have access to it, and perform the update request
final ReportingTaskNode reportingTask = reportingTaskDAO.getReportingTask(reportingTaskDTO.getId());
final RevisionUpdate<ReportingTaskDTO> snapshot = updateComponent(revision, reportingTask, () -> reportingTaskDAO.updateReportingTask(reportingTaskDTO), rt -> dtoFactory.createReportingTaskDto(rt));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(reportingTask);
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(reportingTask.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
return entityFactory.createReportingTaskEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, bulletinEntities);
}
use of org.apache.nifi.controller.ReportingTaskNode 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.controller.ReportingTaskNode 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;
}
use of org.apache.nifi.controller.ReportingTaskNode in project nifi by apache.
the class StandardNiFiServiceFacade method createReportingTaskEntity.
private ReportingTaskEntity createReportingTaskEntity(final ReportingTaskNode reportingTask) {
final RevisionDTO revision = dtoFactory.createRevisionDTO(revisionManager.getRevision(reportingTask.getIdentifier()));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(reportingTask);
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(reportingTask.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
return entityFactory.createReportingTaskEntity(dtoFactory.createReportingTaskDto(reportingTask), revision, permissions, bulletinEntities);
}
Aggregations