public void uploadAlgorithmJar()

in computer-k8s/src/main/java/org/apache/hugegraph/computer/k8s/driver/KubernetesDriver.java [168:223]


    public void uploadAlgorithmJar(String algorithmName, InputStream input) {
        File tempFile = null;
        try {
            Path path = Files.createDirectories(
                        Paths.get(TMP_DIR, UUID.randomUUID().toString()));
            tempFile = File.createTempFile("userAlgorithm", ".jar",
                                           path.toFile());
            FileUtils.copyInputStreamToFile(input, tempFile);

            InputStream bashStream;
            if (StringUtils.isBlank(this.bashPath)) {
                bashStream = this.getClass()
                                 .getResourceAsStream(DEFAULT_PUSH_BASH_PATH);
            } else {
                bashStream = new FileInputStream(this.bashPath);
            }
            String bashAsStr = IOHelpers.readFully(bashStream);

            StringBuilder builder = new StringBuilder();
            builder.append(BUILD_IMAGE_FUNC);
            if (StringUtils.isNotBlank(this.registry)) {
                builder.append(" -r ").append(this.registry);
            }
            if (StringUtils.isNotBlank(this.username)) {
                builder.append(" -u ").append(this.username);
            }
            if (StringUtils.isNotBlank(this.password)) {
                builder.append(" -p ").append(this.password);
            }
            builder.append(" -s ").append(tempFile.getAbsolutePath());
            String jarFile = this.buildJarFile(this.jarFileDir, algorithmName);
            builder.append(" -j ").append(jarFile);
            String imageUrl = this.buildImageUrl(algorithmName);
            builder.append(" -i ").append(imageUrl);
            builder.append(" -f ").append(this.frameworkImageUrl);
            String args = builder.toString();
            String[] command = {"bash", "-c", bashAsStr + "\n" + args};

            Process process = Runtime.getRuntime().exec(command);
            int code = process.waitFor();
            if (code != 0) {
                InputStream errorStream = process.getErrorStream();
                String errorInfo = IOHelpers.readFully(errorStream);
                if (StringUtils.isBlank(errorInfo)) {
                    InputStream stdoutStream = process.getInputStream();
                    errorInfo = IOHelpers.readFully(stdoutStream);
                }
                throw new ComputerDriverException(errorInfo);
            }
        } catch (Throwable exception) {
            throw new ComputerDriverException("Failed to upload algorithm Jar",
                                              exception);
        } finally {
            FileUtils.deleteQuietly(tempFile);
        }
    }