All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.boozallen.aiops.mda.basic.ExampleAsyncStepBase Maven / Gradle / Ivy

Go to download

Contains a barebones model with all features turned off to verify basic MDA generation and compilation

There is a newer version: 1.10.0
Show newest version
package com.boozallen.aiops.mda.basic;

/*-
 * #%L
 * aiSSEMBLE::Test::MDA::Data Delivery Spark Basic
 * %%
 * Copyright (C) 2021 Booz Allen
 * %%
 * This software package is licensed under the Booz Allen Public License. All Rights Reserved.
 * #L%
 */

import java.time.Duration;

import com.boozallen.aiops.mda.basic.pipeline.PipelineBase;
import org.aeonbits.owner.KrauseningConfigFactory;
import io.smallrye.mutiny.Multi;
import java.util.concurrent.CompletionStage;
import com.boozallen.aissemble.core.filestore.AbstractFileStore;

import com.boozallen.aiops.data.delivery.spark.SparkConfig;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.spark.sql.api.java.UDF1;
import org.apache.spark.sql.api.java.UDF2;
import com.boozallen.aissemble.data.encryption.policy.config.EncryptAlgorithm;
import org.apache.spark.sql.types.DataTypes;

import javax.inject.Inject;
import java.time.Clock;

import com.boozallen.aissemble.data.encryption.AiopsEncrypt;
import com.boozallen.aissemble.data.encryption.SimpleAesEncrypt;
import com.boozallen.aissemble.data.encryption.VaultEncrypt;
import com.boozallen.aissemble.data.encryption.policy.EncryptionPolicy;
import com.boozallen.aissemble.data.encryption.policy.EncryptionPolicyManager;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.functions;
import org.apache.spark.sql.types.StructType;
import java.util.stream.Collectors;
import static org.apache.spark.sql.functions.col;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.HashSet;
import org.apache.spark.sql.Encoder;
import org.apache.spark.sql.Encoders;
import static org.apache.spark.sql.functions.col;
import static org.apache.spark.sql.functions.lit;
import org.apache.commons.lang.NotImplementedException;
import org.aeonbits.owner.KrauseningConfigFactory;

/**
 * The smallrye connector consumes one message at a time - this class writes multiple source data records within one
 * message so that they can be ingested in batches.
 * 
 * GENERATED CODE - DO NOT MODIFY (add your customizations in ExampleAsyncStep).
 * 
 * Generated from: templates/data-delivery-spark/asynchronous.processor.base.java.vm
 */
public abstract class ExampleAsyncStepBase extends AbstractPipelineStep {

    private static final Logger logger = LoggerFactory.getLogger(ExampleAsyncStepBase.class);

    protected static final SparkConfig config = KrauseningConfigFactory.create(SparkConfig.class);

    protected static final String stepPhase = "ExampleAsyncStep";

    protected ExampleAsyncStepBase(String subject, String action) {
        super(subject, action);
    }

    /**
     * Receives messages and processes them asynchronously.
     */
    public CompletionStage executeStep() {
        try {

            CompletionStage outboundPayload = executeStepImpl();
            return outboundPayload;
        } catch (Exception e) {
            logger.error("Step failed to complete", e);
            throw e;
        }
    }

    /**
     * Performs the processing of inbound data. This method is called when a message is received.
     */
    protected abstract CompletionStage executeStepImpl();

    /**
     * Spark User Defined Function for running encryption on columns. Note: must be registered with the spark session.
     * 
     * @return The cipher text
     */
    protected UDF2 encryptUDF() {
        return (plainText, encryptAlgorithm) -> {
            if (plainText != null) {
                // Default algorithm is AES
                AiopsEncrypt aiopsEncrypt = new SimpleAesEncrypt();

                if(encryptAlgorithm.equals("VAULT_ENCRYPT")) {
                    aiopsEncrypt = new VaultEncrypt();
                }

                return aiopsEncrypt.encryptValue(plainText);
            } else {
                return "";
            }
        };
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy