use of org.apache.nifi.bundle.BundleCoordinate in project nifi by apache.
the class FingerprintFactory method addControllerServiceFingerprint.
private void addControllerServiceFingerprint(final StringBuilder builder, final ControllerServiceDTO dto) {
builder.append(dto.getId());
builder.append(dto.getVersionedComponentId());
builder.append(dto.getType());
builder.append(dto.getName());
addBundleFingerprint(builder, dto.getBundle());
builder.append(dto.getComments());
builder.append(dto.getAnnotationData());
builder.append(dto.getState());
// get the temp instance of the ControllerService 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 ControllerService of type {}; its default properties will be fingerprinted instead of being ignored.", dto.getType());
}
addPropertiesFingerprint(builder, configurableComponent, dto.getProperties());
}
use of org.apache.nifi.bundle.BundleCoordinate in project nifi by apache.
the class FingerprintFactory method addReportingTaskFingerprint.
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());
}
use of org.apache.nifi.bundle.BundleCoordinate in project nifi by apache.
the class HtmlDocumentationWriter method iterateAndLinkComponents.
/**
* Writes a link to another configurable component
*
* @param xmlStreamWriter the xml stream writer
* @param linkedComponents the array of configurable component to link to
* @param classNames the array of class names in string format to link to
* @param separator a separator used to split the values (in case more than 1. If the separator is enclosed in
* between "<" and ">" (.e.g "<br>" it is treated as a tag and written to the xmlStreamWriter as an
* empty tag
* @param sourceContextName the source context/name of the item being linked
* @throws XMLStreamException thrown if there is a problem writing the XML
*/
protected void iterateAndLinkComponents(final XMLStreamWriter xmlStreamWriter, final Class<? extends ConfigurableComponent>[] linkedComponents, final String[] classNames, final String separator, final String sourceContextName) throws XMLStreamException {
String effectiveSeparator = separator;
// Treat the the possible separators
boolean separatorIsElement;
if (effectiveSeparator.startsWith("<") && effectiveSeparator.endsWith(">")) {
separatorIsElement = true;
} else {
separatorIsElement = false;
}
// Whatever the result, strip the possible < and > characters
effectiveSeparator = effectiveSeparator.replaceAll("\\<([^>]*)>", "$1");
int index = 0;
for (final Class<? extends ConfigurableComponent> linkedComponent : linkedComponents) {
final String linkedComponentName = linkedComponent.getName();
final List<Bundle> linkedComponentBundles = ExtensionManager.getBundles(linkedComponentName);
if (linkedComponentBundles != null && linkedComponentBundles.size() > 0) {
final Bundle firstLinkedComponentBundle = linkedComponentBundles.get(0);
final BundleCoordinate coordinate = firstLinkedComponentBundle.getBundleDetails().getCoordinate();
final String group = coordinate.getGroup();
final String id = coordinate.getId();
final String version = coordinate.getVersion();
if (index != 0) {
if (separatorIsElement) {
xmlStreamWriter.writeEmptyElement(effectiveSeparator);
} else {
xmlStreamWriter.writeCharacters(effectiveSeparator);
}
}
writeLink(xmlStreamWriter, linkedComponent.getSimpleName(), "../../../../../components/" + group + "/" + id + "/" + version + "/" + linkedComponent.getCanonicalName() + "/index.html");
++index;
} else {
LOGGER.warn("Could not link to {} because no bundles were found for {}", new Object[] { linkedComponentName, sourceContextName });
}
}
if (classNames != null) {
for (final String className : classNames) {
if (index != 0) {
if (separatorIsElement) {
xmlStreamWriter.writeEmptyElement(effectiveSeparator);
} else {
xmlStreamWriter.writeCharacters(effectiveSeparator);
}
}
final List<Bundle> linkedComponentBundles = ExtensionManager.getBundles(className);
if (linkedComponentBundles != null && linkedComponentBundles.size() > 0) {
final Bundle firstBundle = linkedComponentBundles.get(0);
final BundleCoordinate firstCoordinate = firstBundle.getBundleDetails().getCoordinate();
final String group = firstCoordinate.getGroup();
final String id = firstCoordinate.getId();
final String version = firstCoordinate.getVersion();
final String link = "../../../../../components/" + group + "/" + id + "/" + version + "/" + className + "/index.html";
final int indexOfLastPeriod = className.lastIndexOf(".") + 1;
writeLink(xmlStreamWriter, className.substring(indexOfLastPeriod), link);
++index;
} else {
LOGGER.warn("Could not link to {} because no bundles were found for {}", new Object[] { className, sourceContextName });
}
}
}
}
use of org.apache.nifi.bundle.BundleCoordinate in project nifi by apache.
the class AbstractConfiguredComponent method matchesApi.
/**
* Determines if the given controller service node has the required API as an ancestor.
*
* @param controllerServiceImplBundle the bundle of a controller service being referenced by a processor
* @param requiredApiCoordinate the controller service API required by the processor
* @return true if the controller service node has the require API as an ancestor, false otherwise
*/
private boolean matchesApi(final Bundle controllerServiceImplBundle, final BundleCoordinate requiredApiCoordinate) {
// start with the coordinate of the controller service for cases where the API and service are in the same bundle
BundleCoordinate controllerServiceDependencyCoordinate = controllerServiceImplBundle.getBundleDetails().getCoordinate();
boolean foundApiDependency = false;
while (controllerServiceDependencyCoordinate != null) {
// determine if the dependency coordinate matches the required API
if (requiredApiCoordinate.equals(controllerServiceDependencyCoordinate)) {
foundApiDependency = true;
break;
}
// move to the next dependency in the chain, or stop if null
final Bundle controllerServiceDependencyBundle = ExtensionManager.getBundle(controllerServiceDependencyCoordinate);
if (controllerServiceDependencyBundle == null) {
controllerServiceDependencyCoordinate = null;
} else {
controllerServiceDependencyCoordinate = controllerServiceDependencyBundle.getBundleDetails().getDependencyCoordinate();
}
}
return foundApiDependency;
}
use of org.apache.nifi.bundle.BundleCoordinate in project nifi by apache.
the class AbstractConfiguredComponent method validate.
@Override
public Collection<ValidationResult> validate(final ValidationContext context) {
try (final NarCloseable narCloseable = NarCloseable.withComponentNarLoader(getComponent().getClass(), getComponent().getIdentifier())) {
final Collection<ValidationResult> validationResults = getComponent().validate(context);
// validate selected controller services implement the API required by the processor
final List<PropertyDescriptor> supportedDescriptors = getComponent().getPropertyDescriptors();
if (null != supportedDescriptors) {
for (final PropertyDescriptor descriptor : supportedDescriptors) {
if (descriptor.getControllerServiceDefinition() == null) {
// skip properties that aren't for a controller service
continue;
}
final String controllerServiceId = context.getProperty(descriptor).getValue();
if (controllerServiceId == null) {
// if the property value is null we should already have a validation error
continue;
}
final ControllerServiceNode controllerServiceNode = getControllerServiceProvider().getControllerServiceNode(controllerServiceId);
if (controllerServiceNode == null) {
// if the node was null we should already have a validation error
continue;
}
final Class<? extends ControllerService> controllerServiceApiClass = descriptor.getControllerServiceDefinition();
final ClassLoader controllerServiceApiClassLoader = controllerServiceApiClass.getClassLoader();
final Consumer<String> addValidationError = explanation -> validationResults.add(new ValidationResult.Builder().input(controllerServiceId).subject(descriptor.getDisplayName()).valid(false).explanation(explanation).build());
final Bundle controllerServiceApiBundle = ExtensionManager.getBundle(controllerServiceApiClassLoader);
if (controllerServiceApiBundle == null) {
addValidationError.accept(String.format("Unable to find bundle for ControllerService API class %s.", controllerServiceApiClass.getCanonicalName()));
continue;
}
final BundleCoordinate controllerServiceApiCoordinate = controllerServiceApiBundle.getBundleDetails().getCoordinate();
final Bundle controllerServiceBundle = ExtensionManager.getBundle(controllerServiceNode.getBundleCoordinate());
if (controllerServiceBundle == null) {
addValidationError.accept(String.format("Unable to find bundle for coordinate %s.", controllerServiceNode.getBundleCoordinate()));
continue;
}
final BundleCoordinate controllerServiceCoordinate = controllerServiceBundle.getBundleDetails().getCoordinate();
final boolean matchesApi = matchesApi(controllerServiceBundle, controllerServiceApiCoordinate);
if (!matchesApi) {
final String controllerServiceType = controllerServiceNode.getComponentType();
final String controllerServiceApiType = controllerServiceApiClass.getSimpleName();
final String explanation = new StringBuilder().append(controllerServiceType).append(" - ").append(controllerServiceCoordinate.getVersion()).append(" from ").append(controllerServiceCoordinate.getGroup()).append(" - ").append(controllerServiceCoordinate.getId()).append(" is not compatible with ").append(controllerServiceApiType).append(" - ").append(controllerServiceApiCoordinate.getVersion()).append(" from ").append(controllerServiceApiCoordinate.getGroup()).append(" - ").append(controllerServiceApiCoordinate.getId()).toString();
addValidationError.accept(explanation);
}
}
}
return validationResults;
}
}
Aggregations