本文整理汇总了Java中org.apache.nifi.controller.ConfigurationContext类的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationContext类的具体用法?Java ConfigurationContext怎么用?Java ConfigurationContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurationContext类属于org.apache.nifi.controller包,在下文中一共展示了ConfigurationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enable
import org.apache.nifi.controller.ConfigurationContext; //导入依赖的package包/类
/**
*
*/
@OnEnabled
public void enable(ConfigurationContext context) throws InitializationException {
try {
if (!this.configured) {
if (logger.isInfoEnabled()) {
logger.info("Configuring " + this.getClass().getSimpleName() + " for '"
+ context.getProperty(CONNECTION_FACTORY_IMPL).evaluateAttributeExpressions().getValue() + "' to be connected to '"
+ context.getProperty(BROKER_URI).evaluateAttributeExpressions().getValue() + "'");
}
// will load user provided libraries/resources on the classpath
Utils.addResourcesToClasspath(context.getProperty(CLIENT_LIB_DIR_PATH).evaluateAttributeExpressions().getValue());
this.createConnectionFactoryInstance(context);
if(!isSolace(context))
this.setConnectionFactoryProperties(context);
}
this.configured = true;
} catch (Exception e) {
logger.error("Failed to configure " + this.getClass().getSimpleName(), e);
this.configured = false;
throw new IllegalStateException(e);
}
}
示例2: createConnectionFactoryInstance
import org.apache.nifi.controller.ConfigurationContext; //导入依赖的package包/类
/**
* Creates an instance of the {@link ConnectionFactory} from the provided 'CONNECTION_FACTORY_IMPL'.
*/
private void createConnectionFactoryInstance(ConfigurationContext context) {
String connectionFactoryImplName = getContextValue(context, CONNECTION_FACTORY_IMPL);
Properties env = new Properties();
try {
env.put(InitialContext.INITIAL_CONTEXT_FACTORY, connectionFactoryImplName);
env.put(InitialContext.PROVIDER_URL, getContextValue(context, BROKER_URI));
InitialContext initialContext = new InitialContext(env);
this.connectionFactory = (ConnectionFactory) initialContext.lookup(context.getProperty(JNDI_CF_LOOKUP).evaluateAttributeExpressions().getValue());
if (logger.isDebugEnabled())
logger.debug("Connection factory is created");
} catch (Exception e) {
throw new IllegalStateException("Failed to load and/or instantiate class 'com.solacesystems.jndi.SolJNDIInitialContextFactory'", e);
}
}
示例3: enable
import org.apache.nifi.controller.ConfigurationContext; //导入依赖的package包/类
/**
*
*/
@OnEnabled
public void enable(ConfigurationContext context) throws InitializationException {
try {
if (!this.configured) {
if (logger.isInfoEnabled()) {
logger.info("Configuring " + this.getClass().getSimpleName() + " for '"
+ context.getProperty(CONNECTION_FACTORY_IMPL).evaluateAttributeExpressions().getValue() + "' to be connected to '"
+ BROKER_URI + "'");
}
// will load user provided libraries/resources on the classpath
Utils.addResourcesToClasspath(context.getProperty(CLIENT_LIB_DIR_PATH).evaluateAttributeExpressions().getValue());
this.createConnectionFactoryInstance(context);
this.setConnectionFactoryProperties(context);
}
this.configured = true;
} catch (Exception e) {
logger.error("Failed to configure " + this.getClass().getSimpleName(), e);
this.configured = false;
throw new IllegalStateException(e);
}
}
示例4: initProvenanceConsumer
import org.apache.nifi.controller.ConfigurationContext; //导入依赖的package包/类
private void initProvenanceConsumer(final ConfigurationContext context) throws IOException {
consumer = new ProvenanceEventConsumer();
consumer.setStartPositionValue(context.getProperty(PROVENANCE_START_POSITION).getValue());
consumer.setBatchSize(context.getProperty(PROVENANCE_BATCH_SIZE).asInteger());
consumer.addTargetEventType(CREATE, FETCH, RECEIVE, SEND, CLONE);
consumer.setLogger(getLogger());
consumer.setScheduled(true);
final Set<ClusterResolver> loadedClusterResolvers = new LinkedHashSet<>();
clusterResolverLoader.forEach(resolver -> {
resolver.configure(context);
loadedClusterResolvers.add(resolver);
});
clusterResolvers = new ClusterResolvers(Collections.unmodifiableSet(loadedClusterResolvers), null);
nifiAtlasHook = new NiFIAtlasHook();
}
示例5: createCommsSession
import org.apache.nifi.controller.ConfigurationContext; //导入依赖的package包/类
private CommsSession createCommsSession(final ConfigurationContext context) throws IOException {
final String hostname = context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue();
final int port = context.getProperty(PORT).evaluateAttributeExpressions().asInteger();
final long timeoutMillis = context.getProperty(COMMUNICATIONS_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS);
final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
final CommsSession commsSession;
if (sslContextService == null) {
commsSession = new StandardCommsSession(hostname, port);
} else {
commsSession = new SSLCommsSession(sslContextService.createSSLContext(ClientAuth.REQUIRED), hostname, port);
}
commsSession.setTimeout(timeoutMillis, TimeUnit.MILLISECONDS);
return commsSession;
}
示例6: onEnabled
import org.apache.nifi.controller.ConfigurationContext; //导入依赖的package包/类
/**
* @param context the configuration context
* @throws InitializationException if unable to create a database connection
*/
@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException {
Set<AuthorizationToken> tokensToUse = new HashSet<>();
final String authorizationFilePath = context.getProperty(AUTHORIZATION_FILE_PATH).getValue();
try (Scanner authsScanner = new Scanner(new File(authorizationFilePath))) {
authsScanner.useDelimiter(",");
while (authsScanner.hasNext()) {
tokensToUse.add(new StandardAuthorizationToken(authsScanner.next()));
}
} catch (IOException ioe) {
throw new InitializationException("Could not initialize " + this.getClass().getSimpleName() + " when trying to acquire authorizations.", ioe);
}
getLogger().info("Providing authorities for the following: {}", new Object[]{tokensToUse});
this.authorizationTokens = tokensToUse;
}
开发者ID:apiri,项目名称:nifi-delegated-authorization-bundle,代码行数:22,代码来源:FileBasedDelegatedAuthorizationProviderService.java
示例7: createSockJSServer
import org.apache.nifi.controller.ConfigurationContext; //导入依赖的package包/类
private void createSockJSServer(final ConfigurationContext context) throws InitializationException {
final int port = context.getProperty(PORT).asInteger();
final String ContextPath = context.getProperty(CONTEXT_PATH).getValue();
Router router = Router.router(vertx);
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
BridgeOptions options = new BridgeOptions();
if (context.getProperty(INBOUND_ADDRESS_REGEX).isSet()) {
options.addInboundPermitted(new PermittedOptions().setAddressRegex(context.getProperty(INBOUND_ADDRESS_REGEX).getValue()));
}
if (context.getProperty(OUTBOUND_ADDRESS_REGEX).isSet()) {
options.addOutboundPermitted(new PermittedOptions().setAddressRegex(context.getProperty(OUTBOUND_ADDRESS_REGEX).getValue()));
}
sockJSHandler.bridge(options);
router.route(ContextPath).handler(sockJSHandler);
httpServer = vertx.createHttpServer().requestHandler(router::accept).listen(port);
}
示例8: setConnectionFactoryProperties
import org.apache.nifi.controller.ConfigurationContext; //导入依赖的package包/类
/**
* This operation follows standard bean convention by matching property name to its corresponding 'setter' method.
* Once the method was located it is invoked to set the corresponding property to a value provided by during service
* configuration. For example, 'channel' property will correspond to 'setChannel(..) method and 'queueManager'
* property will correspond to setQueueManager(..) method with a single argument.
*
* There are also few adjustments to accommodate well known brokers. For example ActiveMQ ConnectionFactory accepts
* address of the Message Broker in a form of URL while IBMs in the form of host/port pair (more common). So this
* method will use value retrieved from the 'BROKER_URI' static property 'as is' if ConnectionFactory implementation
* is coming from ActiveMQ and for all others (for now) the 'BROKER_URI' value will be split on ':' and the
* resulting pair will be used to execute setHostName(..) and setPort(..) methods on the provided ConnectionFactory.
* This may need to be maintained and adjusted to accommodate other implementation of ConnectionFactory, but only
* for URL/Host/Port issue. All other properties are set as dynamic properties where user essentially provides both
* property name and value, The bean convention is also explained in user manual for this component with links
* pointing to documentation of various ConnectionFactories.
*
* @see #setProperty(String, String) method
*/
private void setConnectionFactoryProperties(ConfigurationContext context) {
for (final Entry<PropertyDescriptor, String> entry : context.getProperties().entrySet()) {
logger.info("entry = " + entry.toString());
PropertyDescriptor descriptor = entry.getKey();
String propertyName = descriptor.getName();
if (descriptor.isDynamic()) {
this.setProperty(propertyName, entry.getValue());
} else {
if (propertyName.equals(BROKER)) {
if (context.getProperty(CONNECTION_FACTORY_IMPL).evaluateAttributeExpressions().getValue().startsWith("org.apache.activemq")) {
this.setProperty("brokerURL", entry.getValue());
} else if (isSolace(context)) {
// TODO
;
} else {
String[] hostPort = entry.getValue().split(":");
if (hostPort.length == 2) {
this.setProperty("hostName", hostPort[0]);
this.setProperty("port", hostPort[1]);
} else if (hostPort.length != 2) {
this.setProperty("serverUrl", entry.getValue()); // for tibco
} else {
throw new IllegalArgumentException("Failed to parse broker url: " + entry.getValue());
}
}
SSLContextService sc = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
if (sc != null) {
SSLContext ssl = sc.createSSLContext(ClientAuth.NONE);
this.setProperty("sSLSocketFactory", ssl.getSocketFactory());
}
} // ignore 'else', since it's the only non-dynamic property that is relevant to CF configuration
}
}
}
示例9: getContextValue
import org.apache.nifi.controller.ConfigurationContext; //导入依赖的package包/类
private String getContextValue(ConfigurationContext context, PropertyDescriptor key) {
String ret = null;
if (key != null) {
ret = context.getProperty(key).evaluateAttributeExpressions().getValue();
}
if (ret != null) {
ret = ret.trim();
}
return ret;
}
示例10: setConnectionFactoryProperties
import org.apache.nifi.controller.ConfigurationContext; //导入依赖的package包/类
/**
* This operation follows standard bean convention by matching property name
* to its corresponding 'setter' method. Once the method was located it is
* invoked to set the corresponding property to a value provided by during
* service configuration. For example, 'channel' property will correspond to
* 'setChannel(..) method and 'queueManager' property will correspond to
* setQueueManager(..) method with a single argument.
*
* There are also few adjustments to accommodate well known brokers. For
* example ActiveMQ ConnectionFactory accepts address of the Message Broker
* in a form of URL while IBMs in the form of host/port pair (more common).
* So this method will use value retrieved from the 'BROKER_URI' static
* property 'as is' if ConnectionFactory implementation is coming from
* ActiveMQ and for all others (for now) the 'BROKER_URI' value will be
* split on ':' and the resulting pair will be used to execute
* setHostName(..) and setPort(..) methods on the provided
* ConnectionFactory. This may need to be maintained and adjusted to
* accommodate other implementation of ConnectionFactory, but only for
* URL/Host/Port issue. All other properties are set as dynamic properties
* where user essentially provides both property name and value, The bean
* convention is also explained in user manual for this component with links
* pointing to documentation of various ConnectionFactories.
*
* @see #setProperty(String, String) method
*/
private void setConnectionFactoryProperties(ConfigurationContext context) {
for (final Entry<PropertyDescriptor, String> entry : context.getProperties().entrySet()) {
PropertyDescriptor descriptor = entry.getKey();
String propertyName = descriptor.getName();
if (descriptor.isDynamic()) {
this.setProperty(propertyName, entry.getValue());
} else {
if (propertyName.equals(BROKER)) {
String impl = context.getProperty(CONNECTION_FACTORY_IMPL).evaluateAttributeExpressions().getValue();
boolean isSolace = "com.solacesystems.jms.SolConnectionFactoryImpl".equals(impl);
if (impl.startsWith("org.apache.activemq")) {
this.setProperty("brokerURL", entry.getValue());
} else {
String val = entry.getValue();
if(val != null) {
String[] hostPort = val.split(":");
if (hostPort.length == 2) {
this.setProperty(isSolace? "Host" :"hostName", hostPort[0]);
this.setProperty("port", hostPort[1]);
} else if (hostPort.length != 2) {
this.setProperty(isSolace? "Host" : "serverUrl", val); // for tibco
} else {
throw new IllegalArgumentException("Failed to parse broker url: " + entry.getValue());
}
}
}
SSLContextService sc = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
if (sc != null) {
SSLContext ssl = sc.createSSLContext(ClientAuth.NONE);
this.setProperty("sSLSocketFactory", ssl.getSocketFactory());
}
} // ignore 'else', since it's the only non-dynamic property that is relevant to CF configuration
}
}
}
示例11: setConnectionFactoryProperties
import org.apache.nifi.controller.ConfigurationContext; //导入依赖的package包/类
/**
* This operation follows standard bean convention by matching property name
* to its corresponding 'setter' method. Once the method was located it is
* invoked to set the corresponding property to a value provided by during
* service configuration. For example, 'channel' property will correspond to
* 'setChannel(..) method and 'queueManager' property will correspond to
* setQueueManager(..) method with a single argument.
*
* There are also few adjustments to accommodate well known brokers. For
* example ActiveMQ ConnectionFactory accepts address of the Message Broker
* in a form of URL while IBMs in the form of host/port pair (more common).
* So this method will use value retrieved from the 'BROKER_URI' static
* property 'as is' if ConnectionFactory implementation is coming from
* ActiveMQ and for all others (for now) the 'BROKER_URI' value will be
* split on ':' and the resulting pair will be used to execute
* setHostName(..) and setPort(..) methods on the provided
* ConnectionFactory. This may need to be maintained and adjusted to
* accommodate other implementation of ConnectionFactory, but only for
* URL/Host/Port issue. All other properties are set as dynamic properties
* where user essentially provides both property name and value, The bean
* convention is also explained in user manual for this component with links
* pointing to documentation of various ConnectionFactories.
*
* @see #setProperty(String, String) method
*/
private void setConnectionFactoryProperties(ConfigurationContext context) {
for (final Entry<PropertyDescriptor, String> entry : context.getProperties().entrySet()) {
PropertyDescriptor descriptor = entry.getKey();
String propertyName = descriptor.getName();
if (descriptor.isDynamic()) {
this.setProperty(propertyName, entry.getValue());
} else {
if (propertyName.equals(BROKER)) {
if (context.getProperty(CONNECTION_FACTORY_IMPL).evaluateAttributeExpressions().getValue().startsWith("org.apache.activemq")) {
this.setProperty("brokerURL", entry.getValue());
} else {
String[] hostPort = entry.getValue().split(":");
if (hostPort.length == 2) {
this.setProperty("hostName", hostPort[0]);
this.setProperty("port", hostPort[1]);
} else if (hostPort.length != 2) {
this.setProperty("serverUrl", entry.getValue()); // for tibco
} else {
throw new IllegalArgumentException("Failed to parse broker url: " + entry.getValue());
}
}
SSLContextService sc = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
if (sc != null) {
SSLContext ssl = sc.createSSLContext(ClientAuth.NONE);
this.setProperty("sSLSocketFactory", ssl.getSocketFactory());
}
} // ignore 'else', since it's the only non-dynamic property that is relevant to CF configuration
}
}
}
示例12: setup
import org.apache.nifi.controller.ConfigurationContext; //导入依赖的package包/类
@OnScheduled
public void setup(ConfigurationContext context) throws IOException {
// initAtlasClient has to be done first as it loads AtlasProperty.
initAtlasClient(context);
initProvenanceConsumer(context);
String strategy = context.getProperty(NIFI_LINEAGE_STRATEGY).getValue();
lineageStrategy = "ByFlowFile".equals(strategy) ? LineageStrategy.BY_FILE : LineageStrategy.BY_PATH;
}
示例13: initAtlasClient
import org.apache.nifi.controller.ConfigurationContext; //导入依赖的package包/类
private void initAtlasClient(ConfigurationContext context) throws IOException {
List<String> urls = new ArrayList<>();
parseAtlasUrls(context.getProperty(ATLAS_URLS), url -> urls.add(url));
final String user = context.getProperty(ATLAS_USER).getValue();
final String password = context.getProperty(ATLAS_PASSWORD).getValue();
final String confDirStr = context.getProperty(ATLAS_CONF_DIR).getValue();
final File confDir = confDirStr != null && !confDirStr.isEmpty() ? new File(confDirStr) : null;
atlasProperties = new Properties();
final File atlasPropertiesFile = new File(confDir, ATLAS_PROPERTIES_FILENAME);
if (atlasPropertiesFile.isFile()) {
getLogger().info("Loading {}", new Object[]{confDir});
try (InputStream in = new FileInputStream(atlasPropertiesFile)) {
atlasProperties.load(in);
}
} else {
final String fileInClasspath = "/" + ATLAS_PROPERTIES_FILENAME;
try (InputStream in = AtlasNiFiFlowLineage.class.getResourceAsStream(fileInClasspath)) {
getLogger().info("Loading {} from classpath", new Object[]{fileInClasspath});
if (in == null) {
throw new ProcessException(String.format("Could not find %s from classpath.", fileInClasspath));
}
atlasProperties.load(in);
}
}
atlasClient = NiFiAtlasClient.getInstance();
try {
atlasClient.initialize(true, urls.toArray(new String[]{}), user, password, confDir);
} catch (final NullPointerException e) {
throw new ProcessException(String.format("Failed to initialize Atlas client due to %s." +
" Make sure 'atlas-application.properties' is in the directory specified with %s" +
" or under root classpath if not specified.", e, ATLAS_CONF_DIR.getDisplayName()), e);
}
}
示例14: initialize
import org.apache.nifi.controller.ConfigurationContext; //导入依赖的package包/类
@OnEnabled
public void initialize(final ConfigurationContext context) {
if (cache == null) {
final int maxSize = context.getProperty(MAX_SIZE).asInteger();
final Long expireDuration = context.getProperty(AGE_OFF_DURATION).asTimePeriod(TimeUnit.MILLISECONDS);
final int concurrencyLevel = context.getProperty(CONCURRENCY_LEVEL).isSet() ?
context.getProperty(CONCURRENCY_LEVEL).asInteger() : -1;
cache = new SetCacheImpl<>(maxSize, expireDuration, TimeUnit.MILLISECONDS, concurrencyLevel);
}
}
示例15: createCache
import org.apache.nifi.controller.ConfigurationContext; //导入依赖的package包/类
private void createCache(final ConfigurationContext context) {
final int maxSize = context.getProperty(SetCacheService.MAX_SIZE).asInteger();
final Long expireDuration = context.getProperty(SetCacheService.AGE_OFF_DURATION).asTimePeriod(TimeUnit.MILLISECONDS);
final int concurrencyLevel = context.getProperty(SetCacheService.CONCURRENCY_LEVEL).isSet() ?
context.getProperty(SetCacheService.CONCURRENCY_LEVEL).asInteger() : -1;
this.cache = new SetCacheImpl<>(maxSize, expireDuration, TimeUnit.MILLISECONDS, concurrencyLevel);
}