BookmarkSubscribeRSS Feed
WaelAburezeq
Obsidian | Level 7

Hello,

 

I have created a SAS job file, scheduled it for one time -for testing purposes- and it worked perfectly. Now, I am trying to call this SAS job (using Job Definition Id) through REST API following this link

 

export server_name='..... '
curl POST 'https://$server_name/jobExecution/jobs' \
--header 'Content-Type: application/vnd.sas.job.execution.job.request+json' \
--header 'Accept: application/vnd.sas.job.execution.job+json' \
--header 'Authorization: Bearer ey..' \
--data-raw '{
  "jobDefinitionUri": "/jobDefinitions/definitions/49bbd477-dc4f-4155-9e72-2b9ecf09c148"
}'

but I am getting the following error:

"error": {
        "errorCode": 31509,
        "message": "Job routing failure.",
        "errors": [
            {
                "errorCode": 5734,
                "message": "The job must include an argument named either \"_contextName\" or \"_sessionId\".",
                "details": [
                    "traceId: 7fbbb6e817a969da",
                    "path: /compute/jobs"
                ],
                "links": [],
                "version": 2,
                "httpStatusCode": 400
            }
Although I have done the following:
1- Successfully created 0Auth Session
2- Tried to create a Compute Session mapped to SAS Job Execution compute context Service Id (retrieved from Get Compute)  as the following link
curl --location --request POST 'https://$server_name/compute/contexts/347103b9-e3f3-43dc-88c7-0546678ea285/sessions' \
--header 'Content-Type: application/vnd.sas.compute.session.request+json' \
--header 'Accept: application/vnd.sas.compute.session+json' \
--header 'Authorization: Bearer ey...' \
--data-raw ''
but also got the response status as "Pending":
{
    "owner""sas.user",
    "state""pending",
    "attributes": {
        "homeDirectory""/opt/sas/viya/config/var/run/compsrv/default/02380a82-c6ef-4e44-9dd9-df96fc559764",
        "sessionInactiveTimeout"900
    },
 
Any help as I am really diving into this documentation: https://developer.sas.com/apis/rest/Compute/?shell#schemasessionrequest
 
11 REPLIES 11
joeFurbee
Community Manager

Hi @WaelAburezeq,

Perhaps the issue is with your Job Definition? Feel free to post a sample of your jobDefinition code. I wasn't able to replicate your error. You can refer to a series of jobs API calls in this Postman collection on GitHub for examples of CRUD operations with jobs.

 

Thanks,

Joe


Join us for SAS Community Trivia
SAS Bowl XLVI, Causal Analysis
Wednesday, December 18, 2024, at 10 a.m. ET | #SASBowl

WaelAburezeq
Obsidian | Level 7

Hi Joe,

Your PostMan file worked perfectly when I run it. However, let's replicate my issue as the following:

 

1- Create a SAS Code file with the same code in your Job Definition and save it under your folder.

proc print data=sashelp.class; run;

2- Right click on SAS code file , Create Job and then Schedule it for one time. This worked!

3- From Environment Manager --> Jobs --> Scheduling --> Job Propriety --> Job Definition Tab then get the job Id. You will notice Type is Compute as well.

4- Go to Postman, run only CAS Session authentication to get Session Id (Without Job Definition task) 

5- Run Your jobExecution  with a Pre-requisite script as below where the "456...etc" is the job id retrieved from step #3.

pm.environment.set("jobDefinition", "4568b08b-e071-4d9a-9f2e-88f12192e134");

 

You will then get the same error as mine (I attached the response too) 

    "error": {
        "errorCode"31509,
        "message""Job routing failure.",
        "errors": [
            {
                "errorCode"5734,
                "message""The job must include an argument named either \"_contextName\" or \"_sessionId\".",
                "details": [
                    "traceId: 0e7e88358410279b",
                    "path: /compute/jobs"
                ],
                "links": [],
                "version"2,
                "httpStatusCode"400
            }
        ],
        "links": [],
        "version"2,
        "httpStatusCode"400
    }
joeFurbee
Community Manager

Hi @WaelAburezeq,

Unfortunately, I couldn't recreate your error using the steps you outlined. When I send the POST {{sasserver}}/jobExecution/jobs with the JSON body

{
  "jobDefinitionUri""/jobDefinitions/definitions/{{jobDefinition}}"
}
 

I get a 201 response with the following:

{
    "creationTimeStamp": "2020-10-02T17:17:10.118Z",
    "modifiedTimeStamp": "2020-10-02T17:17:10.118Z",
    "createdBy": "jofurb",
    "modifiedBy": "jofurb",
    "version": 4,
    "id": "6fc47d68-d4e3-4dba-aa55-dd5f2b79c7b1",
    "jobRequest": {
        "version": 3,
        "jobDefinitionUri": "/jobDefinitions/definitions/182343f8-8e5c-46ec-a8f9-70d101f04741",
        "jobDefinition": {
            "creationTimeStamp": "2020-10-02T16:49:53.265Z",
            "modifiedTimeStamp": "2020-10-02T16:49:53.266Z",
            "createdBy": "jofurb",
            "modifiedBy": "jofurb",
            "version": 2,
            "id": "182343f8-8e5c-46ec-a8f9-70d101f04741",
            "name": "printClassProgram",
            "type": "Compute",
            "parameters": [],
            "code": "proc print data=sashelp.class; run;",
            "links": [
                {
                    "method": "GET",
.....................

I'm attaching the entire response.


Join us for SAS Community Trivia
SAS Bowl XLVI, Causal Analysis
Wednesday, December 18, 2024, at 10 a.m. ET | #SASBowl

WaelAburezeq
Obsidian | Level 7

Hi Joe, Thank you so much for your reply.

 

A- Are you using SAS Compute Service ID to create a session Id or it is just a normal session Id request?  

B- Are you using the Job Id extracted from Job Definition under Jobs that are located in Environment Manger - the job you created from the .sas code file?

 

I am attaching my postman two requests:

1- Creating SAS Session Id

2- Executing Job Definition 

Parameters are:

1- OAuth Username and Password

2- viyahostserver

3- Job Id from the above Point B in second API pre-requisite

 

Looking forward for your continuous support

 

WaelAburezeq
Obsidian | Level 7

Hi @joeFurbee ,

 

Would you please let me know if you replicated the issue and how to overcome it?

 

Thank you,

joeFurbee
Community Manager

Hi @WaelAburezeq,

I collaborated with a colleague on looking into this thread and we think we've found the root issue. This is what we came up with:

 

Looking at the postman collection in your latest post, try adding a _sessionId parameter to the request body of his  POST /jobExecution/jobs request. Something like:

{

   "jobDefinitionUri": "/jobDefinitions/definitions/{{jobDefinition}}",

   "arguments": {

      "_sessionId": "<compute_session_id>"

   }

}

 

Note however, you need to adjust how you find the correct value for the _sessionId parameter.

 

In your Postman collection, you use POST /casManagement/servers/cas-shared-defaults/sessions, but that is not the right "session". You need a compute session ID and not a CAS session ID.

You were on the right track initially when looking at the response from the POST /compute/contexts/{contextId}/sessions request. The session ID in that response is the correct one to use for the _sessionId parameter in the request body of his POST /jobExecution/jobs request.

Finally note, you are responsible for terminating the compute session when you run jobs on it in this way. The job execution service will not terminate the session after your job runs in this case. 

 

Hope this helps,

Joe


Join us for SAS Community Trivia
SAS Bowl XLVI, Causal Analysis
Wednesday, December 18, 2024, at 10 a.m. ET | #SASBowl

WaelAburezeq
Obsidian | Level 7

Thank a million Joe for your continuous support , I have some good news actually.

 

I tried to pass _Sessionid in argument body but I kept getting invalid body response. I already retrieved the compute context id for "SAS Job Execution Compute Context" , created compute session id and tried to pass it in job execution API. 

 

However, what worked for me is to pass  "_contextName""SAS Job Execution compute context" instead of _SessionId and that worked as magic! I also didn't have to create compute session id nor SAS session id (which I think is a bit weird unless the "/jobExecution/jobs" creates a compute session by default.

 

I am attaching my postman requests for your kind review, please have a look at:

 

- Submit SAS Job Definition for Execution

- JobState

- Delete SAS Studio Compute Session (I couldn't get the Compute Session Id from the first API in order to terminate the session)

 

WaelAburezeq
Obsidian | Level 7

Hi @joeFurbee 

 

Did you have a chance to look at my latest reply?

joeFurbee
Community Manager

Hi @WaelAburezeq,

I uploaded your Postman collection. I created the viyahostserver environment variable and replaced the jobDefinitionID with one of my own jobs. The collection ran without issue. Did you need anything besides confirmation of your collection?

 

Thanks,

Joe


Join us for SAS Community Trivia
SAS Bowl XLVI, Causal Analysis
Wednesday, December 18, 2024, at 10 a.m. ET | #SASBowl

WaelAburezeq
Obsidian | Level 7
Hi Joe,

Yes it is running perfectly. However, I need the computer Session id so I
terminate it after the job is completed. I know it gets terminated by
itself once idle, but I don't want to keep the compute resources busy. What
do you think?
joeFurbee
Community Manager

Hi @WaelAburezeq,

When I ran your collection, in the POST Create SAS Studio Compute Session call, I see the key:value  "id""5fe124e0-a4fe-4149-85cd-58ac5530009f-ses0000", and you add that value to a variable in the Tests code: pm.environment.set("computesessionid"jsonData.id);

 

I then ran the last call in your collection GET Get Active Compute Sessions. The session id from above returned successfully. 

 

I then see you use that same value to end the session in the DELETE SAS Studio Compute Session: {{viyahostserver}}/compute/sessions/{{computesessionid}}.

 

I rerun the GET Get Active Compute Sessions call and this returned an empty response as there are no active sessions, indicated by this in the response: "count":0,"items":[],"limit":10,"version":2}.

 

I think your code is good and running properly. 

 

Thanks,

Joe


Join us for SAS Community Trivia
SAS Bowl XLVI, Causal Analysis
Wednesday, December 18, 2024, at 10 a.m. ET | #SASBowl

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 7434 views
  • 0 likes
  • 2 in conversation