###############################################################################
# Condor Pilot Configuration
#
# This file is used to configure the condor daemons on the remote site as 
# pilot job daemons.
#
# The following parameters will be set at runtime:
#
#  PILOT_LOCAL_DIR - The path to the local directory
#  PILOT_CONDOR_HOST - The condor central manager host/host:port
#  PILOT_WALL_TIME - The runtime of the glidein job in minutes
#  PILOT_WALL_TIME_SECONDS - The runtime of the glidein job in seconds
#  PILOT_IDLE_TIME - The maximum idle time for the glidein in minutes
#  PILOT_IDLE_TIME_SECONDS - The maximum idle time for the glidein in seconds
#  PILOT_SBIN - Path to the condor daemon executables
#  PILOT_DEBUG - The debug level. Default: D_ALWAYS Enabled: D_FULLDEBUG
#  PILOT_LOCK - The path to a node-local dir to use for lock files
#  PILOT_HIGHPORT - The high port number to allow Condor to use
#  PILOT_LOWPORT - The low port number to allow Condor to use
#  PILOT_CCB_ADDRESS - The CCB broker to use.
#
#  NUM_CPUS - The number of CPUs to allocate. This has to be set explicitly.
#
###############################################################################


###############################################################################
# Pool settings
###############################################################################
COLLECTOR_HOST = $(PILOT_CONDOR_HOST)
UID_DOMAIN = $(FULL_HOSTNAME)
FILESYSTEM_DOMAIN = $(FULL_HOSTNAME)
USE_NFS = False
USE_AFS = False
USE_CKPT_SERVER = False

###############################################################################
# Local paths
###############################################################################
LOCAL_DIR = $(PILOT_LOCAL_DIR)

# LOG and EXECUTE are set automatically by the startup script. They can't be
# changed here.
#LOG = $(LOCAL_DIR)/log
#EXECUTE  = $(LOCAL_DIR)/execute

# This should be a non-network file system to prevent problems
LOCK = $(PILOT_LOCK)

###############################################################################
# Security settings
###############################################################################
HOSTALLOW_ADMINISTRATOR = $(FULL_HOSTNAME), $(PILOT_CONDOR_HOST)

###############################################################################
# Pilot job settings
###############################################################################

# This is only checked every UPDATE_INTERVAL seconds, by the way
STARTD_NOCLAIM_SHUTDOWN = $(PILOT_IDLE_TIME_SECONDS)

# Don't count a hyperthreaded CPU as multiple CPUs
COUNT_HYPERTHREAD_CPUS = False

# No need to be nice
JOB_RENICE_INCREMENT = 0

# Creating new sessions and process groups can cause problems with batch 
# schedulers on some systems. Jobs may not get killed properly, for example. 
USE_PROCESS_GROUPS = False

# WARNING: If you specify numCpus when you create the glidein job, then the 
# value for the following variable will be overridden. That's because NUM_CPUS 
# must be defined as an integer, it can't be an expression, so I have to
# set it explicitly in the startup script by setting the _condor_NUM_CPUS 
# environment variable.
#NUM_CPUS = 0

# This will cause the startd to advertise one slot, which can be split up
# automatically into smaller slots. Users specify request_cpus, request_memory,
# and request_disk in their submit script to get an appropriately sized slot.
# However, this feature is terribly crippled. It creates too many situations
# in which starvation occurs. It will create, e.g., a 4-core dynamic slot,
# but it will allow condor to use that slot for single core jobs, which is
# 100% useless. It also allows serial jobs to starve multi-core jobs by 
# fragmenting all the slots. We should not use this.
#SLOT_TYPE_1 = cpus=100%, disk=100%, memory=100%, swap=100%
#SLOT_TYPE_1_PARTITIONABLE = True
#NUM_SLOTS_TYPE_1 = 1
#NUM_SLOTS = 1

# Pass site environment variables to application jobs. This gives Condor jobs
# the same environment you would get when running the job on the grid site
# directly.
JOB_INHERITS_STARTER_ENVIRONMENT = True

###############################################################################
# Daemon settings
###############################################################################
DAEMON_LIST = MASTER, STARTD

SBIN = $(PILOT_SBIN)
# Required for parallel universe
BIN = $(PILOT_SBIN)

ALL_DEBUG = $(PILOT_DEBUG)

MASTER = $(SBIN)/condor_master
MASTER_ADDRESS_FILE = $(LOG)/.master_address
MASTER_LOG = $(LOG)/MasterLog
MASTER_CHECK_NEW_EXEC_INTERVAL = 86400

STARTD = $(SBIN)/condor_startd
STARTD_LOG = $(LOG)/StartdLog

STARTER = $(SBIN)/condor_starter
STARTER_STD = $(SBIN)/condor_starter.std
STARTER_LOG = $(LOG)/StarterLog
STARTER_LIST = STARTER, STARTER_STD

PROCD = $(SBIN)/condor_procd
PROCD_ADDRESS = $(LOG)/.procd_address
PROCD_LOG = $(LOG)/ProcLog
PROCD_MAX_SNAPSHOT_INTERVAL = 60

###############################################################################
# Classads
###############################################################################
START = True
SUSPEND = False
CONTINUE = True
PREEMPT = False
WANT_VACATE = False
WANT_SUSPEND = True
SUSPEND_VANILLA = False
WANT_SUSPEND_VANILLA = True
KILL = False
IsPilot = True
PilotStartTime = DaemonStartTime
PilotRunTime = $(PILOT_WALL_TIME_SECONDS)
PilotStopTime = PilotStartTime+$(PILOT_WALL_TIME_SECONDS)
PilotTimeLeft = PilotStopTime-CurrentTime
PilotJobId = $(PILOT_JOBID)

# Note: This next line assumes the user is running Condor as root.
# If they are not running it as root we need to use:
#    "DedicatedScheduler@user@$(PILOT_CONDOR_HOST)"
# where 'user' the the user ID on the Condor host. Of course we
# don't have that information right now.
DedicatedScheduler = "DedicatedScheduler@$(PILOT_CONDOR_HOST)"

STARTD_ATTRS = IsPilot, START, PilotRunTime, PilotStopTime, PilotTimeLeft, \
               PilotJobId, DedicatedScheduler

MASTER_NAME = pilot_$(PILOT_JOBID)
STARTD_NAME = pilot_$(PILOT_JOBID)

###############################################################################
# Network settings
###############################################################################

# TCP works better in the WAN
UPDATE_COLLECTOR_WITH_TCP = True

# Might as well
BIND_ALL_INTERFACES = True

# Use random numbers here so the glideins don't all hit the collector at 
# the same time. If there are many glideins the collector can get overwhelmed.
UPDATE_INTERVAL = $RANDOM_INTEGER(230, 370)
MASTER_UPDATE_INTERVAL = $RANDOM_INTEGER(230, 370)

# The port range
HIGHPORT = $(PILOT_HIGHPORT)
LOWPORT = $(PILOT_LOWPORT)

# CCB settings
CCB_ADDRESS = $(PILOT_CCB_ADDRESS)
PRIVATE_NETWORK_NAME = $(FULL_HOSTNAME)

