Flink Rest API : /jars/upload returning 404

371 Views Asked by At

Following is my code snippet used for uploading Jar in Flink. I am getting 404 response for this post request. Following is the output for request. I also tried updating the url with /v1/jars/upload but same response. All the API related to jars is giving me same response. I am running this code inside AWS lambda which is present in same vpc where EMR exists which is runing my Flink Job. APIs like /config, /jobs working in this lambda, only APIs like upload jar, submit jobs not working and getting 404 for them

<Response [404]> {"errors":["Not found: /jars/upload"]}

Also tried the same thing by directly logging into job manager node and running curl command, but got the same response. I am using Flink 1.14.2 version on EMR cluster

curl -X POST -H "Expect:" -F "jarfile=@/home/hadoop/test-1.0-global-14-dyn.jar" http://ip-10-0-1-xxx:8081/jars/upload

{"errors":["Not found:> /jars/upload"]}

import json
import requests
import boto3
import os

def lambda_handler(event, context):
    
  config = dict(
    service_name="s3",
    region_name="us-east-1"
  )
  s3_ = boto3.resource(**config)

  bucket = "dv-stream-processor-na-gamma"
  prefix = ""
  file = "Test-1.0-global-14-dyn.jar"
  path = "/tmp/"+file;

  try:
    s3_.Bucket(bucket).download_file(f"{file}", "/tmp/"+file)
  except botocore.exceptions.ClientError as e:
    print(e.response['Error']['Code'])   
    if e.response['Error']['Code'] == "404":
        print("The object does not exist.")
        
  print(os.path.isfile('/tmp/' + file))
  response = requests.post(
     "http://ip-10-0-1-xx.ec2.internal:8081/jars/upload",
     files={
              "jarfile": (
                os.path.basename(path), 
                open(path, "rb"),
                "application/x-java-archive"
            )
     }
  )

print(response)
print(response.text)
1

There are 1 best solutions below

0
On

Reason for upload jar was not working for me was I was using Flink "Per Job" cluster mode where it was not allowed to submit job via REST API. I updated the cluster mode to "Session" mode and it started working

References for Flink cluster mode information :

https://nightlies.apache.org/flink/flink-docs-release-1.15/docs/deployment/overview/

Code you can refer to start cluster in session mode : https://nightlies.apache.org/flink/flink-docs-master/docs/deployment/resource-providers/yarn/#starting-a-flink-session-on-yarn