#!/bin/bash

set -e

TOPDIR=`pwd`

# figure out where Pegasus is installed
export PEGASUS_HOME=`which pegasus-plan | sed 's:/bin/pegasus-plan::'`
if [ "x$PEGASUS_HOME" = "x" ]; then
    echo "Unable to determine location of your Pegasus install"
    echo "Please make sure pegasus-plan is in your path"
    exit 1
fi 


# geneate the input file
echo "This is sample input file" >f.a

# generate the dax
export PYTHONPATH=$PEGASUS_HOME/lib/python
./blackdiamond.py $PEGASUS_HOME >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_64" os="LINUX">
        <grid  type="gt2" contact="localhost/jobmanager-fork" scheduler="Fork" jobtype="auxillary"/>
        <grid  type="gt2" contact="localhost/jobmanager-fork" scheduler="Fork" jobtype="compute"/>
        <head-fs>
            <scratch>
                <shared>
                    <file-server protocol="file" url="file://" mount-point="$TOPDIR/outputs"/>
                    <internal-mount-point mount-point="$TOPDIR/outputs" free-size="100G" total-size="30G"/>
                </shared>
            </scratch>
            <storage>
                <shared>
                    <file-server protocol="file" url="file://" mount-point="$TOPDIR/outputs"/>
                    <internal-mount-point mount-point="$TOPDIR/outputs" free-size="100G" total-size="30G"/>
                </shared>
            </storage>
        </head-fs>
        <replica-catalog  type="LRC" url="rlsn://dummyValue.url.edu" />
        <profile namespace="env" key="PEGASUS_HOME" >$PEGASUS_HOME</profile>
    </site>
</sitecatalog>
EOF

# plan and submit the  workflow
pegasus-plan \
    --conf pegasusrc \
    --sites local \
    --dir work \
    --output local \
    --dax blackdiamond.dax \
    --submit


