#!groovy

def init( commonFuncs ){
    funcs = commonFuncs
}
def lastCommaRemover( str ){
    if ( str.size() > 0 && str[ str.size() - 1 ] == ',' ){
        str = str.substring( 0,str.size() - 1 )
    }
    return str
}
def printDaysForTest( AllTheTests ){
    result = ""
    for ( String test in AllTheTests.keySet() ){
        result += test + " : \n"
        for( String each in AllTheTests[ test ].keySet() ){
            AllTheTests[ test ][ each ][ "day" ] = lastCommaRemover( AllTheTests[ test ][ each ][ "day" ] )
            result += "    " + each + ":[" + AllTheTests[ test ][ each ][ "day" ] + "]\n"
        }
        result += "\n"
    }
    return result
}
def runTestSeq( testList ){
    return{
        for ( test in testList.keySet() ){
            testList[ test ].call()
        }
    }
}
def print_tests( tests ){
    for( String test in tests.keySet() ){
        if( tests[ test ][ "tests" ] != "" ){
            println test + ":"
            println tests[ test ][ "tests" ]
        }
    }
}
def organize_tests( tests, testcases ){
    testList = tests.tokenize( "\n;, " )
    for( String test in testList )
        testcases [ Prefix_organizer[ ( test == "FUNCbgpls" || test == "FUNCvirNetNB" ? "US" : ( test[ 0 ] + test[ 1 ] ) ) ] ][ "tests" ] += test + ","
    return testcases
}
def borrow_mn( jobOn ){
    result = ""
    if( jobOn == "SR" ){
        result = "~/cell_borrow.sh"
    }
    return result
}
def trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){
    println jobOn + "-pipeline-" + manuallyRun ? "manually" : branch
    wiki = branch
    branch = funcs.branchWithPrefix( branch )
    test_branch = "master"
    print "HERE2:" + branch
    node( "TestStation-" + nodeName + "s" ){
        envSetup( branch, test_branch, onosTag, jobOn, manuallyRun )

        exportEnvProperty( branch, test_branch, wiki, tests, post_result, manuallyRun, onosTag, isOldFlow )
    }

    jobToRun = jobOn + "-pipeline-" + ( manuallyRun ? "manually" : wiki )
    build job: jobToRun, propagate: false
}
def trigger_pipeline( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){
// nodeName : "BM" or "VM"
// jobOn : "SCPF" or "USECASE" or "FUNC" or "HA"
    return{
        print "HERE:" + branch
        trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag )
    }
}
// export Environment properties.
def exportEnvProperty( onos_branch, test_branch, wiki, tests, postResult, manually_run, onosTag, isOldFlow ){
    stage( "export Property" ){
        sh '''
            echo "ONOSBranch=''' + onos_branch +'''" > /var/jenkins/TestONOS.property
            echo "TestONBranch=''' + test_branch +'''" >> /var/jenkins/TestONOS.property
            echo "ONOSTag='''+ onosTag +'''" >> /var/jenkins/TestONOS.property
            echo "WikiPrefix=''' + wiki +'''" >> /var/jenkins/TestONOS.property
            echo "ONOSJVMHeap='''+ env.ONOSJVMHeap +'''" >> /var/jenkins/TestONOS.property
            echo "Tests=''' + tests +'''" >> /var/jenkins/TestONOS.property
            echo "postResult=''' + postResult +'''" >> /var/jenkins/TestONOS.property
            echo "manualRun=''' + manually_run +'''" >> /var/jenkins/TestONOS.property
            echo "isOldFlow=''' + isOldFlow +'''" >> /var/jenkins/TestONOS.property
        '''
    }
}
// Initialize the environment Setup for the onos and OnosSystemTest
def envSetup( onos_branch, test_branch, onos_tag, jobOn, manuallyRun ){
    print "HERE3:" + onos_branch
    stage( "envSetup" ) {
        // after env: ''' + borrow_mn( jobOn ) + '''
        sh '''#!/bin/bash -l
        set +e
        . ~/.bashrc
        env
        ''' + preSetup( onos_branch, test_branch, onos_tag, manuallyRun ) + '''
        ''' + oldFlowCheck( jobOn, onos_branch ) + '''
        ''' + postSetup( onos_branch, test_branch, onos_tag, manuallyRun )
    }
}
def tagCheck( onos_tag, onos_branch ){
    result = "git checkout "
    if ( onos_tag == "" )
        result += onos_branch //create new local branch
    else
        result += onos_tag //checkout the tag
    return result
}
def preSetup( onos_branch, test_branch, onos_tag, isManual ){
    result = ""
    if( !isManual ){
        result = '''echo -e "\n#####  Set TestON Branch #####"
        echo "TestON Branch is set on: ''' + test_branch + '''"
        cd ~/OnosSystemTest/
        git checkout HEAD~1      # Make sure you aren't pn a branch
        git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
        git branch -D ''' + test_branch + ''' # just incase there are local changes. This will normally result in a branch not found error
        git clean -df # clean any local files
        git fetch --all # update all caches from remotes
        git reset --hard origin/''' + test_branch +'''  # force local index to match remote branch
        git clean -df # clean any local files
        git checkout ''' + test_branch + ''' #create new local branch
        git branch
        git log -1 --decorate
        echo -e "\n#####  Set ONOS Branch #####"
        echo "ONOS Branch is set on: ''' + onos_branch + '''"
        echo -e "\n #### check karaf version ######"
        env |grep karaf
        cd ~/onos
        rm -rf buck-out/*
        ~/onos/tools/build/onos-buck clean
        git checkout HEAD~1      # Make sure you aren't pn a branch
        git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
        git branch -D ''' + onos_branch + ''' # just incase there are local changes. This will normally result in a branch not found error
        git clean -df # clean any local files
        git fetch --all # update all caches from remotes
        git reset --hard origin/''' + onos_branch + '''  # force local index to match remote branch
        git clean -df # clean any local files
        ''' + tagCheck( onos_tag, onos_branch ) + '''
        git branch
        git log -1 --decorate
        echo -e "\n##### set jvm heap size to 8G #####"
        echo ${ONOSJVMHeap}
        inserted_line="export JAVA_OPTS=\"\${ONOSJVMHeap}\""
        sed -i "s/bash/bash\\n$inserted_line/" ~/onos/tools/package/bin/onos-service
        echo "##### Check onos-service setting..... #####"
        cat ~/onos/tools/package/bin/onos-service
        export JAVA_HOME=/usr/lib/jvm/java-8-oracle'''
    }
    return result
}
def oldFlowCheck( jobOn, onos_branch ){
    result = ""
    if( jobOn == "SCPF" && ( onos_branch== "master" || onos_branch=="onos-1.12" ) )
        result = '''sed -i -e 's/@Component(immediate = true)/@Component(enabled = false)/g' ~/onos/core/store/dist/src/main/java/org/onosproject/store/flow/impl/''' + ( isOldFlow ? "DistributedFlowRuleStore" : "ECFlowRuleStore" ) + '''.java
        sed -i -e 's/@Component(enabled = false)/@Component(immediate = true)/g' ~/onos/core/store/dist/src/main/java/org/onosproject/store/flow/impl/''' + ( isOldFlow ? "ECFlowRuleStore" : "DistributedFlowRuleStore" ) + ".java"
    return result
}
def postSetup( onos_branch, test_branch, onos_tag, isManual ){
    result = ""
    if( !isManual ){
        result = '''echo -e "\n##### build ONOS skip unit tests ######"
        #mvn clean install -DskipTests
        # Force buck update
        rm -f ~/onos/bin/buck
        ~/onos/tools/build/onos-buck build onos
        sleep 30
        echo -e "\n##### Stop all running instances of Karaf #####"
        kill $(ps -efw | grep karaf | grep -v grep | awk '{print $2}')
        sleep 30
        git branch'''
    }
    return result
}
def returnCell( nodeName ){
    node( "TestStation-" + nodeName + "s" ){
        sh '''#!/bin/bash -l
            set +e
            . ~/.bashrc
            env
            ~/./return_cell.sh
            '''
    }
}

return this;