Search in sources :

Example 1 with StringUtils

use of dlshade.org.apache.commons.lang3.StringUtils in project kylo by Teradata.

the class AbstractMergeTable method onTrigger.

@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
    final ComponentLog logger = getLog();
    FlowFile flowFile = session.get();
    if (flowFile == null) {
        return;
    }
    final String blockingValue = context.getProperty(BLOCKING_KEY).evaluateAttributeExpressions(flowFile).getValue();
    String flowFileId = flowFile.getAttribute(CoreAttributes.UUID.key());
    boolean block = false;
    if (blocking && blockingCache.putIfAbsent(blockingValue, flowFileId) != null) {
        if (StringUtils.isBlank(flowFile.getAttribute(BLOCKED_START_TIME))) {
            flowFile = session.putAttribute(flowFile, BLOCKED_START_TIME, String.valueOf(System.currentTimeMillis()));
            getLogger().info("Transferring Flow file {} to blocked relationship", new Object[] { flowFile });
        }
        // penalize the flow file and transfer to BLOCKED
        flowFile = session.penalize(flowFile);
        session.transfer(flowFile, REL_BLOCKED);
        return;
    }
    // Add Blocking time to flow file if this was a blocked flowfile.
    if (blocking && StringUtils.isNotBlank(flowFile.getAttribute(BLOCKED_START_TIME))) {
        String blockedStartTime = flowFile.getAttribute(BLOCKED_START_TIME);
        try {
            Long l = Long.parseLong(blockedStartTime);
            Long blockTime = System.currentTimeMillis() - l;
            getLogger().info("Processing Blocked flow file {}.  This was blocked for {} ms", new Object[] { flowFile, blockTime });
            flowFile = session.putAttribute(flowFile, BLOCKED_TIME, String.valueOf(blockTime) + " ms");
        } catch (NumberFormatException e) {
        }
    }
    String PROVENANCE_EXECUTION_STATUS_KEY = context.getName() + " Execution Status";
    String partitionSpecString = context.getProperty(PARTITION_SPECIFICATION).evaluateAttributeExpressions(flowFile).getValue();
    String sourceSchema = context.getProperty(SOURCE_SCHEMA).evaluateAttributeExpressions(flowFile).getValue();
    String sourceTable = context.getProperty(SOURCE_TABLE).evaluateAttributeExpressions(flowFile).getValue();
    String targetSchema = context.getProperty(TARGET_SCHEMA).evaluateAttributeExpressions(flowFile).getValue();
    String targetTable = context.getProperty(TARGET_TABLE).evaluateAttributeExpressions(flowFile).getValue();
    String feedPartitionValue = context.getProperty(FEED_PARTITION).evaluateAttributeExpressions(flowFile).getValue();
    String mergeStrategyValue = context.getProperty(MERGE_STRATEGY).evaluateAttributeExpressions(flowFile).getValue();
    String hiveConfigurations = context.getProperty(HIVE_CONFIGURATIONS).evaluateAttributeExpressions(flowFile).getValue();
    boolean resetHive = context.getProperty(RESET_HIVE).asBoolean();
    final ColumnSpec[] columnSpecs = Optional.ofNullable(context.getProperty(FIELD_SPECIFICATION).evaluateAttributeExpressions(flowFile).getValue()).filter(StringUtils::isNotEmpty).map(ColumnSpec::createFromString).orElse(new ColumnSpec[0]);
    if (STRATEGY_PK_MERGE.equals(mergeStrategyValue) && (columnSpecs == null || columnSpecs.length == 0)) {
        getLog().error("Missing required field specification for PK merge feature");
        flowFile = session.putAttribute(flowFile, PROVENANCE_EXECUTION_STATUS_KEY, "Failed: Missing required field specification for PK merge feature");
        release(blockingValue);
        session.transfer(flowFile, IngestProperties.REL_FAILURE);
        return;
    }
    // Maintain default for backward compatibility
    if (StringUtils.isEmpty(mergeStrategyValue)) {
        mergeStrategyValue = STRATEGY_DEDUPE_MERGE;
    }
    logger.info("Merge strategy: " + mergeStrategyValue + " Using Source: " + sourceTable + " Target: " + targetTable + " feed partition:" + feedPartitionValue + " partSpec: " + partitionSpecString);
    final StopWatch stopWatch = new StopWatch(true);
    try (final Connection conn = getConnection(context)) {
        TableMergeSyncSupport mergeSupport = new TableMergeSyncSupport(conn);
        if (resetHive) {
            mergeSupport.resetHiveConf();
        }
        mergeSupport.enableDynamicPartitions();
        if (StringUtils.isNotEmpty(hiveConfigurations)) {
            mergeSupport.setHiveConf(hiveConfigurations.split("\\|"));
        }
        PartitionSpec partitionSpec = new PartitionSpec(partitionSpecString);
        if (STRATEGY_DEDUPE_MERGE.equals(mergeStrategyValue)) {
            mergeSupport.doMerge(sourceSchema, sourceTable, targetSchema, targetTable, partitionSpec, feedPartitionValue, true);
        } else if (STRATEGY_MERGE.equals(mergeStrategyValue)) {
            mergeSupport.doMerge(sourceSchema, sourceTable, targetSchema, targetTable, partitionSpec, feedPartitionValue, false);
        } else if (STRATEGY_SYNC.equals(mergeStrategyValue)) {
            mergeSupport.doSync(sourceSchema, sourceTable, targetSchema, targetTable, partitionSpec, feedPartitionValue);
        } else if (STRATEGY_ROLLING_SYNC.equals(mergeStrategyValue)) {
            mergeSupport.doRollingSync(sourceSchema, sourceTable, targetSchema, targetTable, partitionSpec, feedPartitionValue);
        } else if (STRATEGY_PK_MERGE.equals(mergeStrategyValue)) {
            mergeSupport.doPKMerge(sourceSchema, sourceTable, targetSchema, targetTable, partitionSpec, feedPartitionValue, columnSpecs);
        } else {
            throw new UnsupportedOperationException("Failed to resolve the merge strategy");
        }
        stopWatch.stop();
        session.getProvenanceReporter().modifyContent(flowFile, "Execution completed", stopWatch.getElapsed(TimeUnit.MILLISECONDS));
        flowFile = session.putAttribute(flowFile, PROVENANCE_EXECUTION_STATUS_KEY, "Successful");
        release(blockingValue);
        session.transfer(flowFile, REL_SUCCESS);
    } catch (final Exception e) {
        logger.error("Unable to execute merge doMerge for {} due to {}; routing to failure", new Object[] { flowFile, e }, e);
        flowFile = session.putAttribute(flowFile, PROVENANCE_EXECUTION_STATUS_KEY, "Failed: " + e.getMessage());
        release(blockingValue);
        session.transfer(flowFile, REL_FAILURE);
    }
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) ColumnSpec(com.thinkbiganalytics.util.ColumnSpec) Connection(java.sql.Connection) ComponentLog(org.apache.nifi.logging.ComponentLog) PartitionSpec(com.thinkbiganalytics.util.PartitionSpec) ProcessException(org.apache.nifi.processor.exception.ProcessException) StopWatch(org.apache.nifi.util.StopWatch) StringUtils(org.apache.commons.lang3.StringUtils) TableMergeSyncSupport(com.thinkbiganalytics.ingest.TableMergeSyncSupport)

Example 2 with StringUtils

use of dlshade.org.apache.commons.lang3.StringUtils in project kylo by Teradata.

the class CreateElasticsearchBackedHiveTable method onTrigger.

@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
    FlowFile flowFile = session.get();
    if (flowFile == null) {
        return;
    }
    String jarUrl = context.getProperty(JAR_URL).evaluateAttributeExpressions(flowFile).getValue();
    String useWan = context.getProperty(USE_WAN).getValue();
    String autoIndex = context.getProperty(AUTO_CREATE_INDEX).getValue();
    String idField = context.getProperty(ID_FIELD).evaluateAttributeExpressions(flowFile).getValue();
    final ColumnSpec[] columnSpecs = Optional.ofNullable(context.getProperty(FIELD_SPECIFICATION).evaluateAttributeExpressions(flowFile).getValue()).filter(StringUtils::isNotEmpty).map(ColumnSpec::createFromString).orElse(new ColumnSpec[0]);
    validateArrayProperty(FIELD_SPECIFICATION.getDisplayName(), columnSpecs, session, flowFile);
    final String feedName = context.getProperty(IngestProperties.FEED_NAME).evaluateAttributeExpressions(flowFile).getValue();
    validateStringProperty(FEED_NAME.getDisplayName(), feedName, session, flowFile);
    final String categoryName = context.getProperty(IngestProperties.FEED_CATEGORY).evaluateAttributeExpressions(flowFile).getValue();
    validateStringProperty(FEED_CATEGORY.getDisplayName(), categoryName, session, flowFile);
    final String nodes = context.getProperty(NODES).evaluateAttributeExpressions(flowFile).getValue();
    validateStringProperty(NODES.getDisplayName(), nodes, session, flowFile);
    final String indexString = context.getProperty(FIELD_INDEX_STRING).evaluateAttributeExpressions(flowFile).getValue();
    validateStringProperty(FIELD_INDEX_STRING.getDisplayName(), indexString, session, flowFile);
    final String feedRoot = context.getProperty(FEED_ROOT).evaluateAttributeExpressions(flowFile).getValue();
    validateStringProperty(FEED_ROOT.getDisplayName(), indexString, session, flowFile);
    List<String> hiveStatements = getHQLStatements(columnSpecs, nodes, feedRoot, feedName, categoryName, useWan, autoIndex, idField, jarUrl, indexString);
    final ThriftService thriftService = context.getProperty(THRIFT_SERVICE).asControllerService(ThriftService.class);
    executeStatements(context, session, flowFile, hiveStatements.toArray(new String[hiveStatements.size()]), thriftService);
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) ColumnSpec(com.thinkbiganalytics.util.ColumnSpec) ThriftService(com.thinkbiganalytics.nifi.v2.thrift.ThriftService) StringUtils(org.apache.commons.lang3.StringUtils)

Example 3 with StringUtils

use of dlshade.org.apache.commons.lang3.StringUtils in project kylo by Teradata.

the class RegisterFeedTables method onTrigger.

@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
    // Verify flow file exists
    final FlowFile flowFile = session.get();
    if (flowFile == null) {
        return;
    }
    // Verify properties and attributes
    final String feedFormatOptions = Optional.ofNullable(context.getProperty(FEED_FORMAT_SPECS).evaluateAttributeExpressions(flowFile).getValue()).filter(StringUtils::isNotEmpty).orElse(DEFAULT_FEED_FORMAT_OPTIONS);
    final String targetFormatOptions = Optional.ofNullable(context.getProperty(TARGET_FORMAT_SPECS).evaluateAttributeExpressions(flowFile).getValue()).filter(StringUtils::isNotEmpty).orElse(DEFAULT_STORAGE_FORMAT);
    final String targetTableProperties = context.getProperty(TARGET_TBLPROPERTIES).evaluateAttributeExpressions(flowFile).getValue();
    final ColumnSpec[] partitions = Optional.ofNullable(context.getProperty(PARTITION_SPECS).evaluateAttributeExpressions(flowFile).getValue()).filter(StringUtils::isNotEmpty).map(ColumnSpec::createFromString).orElse(new ColumnSpec[0]);
    final String tableType = context.getProperty(TABLE_TYPE).getValue();
    final ColumnSpec[] columnSpecs = Optional.ofNullable(context.getProperty(FIELD_SPECIFICATION).evaluateAttributeExpressions(flowFile).getValue()).filter(StringUtils::isNotEmpty).map(ColumnSpec::createFromString).orElse(new ColumnSpec[0]);
    if (columnSpecs == null || columnSpecs.length == 0) {
        getLog().error("Missing field specification");
        session.transfer(flowFile, IngestProperties.REL_FAILURE);
        return;
    }
    ColumnSpec[] feedColumnSpecs = Optional.ofNullable(context.getProperty(FEED_FIELD_SPECIFICATION).evaluateAttributeExpressions(flowFile).getValue()).filter(StringUtils::isNotEmpty).map(ColumnSpec::createFromString).orElse(new ColumnSpec[0]);
    if (feedColumnSpecs == null || feedColumnSpecs.length == 0) {
        // Backwards compatibility with older templates we set the source and target to the same
        feedColumnSpecs = columnSpecs;
    }
    final String entity = context.getProperty(IngestProperties.FEED_NAME).evaluateAttributeExpressions(flowFile).getValue();
    if (entity == null || entity.isEmpty()) {
        getLog().error("Missing feed name");
        session.transfer(flowFile, IngestProperties.REL_FAILURE);
        return;
    }
    final String source = context.getProperty(IngestProperties.FEED_CATEGORY).evaluateAttributeExpressions(flowFile).getValue();
    if (source == null || source.isEmpty()) {
        getLog().error("Missing category name");
        session.transfer(flowFile, IngestProperties.REL_FAILURE);
        return;
    }
    final String feedRoot = context.getProperty(FEED_ROOT).evaluateAttributeExpressions(flowFile).getValue();
    final String profileRoot = context.getProperty(PROFILE_ROOT).evaluateAttributeExpressions(flowFile).getValue();
    final String masterRoot = context.getProperty(MASTER_ROOT).evaluateAttributeExpressions(flowFile).getValue();
    final TableRegisterConfiguration config = new TableRegisterConfiguration(feedRoot, profileRoot, masterRoot);
    // Register the tables
    final ThriftService thriftService = context.getProperty(THRIFT_SERVICE).asControllerService(ThriftService.class);
    try (final Connection conn = thriftService.getConnection()) {
        final TableRegisterSupport register = new TableRegisterSupport(conn, config);
        final boolean result;
        if (ALL_TABLES.equals(tableType)) {
            result = register.registerStandardTables(source, entity, feedColumnSpecs, feedFormatOptions, targetFormatOptions, partitions, columnSpecs, targetTableProperties);
        } else {
            result = register.registerTable(source, entity, feedColumnSpecs, feedFormatOptions, targetFormatOptions, partitions, columnSpecs, targetTableProperties, TableType.valueOf(tableType), true);
        }
        final Relationship relnResult = (result ? REL_SUCCESS : REL_FAILURE);
        session.transfer(flowFile, relnResult);
    } catch (final ProcessException | SQLException e) {
        getLog().error("Unable to obtain connection for {} due to {}; routing to failure", new Object[] { flowFile, e });
        session.transfer(flowFile, REL_FAILURE);
    }
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) ColumnSpec(com.thinkbiganalytics.util.ColumnSpec) SQLException(java.sql.SQLException) Connection(java.sql.Connection) TableRegisterConfiguration(com.thinkbiganalytics.util.TableRegisterConfiguration) ProcessException(org.apache.nifi.processor.exception.ProcessException) ThriftService(com.thinkbiganalytics.nifi.v2.thrift.ThriftService) StringUtils(org.apache.commons.lang3.StringUtils) TableRegisterSupport(com.thinkbiganalytics.ingest.TableRegisterSupport) Relationship(org.apache.nifi.processor.Relationship)

Example 4 with StringUtils

use of dlshade.org.apache.commons.lang3.StringUtils in project molgenis by molgenis.

the class SemanticSearchServiceHelper method createDisMaxQueryRuleForAttribute.

/**
 * Create a disMaxJunc query rule based on the given search terms as well as the information from given ontology
 * terms
 *
 * @return disMaxJunc queryRule
 */
public QueryRule createDisMaxQueryRuleForAttribute(Set<String> searchTerms, Collection<OntologyTerm> ontologyTerms) {
    List<String> queryTerms = new ArrayList<>();
    if (searchTerms != null) {
        queryTerms.addAll(searchTerms.stream().filter(StringUtils::isNotBlank).map(this::processQueryString).collect(Collectors.toList()));
    }
    // Handle tags with only one ontologyterm
    ontologyTerms.stream().filter(ontologyTerm -> !ontologyTerm.getIRI().contains(COMMA_CHAR)).forEach(ot -> queryTerms.addAll(parseOntologyTermQueries(ot)));
    QueryRule disMaxQueryRule = createDisMaxQueryRuleForTerms(queryTerms);
    // Handle tags with multiple ontologyterms
    ontologyTerms.stream().filter(ontologyTerm -> ontologyTerm.getIRI().contains(COMMA_CHAR)).forEach(ot -> disMaxQueryRule.getNestedRules().add(createShouldQueryRule(ot.getIRI())));
    return disMaxQueryRule;
}
Also used : NGramDistanceAlgorithm(org.molgenis.semanticsearch.string.NGramDistanceAlgorithm) Stemmer(org.molgenis.semanticsearch.string.Stemmer) java.util(java.util) EntityTypeMetadata(org.molgenis.data.meta.model.EntityTypeMetadata) TermFrequencyService(org.molgenis.ontology.core.ic.TermFrequencyService) Operator(org.molgenis.data.QueryRule.Operator) QueryImpl(org.molgenis.data.support.QueryImpl) StringUtils(org.apache.commons.lang3.StringUtils) EntityType(org.molgenis.data.meta.model.EntityType) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ENTITY_TYPE_META_DATA(org.molgenis.data.meta.model.EntityTypeMetadata.ENTITY_TYPE_META_DATA) MolgenisDataAccessException(org.molgenis.data.MolgenisDataAccessException) COMPOUND(org.molgenis.data.meta.AttributeType.COMPOUND) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) Objects.requireNonNull(java.util.Objects.requireNonNull) DataService(org.molgenis.data.DataService) AttributeMetadata(org.molgenis.data.meta.model.AttributeMetadata) OntologyService(org.molgenis.ontology.core.service.OntologyService) Arrays.stream(java.util.Arrays.stream) QueryRule(org.molgenis.data.QueryRule) Entity(org.molgenis.data.Entity) QueryRule(org.molgenis.data.QueryRule)

Example 5 with StringUtils

use of dlshade.org.apache.commons.lang3.StringUtils in project cloudbreak by hortonworks.

the class AmbariStackDetailsJsonToStackRepoDetailsConverter method convert.

@Override
public StackRepoDetails convert(AmbariStackDetailsJson source) {
    StackRepoDetails repo = new StackRepoDetails();
    Map<String, String> stack = new HashMap<>();
    Map<String, String> util = new HashMap<>();
    boolean baseRepoRequiredFieldsExists = Stream.of(source.getStackRepoId(), source.getStackBaseURL(), source.getUtilsRepoId(), source.getUtilsBaseURL()).noneMatch(StringUtils::isEmpty);
    if (!isVdfRequiredFieldsExists(source) && !baseRepoRequiredFieldsExists) {
        String msg = "The 'repositoryVersion', 'versionDefinitionFileUrl' or " + "'stackBaseURL', 'stackRepoId', 'utilsBaseUrl', 'utilsRepoId' fields must be specified!";
        throw new BadRequestException(msg);
    }
    stack.put("repoid", source.getStackRepoId());
    util.put("repoid", source.getUtilsRepoId());
    if (baseRepoRequiredFieldsExists) {
        String stackBaseURL = source.getStackBaseURL();
        String utilsBaseURL = source.getUtilsBaseURL();
        if (source.getOs() == null) {
            stack.put(REDHAT_6, stackBaseURL);
            stack.put(REDHAT_7, stackBaseURL);
            stack.put(DEBIAN_9, stackBaseURL);
            stack.put(UBUNTU_16, stackBaseURL);
            util.put(REDHAT_6, utilsBaseURL);
            util.put(REDHAT_7, utilsBaseURL);
            util.put(DEBIAN_9, utilsBaseURL);
            util.put(UBUNTU_16, utilsBaseURL);
        } else {
            stack.put(source.getOs(), stackBaseURL);
            util.put(source.getOs(), utilsBaseURL);
        }
    }
    if (!StringUtils.isEmpty(source.getRepositoryVersion())) {
        stack.put(StackRepoDetails.REPOSITORY_VERSION, source.getRepositoryVersion());
        stack.put("repoid", source.getStack());
    }
    if (!StringUtils.isEmpty(source.getVersionDefinitionFileUrl())) {
        stack.put(StackRepoDetails.CUSTOM_VDF_REPO_KEY, source.getVersionDefinitionFileUrl());
    }
    if (!StringUtils.isEmpty(source.getMpackUrl())) {
        stack.put(StackRepoDetails.MPACK_TAG, source.getMpackUrl());
    }
    repo.setStack(stack);
    repo.setUtil(util);
    repo.setEnableGplRepo(source.isEnableGplRepo());
    repo.setVerify(source.getVerify());
    repo.setHdpVersion(source.getVersion());
    return repo;
}
Also used : StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Aggregations

StringUtils (org.apache.commons.lang3.StringUtils)10 ColumnSpec (com.thinkbiganalytics.util.ColumnSpec)3 HashMap (java.util.HashMap)3 FlowFile (org.apache.nifi.flowfile.FlowFile)3 ThriftService (com.thinkbiganalytics.nifi.v2.thrift.ThriftService)2 Connection (java.sql.Connection)2 ComponentLog (org.apache.nifi.logging.ComponentLog)2 ProcessException (org.apache.nifi.processor.exception.ProcessException)2 QueryRule (org.molgenis.data.QueryRule)2 DefaultCheckInResult (alfio.manager.support.DefaultCheckInResult)1 OnSitePaymentResult (alfio.manager.support.OnSitePaymentResult)1 TicketAndCheckInResult (alfio.manager.support.TicketAndCheckInResult)1 TicketStatus (alfio.model.Ticket.TicketStatus)1 Sets (com.google.common.collect.Sets)1 StackRepoDetails (com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 TableMergeSyncSupport (com.thinkbiganalytics.ingest.TableMergeSyncSupport)1 TableRegisterSupport (com.thinkbiganalytics.ingest.TableRegisterSupport)1 PartitionSpec (com.thinkbiganalytics.util.PartitionSpec)1 TableRegisterConfiguration (com.thinkbiganalytics.util.TableRegisterConfiguration)1