#
# @package      hubzero-submit-distributor
# @file         Scripts/tapis2/README
# @copyright    Copyright 2004-2022 The Regents of the University of California.
# @license      http://opensource.org/licenses/MIT MIT
#
# Copyright (c) 2004-2022 The Regents of the University of California.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# HUBzero is a registered trademark of The Regents of the University of California.
#
Install AgavePy

   pip3 install --prefix /usr/local agavepy==1.0.0a10


Make directory to hold tokens

   mkdir -p /var/gridman/.tapis2/SUBMITHOST

Utilities

   TapisAPI.py

   printJsonFile.sh jsonFile

   refreshToken.sh

   resetToken.sh


Monitoring

   python3 jobStat.py


Clients

   listClients.sh

   createClient.sh clientDefinitionFile [responseFile.json]

   deleteClient.sh clientName


Systems

   listSystems.sh

   addSystem.sh definition.json [responseFile.json]

   getSystem.sh systemId [responseFile.json]

   updateSystem.sh definition.json [responseFile.json]

   deleteSystem.sh systemId

   To enable deleted sytem:

      curl -sk -H "Authorization: Bearer $AUTH_TOKEN" -H "Content-Type: application/json" -X PUT --data-binary '{"action": "enable"}' https://api.tacc.utexas.edu/systems/v2/$SYSTEM_ID


Apps

   listApps.sh

   addApp.sh definition.json [responseFile.json]

   getApp.sh appId

   updateApp.sh definition.json [responseFile.json]

   deleteApp.sh appId


Files and Directories

   listFiles.sh systemId relativePath

   removeFile.sh systemId relativePath

   removeDirectory.sh systemId relativePath

   downloadFile.sh systemId relativePath

   uploadFile.sh localFile systemId relativePath

   copyPath.sh systemId srcPath destPath

   movePath.sh systemId srcPath destPath

   makeDirectory.sh systemId srcPath destPath


Jobs

   python3 uploadJobInputs.py systemId instanceToken jobInputTarPath auxiliaryTarFile

   removeJobInputs.sh systemId jobId instanceId

   python3 submitJob.py definition.tapis [responseFile.json]

   listJobs.sh

   getJobHistory.sh jobId [jobHistory.json]

   getJobStatus.sh jobId

   getJob.sh jobId

   deleteJob.sh jobId

   python3 killJob.py jobId

   listJobOutputs.sh jobId

   downloadJobOutputs.sh jobId resultsDirectory

   removeJobArchive.sh systemId jobId instanceId


Create New System:

   - Create and set permissions on system "root" directory

       $ mkdir -p      SCRATCH/Tapis/SUBMITHOST
       $ chmod go-rwsx SCRATCH/Tapis/SUBMITHOST

   - Create Tapis storage system

       $ ./addSystem.sh CLUSTER_storage

   - Create Job related scratch directories

       $ ./makeDirectory.sh SUBMITHOST.storage-CLUSTER / Jobs
       $ ./makeDirectory.sh SUBMITHOST.storage-CLUSTER / JobInputs

   - Create Job archive directory

       $ ./makeDirectory.sh SUBMITHOST.storage-CLUSTER / Archive

   - Upload startup script

       $ ./uploadFile.sh SystemDefinitions/tapisStartupScript.sh SUBMITHOST.storage-CLUSTER /

   - Create Tapis execution systems

       $ ./addSystem.sh CLUSTER_execution
       $ ./addSystem.sh CLUSTER_execution_headnode

   - Create app Deployment directories

       $ ./makeDirectory.sh SUBMITHOST.storage-CLUSTER / Apps/share64/centos7/generic/generic-serial/bin
       $ ./makeDirectory.sh SUBMITHOST.storage-CLUSTER / Apps/share64/centos7/generic/generic-mpi/bin
       $ ./makeDirectory.sh SUBMITHOST.storage-CLUSTER / Apps/share64/centos7/generic/generic-fork/bin

   - Upload app scripts

       $ ./uploadFile.sh AppDefinitions/generic_serial_test.sh \
                         SUBMITHOST.storage-CLUSTER Apps/share64/centos7/generic/generic-serial/bin
       $ ./uploadFile.sh AppDefinitions/generic_serial_wrapper.sh \
                         SUBMITHOST.storage-CLUSTER Apps/share64/centos7/generic/generic-serial/bin
       $ ./uploadFile.sh AppDefinitions/generic_mpi_test.sh \
                         SUBMITHOST.storage-CLUSTER Apps/share64/centos7/generic/generic-mpi/bin
       $ ./uploadFile.sh AppDefinitions/generic_mpi_wrapper.sh \
                         SUBMITHOST.storage-CLUSTER Apps/share64/centos7/generic/generic-mpi/bin
       $ ./uploadFile.sh AppDefinitions/generic_fork_test.sh \
                         SUBMITHOST.storage-CLUSTER Apps/share64/centos7/generic/generic-fork/bin
       $ ./uploadFile.sh AppDefinitions/generic_fork_wrapper.sh \
                         SUBMITHOST.storage-CLUSTER Apps/share64/centos7/generic/generic-fork/bin

   - Create Tapis apps

       $ ./addApp.sh CLUSTER_generic-serial
       $ ./addApp.sh CLUSTER_generic-mpi
       $ ./addApp.sh CLUSTER_generic-fork

