Java Code Examples for org.apache.nifi.util.StringUtils

The following examples show how to use org.apache.nifi.util.StringUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: localization_nifi   Source File: BaseTlsManager.java    License: Apache License 2.0 6 votes vote down vote up
private String getKeyPassword() {
    if (keyStore.getType().equalsIgnoreCase(KeystoreType.PKCS12.toString())) {
        tlsConfig.setKeyPassword(null);
        return null;
    } else {
        String result = tlsConfig.getKeyPassword();
        if (StringUtils.isEmpty(result)) {
            if (differentKeyAndKeyStorePassword) {
                result = passwordUtil.generatePassword();
            } else {
                result = getKeyStorePassword();
            }
            tlsConfig.setKeyPassword(result);
        }
        return result;
    }
}
 
Example 2
Source Project: nifi   Source File: PrometheusMetricsUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static CollectorRegistry createJvmMetrics(JvmMetricsRegistry jvmMetricsRegistry, JvmMetrics jvmMetrics, String instId) {
    final String instanceId = StringUtils.isEmpty(instId) ? DEFAULT_LABEL_STRING : instId;
    jvmMetricsRegistry.setDataPoint(jvmMetrics.heapUsed(DataUnit.B), "JVM_HEAP_USED", instanceId);
    jvmMetricsRegistry.setDataPoint(jvmMetrics.heapUsage(), "JVM_HEAP_USAGE", instanceId);
    jvmMetricsRegistry.setDataPoint(jvmMetrics.nonHeapUsage(), "JVM_HEAP_NON_USAGE", instanceId);
    jvmMetricsRegistry.setDataPoint(jvmMetrics.threadCount(), "JVM_THREAD_COUNT", instanceId);
    jvmMetricsRegistry.setDataPoint(jvmMetrics.daemonThreadCount(), "JVM_DAEMON_THREAD_COUNT", instanceId);
    jvmMetricsRegistry.setDataPoint(jvmMetrics.uptime(), "JVM_UPTIME", instanceId);
    jvmMetricsRegistry.setDataPoint(jvmMetrics.fileDescriptorUsage(), "JVM_FILE_DESCRIPTOR_USAGE", instanceId);

    jvmMetrics.garbageCollectors()
            .forEach((name, stat) -> {
                jvmMetricsRegistry.setDataPoint(stat.getRuns(), "JVM_GC_RUNS", instanceId, name);
                jvmMetricsRegistry.setDataPoint(stat.getTime(TimeUnit.MILLISECONDS), "JVM_GC_TIME", instanceId, name);
            });

    return jvmMetricsRegistry.getRegistry();
}
 
Example 3
Source Project: nifi   Source File: AbstractEasyRulesEngineController.java    License: Apache License 2.0 6 votes vote down vote up
@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException {
    final String rulesFile = context.getProperty(RULES_FILE_PATH).getValue();
    final String rulesBody = context.getProperty(RULES_BODY).getValue();
    final String rulesFileType = context.getProperty(RULES_FILE_TYPE).getValue();
    rulesFileFormat = context.getProperty(RULES_FILE_FORMAT).getValue();
    ignoreConditionErrors = context.getProperty(IGNORE_CONDITION_ERRORS).asBoolean();
    filterRules = context.getProperty(FILTER_RULES_MISSING_FACTS).asBoolean();

    try{
        if(StringUtils.isEmpty(rulesFile)){
            rules = RulesFactory.createRulesFromString(rulesBody, rulesFileType, rulesFileFormat);
        }else{
            rules = RulesFactory.createRulesFromFile(rulesFile, rulesFileType, rulesFileFormat);
        }
    } catch (Exception fex){
        throw new InitializationException(fex);
    }
}
 
Example 4
Source Project: nifi   Source File: MongoDBLookupService.java    License: Apache License 2.0 6 votes vote down vote up
@OnEnabled
public void onEnabled(final ConfigurationContext context) {
    this.lookupValueField = context.getProperty(LOOKUP_VALUE_FIELD).getValue();
    this.controllerService = context.getProperty(CONTROLLER_SERVICE).asControllerService(MongoDBClientService.class);

    this.schemaNameProperty = context.getProperty(SchemaAccessUtils.SCHEMA_NAME).getValue();

    this.databaseName = context.getProperty(DATABASE_NAME).evaluateAttributeExpressions().getValue();
    this.collection   = context.getProperty(COLLECTION_NAME).evaluateAttributeExpressions().getValue();

    String configuredProjection = context.getProperty(PROJECTION).isSet()
        ? context.getProperty(PROJECTION).getValue()
        : null;
    if (!StringUtils.isBlank(configuredProjection)) {
        projection = Document.parse(configuredProjection);
    }

    super.onEnabled(context);
}
 
Example 5
Source Project: nifi   Source File: StandardExtensionDiscoveringManager.java    License: Apache License 2.0 6 votes vote down vote up
private static boolean checkControllerServiceReferenceEligibility(final ConfigurableComponent component, final ClassLoader classLoader) {
    // if the extension does not require instance classloading, its eligible
    final boolean requiresInstanceClassLoading = component.getClass().isAnnotationPresent(RequiresInstanceClassLoading.class);

    final Set<Class> cobundledApis = new HashSet<>();
    try (final NarCloseable closeable = NarCloseable.withComponentNarLoader(component.getClass().getClassLoader())) {
        final List<PropertyDescriptor> descriptors = component.getPropertyDescriptors();
        if (descriptors != null && !descriptors.isEmpty()) {
            for (final PropertyDescriptor descriptor : descriptors) {
                final Class<? extends ControllerService> serviceApi = descriptor.getControllerServiceDefinition();
                if (serviceApi != null && classLoader.equals(serviceApi.getClassLoader())) {
                    cobundledApis.add(serviceApi);
                }
            }
        }
    }

    if (!cobundledApis.isEmpty()) {
        logger.warn(String.format(
                "Component %s is bundled with its referenced Controller Service APIs %s. The service APIs should not be bundled with component implementations that reference it.",
                component.getClass().getName(), StringUtils.join(cobundledApis.stream().map(Class::getName).collect(Collectors.toSet()), ", ")));
    }

    // the component is eligible when it does not require instance classloading or when the supporting APIs are bundled in a parent NAR
    return requiresInstanceClassLoading == false || cobundledApis.isEmpty();
}
 
Example 6
@Override
protected HandshakeProperties doHandshake(Peer peer) throws IOException, HandshakeException {

    HttpServerCommunicationsSession commsSession = (HttpServerCommunicationsSession) peer.getCommunicationsSession();
    final String transactionId = commsSession.getTransactionId();

    HandshakeProperties confirmed = null;
    if (!StringUtils.isEmpty(transactionId)) {
        // If handshake is already done, use it.
        confirmed = transactionManager.getHandshakenProperties(transactionId);
    }
    if (confirmed == null) {
        // If it's not, then do handshake.
        confirmed = new HandshakeProperties();
        confirmed.setCommsIdentifier(transactionId);
        validateHandshakeRequest(confirmed, peer, commsSession.getHandshakeParams());
    }

    logger.debug("{} Done handshake, confirmed={}", this, confirmed);
    return confirmed;
}
 
Example 7
Source Project: nifi   Source File: TestEvaluateJsonPath.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testExtractPath_destinationAttributes_twoPaths_oneFound() throws Exception {
    final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateJsonPath());
    testRunner.setProperty(EvaluateJsonPath.DESTINATION, EvaluateJsonPath.DESTINATION_ATTRIBUTE);

    String jsonPathIdAttrKey = "evaluatejson.id";
    String jsonPathNameAttrKey = "evaluatejson.name";

    testRunner.setProperty(jsonPathIdAttrKey, "$[0]._id");
    testRunner.setProperty(jsonPathNameAttrKey, "$[0].name.nonexistent");

    testRunner.enqueue(JSON_SNIPPET);
    testRunner.run();

    Relationship expectedRel = EvaluateJsonPath.REL_MATCH;

    testRunner.assertAllFlowFilesTransferred(expectedRel, 1);
    final MockFlowFile out = testRunner.getFlowFilesForRelationship(expectedRel).get(0);
    Assert.assertEquals("Transferred flow file did not have the correct result for id attribute", "54df94072d5dbf7dc6340cc5", out.getAttribute(jsonPathIdAttrKey));
    Assert.assertEquals("Transferred flow file did not have the correct result for name attribute", StringUtils.EMPTY, out.getAttribute(jsonPathNameAttrKey));
}
 
Example 8
Source Project: nifi   Source File: KerberosPrincipalParser.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <p>Determines the realm specified in the given kerberos principal.
 *
 * <p>The content of the given {@code principal} after the occurrence
 * of the last non-escaped realm delimiter ("@") will be considered
 * the realm of the principal.
 *
 * <p>The validity of the given {@code principal} and the determined realm
 * is not be verified by this method.
 *
 * @param principal the principal for which the realm will be determined
 * @return the realm of the given principal
 */
public static String getRealm(String principal) {
    if (StringUtils.isBlank(principal)) {
        throw new IllegalArgumentException("principal can not be null or empty");
    }

    char previousChar = 0;
    int realmDelimiterIndex = -1;
    char currentChar;
    boolean realmDelimiterFound = false;
    int principalLength = principal.length();

    // find the last non-escaped occurrence of the realm delimiter
    for (int i = 0; i < principalLength; ++i) {
        currentChar = principal.charAt(i);
        if (currentChar == '@' && previousChar != '\\' ) {
            realmDelimiterIndex = i;
            realmDelimiterFound = true;
        }
        previousChar = currentChar;
    }

    String principalAfterLastRealmDelimiter = principal.substring(realmDelimiterIndex + 1);
    return realmDelimiterFound && realmDelimiterIndex + 1 < principalLength ? principalAfterLastRealmDelimiter : null;
}
 
Example 9
Source Project: nifi   Source File: PutBigQueryBatch.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
    final ValidationResult.Builder builder = new ValidationResult.Builder();
    builder.subject(subject).input(input);
    if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
        return builder.valid(true).explanation("Contains Expression Language").build();
    }

    if (TYPES.contains(input.toUpperCase())) {
        builder.valid(true);
    } else {
        builder.valid(false).explanation("Load File Type must be one of the following options: " + StringUtils.join(TYPES, ", "));
    }

    return builder.build();
}
 
Example 10
Source Project: nifi   Source File: ToDate.java    License: Apache License 2.0 6 votes vote down vote up
private java.text.DateFormat getDateFormat(final RecordPathSegment dateFormatSegment, final RecordPathSegment timeZoneID, final RecordPathEvaluationContext context) {
    if (dateFormatSegment == null) {
        return null;
    }

    final String dateFormatString = RecordPathUtils.getFirstStringValue(dateFormatSegment, context);
    if (StringUtils.isEmpty(dateFormatString)) {
        return null;
    }

    try {
        if (timeZoneID == null) {
            return DataTypeUtils.getDateFormat(dateFormatString);
        } else {
            final String timeZoneStr = RecordPathUtils.getFirstStringValue(timeZoneID, context);
            if (StringUtils.isEmpty(timeZoneStr)) {
                return null;
            }
            return DataTypeUtils.getDateFormat(dateFormatString, timeZoneStr);
        }
    } catch (final Exception e) {
        return null;
    }
}
 
Example 11
public FlowConfigurationArchiveManager(final Path flowConfigFile, final NiFiProperties properties) {
    final String archiveDirVal = properties.getFlowConfigurationArchiveDir();
    final Path archiveDir = (archiveDirVal == null || archiveDirVal.equals(""))
            ? flowConfigFile.getParent().resolve("archive") : new File(archiveDirVal).toPath();

    this.maxCount = properties.getFlowConfigurationArchiveMaxCount();

    String maxTime = properties.getFlowConfigurationArchiveMaxTime();
    String maxStorage = properties.getFlowConfigurationArchiveMaxStorage();

    if (maxCount == null && StringUtils.isBlank(maxTime) && StringUtils.isBlank(maxStorage)) {
        // None of limitation is specified, fall back to the default configuration;
        maxTime = NiFiProperties.DEFAULT_FLOW_CONFIGURATION_ARCHIVE_MAX_TIME;
        maxStorage = NiFiProperties.DEFAULT_FLOW_CONFIGURATION_ARCHIVE_MAX_STORAGE;
        logger.info("None of archive max limitation is specified, fall back to the default configuration, maxTime={}, maxStorage={}",
                maxTime, maxStorage);
    }

    this.maxTimeMillis = StringUtils.isBlank(maxTime) ? null : FormatUtils.getTimeDuration(maxTime, TimeUnit.MILLISECONDS);
    this.maxStorageBytes = StringUtils.isBlank(maxStorage) ? null : DataUnit.parseDataSize(maxStorage, DataUnit.B).longValue();

    this.flowConfigFile = flowConfigFile;
    this.archiveDir = archiveDir;
}
 
Example 12
Source Project: nifi   Source File: TlsConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
private boolean isStorePopulated(String path, String password, KeystoreType type, String label) {
    boolean isPopulated;
    String passwordForLogging;

    // Legacy truststores can be populated without a password; only check the path and type
    isPopulated = StringUtils.isNotBlank(path) && type != null;
    if ("truststore".equalsIgnoreCase(label)) {
        passwordForLogging = getTruststorePasswordForLogging();
    } else {
        // Keystores require a password
        isPopulated = isPopulated && StringUtils.isNotBlank(password);
        passwordForLogging = getKeystorePasswordForLogging();
    }

    if (logger.isDebugEnabled()) {
        logger.debug("TLS config {} is {}: {}, {}, {}", label, isPopulated ? "populated" : "not populated", path, passwordForLogging, type);
    }
    return isPopulated;
}
 
Example 13
Source Project: nifi   Source File: FlowConfigurationArchiveManager.java    License: Apache License 2.0 6 votes vote down vote up
public FlowConfigurationArchiveManager(final Path flowConfigFile, final NiFiProperties properties) {
    final String archiveDirVal = properties.getFlowConfigurationArchiveDir();
    final Path archiveDir = (archiveDirVal == null || archiveDirVal.equals(""))
            ? flowConfigFile.getParent().resolve("archive") : new File(archiveDirVal).toPath();

    this.maxCount = properties.getFlowConfigurationArchiveMaxCount();

    String maxTime = properties.getFlowConfigurationArchiveMaxTime();
    String maxStorage = properties.getFlowConfigurationArchiveMaxStorage();

    if (maxCount == null && StringUtils.isBlank(maxTime) && StringUtils.isBlank(maxStorage)) {
        // None of limitation is specified, fall back to the default configuration;
        maxTime = NiFiProperties.DEFAULT_FLOW_CONFIGURATION_ARCHIVE_MAX_TIME;
        maxStorage = NiFiProperties.DEFAULT_FLOW_CONFIGURATION_ARCHIVE_MAX_STORAGE;
        logger.info("None of archive max limitation is specified, fall back to the default configuration, maxTime={}, maxStorage={}",
                maxTime, maxStorage);
    }

    this.maxTimeMillis = StringUtils.isBlank(maxTime) ? null : FormatUtils.getTimeDuration(maxTime, TimeUnit.MILLISECONDS);
    this.maxStorageBytes = StringUtils.isBlank(maxStorage) ? null : DataUnit.parseDataSize(maxStorage, DataUnit.B).longValue();

    this.flowConfigFile = flowConfigFile;
    this.archiveDir = archiveDir;
}
 
Example 14
Source Project: nifi   Source File: JsonParseExceptionMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Response toResponse(JsonParseException ex) {
    // log the error
    logger.info(String.format("%s. Returning %s response.", ex, Response.Status.BAD_REQUEST));

    if (logger.isDebugEnabled()) {
        logger.debug(StringUtils.EMPTY, ex);
    }

    return Response.status(Response.Status.BAD_REQUEST).entity("Unable to parse body as JSON.").type("text/plain").build();
}
 
Example 15
Source Project: nifi   Source File: IllegalClusterStateExceptionMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Response toResponse(IllegalClusterStateException exception) {
    // log the error
    logger.info(String.format("%s. Returning %s response.", exception, Response.Status.CONFLICT));

    if (logger.isDebugEnabled()) {
        logger.debug(StringUtils.EMPTY, exception);
    }

    return Response.status(Response.Status.CONFLICT).entity(exception.getMessage()).type("text/plain").build();
}
 
Example 16
Source Project: nifi   Source File: Basic.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void configure(PropertyContext context) {
    user = context.getProperty(ATLAS_USER).evaluateAttributeExpressions().getValue();
    password = context.getProperty(ATLAS_PASSWORD).evaluateAttributeExpressions().getValue();

    if (StringUtils.isEmpty(user)) {
        throw new IllegalArgumentException("User is required for basic auth.");
    }

    if (StringUtils.isEmpty(password)){
        throw new IllegalArgumentException("Password is required for basic auth.");
    }
}
 
Example 17
public void generateCertificateAndGetItSigned(TlsClientConfig tlsClientConfig, String certificateDirectory, String configJson, boolean differentKeyAndKeyStorePassword) throws Exception {
    TlsClientManager tlsClientManager;
    try {
        tlsClientManager = new TlsClientManager(tlsClientConfig);
    } catch (IOException e) {
        logger.error("Unable to open existing keystore, it can be reused by specifiying both " + BaseCertificateAuthorityCommandLine.CONFIG_JSON_ARG + " and " +
                BaseCertificateAuthorityCommandLine.USE_CONFIG_JSON_ARG);
        throw e;
    }
    tlsClientManager.setDifferentKeyAndKeyStorePassword(differentKeyAndKeyStorePassword);

    if (!StringUtils.isEmpty(certificateDirectory)) {
        tlsClientManager.setCertificateAuthorityDirectory(new File(certificateDirectory));
    }

    if (!StringUtils.isEmpty(configJson)) {
        tlsClientManager.addClientConfigurationWriter(new JsonConfigurationWriter<>(new ObjectMapper(), new File(configJson)));
    }

    if (tlsClientManager.getEntry(TlsToolkitStandalone.NIFI_KEY) == null) {
        if (logger.isInfoEnabled()) {
            logger.info("Requesting new certificate from " + tlsClientConfig.getCaHostname() + ":" + tlsClientConfig.getPort());
        }
        KeyPair keyPair = TlsHelper.generateKeyPair(tlsClientConfig.getKeyPairAlgorithm(), tlsClientConfig.getKeySize());

        X509Certificate[] certificates = tlsClientConfig.createCertificateSigningRequestPerformer().perform(keyPair);

        tlsClientManager.addPrivateKeyToKeyStore(keyPair, TlsToolkitStandalone.NIFI_KEY, certificates);
        tlsClientManager.setCertificateEntry(TlsToolkitStandalone.NIFI_CERT, certificates[certificates.length - 1]);
    } else {
        if (logger.isInfoEnabled()) {
            logger.info("Already had entry for " + TlsToolkitStandalone.NIFI_KEY + " not requesting new certificate.");
        }
    }

    tlsClientManager.write(outputStreamFactory);
}
 
Example 18
@Override
protected String getDnHostname() {
    String dnHostname = getCertificateAuthorityHostname();
    if (StringUtils.isEmpty(dnHostname)) {
        return "YOUR_CA_HOSTNAME";
    }
    return dnHostname;
}
 
Example 19
Source Project: localization_nifi   Source File: TlsToolkitMainTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAllMainClassesHaveDescription() {
    tlsToolkitMain.getMainMap().values().forEach(mainClass -> {
        String description = tlsToolkitMain.getDescription(mainClass);
        assertFalse(StringUtils.isEmpty(description));
        assertFalse(description.contains(TlsToolkitMain.UNABLE_TO_GET_DESCRIPTION));
    });
}
 
Example 20
Source Project: localization_nifi   Source File: ScriptedReportingTask.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Performs setup operations when the processor is scheduled to run. This includes evaluating the processor's
 * properties, as well as reloading the script (from file or the "Script Body" property)
 *
 * @param context the context in which to perform the setup operations
 */
@OnScheduled
public void setup(final ConfigurationContext context) {
    scriptingComponentHelper.setScriptEngineName(context.getProperty(scriptingComponentHelper.SCRIPT_ENGINE).getValue());
    scriptingComponentHelper.setScriptPath(context.getProperty(ScriptingComponentUtils.SCRIPT_FILE).evaluateAttributeExpressions().getValue());
    scriptingComponentHelper.setScriptBody(context.getProperty(ScriptingComponentUtils.SCRIPT_BODY).getValue());
    String modulePath = context.getProperty(ScriptingComponentUtils.MODULES).getValue();
    if (!StringUtils.isEmpty(modulePath)) {
        scriptingComponentHelper.setModules(modulePath.split(","));
    } else {
        scriptingComponentHelper.setModules(new String[0]);
    }
    // Create a script engine for each possible task
    scriptingComponentHelper.setup(1, getLogger());
    scriptToRun = scriptingComponentHelper.getScriptBody();

    try {
        String scriptPath = scriptingComponentHelper.getScriptPath();
        if (scriptToRun == null && scriptPath != null) {
            try (final FileInputStream scriptStream = new FileInputStream(scriptPath)) {
                scriptToRun = IOUtils.toString(scriptStream, Charset.defaultCharset());
            }
        }
    } catch (IOException ioe) {
        throw new ProcessException(ioe);
    }

    vmMetrics = VirtualMachineMetrics.getInstance();
}
 
Example 21
Source Project: nifi   Source File: NotFoundExceptionMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Response toResponse(NotFoundException exception) {
    // log the error
    logger.info(String.format("%s. Returning %s response.", exception, Status.NOT_FOUND));

    if (logger.isDebugEnabled()) {
        logger.debug(StringUtils.EMPTY, exception);
    }

    return Response.status(Status.NOT_FOUND).entity("The specified resource could not be found.").type("text/plain").build();
}
 
Example 22
void setupVariables(ProcessContext context) {
    scriptEngineName = context.getProperty(SCRIPT_ENGINE).getValue();
    scriptPath = context.getProperty(ScriptingComponentUtils.SCRIPT_FILE).evaluateAttributeExpressions().getValue();
    scriptBody = context.getProperty(ScriptingComponentUtils.SCRIPT_BODY).getValue();
    String modulePath = context.getProperty(ScriptingComponentUtils.MODULES).getValue();
    if (!StringUtils.isEmpty(modulePath)) {
        modules = modulePath.split(",");
    } else {
        modules = new String[0];
    }
}
 
Example 23
public void setup(final ProcessContext context) {
    final String maxValueColumnNames = context.getProperty(MAX_VALUE_COLUMN_NAMES).evaluateAttributeExpressions().getValue();

    // If there are no max-value column names specified, we don't need to perform this processing
    if (StringUtils.isEmpty(maxValueColumnNames)) {
        return;
    }

    // Try to fill the columnTypeMap with the types of the desired max-value columns
    final DBCPService dbcpService = context.getProperty(DBCP_SERVICE).asControllerService(DBCPService.class);
    final String tableName = context.getProperty(TABLE_NAME).evaluateAttributeExpressions().getValue();

    final DatabaseAdapter dbAdapter = dbAdapters.get(context.getProperty(DB_TYPE).getValue());
    try (final Connection con = dbcpService.getConnection();
         final Statement st = con.createStatement()) {

        // Try a query that returns no rows, for the purposes of getting metadata about the columns. It is possible
        // to use DatabaseMetaData.getColumns(), but not all drivers support this, notably the schema-on-read
        // approach as in Apache Drill
        String query = dbAdapter.getSelectStatement(tableName, maxValueColumnNames, "1 = 0", null, null, null);
        ResultSet resultSet = st.executeQuery(query);
        ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
        int numCols = resultSetMetaData.getColumnCount();
        if (numCols > 0) {
            columnTypeMap.clear();
            for (int i = 1; i <= numCols; i++) {
                String colName = resultSetMetaData.getColumnName(i).toLowerCase();
                String colKey = getStateKey(tableName, colName);
                int colType = resultSetMetaData.getColumnType(i);
                columnTypeMap.putIfAbsent(colKey, colType);
            }
        } else {
            throw new ProcessException("No columns found in table from those specified: " + maxValueColumnNames);
        }

    } catch (SQLException e) {
        throw new ProcessException("Unable to communicate with database in order to determine column types", e);
    }
}
 
Example 24
Source Project: nifi   Source File: HBase_2_RecordLookupService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Optional<Record> lookup(Map<String, Object> coordinates) throws LookupFailureException {
    if (coordinates.get(ROW_KEY_KEY) == null) {
        return Optional.empty();
    }

    final String rowKey = coordinates.get(ROW_KEY_KEY).toString();
    if (StringUtils.isBlank(rowKey)) {
        return Optional.empty();
    }

    final byte[] rowKeyBytes = rowKey.getBytes(StandardCharsets.UTF_8);
    try {
        final Map<String, Object> values = scan(rowKeyBytes);

        if (values.size() > 0) {
            final List<RecordField> fields = new ArrayList<>();
            for (String key : values.keySet()) {
                fields.add(new RecordField(key, RecordFieldType.STRING.getDataType()));
            }
            final RecordSchema schema = new SimpleRecordSchema(fields);
            return Optional.ofNullable(new MapRecord(schema, values));
        } else {
            return Optional.empty();
        }
    } catch (IOException e) {
        getLogger().error("Error occurred loading {}", new Object[] { coordinates.get("rowKey") }, e);
        throw new LookupFailureException(e);
    }
}
 
Example 25
Source Project: nifi   Source File: IllegalNodeOffloadExceptionMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Response toResponse(IllegalNodeOffloadException exception) {
    logger.info(String.format("%s. Returning %s response.", exception, Response.Status.CONFLICT));

    if (logger.isDebugEnabled()) {
        logger.debug(StringUtils.EMPTY, exception);
    }
    return Response.status(Response.Status.CONFLICT).entity(exception.getMessage()).type("text/plain").build();
}
 
Example 26
Source Project: nifi   Source File: JerseyTenantsClient.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public UserGroupEntity getUserGroup(final String id) throws NiFiClientException, IOException {
    if (StringUtils.isBlank(id)) {
        throw new IllegalArgumentException("User group id cannot be null");
    }

    return executeAction("Error retrieving user group", () -> {
        final WebTarget target = tenantsTarget
                .path("user-groups/{id}")
                .resolveTemplate("id", id);
        return getRequestBuilder(target).get(UserGroupEntity.class);
    });
}
 
Example 27
@Override
public Response toResponse(NoResponseFromNodesException exception) {
    // log the error
    logger.info(String.format("%s. Returning %s response.", exception, Response.Status.CONFLICT));

    if (logger.isDebugEnabled()) {
        logger.debug(StringUtils.EMPTY, exception);
    }

    return Response.status(Response.Status.CONFLICT).entity(exception.getMessage()).type("text/plain").build();
}
 
Example 28
@Override
public Response toResponse(InterruptedException exception) {
    // log the error
    logger.info(String.format("%s. Returning %s response.", exception, Response.Status.INTERNAL_SERVER_ERROR));

    if (logger.isDebugEnabled()) {
        logger.debug(StringUtils.EMPTY, exception);
    }

    return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(exception.getMessage()).type("text/plain").build();
}
 
Example 29
Source Project: nifi   Source File: RegistryManualIT.java    License: Apache License 2.0 5 votes vote down vote up
private void testListUsers(String expectedUserName) throws IOException {
    runCommand(
        "\\s{3,}",
        () -> runRegistryCommand("list-users", ""),
        words -> {
            if (words.length > 2 && words[1].equals(expectedUserName)) {
                testUserId = words[2];
            }
        },
        () -> {
            assertNotNull(testUserId);
            assertTrue("User id shouldn't be blank!", !StringUtils.isBlank(testUserId));
        }
    );
}
 
Example 30
Source Project: nifi   Source File: AbstractEasyRulesEngineController.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Custom validation for ensuring exactly one of Script File or Script Body is populated
 *
 * @param validationContext provides a mechanism for obtaining externally
 *                          managed values, such as property values and supplies convenience methods
 *                          for operating on those values
 * @return A collection of validation results
 */
@Override
public Collection<ValidationResult> customValidate(ValidationContext validationContext) {
    Set<ValidationResult> results = new HashSet<>();

    // Verify that exactly one of "script file" or "script body" is set
    Map<PropertyDescriptor, String> propertyMap = validationContext.getProperties();
    if (StringUtils.isEmpty(propertyMap.get(RULES_FILE_PATH)) == StringUtils.isEmpty(propertyMap.get(RULES_BODY))) {
        results.add(new ValidationResult.Builder().subject("Rules Body or Rules File").valid(false).explanation(
                "exactly one of Rules File or Rules Body must be set").build());
    }
    return results;
}