#
# Copyright 2012 Mortar Data Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

module Mortar
    module PigVersion
        PIG_0_12_HADOOP_2_TGZ_NAME = "pig-0.12-Hadoop-2.7.3.tar.gz"
        PIG_0_12_HADOOP_2_TGZ_DEFAULT_URL_PATH = "resource/pig_0_12_hadoop_2"

        def PigVersion.from_string(pig_version_str)
            if pig_version_str == '0.12'
                raise ArgumentError, "Our Hadoop 1 clusters are no longer supported by EMR.  Please use the default version of Pig: 0.12-Hadoop-2.7.3.  If you're unsure of why you're seeing this error please ensure that the project.properties file is not setting pigversion to an unsupported value."
            elsif pig_version_str == '0.12-Hadoop-2'
                raise ArgumentError, "EMR 3 is no longer supported. Please use the default version of Pig: 0.12-Hadoop-2.7.3.  If you're unsure of why you're seeing this error please ensure that the project.properties file is not setting pigversion to an unsupported value."
            elsif pig_version_str == '0.12-Hadoop-2.7.3'
                return Pig012Hadoop273.new
            else
                raise ArgumentError, "Unsupported pig version: #{pig_version_str}.  Options are: ['0.12-Hadoop-2.7.3']."
            end
        end

        class Pig012Hadoop273
            def tgz_name
                PIG_0_12_HADOOP_2_TGZ_NAME
            end

            def tgz_default_url_path
                PIG_0_12_HADOOP_2_TGZ_DEFAULT_URL_PATH
            end

            def name
                "pig-#{version}"
            end

            def version
                "0.12-Hadoop-2.7.3"
            end

            def pig_version
                "pig-0.12"
            end

            def cluster_backend
                Mortar::API::Jobs::CLUSTER_BACKEND__EMR_HADOOP_2_7_3
            end
        end

    end
end