getPaiCommand()

in src/webportal/src/app/job-submission/models/data/mount-directories.js [18:122]


  getPaiCommand() {
    if (isEmpty(this.selectedConfigs)) {
      return [];
    }

    const returnValue = [
      TEAMWISE_DATA_CMD_START,
      AUTO_GENERATE_NOTIFY,
      'apt-get update',
      'umask 000',
    ];

    const serverMountDict = {};

    for (const config of this.selectedConfigs) {
      if (config.mountInfos !== undefined) {
        for (const mountInfo of config.mountInfos) {
          if (mountInfo.server in serverMountDict) {
            serverMountDict[mountInfo.server].push(mountInfo);
          } else {
            serverMountDict[mountInfo.server] = [mountInfo];
          }
        }
      }
    }

    const mountPoints = [];

    for (const spn in serverMountDict) {
      if (!isNil(serverMountDict[spn])) {
        const mountInfos = serverMountDict[spn];
        const server = this.servers.find(item => item.spn === spn);

        if (server !== undefined) {
          const tmpFolder = `/tmp_${spn}_root/`;

          const preCmds = this.generatePreMountCmds(server, tmpFolder);
          if (preCmds !== undefined) {
            for (const preCmd of preCmds) {
              returnValue.push(preCmd);
            }
          }

          // Step1: Mount root folder and make sub directories
          const mountStrs = this.generateMountCmds(
            server,
            tmpFolder,
            '',
            tmpFolder,
          );
          if (mountStrs !== undefined) {
            for (const mountStr of mountStrs) {
              returnValue.push(mountStr);
            }
          }

          for (const mountInfo of mountInfos) {
            // Check duplicated mount points
            if (mountPoints.includes(mountInfo.mountPoint)) {
              throw new Error(
                'Mount point error! More than one mount point [' +
                  mountInfo.mountPoint +
                  ']!',
              );
            } else {
              mountPoints.push(mountInfo.mountPoint);
            }

            // Create folder on server root path
            returnValue.push(`mkdir --parents ${mountInfo.mountPoint}`);
            returnValue.push(
              `mkdir --parents ${this.normalizePath(
                tmpFolder + mountInfo.path,
              )}`,
            );
          }

          const postCmds = this.generatePostMountCmds(server, tmpFolder);
          if (postCmds !== undefined) {
            for (const postCmd of postCmds) {
              returnValue.push(postCmd);
            }
          }

          // Step2: Mount folder for mount infos
          for (const mountInfo of mountInfos) {
            // Mount
            const mountSubStrs = this.generateMountCmds(
              server,
              mountInfo.mountPoint,
              mountInfo.path,
              tmpFolder,
            );
            if (mountSubStrs !== undefined) {
              for (const mountStr of mountSubStrs) {
                returnValue.push(mountStr);
              }
            }
          }
        }
      }
    }
    returnValue.push(TEAMWISE_DATA_CMD_END);
    return returnValue;
  }