%HadoopMapReduceJobInfo
% Internal class that contains all information necessary to configure a
% Hadoop-based MATLAB Worker to service a MapReduce Job.

%   Copyright 2016 The MathWorks, Inc.

classdef (Sealed) HadoopMapReduceJobInfo < parallel.internal.hadoop.HadoopJobInfo
    properties (SetAccess = immutable)
        % Serialized versions of InputData, MapFunction and ReduceFunction
        % properties. These are stored serialized so that the info object
        % can be loaded before the MATLAB Worker is fully initialized.
        SerializedInputDatastore
        SerializedMapFunction
        SerializedReduceFunction
        
        % The type of the output files.
        OutputType;
        
        % The final output folder.
        FinalOutputFolder;
        
        % 'On' or 'Off' to determine whether to display Hadoop logs.
        Display;
    end
    
    properties (Dependent)
        % The datastore describing the format of the input data.
        InputDatastore;
        
        % The user Map function.
        MapFunction;
        
        % The user Reduce function.
        ReduceFunction;
    end
    
    methods
        % Construct an HadoopMapReduceJobInfo from the given mapreduce inputs.
        function obj = HadoopMapReduceJobInfo(inputDatastore, mapFunction, reduceFunction, settings)
            obj.SerializedInputDatastore = distcompserialize64(inputDatastore);
            obj.SerializedMapFunction = distcompserialize64(mapFunction);
            obj.SerializedReduceFunction = distcompserialize64(reduceFunction);
            
            obj.OutputType = settings.OutputType;
            obj.FinalOutputFolder = settings.getOutputFolderAsIri();
            obj.Display = settings.Display;
        end
        
        function out = get.InputDatastore(obj)
            out = distcompdeserialize(obj.SerializedInputDatastore);
        end
        
        function out = get.MapFunction(obj)
            out = distcompdeserialize(obj.SerializedMapFunction);
        end
        
        function out = get.ReduceFunction(obj)
            out = distcompdeserialize(obj.SerializedReduceFunction);
        end
        
        % Wrap this info object as a parallel.Job of the correct type.
        function job = wrapAsJob(obj, cluster)
            job = parallel.internal.hadoop.HadoopMapReduceJob(cluster, obj);
        end
    end
end
