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; }
final NodeIdentifier nodeId = nodeEntry.getKey(); if (nodeReportingTask.getActiveThreadCount() != null) { activeThreadCount += nodeReportingTask.getActiveThreadCount(); ErrorMerger.mergeErrors(validationErrorMap, nodeId, nodeReportingTask.getValidationErrors()); nodeReportingTask.getDescriptors().values().stream().forEach(propertyDescriptor -> { propertyDescriptorMap.computeIfAbsent(propertyDescriptor.getName(), nodeIdToPropertyDescriptor -> new HashMap<>()).put(nodeId, propertyDescriptor); }); final PropertyDescriptorDTO clientPropertyDescriptor = clientDto.getDescriptors().get(propertyDescriptor.getName()); PropertyDescriptorDtoMerger.merge(clientPropertyDescriptor, propertyDescriptorByNodeId); clientDto.setActiveThreadCount(activeThreadCount); clientDto.setValidationStatus(ErrorMerger.mergeValidationStatus(validationStatuses)); clientDto.setValidationErrors(ErrorMerger.normalizedMergedErrors(validationErrorMap, dtoMap.size()));
private void addReportingTaskFingerprint(final StringBuilder builder, final ReportingTaskDTO dto) { builder.append(dto.getId()); builder.append(dto.getType()); builder.append(dto.getName()); addBundleFingerprint(builder, dto.getBundle()); builder.append(dto.getComments()); builder.append(dto.getSchedulingPeriod()); builder.append(dto.getSchedulingStrategy()); builder.append(dto.getAnnotationData()); // get the temp instance of the ReportingTask so that we know the default property values final BundleCoordinate coordinate = getCoordinate(dto.getType(), dto.getBundle()); final ConfigurableComponent configurableComponent = extensionManager.getTempComponent(dto.getType(), coordinate); if (configurableComponent == null) { logger.warn("Unable to get ReportingTask of type {}; its default properties will be fingerprinted instead of being ignored.", dto.getType()); } addPropertiesFingerprint(builder, configurableComponent, dto.getProperties()); }
private ReportingTaskDTO createDTOWithDesiredRunStatus(final String id, final String runStatus) { final ReportingTaskDTO dto = new ReportingTaskDTO(); dto.setId(id); dto.setState(runStatus); return dto; }
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); dto.setDefaultSchedulingPeriod(defaultSchedulingPeriod); 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(); dto.getDescriptors().put(descriptor.getName(), createPropertyDescriptorDto(descriptor, null)); dto.getProperties().put(descriptor.getName(), propertyValue); dto.setValidationStatus(validationStatus.name());
private ComponentDetails getComponentConfiguration(final ReportingTaskDTO reportingTask) { return new ComponentDetails.Builder() .id(reportingTask.getId()) .name(reportingTask.getName()) .type(reportingTask.getType()) .state(reportingTask.getState()) .annotationData(reportingTask.getAnnotationData()) .properties(reportingTask.getProperties()) .validateErrors(reportingTask.getValidationErrors()).build(); } }
private void verifyUpdate(final ReportingTaskNode reportingTask, final ReportingTaskDTO reportingTaskDTO) { if (isNotNull(reportingTaskDTO.getState())) { try { final ScheduledState purposedScheduledState = ScheduledState.valueOf(reportingTaskDTO.getState()); throw new IllegalArgumentException(String.format( "The specified reporting task state (%s) is not valid. Valid options are 'RUNNING', 'STOPPED', and 'DISABLED'.", reportingTaskDTO.getState())); if (isAnyNotNull(reportingTaskDTO.getName(), reportingTaskDTO.getSchedulingStrategy(), reportingTaskDTO.getSchedulingPeriod(), reportingTaskDTO.getAnnotationData(), reportingTaskDTO.getProperties(), reportingTaskDTO.getBundle())) { modificationRequest = true; final BundleDTO bundleDTO = reportingTaskDTO.getBundle(); if (bundleDTO != null) {
private void configureReportingTask(final ReportingTaskNode reportingTask, final ReportingTaskDTO reportingTaskDTO) { final String name = reportingTaskDTO.getName(); final String schedulingStrategy = reportingTaskDTO.getSchedulingStrategy(); final String schedulingPeriod = reportingTaskDTO.getSchedulingPeriod(); final String annotationData = reportingTaskDTO.getAnnotationData(); final String comments = reportingTaskDTO.getComments(); final Map<String, String> properties = reportingTaskDTO.getProperties();
if (requestReportingTask.getId() != null) { throw new IllegalArgumentException("Reporting task ID cannot be specified."); if (StringUtils.isBlank(requestReportingTask.getType())) { throw new IllegalArgumentException("The type of reporting task to create must be specified."); authorizable = lookup.getConfigurableComponent(requestReportingTask.getType(), requestReportingTask.getBundle()); if (requestReportingTask.getProperties() != null) { AuthorizeControllerServiceReference.authorizeControllerServiceReferences(requestReportingTask.getProperties(), authorizable, authorizer, lookup); reportingTask.setId(generateUuid()); final Revision revision = getRevision(reportingTaskEntity, reportingTask.getId()); final ReportingTaskEntity entity = serviceFacade.createReportingTask(revision, reportingTask); reportingTaskResource.populateRemainingReportingTaskEntityContent(entity);
Map<String, String> values = new HashMap<>(); if (reportingTaskDTO.getName() != null) { values.put(NAME, reportingTask.getName()); if (reportingTaskDTO.getAnnotationData() != null) { values.put(ANNOTATION_DATA, reportingTask.getAnnotationData()); if (reportingTaskDTO.getBundle() != null) { final BundleCoordinate bundle = reportingTask.getBundleCoordinate(); values.put(EXTENSION_VERSION, formatExtensionVersion(reportingTask.getComponentType(), bundle)); if (reportingTaskDTO.getProperties() != null) { Map<String, String> properties = reportingTaskDTO.getProperties(); Map<PropertyDescriptor, String> configuredProperties = reportingTask.getProperties(); for (String propertyName : properties.keySet()) {
final ReportingTaskDTO reportingTaskDto = new ReportingTaskDTO(); reportingTaskEntity.setComponent(reportingTaskDto); reportingTaskDto.setId(id); reportingTaskDto.setAnnotationData(annotationData); reportingTaskDto.setProperties(properties); final ReportingTaskDTO reportingTaskDto = new ReportingTaskDTO(); reportingTaskDto.setId(id); reportingTaskDto.setAnnotationData(annotationData); reportingTaskDto.setProperties(properties);
public ReportingTaskEntity createReportingTaskEntity(final ReportingTaskDTO dto, final RevisionDTO revision, final PermissionsDTO permissions, final PermissionsDTO operatePermissions, final List<BulletinEntity> bulletins) { final ReportingTaskEntity entity = new ReportingTaskEntity(); entity.setRevision(revision); if (dto != null) { entity.setPermissions(permissions); entity.setOperatePermissions(operatePermissions); entity.setId(dto.getId()); final ReportingTaskStatusDTO status = new ReportingTaskStatusDTO(); status.setRunStatus(dto.getState()); status.setValidationStatus(dto.getValidationStatus()); status.setActiveThreadCount(dto.getActiveThreadCount()); entity.setStatus(status); if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); entity.setBulletins(bulletins); } } return entity; }
@Override public ReportingTaskNode createReportingTask(final ReportingTaskDTO reportingTaskDTO) { // ensure the type is specified if (reportingTaskDTO.getType() == null) { throw new IllegalArgumentException("The reporting task type must be specified."); } try { // create the reporting task final ExtensionManager extensionManager = reportingTaskProvider.getExtensionManager(); final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(extensionManager, reportingTaskDTO.getType(), reportingTaskDTO.getBundle()); final ReportingTaskNode reportingTask = reportingTaskProvider.createReportingTask( reportingTaskDTO.getType(), reportingTaskDTO.getId(), bundleCoordinate, true); // ensure we can perform the update verifyUpdate(reportingTask, reportingTaskDTO); // perform the update configureReportingTask(reportingTask, reportingTaskDTO); return reportingTask; } catch (ReportingTaskInstantiationException rtie) { throw new NiFiCoreException(rtie.getMessage(), rtie); } }
/** * Populates the uri for the specified reporting task. */ public ReportingTaskDTO populateRemainingReportingTaskContent(final ReportingTaskDTO reportingTask) { final BundleDTO bundle = reportingTask.getBundle(); if (bundle == null) { return reportingTask; } // see if this processor has any ui extensions final UiExtensionMapping uiExtensionMapping = (UiExtensionMapping) servletContext.getAttribute("nifi-ui-extensions"); if (uiExtensionMapping.hasUiExtension(reportingTask.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion())) { final List<UiExtension> uiExtensions = uiExtensionMapping.getUiExtension(reportingTask.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion()); for (final UiExtension uiExtension : uiExtensions) { if (UiExtensionType.ReportingTaskConfiguration.equals(uiExtension.getExtensionType())) { reportingTask.setCustomUiUrl(uiExtension.getContextPath() + "/configure"); } } } return reportingTask; }
if (isNotNull(reportingTaskDTO.getSchedulingStrategy())) { try { schedulingStrategy = SchedulingStrategy.valueOf(reportingTaskDTO.getSchedulingStrategy()); } catch (IllegalArgumentException iae) { validationErrors.add(String.format("Scheduling strategy: Value must be one of [%s]", StringUtils.join(SchedulingStrategy.values(), ", "))); if (isNotNull(reportingTaskDTO.getSchedulingPeriod())) { switch (schedulingStrategy) { case TIMER_DRIVEN: final Matcher schedulingMatcher = FormatUtils.TIME_DURATION_PATTERN.matcher(reportingTaskDTO.getSchedulingPeriod()); if (!schedulingMatcher.matches()) { validationErrors.add("Scheduling period is not a valid time duration (ie 30 sec, 5 min)"); case CRON_DRIVEN: try { new CronExpression(reportingTaskDTO.getSchedulingPeriod()); } catch (final ParseException pe) { throw new IllegalArgumentException(String.format("Scheduling Period '%s' is not a valid cron expression: %s", reportingTaskDTO.getSchedulingPeriod(), pe.getMessage())); } catch (final Exception e) { throw new IllegalArgumentException("Scheduling Period is not a valid cron expression: " + reportingTaskDTO.getSchedulingPeriod());
if (!id.equals(requestReportingTaskDTO.getId())) { throw new IllegalArgumentException(String.format("The reporting task id (%s) in the request body does not equal the " + "reporting task id of the requested resource (%s).", requestReportingTaskDTO.getId(), id)); AuthorizeControllerServiceReference.authorizeControllerServiceReferences(requestReportingTaskDTO.getProperties(), authorizable, authorizer, lookup); }, () -> serviceFacade.verifyUpdateReportingTask(requestReportingTaskDTO),
private void updateBundle(ReportingTaskNode reportingTask, ReportingTaskDTO reportingTaskDTO) { final BundleDTO bundleDTO = reportingTaskDTO.getBundle(); if (bundleDTO != null) { final ExtensionManager extensionManager = reportingTaskProvider.getExtensionManager(); final BundleCoordinate incomingCoordinate = BundleUtils.getBundle(extensionManager, reportingTask.getCanonicalClassName(), bundleDTO); final BundleCoordinate existingCoordinate = reportingTask.getBundleCoordinate(); if (!existingCoordinate.getCoordinate().equals(incomingCoordinate.getCoordinate())) { try { // we need to use the property descriptors from the temp component here in case we are changing from a ghost component to a real component final ConfigurableComponent tempComponent = extensionManager.getTempComponent(reportingTask.getCanonicalClassName(), incomingCoordinate); final Set<URL> additionalUrls = reportingTask.getAdditionalClasspathResources(tempComponent.getPropertyDescriptors()); reloadComponent.reload(reportingTask, reportingTask.getCanonicalClassName(), incomingCoordinate, additionalUrls); } catch (ReportingTaskInstantiationException e) { throw new NiFiCoreException(String.format("Unable to update reporting task %s from %s to %s due to: %s", reportingTaskDTO.getId(), reportingTask.getBundleCoordinate().getCoordinate(), incomingCoordinate.getCoordinate(), e.getMessage()), e); } } } }
@Override public ReportingTaskNode updateReportingTask(final ReportingTaskDTO reportingTaskDTO) { final ReportingTaskNode reportingTask = locateReportingTask(reportingTaskDTO.getId()); if (isNotNull(reportingTaskDTO.getState())) { final ScheduledState purposedScheduledState = ScheduledState.valueOf(reportingTaskDTO.getState());