use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.
the class DtoFactory method createControllerServiceDto.
public ControllerServiceDTO createControllerServiceDto(final ControllerServiceNode controllerServiceNode) {
final BundleCoordinate bundleCoordinate = controllerServiceNode.getBundleCoordinate();
final List<Bundle> compatibleBundles = ExtensionManager.getBundles(controllerServiceNode.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 ControllerServiceDTO dto = new ControllerServiceDTO();
dto.setId(controllerServiceNode.getIdentifier());
dto.setParentGroupId(controllerServiceNode.getProcessGroup() == null ? null : controllerServiceNode.getProcessGroup().getIdentifier());
dto.setName(controllerServiceNode.getName());
dto.setType(controllerServiceNode.getCanonicalClassName());
dto.setBundle(createBundleDto(bundleCoordinate));
dto.setControllerServiceApis(createControllerServiceApiDto(controllerServiceNode.getControllerServiceImplementation().getClass()));
dto.setState(controllerServiceNode.getState().name());
dto.setAnnotationData(controllerServiceNode.getAnnotationData());
dto.setComments(controllerServiceNode.getComments());
dto.setPersistsState(controllerServiceNode.getControllerServiceImplementation().getClass().isAnnotationPresent(Stateful.class));
dto.setRestricted(controllerServiceNode.isRestricted());
dto.setDeprecated(controllerServiceNode.isDeprecated());
dto.setExtensionMissing(controllerServiceNode.isExtensionMissing());
dto.setMultipleVersionsAvailable(compatibleBundles.size() > 1);
dto.setVersionedComponentId(controllerServiceNode.getVersionedComponentId().orElse(null));
// 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(controllerServiceNode.getProperties());
// get the property order from the controller service
final ControllerService controllerService = controllerServiceNode.getControllerServiceImplementation();
final Map<PropertyDescriptor, String> orderedProperties = new LinkedHashMap<>();
final List<PropertyDescriptor> descriptors = controllerService.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
final String groupId = controllerServiceNode.getProcessGroup() == null ? null : controllerServiceNode.getProcessGroup().getIdentifier();
dto.getDescriptors().put(descriptor.getName(), createPropertyDescriptorDto(descriptor, groupId));
// 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 = controllerServiceNode.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.service.ControllerServiceNode in project nifi by apache.
the class DtoFactory method createReferencedServiceDiagnostics.
private Set<ControllerServiceDiagnosticsDTO> createReferencedServiceDiagnostics(final Map<PropertyDescriptor, String> properties, final ControllerServiceProvider serviceProvider, final Function<String, ControllerServiceEntity> serviceEntityFactory) {
final Set<ControllerServiceDiagnosticsDTO> referencedServiceDiagnostics = new HashSet<>();
for (final Map.Entry<PropertyDescriptor, String> entry : properties.entrySet()) {
final PropertyDescriptor descriptor = entry.getKey();
if (descriptor.getControllerServiceDefinition() == null) {
continue;
}
final String serviceId = entry.getValue();
final ControllerServiceNode serviceNode = serviceProvider.getControllerServiceNode(serviceId);
if (serviceNode == null) {
continue;
}
final ControllerServiceDiagnosticsDTO serviceDiagnostics = createControllerServiceDiagnosticsDto(serviceNode, serviceEntityFactory, serviceProvider);
if (serviceDiagnostics != null) {
referencedServiceDiagnostics.add(serviceDiagnostics);
}
}
return referencedServiceDiagnostics;
}
use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.
the class DtoFactory method createAffectedComponentDto.
public AffectedComponentDTO createAffectedComponentDto(final ConfiguredComponent component) {
final AffectedComponentDTO dto = new AffectedComponentDTO();
dto.setId(component.getIdentifier());
dto.setName(component.getName());
dto.setProcessGroupId(component.getProcessGroupIdentifier());
if (component instanceof ProcessorNode) {
final ProcessorNode node = ((ProcessorNode) component);
dto.setState(node.getScheduledState().name());
dto.setActiveThreadCount(node.getActiveThreadCount());
dto.setReferenceType(AffectedComponentDTO.COMPONENT_TYPE_PROCESSOR);
} else if (component instanceof ControllerServiceNode) {
final ControllerServiceNode node = ((ControllerServiceNode) component);
dto.setState(node.getState().name());
dto.setReferenceType(AffectedComponentDTO.COMPONENT_TYPE_CONTROLLER_SERVICE);
}
final Collection<ValidationResult> validationErrors = component.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.service.ControllerServiceNode in project nifi by apache.
the class StandardControllerServiceDAO method verifyDelete.
@Override
public void verifyDelete(final String controllerServiceId) {
final ControllerServiceNode controllerService = locateControllerService(controllerServiceId);
controllerService.verifyCanDelete();
}
use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.
the class StandardControllerServiceDAO method verifyClearState.
@Override
public void verifyClearState(final String controllerServiceId) {
final ControllerServiceNode controllerService = locateControllerService(controllerServiceId);
controllerService.verifyCanClearState();
}
Aggregations