#!/bin/bash

set -e

TOPDIR=`pwd`

# pegasus bin directory is needed to find keg
BIN_DIR=`pegasus-config --bin`

# build the dax generator
PYTHONPATH=`pegasus-config --python`
export PYTHONPATH=".:$PYTHONPATH"

# generate the dax
./local_hierarchy.py > outer.dax

echo "inner.dax $TOPDIR/inner.dax site=local" > rc.data

# 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-4.0.xsd" version="4.0">

    <site  handle="local" arch="x86" os="LINUX">
        <directory type="shared-scratch" path="$TOPDIR/work">
            <file-server operation="all" url="file://$TOPDIR/work"/>
        </directory>
        <directory type="local-storage" path="$TOPDIR/outputs">
            <file-server operation="all" url="file://$TOPDIR/outputs"/>
        </directory>
    </site>

    <site  handle="condorpool" arch="x86" os="LINUX">
        <profile namespace="pegasus" key="style" >condor</profile>
        <profile namespace="condor" key="universe" >vanilla</profile>
    </site>

</sitecatalog>
EOF

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

