umbrella
index
/private/var/condor/execute/dir_27339/condor_exec.exe.27342/cctools-c3f12736-source/umbrella/src/umbrella.py

Umbrella is a tool for specifying and materializing comprehensive execution environments, from the hardware all the way up to software and data.  A user simply invokes Umbrella with the desired task, and Umbrella determines the minimum mechanism necessary to run the task, whether it be direct execution, a system container, a local virtual machine, or submission to a cloud or grid environment.  We present the overall design of Umbrella and demonstrate its use to precisely execute a high energy physics application and a ray-tracing application across many platforms using a combination of Parrot, Chroot, Docker, VMware, Condor, and Amazon EC2.
 
Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
Copyright (C) 2005- The University of Notre Dame
This software is distributed under the GNU General Public License.
See the file COPYING for details.
 
Implementation Logics of Different Execution Engines:
        If the sandbox type is Parrot, create the mountlist file and set PARROT_MOUNT_FILE; set PATH; set PARROT_LDSO_PATH if a separate OS image is needed; parrotize the user's command into `parrot_run user_cmd`.
        If the sandbox type is Docker, transfer the OS image into a Docker image; use volume to mount all the software and data dependencies into a container; set PATH; dockerize the user's command into `docker run user_cmd`. To use Docker, a separate OS image is needed.
        If the sandbox type is chroot, create mountpoints for software and data dependencies inside the OS image directory and mount software and data into the OS image, set PATH, chrootize the user's command into `chroot user_cmd`.
 
Implementation Logic of Dependency Sources:
        HTTP/HTTPS: Download the dependency into Umbrella local cache.
        CVMFS: check whether the mountpoint already exists on the execution node, if yes, do not need to set mountpoint for this dependency and directly process the next dependency; if no, parrot will be used to deliver cvmfs for the application.
                If Parrot is needed to access cvmfs, and the sandbox type is Parrot,
                        Do all the work mentioned above for Parrot execution engine + add SITEINFO into mountlist file.
                If Parrot is needed to access cvmfs, and the sandbox type is Docker,
                        Do all the work mentioned above for Docker execution engine + add SITEINFO into mountlist file + parrotize the user's command. First parrotize the user's command, then dockerize the user's command.
                If Parrot is needed to access cvmfs, and the sandbox type is chroot,
                        Do all the work mentioned above for chroot execution engine + add SITEINFO into mountlist file + parrotize the user's command. First parrotize the user's command, then chrootize the user's command.
        ROOT: do nothing if a ROOT file through ROOT protocol is needed, because ROOT supports data access during runtime without downloading first.
 
mount_env and mountpoint:
If only mountpoint is set to A in a specification, the dependency will be downloaded into the umbrella local cache with the file path of D, and a new mountpoint will be added into mount_dict (mount_dict[A] = D).
If only mount_env is set to B in a specification, the dependency will not be downloaded, package_search will be executed to get one remote storage location, C, of the dependency, a new environment variable will be set (env_para_dict[B] = C).
If mountpoint is set to A and mount_env is set to B in a specification, the dependency will be downloaded into the umbrella local cache with the file path of D, and a new mountpoint will be added into mount_dict (mount_dict[A] = D) and a new environment variable will also be set (env_para_dict[B] = A).

 
Modules
       
StringIO
datetime
difflib
getpass
grp
hashlib
json
logging
multiprocessing
os
platform
re
resource
shutil
sqlite3
subprocess
sys
tarfile
tempfile
time
urllib2
urlparse

 
Functions
       
cctools_download(sandbox_dir, packages_json, hardware_platform, linux_distro, action)
Download cctools
 
Args:
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        packages_json: the json object including all the metadata of dependencies.
        hardware_platform: the architecture of the required hardware platform (e.g., x86_64).
        linux_distro: the linux distro.  For Example: redhat6, centos6.
        action: the action on the downloaded dependency. Options: none, unpack. "none" leaves the downloaded dependency at it is. "unpack" uncompresses the dependency.
 
Returns:
        the path of the downloaded cctools in the umbrella local cache. For example: /tmp/umbrella_test/cache/d19376d92daa129ff736f75247b79ec8/cctools-4.9.0-redhat6-x86_64
check_cvmfs_repo(repo_name)
Check whether a cvmfs repo is installed on the host or not
 
Args:
        repo_name: a cvmfs repo name. For example: "/cvmfs/cms.cern.ch".
 
Returns:
        If the cvmfs repo is installed,  returns the string including the mountpoint of cvmfs cms repo. For example: "/cvmfs/cms.cern.ch".
        Otherwise, return an empty string.
chroot_mount_bind(dir_dict, file_dict, sandbox_dir, need_separate_rootfs, hardware_platform, distro_name, distro_version)
Create each target mountpoint under the cached os image directory through `mount --bind`.
 
Args:
        dir_dict: a dict including all the directory mountpoints needed to be created inside the OS image.
        file_dict: a dict including all the file mountpoints needed to be created inside the OS image.
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        need_separate_rootfs: whether a separate rootfs is needed to execute the user's command.
        hardware_platform: the architecture of the required hardware platform (e.g., x86_64).
        distro_name: the name of the required OS (e.g., redhat).
        distro_version: the version of the required OS (e.g., 6.5).
 
Returns:
        If no error happens, returns None.
        Otherwise, directly exit.
chroot_post_process(dir_dict, file_dict, sandbox_dir, need_separate_rootfs, hardware_platform, distro_name, distro_version)
Remove all the created target mountpoints within the cached os image directory.
It is not necessary to change the mode of the output dir, because only the root user can use the chroot method.
 
Args:
        dir_dict: a dict including all the directory mountpoints needed to be created inside the OS image.
        file_dict: a dict including all the file mountpoints needed to be created inside the OS image.
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        need_separate_rootfs: whether a separate rootfs is needed to execute the user's command.
        hardware_platform: the architecture of the required hardware platform (e.g., x86_64).
        distro_name: the name of the required OS (e.g., redhat).
        distro_version: the version of the required OS (e.g., 6.5).
 
Returns:
        If no error happens, returns None.
        Otherwise, directly exit.
chrootize_user_cmd(user_cmd, cwd_setting)
Modify the user's command when the sandbox_mode is chroot. This check should be done after `parrotize_user_cmd`.
The cases when this function should be called: sandbox_mode == chroot
 
Args:
        user_cmd: the user's command.
        cwd_setting: the current working directory for the execution of the user's command.
 
Returns:
        the modified version of the user's cmd.
collect_software_bin(host_cctools_path, sw_mount_dict)
Construct the path environment from the mountpoints of software dependencies.
Each softare package has a bin subdir containing all its executables.
 
Args:
        host_cctools_path: the path of cctools under the umbrella local cache.
        sw_mount_dict: a dict only including all the software mounting items.
 
Returns:
        extra_path: the paths which are extracted from sw_mount_dict and host_cctools_path, and needed to be added into PATH.
compare_versions(v1, v2)
Compare two versions, the format of version is: X.X.X
 
Args:
        v1: a version.
        v2: a version.
 
Returns:
        0 if v1 == v2; 1 if v1 is newer than v2; -1 if v1 is older than v2.
condor_process(spec_path, spec_json, spec_path_basename, packages_path, sandbox_dir, output_dir, input_list_origin, user_cmd, cwd_setting, condorlog_path, cvmfs_http_proxy)
Process the specification when condor execution engine is chosen
 
Args:
        spec_path: the absolute path of the specification.
        spec_json: the json object including the specification.
        spec_path_basename: the file name of the specification.
        packages_path: the path of the json file including all the metadata information.
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        output_dir: the output directory.
        input_list_origin: the list of input file paths.
        user_cmd: the user's command.
        cwd_setting: the current working directory for the execution of the user's command.
        condorlog_path: the path of the umbrella log executed on the remote condor execution node.
        cvmfs_http_proxy: HTTP_PROXY environmetn variable used to access CVMFS by Parrot
 
Returns:
        If no errors happen, return None;
        Otherwise, directly exit.
construct_chroot_mount_dict(sandbox_dir, output_dir, input_dict, need_separate_rootfs, os_image_dir, mount_dict, host_cctools_path)
Construct directory mount list and file mount list for chroot. chroot requires the target mountpoint must be created within the chroot jail.
 
Args:
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        output_dir: the output directory.
        input_dict: the setting of input files specified by the --inputs option.
        need_separate_rootfs: whether a separate rootfs is needed to execute the user's command.
        os_image_dir: the path of the OS image inside the umbrella local cache.
        mount_dict: a dict including each mounting item in the specification, whose key is the access path used by the user's task; whose value is the actual storage path.
        host_cctools_path: the path of cctools under the umbrella local cache.
 
Returns:
        a tuple includes the directory mount list and the file mount list
construct_docker_volume(input_dict, mount_dict)
Construct the docker volume parameters based on mount_dict.
 
Args:
        input_dict: the setting of input files specified by the --inputs option.
        mount_dict: a dict including each mounting item in the specification, whose key is the access path used by the user's task; whose value is the actual storage path.
 
Returns:
        volume_paras: all the `-v` options for the docker command.
construct_env(sandbox_dir, os_image_dir)
Read env_list inside an OS image and save all the environment variables into a dictionary.
 
Args:
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        os_image_dir: the path of the OS image inside the umbrella local cache.
 
Returns:
        env_dict: a dictionary which includes all the environment variables from env_list
construct_mountfile_cvmfs_cms_siteconf(sandbox_dir, cvmfs_cms_siteconf_mountpoint)
Create the mountfile if chroot and docker is used to execute a CMS application and the host machine does not have cvmfs installed.
 
Args:
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        cvmfs_cms_siteconf_mountpoint: a string in the format of '/cvmfs/cms.cern.ch/SITECONF/local <SITEINFO dir in the umbrella local cache>/local'
 
Returns:
        the path of the mountfile.
construct_mountfile_easy(sandbox_dir, input_dict, mount_dict, cvmfs_cms_siteconf_mountpoint)
Create the mountfile if parrot is used to create a sandbox for the application and a separate rootfs is not needed.
The trick here is the adding sequence does matter. The latter-added items will be checked first during the execution.
 
Args:
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        mount_dict: all the mount items extracted from the specification file and possible implicit dependencies like cctools.
        input_dict: the setting of input files specified by the --inputs option
        cvmfs_cms_siteconf_mountpoint: a string in the format of '/cvmfs/cms.cern.ch/SITECONF/local <SITEINFO dir in the umbrella local cache>/local'
 
Returns:
        the path of the mountfile.
construct_mountfile_full(sandbox_dir, os_image_dir, mount_dict, input_dict, cvmfs_cms_siteconf_mountpoint)
Create the mountfile if parrot is used to create a sandbox for the application and a separate rootfs is needed.
The trick here is the adding sequence does matter. The latter-added items will be checked first during the execution.
 
Args:
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        os_image_dir: the path of the OS image inside the umbrella local cache.
        mount_dict: all the mount items extracted from the specification file and possible implicit dependencies like cctools.
        input_dict: the setting of input files specified by the --inputs option
        cvmfs_cms_siteconf_mountpoint: a string in the format of '/cvmfs/cms.cern.ch/SITECONF/local <SITEINFO dir in the umbrella local cache>/local'
 
Returns:
        the path of the mountfile.
create_docker_image(sandbox_dir, hardware_platform, distro_name, distro_version, packages)
Create a docker image based on the cached os image directory.
 
Returns:
        If the docker image is imported from the tarball successfully, returns None.
        Otherwise, directly exit.
create_fake_mount(os_image_dir, sandbox_dir, mount_list, path)
For each ancestor dir B of path (including path iteself), check whether it exists in the rootfs and whether it exists in the mount_list and
whether it exists in the fake_mount directory inside the sandbox.
If B is inside the rootfs or the fake_mount dir, do nothing. Otherwise, create a fake directory inside the fake_mount.
Reason: the reason why we need to guarantee any ancestor dir of a path exists somehow is that `cd` shell builtin does a syscall stat on each level of
the ancestor dir of a path. Without creating the mountpoint for any ancestor dir, `cd` would fail.
 
Args:
        os_image_dir: the path of the OS image inside the umbrella local cache.
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        mount_list: a list of mountpoints which already been inside the parrot mountlist file.
        path: a dir path.
 
Returns:
        mount_str: a string including the mount items which are needed to added into the parrot mount file.
data_dependency_process(name, id, packages_json, sandbox_dir, action)
Download a data dependency
 
Args:
        name: the item name in the data section
        id: the id attribute of the processed dependency
        packages_json: the json object including all the metadata of dependencies.
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        action: the action on the downloaded dependency. Options: none, unpack. "none" leaves the downloaded dependency at it is. "unpack" uncompresses the dependency.
 
Returns:
        the path of the downloaded data dependency in the umbrella local cache.
data_install(data_spec, packages_json, sandbox_dir, mount_dict, env_para_dict)
Process data section of the specification.
At the beginning of the function, mount_dict only includes items for software and os dependencies. After this function is done, all the items for data dependencies will be added into mount_dict.
 
Args:
        data_spec: the data section of the specification.
        packages_json: the json object including all the metadata of dependencies.
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        mount_dict: a dict including each mounting item in the specification, whose key is the access path used by the user's task; whose value is the actual storage path.
        env_para_dict: the environment variables which need to be set for the execution of the user's command.
 
Returns:
        mount_dict: the modified mount_dict with all the new mountpoints for data dependencies.
        env_para_dict: the environment variables which need to be set for the execution of the user's command.
decide_instance_type(cpu_cores, memory_size, disk_size, instances)
Compare the required hardware configurations with each instance type, and return the first matched instance type, return 'no' if no matched instance type exist.
We can rank each instance type in the future, so that in the case of multiple matches exit, the closest matched instance type is returned.
 
Args:
        cpu_cores: the number of required  cpus (e.g., 1).
        memory_size: the memory size requirement (e.g., 2GB). Not case sensitive.
        disk_size: the disk size requirement (e.g., 2GB). Not case sensitive.
        instances: the instances section of the ec2 json file.
 
Returns:
        If there is no matched instance type, return 'no'.
        Otherwise, returns the first matched instance type.
dependency_check(item)
Check whether an executable exists or not.
 
Args:
        item: the name of the executable to be found.
 
Returns:
        If the executable can be found through $PATH, return 0;
        Otherwise, return -1.
dependency_download(url, checksum, checksum_tool, dest, format_remote_storage, action)
Download a dependency from the url and verify its integrity.
 
Args:
        url: the storage location of the dependency.
        checksum: the checksum of the dependency.
        checksum_tool: the tool used to calculate the checksum, such as md5sum.
        dest: the destination of the dependency where the downloaded dependency will be put.
        format_remote_storage: the file format of the dependency, such as .tgz.
        action: the action on the downloaded dependency. Options: none, unpack. "none" leaves the downloaded dependency at it is. "unpack" uncompresses the dependency.
 
Returns:
        If the url is a broken link or the integrity of the downloaded data is bad, directly exit.
        Otherwise, return None.
dependency_process(name, id, action, packages_json, sandbox_dir, sandbox_mode, user_cmd, cwd_setting, hardware_platform, host_linux_distro, linux_distro, cvmfs_http_proxy)
Process each explicit and implicit dependency.
 
Args:
        name: the item name in the software section
        id: the id attribute of the processed dependency
        action: the action on the downloaded dependency. Options: none, unpack. "none" leaves the downloaded dependency at it is. "unpack" uncompresses the dependency.
        os_id: the id attribute of the required OS.
        packages_json: the json object including all the metadata of dependencies.
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        sandbox_mode: the execution engine.
        user_cmd: the user's command.
        cwd_setting: the current working directory for the execution of the user's command.
        hardware_platform: the architecture of the required hardware platform (e.g., x86_64).
        host_linux_distro: the linux distro of the host machine. For Example: redhat6, centos6.
        linux_distro: the linux distro of the required OS. For Example: redhat6, centos6.
        cvmfs_http_proxy: HTTP_PROXY environmetn variable used to access CVMFS by Parrot
 
Returns:
        is_cms_cvmfs_app: whether this is a cms app which will be delivered by cmvfs and the local machine has no cvmfs installed. 1 means this is a cms app. 0 means this is not.
        cvmfs_cms_siteconf_mountpoint: a string in the format of '/cvmfs/cms.cern.ch/SITECONF/local <SITEINFO dir in the umbrella local cache>/local'
        mount_value: the actual storage path of one dependency.
        local_cvmfs: the mountpoint of the local-installed cvmfs (e.g., /cvmfs).
ec2_process(spec_path, spec_json, packages_path, packages_json, ec2_path, ec2_json, ssh_key, ec2_key_pair, ec2_security_group, sandbox_dir, output_dir, sandbox_mode, input_list, input_list_origin, env_options, user_cmd, cwd_setting, ec2log_path, cvmfs_http_proxy)
Args:
        spec_path: the path of the specification.
        spec_json: the json object including the specification.
        packages_path: the path of the json file including all the metadata information.
        packages_json: the json object including all the metadata of dependencies.
        ec2_path: the path of the json file including all infomration about the ec2 AMIs and instance types.
        ec2_json: the json object corresponding to ec2_path.
        ssh_key: the name the private key file to use when connecting to an instance.
        ec2_key_pair: the path of the key-pair to use when launching an instance.
        ec2_security_group: the security group within which the EC2 instance should be run.
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        output_dir: the output directory.
        sandbox_mode: the execution engine.
        input_list: a list including all the absolute path of the input files on the local machine.
        input_list_origin: the list of input file paths.
        env_options: the original `--env` option.
        user_cmd: the user's command.
        cwd_setting: the current working directory for the execution of the user's command.
        ec2log_path: the path of the umbrella log executed on the remote EC2 execution node.
        cvmfs_http_proxy: HTTP_PROXY environmetn variable used to access CVMFS by Parrot
 
Returns:
        If no errors happen, return None;
        Otherwise, directly exit.
env_check(sandbox_dir, sandbox_mode, hardware_platform, cpu_cores, memory_size, disk_size, kernel_name, kernel_version)
Check the matching degree between the specification requirement and the host machine.
Currently check the following item: sandbox_mode, hardware platform, kernel, OS, disk, memory, cpu cores.
Other things needed to check: software, and data??
 
Args:
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        sandbox_mode: the execution engine.
        hardware_platform: the architecture of the required hardware platform (e.g., x86_64).
        cpu_cores: the number of required  cpus (e.g., 1).
        memory_size: the memory size requirement (e.g., 2GB). Not case sensitive.
        disk_size: the disk size requirement (e.g., 2GB). Not case sensitive.
        kernel_name: the name of the required OS kernel (e.g., linux). Not case sensitive.
        kernel_version: the version of the required kernel (e.g., 2.6.18).
 
Returns:
        host_linux_distro: the linux distro of the host machine. For Example: redhat6, centos6.
env_parameter_init(hardware_spec, kernel_spec, os_spec)
Set the environment parameters according to the specification file.
 
Args:
        hardware_spec: the hardware section in the specification for the user's task.
        kernel_spec: the kernel section in the specification for the user's task.
        os_spec: the os section in the specification for the user's task.
 
Returns:
        a tuple including the requirements for hardware, kernel and os.
func_call(cmd)
Execute a command and return the return code, stdout, stderr.
 
Args:
        cmd: the command needs to execute using the subprocess module.
 
Returns:
        a tuple including the return code, stdout, stderr.
func_call_withenv(cmd, env_dict)
Execute a command with a special setting of the environment variables and return the return code, stdout, stderr.
 
Args:
        cmd: the command needs to execute using the subprocess module.
        env_dict: the environment setting.
 
Returns:
        a tuple including the return code, stdout, stderr.
get_instance_id(image_id, instance_type, ec2_key_pair, ec2_security_group)
Start one VM instance through Amazon EC2 command line interface and return the instance id.
 
Args:
        image_id: the Amazon Image Identifier.
        instance_type: the Amazon EC2 instance type used for the task.
        ec2_key_pair: the path of the key-pair to use when launching an instance.
        ec2_security_group: the security group within which the EC2 instance should be run.
 
Returns:
        If no error happens, returns the id of the started instance.
        Otherwise, directly exit.
get_linker_path(hardware_platform, os_image_dir)
Return the path of ld-linux.so within the downloaded os image dependency
 
Args:
        hardware_platform: the architecture of the required hardware platform (e.g., x86_64).
        os_image_dir: the path of the OS image inside the umbrella local cache.
 
Returns:
        If the dynamic linker is found within the OS image, return its fullpath.
        Otherwise, returns None.
get_public_dns(instance_id)
Get the public dns of one VM instance from Amazon EC2.
`ec2-run-instances` can not directly return the public dns of the instance, so this function is needed to check the result of `ec2-describe-instances` to obtain the public dns of the instance.
 
Args:
        instance_id: the id of the VM instance.
 
Returns:
        If no error happens, returns the public dns of the instance.
        Otherwise, directly exit.
has_docker_image(hardware_platform, distro_name, distro_version)
Check whether the required docker image exists on the local machine or not.
 
Args:
        hardware_platform: the architecture of the required hardware platform (e.g., x86_64).
        distro_name: the name of the required OS (e.g., redhat).
        distro_version: the version of the required OS (e.g., 6.5).
 
Returns:
        If the required docker image exists on the local machine, returns 'yes'.
        Otherwise, returns 'no'.
in_local_group()
Judge whether the current user's group exists in /etc/group.
 
Returns:
        If the current user's group exists in /etc/group, returns 'yes'.
        Otherwise, returns 'no'.
in_local_passwd()
Judge whether the current user exists in /etc/passwd.
 
Returns:
        If the current user is inside /etc/passwd, returns 'yes'.
        Otherwise, returns 'no'.
main()
md5_cal(filename, block_size=1048576)
Calculate the md5sum of a file
 
Args:
        filename: the name of the file
        block_size: the size of each block
 
Returns:
        If the calculation fails for any reason, directly exit.
        Otherwise, return the md5 value of the content of the file
obtain_path(os_image_dir, sw_mount_dict)
Get the path environment variable from envfile and add the mountpoints of software dependencies into it
the envfile here is named env_list under the OS image.
 
Args:
 
        os_image_dir: the path of the OS image inside the umbrella local cache.
        sw_mount_dict: a dict only including all the software mounting items.
 
Returns:
        path_env: the new value for PATH.
package_search(packages_json, name, id=None)
Search the metadata information of an dependency in the packages_json
First find all the items with the required name in packages_json.
Then find the right one whose id satisfied the requirement.
If no id parameter is problem, then the first matched one will be returned.
 
Args:
        packages_json: the json object including all the metadata of dependencies.
        name: the name of the dependency.
        id: the id attribute of the dependency. Defaults to None.
 
Returns:
        If one item is found in packages_json, return the item, which is a dictionary.
        If no item satisfied the requirement on packages_json, directly exit.
parrotize_user_cmd(user_cmd, sandbox_dir, cwd_setting, linux_distro, hardware_platform, packages_json, cvmfs_http_proxy)
Modify the user's command into `parrot_run + the user's command`.
The cases when this function should be called: (1) sandbox_mode == parrot; (2) sandbox_mode != parrot and cvmfs is needed to deliver some dependencies not installed on the execution node.
 
Args:
        user_cmd: the user's command.
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        cwd_setting: the current working directory for the execution of the user's command.
        hardware_platform: the architecture of the required hardware platform (e.g., x86_64).
        linux_distro: the linux distro. For Example: redhat6, centos6.
        packages_json: the json object including all the metadata of dependencies.
        cvmfs_http_proxy: HTTP_PROXY environmetn variable used to access CVMFS by Parrot
 
Returns:
        the modified version of the user's cmd.
remove_trailing_slashes(path)
Remove the trailing slashes of a string
 
Args:
        path: a path, which can be any string.
 
Returns:
        path: the new path without any trailing slashes.
set_cvmfs_cms_siteconf(name, action, packages_json, sandbox_dir)
Download cvmfs SITEINFO and set its mountpoint.
 
Args:
        name: the name of the cmvfs SITEINFO package in packages_json.
        action: the action on the downloaded dependency. Options: none, unpack. "none" leaves the downloaded dependency at it is. "unpack" uncompresses the dependency.
        packages_json: the json object including all the metadata of dependencies.
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
 
Returns:
        cvmfs_cms_siteconf_mountpoint: a string in the format of '/cvmfs/cms.cern.ch/SITECONF/local <SITEINFO dir in the umbrella local cache>/local'
software_install(env_para_dict, os_id, software_spec, packages_json, sandbox_dir, sandbox_mode, user_cmd, cwd_setting, hardware_platform, host_linux_distro, linux_distro, distro_name, distro_version, need_separate_rootfs, cvmfs_http_proxy)
Installation each software dependency specified in the software section of the specification.
If the application is a CMS app and the execution node does not have cvmfs installed, change `user_cmd` to `parrot_run ... user_cmd` and cvmfs_cms_siteconf_mountpoint.
 
Args:
        env_para_dict: the environment variables which need to be set for the execution of the user's command.
        os_id: the id attribute of the required OS.
        software_spec: the software section of the specification
        packages_json: the json object including all the metadata of dependencies.
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        sandbox_mode: the execution engine.
        user_cmd: the user's command.
        cwd_setting: the current working directory for the execution of the user's command.
        hardware_platform: the architecture of the required hardware platform (e.g., x86_64).
        host_linux_distro: the linux distro of the host machine. For Example: redhat6, centos6.
        linux_distro: the linux distro of the required OS. For Example: redhat6, centos6.
        distro_name: the name of the required OS (e.g., redhat).
        distro_version: the version of the required OS (e.g., 6.5).
        need_separate_rootfs: whether a separate rootfs is needed to execute the user's command.
        cvmfs_http_proxy: HTTP_PROXY environmetn variable used to access CVMFS by Parrot
 
Returns:
        host_cctools_path: the path of cctools under the umbrella local cache.
        cvmfs_cms_siteconf_mountpoint: a string in the format of '/cvmfs/cms.cern.ch/SITECONF/local <SITEINFO dir in the umbrella local cache>/local'
        mount_dict: a dict including each mounting item in the specification, whose key is the access path used by the user's task; whose value is the actual storage path.
        env_para_dict: the environment variables which need to be set for the execution of the user's command.
specification_process(spec_json, sandbox_dir, behavior, packages_json, sandbox_mode, output_dir, input_dict, env_para_dict, user_cmd, cwd_setting, cvmfs_http_proxy)
Create the execution environment specified in the specification file and run the task on it.
 
Args:
        spec_json: the json object including the specification.
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        behavior: the umbrella behavior, such as `run`.
        packages_json: the json object including all the metadata of dependencies.
        sandbox_mode: the execution engine.
        output_dir: the output directory.
        input_dict: the setting of input files specified by the --inputs option.
        env_para_dict: the environment variables which need to be set for the execution of the user's command.
        user_cmd: the user's command.
        cwd_setting: the current working directory for the execution of the user's command.
        cvmfs_http_proxy: HTTP_PROXY environmetn variable used to access CVMFS by Parrot
 
Returns:
        None.
subprocess_error(cmd, rc, stdout, stderr)
Print the command, return code, stdout, and stderr; and then directly exit.
 
Args:
        cmd: the executed command.
        rc: the return code.
        stdout: the standard output of the command.
        stderr: standard error of the command.
 
Returns:
        directly exit the program.
terminate_instance(instance_id)
Terminate an instance.
 
Args:
        instance_id: the id of the VM instance.
 
Returns:
        None.
transfer_env_para_docker(env_para_dict)
Transfer the env_para_dict into the docker `-e` options.
 
Args:
        env_para_dict: the environment variables which need to be set for the execution of the user's command.
 
Returns:
        env_options: the docker `-e` options constructed from env_para_dict.
url_download(url, dest)
Download url into dest
 
Args:
        url: the url needed to be downloaded.
        dest: the path where the content from the url should be put.
 
Returns:
        If the url is downloaded successfully, return None;
        Otherwise, directly exit.
verify_kernel(host_kernel_name, host_kernel_version, kernel_name, kernel_version)
Check whether the kernel version of the host machine matches the requirement.
The kernel_version format supported for now includes: >=2.6.18; [2.6.18, 2.6.32].
 
Args:
        host_kernel_name: the name of the OS kernel of the host machine.
        host_kernel_version: the version of the kernel of the host machine.
        kernel_name: the name of the required OS kernel (e.g., linux). Not case sensitive.
        kernel_version: the version of the required kernel (e.g., 2.6.18).
 
Returns:
        If the kernel version of the host machine matches the requirement, return None.
        If the kernel version of the host machine does not match the requirement, directly exit.
which_exec(name)
The implementation of shell which command
 
Args:
        name: the name of the executable to be found.
 
Returns:
        If the executable is found, returns its fullpath.
        Otherwise, returns None.
workflow_repeat(cwd_setting, sandbox_dir, sandbox_mode, output_dir, input_dict, env_para_dict, user_cmd, hardware_platform, host_linux_distro, distro_name, distro_version, need_separate_rootfs, os_image_dir, host_cctools_path, cvmfs_cms_siteconf_mountpoint, mount_dict, sw_mount_dict, packages_json)
Run user's task with the help of the sandbox techniques, which currently inculde chroot, parrot, docker.
 
Args:
        cwd_setting: the current working directory for the execution of the user's command.
        sandbox_dir: the sandbox dir for temporary files like Parrot mountlist file.
        sandbox_mode: the execution engine.
        output_dir: the output directory.
        input_dict: the setting of input files specified by the --inputs option.
        env_para_dict: the environment variables which need to be set for the execution of the user's command.
        user_cmd: the user's command.
        hardware_platform: the architecture of the required hardware platform (e.g., x86_64).
        distro_name: the name of the required OS (e.g., redhat).
        distro_version: the version of the required OS (e.g., 6.5).
        need_separate_rootfs: whether a separate rootfs is needed to execute the user's command.
        os_image_dir: the path of the OS image inside the umbrella local cache.
        host_cctools_path: the path of cctools under the umbrella local cache.
        cvmfs_cms_siteconf_mountpoint: a string in the format of '/cvmfs/cms.cern.ch/SITECONF/local <SITEINFO dir in the umbrella local cache>/local'
        mount_dict: a dict including each mounting item in the specification, whose key is the access path used by the user's task; whose value is the actual storage path.
        sw_mount_dict: a dict only including all the software mounting items.
        packages_json: the json object including all the metadata of dependencies.
 
Returns:
        If no error happens, returns None.
        Otherwise, directly exit.

 
Data
        SF_APPEND = 262144
SF_ARCHIVED = 65536
SF_IMMUTABLE = 131072
SF_NOUNLINK = 1048576
SF_SNAPSHOT = 2097152
ST_ATIME = 7
ST_CTIME = 9
ST_DEV = 2
ST_GID = 5
ST_INO = 1
ST_MODE = 0
ST_MTIME = 8
ST_NLINK = 3
ST_SIZE = 6
ST_UID = 4
S_ENFMT = 1024
S_IEXEC = 64
S_IFBLK = 24576
S_IFCHR = 8192
S_IFDIR = 16384
S_IFIFO = 4096
S_IFLNK = 40960
S_IFREG = 32768
S_IFSOCK = 49152
S_IREAD = 256
S_IRGRP = 32
S_IROTH = 4
S_IRUSR = 256
S_IRWXG = 56
S_IRWXO = 7
S_IRWXU = 448
S_ISGID = 1024
S_ISUID = 2048
S_ISVTX = 512
S_IWGRP = 16
S_IWOTH = 2
S_IWRITE = 128
S_IWUSR = 128
S_IXGRP = 8
S_IXOTH = 1
S_IXUSR = 64
UF_APPEND = 4
UF_IMMUTABLE = 2
UF_NODUMP = 1
UF_NOUNLINK = 16
UF_OPAQUE = 8