下面列出了com.amazonaws.auth.AnonymousAWSCredentials#org.apache.nifi.components.PropertyDescriptor 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public ValidationResult setControllerServiceProperty(final ControllerService service, final PropertyDescriptor property, final StatelessProcessContext context,
final VariableRegistry registry, final String value) {
final StatelessStateManager serviceStateManager = controllerServiceStateManagers.get(service.getIdentifier());
if (serviceStateManager == null) {
throw new IllegalStateException("Controller service " + service + " has not been added to this TestRunner via the #addControllerService method");
}
final ValidationContext validationContext = new StatelessValidationContext(context, this, serviceStateManager, registry, parameterContext);
final ValidationResult validationResult = property.validate(value, validationContext);
final StatelessControllerServiceConfiguration configuration = getControllerServiceConfigToUpdate(service);
final PropertyConfiguration oldValue = configuration.getProperties().get(property);
final PropertyConfiguration propertyConfiguration = createPropertyConfiguration(value, property.isExpressionLanguageSupported());
configuration.setProperty(property, propertyConfiguration);
if (oldValue == null && value != null) {
service.onPropertyModified(property, null, value);
} else if ((value == null && oldValue.getRawValue() != null) || (value != null && !value.equals(oldValue.getRawValue()))) {
service.onPropertyModified(property, oldValue.getRawValue(), value);
}
return validationResult;
}
@Override
protected void init(final ControllerServiceInitializationContext context) {
List<PropertyDescriptor> props = new ArrayList<>();
props.add(DATABASE_URL);
props.add(HIVE_CONFIGURATION_RESOURCES);
props.add(DB_USER);
props.add(DB_PASSWORD);
props.add(MAX_WAIT_TIME);
props.add(MAX_TOTAL_CONNECTIONS);
props.add(VALIDATION_QUERY);
kerberosConfigFile = context.getKerberosConfigurationFile();
kerberosProperties = new KerberosProperties(kerberosConfigFile);
props.add(kerberosProperties.getKerberosPrincipal());
props.add(kerberosProperties.getKerberosKeytab());
properties = props;
}
public static void authorizeParameterReferences(final ComponentAuthorizable authorizable, final Authorizer authorizer, final Authorizable parameterContextAuthorizable, final NiFiUser user) {
if (parameterContextAuthorizable == null) {
return;
}
final ParameterParser parameterParser = new ExpressionLanguageAgnosticParameterParser();
boolean referencesParameter = false;
for (final PropertyDescriptor propertyDescriptor : authorizable.getPropertyDescriptors()) {
final String rawValue = authorizable.getRawValue(propertyDescriptor);
final ParameterTokenList tokenList = parameterParser.parseTokens(rawValue);
if (!tokenList.toReferenceList().isEmpty()) {
referencesParameter = true;
break;
}
}
if (referencesParameter) {
parameterContextAuthorizable.authorize(authorizer, RequestAction.READ, user);
}
}
@Override
public boolean removeProperty(final ControllerService service, final PropertyDescriptor property) {
final MockStateManager serviceStateManager = controllerServiceStateManagers.get(service.getIdentifier());
if (serviceStateManager == null) {
throw new IllegalStateException("Controller service " + service + " has not been added to this TestRunner via the #addControllerService method");
}
final ControllerServiceConfiguration configuration = getConfigToUpdate(service);
final Map<PropertyDescriptor, String> curProps = configuration.getProperties();
final Map<PropertyDescriptor, String> updatedProps = new HashMap<>(curProps);
final String oldValue = updatedProps.remove(property);
if (oldValue == null) {
return false;
}
configuration.setProperties(updatedProps);
service.onPropertyModified(property, oldValue, null);
return true;
}
private Set<ControllerServiceDTO> getControllerServices(final Map<PropertyDescriptor, String> componentProperties) {
final Set<ControllerServiceDTO> serviceDtos = new HashSet<>();
for (final Map.Entry<PropertyDescriptor, String> entry : componentProperties.entrySet()) {
final PropertyDescriptor descriptor = entry.getKey();
if (descriptor.getControllerServiceDefinition() != null) {
final String controllerServiceId = entry.getValue();
if (controllerServiceId != null) {
final ControllerServiceNode serviceNode = flowController.getControllerServiceNode(controllerServiceId);
if (serviceNode != null) {
serviceDtos.add(dtoFactory.createControllerServiceDto(serviceNode));
final Set<ControllerServiceDTO> recursiveRefs = getControllerServices(serviceNode.getProperties());
serviceDtos.addAll(recursiveRefs);
}
}
}
}
return serviceDtos;
}
@Override
protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
final List<PropertyDescriptor> properties = new ArrayList<>(super.getSupportedPropertyDescriptors());
properties.add(CSVUtils.CSV_FORMAT);
properties.add(CSVUtils.VALUE_SEPARATOR);
properties.add(CSVUtils.INCLUDE_HEADER_LINE);
properties.add(CSVUtils.QUOTE_CHAR);
properties.add(CSVUtils.ESCAPE_CHAR);
properties.add(CSVUtils.COMMENT_MARKER);
properties.add(CSVUtils.NULL_STRING);
properties.add(CSVUtils.TRIM_FIELDS);
properties.add(CSVUtils.QUOTE_MODE);
properties.add(CSVUtils.RECORD_SEPARATOR);
properties.add(CSVUtils.TRAILING_DELIMITER);
properties.add(CSVUtils.CHARSET);
return properties;
}
public GenerateTableFetch() {
final Set<Relationship> r = new HashSet<>();
r.add(REL_SUCCESS);
r.add(REL_FAILURE);
relationships = Collections.unmodifiableSet(r);
final List<PropertyDescriptor> pds = new ArrayList<>();
pds.add(DBCP_SERVICE);
pds.add(DB_TYPE);
pds.add(TABLE_NAME);
pds.add(COLUMN_NAMES);
pds.add(MAX_VALUE_COLUMN_NAMES);
pds.add(QUERY_TIMEOUT);
pds.add(PARTITION_SIZE);
propDescriptors = Collections.unmodifiableList(pds);
}
public static PropertyDescriptor createProxyConfigPropertyDescriptor(final boolean hasComponentProxyConfigs, final ProxySpec ... _specs) {
final Set<ProxySpec> specs = getUniqueProxySpecs(_specs);
final StringBuilder description = new StringBuilder("Specifies the Proxy Configuration Controller Service to proxy network requests.");
if (hasComponentProxyConfigs) {
description.append(" If set, it supersedes proxy settings configured per component.");
}
description.append(" Supported proxies: ");
description.append(specs.stream().map(ProxySpec::getDisplayName).collect(Collectors.joining(", ")));
return new PropertyDescriptor.Builder()
.fromPropertyDescriptor(ProxyConfigurationService.PROXY_CONFIGURATION_SERVICE)
.description(description.toString())
.build();
}
/**
* If any parameter is referenced by the given component node, will authorize user against the given group's Parameter context
* @param destinationGroup the group that the component is being moved to
* @param component the component being moved
* @param authorizer the authorizer
* @param user the nifi user
*/
public static void authorizeParameterReferences(final ProcessGroup destinationGroup, final ComponentAuthorizable component, final Authorizer authorizer, final NiFiUser user) {
final ParameterParser parameterParser = new ExpressionLanguageAgnosticParameterParser();
boolean referencesParameter = false;
for (final PropertyDescriptor propertyDescriptor : component.getPropertyDescriptors()) {
final String rawValue = component.getRawValue(propertyDescriptor);
final ParameterTokenList tokenList = parameterParser.parseTokens(rawValue);
if (!tokenList.toReferenceList().isEmpty()) {
referencesParameter = true;
break;
}
}
if (referencesParameter) {
final ParameterContext destinationContext = destinationGroup.getParameterContext();
if (destinationContext != null) {
destinationContext.authorize(authorizer, RequestAction.READ, user);
}
}
}
/**
* Returns a list of {@link ValidationResult}s for truststore validity checking. Ensures none of the properties
* are populated or at least filename and type are populated; if populated, validates the truststore file on disk
* and password as well.
*
* @param properties the component properties
* @return the list of validation results (empty is valid)
*/
private static List<ValidationResult> validateTruststore(final Map<PropertyDescriptor, String> properties) {
String filename = properties.get(TRUSTSTORE);
String password = properties.get(TRUSTSTORE_PASSWORD);
String type = properties.get(TRUSTSTORE_TYPE);
List<ValidationResult> results = new ArrayList<>();
if (!StringUtils.isBlank(filename) && !StringUtils.isBlank(type)) {
// In this case both the filename and type are populated, which is sufficient
results.addAll(validateTruststoreFile(filename, password, type));
} else {
// The filename or type are blank; all values must be unpopulated for this to be valid
if (!StringUtils.isBlank(filename) || !StringUtils.isBlank(type)) {
results.add(new ValidationResult.Builder().valid(false).explanation("If the truststore filename or type are set, both must be populated").subject("Truststore Properties").build());
}
}
return results;
}
@Override
protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
final List<PropertyDescriptor> properties = new ArrayList<>();
properties.add(LOG_ANALYTICS_WORKSPACE_ID);
properties.add(LOG_ANALYTICS_CUSTOM_LOG_NAME);
properties.add(LOG_ANALYTICS_WORKSPACE_KEY);
properties.add(APPLICATION_ID);
properties.add(INSTANCE_ID);
properties.add(JOB_NAME);
properties.add(LOG_ANALYTICS_URL_ENDPOINT_FORMAT);
properties.add(FILTER_EVENT_TYPE);
properties.add(FILTER_EVENT_TYPE_EXCLUDE);
properties.add(FILTER_COMPONENT_TYPE);
properties.add(FILTER_COMPONENT_TYPE_EXCLUDE);
properties.add(FILTER_COMPONENT_ID);
properties.add(FILTER_COMPONENT_ID_EXCLUDE);
properties.add(FILTER_COMPONENT_NAME);
properties.add(FILTER_COMPONENT_NAME_EXCLUDE);
properties.add(START_POSITION);
properties.add(ALLOW_NULL_VALUES);
properties.add(PLATFORM);
properties.add(INSTANCE_URL);
properties.add(BATCH_SIZE);
return properties;
}
private Map<String, Action> getDefaultActions(final Map<PropertyDescriptor, String> properties) {
final Map<String, Action> defaultActions = new HashMap<>();
for (final Map.Entry<PropertyDescriptor, String> entry : properties.entrySet()) {
if(entry.getKey() != STORE_STATE && entry.getKey() != STATEFUL_VARIABLES_INIT_VALUE) {
final Action action = new Action();
action.setAttribute(entry.getKey().getName());
action.setValue(entry.getValue());
defaultActions.put(action.getAttribute(), action);
}
}
return defaultActions;
}
private Map<String, VersionedPropertyDescriptor> mapPropertyDescriptors(final ComponentNode component, final ControllerServiceProvider serviceProvider, final Set<String> includedGroupIds,
final Map<String, ExternalControllerServiceReference> externalControllerServiceReferences) {
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.setSensitive(descriptor.isSensitive());
final Class<?> referencedServiceType = descriptor.getControllerServiceDefinition();
versionedDescriptor.setIdentifiesControllerService(referencedServiceType != null);
if (referencedServiceType != null) {
final String value = component.getProperty(descriptor).getRawValue();
if (value != null) {
final ControllerServiceNode serviceNode = serviceProvider.getControllerServiceNode(value);
if (serviceNode == null) {
continue;
}
final String serviceGroupId = serviceNode.getProcessGroupIdentifier();
if (!includedGroupIds.contains(serviceGroupId)) {
final String serviceId = getId(serviceNode.getVersionedComponentId(), serviceNode.getIdentifier());
final ExternalControllerServiceReference controllerServiceReference = new ExternalControllerServiceReference();
controllerServiceReference.setIdentifier(serviceId);
controllerServiceReference.setName(serviceNode.getName());
externalControllerServiceReferences.put(serviceId, controllerServiceReference);
}
}
}
descriptors.put(descriptor.getName(), versionedDescriptor);
}
return descriptors;
}
@Override
protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
final List<PropertyDescriptor> properties = new ArrayList<>();
properties.add(URL);
properties.add(CACHE_SIZE);
properties.add(CACHE_EXPIRATION);
properties.add(SSL_CONTEXT_SERVICE);
properties.add(KERBEROS_CREDENTIALS_SERVICE);
properties.add(KERBEROS_PRINCIPAL);
properties.add(KERBEROS_PASSWORD);
return properties;
}
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(String propertyDescriptorName) {
for (NamespaceResolver resolver : namespaceResolverLoader) {
final PropertyDescriptor propertyDescriptor = resolver.getSupportedDynamicPropertyDescriptor(propertyDescriptorName);
if(propertyDescriptor != null) {
return propertyDescriptor;
}
}
return null;
}
@Override
protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
final List<PropertyDescriptor> descriptors = new ArrayList<>();
descriptors.add(HBASE_CACHE_TABLE_NAME);
descriptors.add(AUTHORIZATIONS);
descriptors.add(VISIBILITY_EXPRESSION);
descriptors.add(HBASE_CLIENT_SERVICE);
descriptors.add(HBASE_COLUMN_FAMILY);
descriptors.add(HBASE_COLUMN_QUALIFIER);
return descriptors;
}
@Test
public void testAmbariFormatWithNullValues() throws IOException, InitializationException {
final Map<PropertyDescriptor, String> properties = new HashMap<>();
properties.put(SiteToSiteMetricsReportingTask.FORMAT, SiteToSiteMetricsReportingTask.AMBARI_FORMAT.getValue());
properties.put(SiteToSiteMetricsReportingTask.ALLOW_NULL_VALUES, "true");
MockSiteToSiteMetricsReportingTask task = initTask(properties);
task.onTrigger(context);
assertEquals(1, task.dataSent.size());
final String msg = new String(task.dataSent.get(0), StandardCharsets.UTF_8);
JsonReader jsonReader = Json.createReader(new ByteArrayInputStream(msg.getBytes()));
JsonArray array = jsonReader.readObject().getJsonArray("metrics");
for(int i = 0; i < array.size(); i++) {
JsonObject object = array.getJsonObject(i);
assertEquals("nifi", object.getString("appid"));
assertEquals("1234", object.getString("instanceid"));
if(object.getString("metricname").equals("BytesReadLast5Minutes")) {
for(Entry<String, JsonValue> kv : object.getJsonObject("metrics").entrySet()) {
assertEquals("\"null\"", kv.getValue().toString());
}
return;
}
}
fail();
}
@Override
public Map<String, String> getAllProperties() {
final Map<String, String> propValueMap = new LinkedHashMap<>();
for (final Map.Entry<PropertyDescriptor, String> entry : getProperties().entrySet()) {
propValueMap.put(entry.getKey().getName(), entry.getValue());
}
return propValueMap;
}
public NotificationValidationContext(final NotificationContext processContext, VariableRegistry variableRegistry) {
this.context = processContext;
final Map<PropertyDescriptor, String> properties = processContext.getProperties();
expressionLanguageSupported = new HashMap<>(properties.size());
for (final PropertyDescriptor descriptor : properties.keySet()) {
expressionLanguageSupported.put(descriptor.getName(), descriptor.isExpressionLanguageSupported());
}
this.variableRegistry = variableRegistry;
}
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
if (propertyDescriptorName.startsWith("visibility.")) {
String[] parts = propertyDescriptorName.split("\\.");
String displayName;
String description;
if (parts.length == 2) {
displayName = String.format("Column Family %s Default Visibility", parts[1]);
description = String.format("Default visibility setting for %s", parts[1]);
} else if (parts.length == 3) {
displayName = String.format("Column Qualifier %s.%s Default Visibility", parts[1], parts[2]);
description = String.format("Default visibility setting for %s.%s", parts[1], parts[2]);
} else {
return null;
}
return new PropertyDescriptor.Builder()
.name(propertyDescriptorName)
.displayName(displayName)
.description(description)
.addValidator(StandardValidators.NON_BLANK_VALIDATOR)
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
.dynamic(true)
.build();
}
return null;
}
/**
* Locates the actual property descriptor for the given spec property descriptor.
*
* @param propertyDescriptors properties
* @param specDescriptor example property
* @return property
*/
private PropertyDescriptor locatePropertyDescriptor(Set<PropertyDescriptor> propertyDescriptors, PropertyDescriptor specDescriptor) {
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
if (propertyDescriptor.equals(specDescriptor)) {
return propertyDescriptor;
}
}
return specDescriptor;
}
@Override
protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
List<PropertyDescriptor> propDescs = new ArrayList<>();
propDescs.add(new PropertyDescriptor.Builder()
.name("DBCPService test processor")
.description("DBCPService test processor")
.identifiesControllerService(DBCPService.class)
.required(true)
.build());
return propDescs;
}
protected Map<String,String> getDefaultMaxValueProperties(final Map<PropertyDescriptor, String> properties){
final Map<String,String> defaultMaxValues = new HashMap<>();
for (final Map.Entry<PropertyDescriptor, String> entry : properties.entrySet()) {
final String key = entry.getKey().getName();
if(!key.startsWith(INTIIAL_MAX_VALUE_PROP_START)) {
continue;
}
defaultMaxValues.put(key.substring(INTIIAL_MAX_VALUE_PROP_START.length()), entry.getValue());
}
return defaultMaxValues;
}
public CredentialsStrategy selectPrimaryStrategy(final Map<PropertyDescriptor, String> properties) {
for (CredentialsStrategy strategy : strategies) {
if (strategy.canCreatePrimaryCredential(properties)) {
return strategy;
}
}
return null;
}
@Override
protected void init(final ProcessorInitializationContext context) {
final List<PropertyDescriptor> descriptors = new ArrayList<>();
descriptors.add(DESIRED_SHEETS);
descriptors.add(ROWS_TO_SKIP);
descriptors.add(COLUMNS_TO_SKIP);
descriptors.add(FORMAT_VALUES);
descriptors.add(CSVUtils.CSV_FORMAT);
descriptors.add(CSVUtils.VALUE_SEPARATOR);
descriptors.add(CSVUtils.INCLUDE_HEADER_LINE);
descriptors.add(CSVUtils.QUOTE_CHAR);
descriptors.add(CSVUtils.ESCAPE_CHAR);
descriptors.add(CSVUtils.COMMENT_MARKER);
descriptors.add(CSVUtils.NULL_STRING);
descriptors.add(CSVUtils.TRIM_FIELDS);
descriptors.add(new PropertyDescriptor.Builder()
.fromPropertyDescriptor(CSVUtils.QUOTE_MODE)
.defaultValue(CSVUtils.QUOTE_NONE.getValue())
.build());
descriptors.add(CSVUtils.RECORD_SEPARATOR);
descriptors.add(CSVUtils.TRAILING_DELIMITER);
this.descriptors = Collections.unmodifiableList(descriptors);
final Set<Relationship> relationships = new HashSet<>();
relationships.add(ORIGINAL);
relationships.add(SUCCESS);
relationships.add(FAILURE);
this.relationships = Collections.unmodifiableSet(relationships);
}
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
return new PropertyDescriptor.Builder()
.name(propertyDescriptorName)
.required(false)
.dynamic(true)
.addValidator(Validator.VALID)
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
.build();
}
@Test
public void testJsonFileCredentials() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(MockCredentialsFactoryProcessor.class);
runner.setProperty(CredentialPropertyDescriptors.SERVICE_ACCOUNT_JSON_FILE,
"src/test/resources/mock-gcp-service-account.json");
runner.assertValid();
Map<PropertyDescriptor, String> properties = runner.getProcessContext().getProperties();
final CredentialsFactory factory = new CredentialsFactory();
final GoogleCredentials credentials = factory.getGoogleCredentials(properties);
assertNotNull(credentials);
assertEquals("credentials class should be equal", ServiceAccountCredentials.class,
credentials.getClass());
}
@Override
protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
final List<PropertyDescriptor> properties = new ArrayList<>();
properties.add(MODE);
properties.add(FILENAME);
properties.add(ROLLING_FILENAME_PATTERN);
properties.add(BASE_DIRECTORY);
properties.add(START_POSITION);
properties.add(STATE_LOCATION);
properties.add(RECURSIVE);
properties.add(LOOKUP_FREQUENCY);
properties.add(MAXIMUM_AGE);
return properties;
}
@Test
public void testPutWithLastModifiedTime() throws IOException, ParseException {
final String permissions = "rw-rw-rw-";
final String lastModifiedTime = "2019-09-01T11:11:11-0500";
final DateFormat formatter = new SimpleDateFormat(SFTPTransfer.FILE_MODIFY_DATE_ATTR_FORMAT, Locale.US);
final long expectedLastModifiedTime = formatter.parse(lastModifiedTime).getTime();
final Map<PropertyDescriptor, String> properties = createBaseProperties();
properties.put(SFTPTransfer.PERMISSIONS, permissions);
properties.put(SFTPTransfer.LAST_MODIFIED_TIME, lastModifiedTime);
final String filename = "test-put-simple.txt";
final String fileContent = "this is a test";
try(final SFTPTransfer transfer = createSFTPTransfer(properties);
final InputStream in = new ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8))) {
// Verify file does not already exist
final FileInfo fileInfoBefore = transfer.getRemoteFileInfo(null, DIR_4, filename);
assertNull(fileInfoBefore);
final String fullPath = transfer.put(null, DIR_4, filename, in);
assertNotNull(fullPath);
// Verify file now exists
final FileInfo fileInfoAfter = transfer.getRemoteFileInfo(null, DIR_4, filename);
assertNotNull(fileInfoAfter);
assertEquals(permissions, fileInfoAfter.getPermissions());
assertEquals(expectedLastModifiedTime, fileInfoAfter.getLastModifiedTime());
}
}
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
return new PropertyDescriptor.Builder()
.description("Specifies the value for '" + propertyDescriptorName + "' Kafka Configuration.")
.name(propertyDescriptorName)
.addValidator(new KafkaProcessorUtils.KafkaConfigValidator(ProducerConfig.class))
.dynamic(true)
.expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
.build();
}