1
0
mirror of https://github.com/sasjs/adapter.git synced 2025-12-11 01:14:36 +00:00

Compare commits

...

23 Commits

Author SHA1 Message Date
Yury Shkoda
33a202fa1c Merge pull request #189 from sasjs/job-pid
feat(job-pid): added print PID of the executed job
2020-12-23 12:06:24 +03:00
Yury Shkoda
ff5463a84c chore(example): fixed example 2020-12-23 09:24:15 +03:00
Yury Shkoda
aa7c3ae4a9 docs(pid): updated docs 2020-12-23 09:18:49 +03:00
Yury Shkoda
2e66bfde4b chore(pid): made printing PID optional 2020-12-23 09:17:40 +03:00
Yury Shkoda
16e21adb20 chore: updated docs 2020-12-22 16:58:14 +03:00
Yury Shkoda
01c5682c3d Merge branch 'job-pid' of https://github.com/sasjs/adapter into job-pid 2020-12-22 16:46:48 +03:00
Yury Shkoda
cfc8ff2837 chore: added 'Assign Reviewer' CI step 2020-12-22 16:46:16 +03:00
Yury Shkoda
edf25b471a chore: added 'Assign Reviewer' CI step 2020-12-22 16:41:22 +03:00
Yury Shkoda
bb894e6107 feat(job-pid): added print PID of the executed job 2020-12-22 16:21:24 +03:00
Yury Shkoda
7bf53858f0 Merge pull request #176 from sasjs/cli-issue-317
fix(session-status): fixed stop polling session status
2020-12-09 12:56:17 +03:00
Yury Shkoda
02780d0bcd fix(session-status): fixed stop polling session status 2020-12-09 12:45:37 +03:00
Allan Bowe
6356aed06b Merge pull request #173 from sasjs/fix
fix: fetch all items of folder
2020-12-08 00:43:38 +01:00
Saad Jutt
69fd7b2cb5 fix: fetch all items of folder 2020-12-08 04:37:42 +05:00
Allan Bowe
5d1eed1494 Merge pull request #169 from sasjs/execScriptReturn
fix: executeScript return no log
2020-12-04 15:01:47 +01:00
Mihajlo Medjedovic
e2e2824f37 chore: cleanup 2020-12-03 13:05:02 +01:00
Mihajlo Medjedovic
d461135980 chore: job object rename 2020-12-03 12:29:50 +01:00
Mihajlo Medjedovic
65fbae7610 docs: generated 2020-12-03 12:26:23 +01:00
Mihajlo Medjedovic
761428502a fix: added debug override on executeScriptSASViya and added tests for same function 2020-12-03 12:25:42 +01:00
Mihajlo Medjedovic
6eb2ceaf53 test: fixed compute job 2020-12-02 20:48:31 +01:00
Mihajlo Medjedovic
66813b9824 fix: executeScript return no log 2020-12-02 18:18:56 +01:00
Krishna Acondy
140d8e4eac Merge pull request #165 from sasjs/debugIssue
fix: sasjsconfig.debug not passed in executeScriptSASViya function
2020-12-01 11:13:37 +00:00
Mihajlo Medjedovic
0d730e0576 Merge branch 'master' into debugIssue 2020-12-01 12:09:46 +01:00
Mihajlo Medjedovic
9037160362 fix: sasjsconfig.debug not passed in executeScriptSASViya function 2020-11-27 15:45:36 +01:00
49 changed files with 10856 additions and 2999 deletions

2
.env.example Normal file
View File

@@ -0,0 +1,2 @@
SERVER_URL=https://server.com
DEFAULT_COMPUTE_CONTEXT=SAS Job Execution compute context

9
.github/reviewer-lottery.yml vendored Normal file
View File

@@ -0,0 +1,9 @@
groups:
- name: SASjs Devs # name of the group
reviewers: 1 # how many reviewers do you want to assign?
usernames: # github usernames of the reviewers
- krishna-acondy
- YuryShkoda
- saadjutt01
- medjedovicm
- allanbowe

13
.github/workflows/assign-reviewer.yml vendored Normal file
View File

@@ -0,0 +1,13 @@
name: 'Assign Reviewer'
on:
pull_request:
types: [opened]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: uesteibar/reviewer-lottery@v1
with:
repo-token: ${{ secrets.GH_TOKEN }}

4
.gitignore vendored
View File

@@ -1,2 +1,4 @@
node_modules
build
build
.env

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1673
docs/classes/root.sasjs.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

125
docs/modules/root.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4610
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -39,6 +39,7 @@
"@types/isomorphic-fetch": "0.0.35",
"@types/jest": "^26.0.15",
"cp": "^0.2.0",
"dotenv": "^8.2.0",
"jest": "^25.5.4",
"path": "^0.12.7",
"rimraf": "^3.0.2",
@@ -57,6 +58,7 @@
},
"main": "index.js",
"dependencies": {
"@sasjs/utils": "^1.5.0",
"es6-promise": "^4.2.8",
"form-data": "^3.0.0",
"isomorphic-fetch": "^2.2.1"

View File

@@ -25,17 +25,71 @@ export const computeTests = (adapter: SASjs): TestSuite => ({
},
assertion: (res: any) => {
const expectedProperties = ["id", "state", "creationTimeStamp", "jobConditionCode"]
return validate(expectedProperties, res);
return validate(expectedProperties, res.result);
}
},
{
title: "Execute Script Viya - complete job",
description: "Should execute sas file and return log",
test: () => {
const fileLines = [
`data;`,
`do x=1 to 100;`,
`output;`,
`end;`,
`run;`
]
return adapter.executeScriptSASViya(
'sasCode.sas',
fileLines,
'SAS Studio compute context',
undefined,
true
)
},
assertion: (res: any) => {
const expectedLogContent = `1 data;\\n2 do x=1 to 100;\\n3 output;\\n4 end;\\n5 run;\\n\\n`
return validateLog(expectedLogContent, res.log);
}
},
{
title: "Execute Script Viya - failed job",
description: "Should execute sas file and return log",
test: () => {
const fileLines = [
`%abort;`
]
return adapter.executeScriptSASViya(
'sasCode.sas',
fileLines,
'SAS Studio compute context',
undefined,
true
).catch((err: any) => err )
},
assertion: (res: any) => {
const expectedLogContent = `1 %abort;\\nERROR: The %ABORT statement is not valid in open code.\\n`
return validateLog(expectedLogContent, res.log);
}
}
]
});
const validateLog = (text: string, log: string): boolean => {
const isValid = JSON.stringify(log).includes(text)
return isValid
}
const validate = (expectedProperties: string[], data: any): boolean => {
const actualProperties = Object.keys(data);
const isValid = expectedProperties.every(
(property) => actualProperties.includes(property)
);
return isValid
const isValid = expectedProperties.every(
(property) => actualProperties.includes(property)
);
return isValid
}

View File

@@ -16,12 +16,13 @@ import {
Folder,
CsrfToken,
EditContextInput,
ErrorResponse,
JobDefinition,
PollOptions
} from './types'
import { formatDataForRequest } from './utils/formatDataForRequest'
import { SessionManager } from './SessionManager'
import { timestampToYYYYMMDDHHMMSS } from '@sasjs/utils/time'
import { Logger, LogLevel } from '@sasjs/utils/logger'
/**
* A client for interfacing with the SAS Viya REST API.
@@ -430,6 +431,7 @@ export class SASViyaApiClient {
* @param expectWebout - when set to true, the automatic _webout fileref will be checked for content, and that content returned. This fileref is used when the Job contains a SASjs web request (as opposed to executing arbitrary SAS code).
* @param waitForResult - when set to true, function will return the session
* @param pollOptions - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { MAX_POLL_COUNT: 24 * 60 * 60, POLL_INTERVAL: 1000 }.
* @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
*/
public async executeScript(
jobPath: string,
@@ -440,7 +442,8 @@ export class SASViyaApiClient {
debug: boolean = false,
expectWebout = false,
waitForResult = true,
pollOptions?: PollOptions
pollOptions?: PollOptions,
printPid = false
): Promise<any> {
try {
const headers: any = {
@@ -460,6 +463,28 @@ export class SASViyaApiClient {
executionSessionId = session!.id
if (printPid) {
const { result: jobIdVariable } = await this.sessionManager.getVariable(
executionSessionId,
'SYSJOBID',
accessToken
)
if (jobIdVariable && jobIdVariable.value) {
const relativeJobPath = this.rootFolderName
? jobPath.split(this.rootFolderName).join('').replace(/^\//, '')
: jobPath
const logger = new Logger(debug ? LogLevel.Debug : LogLevel.Info)
logger.info(
`Triggered '${relativeJobPath}' with PID ${
jobIdVariable.value
} at ${timestampToYYYYMMDDHHMMSS()}`
)
}
}
const jobArguments: { [key: string]: any } = {
_contextName: contextName,
_OMITJSONLISTING: true,
@@ -589,7 +614,7 @@ export class SASViyaApiClient {
if (expectWebout) {
resultLink = `/compute/sessions/${executionSessionId}/filerefs/_webout/content`
} else {
return currentJob
return { job: currentJob, log }
}
if (resultLink) {
@@ -958,6 +983,7 @@ export class SASViyaApiClient {
* @param waitForResult - a boolean indicating if the function should wait for a result.
* @param expectWebout - a boolean indicating whether to expect a _webout response.
* @param pollOptions - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { MAX_POLL_COUNT: 24 * 60 * 60, POLL_INTERVAL: 1000 }.
* @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
*/
public async executeComputeJob(
sasJob: string,
@@ -967,7 +993,8 @@ export class SASViyaApiClient {
accessToken?: string,
waitForResult = true,
expectWebout = false,
pollOptions?: PollOptions
pollOptions?: PollOptions,
printPid = false
) {
if (isRelativePath(sasJob) && !this.rootFolderName) {
throw new Error(
@@ -1053,7 +1080,8 @@ export class SASViyaApiClient {
debug,
expectWebout,
waitForResult,
pollOptions
pollOptions,
printPid
)
}
@@ -1238,7 +1266,7 @@ export class SASViyaApiClient {
throw new Error(`The path ${path} does not exist on ${this.serverUrl}`)
}
const { result: members } = await this.request<{ items: any[] }>(
`${this.serverUrl}/folders/folders/${folder.id}/members`,
`${this.serverUrl}/folders/folders/${folder.id}/members?limit=${folder.memberCount}`,
requestInfo
)

View File

@@ -206,11 +206,20 @@ export default class SASjs {
return await this.sasViyaApiClient!.createSession(contextName, accessToken)
}
/**
* Executes the sas code against given sas server
* @param fileName - name of the file to run. It will be converted to path to the file being submitted for execution.
* @param linesOfCode - lines of sas code from the file to run.
* @param contextName - context name on which code will be run on the server.
* @param accessToken - (optional) the access token for authorizing the request.
* @param debug - (optional) if true, global debug config will be overriden
*/
public async executeScriptSASViya(
fileName: string,
linesOfCode: string[],
contextName: string,
accessToken?: string
accessToken?: string,
debug?: boolean
) {
this.isMethodSupported('executeScriptSASViya', ServerType.SASViya)
@@ -219,7 +228,8 @@ export default class SASjs {
linesOfCode,
contextName,
accessToken,
null
null,
debug ? debug : this.sasjsConfig.debug
)
}
@@ -713,6 +723,7 @@ export default class SASjs {
* The access token is not required when the user is authenticated via the browser.
* @param waitForResult - a boolean that indicates whether the function needs to wait for execution to complete.
* @param pollOptions - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { MAX_POLL_COUNT: 24 * 60 * 60, POLL_INTERVAL: 1000 }.
* @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
*/
public async startComputeJob(
sasJob: string,
@@ -720,7 +731,8 @@ export default class SASjs {
config: any = {},
accessToken?: string,
waitForResult?: boolean,
pollOptions?: PollOptions
pollOptions?: PollOptions,
printPid = false
) {
config = {
...this.sasjsConfig,
@@ -742,7 +754,8 @@ export default class SASjs {
accessToken,
!!waitForResult,
false,
pollOptions
pollOptions,
printPid
)
}

View File

@@ -1,5 +1,6 @@
import { Session, Context, CsrfToken } from './types'
import { Session, Context, CsrfToken, SessionVariable } from './types'
import { asyncForEach, makeRequest, isUrl } from './utils'
import { prefixMessage } from '@sasjs/utils/error'
const MAX_SESSION_COUNT = 1
const RETRY_LIMIT: number = 3
@@ -168,7 +169,11 @@ export class SessionManager {
const stateLink = session.links.find((l: any) => l.rel === 'state')
return new Promise(async (resolve, _) => {
if (sessionState === 'pending') {
if (
sessionState === 'pending' ||
sessionState === 'running' ||
sessionState === ''
) {
if (stateLink) {
if (this.debug) {
console.log('Polling session status... \n') // ?
@@ -261,4 +266,21 @@ export class SessionManager {
throw err
})
}
async getVariable(sessionId: string, variable: string, accessToken?: string) {
const getSessionVariable = {
method: 'GET',
headers: this.getHeaders(accessToken)
}
return await this.request<SessionVariable>(
`${this.serverUrl}/compute/sessions/${sessionId}/variables/${variable}`,
getSessionVariable
).catch((err) => {
throw prefixMessage(
err,
`Error while fetching session variable '${variable}'.`
)
})
}
}

View File

@@ -0,0 +1,53 @@
import { SessionManager } from '../SessionManager'
import * as dotenv from 'dotenv'
describe('SessionManager', () => {
dotenv.config()
let originalFetch: any
const sessionManager = new SessionManager(
process.env.SERVER_URL as string,
process.env.DEFAULT_COMPUTE_CONTEXT as string,
() => {}
)
beforeAll(() => {
originalFetch = (global as any).fetch
})
afterEach(() => {
;(global as any).fetch = originalFetch
})
describe('getVariable', () => {
it('should fetch session variable', async () => {
const sampleResponse = {
ok: true,
links: [],
name: 'SYSJOBID',
scope: 'GLOBAL',
value: '25218',
version: 1
}
;(global as any).fetch = jest.fn().mockImplementation(() =>
Promise.resolve({
ok: true,
headers: { get: () => '' },
json: () => Promise.resolve(sampleResponse)
})
)
const expectedResponse = { etag: '', result: sampleResponse }
await expect(
sessionManager.getVariable(
'fakeSessionId',
'SYSJOBID',
'fakeAccessToken'
)
).resolves.toEqual(expectedResponse)
})
})
})

View File

@@ -4,4 +4,5 @@ export interface Folder {
id: string
uri: string
links: Link[]
memberCount: number
}

View File

@@ -9,3 +9,7 @@ export interface Session {
}
creationTimeStamp: string
}
export interface SessionVariable {
value: string
}