// Path: ooso/src/main/java/fr/d2si/ooso/mapper_wrapper/MapperWrapperInfo.java
// public class MapperWrapperInfo {
//     private long id;
//     private List<ObjectInfoSimple> batch;
//     private String mapperLogicInBase64;
//     private JobInfo jobInfo;
// 
//     public MapperWrapperInfo() {
//     }
// 
//     public MapperWrapperInfo(List<ObjectInfoSimple> batch, long id, String mapperLogicInBase64, JobInfo jobInfo) {
//         this.batch = batch;
//         this.id = id;
//         this.mapperLogicInBase64 = mapperLogicInBase64;
//         this.jobInfo = jobInfo;
//     }
// 
//     public List<ObjectInfoSimple> getBatch() {
//         return batch;
//     }
// 
//     public void setBatch(List<ObjectInfoSimple> batch) {
//         this.batch = batch;
//     }
// 
//     public long getId() {
//         return id;
//     }
// 
//     public void setId(long id) {
//         this.id = id;
//     }
// 
//     public String getMapperLogicInBase64() {
//         return mapperLogicInBase64;
//     }
// 
//     public void setMapperLogicInBase64(String mapperLogicInBase64) {
//         this.mapperLogicInBase64 = mapperLogicInBase64;
//     }
// 
//     public JobInfo getJobInfo() {
//         return jobInfo;
//     }
// 
//     public void setJobInfo(JobInfo jobInfo) {
//         this.jobInfo = jobInfo;
//     }
// }
// 
// Path: ooso/src/main/java/fr/d2si/ooso/mappers_listener/MappersListenerInfo.java
// public class MappersListenerInfo {
//     private String reducerInBase64;
//     private JobInfo jobInfo;
// 
//     public MappersListenerInfo() {
//     }
// 
//     public MappersListenerInfo(String reducerInBase64, JobInfo jobInfo) {
//         this.reducerInBase64 = reducerInBase64;
//         this.jobInfo = jobInfo;
//     }
// 
//     public String getReducerInBase64() {
//         return reducerInBase64;
//     }
// 
//     public void setReducerInBase64(String reducerInBase64) {
//         this.reducerInBase64 = reducerInBase64;
//     }
// 
//     public JobInfo getJobInfo() {
//         return jobInfo;
//     }
// 
//     public void setJobInfo(JobInfo jobInfo) {
//         this.jobInfo = jobInfo;
//     }
// }
// 
// Path: ooso/src/main/java/fr/d2si/ooso/utils/Commons.java
// public final static String IGNORED_RETURN_VALUE = "";


import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.AmazonS3Exception;
import com.amazonaws.services.s3.model.S3ObjectSummary;
import fr.d2si.ooso.mapper_wrapper.MapperWrapperInfo;
import fr.d2si.ooso.mappers_listener.MappersListenerInfo;
import fr.d2si.ooso.utils.*;
import java.util.List;
import static fr.d2si.ooso.utils.Commons.IGNORED_RETURN_VALUE;
package fr.d2si.ooso.mappers_driver;




public class MappersDriver implements RequestHandler<MappersDriverInfo, String> {

    private AmazonS3 s3Client;
    private JobInfo jobInfo;

    private String jobId;
    private MappersDriverInfo mappersDriverInfo;

    @Override
    public String handleRequest(MappersDriverInfo mappersDriverInfo, Context context) {
        try {
            this.mappersDriverInfo = mappersDriverInfo;

            this.s3Client = AmazonS3Provider.getS3Client();

            this.jobInfo = this.mappersDriverInfo.getJobInfo();

            this.jobId = this.jobInfo.getJobId();

            cleanup();

            validateParamsOrFail();

            List<List<ObjectInfoSimple>> batches = getBatches();

            invokeMappersListener();

            invokeMappers(batches);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return IGNORED_RETURN_VALUE;
    }

    private void cleanup() {
        List<S3ObjectSummary> mapOutput = Commons.getBucketObjectSummaries(this.jobInfo.getMapperOutputBucket(), this.jobId + "/");
// Path: ooso/src/main/java/fr/d2si/ooso/mapper_wrapper/MapperWrapperInfo.java
// public class MapperWrapperInfo {
//     private long id;
//     private List<ObjectInfoSimple> batch;
//     private String mapperLogicInBase64;
//     private JobInfo jobInfo;
// 
//     public MapperWrapperInfo() {
//     }
// 
//     public MapperWrapperInfo(List<ObjectInfoSimple> batch, long id, String mapperLogicInBase64, JobInfo jobInfo) {
//         this.batch = batch;
//         this.id = id;
//         this.mapperLogicInBase64 = mapperLogicInBase64;
//         this.jobInfo = jobInfo;
//     }
// 
//     public List<ObjectInfoSimple> getBatch() {
//         return batch;
//     }
// 
//     public void setBatch(List<ObjectInfoSimple> batch) {
//         this.batch = batch;
//     }
// 
//     public long getId() {
//         return id;
//     }
// 
//     public void setId(long id) {
//         this.id = id;
//     }
// 
//     public String getMapperLogicInBase64() {
//         return mapperLogicInBase64;
//     }
// 
//     public void setMapperLogicInBase64(String mapperLogicInBase64) {
//         this.mapperLogicInBase64 = mapperLogicInBase64;
//     }
// 
//     public JobInfo getJobInfo() {
//         return jobInfo;
//     }
// 
//     public void setJobInfo(JobInfo jobInfo) {
//         this.jobInfo = jobInfo;
//     }
// }
// 
// Path: ooso/src/main/java/fr/d2si/ooso/mappers_listener/MappersListenerInfo.java
// public class MappersListenerInfo {
//     private String reducerInBase64;
//     private JobInfo jobInfo;
// 
//     public MappersListenerInfo() {
//     }
// 
//     public MappersListenerInfo(String reducerInBase64, JobInfo jobInfo) {
//         this.reducerInBase64 = reducerInBase64;
//         this.jobInfo = jobInfo;
//     }
// 
//     public String getReducerInBase64() {
//         return reducerInBase64;
//     }
// 
//     public void setReducerInBase64(String reducerInBase64) {
//         this.reducerInBase64 = reducerInBase64;
//     }
// 
//     public JobInfo getJobInfo() {
//         return jobInfo;
//     }
// 
//     public void setJobInfo(JobInfo jobInfo) {
//         this.jobInfo = jobInfo;
//     }
// }
// 
// Path: ooso/src/main/java/fr/d2si/ooso/utils/Commons.java
// public final static String IGNORED_RETURN_VALUE = "";


// Path: ooso/src/main/java/fr/d2si/ooso/mappers_driver/MappersDriver.java
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.AmazonS3Exception;
import com.amazonaws.services.s3.model.S3ObjectSummary;
import fr.d2si.ooso.mapper_wrapper.MapperWrapperInfo;
import fr.d2si.ooso.mappers_listener.MappersListenerInfo;
import fr.d2si.ooso.utils.*;
import java.util.List;
import static fr.d2si.ooso.utils.Commons.IGNORED_RETURN_VALUE;

package fr.d2si.ooso.mappers_driver;




public class MappersDriver implements RequestHandler<MappersDriverInfo, String> {

    private AmazonS3 s3Client;
    private JobInfo jobInfo;

    private String jobId;
    private MappersDriverInfo mappersDriverInfo;

    @Override
    public String handleRequest(MappersDriverInfo mappersDriverInfo, Context context) {
        try {
            this.mappersDriverInfo = mappersDriverInfo;

            this.s3Client = AmazonS3Provider.getS3Client();

            this.jobInfo = this.mappersDriverInfo.getJobInfo();

            this.jobId = this.jobInfo.getJobId();

            cleanup();

            validateParamsOrFail();

            List<List<ObjectInfoSimple>> batches = getBatches();

            invokeMappersListener();

            invokeMappers(batches);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return IGNORED_RETURN_VALUE;
    }

    private void cleanup() {
        List<S3ObjectSummary> mapOutput = Commons.getBucketObjectSummaries(this.jobInfo.getMapperOutputBucket(), this.jobId + "/");
        List<S3ObjectSummary> reduceOutput = Commons.getBucketObjectSummaries(this.jobInfo.getReducerOutputBucket(), this.jobId + "/");