use of org.apache.nifi.registry.flow.VersionedPropertyDescriptor in project nifi by apache.
the class StandardProcessGroup method populatePropertiesMap.
private Map<String, String> populatePropertiesMap(final Map<PropertyDescriptor, String> currentProperties, final Map<String, String> proposedProperties, final Map<String, VersionedPropertyDescriptor> proposedDescriptors, final ProcessGroup group) {
// since VersionedPropertyDescriptor currently doesn't know if it is sensitive or not,
// keep track of which property descriptors are sensitive from the current properties
final Set<String> sensitiveProperties = new HashSet<>();
final Map<String, String> fullPropertyMap = new HashMap<>();
for (final PropertyDescriptor property : currentProperties.keySet()) {
if (property.isSensitive()) {
sensitiveProperties.add(property.getName());
} else {
fullPropertyMap.put(property.getName(), null);
}
}
if (proposedProperties != null) {
for (final Map.Entry<String, String> entry : proposedProperties.entrySet()) {
final String propertyName = entry.getKey();
final VersionedPropertyDescriptor descriptor = proposedDescriptors.get(propertyName);
// skip any sensitive properties so we can retain whatever is currently set
if (sensitiveProperties.contains(propertyName)) {
continue;
}
String value;
if (descriptor != null && descriptor.getIdentifiesControllerService()) {
// Property identifies a Controller Service. So the value that we want to assign is not the value given.
// The value given is instead the Versioned Component ID of the Controller Service. We want to resolve this
// to the instance ID of the Controller Service.
final String serviceVersionedComponentId = entry.getValue();
String instanceId = getServiceInstanceId(serviceVersionedComponentId, group);
value = instanceId == null ? serviceVersionedComponentId : instanceId;
} else {
value = entry.getValue();
}
fullPropertyMap.put(propertyName, value);
}
}
return fullPropertyMap;
}
use of org.apache.nifi.registry.flow.VersionedPropertyDescriptor in project nifi by apache.
the class NiFiRegistryFlowMapper method mapPropertyDescriptors.
private Map<String, VersionedPropertyDescriptor> mapPropertyDescriptors(final ConfiguredComponent component) {
final Map<String, VersionedPropertyDescriptor> descriptors = new HashMap<>();
for (final PropertyDescriptor descriptor : component.getProperties().keySet()) {
final VersionedPropertyDescriptor versionedDescriptor = new VersionedPropertyDescriptor();
versionedDescriptor.setName(descriptor.getName());
versionedDescriptor.setDisplayName(descriptor.getDisplayName());
versionedDescriptor.setIdentifiesControllerService(descriptor.getControllerServiceDefinition() != null);
descriptors.put(descriptor.getName(), versionedDescriptor);
}
return descriptors;
}
use of org.apache.nifi.registry.flow.VersionedPropertyDescriptor in project nifi-registry by apache.
the class UnsecuredNiFiRegistryClientIT method buildSnapshot.
private static VersionedFlowSnapshot buildSnapshot(VersionedFlow flow, int num) {
final VersionedFlowSnapshotMetadata snapshotMetadata = new VersionedFlowSnapshotMetadata();
snapshotMetadata.setBucketIdentifier(flow.getBucketIdentifier());
snapshotMetadata.setFlowIdentifier(flow.getIdentifier());
snapshotMetadata.setVersion(num);
snapshotMetadata.setComments("This is snapshot #" + num);
final VersionedProcessGroup rootProcessGroup = new VersionedProcessGroup();
rootProcessGroup.setIdentifier("root-pg");
rootProcessGroup.setName("Root Process Group");
final VersionedProcessGroup subProcessGroup = new VersionedProcessGroup();
subProcessGroup.setIdentifier("sub-pg");
subProcessGroup.setName("Sub Process Group");
rootProcessGroup.getProcessGroups().add(subProcessGroup);
final Map<String, String> processorProperties = new HashMap<>();
processorProperties.put("Prop 1", "Val 1");
processorProperties.put("Prop 2", "Val 2");
final Map<String, VersionedPropertyDescriptor> propertyDescriptors = new HashMap<>();
final VersionedProcessor processor1 = new VersionedProcessor();
processor1.setIdentifier("p1");
processor1.setName("Processor 1");
processor1.setProperties(processorProperties);
processor1.setPropertyDescriptors(propertyDescriptors);
final VersionedProcessor processor2 = new VersionedProcessor();
processor2.setIdentifier("p2");
processor2.setName("Processor 2");
processor2.setProperties(processorProperties);
processor2.setPropertyDescriptors(propertyDescriptors);
subProcessGroup.getProcessors().add(processor1);
subProcessGroup.getProcessors().add(processor2);
final VersionedFlowSnapshot snapshot = new VersionedFlowSnapshot();
snapshot.setSnapshotMetadata(snapshotMetadata);
snapshot.setFlowContents(rootProcessGroup);
return snapshot;
}
use of org.apache.nifi.registry.flow.VersionedPropertyDescriptor in project nifi-registry by apache.
the class StandardFlowComparator method compareProperties.
private void compareProperties(final VersionedComponent componentA, final VersionedComponent componentB, final Map<String, String> propertiesA, final Map<String, String> propertiesB, final Map<String, VersionedPropertyDescriptor> descriptorsA, final Map<String, VersionedPropertyDescriptor> descriptorsB, final Set<FlowDifference> differences) {
propertiesA.entrySet().stream().forEach(entry -> {
final String valueA = entry.getValue();
final String valueB = propertiesB.get(entry.getKey());
VersionedPropertyDescriptor descriptor = descriptorsA.get(entry.getKey());
if (descriptor == null) {
descriptor = descriptorsB.get(entry.getKey());
}
final String displayName;
if (descriptor == null) {
displayName = entry.getKey();
} else {
displayName = descriptor.getDisplayName() == null ? descriptor.getName() : descriptor.getDisplayName();
}
if (valueA == null && valueB != null) {
differences.add(difference(DifferenceType.PROPERTY_ADDED, componentA, componentB, displayName, displayName));
} else if (valueA != null && valueB == null) {
differences.add(difference(DifferenceType.PROPERTY_REMOVED, componentA, componentB, displayName, displayName));
} else if (valueA != null && valueB != null && !valueA.equals(valueB)) {
// flow as having changed, since it is an environment-specific change (similar to how we handle variables).
if (descriptor.getIdentifiesControllerService()) {
final boolean accessibleA = externallyAccessibleServiceIds.contains(valueA);
final boolean accessibleB = externallyAccessibleServiceIds.contains(valueB);
if (!accessibleA && accessibleB) {
return;
}
}
differences.add(difference(DifferenceType.PROPERTY_CHANGED, componentA, componentB, displayName + "=" + valueA, displayName + "=" + valueB));
}
});
propertiesB.entrySet().stream().forEach(entry -> {
final String valueA = propertiesA.get(entry.getKey());
final String valueB = entry.getValue();
// If there are any properties for component B that do not exist for Component A, add those as differences as well.
if (valueA == null && valueB != null) {
final VersionedPropertyDescriptor descriptor = descriptorsB.get(entry.getKey());
final String displayName;
if (descriptor == null) {
displayName = entry.getKey();
} else {
displayName = descriptor.getDisplayName() == null ? descriptor.getName() : descriptor.getDisplayName();
}
differences.add(difference(DifferenceType.PROPERTY_ADDED, componentA, componentB, displayName, displayName));
}
});
}
Aggregations