mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-05 03:30:05 +00:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
361ec84638 | ||
|
|
35cc1e4f62 | ||
|
|
64a976e888 | ||
|
|
7e2cb8491f | ||
|
|
2cdab7522d | ||
|
|
a07eabc408 | ||
|
|
d5920c5885 | ||
|
|
6a3a6b4485 | ||
|
|
2b1df0c61a | ||
|
|
216725f306 | ||
|
|
3183f89a62 | ||
|
|
f5cc16c3bd | ||
|
|
e78dc76e56 | ||
|
|
bfdb5ef0a6 | ||
|
|
35353d3fce | ||
|
|
ef5686cce7 | ||
|
|
a07c16fb52 | ||
|
|
fd6905ea9f | ||
|
|
08f58b5f4f |
File diff suppressed because one or more lines are too long
231
docs/classes/reflection-787.reflection-214.fileuploader.html
Normal file
231
docs/classes/reflection-787.reflection-214.fileuploader.html
Normal file
File diff suppressed because one or more lines are too long
312
docs/classes/reflection-787.reflection-214.sas9apiclient.html
Normal file
312
docs/classes/reflection-787.reflection-214.sas9apiclient.html
Normal file
File diff suppressed because one or more lines are too long
1590
docs/classes/reflection-787.reflection-214.sasjs.html
Normal file
1590
docs/classes/reflection-787.reflection-214.sasjs.html
Normal file
File diff suppressed because one or more lines are too long
1435
docs/classes/reflection-787.reflection-214.sasviyaapiclient.html
Normal file
1435
docs/classes/reflection-787.reflection-214.sasviyaapiclient.html
Normal file
File diff suppressed because one or more lines are too long
323
docs/classes/reflection-787.reflection-214.sessionmanager.html
Normal file
323
docs/classes/reflection-787.reflection-214.sessionmanager.html
Normal file
File diff suppressed because one or more lines are too long
231
docs/classes/reflection-790.reflection-214.fileuploader.html
Normal file
231
docs/classes/reflection-790.reflection-214.fileuploader.html
Normal file
File diff suppressed because one or more lines are too long
312
docs/classes/reflection-790.reflection-214.sas9apiclient.html
Normal file
312
docs/classes/reflection-790.reflection-214.sas9apiclient.html
Normal file
File diff suppressed because one or more lines are too long
1641
docs/classes/reflection-790.reflection-214.sasjs.html
Normal file
1641
docs/classes/reflection-790.reflection-214.sasjs.html
Normal file
File diff suppressed because one or more lines are too long
1444
docs/classes/reflection-790.reflection-214.sasviyaapiclient.html
Normal file
1444
docs/classes/reflection-790.reflection-214.sasviyaapiclient.html
Normal file
File diff suppressed because one or more lines are too long
323
docs/classes/reflection-790.reflection-214.sessionmanager.html
Normal file
323
docs/classes/reflection-790.reflection-214.sessionmanager.html
Normal file
File diff suppressed because one or more lines are too long
@@ -76,7 +76,7 @@
|
|||||||
<section class="tsd-index-section ">
|
<section class="tsd-index-section ">
|
||||||
<h3>Modules</h3>
|
<h3>Modules</h3>
|
||||||
<ul class="tsd-index-list">
|
<ul class="tsd-index-list">
|
||||||
<li class="tsd-kind-module tsd-is-not-exported"><a href="modules/reflection-762.html" class="tsd-kind-icon"><em>Module</em></a></li>
|
<li class="tsd-kind-module tsd-is-not-exported"><a href="modules/reflection-790.html" class="tsd-kind-icon"><em>Module</em></a></li>
|
||||||
<li class="tsd-kind-module"><a href="modules/types.html" class="tsd-kind-icon">types</a></li>
|
<li class="tsd-kind-module"><a href="modules/types.html" class="tsd-kind-icon">types</a></li>
|
||||||
<li class="tsd-kind-module"><a href="modules/utils.html" class="tsd-kind-icon">utils</a></li>
|
<li class="tsd-kind-module"><a href="modules/utils.html" class="tsd-kind-icon">utils</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
106
docs/modules/reflection-787.html
Normal file
106
docs/modules/reflection-787.html
Normal file
File diff suppressed because one or more lines are too long
128
docs/modules/reflection-787.reflection-214.html
Normal file
128
docs/modules/reflection-787.reflection-214.html
Normal file
File diff suppressed because one or more lines are too long
106
docs/modules/reflection-790.html
Normal file
106
docs/modules/reflection-790.html
Normal file
File diff suppressed because one or more lines are too long
128
docs/modules/reflection-790.reflection-214.html
Normal file
128
docs/modules/reflection-790.reflection-214.html
Normal file
File diff suppressed because one or more lines are too long
@@ -5,6 +5,7 @@ import { sendArrTests, sendObjTests } from "./testSuites/RequestData";
|
|||||||
import { specialCaseTests } from "./testSuites/SpecialCases";
|
import { specialCaseTests } from "./testSuites/SpecialCases";
|
||||||
import { sasjsRequestTests } from "./testSuites/SasjsRequests";
|
import { sasjsRequestTests } from "./testSuites/SasjsRequests";
|
||||||
import "@sasjs/test-framework/dist/index.css";
|
import "@sasjs/test-framework/dist/index.css";
|
||||||
|
import { computeTests } from "./testSuites/Compute";
|
||||||
|
|
||||||
const App = (): ReactElement<{}> => {
|
const App = (): ReactElement<{}> => {
|
||||||
const { adapter, config } = useContext(AppContext);
|
const { adapter, config } = useContext(AppContext);
|
||||||
@@ -17,7 +18,8 @@ const App = (): ReactElement<{}> => {
|
|||||||
sendArrTests(adapter),
|
sendArrTests(adapter),
|
||||||
sendObjTests(adapter),
|
sendObjTests(adapter),
|
||||||
specialCaseTests(adapter),
|
specialCaseTests(adapter),
|
||||||
sasjsRequestTests(adapter)
|
sasjsRequestTests(adapter),
|
||||||
|
computeTests(adapter)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}, [adapter, config]);
|
}, [adapter, config]);
|
||||||
|
|||||||
41
sasjs-tests/src/testSuites/Compute.ts
Normal file
41
sasjs-tests/src/testSuites/Compute.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import SASjs from "@sasjs/adapter";
|
||||||
|
import { TestSuite } from "@sasjs/test-framework";
|
||||||
|
|
||||||
|
export const computeTests = (adapter: SASjs): TestSuite => ({
|
||||||
|
name: "Compute",
|
||||||
|
tests: [
|
||||||
|
{
|
||||||
|
title: "Start Compute Job - not waiting for result",
|
||||||
|
description: "Should start a compute job and return the session",
|
||||||
|
test: () => {
|
||||||
|
const data: any = { table1: [{ col1: "first col value" }] };
|
||||||
|
return adapter.startComputeJob("/Public/app/common/sendArr", data);
|
||||||
|
},
|
||||||
|
assertion: (res: any) => {
|
||||||
|
const expectedProperties = ["id", "applicationName", "attributes"]
|
||||||
|
return validate(expectedProperties, res);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Start Compute Job - waiting for result",
|
||||||
|
description: "Should start a compute job and return the job",
|
||||||
|
test: () => {
|
||||||
|
const data: any = { table1: [{ col1: "first col value" }] };
|
||||||
|
return adapter.startComputeJob("/Public/app/common/sendArr", data, {}, "", true);
|
||||||
|
},
|
||||||
|
assertion: (res: any) => {
|
||||||
|
const expectedProperties = ["id", "state", "creationTimeStamp", "jobConditionCode"]
|
||||||
|
return validate(expectedProperties, res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
const validate = (expectedProperties: string[], data: any): boolean => {
|
||||||
|
const actualProperties = Object.keys(data);
|
||||||
|
|
||||||
|
const isValid = expectedProperties.every(
|
||||||
|
(property) => actualProperties.includes(property)
|
||||||
|
);
|
||||||
|
return isValid
|
||||||
|
}
|
||||||
@@ -52,7 +52,9 @@ export class SASViyaApiClient {
|
|||||||
|
|
||||||
public set debug(value: boolean) {
|
public set debug(value: boolean) {
|
||||||
this._debug = value
|
this._debug = value
|
||||||
this.sessionManager.debug = value
|
if (this.sessionManager) {
|
||||||
|
this.sessionManager.debug = value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -152,6 +154,7 @@ export class SASViyaApiClient {
|
|||||||
context.name,
|
context.name,
|
||||||
accessToken,
|
accessToken,
|
||||||
null,
|
null,
|
||||||
|
true,
|
||||||
true
|
true
|
||||||
).catch((err) => err)
|
).catch((err) => err)
|
||||||
})
|
})
|
||||||
@@ -434,7 +437,8 @@ export class SASViyaApiClient {
|
|||||||
contextName: string,
|
contextName: string,
|
||||||
accessToken?: string,
|
accessToken?: string,
|
||||||
data = null,
|
data = null,
|
||||||
expectWebout = false
|
expectWebout = false,
|
||||||
|
waitForResult = true
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
try {
|
try {
|
||||||
const headers: any = {
|
const headers: any = {
|
||||||
@@ -527,6 +531,10 @@ export class SASViyaApiClient {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!waitForResult) {
|
||||||
|
return session
|
||||||
|
}
|
||||||
|
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
console.log(`Job has been submitted for '${fileName}'.`)
|
console.log(`Job has been submitted for '${fileName}'.`)
|
||||||
console.log(
|
console.log(
|
||||||
@@ -573,6 +581,8 @@ export class SASViyaApiClient {
|
|||||||
|
|
||||||
if (expectWebout) {
|
if (expectWebout) {
|
||||||
resultLink = `/compute/sessions/${executionSessionId}/filerefs/_webout/content`
|
resultLink = `/compute/sessions/${executionSessionId}/filerefs/_webout/content`
|
||||||
|
} else {
|
||||||
|
return currentJob
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resultLink) {
|
if (resultLink) {
|
||||||
@@ -624,7 +634,9 @@ export class SASViyaApiClient {
|
|||||||
linesOfCode,
|
linesOfCode,
|
||||||
contextName,
|
contextName,
|
||||||
accessToken,
|
accessToken,
|
||||||
data
|
data,
|
||||||
|
false,
|
||||||
|
true
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
throw e
|
throw e
|
||||||
@@ -937,13 +949,16 @@ export class SASViyaApiClient {
|
|||||||
* @param debug - sets the _debug flag in the job arguments.
|
* @param debug - sets the _debug flag in the job arguments.
|
||||||
* @param data - any data to be passed in as input to the job.
|
* @param data - any data to be passed in as input to the job.
|
||||||
* @param accessToken - an optional access token for an authorized user.
|
* @param accessToken - an optional access token for an authorized user.
|
||||||
|
* @param waitForResult - a boolean indicating if the function should wait for a result.
|
||||||
|
* @param expectWebout - a boolean indicating whether to expect a _webout response.
|
||||||
*/
|
*/
|
||||||
public async executeComputeJob(
|
public async executeComputeJob(
|
||||||
sasJob: string,
|
sasJob: string,
|
||||||
contextName: string,
|
contextName: string,
|
||||||
debug: boolean,
|
|
||||||
data?: any,
|
data?: any,
|
||||||
accessToken?: string
|
accessToken?: string,
|
||||||
|
waitForResult = true,
|
||||||
|
expectWebout = false
|
||||||
) {
|
) {
|
||||||
if (isRelativePath(sasJob) && !this.rootFolderName) {
|
if (isRelativePath(sasJob) && !this.rootFolderName) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -1017,6 +1032,8 @@ export class SASViyaApiClient {
|
|||||||
jobToExecute.code = code
|
jobToExecute.code = code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!code) code = ''
|
||||||
|
|
||||||
const linesToExecute = code.replace(/\r\n/g, '\n').split('\n')
|
const linesToExecute = code.replace(/\r\n/g, '\n').split('\n')
|
||||||
return await this.executeScript(
|
return await this.executeScript(
|
||||||
sasJob,
|
sasJob,
|
||||||
@@ -1024,7 +1041,8 @@ export class SASViyaApiClient {
|
|||||||
contextName,
|
contextName,
|
||||||
accessToken,
|
accessToken,
|
||||||
data,
|
data,
|
||||||
true
|
expectWebout,
|
||||||
|
waitForResult
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
79
src/SASjs.ts
79
src/SASjs.ts
@@ -44,7 +44,7 @@ const defaultConfig: SASjsConfig = {
|
|||||||
pathSASViya: '/SASJobExecution',
|
pathSASViya: '/SASJobExecution',
|
||||||
appLoc: '/Public/seedapp',
|
appLoc: '/Public/seedapp',
|
||||||
serverType: ServerType.SASViya,
|
serverType: ServerType.SASViya,
|
||||||
debug: true,
|
debug: false,
|
||||||
contextName: 'SAS Job Execution compute context',
|
contextName: 'SAS Job Execution compute context',
|
||||||
useComputeApi: false
|
useComputeApi: false
|
||||||
}
|
}
|
||||||
@@ -670,6 +670,50 @@ export default class SASjs {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kicks off execution of the given job via the compute API.
|
||||||
|
* @returns an object representing the compute session created for the given job.
|
||||||
|
* @param sasJob - the path to the SAS program (ultimately resolves to
|
||||||
|
* the SAS `_program` parameter to run a Job Definition or SAS 9 Stored
|
||||||
|
* Process). Is prepended at runtime with the value of `appLoc`.
|
||||||
|
* @param data - a JSON object containing one or more tables to be sent to
|
||||||
|
* SAS. Can be `null` if no inputs required.
|
||||||
|
* @param config - provide any changes to the config here, for instance to
|
||||||
|
* enable/disable `debug`. Any change provided will override the global config,
|
||||||
|
* for that particular function call.
|
||||||
|
* @param accessToken - a valid access token that is authorised to execute compute jobs.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
public async startComputeJob(
|
||||||
|
sasJob: string,
|
||||||
|
data: any,
|
||||||
|
config: any = {},
|
||||||
|
accessToken?: string,
|
||||||
|
waitForResult?: boolean
|
||||||
|
) {
|
||||||
|
config = {
|
||||||
|
...this.sasjsConfig,
|
||||||
|
...config
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isMethodSupported('startComputeJob', ServerType.SASViya)
|
||||||
|
if (!config.contextName) {
|
||||||
|
throw new Error(
|
||||||
|
'Context name is undefined. Please set a `contextName` in your SASjs or override config.'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.sasViyaApiClient?.executeComputeJob(
|
||||||
|
sasJob,
|
||||||
|
config.contextName,
|
||||||
|
data,
|
||||||
|
accessToken,
|
||||||
|
!!waitForResult,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private async executeJobViaComputeApi(
|
private async executeJobViaComputeApi(
|
||||||
sasJob: string,
|
sasJob: string,
|
||||||
data: any,
|
data: any,
|
||||||
@@ -689,13 +733,16 @@ export default class SASjs {
|
|||||||
|
|
||||||
sasjsWaitingRequest.requestPromise.promise = new Promise(
|
sasjsWaitingRequest.requestPromise.promise = new Promise(
|
||||||
async (resolve, reject) => {
|
async (resolve, reject) => {
|
||||||
|
const waitForResult = true
|
||||||
|
const expectWebout = true
|
||||||
this.sasViyaApiClient
|
this.sasViyaApiClient
|
||||||
?.executeComputeJob(
|
?.executeComputeJob(
|
||||||
sasJob,
|
sasJob,
|
||||||
config.contextName,
|
config.contextName,
|
||||||
config.debug,
|
|
||||||
data,
|
data,
|
||||||
accessToken
|
accessToken,
|
||||||
|
waitForResult,
|
||||||
|
expectWebout
|
||||||
)
|
)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (!config.debug) {
|
if (!config.debug) {
|
||||||
@@ -1217,10 +1264,20 @@ export default class SASjs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fetchLogFileContent(logLink: string) {
|
/**
|
||||||
|
* Fetches content of the log file
|
||||||
|
* @param logLink - url of the log file.
|
||||||
|
* @param accessToken - an access token for an authorized user.
|
||||||
|
*/
|
||||||
|
public fetchLogFileContent(logLink: string, accessToken?: string) {
|
||||||
|
const headers: any = { 'Content-Type': 'application/json' }
|
||||||
|
|
||||||
|
if (accessToken) headers.Authorization = 'Bearer ' + accessToken
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fetch(logLink, {
|
fetch(logLink, {
|
||||||
method: 'GET'
|
method: 'GET',
|
||||||
|
headers
|
||||||
})
|
})
|
||||||
.then((response: any) => response.text())
|
.then((response: any) => response.text())
|
||||||
.then((response: any) => resolve(response))
|
.then((response: any) => resolve(response))
|
||||||
@@ -1318,11 +1375,15 @@ export default class SASjs {
|
|||||||
this.sasjsConfig.serverUrl === undefined ||
|
this.sasjsConfig.serverUrl === undefined ||
|
||||||
this.sasjsConfig.serverUrl === ''
|
this.sasjsConfig.serverUrl === ''
|
||||||
) {
|
) {
|
||||||
let url = `${location.protocol}//${location.hostname}`
|
if (typeof location !== 'undefined') {
|
||||||
if (location.port) {
|
let url = `${location.protocol}//${location.hostname}`
|
||||||
url = `${url}:${location.port}`
|
|
||||||
|
if (location.port) url = `${url}:${location.port}`
|
||||||
|
|
||||||
|
this.sasjsConfig.serverUrl = url
|
||||||
|
} else {
|
||||||
|
this.sasjsConfig.serverUrl = ''
|
||||||
}
|
}
|
||||||
this.sasjsConfig.serverUrl = url
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.sasjsConfig.serverUrl.slice(-1) === '/') {
|
if (this.sasjsConfig.serverUrl.slice(-1) === '/') {
|
||||||
|
|||||||
Reference in New Issue
Block a user