use of org.apache.nifi.bundle.BundleCoordinate in project nifi by apache.
the class DtoFactory method createControllerServiceApiDto.
private List<ControllerServiceApiDTO> createControllerServiceApiDto(final Class cls) {
final Set<Class> serviceApis = new HashSet<>();
// if this is a controller service
if (ControllerService.class.isAssignableFrom(cls)) {
// get all of it's interfaces to determine the controller service api's it implements
final List<Class<?>> interfaces = ClassUtils.getAllInterfaces(cls);
for (final Class i : interfaces) {
// add all controller services that's not ControllerService itself
if (ControllerService.class.isAssignableFrom(i) && !ControllerService.class.equals(i)) {
serviceApis.add(i);
}
}
final List<ControllerServiceApiDTO> dtos = new ArrayList<>();
for (final Class serviceApi : serviceApis) {
final Bundle bundle = ExtensionManager.getBundle(serviceApi.getClassLoader());
final BundleCoordinate bundleCoordinate = bundle.getBundleDetails().getCoordinate();
final ControllerServiceApiDTO dto = new ControllerServiceApiDTO();
dto.setType(serviceApi.getName());
dto.setBundle(createBundleDto(bundleCoordinate));
dtos.add(dto);
}
return dtos;
} else {
return null;
}
}
use of org.apache.nifi.bundle.BundleCoordinate 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.bundle.BundleCoordinate in project nifi by apache.
the class DtoFactory method fromDocumentedTypes.
/**
* Gets the DocumentedTypeDTOs from the specified classes.
*
* @param classes classes
* @param bundleGroupFilter if specified, must be member of bundle group
* @param bundleArtifactFilter if specified, must be member of bundle artifact
* @param typeFilter if specified, type must match
* @return dtos
*/
public Set<DocumentedTypeDTO> fromDocumentedTypes(final Map<Class, Bundle> classes, final String bundleGroupFilter, final String bundleArtifactFilter, final String typeFilter) {
final Set<DocumentedTypeDTO> types = new LinkedHashSet<>();
final List<Class> sortedClasses = new ArrayList<>(classes.keySet());
Collections.sort(sortedClasses, CLASS_NAME_COMPARATOR);
for (final Class cls : sortedClasses) {
final Bundle bundle = classes.get(cls);
final BundleCoordinate coordinate = bundle.getBundleDetails().getCoordinate();
// only include classes that meet the criteria if specified
if (bundleGroupFilter != null && !bundleGroupFilter.equals(coordinate.getGroup())) {
continue;
}
if (bundleArtifactFilter != null && !bundleArtifactFilter.equals(coordinate.getId())) {
continue;
}
if (typeFilter != null && !typeFilter.equals(cls.getName())) {
continue;
}
final DocumentedTypeDTO dto = new DocumentedTypeDTO();
dto.setType(cls.getName());
dto.setBundle(createBundleDto(coordinate));
dto.setControllerServiceApis(createControllerServiceApiDto(cls));
dto.setDescription(getCapabilityDescription(cls));
dto.setRestricted(isRestricted(cls));
dto.setUsageRestriction(getUsageRestriction(cls));
dto.setExplicitRestrictions(getExplicitRestrictions(cls));
dto.setDeprecationReason(getDeprecationReason(cls));
dto.setTags(getTags(cls));
types.add(dto);
}
return types;
}
use of org.apache.nifi.bundle.BundleCoordinate in project nifi by apache.
the class ProcessGroupResource method discoverCompatibleBundles.
// -----------------
// template instance
// -----------------
/**
* Discovers the compatible bundle details for the components in the specified snippet.
*
* @param snippet the snippet
*/
private void discoverCompatibleBundles(final FlowSnippetDTO snippet) {
if (snippet.getProcessors() != null) {
snippet.getProcessors().forEach(processor -> {
final BundleCoordinate coordinate = BundleUtils.getCompatibleBundle(processor.getType(), processor.getBundle());
processor.setBundle(new BundleDTO(coordinate.getGroup(), coordinate.getId(), coordinate.getVersion()));
});
}
if (snippet.getControllerServices() != null) {
snippet.getControllerServices().forEach(controllerService -> {
final BundleCoordinate coordinate = BundleUtils.getCompatibleBundle(controllerService.getType(), controllerService.getBundle());
controllerService.setBundle(new BundleDTO(coordinate.getGroup(), coordinate.getId(), coordinate.getVersion()));
});
}
if (snippet.getProcessGroups() != null) {
snippet.getProcessGroups().forEach(processGroup -> {
discoverCompatibleBundles(processGroup.getContents());
});
}
}
use of org.apache.nifi.bundle.BundleCoordinate in project nifi by apache.
the class ControllerFacade method getControllerServiceTypes.
/**
* Gets the ControllerService types that this controller supports.
*
* @param serviceType type
* @param serviceBundleGroup if serviceType specified, the bundle group of the serviceType
* @param serviceBundleArtifact if serviceType specified, the bundle artifact of the serviceType
* @param serviceBundleVersion if serviceType specified, the bundle version of the serviceType
* @param bundleGroupFilter if specified, must be member of bundle group
* @param bundleArtifactFilter if specified, must be member of bundle artifact
* @param typeFilter if specified, type must match
* @return the ControllerService types that this controller supports
*/
public Set<DocumentedTypeDTO> getControllerServiceTypes(final String serviceType, final String serviceBundleGroup, final String serviceBundleArtifact, final String serviceBundleVersion, final String bundleGroupFilter, final String bundleArtifactFilter, final String typeFilter) {
final Set<Class> serviceImplementations = ExtensionManager.getExtensions(ControllerService.class);
// identify the controller services that implement the specified serviceType if applicable
if (serviceType != null) {
final BundleCoordinate bundleCoordinate = new BundleCoordinate(serviceBundleGroup, serviceBundleArtifact, serviceBundleVersion);
final Bundle csBundle = ExtensionManager.getBundle(bundleCoordinate);
if (csBundle == null) {
throw new IllegalStateException("Unable to find bundle for coordinate " + bundleCoordinate.getCoordinate());
}
Class serviceClass = null;
final ClassLoader currentContextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(csBundle.getClassLoader());
serviceClass = Class.forName(serviceType, false, csBundle.getClassLoader());
} catch (final Exception e) {
Thread.currentThread().setContextClassLoader(currentContextClassLoader);
throw new IllegalArgumentException(String.format("Unable to load %s from bundle %s: %s", serviceType, bundleCoordinate, e), e);
}
final Map<Class, Bundle> matchingServiceImplementations = new HashMap<>();
// check each type and remove those that aren't in the specified ancestry
for (final Class csClass : serviceImplementations) {
if (implementsServiceType(serviceClass, csClass)) {
matchingServiceImplementations.put(csClass, ExtensionManager.getBundle(csClass.getClassLoader()));
}
}
return dtoFactory.fromDocumentedTypes(matchingServiceImplementations, bundleGroupFilter, bundleArtifactFilter, typeFilter);
} else {
return dtoFactory.fromDocumentedTypes(serviceImplementations, bundleGroupFilter, bundleArtifactFilter, typeFilter);
}
}
Aggregations