use of org.apache.nifi.bundle.BundleCoordinate 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.bundle.BundleCoordinate 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.bundle.BundleCoordinate 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.bundle.BundleCoordinate in project nifi by apache.
the class StandardControllerServiceDAO method updateBundle.
private void updateBundle(final ControllerServiceNode controllerService, final ControllerServiceDTO controllerServiceDTO) {
final BundleDTO bundleDTO = controllerServiceDTO.getBundle();
if (bundleDTO != null) {
final BundleCoordinate incomingCoordinate = BundleUtils.getBundle(controllerService.getCanonicalClassName(), bundleDTO);
final BundleCoordinate existingCoordinate = controllerService.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(controllerService.getCanonicalClassName(), incomingCoordinate);
final Set<URL> additionalUrls = controllerService.getAdditionalClasspathResources(tempComponent.getPropertyDescriptors());
flowController.reload(controllerService, controllerService.getCanonicalClassName(), incomingCoordinate, additionalUrls);
} catch (ControllerServiceInstantiationException e) {
throw new NiFiCoreException(String.format("Unable to update controller service %s from %s to %s due to: %s", controllerServiceDTO.getId(), controllerService.getBundleCoordinate().getCoordinate(), incomingCoordinate.getCoordinate(), e.getMessage()), e);
}
}
}
}
use of org.apache.nifi.bundle.BundleCoordinate in project nifi by apache.
the class StandardProcessorDAO method updateBundle.
private void updateBundle(ProcessorNode processor, ProcessorDTO processorDTO) {
final BundleDTO bundleDTO = processorDTO.getBundle();
if (bundleDTO != null) {
final BundleCoordinate incomingCoordinate = BundleUtils.getBundle(processor.getCanonicalClassName(), bundleDTO);
final BundleCoordinate existingCoordinate = processor.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(processor.getCanonicalClassName(), incomingCoordinate);
final Set<URL> additionalUrls = processor.getAdditionalClasspathResources(tempComponent.getPropertyDescriptors());
flowController.reload(processor, processor.getCanonicalClassName(), incomingCoordinate, additionalUrls);
} catch (ProcessorInstantiationException e) {
throw new NiFiCoreException(String.format("Unable to update processor %s from %s to %s due to: %s", processorDTO.getId(), processor.getBundleCoordinate().getCoordinate(), incomingCoordinate.getCoordinate(), e.getMessage()), e);
}
}
}
}
Aggregations