Apache Flink Rest-Client Jar-Upload not working

前端 未结 3 1653
忘了有多久
忘了有多久 2021-01-03 03:23

I am struggling to automatically deploy new Flink jobs within our CI/CD workflows by using the Flink rest-api (which may be found here in the flink Github repository).

相关标签:
3条回答
  • I've run into the same issue and solved it by looking at the network request in chrome when uploading a jar with the web UI.

    The request must

    • Use multipart upload
    • The field name must be jarfile
    • The multi part content must include the file Content-Type as well (otherwise you'll get a 500 from Flink complaining about the missing header)

    Here is a python script using requests that does the upload

    upload = requests.post(                                                                                               
        base_url + "/jars/upload",                                                                                        
        files={
            "jarfile": (
                os.path.basename(path), 
                open(path, "rb"), 
                "application/x-java-archive"
             )
        }
    )       
    
    0 讨论(0)
  • 2021-01-03 04:05

    For those who want a java solution can use:

    CloseableHttpClient client = HttpClients.createDefault();
            HttpPost httpPost = new HttpPost("YOUR API URL");
            MultipartEntityBuilder builder = MultipartEntityBuilder.create();
            builder.addBinaryBody("jarfile", new File("jarr.jar"));
            HttpEntity multipart = builder.build();
            httpPost.setEntity(multipart);
    
            try{
                CloseableHttpResponse response = client.execute(httpPost);
                System.out.println(response);
                BufferedReader rd = new BufferedReader(new InputStreamReader(
                        response.getEntity().getContent()));
    
                String line = "";
                while ((line = rd.readLine()) != null) {
                    System.out.println(line);
                    }
            }
            catch (Exception e){
                e.printStackTrace();
            }
    
    0 讨论(0)
  • 2021-01-03 04:29

    Those who are more partial to a command line can use curl:

    curl -X POST -H "Expect:" -F "jarfile=@path/to/flink-job.jar" http://hostname:8081/jars/upload
    
    0 讨论(0)
提交回复
热议问题