#!/bin/bash

set -e
set -v

if [ X${testdir} = "X" ]; then
    testdir=`dirname  $0`
    export testdir
fi

TOPDIR=`pwd`

# generate the input file
echo "This is sample input to KEG" > f.a

# output directory
mkdir -p outputs

# build the dax generator
export PYTHONPATH=`pegasus-config --python`
$testdir/blackdiamond.py /usr > blackdiamond.dax

# create the site catalog
cat > sites.xml <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<sitecatalog xmlns="http://pegasus.isi.edu/schema/sitecatalog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pegasus.isi.edu/schema/sitecatalog http://pegasus.isi.edu/schema/sc-3.0.xsd" version="3.0">
    <site  handle="local" arch="x86" os="LINUX">
         <grid type="condor" contact="ccg-testing1.isi.edu" scheduler="Condor" jobtype="compute" total-nodes="50"/>
         <grid type="condor" contact="ccg-testing1.isi.edu" scheduler="Condor" jobtype="auxillary" total-nodes="50"/>
        <head-fs>
              <scratch>                                                                                                                                                                                                                                    <shared>                                                                                                                                                                                                                                    <file-server protocol="file" url="file://" mount-point="/nfs/ccg4/scratch-purge-no-backups"/>                                                                                                                                                            <internal-mount-point mount-point="/nfs/ccg4/scratch-purge-no-backups"/>                                                                                                                                                                             </shared>                                                                                                                                                                                                                           </scratch>                                                                                                                                                                                                                              <storage>                                                                                                                                                                                                                                   <shared>                                                                                                                                                                                                                                    <file-server protocol="file" url="file://" mount-point="/nfs/ccg4/scratch-purge-no-backups/bamboo/outputs"/>                                                                                                                                             <internal-mount-point mount-point="/nfs/ccg4/scratch-purge-no-backups/bamboo/outputs"/>                                                                                                                                                              </shared>                                                                                                                                                                                                                           </storage> 
        </head-fs>
       
             <profile namespace="pegasus" key="style">condor</profile>
        <profile namespace="condor" key="getenv">True</profile>
        <profile namespace="condor" key="requirements">(TARGET.FileSystemDomain =!= &quot;&quot;)</profile>
    </site>

     <site handle="CCG" arch="x86" os="LINUX">


        <head-fs>
            <scratch>
                <shared>
                    <file-server protocol="file" url="file://" mount-point="/nfs/ccg4/scratch-purge-no-backups"/>
                    <internal-mount-point mount-point="/nfs/ccg4/scratch-purge-no-backups"/>
                </shared>
            </scratch>
            <storage>
                <shared>
                    <file-server protocol="file" url="file://" mount-point="/nfs/ccg4/scratch-purge-no-backups/bamboo/outputs"/>
                    <internal-mount-point mount-point="/nfs/ccg4/scratch-purge-no-backups/bamboo/outputs"/>
                </shared>
            </storage>
        </head-fs>
        <replica-catalog type="LRC" url="rlsn://dummyValue.url.edu" />
        <profile namespace="pegasus" key="style">condor</profile>
        <profile namespace="condor" key="getenv">True</profile>
        <profile namespace="condor" key="requirements">(TARGET.FileSystemDomain =!= &quot;&quot;)</profile>

    </site>

</sitecatalog>
EOF

# plan and submit the  workflow
pegasus-plan \
    --conf $testdir/pegasusrc \
    --sites local \
    --output-site local \
    --dir work \
    --cleanup leaf \
    --cluster horizontal \
    --dax blackdiamond.dax \
    -vvvv \
    --submit | tee plan.out

