use of org.apache.nifi.web.api.dto.ReportingTaskDTO in project nifi by apache.
the class FlowFromDOMFactory method getReportingTask.
public static ReportingTaskDTO getReportingTask(final Element element, final StringEncryptor encryptor) {
final ReportingTaskDTO dto = new ReportingTaskDTO();
dto.setId(getString(element, "id"));
dto.setName(getString(element, "name"));
dto.setComments(getString(element, "comment"));
dto.setType(getString(element, "class"));
dto.setBundle(getBundle(DomUtils.getChild(element, "bundle")));
dto.setSchedulingPeriod(getString(element, "schedulingPeriod"));
dto.setState(getString(element, "scheduledState"));
dto.setSchedulingStrategy(getString(element, "schedulingStrategy"));
dto.setProperties(getProperties(element, encryptor));
dto.setAnnotationData(getString(element, "annotationData"));
return dto;
}
use of org.apache.nifi.web.api.dto.ReportingTaskDTO in project nifi by apache.
the class FingerprintFactory method addFlowControllerFingerprint.
private StringBuilder addFlowControllerFingerprint(final StringBuilder builder, final Element flowControllerElem, final FlowController controller) {
// registries
final Element registriesElement = DomUtils.getChild(flowControllerElem, "registries");
if (registriesElement == null) {
builder.append("NO_VALUE");
} else {
final List<Element> flowRegistryElems = DomUtils.getChildElementsByTagName(registriesElement, "flowRegistry");
if (flowRegistryElems.isEmpty()) {
builder.append("NO_VALUE");
} else {
for (final Element flowRegistryElement : flowRegistryElems) {
addFlowRegistryFingerprint(builder, flowRegistryElement);
}
}
}
// root group
final Element rootGroupElem = (Element) DomUtils.getChildNodesByTagName(flowControllerElem, "rootGroup").item(0);
addProcessGroupFingerprint(builder, rootGroupElem, controller);
final Element controllerServicesElem = DomUtils.getChild(flowControllerElem, "controllerServices");
if (controllerServicesElem != null) {
final List<ControllerServiceDTO> serviceDtos = new ArrayList<>();
for (final Element serviceElem : DomUtils.getChildElementsByTagName(controllerServicesElem, "controllerService")) {
final ControllerServiceDTO dto = FlowFromDOMFactory.getControllerService(serviceElem, encryptor);
serviceDtos.add(dto);
}
Collections.sort(serviceDtos, new Comparator<ControllerServiceDTO>() {
@Override
public int compare(final ControllerServiceDTO o1, final ControllerServiceDTO o2) {
if (o1 == null && o2 == null) {
return 0;
}
if (o1 == null && o2 != null) {
return 1;
}
if (o1 != null && o2 == null) {
return -1;
}
return o1.getId().compareTo(o2.getId());
}
});
for (final ControllerServiceDTO dto : serviceDtos) {
addControllerServiceFingerprint(builder, dto);
}
}
final Element reportingTasksElem = DomUtils.getChild(flowControllerElem, "reportingTasks");
if (reportingTasksElem != null) {
final List<ReportingTaskDTO> reportingTaskDtos = new ArrayList<>();
for (final Element taskElem : DomUtils.getChildElementsByTagName(reportingTasksElem, "reportingTask")) {
final ReportingTaskDTO dto = FlowFromDOMFactory.getReportingTask(taskElem, encryptor);
reportingTaskDtos.add(dto);
}
Collections.sort(reportingTaskDtos, new Comparator<ReportingTaskDTO>() {
@Override
public int compare(final ReportingTaskDTO o1, final ReportingTaskDTO o2) {
if (o1 == null && o2 == null) {
return 0;
}
if (o1 == null && o2 != null) {
return 1;
}
if (o1 != null && o2 == null) {
return -1;
}
return o1.getId().compareTo(o2.getId());
}
});
for (final ReportingTaskDTO dto : reportingTaskDtos) {
addReportingTaskFingerprint(builder, dto);
}
}
return builder;
}
use of org.apache.nifi.web.api.dto.ReportingTaskDTO in project nifi by apache.
the class StandardNiFiServiceFacade method createReportingTask.
@Override
public ReportingTaskEntity createReportingTask(final Revision revision, final ReportingTaskDTO reportingTaskDTO) {
final NiFiUser user = NiFiUserUtils.getNiFiUser();
// request claim for component to be created... revision already verified (version == 0)
final RevisionClaim claim = new StandardRevisionClaim(revision);
// update revision through revision manager
final RevisionUpdate<ReportingTaskDTO> snapshot = revisionManager.updateRevision(claim, user, () -> {
// create the reporting task
final ReportingTaskNode reportingTask = reportingTaskDAO.createReportingTask(reportingTaskDTO);
// save the update
controllerFacade.save();
final ReportingTaskDTO dto = dtoFactory.createReportingTaskDto(reportingTask);
final FlowModification lastMod = new FlowModification(revision.incrementRevision(revision.getClientId()), user.getIdentity());
return new StandardRevisionUpdate<>(dto, lastMod);
});
final ReportingTaskNode reportingTask = reportingTaskDAO.getReportingTask(reportingTaskDTO.getId());
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.web.api.dto.ReportingTaskDTO in project nifi by apache.
the class StandardNiFiServiceFacade method deleteReportingTask.
@Override
public ReportingTaskEntity deleteReportingTask(final Revision revision, final String reportingTaskId) {
final ReportingTaskNode reportingTask = reportingTaskDAO.getReportingTask(reportingTaskId);
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(reportingTask);
final ReportingTaskDTO snapshot = deleteComponent(revision, reportingTask.getResource(), () -> reportingTaskDAO.deleteReportingTask(reportingTaskId), true, dtoFactory.createReportingTaskDto(reportingTask));
return entityFactory.createReportingTaskEntity(snapshot, null, permissions, null);
}
use of org.apache.nifi.web.api.dto.ReportingTaskDTO in project nifi by apache.
the class ReportingTaskEntityMerger method mergeDtos.
private static void mergeDtos(final ReportingTaskDTO clientDto, final Map<NodeIdentifier, ReportingTaskDTO> dtoMap) {
// if unauthorized for the client dto, simple return
if (clientDto == null) {
return;
}
final Map<String, Set<NodeIdentifier>> validationErrorMap = new HashMap<>();
final Map<String, Map<NodeIdentifier, PropertyDescriptorDTO>> propertyDescriptorMap = new HashMap<>();
int activeThreadCount = 0;
for (final Map.Entry<NodeIdentifier, ReportingTaskDTO> nodeEntry : dtoMap.entrySet()) {
final ReportingTaskDTO nodeReportingTask = nodeEntry.getValue();
// consider the node reporting task if authorized
if (nodeReportingTask != null) {
final NodeIdentifier nodeId = nodeEntry.getKey();
if (nodeReportingTask.getActiveThreadCount() != null) {
activeThreadCount += nodeReportingTask.getActiveThreadCount();
}
// merge the validation errors
ErrorMerger.mergeErrors(validationErrorMap, nodeId, nodeReportingTask.getValidationErrors());
// aggregate the property descriptors
nodeReportingTask.getDescriptors().values().stream().forEach(propertyDescriptor -> {
propertyDescriptorMap.computeIfAbsent(propertyDescriptor.getName(), nodeIdToPropertyDescriptor -> new HashMap<>()).put(nodeId, propertyDescriptor);
});
}
}
// merge property descriptors
for (Map<NodeIdentifier, PropertyDescriptorDTO> propertyDescriptorByNodeId : propertyDescriptorMap.values()) {
final Collection<PropertyDescriptorDTO> nodePropertyDescriptors = propertyDescriptorByNodeId.values();
if (!nodePropertyDescriptors.isEmpty()) {
// get the name of the property descriptor and find that descriptor being returned to the client
final PropertyDescriptorDTO propertyDescriptor = nodePropertyDescriptors.iterator().next();
final PropertyDescriptorDTO clientPropertyDescriptor = clientDto.getDescriptors().get(propertyDescriptor.getName());
PropertyDescriptorDtoMerger.merge(clientPropertyDescriptor, propertyDescriptorByNodeId);
}
}
// set the merged active thread counts
clientDto.setActiveThreadCount(activeThreadCount);
// set the merged the validation errors
clientDto.setValidationErrors(ErrorMerger.normalizedMergedErrors(validationErrorMap, dtoMap.size()));
}
Aggregations