// Path: legacy-amazon/src/main/java/org/pentaho/amazon/client/ClientFactoriesManager.java
// public class ClientFactoriesManager {
// 
//   private Map<ClientType, AbstractClientFactory> clientFactoryMap;
//   private static ClientFactoriesManager instance;
// 
//   private ClientFactoriesManager() {
//     clientFactoryMap = new HashMap<>();
//     clientFactoryMap.put( ClientType.S3, new S3ClientFactory() );
//     clientFactoryMap.put( ClientType.EMR, new EmrClientFactory() );
//     clientFactoryMap.put( ClientType.AIM, new AimClientFactory() );
//     clientFactoryMap.put( ClientType.PRICING, new PricingClientFactory() );
//   }
// 
//   public static ClientFactoriesManager getInstance() {
//     if ( instance == null ) {
//       instance = new ClientFactoriesManager();
//     }
//     return instance;
//   }
// 
//   public <T> T createClient( String accessKey, String secretKey, String sessionToken, String region, ClientType clientType ) {
//     AbstractClientFactory clientFactory = getClientFactory( clientType );
//     T amazonClient = (T) clientFactory.createClient( accessKey, secretKey, sessionToken, region );
//     return amazonClient;
//   }
// 
//   private AbstractClientFactory getClientFactory( ClientType clientType ) {
//     if ( clientFactoryMap.containsKey( clientType ) ) {
//       return clientFactoryMap.get( clientType );
//     }
//     return null;
//   }
// }


import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.auth.StaticUserAuthenticator;
import org.apache.commons.vfs2.impl.DefaultFileSystemConfigBuilder;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.pentaho.amazon.client.ClientFactoriesManager;
import org.pentaho.amazon.client.ClientType;
import org.pentaho.amazon.client.api.EmrClient;
import org.pentaho.amazon.client.api.S3Client;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.Result;
import org.pentaho.di.core.ResultFile;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.exception.KettleFileException;
import org.pentaho.di.core.logging.LogLevel;
import org.pentaho.di.core.logging.log4j.Log4jKettleLayout;
import org.pentaho.di.core.vfs.KettleVFS;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.platform.api.util.LogUtil;
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
  }

  public String buildFilename( String filename ) {
    filename = environmentSubstitute( filename );
    return filename;
  }

  public abstract File createStagingFile() throws IOException, KettleException;

  public abstract String getStepBootstrapActions();

  public abstract String getMainClass() throws Exception;

  public abstract String getStepType();

  private void runNewJobFlow( String stagingS3FileUrl, String stagingS3BucketUrl ) throws Exception {
    emrClient
      .runJobFlow( stagingS3FileUrl, stagingS3BucketUrl, getStepType(), getMainClass(), getStepBootstrapActions(),
        this );
  }

  private void addStepToExistingJobFlow( String stagingS3FileUrl, String stagingS3BucketUrl ) throws Exception {
    emrClient.addStepToExistingJobFlow( stagingS3FileUrl, stagingS3BucketUrl, getStepType(), getMainClass(), this );
  }

  private void logError( String stagingBucketName, String stepId ) {
    logError( s3Client.readStepLogsFromS3( stagingBucketName, hadoopJobFlowId, stepId ) );
  }

  private void initAmazonClients() {
// Path: legacy-amazon/src/main/java/org/pentaho/amazon/client/ClientFactoriesManager.java
// public class ClientFactoriesManager {
// 
//   private Map<ClientType, AbstractClientFactory> clientFactoryMap;
//   private static ClientFactoriesManager instance;
// 
//   private ClientFactoriesManager() {
//     clientFactoryMap = new HashMap<>();
//     clientFactoryMap.put( ClientType.S3, new S3ClientFactory() );
//     clientFactoryMap.put( ClientType.EMR, new EmrClientFactory() );
//     clientFactoryMap.put( ClientType.AIM, new AimClientFactory() );
//     clientFactoryMap.put( ClientType.PRICING, new PricingClientFactory() );
//   }
// 
//   public static ClientFactoriesManager getInstance() {
//     if ( instance == null ) {
//       instance = new ClientFactoriesManager();
//     }
//     return instance;
//   }
// 
//   public <T> T createClient( String accessKey, String secretKey, String sessionToken, String region, ClientType clientType ) {
//     AbstractClientFactory clientFactory = getClientFactory( clientType );
//     T amazonClient = (T) clientFactory.createClient( accessKey, secretKey, sessionToken, region );
//     return amazonClient;
//   }
// 
//   private AbstractClientFactory getClientFactory( ClientType clientType ) {
//     if ( clientFactoryMap.containsKey( clientType ) ) {
//       return clientFactoryMap.get( clientType );
//     }
//     return null;
//   }
// }


// Path: legacy-amazon/src/main/java/org/pentaho/amazon/AbstractAmazonJobExecutor.java
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.auth.StaticUserAuthenticator;
import org.apache.commons.vfs2.impl.DefaultFileSystemConfigBuilder;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.pentaho.amazon.client.ClientFactoriesManager;
import org.pentaho.amazon.client.ClientType;
import org.pentaho.amazon.client.api.EmrClient;
import org.pentaho.amazon.client.api.S3Client;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.Result;
import org.pentaho.di.core.ResultFile;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.exception.KettleFileException;
import org.pentaho.di.core.logging.LogLevel;
import org.pentaho.di.core.logging.log4j.Log4jKettleLayout;
import org.pentaho.di.core.vfs.KettleVFS;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.platform.api.util.LogUtil;
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;

  }

  public String buildFilename( String filename ) {
    filename = environmentSubstitute( filename );
    return filename;
  }

  public abstract File createStagingFile() throws IOException, KettleException;

  public abstract String getStepBootstrapActions();

  public abstract String getMainClass() throws Exception;

  public abstract String getStepType();

  private void runNewJobFlow( String stagingS3FileUrl, String stagingS3BucketUrl ) throws Exception {
    emrClient
      .runJobFlow( stagingS3FileUrl, stagingS3BucketUrl, getStepType(), getMainClass(), getStepBootstrapActions(),
        this );
  }

  private void addStepToExistingJobFlow( String stagingS3FileUrl, String stagingS3BucketUrl ) throws Exception {
    emrClient.addStepToExistingJobFlow( stagingS3FileUrl, stagingS3BucketUrl, getStepType(), getMainClass(), this );
  }

  private void logError( String stagingBucketName, String stepId ) {
    logError( s3Client.readStepLogsFromS3( stagingBucketName, hadoopJobFlowId, stepId ) );
  }

  private void initAmazonClients() {
    ClientFactoriesManager manager = ClientFactoriesManager.getInstance();