[ONOS-8003]: Migrate single-use dependency functions in TestON Pipelines

Change-Id: I6975899654f13bd2fa55a6f48122c6336195ae49
diff --git a/TestON/JenkinsFile/CommonJenkinsFile.groovy b/TestON/JenkinsFile/CommonJenkinsFile.groovy
index 29a5862..5ecf63d 100644
--- a/TestON/JenkinsFile/CommonJenkinsFile.groovy
+++ b/TestON/JenkinsFile/CommonJenkinsFile.groovy
@@ -18,8 +18,11 @@
 //     You should have received a copy of the GNU General Public License
 //     along with TestON.  If not, see <http://www.gnu.org/licenses/>.
 
+import groovy.time.TimeCategory
+import groovy.time.TimeDuration
+
 // read the dependency files
-funcs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy' )
+graphs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsGraphs.groovy' )
 test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' )
 fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
 SCPFfuncs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/PerformanceFuncs.groovy' )
@@ -29,8 +32,13 @@
 testsToRun = null
 testsToRunStrList = null
 branch = null
+branchWithPrefix = null
 start = null
+nodeLabel = null
 testStation = null
+testsOverride = null
+isGraphOnly = false
+isSCPF = false
 testsFromList = [:]
 graphPaths = [:]
 pipeline = [:]
@@ -50,37 +58,57 @@
     readParams()
 
     if ( category == "SCPF" ){
-        // SCPF needs to obtain properties earlier
-        funcs.initialize( category, testStation, nodeLabel, SCPFfuncs );
-        prop = funcs.getProperties( category, test_list.addPrefixToBranch( branch ) )
-
+        isSCPF = true
         SCPFfuncs.init()
-        isOldFlow = prop[ "isOldFlow" ] == "true"
+        graphs.initialize( category, SCPFfuncs );
+        prop = getProperties()
+        isOldFlow = ( prop[ "isOldFlow" ] == "true" )
         SCPFfuncs.oldFlowRuleCheck( isOldFlow, prop[ "ONOSBranch" ] )
-    } else if ( category == "SR" ){
-        funcs.initialize( category, testStation, nodeLabel );
-        // get the name of the Jenkins job.
-        jobName = env.JOB_NAME
-        prop = funcs.getProperties( category, test_list.addPrefixToBranch( branch ) )
     } else {
-        funcs.initialize( category, testStation, nodeLabel );
-        prop = funcs.getProperties( category, test_list.addPrefixToBranch( branch ) )
+        isSCPF = false
+        graphs.initialize()
+        prop = getProperties()
     }
 
     // get the list of the test and init branch to it.
     testsFromList = test_list.getTestsFromCategory( category )
 
     initGraphPaths()
+    tokenizeTokens = "\n;, "
 
-    testsToRunStrList = funcs.getTestsToRun( prop[ "Tests" ] )
+    if ( testsOverride == "" || testsOverride == null ){
+        testsToRunStrList = prop[ "Tests" ].tokenize( tokenizeTokens )
+    } else {
+        testsToRunStrList = testsOverride.tokenize( tokenizeTokens )
+    }
     testsToRun = test_list.getTestsFromStringList( testsToRunStrList )
 }
 
 def readParams(){
     category = params.Category       // "FUNC", "HA", "USECASE", etc.
     branch = params.Branch           // "1.15", "2.1", "master", etc.
+    branchWithPrefix = test_list.addPrefixToBranch( branch )
     testStation = params.TestStation // "TestStation-BMs", etc.
     nodeLabel = params.NodeLabel     // "BM", "VM", "Fabric-1.x", etc.
+    testsOverride = params.TestsOverride // "FUNCflow, FUNCintent, [...]", overrides property file
+    isGraphOnly = params.OnlyRefreshGraphs // true or false
+}
+
+def getProperties(){
+    // get the properties of the test by reading the TestONOS.property
+
+    filePath = '''/var/jenkins/TestONOS-''' + category + '''-''' + branchWithPrefix + '''.property'''
+
+    node( testStation ) {
+        return readProperties( file: filePath )
+    }
+}
+
+def getCurrentTime(){
+    // get time of the PST zone.
+
+    TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) )
+    return new Date()
 }
 
 def initGraphPaths(){
@@ -99,15 +127,21 @@
 def runTests(){
     // run the test sequentially and save the function into the dictionary.
     for ( String test : testsToRun.keySet() ){
-        def toBeRun = test
-        def stepName = ( toBeRun ? "" : "Not " ) + "Running $test"
-        def pureTestName = ( testsToRun[ test ].containsKey( "test" ) ? testsToRun[ test ][ "test" ].split().head() : test )
-        pipeline[ stepName ] = funcs.runTest( test, toBeRun, prop, pureTestName, false,
-                                           testsToRun, graphPaths[ "trendIndividual" ], graphPaths[ "saveDirectory" ] )
+        toBeRun = test
+        stepName = ( toBeRun ? "" : "Not " ) + "Running $test"
+        pureTestName = ( testsToRun[ test ].containsKey( "test" ) ? testsToRun[ test ][ "test" ].split().head() : test )
+        pipeline[ stepName ] = runTest( test,
+                                        toBeRun,
+                                        prop,
+                                        pureTestName,
+                                        isGraphOnly,
+                                        testsToRun,
+                                        graphPaths[ "trendIndividual" ],
+                                        graphPaths[ "saveDirectory" ] )
     }
 
     // get the start time of the test.
-    start = funcs.getCurrentTime()
+    start = getCurrentTime()
 
     // run the tests sequentially.
     for ( test in pipeline.keySet() ){
@@ -115,14 +149,272 @@
     }
 }
 
+def initTest(){
+    return '''#!/bin/bash -l
+        set -i # interactive
+        set +e
+        shopt -s expand_aliases # expand alias in non-interactive mode
+        export PYTHONUNBUFFERED=1
+        ifconfig
+        echo "ONOS Branch is: $ONOSBranch"
+        echo "TestON Branch is: $TestONBranch"
+        echo "Test date: "
+        date
+        cd ~
+        export PATH=$PATH:onos/tools/test/bin
+        timeout 240 stc shutdown | head -100
+        timeout 240 stc teardown | head -100
+        timeout 240 stc shutdown | head -100
+        cd ~/OnosSystemTest/TestON/bin
+        git log | head
+        ./cleanup.sh -f || true
+        '''
+}
+
+def runTestCli_py( testName, testCategory ){
+    // Bash script that will run the test.
+    // testName : name of the test
+    // testCategory : (SR,FUNC ... )
+
+    return '''cd ~/OnosSystemTest/TestON/bin
+           ./cli.py run ''' +
+           testName +
+           ''' --params GRAPH/nodeCluster=''' + nodeLabel
+}
+
+def concludeRunTest(){
+    return '''cd ~/OnosSystemTest/TestON/bin
+              ./cleanup.sh -f || true
+              # cleanup config changes
+              cd ~/onos/tools/package/config
+              git clean -df'''
+}
+
+def copyLogs(){
+    // bash script to copy the logs and other necessary element for SR tests.
+
+    result = ""
+    if ( category == "SR" ){
+        result = '''
+      sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
+      sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
+      sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
+      sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
+      sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
+      sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
+      '''
+    }
+    return result
+}
+
+def cleanAndCopyFiles( testName ){
+    // clean up some files that were in the folder and copy the new files from the log
+    // testName : name of the test
+
+    return '''#!/bin/bash -i
+        set +e
+        echo "ONOS Branch is: ${ONOSBranch}"
+        echo "TestON Branch is: ${TestONBranch}"
+        echo "Job name is: "''' + testName + '''
+        echo "Workspace is: ${WORKSPACE}/"
+        echo "Wiki page to post is: ${WikiPrefix}-"
+        # remove any leftover files from previous tests
+        sudo rm ${WORKSPACE}/*Wiki.txt
+        sudo rm ${WORKSPACE}/*Summary.txt
+        sudo rm ${WORKSPACE}/*Result.txt
+        sudo rm ${WORKSPACE}/*Alarm.txt || true
+        sudo rm ${WORKSPACE}/*.csv
+        #copy files to workspace
+        cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
+        ''' + copyLogs() + '''
+        sudo cp *.txt ${WORKSPACE}/
+        sudo cp *.csv ${WORKSPACE}/
+        cd ${WORKSPACE}/
+        for i in *.csv
+            do mv "$i" "$WikiPrefix"-"$i"
+        done
+        ls -al
+        cd '''
+}
+
+def fetchLogs( testName ){
+    // fetch the logs of onos from onos nodes to onos System Test logs
+    // testName: name of the test
+
+    return '''#!/bin/bash
+  set +e
+  cd ~/OnosSystemTest/TestON/logs
+  echo "TestON test name is: "''' + testName + '''
+  TestONlogDir=$(ls -t | grep ${TEST_NAME}_  |head -1)
+  echo "########################################################################################"
+  echo "#####  copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
+  echo "########################################################################################"
+  cd $TestONlogDir
+  if [ $? -eq 1 ]
+  then
+      echo "Job name does not match any test suite name to move log!"
+  else
+      pwd
+      for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist for onos $i; done
+      for i in $OC{1..7}; do atomix-fetch-logs $i || echo log does not exist for atomix $i; done
+  fi
+  cd'''
+}
+
+def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
+    // publish HTML script to wiki confluence
+    // isManualRun : string "true" "false"
+    // isPostResult : string "true" "false"
+    // wikiLink : link of the wiki page to publish
+    // file : name of the file to be published
+
+    if ( isPostingResult( isManualRun, isPostResult ) ){
+        publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
+                          attachArchivedArtifacts: true, buildIfUnstable: true,
+                          editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
+    }
+}
+
+def postLogs( testName, prefix ){
+    // posting logs of the onos jobs specifically SR tests
+    // testName : name of the test
+    // prefix : branch prefix ( master, 2.1, 1.15 ... )
+
+    resultURL = ""
+    if ( category == "SR" ){
+        def post = build job: "SR-log-" + prefix, propagate: false
+        resultURL = post.getAbsoluteUrl()
+    }
+    return resultURL
+}
+
+def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
+    // analyzing the result of the test and send to slack if any abnormal result is logged.
+    // prop : property dictionary
+    // workSpace : workSpace where the result file is saved
+    // pureTestName : TestON name of the test
+    // testName : Jenkins name of the test. Example: SCPFflowTPFobj
+    // resultURL : url for the logs for SR tests. Will not be posted if it is empty
+    // wikiLink : link of the wiki page where the result was posted
+    // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
+
+    node( testStation ) {
+        def alarmFile = workSpace + "/" + pureTestName + "Alarm.txt"
+        if ( fileExists( alarmFile ) ) {
+            def alarmContents = readFile( alarmFile )
+            slackSend( channel: "#jenkins-related",
+                       color: "FF0000",
+                       message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : triggered alarms:\n" +
+                                alarmContents + "\n" +
+                                "[TestON log] : \n" +
+                                "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
+                                ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
+                                                  "https://wiki.onosproject.org/display/ONOS/" +
+                                                  wikiLink.replaceAll( "\\s", "+" ) ) ) +
+                                ( resultURL != "" ? ( "\n[Karaf log] : \n" +
+                                                      resultURL + "artifact/" ) : "" ),
+                       teamDomain: 'onosproject' )
+            throw new Exception( "Abnormal test result." )
+        }
+        else {
+            print "Test results are OK."
+        }
+    }
+}
+
+def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
+             graph_saved_directory ){
+    // run the test on the machine that contains all the steps : init and run test, copy files, publish result ...
+    // testName : name of the test in Jenkins
+    // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
+    //           result on pipeline view
+    // prop : dictionary property on the machine
+    // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
+    // graphOnly : check if it is generating graph job. If so, it will only generate the generating graph part
+    // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
+    // graph_generator_file : Rscript file with the full path.
+    // graph_saved_directory : where the generated graph will be saved to.
+
+    return {
+        catchError {
+            stage( testName ) {
+                if ( toBeRun ){
+                    def workSpace = "/var/jenkins/workspace/" + testName
+                    def fileContents = ""
+                    node( testStation ) {
+                        withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
+                                   'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ],
+                                   'TestONBranch=' + prop[ "TestONBranch" ],
+                                   'ONOSTag=' + prop[ "ONOSTag" ],
+                                   'WikiPrefix=' + prop[ "WikiPrefix" ],
+                                   'WORKSPACE=' + workSpace ] ) {
+                            if ( !graphOnly ){
+                                if ( isSCPF ){
+                                    // Remove the old database file
+                                    sh SCPFfuncs.cleanupDatabaseFile( testName )
+                                }
+                                sh script: initTest(), label: "Test Initialization: stc shutdown; stc teardown; ./cleanup.sh"
+                                catchError{
+                                    sh script: runTestCli_py( testName, testCategory ), label: ( "Run Test: ./cli.py run " + testName )
+                                }
+                                catchError{
+                                    sh script: concludeRunTest(), label: "Conclude Running Test: ./cleanup.sh; git clean -df"
+                                }
+                                catchError{
+                                    // For the Wiki page
+                                    sh script: cleanAndCopyFiles( pureTestName ), label: "Clean and Copy Files"
+                                }
+                            }
+                            graphs.databaseAndGraph( prop, testName, pureTestName, graphOnly,
+                                                    graph_generator_file, graph_saved_directory )
+                            if ( !graphOnly ){
+                                sh script: fetchLogs( pureTestName ), label: "Fetch Logs"
+                                if ( !isSCPF ){
+                                    publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
+                                                         prop[ "WikiPrefix" ] + "-" + testCategory[ testName ][ 'wikiName' ],
+                                                         workSpace + "/" + testCategory[ testName ][ 'wikiFile' ] )
+                                }
+                            }
+                        }
+                    }
+                    graphs.postResult( prop, graphOnly, nodeLabel )
+                    if ( !graphOnly ){
+                        def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
+                        analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
+                                       isSCPF ? "" : testCategory[ testName ][ 'wikiName' ],
+                                       isSCPF )
+                    }
+                }
+            }
+        }
+    }
+}
+
 def generateGraphs(){
     if ( category != "SCPF" ){
         // generate the overall graph of the non SCPF tests.
-        funcs.generateOverallGraph( prop, testsToRun, graphPaths[ "saveDirectory" ] )
+        graphs.generateOverallGraph( prop, testsToRun, graphPaths[ "saveDirectory" ], nodeLabel, category )
     }
 }
 
 def sendToSlack(){
-    // send the notification to Slack that running tests ended.
-    funcs.sendResultToSlack( start, prop[ "manualRun" ], prop[ "WikiPrefix" ] )
+    // send the result of the test to the slack when it is not manually running.
+    // start : start time of the test
+    // isManualRun : string that is whether "false" or "true"
+    // branch : branch of the onos.
+
+    try {
+        if ( prop[ "manualRun" ] == "false" ){
+            end = getCurrentTime()
+            TimeDuration duration = TimeCategory.minus( end, start )
+            // FIXME: for now we disable notifications of normal test results
+            /*
+            slackSend( color: "#5816EE",
+                       message: category + "-" + prop[ "WikiPrefix" ] + " tests ended at: " + end.toString() +
+                                "\nTime took : " + duration )
+            */
+        }
+    }
+    catch ( all ){
+    }
 }
diff --git a/TestON/JenkinsFile/JenkinsfileTrigger b/TestON/JenkinsFile/JenkinsfileTrigger
deleted file mode 100644
index 28d6940..0000000
--- a/TestON/JenkinsFile/JenkinsfileTrigger
+++ /dev/null
@@ -1,62 +0,0 @@
-#!groovy
-// Copyright 2017 Open Networking Foundation (ONF)
-//
-// Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
-// the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
-// or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
-//
-//     TestON is free software: you can redistribute it and/or modify
-//     it under the terms of the GNU General Public License as published by
-//     the Free Software Foundation, either version 2 of the License, or
-//     (at your option) any later version.
-//
-//     TestON is distributed in the hope that it will be useful,
-//     but WITHOUT ANY WARRANTY; without even the implied warranty of
-//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//     GNU General Public License for more details.
-//
-//     You should have received a copy of the GNU General Public License
-//     along with TestON.  If not, see <http://www.gnu.org/licenses/>.
-
-// This is the Jenkins script for all-pipeline-trigger
-
-// read the dependency functions
-funcs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy' )
-
-// get current time and send the notification of starting the test.
-def now = funcs.getCurrentTime()
-print now.toString()
-
-// read the passed parameters from the Jenkins.
-machines = params.machines
-manually_run = params.manual_run
-// FIXME: for now we disable any other slack notifications excpet alarms
-/*
-if ( !manually_run ){
-    slackSend( color: '#03CD9F',
-               message: ":sparkles:" * 16 + "\n" +
-                        "Starting tests on : " + now.toString() +
-                        "\n" + ":sparkles:" * 16 )
-}
-*/
-
-// store the list of the machines into the dictionary.
-machineList = machines.tokenize( "\n;, " )
-machineOn = [ : ]
-
-// save the triggering job function as a dictionary.
-for ( machine in machineList ){
-    print( machine )
-    machineOn[ machine ] = triggerJob( machine )
-}
-
-// run the triggering jobs concurrently.
-parallel machineOn
-
-// function that will trigger the specific jobs from current pipeline.
-def triggerJob( on ){
-    return {
-        jobToRun = on + "-pipeline-trigger"
-        build job: jobToRun, propagate: false
-    }
-}
diff --git a/TestON/JenkinsFile/MasterTrigger.groovy b/TestON/JenkinsFile/MasterTrigger.groovy
index 372efc6..c095810 100644
--- a/TestON/JenkinsFile/MasterTrigger.groovy
+++ b/TestON/JenkinsFile/MasterTrigger.groovy
@@ -20,9 +20,11 @@
 
 // This is the Jenkins script for master-trigger
 
+import groovy.time.TimeCategory
+import groovy.time.TimeDuration
+
 // set the functions of the dependencies.
-funcs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy' )
-triggerFuncs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/TriggerFuncs.groovy' )
+graphs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsGraphs.groovy' )
 fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
 test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' )
 
@@ -86,7 +88,7 @@
     manually_run = params.manual_run
     onos_tag = params.ONOSTag
     branchesParam = params.branches
-    isOldFlow = params.isOldFlow
+    isOldFlow = true // hardcoding to true since we are always using oldFlow.
     testsParam = params.Tests
     isFabric = params.isFabric
     simulateDay = params.simulate_day
@@ -95,7 +97,7 @@
 // Set tests based on day of week
 def initDates(){
     echo "-> initDates()"
-    now = funcs.getCurrentTime()
+    now = getCurrentTime()
     dayMap = [ ( Calendar.MONDAY )    : "mon",
                ( Calendar.TUESDAY )   : "tue",
                ( Calendar.WEDNESDAY ) : "wed",
@@ -119,6 +121,13 @@
     }
 }
 
+def getCurrentTime(){
+    // get time of the PST zone.
+
+    TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) )
+    return new Date()
+}
+
 // gets ONOS branches from params or string parameter
 def getONOSBranches(){
     echo "-> getONOSBranches()"
@@ -178,13 +187,204 @@
 def postToSlackTestsToRun(){
     slackSend( color: '#FFD988',
                message: "Tests to be run this weekdays : \n" +
-                        triggerFuncs.printDaysForTest() )
+                        printDaysForTest() )
+}
+
+def printDaysForTest(){
+    // Print the days for what test has.
+    AllTheTests = test_list.getAllTests()
+
+    result = ""
+    for ( String test in AllTheTests.keySet() ){
+        result += test + ": ["
+        test_schedule = AllTheTests[ test ][ "schedules" ]
+        for ( String sch_dict in test_schedule ){
+            for ( String day in test_list.convertScheduleKeyToDays( sch_dict[ "branch" ] ) ){
+                result += day + " "
+            }
+        }
+        result += "]\n"
+    }
+    return result
 }
 
 // *********
 // Run Tests
 // *********
 
+def tagCheck( onos_tag, onos_branch ){
+    // check the tag for onos if it is not empty
+
+    result = "git checkout "
+    if ( onos_tag == "" ){
+        //create new local branch
+        result += onos_branch
+    }
+    else {
+        //checkout the tag
+        result += onos_tag
+    }
+    return result
+}
+
+def preSetup( onos_branch, test_branch, onos_tag, isManual ){
+    // pre setup part which will clean up and checkout to corresponding branch.
+
+    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 in case 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
+        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
+        rm -rf buck-out
+        rm -rf bazel-*
+        ''' + tagCheck( onos_tag, onos_branch ) + '''
+        git branch
+        git log -1 --decorate
+        echo -e "\n##### set jvm heap size to 8G #####"
+        echo ${ONOSJAVAOPTS}
+        inserted_line="export JAVA_OPTS=\"\${ONOSJAVAOPTS}\""
+        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'''
+    } else {
+        result = '''echo "Since this is a manual run, we'll use the current ONOS and TestON branch:"
+                    echo "ONOS branch:"
+                    cd ~/OnosSystemTest/
+                    git branch
+                    echo "TestON branch:"
+                    cd ~/TestON/
+                    git branch'''
+    }
+    return result
+}
+
+def postSetup( onos_branch, test_branch, onos_tag, isManual ){
+    // setup that will build ONOS
+
+    result = ""
+    if ( !isManual ){
+        result = '''echo -e "Installing bazel"
+        cd ~
+        rm -rf ci-management
+        git clone https://gerrit.onosproject.org/ci-management
+        cd ci-management/jjb/onos/
+        export GERRIT_BRANCH="''' + onos_branch + '''"
+        chmod +x install-bazel.sh
+        ./install-bazel.sh
+        '''
+    } else {
+        result = '''echo -e "Since this is a manual run, we will not install Bazel."'''
+    }
+    return result
+}
+
+def generateKey(){
+    // generate cluster-key of the onos
+
+    try {
+        sh script: '''
+        #!/bin/bash -l
+        set +e
+        . ~/.bashrc
+        env
+        onos-push-bits-through-proxy
+        onos-gen-cluster-key -f
+        ''', label: "Generate Cluster Key", returnStdout: false
+    } catch ( all ){
+    }
+}
+
+// Initialize the environment Setup for the onos and OnosSystemTest
+def envSetup( onos_branch, test_branch, onos_tag, jobOn, manuallyRun, nodeLabel ){
+    // to setup the environment using the bash script
+    stage( "Environment Setup: " + onos_branch + "-" + nodeLabel + "-" + jobOn ) {
+        // after env: ''' + borrow_mn( jobOn ) + '''
+        sh script: '''#!/bin/bash -l
+        set +e
+        . ~/.bashrc
+        env
+        ''' + preSetup( onos_branch, test_branch, onos_tag, manuallyRun ), label: "Repo Setup", returnStdout: false
+        sh script: postSetup( onos_branch, test_branch, onos_tag, manuallyRun ), label: "Install Bazel", returnStdout: false
+        generateKey()
+    }
+}
+
+// export Environment properties.
+def exportEnvProperty( onos_branch, test_branch, jobOn, wiki, tests, postResult, manually_run, onosTag, isOldFlow, nodeLabel ){
+    // export environment properties to the machine.
+
+    filePath = "/var/jenkins/TestONOS-" + jobOn + "-" + onos_branch + ".property"
+
+    stage( "Property Export: " + onos_branch + "-" + nodeLabel + "-" + jobOn ) {
+        sh script: '''
+            echo "ONOSBranch=''' + onos_branch + '''" > ''' + filePath + '''
+            echo "TestONBranch=''' + test_branch + '''" >> ''' + filePath + '''
+            echo "ONOSTag=''' + onosTag + '''" >> ''' + filePath + '''
+            echo "WikiPrefix=''' + wiki + '''" >> ''' + filePath + '''
+            echo "ONOSJAVAOPTS=''' + env.ONOSJAVAOPTS + '''" >> ''' + filePath + '''
+            echo "Tests=''' + tests + '''" >> ''' + filePath + '''
+            echo "postResult=''' + postResult + '''" >> ''' + filePath + '''
+            echo "manualRun=''' + manually_run + '''" >> ''' + filePath + '''
+            echo "isOldFlow=''' + isOldFlow + '''" >> ''' + filePath + '''
+        ''', label: "Exporting Property File: " + filePath
+    }
+}
+
+def trigger( branch, tests, nodeLabel, jobOn, manuallyRun, onosTag ){
+    // triggering function that will setup the environment and determine which pipeline to trigger
+
+    println "Job name: " + jobOn + "-pipeline-" + ( manuallyRun ? "manually" : branch )
+    def wiki = branch
+    def onos_branch = test_list.addPrefixToBranch( branch )
+    def test_branch = test_list.addPrefixToBranch( branch )
+    assignedNode = null
+    node( label: nodeLabel ) {
+
+        envSetup( onos_branch, test_branch, onosTag, jobOn, manuallyRun, nodeLabel )
+        exportEnvProperty( onos_branch, test_branch, jobOn, wiki, tests, post_result, manuallyRun, onosTag, isOldFlow, nodeLabel )
+        assignedNode = env.NODE_NAME
+    }
+
+    jobToRun = jobOn + "-pipeline-" + ( manuallyRun ? "manually" : wiki )
+    build job: jobToRun, propagate: false, parameters: [ [ $class: 'StringParameterValue', name: 'Category', value: jobOn ],
+                                                         [ $class: 'StringParameterValue', name: 'Branch', value: branch ],
+                                                         [ $class: 'StringParameterValue', name: 'TestStation', value: assignedNode ],
+                                                         [ $class: 'StringParameterValue', name: 'NodeLabel', value: nodeLabel ] ]
+}
+
+def trigger_pipeline( branch, tests, nodeLabel, jobOn, manuallyRun, onosTag ){
+    // nodeLabel : nodeLabel from tests.json
+    // jobOn : "SCPF" or "USECASE" or "FUNC" or "HA"
+    // this will return the function by wrapping them up with return{} to prevent them to be
+    // executed once this function is called to assign to specific variable.
+    return {
+        trigger( branch, tests, nodeLabel, jobOn, manuallyRun, onosTag )
+    }
+}
+
 def generateRunList(){
     runList = [:]
     validSchedules = test_list.getValidSchedules( day )
@@ -214,7 +414,7 @@
                 echo "TESTS: " + filteredList
                 if ( filteredList != [:] ){
                     exeTestList = test_list.getTestListAsString( filteredList )
-                    runList.put( branch + "-" + nodeLabel + "-" + category, triggerFuncs.trigger_pipeline( branch, exeTestList, nodeLabel, category, manually_run, onos_tag ) )
+                    runList.put( branch + "-" + nodeLabel + "-" + category, trigger_pipeline( branch, exeTestList, nodeLabel, category, manually_run, onos_tag ) )
                 }
 
             }
@@ -237,7 +437,7 @@
     // If it is automated running, it will generate the stats graph on VM.
     if ( !manually_run ){
         for ( String b in onos_branches ){
-            funcs.generateStatGraph( "TestStation-VMs",
+            graphs.generateStatGraph( "TestStation-VMs",
                                      test_list.addPrefixToBranch( b ),
                                      graphPaths[ "histogramMultiple" ],
                                      graphPaths[ "pieMultiple" ],
diff --git a/TestON/JenkinsFile/Overall_Graph_Generator b/TestON/JenkinsFile/Overall_Graph_Generator
index 4eed1b3..8e46c7c 100644
--- a/TestON/JenkinsFile/Overall_Graph_Generator
+++ b/TestON/JenkinsFile/Overall_Graph_Generator
@@ -21,7 +21,7 @@
 // This is the Jenkins script for manual-graph-generator-overall
 
 // read the dependency functions.
-funcs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy' )
+graphs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsGraphs.groovy' )
 fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
 
 fileRelated.init()
@@ -31,15 +31,12 @@
 pie_graph_generator_file = fileRelated.rScriptPaths[ "scripts" ][ "pieMultiple" ]
 graph_saved_directory = fileRelated.workspaces[ "VM" ]
 
-// init trend which will generate the pie and histogram graphs to be VM.
-funcs.initializeTrend( "VM" )
-
 onos_branch = params.ONOSbranch
 
 // generate the graph and post the result on TestStation-VMs. Right now, all the pie and histograms are saved
 // on VM.
-funcs.generateStatGraph( "TestStation-VMs",
+graphs.generateStatGraph( "TestStation-VMs",
                          onos_branch,
                          stat_graph_generator_file,
                          pie_graph_generator_file,
-                         graph_saved_directory )
+                         graph_saved_directory, "VM" )
diff --git a/TestON/JenkinsFile/SCPF_Graph_Generator b/TestON/JenkinsFile/SCPF_Graph_Generator
deleted file mode 100644
index d120911..0000000
--- a/TestON/JenkinsFile/SCPF_Graph_Generator
+++ /dev/null
@@ -1,53 +0,0 @@
-#!groovy
-// Copyright 2017 Open Networking Foundation (ONF)
-//
-// Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
-// the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
-// or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
-//
-//     TestON is free software: you can redistribute it and/or modify
-//     it under the terms of the GNU General Public License as published by
-//     the Free Software Foundation, either version 2 of the License, or
-//     (at your option) any later version.
-//
-//     TestON is distributed in the hope that it will be useful,
-//     but WITHOUT ANY WARRANTY; without even the implied warranty of
-//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//     GNU General Public License for more details.
-//
-//     You should have received a copy of the GNU General Public License
-//     along with TestON.  If not, see <http://www.gnu.org/licenses/>.
-
-// This is the Jenkins script for manual-graph-generator-SCPF
-
-// read and set the functions from dependencies.
-SCPFfuncs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/PerformanceFuncs.groovy' )
-SCPFfuncs.init()
-funcs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy' )
-funcs.initialize( "SCPF", "TestStation-BMs", "BM", SCPFfuncs );
-
-def prop = null
-prop = funcs.getProperties( "SCPF", params.ONOSbranch )
-
-// get the variables from the Jenkins parameters.
-def Tests = params.Test
-isOldFlow = params.isOldFlow
-prop[ "ONOSBranch" ] = params.ONOSbranch
-
-SCPFfuncs.oldFlowRuleCheck( isOldFlow, prop[ "ONOSBranch" ] )
-
-def testsToRun = null
-testsToRun = funcs.getTestsToRun( Tests )
-
-// pureTestName is because we don't want 'WFobj' to be used for test name.
-def tests = [ : ]
-for ( String test : testsToRun ){
-    println test
-    pureTestName = test.replaceAll( "WithFlowObj", "" )
-    tests[ test ] = funcs.runTest( test, true, prop, pureTestName, true, [ ], "", "" )
-}
-
-// generate the graphs sequentially.
-for ( test in tests.keySet() ){
-    tests[ test ].call()
-}
diff --git a/TestON/JenkinsFile/Trend_Graph_Generator b/TestON/JenkinsFile/Trend_Graph_Generator
deleted file mode 100644
index fc20373..0000000
--- a/TestON/JenkinsFile/Trend_Graph_Generator
+++ /dev/null
@@ -1,63 +0,0 @@
-#!groovy
-// Copyright 2017 Open Networking Foundation (ONF)
-//
-// Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
-// the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
-// or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
-//
-//     TestON is free software: you can redistribute it and/or modify
-//     it under the terms of the GNU General Public License as published by
-//     the Free Software Foundation, either version 2 of the License, or
-//     (at your option) any later version.
-//
-//     TestON is distributed in the hope that it will be useful,
-//     but WITHOUT ANY WARRANTY; without even the implied warranty of
-//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//     GNU General Public License for more details.
-//
-//     You should have received a copy of the GNU General Public License
-//     along with TestON.  If not, see <http://www.gnu.org/licenses/>.
-
-// This is the Jenkins script for manual-graph-generator-trend
-
-// read the dependency functions
-funcs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy' )
-fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
-
-fileRelated.init()
-
-// read the node cluster ( VM or BM or Fabrics ) from the Jenkins job.
-nodeCluster = params.NodeCluster
-
-funcs.initializeTrend( nodeCluster )
-
-// do additional check for Fabric since it will be different depends on which branch it is running on.
-if ( nodeCluster == "Fabric" ){
-    funcs.additionalInitForSR( params.ONOSbranch )
-}
-def prop = null
-prop = funcs.getProperties( "FUNC" )
-
-// get the list of the tests from the parameters.
-def Tests = params.Test
-prop[ "ONOSBranch" ] = params.ONOSbranch
-
-// set some of the paths of the file and directory
-graph_generator_file = fileRelated.rScriptPaths[ "scripts" ][ "trendIndividual" ]
-graph_saved_directory = fileRelated.workspaces[ "base" ] + "postjob-" + nodeCluster +
-                        ( nodeCluster == "Fabric" ? funcs.fabricOn( prop[ "ONOSBranch" ] ) : "" ) + "/"
-
-def testsToRun = null
-testsToRun = funcs.getTestsToRun( Tests )
-
-// set functions into the dictionary.
-def tests = [ : ]
-for ( String test : testsToRun ){
-    println test
-    def pureTestName = test.split().head()
-    tests[ test ] = funcs.runTest( test, true, prop, pureTestName, true, [ ], graph_generator_file, graph_saved_directory )
-}
-
-for ( test in tests.keySet() ){
-    tests[ test ].call()
-}
diff --git a/TestON/JenkinsFile/dependencies/GeneralFuncs.groovy b/TestON/JenkinsFile/dependencies/GeneralFuncs.groovy
deleted file mode 100644
index 4c6f021..0000000
--- a/TestON/JenkinsFile/dependencies/GeneralFuncs.groovy
+++ /dev/null
@@ -1,43 +0,0 @@
-#!groovy
-// Copyright 2017 Open Networking Foundation (ONF)
-//
-// Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
-// the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
-// or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
-//
-//     TestON is free software: you can redistribute it and/or modify
-//     it under the terms of the GNU General Public License as published by
-//     the Free Software Foundation, either version 2 of the License, or
-//     (at your option) any later version.
-//
-//     TestON is distributed in the hope that it will be useful,
-//     but WITHOUT ANY WARRANTY; without even the implied warranty of
-//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//     GNU General Public License for more details.
-//
-//     You should have received a copy of the GNU General Public License
-//     along with TestON.  If not, see <http://www.gnu.org/licenses/>.
-
-// This is the dependency Jenkins script.
-// it has some general functionality of making database command, basic graph part, and get list of the test
-
-// make the init part of the database command
-def database_command_create( pass, host, port, user ){
-    return pass + "|psql --host=" + host + " --port=" + port + " --username=" + user + " --password --dbname onostest -c "
-}
-
-// make the basic graph part for the Rscript
-def basicGraphPart( rFileName, host, port, user, pass, subject, branchName ){
-    return " Rscript " + rFileName + " " + host + " " + port + " " + user + " " + pass + " " + subject + " " + branchName
-}
-
-// get the list of the test as dictionary then return as a string
-def getTestList( tests ){
-    def list = ""
-    for ( String test : tests.keySet() ){
-        list += test + ","
-    }
-    return list[ 0..-2 ]
-}
-
-return this
diff --git a/TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy b/TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy
deleted file mode 100644
index 26e846c..0000000
--- a/TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy
+++ /dev/null
@@ -1,521 +0,0 @@
-#!groovy
-// Copyright 2017 Open Networking Foundation (ONF)
-//
-// Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
-// the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
-// or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
-//
-//     TestON is free software: you can redistribute it and/or modify
-//     it under the terms of the GNU General Public License as published by
-//     the Free Software Foundation, either version 2 of the License, or
-//     (at your option) any later version.
-//
-//     TestON is distributed in the hope that it will be useful,
-//     but WITHOUT ANY WARRANTY; without even the implied warranty of
-//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//     GNU General Public License for more details.
-//
-//     You should have received a copy of the GNU General Public License
-//     along with TestON.  If not, see <http://www.gnu.org/licenses/>.
-
-// This is the dependency Jenkins script.
-// it has some common functions that runs test and generate graph.
-
-import groovy.time.TimeCategory
-import groovy.time.TimeDuration
-
-generalFuncs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/GeneralFuncs.groovy' )
-fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
-test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' )
-
-fileRelated.init()
-test_list.init()
-
-nodeLabel = null
-testStation = null
-
-def initializeTrend( machine ){
-    // For initializing any trend graph jobs
-    // machine : Either VM,BM, or Fabric#
-
-    table_name = "executed_test_tests"
-    result_name = "executed_test_results"
-    testStation = "TestStation-" + machine + "s"
-    this.machine = machine
-    isSCPF = false
-    isTrend = true
-}
-
-def initialize( type, testS, nodeL, SCPFfuncs=null ){
-    // initializing for FUNC,HA,SR, and USECASE
-    // type : type of the test ( SR,FUNC,SCPF... )
-
-    testStation = testS
-    testType = type
-    nodeLabel = nodeL
-    isSCPF = ( type == "SCPF" )
-    SCPFfunc = SCPFfuncs
-
-    table_name = "executed_test_tests"
-    result_name = "executed_test_results"
-    trend_generator_file = fileRelated.rScriptPaths[ "scripts" ][ "trendMultiple" ]
-    build_stats_generator_file = fileRelated.rScriptPaths[ "scripts" ][ "histogramMultiple" ]
-    isTrend = false
-}
-
-def getProperties( category, branchWithPrefix ){
-    // get the properties of the test by reading the TestONOS.property
-
-    filePath = '''/var/jenkins/TestONOS-''' + category + '''-''' + branchWithPrefix + '''.property'''
-
-    node( testStation ) {
-        return readProperties( file: filePath )
-    }
-}
-
-def getTestsToRun( testList ){
-    // get test to run by tokenizing the list.
-
-    testList.tokenize( "\n;, " )
-}
-
-def getCurrentTime(){
-    // get time of the PST zone.
-
-    TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) )
-    return new Date()
-}
-
-def sendResultToSlack( start, isManualRun, branch ){
-    // send the result of the test to the slack when it is not manually running.
-    // start : start time of the test
-    // isManualRun : string that is whether "false" or "true"
-    // branch : branch of the onos.
-
-    try {
-        if ( isManualRun == "false" ){
-            end = getCurrentTime()
-            TimeDuration duration = TimeCategory.minus( end, start )
-            // FIXME: for now we disable notifications of normal test results
-            /*
-            slackSend( color: "#5816EE",
-                       message: testType + "-" + branch + " tests ended at: " + end.toString() +
-                                "\nTime took : " + duration )
-            */
-        }
-    }
-    catch ( all ){
-    }
-}
-
-def initAndRunTest( testName, testCategory ){
-    // Bash script that will
-    // Initialize the environment to the machine and run the test.
-    // testName : name of the test
-    // testCategory : (SR,FUNC ... )
-
-    return '''#!/bin/bash -l
-        set -i # interactive
-        set +e
-        shopt -s expand_aliases # expand alias in non-interactive mode
-        export PYTHONUNBUFFERED=1
-        ifconfig
-        echo "ONOS Branch is: $ONOSBranch"
-        echo "TestON Branch is: $TestONBranch"
-        echo "Test date: "
-        date
-        cd ~
-        export PATH=$PATH:onos/tools/test/bin
-        timeout 240 stc shutdown | head -100
-        timeout 240 stc teardown | head -100
-        timeout 240 stc shutdown | head -100
-        cd ~/OnosSystemTest/TestON/bin
-        git log | head
-        ./cleanup.sh -f
-        ''' + "./cli.py run " +
-          testName +
-           " --params GRAPH/nodeCluster=" + nodeLabel + '''
-        ./cleanup.sh -f
-        # cleanup config changes
-        cd ~/onos/tools/package/config
-        git clean -df'''
-}
-
-def copyLogs(){
-    // bash script to copy the logs and other necessary element for SR tests.
-
-    result = ""
-    if ( testType == "SR" ){
-        result = '''
-      sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
-      sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
-      sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
-      sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
-      sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
-      sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
-      '''
-    }
-    return result
-}
-
-def cleanAndCopyFiles( testName ){
-    // clean up some files that were in the folder and copy the new files from the log
-    // testName : name of the test
-
-    return '''#!/bin/bash -i
-        set +e
-        echo "ONOS Branch is: ${ONOSBranch}"
-        echo "TestON Branch is: ${TestONBranch}"
-        echo "Job name is: "''' + testName + '''
-        echo "Workspace is: ${WORKSPACE}/"
-        echo "Wiki page to post is: ${WikiPrefix}-"
-        # remove any leftover files from previous tests
-        sudo rm ${WORKSPACE}/*Wiki.txt
-        sudo rm ${WORKSPACE}/*Summary.txt
-        sudo rm ${WORKSPACE}/*Result.txt
-        sudo rm ${WORKSPACE}/*Alarm.txt || true
-        sudo rm ${WORKSPACE}/*.csv
-        #copy files to workspace
-        cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
-        ''' + copyLogs() + '''
-        sudo cp *.txt ${WORKSPACE}/
-        sudo cp *.csv ${WORKSPACE}/
-        cd ${WORKSPACE}/
-        for i in *.csv
-            do mv "$i" "$WikiPrefix"-"$i"
-        done
-        ls -al
-        cd '''
-}
-
-def fetchLogs( testName ){
-    // fetch the logs of onos from onos nodes to onos System Test logs
-    // testName: name of the test
-
-    return '''#!/bin/bash
-  set +e
-  cd ~/OnosSystemTest/TestON/logs
-  echo "TestON test name is: "''' + testName + '''
-  TestONlogDir=$(ls -t | grep ${TEST_NAME}_  |head -1)
-  echo "########################################################################################"
-  echo "#####  copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
-  echo "########################################################################################"
-  cd $TestONlogDir
-  if [ $? -eq 1 ]
-  then
-      echo "Job name does not match any test suite name to move log!"
-  else
-      pwd
-      for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist for onos $i; done
-      for i in $OC{1..7}; do atomix-fetch-logs $i || echo log does not exist for atomix $i; done
-  fi
-  cd'''
-}
-
-def isPostingResult( manual, postresult ){
-    // check if it is posting the result.
-    // posting when it is automatically running or has postResult condition from the manual run
-
-    return manual == "false" || postresult == "true"
-}
-
-def postResult( prop, graphOnly ){
-    // post the result by triggering postjob.
-    // prop : property dictionary that was read from the machine.
-    // graphOnly : if it is graph generating job
-
-    if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
-        postjob_type = ""
-        switch ( nodeLabel ){
-            case "Fabric-1.x":
-                postjob_type = "Fabric2"
-                break
-            case "Fabric-2.x":
-                postjob_type = "Fabric3"
-                break
-            case "Fabric-master":
-                postjob_type = "Fabric4"
-                break
-            default:
-                postjob_type = nodeLabel
-                break
-        }
-
-        def post = build job: "postjob-" + postjob_type, propagate: false
-    }
-}
-
-def postLogs( testName, prefix ){
-    // posting logs of the onos jobs specifically SR tests
-    // testName : name of the test
-    // prefix : branch prefix ( master, 2.1, 1.15 ... )
-
-    resultURL = ""
-    if ( testType == "SR" ){
-        def post = build job: "SR-log-" + prefix, propagate: false
-        resultURL = post.getAbsoluteUrl()
-    }
-    return resultURL
-}
-
-def getSlackChannel(){
-    // get name of the slack channel.
-    // if the test is SR, it will return sr-failures
-
-    // FIXME: For now we move all notifications to #jenkins-related
-    // return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
-    return "#jenkins-related"
-}
-
-def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
-    // analyzing the result of the test and send to slack if any abnormal result is logged.
-    // prop : property dictionary
-    // workSpace : workSpace where the result file is saved
-    // pureTestName : TestON name of the test
-    // testName : Jenkins name of the test. Example: SCPFflowTPFobj
-    // resultURL : url for the logs for SR tests. Will not be posted if it is empty
-    // wikiLink : link of the wiki page where the result was posted
-    // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
-
-    node( testStation ) {
-        def alarmFile = workSpace + "/" + pureTestName + "Alarm.txt"
-        if ( fileExists( alarmFile ) ) {
-            def alarmContents = readFile( alarmFile )
-            slackSend( channel: getSlackChannel(),
-                       color: "FF0000",
-                       message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : triggered alarms:\n" +
-                                alarmContents + "\n" +
-                                "[TestON log] : \n" +
-                                "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
-                                ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
-                                                  "https://wiki.onosproject.org/display/ONOS/" +
-                                                  wikiLink.replaceAll( "\\s", "+" ) ) ) +
-                                ( resultURL != "" ? ( "\n[Karaf log] : \n" +
-                                                      resultURL + "artifact/" ) : "" ),
-                       teamDomain: 'onosproject' )
-            throw new Exception( "Abnormal test result." )
-        }
-        else {
-            print "Test results are OK."
-        }
-    }
-}
-
-def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
-    // publish HTML script to wiki confluence
-    // isManualRun : string "true" "false"
-    // isPostResult : string "true" "false"
-    // wikiLink : link of the wiki page to publish
-    // file : name of the file to be published
-
-    if ( isPostingResult( isManualRun, isPostResult ) ){
-        publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
-                          attachArchivedArtifacts: true, buildIfUnstable: true,
-                          editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
-    }
-
-}
-
-def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
-             graph_saved_directory ){
-    // run the test on the machine that contains all the steps : init and run test, copy files, publish result ...
-    // testName : name of the test in Jenkins
-    // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
-    //           result on pipeline view
-    // prop : dictionary property on the machine
-    // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
-    // graphOnly : check if it is generating graph job. If so, it will only generate the generating graph part
-    // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
-    // graph_generator_file : Rscript file with the full path.
-    // graph_saved_directory : where the generated graph will be saved to.
-
-    return {
-        catchError {
-            stage( testName ) {
-                if ( toBeRun ){
-                    def workSpace = "/var/jenkins/workspace/" + testName
-                    def fileContents = ""
-                    node( testStation ) {
-                        withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
-                                   'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ],
-                                   'TestONBranch=' + prop[ "TestONBranch" ],
-                                   'ONOSTag=' + prop[ "ONOSTag" ],
-                                   'WikiPrefix=' + prop[ "WikiPrefix" ],
-                                   'WORKSPACE=' + workSpace ] ) {
-                            if ( !graphOnly ){
-                                if ( isSCPF ){
-                                    // Remove the old database file
-                                    sh SCPFfunc.cleanupDatabaseFile( testName )
-                                }
-                                sh initAndRunTest( testName, testCategory )
-                                // For the Wiki page
-                                sh cleanAndCopyFiles( pureTestName )
-                            }
-                            databaseAndGraph( prop, testName, pureTestName, graphOnly,
-                                              graph_generator_file, graph_saved_directory )
-                            if ( !graphOnly ){
-                                sh fetchLogs( pureTestName )
-                                if ( !isSCPF ){
-                                    publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
-                                                         prop[ "WikiPrefix" ] + "-" + testCategory[ testName ][ 'wikiName' ],
-                                                         workSpace + "/" + testCategory[ testName ][ 'wikiFile' ] )
-                                }
-                            }
-                        }
-                    }
-                    postResult( prop, graphOnly )
-                    if ( !graphOnly ){
-                        def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
-                        analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
-                                       isSCPF ? "" : testCategory[ testName ][ 'wikiName' ],
-                                       isSCPF )
-                    }
-                }
-            }
-        }
-    }
-}
-
-def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
-    // part where it insert the data into the database.
-    // It will use the predefined encrypted variables from the Jenkins.
-    // prop : property dictionary that was read from the machine
-    // testName : Jenkins name for the test
-    // pureTestName : TestON name for the test
-    // graphOnly : boolean whether it is graph only or not
-    // graph_generator_file : Rscript file with the full path.
-    // graph_saved_directory : where the generated graph will be saved to.
-    if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
-        // Post Results
-        withCredentials( [
-                string( credentialsId: 'db_pass', variable: 'pass' ),
-                string( credentialsId: 'db_user', variable: 'user' ),
-                string( credentialsId: 'db_host', variable: 'host' ),
-                string( credentialsId: 'db_port', variable: 'port' ) ] ) {
-            def database_command = generalFuncs.database_command_create( pass, host, port, user ) +
-                                   ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
-            sh '''#!/bin/bash
-              export DATE=\$(date +%F_%T)
-              cd ~
-              pwd ''' + ( graphOnly ? "" :
-                          ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
-                            SCPFfunc.databasePart( testName, database_command ) ) ) + '''
-              ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
-                                                 graph_generator_file ) :
-                      SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
-        }
-    }
-}
-
-def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
-                                save_path, pieTestListPart ){
-    // function that will generate the category stat graphs for the overall test.
-    // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
-    // manualRun : string of "true" or "false"
-    // postresult : string of "true" or "false"
-    // stat_file : file name with full path for Rscript for the stat graph
-    // pie_file : file name with full path for Rscript for the pie graph
-    // type : type of the test ( USECASE, FUNC, HA )
-    // branch : branch of the test ( master, onos-2.1, onos-1.15 )
-    // testListPart : list of the test to be included
-    // save_path : path that will save the graphs to
-    // pieTestListPart : list of the test for pie graph
-
-    if ( isPostingResult( manualRun, postresult ) ){
-        node( testMachineOn ) {
-
-            withCredentials( [
-                    string( credentialsId: 'db_pass', variable: 'pass' ),
-                    string( credentialsId: 'db_user', variable: 'user' ),
-                    string( credentialsId: 'db_host', variable: 'host' ),
-                    string( credentialsId: 'db_port', variable: 'port' ) ] ) {
-                sh '''#!/bin/bash
-              ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type,
-                                                 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
-              ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
-                                        save_path ) + '''
-              ''' +
-                   getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
-            }
-        }
-        postResult( [ ], true )
-    }
-}
-
-
-def generateOverallGraph( prop, tests, graph_saved_directory ){
-    // generate the overall graph for the test
-
-    if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
-        node( testStation ) {
-
-            withCredentials( [
-                    string( credentialsId: 'db_pass', variable: 'pass' ),
-                    string( credentialsId: 'db_user', variable: 'user' ),
-                    string( credentialsId: 'db_host', variable: 'host' ),
-                    string( credentialsId: 'db_port', variable: 'port' ) ] ) {
-                testList = test_list.getTestListAsString( tests )
-                sh '''#!/bin/bash
-                   ''' +
-                   generalFuncs.basicGraphPart( trend_generator_file, host, port,
-                                                user, pass, testType,
-                                                prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
-            }
-        }
-        postResult( prop, false )
-    }
-}
-
-def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
-    // Rcommand for the pie graph
-
-    return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) +
-           " \"" + testList + "\" latest " + yOrN + " " + path
-}
-
-def sqlCommand( testName ){
-    // get the inserting sqlCommand for non-SCPF tests.
-
-    return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
-           testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
-}
-
-def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
-    // get the graphGenerating R command for non-SCPF tests
-
-    return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName,
-                                        prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
-}
-
-def databasePart( wikiPrefix, testName, database_command ){
-    // to read and insert the data from .csv to the database
-
-    return '''
-    sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
-    do
-    echo \$line
-    echo ''' + database_command + '''
-    done '''
-}
-
-def generateStatGraph( testMachineOn, onos_branch, stat_graph_generator_file, pie_graph_generator_file,
-                       graph_saved_directory ){
-
-    // Will generate the stats graph.
-    FUNCtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "FUNC" ) )
-    HAtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "HA" ) )
-    USECASEtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "USECASE" ) )
-
-    testListParam = "FUNC-"     + FUNCtestsStr + ";" +
-                    "HA-"       + HAtestsStr   + ";" +
-                    "USECASE-"  + USECASEtestsStr
-
-    pieTestListParam = FUNCtestsStr + "," +
-                       HAtestsStr   + "," +
-                       USECASEtestsStr
-
-    generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
-                                "ALL", onos_branch, testListParam, graph_saved_directory, pieTestListParam )
-}
-
-return this
diff --git a/TestON/JenkinsFile/dependencies/JenkinsGraphs.groovy b/TestON/JenkinsFile/dependencies/JenkinsGraphs.groovy
new file mode 100644
index 0000000..3aef5a9
--- /dev/null
+++ b/TestON/JenkinsFile/dependencies/JenkinsGraphs.groovy
@@ -0,0 +1,228 @@
+#!groovy
+// Copyright 2017 Open Networking Foundation (ONF)
+//
+// Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
+// the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
+// or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
+//
+//     TestON is free software: you can redistribute it and/or modify
+//     it under the terms of the GNU General Public License as published by
+//     the Free Software Foundation, either version 2 of the License, or
+//     (at your option) any later version.
+//
+//     TestON is distributed in the hope that it will be useful,
+//     but WITHOUT ANY WARRANTY; without even the implied warranty of
+//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//     GNU General Public License for more details.
+//
+//     You should have received a copy of the GNU General Public License
+//     along with TestON.  If not, see <http://www.gnu.org/licenses/>.
+
+// This is the dependency Jenkins script.
+// it has some common functions that runs test and generate graph.
+
+generalFuncs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/GeneralFuncs.groovy' )
+fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
+test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' )
+
+fileRelated.init()
+test_list.init()
+
+testStation = null
+isSCPF = null
+
+def initialize( SCPFf=null ){
+    isSCPF = ( SCPFf != null )
+    SCPFfunc = SCPFf
+    trend_generator_file = fileRelated.rScriptPaths[ "scripts" ][ "trendMultiple" ]
+    build_stats_generator_file = fileRelated.rScriptPaths[ "scripts" ][ "histogramMultiple" ]
+}
+
+def postResult( prop, graphOnly, nodeLabel ){
+    // post the result by triggering postjob.
+    // prop : property dictionary that was read from the machine.
+    // graphOnly : if it is graph generating job
+
+    if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
+        postjob_type = ""
+        switch ( nodeLabel ){
+            case "Fabric-1.x":
+                postjob_type = "Fabric2"
+                break
+            case "Fabric-2.x":
+                postjob_type = "Fabric3"
+                break
+            case "Fabric-master":
+                postjob_type = "Fabric4"
+                break
+            default:
+                postjob_type = nodeLabel
+                break
+        }
+
+        def post = build job: "postjob-" + postjob_type, propagate: false
+    }
+}
+
+def isPostingResult( manual, postresult ){
+    // check if it is posting the result.
+    // posting when it is automatically running or has postResult condition from the manual run
+
+    return manual == "false" || postresult == "true"
+}
+
+def database_command_create( pass, host, port, user ){
+    return pass + "|psql --host=" + host + " --port=" + port + " --username=" + user + " --password --dbname onostest -c "
+}
+
+def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
+    // part where it insert the data into the database.
+    // It will use the predefined encrypted variables from the Jenkins.
+    // prop : property dictionary that was read from the machine
+    // testName : Jenkins name for the test
+    // pureTestName : TestON name for the test
+    // graphOnly : boolean whether it is graph only or not
+    // graph_generator_file : Rscript file with the full path.
+    // graph_saved_directory : where the generated graph will be saved to.
+    if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
+        // Post Results
+        withCredentials( [
+                string( credentialsId: 'db_pass', variable: 'pass' ),
+                string( credentialsId: 'db_user', variable: 'user' ),
+                string( credentialsId: 'db_host', variable: 'host' ),
+                string( credentialsId: 'db_port', variable: 'port' ) ] ) {
+            def database_command = database_command_create( pass, host, port, user ) +
+                                   ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
+            sh script: '''#!/bin/bash
+              export DATE=\$(date +%F_%T)
+              cd ~
+              pwd ''' + ( graphOnly ? "" :
+                          ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
+                            SCPFfunc.databasePart( testName, database_command ) ) ), label: "Database"
+            sh script: ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
+                                                 graph_generator_file ) :
+                      SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) ), label: "Generate Test Graph"
+        }
+    }
+}
+
+// make the basic graph part for the Rscript
+def basicGraphPart( rFileName, host, port, user, pass, subject, branchName ){
+    return " Rscript " + rFileName + " " + host + " " + port + " " + user + " " + pass + " " + subject + " " + branchName
+}
+
+def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
+                                save_path, pieTestListPart, nodeLabel ){
+    // function that will generate the category stat graphs for the overall test.
+    // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
+    // manualRun : string of "true" or "false"
+    // postresult : string of "true" or "false"
+    // stat_file : file name with full path for Rscript for the stat graph
+    // pie_file : file name with full path for Rscript for the pie graph
+    // type : type of the test ( USECASE, FUNC, HA )
+    // branch : branch of the test ( master, onos-2.1, onos-1.15 )
+    // testListPart : list of the test to be included
+    // save_path : path that will save the graphs to
+    // pieTestListPart : list of the test for pie graph
+
+    if ( isPostingResult( manualRun, postresult ) ){
+        node( testMachineOn ) {
+
+            withCredentials( [
+                    string( credentialsId: 'db_pass', variable: 'pass' ),
+                    string( credentialsId: 'db_user', variable: 'user' ),
+                    string( credentialsId: 'db_host', variable: 'host' ),
+                    string( credentialsId: 'db_port', variable: 'port' ) ] ) {
+                sh script: ( '''#!/bin/bash
+              ''' + basicGraphPart( stat_file, host, port, user, pass, type,
+                                                 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
+              ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
+                                        save_path ) + '''
+              ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path ) ), label: "Generate Stats Graphs"
+            }
+        }
+        postResult( [ ], true, nodeLabel )
+    }
+}
+
+
+def generateOverallGraph( prop, tests, graph_saved_directory, nodeLabel, testType ){
+    // generate the overall graph for the test
+
+    if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
+        node( testStation ) {
+
+            withCredentials( [
+                    string( credentialsId: 'db_pass', variable: 'pass' ),
+                    string( credentialsId: 'db_user', variable: 'user' ),
+                    string( credentialsId: 'db_host', variable: 'host' ),
+                    string( credentialsId: 'db_port', variable: 'port' ) ] ) {
+                testList = test_list.getTestListAsString( tests )
+                sh script: ( '''#!/bin/bash''' +
+                   basicGraphPart( trend_generator_file, host, port,
+                                                user, pass, testType,
+                                                prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory ), label: "Generate Overall Graph"
+            }
+        }
+        postResult( prop, false, nodeLabel )
+    }
+}
+
+def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
+    // Rcommand for the pie graph
+
+    return basicGraphPart( file, host, port, user, pass, type, branch ) +
+           " \"" + testList + "\" latest " + yOrN + " " + path
+}
+
+def sqlCommand( testName ){
+    // get the inserting sqlCommand for non-SCPF tests.
+    table_name = "executed_test_tests"
+    result_name = "executed_test_results"
+
+    return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
+           testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
+}
+
+def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
+    // get the graphGenerating R command for non-SCPF tests
+
+    return basicGraphPart( graph_generator_file, host, port, user, pass, testName,
+                                        prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
+}
+
+def databasePart( wikiPrefix, testName, database_command ){
+    // to read and insert the data from .csv to the database
+
+    return '''
+    sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
+    do
+    echo \$line
+    echo ''' + database_command + '''
+    done '''
+}
+
+def generateStatGraph( testMachineOn, onos_branch, stat_graph_generator_file, pie_graph_generator_file,
+                       graph_saved_directory, nodeLabel ){
+
+    table_name = "executed_test_tests"
+    result_name = "executed_test_results"
+
+    // Will generate the stats graph.
+    FUNCtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "FUNC" ) )
+    HAtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "HA" ) )
+    USECASEtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "USECASE" ) )
+
+    testListParam = "FUNC-"     + FUNCtestsStr + ";" +
+                    "HA-"       + HAtestsStr   + ";" +
+                    "USECASE-"  + USECASEtestsStr
+
+    pieTestListParam = FUNCtestsStr + "," +
+                       HAtestsStr   + "," +
+                       USECASEtestsStr
+
+    generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
+                                "ALL", onos_branch, testListParam, graph_saved_directory, pieTestListParam, nodeLabel )
+}
+
+return this
diff --git a/TestON/JenkinsFile/dependencies/PerformanceFuncs.groovy b/TestON/JenkinsFile/dependencies/PerformanceFuncs.groovy
index 452ddfc..fd70fcc 100644
--- a/TestON/JenkinsFile/dependencies/PerformanceFuncs.groovy
+++ b/TestON/JenkinsFile/dependencies/PerformanceFuncs.groovy
@@ -255,10 +255,15 @@
     return result
 }
 
+// make the basic graph part for the Rscript
+def basicGraphPart( rFileName, host, port, user, pass, subject, branchName ){
+    return " Rscript " + rFileName + " " + host + " " + port + " " + user + " " + pass + " " + subject + " " + branchName
+}
+
 def generateGraph( rFileName, batch, host, port, user, pass, testName, branchName, isOldFlow ){
     //  generate the Rscript command for individual graphs
 
-    return generalFuncs.basicGraphPart( fileRelated.rScriptPaths[ "directories" ][ "SCPF" ] + rFileName,
+    return basicGraphPart( fileRelated.rScriptPaths[ "directories" ][ "SCPF" ] + rFileName,
                                         host, port, user, pass, testName, branchName ) +
            " " + batch + " " + usingOldFlow( isOldFlow, testName ) + graph_saved_directory
 }
@@ -268,7 +273,7 @@
     def result = ""
 
     for ( int i = 0; i < SCPF[ testName ][ 'graphTitle' ].size(); i++ ){
-        result += generalFuncs.basicGraphPart( fileRelated.rScriptPaths[ "scripts" ][ "trendSCPF" ],
+        result += basicGraphPart( fileRelated.rScriptPaths[ "scripts" ][ "trendSCPF" ],
                                                host,
                                                port,
                                                user,
diff --git a/TestON/JenkinsFile/dependencies/TriggerFuncs.groovy b/TestON/JenkinsFile/dependencies/TriggerFuncs.groovy
deleted file mode 100644
index b6b3212..0000000
--- a/TestON/JenkinsFile/dependencies/TriggerFuncs.groovy
+++ /dev/null
@@ -1,238 +0,0 @@
-#!groovy
-
-// Copyright 2017 Open Networking Foundation (ONF)
-//
-// Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
-// the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
-// or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
-//
-//     TestON is free software: you can redistribute it and/or modify
-//     it under the terms of the GNU General Public License as published by
-//     the Free Software Foundation, either version 2 of the License, or
-//     (at your option) any later version.
-//
-//     TestON is distributed in the hope that it will be useful,
-//     but WITHOUT ANY WARRANTY; without even the implied warranty of
-//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//     GNU General Public License for more details.
-//
-//     You should have received a copy of the GNU General Public License
-//     along with TestON.  If not, see <http://www.gnu.org/licenses/>.
-
-// This is the dependency Jenkins script.
-// This will provide the portion that will set up the environment of the machine
-//      and trigger the corresponding jobs.
-
-import groovy.time.TimeCategory
-import groovy.time.TimeDuration
-
-test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' )
-test_list.init()
-
-def printDaysForTest(){
-    // Print the days for what test has.
-    AllTheTests = test_list.getAllTests()
-
-    result = ""
-    for ( String test in AllTheTests.keySet() ){
-        result += test + ": ["
-        test_schedule = AllTheTests[ test ][ "schedules" ]
-        for ( String sch_dict in test_schedule ){
-            for ( String day in test_list.convertScheduleKeyToDays( sch_dict[ "branch" ] ) ){
-                result += day + " "
-            }
-        }
-        result += "]\n"
-    }
-    return result
-}
-
-def trigger( branch, tests, nodeLabel, jobOn, manuallyRun, onosTag ){
-    // triggering function that will setup the environment and determine which pipeline to trigger
-
-    println "Job name: " + jobOn + "-pipeline-" + ( manuallyRun ? "manually" : branch )
-    def wiki = branch
-    def onos_branch = test_list.addPrefixToBranch( branch )
-    def test_branch = test_list.addPrefixToBranch( branch )
-    println "onos_branch with prefix: " + onos_branch
-    println "test_branch with prefix: " + test_branch
-    assignedNode = null
-    node( label: nodeLabel ) {
-        envSetup( onos_branch, test_branch, onosTag, jobOn, manuallyRun )
-        exportEnvProperty( onos_branch, test_branch, jobOn, wiki, tests, post_result, manuallyRun, onosTag, isOldFlow, nodeLabel )
-        assignedNode = env.NODE_NAME
-    }
-
-    jobToRun = jobOn + "-pipeline-" + ( manuallyRun ? "manually" : wiki )
-    build job: jobToRun, propagate: false, parameters: [ [ $class: 'StringParameterValue', name: 'Category', value: jobOn ],
-                                                         [ $class: 'StringParameterValue', name: 'Branch', value: branch ],
-                                                         [ $class: 'StringParameterValue', name: 'TestStation', value: assignedNode ],
-                                                         [ $class: 'StringParameterValue', name: 'NodeLabel', value: nodeLabel ] ]
-}
-
-def trigger_pipeline( branch, tests, nodeLabel, jobOn, manuallyRun, onosTag ){
-    // nodeLabel : nodeLabel from tests.json
-    // jobOn : "SCPF" or "USECASE" or "FUNC" or "HA"
-    // this will return the function by wrapping them up with return{} to prevent them to be
-    // executed once this function is called to assign to specific variable.
-    return {
-        trigger( branch, tests, nodeLabel, jobOn, manuallyRun, onosTag )
-    }
-}
-
-// export Environment properties.
-def exportEnvProperty( onos_branch, test_branch, jobOn, wiki, tests, postResult, manually_run, onosTag, isOldFlow, nodeLabel ){
-    // export environment properties to the machine.
-
-    filePath = "/var/jenkins/TestONOS-" + jobOn + "-" + onos_branch + ".property"
-
-    stage( "export Property" ) {
-        sh '''
-            echo "ONOSBranch=''' + onos_branch + '''" > ''' + filePath + '''
-            echo "TestONBranch=''' + test_branch + '''" >> ''' + filePath + '''
-            echo "ONOSTag=''' + onosTag + '''" >> ''' + filePath + '''
-            echo "WikiPrefix=''' + wiki + '''" >> ''' + filePath + '''
-            echo "ONOSJAVAOPTS=''' + env.ONOSJAVAOPTS + '''" >> ''' + filePath + '''
-            echo "Tests=''' + tests + '''" >> ''' + filePath + '''
-            echo "postResult=''' + postResult + '''" >> ''' + filePath + '''
-            echo "manualRun=''' + manually_run + '''" >> ''' + filePath + '''
-            echo "isOldFlow=''' + isOldFlow + '''" >> ''' + filePath + '''
-        '''
-    }
-}
-
-// Initialize the environment Setup for the onos and OnosSystemTest
-def envSetup( onos_branch, test_branch, onos_tag, jobOn, manuallyRun ){
-    // to setup the environment using the bash script
-    println "onos_branch is set to " + onos_branch
-    println "test_branch is set to " + test_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 )
-        generateKey()
-    }
-}
-
-def tagCheck( onos_tag, onos_branch ){
-    // check the tag for onos if it is not empty
-
-    result = "git checkout "
-    if ( onos_tag == "" ){
-        //create new local branch
-        result += onos_branch
-    }
-    else {
-        //checkout the tag
-        result += onos_tag
-    }
-    return result
-}
-
-def preSetup( onos_branch, test_branch, onos_tag, isManual ){
-    // pre setup part which will clean up and checkout to corresponding branch.
-
-    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 in case 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
-        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
-        rm -rf buck-out
-        rm -rf bazel-*
-        ''' + tagCheck( onos_tag, onos_branch ) + '''
-        git branch
-        git log -1 --decorate
-        echo -e "\n##### set jvm heap size to 8G #####"
-        echo ${ONOSJAVAOPTS}
-        inserted_line="export JAVA_OPTS=\"\${ONOSJAVAOPTS}\""
-        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 ){
-    // part that will check if it is oldFlow. If so, it will switch to use old flow. Only affected with SCPF.
-
-    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 ){
-    // setup that will build ONOS
-
-    result = ""
-    if ( !isManual ){
-        result = '''echo -e "Installing bazel"
-        cd ~
-        rm -rf ci-management
-        git clone https://gerrit.onosproject.org/ci-management
-        cd ci-management/jjb/onos/
-        export GERRIT_BRANCH="''' + onos_branch + '''"
-        chmod +x install-bazel.sh
-        ./install-bazel.sh
-        bazel --version
-
-        echo -e "\n##### build ONOS skip unit tests ######"
-        cd ~/onos
-        . tools/dev/bash_profile
-        op
-        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 generateKey(){
-    // generate cluster-key of the onos
-
-    try {
-        sh '''
-        #!/bin/bash -l
-        set +e
-        . ~/.bashrc
-        env
-        onos-push-bits-through-proxy
-        onos-gen-cluster-key -f
-        '''
-    } catch ( all ){
-    }
-}
-
-return this