diff --git a/HOW_TO_TEST.md b/HOW_TO_TEST.md new file mode 100644 index 0000000..e59e01b --- /dev/null +++ b/HOW_TO_TEST.md @@ -0,0 +1,43 @@ +# How to run tests + +## Pre-requisites +1. Download [SDK generation code](https://github.ibm.com/CloudEngineering/openapi-sdkgen/releases) +2. Clone [`Node SDK`] https://github.com/IBM/ibm-iae-node-sdk/ +3. Clone [`Cloud API Doc`] https://github.ibm.com/cloud-api-docs/analytics-engine +4. Generate the sdk code with: + `openapi-sdkgen/openapi-sdkgen.sh generate -g ibm-node -i ibmanalyticsengine-v3.json -o /Users/git/ibm-iae-node-sdk --genITs --genExamples` +5. Change to this packages root directory. +6. Exceute + ``` + npm install + ``` + +## Integration Tests + +1. The SDK has been generated from the latest ibmanalyticsengine-v3.json which contains modifications and newly added api methods. +The Integration test have to run on the generated SDK not on the sdk from git. +2. To merge with remote version pick the code marked between + `// !!! Start of custom content to be copied !!!` + `// !!! End of custom content to be copied !!!` + Files to be updated: + a. ibm-analytics-engine-api/v3.ts + b. test/unit/ibm-analytics-engine-api.v3.test.js + c. test/integration/ibm-analytics-engine-api.v3.test.js + d. examples/ibm-analytics-engine-api.v3.test.js + +3. Create a `auth.js` file in the `ibm-iae-node-sdk/test/resources` directory using `ibm-iae-node-sdk/test/resources/auth.example.js` as an example. +4. Update `auth.js` file with your own **APIKEY** and other details. +5. Execute the following command: + `npm install` + `npm run build` + `npm run lint-fix` +6. Go to Project's root directory `ibm-iae-node-sdk/` directory. + Run `yarn jest ibm-analytics-engine-api.v3.test.js` + +7. To execute individual tests + Run `yarn jest test/integration/ibm-analytics-engine-api.v3.test.js`. + Run `yarn jest examples/ibm-analytics-engine-api.v3.test.js`. + +## Unit Tests + +1. Run `jest test/unit/ibm-analytics-engine-api.v3.test.js`. \ No newline at end of file diff --git a/examples/ibm-analytics-engine-api.v3.test.js b/examples/ibm-analytics-engine-api.v3.test.js index 588dfe4..c009fcc 100644 --- a/examples/ibm-analytics-engine-api.v3.test.js +++ b/examples/ibm-analytics-engine-api.v3.test.js @@ -2,7 +2,7 @@ * @jest-environment node */ /** - * (C) Copyright IBM Corp. 2021. + * (C) Copyright IBM Corp. 2022. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,14 @@ const IbmAnalyticsEngineApiV3 = require('../dist/ibm-analytics-engine-api/v3'); // eslint-disable-next-line node/no-unpublished-require + +//!!! Start of custom content to be copied !!! +// Replace auth-helper.js with auth.js for testing const authHelper = require('../test/resources/auth-helper.js'); +const { IamAuthenticator } = require('../dist/auth'); +const timeout = 200000; +// !!! End of custom content to be copied !!! + // You can use the readExternalSources method to access additional configuration values // const { readExternalSources } = require('ibm-cloud-sdk-core'); @@ -38,189 +45,633 @@ const authHelper = require('../test/resources/auth-helper.js'); // in a configuration file and then: // export IBM_CREDENTIALS_FILE= // -const configFile = 'ibm_analytics_engine_api_v3.env'; +//!!! Start of custom content to be copied !!! +// const configFile = 'ibm_analytics_engine_api_v3.env'; -const describe = authHelper.prepareTests(configFile); +// const describe = authHelper.prepareTests(configFile); +// !!! End of custom content to be copied !!! // Save original console.log const originalLog = console.log; +const originalWarn = console.warn; // Mocks for console.log and console.warn const consoleLogMock = jest.spyOn(console, 'log'); const consoleWarnMock = jest.spyOn(console, 'warn'); describe('IbmAnalyticsEngineApiV3', () => { - // begin-common - - const ibmAnalyticsEngineApiService = IbmAnalyticsEngineApiV3.newInstance({}); - - // end-common + // Service instance + let ibmAnalyticsEngineApiService; // To access additional configuration values, uncomment this line and extract the values from config // const config = readExternalSources(IbmAnalyticsEngineApiV3.DEFAULT_SERVICE_NAME); + //!!! Start of custom content to be copied !!! + const options = authHelper.ibm_analytics_engine_api_v3; + options.authenticator = new IamAuthenticator({ apikey: options.apikey, url: options.apiAuthUrl }); + const instanceGuid = options.instance_guid_example; + const instanceIdInstanceHome = options.instance_guid_example_instance_home; + const hmacAccessKey = options.newHmacAccessKey; + const hmacSecretKey = options.newHmacSecretKey; + let applicationId = ''; + jest.setTimeout(timeout); + // !!! End of custom content to be copied !!! + + test('Initialize services', async () => { + // begin-common + //!!! Start of custom content to be copied !!! + ibmAnalyticsEngineApiService = IbmAnalyticsEngineApiV3.newInstance(options); + expect(ibmAnalyticsEngineApiService).not.toBeNull(); + // !!! End of custom content to be copied !!! + // end-common + }); + + //!!! Start of custom content to be copied !!! test('getInstance request example', (done) => { + // !!! End of custom content to be copied !!! consoleLogMock.mockImplementation((output) => { originalLog(output); + //!!! Start of custom content to be copied !!! done(); + // !!! End of custom content to be copied !!! }); consoleWarnMock.mockImplementation((output) => { - done(output); + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! }); originalLog('getInstance() result:'); // begin-get_instance const params = { - instanceId: 'e64c907a-e82f-46fd-addc-ccfafbd28b09', + instanceId: instanceGuid, }; - + //!!! Start of custom content to be copied !!! ibmAnalyticsEngineApiService .getInstance(params) - .then((res) => { + .then((res)=>{ console.log(JSON.stringify(res.result, null, 2)); }) .catch((err) => { console.warn(err); - }); - + }); + // let res; + // try { + // res = await ibmAnalyticsEngineApiService.getInstance(params); + // console.log(JSON.stringify(res.result, null, 2)); + // } catch (err) { + // console.warn(err); + // } + // !!! End of custom content to be copied !!! // end-get_instance }); - test('createApplication request example', (done) => { + + //!!! Start of custom content to be copied !!! + test('getInstanceState request example', (done) => { + // !!! End of custom content to be copied !!! consoleLogMock.mockImplementation((output) => { originalLog(output); + //!!! Start of custom content to be copied !!! done(); + // !!! End of custom content to be copied !!! }); consoleWarnMock.mockImplementation((output) => { - done(output); + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! }); - originalLog('createApplication() result:'); - // begin-create_application + originalLog('getInstanceState() result:'); + // begin-get_instance_state const params = { - instanceId: 'e64c907a-e82f-46fd-addc-ccfafbd28b09', + instanceId: instanceGuid, }; - + //!!! Start of custom content to be copied !!! ibmAnalyticsEngineApiService - .createApplication(params) - .then((res) => { + .getInstanceState(params) + .then((res)=>{ console.log(JSON.stringify(res.result, null, 2)); }) - .catch((err) => { + .catch((err)=>{ console.warn(err); }); + // let res; + // try { + // res = await ibmAnalyticsEngineApiService.getInstanceState(params); + // console.log(JSON.stringify(res.result, null, 2)); + // } catch (err) { + // console.warn(err); + // } + // !!! End of custom content to be copied !!! + // end-get_instance_state + }); + + //!!! Start of custom content to be copied !!! + test('setInstanceHome request example', (done) => { + // !!! End of custom content to be copied !!! + consoleLogMock.mockImplementation((output) => { + originalLog(output); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! + }); + + originalLog('setInstanceHome() result:'); + // begin-set_instance_home + //!!! Start of custom content to be copied !!! + const params = { + instanceId: instanceIdInstanceHome, + newInstanceId: 'testString', + newProvider: 'ibm-cos', + newType: 'objectstore', + newRegion: 'us-south', + newEndpoint: 's3.direct.us-south.cloud-object-storage.appdomain.cloud', + newHmacAccessKey: hmacAccessKey, + newHmacSecretKey: hmacSecretKey, + }; + // !!! End of custom content to be copied !!! + //!!! Start of custom content to be copied !!! + ibmAnalyticsEngineApiService + .setInstanceHome(params) + .then((res)=>{ + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch((err)=>{ + console.warn(err); + }) + // let res; + // try { + // res = await ibmAnalyticsEngineApiService.createInstanceHome(params); + // console.log(JSON.stringify(res.result, null, 2)); + // } catch (err) { + // console.warn(err); + // } + // !!! End of custom content to be copied !!! + // end-set_instance_home + }); + + //!!! Start of custom content to be copied !!! + test('createApplication request example', (done) => { + // !!! End of custom content to be copied !!! + consoleLogMock.mockImplementation((output) => { + originalLog(output); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! + }); + + originalLog('createApplication() result:'); + // begin-create_application + //!!! Start of custom content to be copied !!! + const applicationRequestApplicationDetailsModel = { + application: '/opt/ibm/spark/examples/src/main/python/wordcount.py', + arguments: ['/opt/ibm/spark/examples/src/main/resources/people.txt'], + }; + const params = { + instanceId: instanceGuid, + applicationDetails: applicationRequestApplicationDetailsModel, + }; + + ibmAnalyticsEngineApiService + .createApplication(params) + .then((res) => { + applicationId=res.result.id + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch ((err) => { + console.warn(err); + }) + // let res; + // try { + // res = await ibmAnalyticsEngineApiService.createApplication(params); + // console.log(JSON.stringify(res.result, null, 2)); + // } catch (err) { + // console.warn(err); + // } + // !!! End of custom content to be copied !!! // end-create_application }); + + //!!! Start of custom content to be copied !!! test('listApplications request example', (done) => { + // !!! End of custom content to be copied !!! consoleLogMock.mockImplementation((output) => { originalLog(output); + //!!! Start of custom content to be copied !!! done(); + // !!! End of custom content to be copied !!! }); consoleWarnMock.mockImplementation((output) => { - done(output); + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! }); originalLog('listApplications() result:'); // begin-list_applications const params = { - instanceId: 'e64c907a-e82f-46fd-addc-ccfafbd28b09', + instanceId: instanceGuid, }; - ibmAnalyticsEngineApiService - .listApplications(params) + //!!! Start of custom content to be copied !!! + ibmAnalyticsEngineApiService. + listApplications(params) .then((res) => { console.log(JSON.stringify(res.result, null, 2)); }) .catch((err) => { console.warn(err); }); - + // let res; + // try { + // res = await ibmAnalyticsEngineApiService.listApplications(params); + // console.log(JSON.stringify(res.result, null, 2)); + // } catch (err) { + // console.warn(err); + // } + // !!! End of custom content to be copied !!! // end-list_applications }); + + //!!! Start of custom content to be copied !!! test('getApplication request example', (done) => { + // !!! End of custom content to be copied !!! consoleLogMock.mockImplementation((output) => { originalLog(output); + //!!! Start of custom content to be copied !!! done(); + // !!! End of custom content to be copied !!! }); consoleWarnMock.mockImplementation((output) => { - done(output); + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! }); originalLog('getApplication() result:'); // begin-get_application const params = { - instanceId: 'e64c907a-e82f-46fd-addc-ccfafbd28b09', - applicationId: 'ff48cc19-0e7e-4627-aac6-0b4ad080397b', + instanceId: instanceGuid, + applicationId: applicationId, }; - + //!!! Start of custom content to be copied !!! ibmAnalyticsEngineApiService - .getApplication(params) - .then((res) => { - console.log(JSON.stringify(res.result, null, 2)); - }) - .catch((err) => { - console.warn(err); - }); + .getApplication(params) + .then((res) => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch((err) => { + console.warn(err); + }); + // let res; + // try { + // res = await ibmAnalyticsEngineApiService.getApplication(params); + // console.log(JSON.stringify(res.result, null, 2)); + // } catch (err) { + // console.warn(err); + // } + // !!! End of custom content to be copied !!! // end-get_application }); + + //!!! Start of custom content to be copied !!! test('getApplicationState request example', (done) => { - consoleLogMock.mockImplementation((output) => { + // !!! End of custom content to be copied !!! + consoleLogMock.mockImplementation((output) => { originalLog(output); + //!!! Start of custom content to be copied !!! done(); + // !!! End of custom content to be copied !!! }); consoleWarnMock.mockImplementation((output) => { - done(output); + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! }); originalLog('getApplicationState() result:'); // begin-get_application_state const params = { - instanceId: 'e64c907a-e82f-46fd-addc-ccfafbd28b09', - applicationId: 'ff48cc19-0e7e-4627-aac6-0b4ad080397b', + instanceId: instanceGuid, + applicationId: applicationId, + }; + //!!! Start of custom content to be copied !!! + ibmAnalyticsEngineApiService + .getApplicationState(params) + .then((res) => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch((err) => { + console.warn(err); + }); + // let res; + // try { + // res = await ibmAnalyticsEngineApiService.getApplicationState(params); + // console.log(JSON.stringify(res.result, null, 2)); + // } catch (err) { + // console.warn(err); + // } + // !!! End of custom content to be copied !!! + // end-get_application_state + }); + + //!!! Start of custom content to be copied !!! + test('configurePlatformLogging request example', (done) => { + // !!! End of custom content to be copied !!! + consoleLogMock.mockImplementation((output) => { + originalLog(output); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! + }); + + originalLog('configurePlatformLogging() result:'); + // begin-configure_platform_logging + + const params = { + instanceGuid: instanceGuid, + enable: true, }; + //!!! Start of custom content to be copied !!! + ibmAnalyticsEngineApiService + .configurePlatformLogging(params) + .then((res) => { + console.log(res); + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch((err) => { + console.warn(err); + }); + // let res; + // try { + // res = await ibmAnalyticsEngineApiService.configurePlatformLogging(params); + // console.log(JSON.stringify(res.result, null, 2)); + // } catch (err) { + // console.warn(err); + // } + // !!! End of custom content to be copied !!! + // end-configure_platform_logging + }); + + //!!! Start of custom content to be copied !!! + test('getLoggingConfiguration request example', (done) => { + // !!! End of custom content to be copied !!! + consoleLogMock.mockImplementation((output) => { + originalLog(output); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! + }); + + originalLog('getLoggingConfiguration() result:'); + // begin-get_logging_configuration + const params = { + instanceGuid: instanceGuid, + }; + //!!! Start of custom content to be copied !!! ibmAnalyticsEngineApiService - .getApplicationState(params) - .then((res) => { - console.log(JSON.stringify(res.result, null, 2)); - }) - .catch((err) => { - console.warn(err); - }); + .getLoggingConfiguration(params) + .then((res) => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch((err) => { + console.warn(err); + }); + // let res; + // try { + // res = await ibmAnalyticsEngineApiService.getLoggingConfiguration(params); + // console.log(JSON.stringify(res.result, null, 2)); + // } catch (err) { + // console.warn(err); + // } + // end-configure_platform_logging + // end-get_logging_configuration + }); - // end-get_application_state + //!!! Start of custom content to be copied !!! + test('startSparkHistoryServer request example', (done) => { + // !!! End of custom content to be copied !!! + consoleLogMock.mockImplementation((output) => { + originalLog(output); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! + }); + + originalLog('startSparkHistoryServer() result:'); + // begin-start_spark_history_server + + const params = { + instanceId: instanceGuid, + }; + //!!! Start of custom content to be copied !!! + ibmAnalyticsEngineApiService + .startSparkHistoryServer(params) + .then((res) => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch((err) => { + console.warn(err); + }); + // let res; + // try { + // res = await ibmAnalyticsEngineApiService.startSparkHistoryServer(params); + // console.log(JSON.stringify(res.result, null, 2)); + // } catch (err) { + // console.warn(err); + // } + // !!! End of custom content to be copied !!! + // end-start_spark_history_server + }); + + //!!! Start of custom content to be copied !!! + test('getSparkHistoryServer request example', (done) => { + // !!! End of custom content to be copied !!! + consoleLogMock.mockImplementation((output) => { + originalLog(output); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! + }); + + originalLog('getSparkHistoryServer() result:'); + // begin-get_spark_history_server + + const params = { + instanceId: instanceGuid, + }; + //!!! Start of custom content to be copied !!! + ibmAnalyticsEngineApiService + .getSparkHistoryServer(params) + .then((res) => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch((err) => { + console.warn(err); + }); + // let res; + // try { + // res = await ibmAnalyticsEngineApiService.getSparkHistoryServer(params); + // console.log(JSON.stringify(res.result, null, 2)); + // } catch (err) { + // console.warn(err); + // } + // !!! End of custom content to be copied !!! + // end-get_spark_history_server }); + + //!!! Start of custom content to be copied !!! + test('stopSparkHistoryServer request example', (done) => { + // !!! End of custom content to be copied !!! + consoleLogMock.mockImplementation((output) => { + originalLog(output); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! + }); + + // begin-stop_spark_history_server + + const params = { + instanceId: instanceGuid, + }; + //!!! Start of custom content to be copied !!! + ibmAnalyticsEngineApiService + .stopSparkHistoryServer(params) + .then((res) => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch((err) => { + console.warn(err); + }); + // try { + // await ibmAnalyticsEngineApiService.stopSparkHistoryServer(params); + // } catch (err) { + // console.warn(err); + // } + // !!! End of custom content to be copied !!! + // end-stop_spark_history_server + }); + + //!!! Start of custom content to be copied !!! test('deleteApplication request example', (done) => { + // !!! End of custom content to be copied !!! consoleLogMock.mockImplementation((output) => { originalLog(output); + //!!! Start of custom content to be copied !!! done(); + // !!! End of custom content to be copied !!! }); consoleWarnMock.mockImplementation((output) => { - done(output); + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + //!!! Start of custom content to be copied !!! + done(); + // !!! End of custom content to be copied !!! }); // begin-delete_application const params = { - instanceId: 'e64c907a-e82f-46fd-addc-ccfafbd28b09', - applicationId: 'ff48cc19-0e7e-4627-aac6-0b4ad080397b', + instanceId: instanceGuid, + applicationId: applicationId, }; + //!!! Start of custom content to be copied !!! ibmAnalyticsEngineApiService - .deleteApplication(params) - .then((res) => { - done(); - }) - .catch((err) => { - console.warn(err); - }); - + .deleteApplication(params) + .then((res) => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch((err) => { + console.warn(err); + }); + // try { + // await ibmAnalyticsEngineApiService.deleteApplication(params); + // } catch (err) { + // console.warn(err); + // } + // !!! End of custom content to be copied !!! // end-delete_application }); }); diff --git a/ibm-analytics-engine-api/v3.ts b/ibm-analytics-engine-api/v3.ts index 9e6ab80..a4859c9 100644 --- a/ibm-analytics-engine-api/v3.ts +++ b/ibm-analytics-engine-api/v3.ts @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2021. + * (C) Copyright IBM Corp. 2022. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ */ /** - * IBM OpenAPI SDK Code Generator Version: 3.38.0-07189efd-20210827-205025 + * IBM OpenAPI SDK Code Generator Version: 3.49.0-be9b22fb-20220504-154308 */ import * as extend from 'extend'; @@ -24,7 +24,10 @@ import { Authenticator, BaseService, getAuthenticatorFromEnvironment, + // !!! Start of custom content to be copied !!! + // validateParams, getMissingParams, + // !!! End of custom content to be copied !!! UserOptions, } from 'ibm-cloud-sdk-core'; import { getSdkHeaders } from '../lib/common'; @@ -40,6 +43,16 @@ class IbmAnalyticsEngineApiV3 extends BaseService { static DEFAULT_SERVICE_NAME: string = 'ibm_analytics_engine_api'; + /** + * Returns the service URL associated with the specified region. + * @param region a string representing the region + * @returns the service URL associated with the specified region or undefined + * if no mapping for the region exists + */ + public static getServiceUrlForRegion(region: string): string { + return this._regionalEndpoints.get(region) + } + /************************* * Factory method ************************/ @@ -71,6 +84,11 @@ class IbmAnalyticsEngineApiV3 extends BaseService { return service; } + private static _regionalEndpoints = new Map([ + ['us-south', 'https://api.us-south.ae.cloud.ibm.com'], + ['eu-de', 'https://api.eu-de.ae.cloud.ibm.com'], + ]); + /** * Construct a IbmAnalyticsEngineApiV3 object. * @@ -110,11 +128,18 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.GetInstanceParams ): Promise> { const _params = { ...params }; + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceId']; const missingParams = getMissingParams(_params, requiredParams); if (missingParams) { return Promise.reject(missingParams); + // const _requiredParams = ['instanceId']; + // const _validParams = ['instanceId', 'headers']; + // const _validationErrors = validateParams(_params, _requiredParams, _validParams); + // if (_validationErrors) { + // return Promise.reject(_validationErrors); + // !!! End of custom content to be copied !!! } const path = { @@ -148,6 +173,145 @@ class IbmAnalyticsEngineApiV3 extends BaseService { return this.createRequest(parameters); } + /** + * Find Analytics Engine state by id. + * + * Retrieve the state of a single Analytics Engine instance. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.instanceId - GUID of the Analytics Engine service instance to retrieve state. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getInstanceState( + params: IbmAnalyticsEngineApiV3.GetInstanceStateParams + ): Promise> { + const _params = { ...params }; + // !!! Start of custom content to be copied !!! + const requiredParams = ['instanceId']; + + const missingParams = getMissingParams(_params, requiredParams); + if (missingParams) { + return Promise.reject(missingParams); + // const _requiredParams = ['instanceId']; + // const _validParams = ['instanceId', 'headers']; + // const _validationErrors = validateParams(_params, _requiredParams, _validParams); + // if (_validationErrors) { + // return Promise.reject(_validationErrors); + // !!! End of custom content to be copied !!! + } + + const path = { + 'instance_id': _params.instanceId, + }; + + const sdkHeaders = getSdkHeaders( + IbmAnalyticsEngineApiV3.DEFAULT_SERVICE_NAME, + 'v3', + 'getInstanceState' + ); + + const parameters = { + options: { + url: '/v3/analytics_engines/{instance_id}/state', + method: 'GET', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Set instance home. + * + * Provide the details of the Cloud Object Storage instance to associate with the Analytics Engine instance and use as + * 'instance home' if 'instance home' has not already been set. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.instanceId - GUID of the Analytics Engine instance for which 'instance home' is to be set. + * @param {string} [params.newInstanceId] - UUID of the instance home storage instance. + * @param {string} [params.newProvider] - Currently only ibm-cos (IBM Cloud Object Storage) is supported. + * @param {string} [params.newType] - Type of the instance home storage. Currently, only objectstore (Cloud Object + * Storage) is supported. + * @param {string} [params.newRegion] - Region of the Cloud Object Storage instance. + * @param {string} [params.newEndpoint] - Endpoint to access the Cloud Object Storage instance. + * @param {string} [params.newHmacAccessKey] - Cloud Object Storage access key. + * @param {string} [params.newHmacSecretKey] - Cloud Object Storage secret key. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public setInstanceHome( + params: IbmAnalyticsEngineApiV3.SetInstanceHomeParams + ): Promise> { + const _params = { ...params }; + // !!! Start of custom content to be copied !!! + const requiredParams = ['instanceId']; + + const missingParams = getMissingParams(_params, requiredParams); + if (missingParams) { + return Promise.reject(missingParams); + // const _requiredParams = ['instanceId']; + // const _validParams = ['instanceId', 'newInstanceId', 'newProvider', 'newType', 'newRegion', 'newEndpoint', 'newHmacAccessKey', 'newHmacSecretKey', 'headers']; + // const _validationErrors = validateParams(_params, _requiredParams, _validParams); + // if (_validationErrors) { + // return Promise.reject(_validationErrors); + // !!! End of custom content to be copied !!! + } + + const body = { + 'instance_id': _params.newInstanceId, + 'provider': _params.newProvider, + 'type': _params.newType, + 'region': _params.newRegion, + 'endpoint': _params.newEndpoint, + 'hmac_access_key': _params.newHmacAccessKey, + 'hmac_secret_key': _params.newHmacSecretKey, + }; + + const path = { + 'instance_id': _params.instanceId, + }; + + const sdkHeaders = getSdkHeaders( + IbmAnalyticsEngineApiV3.DEFAULT_SERVICE_NAME, + 'v3', + 'setInstanceHome' + ); + + const parameters = { + options: { + url: '/v3/analytics_engines/{instance_id}/instance_home', + method: 'PUT', + body, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + /** * Deploy a Spark application. * @@ -163,11 +327,18 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.CreateApplicationParams ): Promise> { const _params = { ...params }; + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceId']; const missingParams = getMissingParams(_params, requiredParams); if (missingParams) { return Promise.reject(missingParams); + // const _requiredParams = ['instanceId']; + // const _validParams = ['instanceId', 'applicationDetails', 'headers']; + // const _validationErrors = validateParams(_params, _requiredParams, _validParams); + // if (_validationErrors) { + // return Promise.reject(_validationErrors); + // !!! End of custom content to be copied !!! } const body = { @@ -210,7 +381,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { /** * Retrieve all Spark applications. * - * Gets all applications submitted in an instance with a specified inst_id. + * Gets all applications submitted in an instance with a specified instance-id. * * @param {Object} params - The parameters to send to the service. * @param {string} params.instanceId - Identifier of the instance where the applications run. @@ -221,11 +392,20 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.ListApplicationsParams ): Promise> { const _params = { ...params }; + // !!! Start of custom content to be copied !!! + const requiredParams = ['instanceId']; const missingParams = getMissingParams(_params, requiredParams); if (missingParams) { return Promise.reject(missingParams); + + // const _requiredParams = ['instanceId']; + // const _validParams = ['instanceId', 'headers']; + // const _validationErrors = validateParams(_params, _requiredParams, _validParams); + // if (_validationErrors) { + // return Promise.reject(_validationErrors); + // !!! End of custom content to be copied !!! } const path = { @@ -262,7 +442,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { /** * Retrieve the details of a given Spark application. * - * Gets the details of the given Spark application. + * Gets the details of a given Spark application. * * @param {Object} params - The parameters to send to the service. * @param {string} params.instanceId - Identifier of the instance to which the application belongs. @@ -274,11 +454,18 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.GetApplicationParams ): Promise> { const _params = { ...params }; + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceId', 'applicationId']; const missingParams = getMissingParams(_params, requiredParams); if (missingParams) { return Promise.reject(missingParams); + // const _requiredParams = ['instanceId', 'applicationId']; + // const _validParams = ['instanceId', 'applicationId', 'headers']; + // const _validationErrors = validateParams(_params, _requiredParams, _validParams); + // if (_validationErrors) { + // return Promise.reject(_validationErrors); + // !!! End of custom content to be copied !!! } const path = { @@ -329,11 +516,18 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.DeleteApplicationParams ): Promise> { const _params = { ...params }; + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceId', 'applicationId']; const missingParams = getMissingParams(_params, requiredParams); if (missingParams) { return Promise.reject(missingParams); + // const _requiredParams = ['instanceId', 'applicationId']; + // const _validParams = ['instanceId', 'applicationId', 'headers']; + // const _validationErrors = validateParams(_params, _requiredParams, _validParams); + // if (_validationErrors) { + // return Promise.reject(_validationErrors); + // !!! End of custom content to be copied !!! } const path = { @@ -382,11 +576,18 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.GetApplicationStateParams ): Promise> { const _params = { ...params }; + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceId', 'applicationId']; const missingParams = getMissingParams(_params, requiredParams); if (missingParams) { return Promise.reject(missingParams); + // const _requiredParams = ['instanceId', 'applicationId']; + // const _validParams = ['instanceId', 'applicationId', 'headers']; + // const _validationErrors = validateParams(_params, _requiredParams, _validParams); + // if (_validationErrors) { + // return Promise.reject(_validationErrors); + // !!! End of custom content to be copied !!! } const path = { @@ -420,6 +621,310 @@ class IbmAnalyticsEngineApiV3 extends BaseService { return this.createRequest(parameters); } + + /** + * Enable or disable log forwarding. + * + * Enable or disable log forwarding from IBM Analytics Engine to IBM Log Analysis server. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.instanceGuid - GUID of the instance details for which log forwarding is to be configured. + * @param {boolean} [params.enable] - Enable or disable log forwarding. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public configurePlatformLogging( + params: IbmAnalyticsEngineApiV3.ConfigurePlatformLoggingParams + ): Promise> { + const _params = { ...params }; + // !!! Start of custom content to be copied !!! + const requiredParams = ['instanceGuid']; + + const missingParams = getMissingParams(_params, requiredParams); + if (missingParams) { + return Promise.reject(missingParams); + // const _requiredParams = ['instanceGuid']; + // const _validParams = ['instanceGuid', 'enable', 'headers']; + // const _validationErrors = validateParams(_params, _requiredParams, _validParams); + // if (_validationErrors) { + // return Promise.reject(_validationErrors); + // !!! End of custom content to be copied !!! + } + + const body = { + 'enable': _params.enable, + }; + + const path = { + 'instance_guid': _params.instanceGuid, + }; + + const sdkHeaders = getSdkHeaders( + IbmAnalyticsEngineApiV3.DEFAULT_SERVICE_NAME, + 'v3', + 'configurePlatformLogging' + ); + + const parameters = { + options: { + url: '/v3/analytics_engines/{instance_guid}/logging', + method: 'PUT', + body, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Retrieve the logging configuration for a given instance id. + * + * Retrieve the logging configuration of a given Analytics Engine instance. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.instanceGuid - GUID of the Analytics Engine service instance to retrieve log configuration. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getLoggingConfiguration( + params: IbmAnalyticsEngineApiV3.GetLoggingConfigurationParams + ): Promise> { + const _params = { ...params }; + // !!! Start of custom content to be copied !!! + const requiredParams = ['instanceGuid']; + + const missingParams = getMissingParams(_params, requiredParams); + if (missingParams) { + return Promise.reject(missingParams); + // const _requiredParams = ['instanceGuid']; + // const _validParams = ['instanceGuid', 'headers']; + // const _validationErrors = validateParams(_params, _requiredParams, _validParams); + // if (_validationErrors) { + // return Promise.reject(_validationErrors); + // !!! End of custom content to be copied !!! + } + + const path = { + 'instance_guid': _params.instanceGuid, + }; + + const sdkHeaders = getSdkHeaders( + IbmAnalyticsEngineApiV3.DEFAULT_SERVICE_NAME, + 'v3', + 'getLoggingConfiguration' + ); + + const parameters = { + options: { + url: '/v3/analytics_engines/{instance_guid}/logging', + method: 'GET', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Start Spark history server. + * + * Start the Spark history server for the given Analytics Engine instance. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.instanceId - The ID of the Analytics Engine instance whose Spark history server is to be + * started. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public startSparkHistoryServer( + params: IbmAnalyticsEngineApiV3.StartSparkHistoryServerParams + ): Promise> { + const _params = { ...params }; + // !!! Start of custom content to be copied !!! + const requiredParams = ['instanceId']; + + const missingParams = getMissingParams(_params, requiredParams); + if (missingParams) { + return Promise.reject(missingParams); + // const _requiredParams = ['instanceId']; + // const _validParams = ['instanceId', 'headers']; + // const _validationErrors = validateParams(_params, _requiredParams, _validParams); + // if (_validationErrors) { + // return Promise.reject(_validationErrors); + // !!! End of custom content to be copied !!! + } + + const path = { + 'instance_id': _params.instanceId, + }; + + const sdkHeaders = getSdkHeaders( + IbmAnalyticsEngineApiV3.DEFAULT_SERVICE_NAME, + 'v3', + 'startSparkHistoryServer' + ); + + const parameters = { + options: { + url: '/v3/analytics_engines/{instance_id}/spark_history_server', + method: 'POST', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Retrieve Spark history server details. + * + * Get the details of the Spark history server of the given Analytics Engine instance. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.instanceId - The ID of the Analytics Engine instance to which the Spark history server + * belongs. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getSparkHistoryServer( + params: IbmAnalyticsEngineApiV3.GetSparkHistoryServerParams + ): Promise> { + const _params = { ...params }; + // !!! Start of custom content to be copied !!! + const requiredParams = ['instanceId']; + + const missingParams = getMissingParams(_params, requiredParams); + if (missingParams) { + return Promise.reject(missingParams); + // const _requiredParams = ['instanceId']; + // const _validParams = ['instanceId', 'headers']; + // const _validationErrors = validateParams(_params, _requiredParams, _validParams); + // if (_validationErrors) { + // return Promise.reject(_validationErrors); + // !!! End of custom content to be copied !!! + } + + const path = { + 'instance_id': _params.instanceId, + }; + + const sdkHeaders = getSdkHeaders( + IbmAnalyticsEngineApiV3.DEFAULT_SERVICE_NAME, + 'v3', + 'getSparkHistoryServer' + ); + + const parameters = { + options: { + url: '/v3/analytics_engines/{instance_id}/spark_history_server', + method: 'GET', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Stop Spark history server. + * + * Stop the Spark history server of the given Analytics Engine instance. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.instanceId - The ID of the Analytics Engine instance whose Spark history server is to be + * stopped. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public stopSparkHistoryServer( + params: IbmAnalyticsEngineApiV3.StopSparkHistoryServerParams + ): Promise> { + const _params = { ...params }; + // !!! Start of custom content to be copied !!! + const requiredParams = ['instanceId']; + + const missingParams = getMissingParams(_params, requiredParams); + if (missingParams) { + return Promise.reject(missingParams); + // const _requiredParams = ['instanceId']; + // const _validParams = ['instanceId', 'headers']; + // const _validationErrors = validateParams(_params, _requiredParams, _validParams); + // if (_validationErrors) { + // return Promise.reject(_validationErrors); + // !!! End of custom content to be copied !!! + } + + const path = { + 'instance_id': _params.instanceId, + }; + + const sdkHeaders = getSdkHeaders( + IbmAnalyticsEngineApiV3.DEFAULT_SERVICE_NAME, + 'v3', + 'stopSparkHistoryServer' + ); + + const parameters = { + options: { + url: '/v3/analytics_engines/{instance_id}/spark_history_server', + method: 'DELETE', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } } /************************* @@ -457,6 +962,34 @@ namespace IbmAnalyticsEngineApiV3 { headers?: OutgoingHttpHeaders; } + /** Parameters for the `getInstanceState` operation. */ + export interface GetInstanceStateParams { + /** GUID of the Analytics Engine service instance to retrieve state. */ + instanceId: string; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `setInstanceHome` operation. */ + export interface SetInstanceHomeParams { + /** GUID of the Analytics Engine instance for which 'instance home' is to be set. */ + instanceId: string; + /** UUID of the instance home storage instance. */ + newInstanceId?: string; + /** Currently only ibm-cos (IBM Cloud Object Storage) is supported. */ + newProvider?: string; + /** Type of the instance home storage. Currently, only objectstore (Cloud Object Storage) is supported. */ + newType?: string; + /** Region of the Cloud Object Storage instance. */ + newRegion?: string; + /** Endpoint to access the Cloud Object Storage instance. */ + newEndpoint?: string; + /** Cloud Object Storage access key. */ + newHmacAccessKey?: string; + /** Cloud Object Storage secret key. */ + newHmacSecretKey?: string; + headers?: OutgoingHttpHeaders; + } + /** Parameters for the `createApplication` operation. */ export interface CreateApplicationParams { /** The identifier of the instance where the Spark application is submitted. */ @@ -500,6 +1033,43 @@ namespace IbmAnalyticsEngineApiV3 { headers?: OutgoingHttpHeaders; } + /** Parameters for the `configurePlatformLogging` operation. */ + export interface ConfigurePlatformLoggingParams { + /** GUID of the instance details for which log forwarding is to be configured. */ + instanceGuid: string; + /** Enable or disable log forwarding. */ + enable?: boolean; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `getLoggingConfiguration` operation. */ + export interface GetLoggingConfigurationParams { + /** GUID of the Analytics Engine service instance to retrieve log configuration. */ + instanceGuid: string; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `startSparkHistoryServer` operation. */ + export interface StartSparkHistoryServerParams { + /** The ID of the Analytics Engine instance whose Spark history server is to be started. */ + instanceId: string; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `getSparkHistoryServer` operation. */ + export interface GetSparkHistoryServerParams { + /** The ID of the Analytics Engine instance to which the Spark history server belongs. */ + instanceId: string; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `stopSparkHistoryServer` operation. */ + export interface StopSparkHistoryServerParams { + /** The ID of the Analytics Engine instance whose Spark history server is to be stopped. */ + instanceId: string; + headers?: OutgoingHttpHeaders; + } + /************************* * model interfaces ************************/ @@ -526,10 +1096,44 @@ namespace IbmAnalyticsEngineApiV3 { applications?: Application[]; } + /** Application details. */ + export interface ApplicationDetails { + /** Path of the application to run. */ + application?: string; + /** Path of the jar files containing the application. */ + jars?: string; + /** Package names. */ + packages?: string; + /** Repositories names. */ + repositories?: string; + /** File names. */ + files?: string; + /** Archive Names. */ + archives?: string; + /** Name of the application. */ + name?: string; + /** Entry point for a Spark application bundled as a '.jar' file. This is applicable only for Java or Scala + * applications. + */ + class?: string; + /** An array of arguments to be passed to the application. */ + arguments?: string[]; + /** Application configurations to override the value specified at instance level. See [Spark environment + * variables]( https://spark.apache.org/docs/latest/configuration.html#available-properties) for a list of the + * supported variables. + */ + conf?: JsonObject; + /** Application environment configurations to use. See [Spark environment + * variables](https://spark.apache.org/docs/latest/configuration.html#environment-variables) for a list of the + * supported variables. + */ + env?: JsonObject; + } + /** Response of the Application Get API. */ export interface ApplicationGetResponse { - /** Application request details. */ - application_details?: ApplicationRequest; + /** Application details. */ + application_details?: ApplicationDetails; /** Application ID. */ id?: string; /** Application state. */ @@ -552,16 +1156,22 @@ namespace IbmAnalyticsEngineApiV3 { finish_time?: string; } - /** Application request details. */ - export interface ApplicationRequest { - /** Application details. */ - application_details?: ApplicationRequestApplicationDetails; - } - /** Application details. */ export interface ApplicationRequestApplicationDetails { /** Path of the application to run. */ application?: string; + /** Path of the jar files containing the application. */ + jars?: string; + /** Package names. */ + packages?: string; + /** Repositories names. */ + repositories?: string; + /** File names. */ + files?: string; + /** Archive Names. */ + archives?: string; + /** Name of the application. */ + name?: string; /** Entry point for a Spark application bundled as a '.jar' file. This is applicable only for Java or Scala * applications. */ @@ -618,6 +1228,14 @@ namespace IbmAnalyticsEngineApiV3 { spark_version?: string; } + /** State details of Analytics Engine instance. */ + export interface InstanceGetStateResponse { + /** GUID of the Analytics Engine instance. */ + id?: string; + /** Instance state. */ + state?: string; + } + /** Object storage instance that acts as the home for custom libraries and Spark events. */ export interface InstanceHome { /** UUID of the instance home storage instance. */ @@ -637,6 +1255,66 @@ namespace IbmAnalyticsEngineApiV3 { /** Cloud Object Storage secret key. Masked for security reasons. */ hmac_secret_key?: string; } + + /** Response of Instance home API. */ + export interface InstanceHomeResponse { + /** UUID of the instance home storage instance. */ + instance_id?: string; + /** Currently only ibm-cos (IBM Cloud Object Storage) is supported. */ + provider?: string; + /** Type of the instance home storage. Currently, only objectstore (Cloud Object Storage) is supported. */ + type?: string; + /** Region of the Cloud Object Storage instance. */ + region?: string; + /** Endpoint to access the Cloud Object Storage instance. */ + endpoint?: string; + /** Cloud Object Storage access key. */ + hmac_access_key?: string; + /** Cloud Object Storage secret key. */ + hmac_secret_key?: string; + } + + /** Response of logging API. */ + export interface LoggingConfigurationResponse { + /** component array. */ + components?: string[]; + /** log server properties. */ + log_server?: LoggingConfigurationResponseLogServer; + /** enable. */ + enable?: boolean; + } + + /** log server properties. */ + export interface LoggingConfigurationResponseLogServer { + /** type of log server. */ + type?: string; + } + + /** State of the Spark history server. */ + export interface SparkHistoryServerResponse { + /** State of the Spark history server. */ + state?: string; + /** Number of cpu cores used by the Spark history server. */ + cores?: string; + /** Amount of memory used by the Spark history server. */ + memory?: string; + /** Time when the Spark history server was started. */ + start_time?: string; + /** Time when the Spark history server was stopped. */ + stop_time?: string; + } + + /** Response of the request to start the Spark history server. */ + export interface SparkHistoryServerStartResponse { + /** State of the Spark history server. */ + state?: string; + /** Number of cpu cores used by the Spark history server. */ + cores?: string; + /** Amount of memory used by the Spark history server. */ + memory?: string; + /** Time when the Spark history server was started. */ + start_time?: string; + } } export = IbmAnalyticsEngineApiV3; diff --git a/test/HOW_TO_TEST.md b/test/HOW_TO_TEST.md deleted file mode 100644 index 8ee64bd..0000000 --- a/test/HOW_TO_TEST.md +++ /dev/null @@ -1,24 +0,0 @@ -# How to run tests - -## Pre-requisites -1. Change to this packages root directory. -1. Install jest. - ``` - npm install jest - ``` -1. Build the package. - ``` - npm run build - ``` - -## Integration Tests - -1. Create a `auth.js` file in the `ibm-iae-node-sdk/test/resources` directory using `ibm-iae-node-sdk/test/resources/auth.example.js` as an example. -1. Update `auth.js` file with your own **Service URL**, **APIKEY** and **INSTANCE GUID**. -1. Go to `/test/integartion/` directory. -1. Run `jest ibm-analytics-engine-api.v2.test.js`. - -## Unit Tests - -1. Go to `/test/unit/` directory. -1. Run `jest ibm-analytics-engine-api.v2.test.js`. \ No newline at end of file diff --git a/test/integration/ibm-analytics-engine-api.v3.test.js b/test/integration/ibm-analytics-engine-api.v3.test.js index aa4c5d6..2260185 100644 --- a/test/integration/ibm-analytics-engine-api.v3.test.js +++ b/test/integration/ibm-analytics-engine-api.v3.test.js @@ -1,6 +1,5 @@ -/* eslint-disable no-console */ /** - * (C) Copyright IBM Corp. 2021. + * (C) Copyright IBM Corp. 2022. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,32 +14,52 @@ * limitations under the License. */ +/* eslint-disable no-console */ + const IbmAnalyticsEngineApiV3 = require('../../dist/ibm-analytics-engine-api/v3'); const { readExternalSources } = require('ibm-cloud-sdk-core'); +// !!! Start of custom content to be copied !!! +// Replace auth-helper.js with auth.js for integration testing const authHelper = require('../resources/auth-helper.js'); -// const authHelper = require('../resources/auth.js'); +const { IamAuthenticator } = require('../../dist/auth'); +// !!! End of custom content to be copied !!! // testcase timeout value (200s). const timeout = 200000; -const { IamAuthenticator } = require('../../dist/auth'); + +// !!! Start of custom content to be copied !!! // Location of our config file. // const configFile = 'ibm_analytics_engine_api_v3.env'; - // const describe = authHelper.prepareTests(configFile); +// !!! End of custom content to be copied !!! describe('IbmAnalyticsEngineApiV3_integration', () => { + // !!! Start of custom content to be copied !!! + // Assignment of configuration variables from auth.js const options = authHelper.ibm_analytics_engine_api_v3; - options.authenticator = new IamAuthenticator({ apikey: options.apikey }); + options.authenticator = new IamAuthenticator({ apikey: options.apikey, url: options.apiAuthUrl }); const instanceGuid = options.instance_guid; + const instanceIdInstanceHome = options.instance_guid_instance_home; let applicationId = ''; - const ibmAnalyticsEngineApiService = IbmAnalyticsEngineApiV3.newInstance(options); + const hmacAccessKey = options.newHmacAccessKey; + const hmacSecretKey = options.newHmacSecretKey; + // !!! End of custom content to be copied !!! - expect(ibmAnalyticsEngineApiService).not.toBeNull(); + jest.setTimeout(timeout); - const config = readExternalSources(IbmAnalyticsEngineApiV3.DEFAULT_SERVICE_NAME); - expect(config).not.toBeNull(); + // Service instance + let ibmAnalyticsEngineApiService; - jest.setTimeout(timeout); + test('Initialise service', async () => { + // !!! Start of custom content to be copied !!! + ibmAnalyticsEngineApiService = IbmAnalyticsEngineApiV3.newInstance(options); + // !!! End of custom content to be copied !!! + expect(ibmAnalyticsEngineApiService).not.toBeNull(); + + const config = readExternalSources(IbmAnalyticsEngineApiV3.DEFAULT_SERVICE_NAME); + expect(config).not.toBeNull(); + // ibmAnalyticsEngineApiService.enableRetries(); + }); test('getInstance()', async () => { const params = { @@ -51,6 +70,53 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { expect(res.status).toBe(200); expect(res.result).toBeDefined(); + // + // The following status codes aren't covered by tests. + // Please provide integration tests for these too. + // + // 401 + // 403 + // 404 + // 500 + // + }); + test('getInstanceState()', async () => { + const params = { + instanceId: instanceGuid, + }; + + const res = await ibmAnalyticsEngineApiService.getInstanceState(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + + // + // The following status codes aren't covered by tests. + // Please provide integration tests for these too. + // + // 401 + // 403 + // 404 + // 500 + // + }); + test('setInstanceHome()', async () => { + const params = { + instanceId: instanceIdInstanceHome, + newInstanceId: 'testString', + newProvider: 'ibm-cos', + newType: 'objectstore', + newRegion: 'us-south', + newEndpoint: 's3.direct.us-south.cloud-object-storage.appdomain.cloud', + newHmacAccessKey: hmacAccessKey, + newHmacSecretKey: hmacSecretKey, + }; + + const res = await ibmAnalyticsEngineApiService.setInstanceHome(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + // // The following status codes aren't covered by tests. // Please provide integration tests for these too. @@ -59,6 +125,7 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { // 401 // 403 // 404 + // 409 // 500 // }); @@ -67,13 +134,17 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { // ApplicationRequestApplicationDetails const applicationRequestApplicationDetailsModel = { - // application: 'cos://bucket_name.my_cos/my_spark_app.py', - // class: 'com.company.path.ClassName', - // arguments: ['[arg1, arg2, arg3]'], - // conf: { spark.driver.cores: '1', spark.driver.memory: '4G' }, - // env: { SPARK_ENV_LOADED: '2' }, application: '/opt/ibm/spark/examples/src/main/python/wordcount.py', + // jars: 'cos://cloud-object-storage/jars/tests.jar', + // packages: 'testString', + // repositories: 'testString', + // files: 'testString', + // archives: 'testString', + // name: 'spark-app', + // class: 'com.company.path.ClassName', arguments: ['/opt/ibm/spark/examples/src/main/resources/people.txt'], + // conf: { 'spark.driver.cores': '1', 'spark.driver.memory': '4G' }, + // env: { SPARK_ENV_LOADED: '2' }, }; const params = { @@ -82,7 +153,9 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { }; const res = await ibmAnalyticsEngineApiService.createApplication(params); + // !!! Start of custom content to be copied !!! applicationId = res.result.id; + // !!! End of custom content to be copied !!! expect(res).toBeDefined(); expect(res.status).toBe(202); expect(res.result).toBeDefined(); @@ -112,7 +185,6 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { // The following status codes aren't covered by tests. // Please provide integration tests for these too. // - // 400 // 401 // 403 // 404 @@ -134,7 +206,6 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { // The following status codes aren't covered by tests. // Please provide integration tests for these too. // - // 400 // 401 // 403 // 404 @@ -152,6 +223,110 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { expect(res.status).toBe(200); expect(res.result).toBeDefined(); + // + // The following status codes aren't covered by tests. + // Please provide integration tests for these too. + // + // 401 + // 403 + // 404 + // 500 + // + }); + test('configurePlatformLogging()', async () => { + const params = { + instanceGuid: instanceGuid, + enable: true, + }; + + const res = await ibmAnalyticsEngineApiService.configurePlatformLogging(params); + expect(res).toBeDefined(); + expect(res.status).toBe(201); + expect(res.result).toBeDefined(); + + // + // The following status codes aren't covered by tests. + // Please provide integration tests for these too. + // + // 400 + // 401 + // 403 + // 404 + // 500 + // + }); + test('getLoggingConfiguration()', async () => { + const params = { + instanceGuid: instanceGuid, + }; + + const res = await ibmAnalyticsEngineApiService.getLoggingConfiguration(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + + // + // The following status codes aren't covered by tests. + // Please provide integration tests for these too. + // + // 401 + // 403 + // 404 + // 500 + // + }); + test('startSparkHistoryServer()', async () => { + const params = { + instanceId: instanceGuid, + }; + + const res = await ibmAnalyticsEngineApiService.startSparkHistoryServer(params); + expect(res).toBeDefined(); + expect(res.status).toBe(201); + expect(res.result).toBeDefined(); + + // + // The following status codes aren't covered by tests. + // Please provide integration tests for these too. + // + // 400 + // 401 + // 403 + // 404 + // 500 + // + }); + test('getSparkHistoryServer()', async () => { + const params = { + instanceId: instanceGuid, + }; + + const res = await ibmAnalyticsEngineApiService.getSparkHistoryServer(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + + // + // The following status codes aren't covered by tests. + // Please provide integration tests for these too. + // + // 400 + // 401 + // 403 + // 404 + // 500 + // + }); + test('stopSparkHistoryServer()', async () => { + const params = { + instanceId: instanceGuid, + }; + + const res = await ibmAnalyticsEngineApiService.stopSparkHistoryServer(params); + expect(res).toBeDefined(); + expect(res.status).toBe(204); + expect(res.result).toBeDefined(); + // // The following status codes aren't covered by tests. // Please provide integration tests for these too. diff --git a/test/resources/auth.example.js b/test/resources/auth.example.js index 5f0a2ad..0396d91 100644 --- a/test/resources/auth.example.js +++ b/test/resources/auth.example.js @@ -24,6 +24,12 @@ module.exports = { ibm_analytics_engine_api_v2: { serviceUrl: '', apikey: '', + apiAuthUrl: '', instance_guid: '', + instance_guid_instance_home: '', + instance_guid_example: '', + instance_guid_example_instance_home: '', + newHmacAccessKey: '', + newHmacSecretKey: '', }, }; diff --git a/test/unit/ibm-analytics-engine-api.v3.test.js b/test/unit/ibm-analytics-engine-api.v3.test.js index 0524207..3ef9a86 100644 --- a/test/unit/ibm-analytics-engine-api.v3.test.js +++ b/test/unit/ibm-analytics-engine-api.v3.test.js @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2021. + * (C) Copyright IBM Corp. 2022. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -97,16 +97,29 @@ describe('IbmAnalyticsEngineApiV3', () => { expect(testInstance.baseOptions.serviceUrl).toBe(IbmAnalyticsEngineApiV3.DEFAULT_SERVICE_URL); }); }); + describe('getServiceUrlForRegion', () => { + test('should return undefined for invalid region', () => { + expect(IbmAnalyticsEngineApiV3.getServiceUrlForRegion('INVALID_REGION')).toBeFalsy(); + }); + test('should return valid service url', () => { + expect(IbmAnalyticsEngineApiV3.getServiceUrlForRegion('us-south')).toBe( + 'https://api.us-south.ae.cloud.ibm.com' + ); + expect(IbmAnalyticsEngineApiV3.getServiceUrlForRegion('eu-de')).toBe( + 'https://api.eu-de.ae.cloud.ibm.com' + ); + }); + }); describe('getInstance', () => { describe('positive tests', () => { - test('should pass the right params to createRequest', () => { + function __getInstanceTest() { // Construct the params object for operation getInstance const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; - const params = { + const getInstanceParams = { instanceId: instanceId, }; - const getInstanceResult = ibmAnalyticsEngineApiService.getInstance(params); + const getInstanceResult = ibmAnalyticsEngineApiService.getInstance(getInstanceParams); // all methods should return a Promise expectToBePromise(getInstanceResult); @@ -121,6 +134,25 @@ describe('IbmAnalyticsEngineApiV3', () => { const expectedContentType = undefined; checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); expect(mockRequestOptions.path.instance_id).toEqual(instanceId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getInstanceTest(); + + // enable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.enableRetries(); + // !!! End of custom content to be copied !!! + __getInstanceTest(); + + // disable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.disableRetries(); + // !!! End of custom content to be copied !!! + __getInstanceTest(); }); test('should prioritize user-given headers', () => { @@ -128,7 +160,7 @@ describe('IbmAnalyticsEngineApiV3', () => { const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; const userAccept = 'fake/accept'; const userContentType = 'fake/contentType'; - const params = { + const getInstanceParams = { instanceId, headers: { Accept: userAccept, @@ -136,13 +168,13 @@ describe('IbmAnalyticsEngineApiV3', () => { }, }; - ibmAnalyticsEngineApiService.getInstance(params); + ibmAnalyticsEngineApiService.getInstance(getInstanceParams); checkMediaHeaders(createRequestMock, userAccept, userContentType); }); }); describe('negative tests', () => { - test('should enforce required parameters', async done => { + test('should enforce required parameters', async () => { let err; try { await ibmAnalyticsEngineApiService.getInstance({}); @@ -151,17 +183,220 @@ describe('IbmAnalyticsEngineApiV3', () => { } expect(err.message).toMatch(/Missing required parameters/); - done(); }); - test('should reject promise when required params are not given', done => { - const getInstancePromise = ibmAnalyticsEngineApiService.getInstance(); - expectToBePromise(getInstancePromise); + test('should reject promise when required params are not given', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.getInstance(); + } catch (e) { + err = e; + } - getInstancePromise.catch(err => { - expect(err.message).toMatch(/Missing required parameters/); - done(); - }); + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + describe('getInstanceState', () => { + describe('positive tests', () => { + function __getInstanceStateTest() { + // Construct the params object for operation getInstanceState + const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; + const getInstanceStateParams = { + instanceId: instanceId, + }; + + const getInstanceStateResult = ibmAnalyticsEngineApiService.getInstanceState( + getInstanceStateParams + ); + + // all methods should return a Promise + expectToBePromise(getInstanceStateResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v3/analytics_engines/{instance_id}/state', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.instance_id).toEqual(instanceId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getInstanceStateTest(); + + // enable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.enableRetries(); + // !!! End of custom content to be copied !!! + __getInstanceStateTest(); + + // disable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.disableRetries(); + // !!! End of custom content to be copied !!! + __getInstanceStateTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getInstanceStateParams = { + instanceId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + ibmAnalyticsEngineApiService.getInstanceState(getInstanceStateParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.getInstanceState({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.getInstanceState(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + describe('setInstanceHome', () => { + describe('positive tests', () => { + function __setInstanceHomeTest() { + // Construct the params object for operation setInstanceHome + const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; + const newInstanceId = 'testString'; + const newProvider = 'ibm-cos'; + const newType = 'objectstore'; + const newRegion = 'us-south'; + const newEndpoint = 's3.direct.us-south.cloud-object-storage.appdomain.cloud'; + const newHmacAccessKey = '821**********0ae'; + const newHmacSecretKey = '03e****************4fc3'; + const setInstanceHomeParams = { + instanceId: instanceId, + newInstanceId: newInstanceId, + newProvider: newProvider, + newType: newType, + newRegion: newRegion, + newEndpoint: newEndpoint, + newHmacAccessKey: newHmacAccessKey, + newHmacSecretKey: newHmacSecretKey, + }; + + const setInstanceHomeResult = ibmAnalyticsEngineApiService.setInstanceHome( + setInstanceHomeParams + ); + + // all methods should return a Promise + expectToBePromise(setInstanceHomeResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod( + mockRequestOptions, + '/v3/analytics_engines/{instance_id}/instance_home', + 'PUT' + ); + const expectedAccept = 'application/json'; + const expectedContentType = 'application/json'; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.body.instance_id).toEqual(newInstanceId); + expect(mockRequestOptions.body.provider).toEqual(newProvider); + expect(mockRequestOptions.body.type).toEqual(newType); + expect(mockRequestOptions.body.region).toEqual(newRegion); + expect(mockRequestOptions.body.endpoint).toEqual(newEndpoint); + expect(mockRequestOptions.body.hmac_access_key).toEqual(newHmacAccessKey); + expect(mockRequestOptions.body.hmac_secret_key).toEqual(newHmacSecretKey); + expect(mockRequestOptions.path.instance_id).toEqual(instanceId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __setInstanceHomeTest(); + + // enable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.enableRetries(); + // !!! End of custom content to be copied !!! + __setInstanceHomeTest(); + + // disable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.disableRetries(); + // !!! End of custom content to be copied !!! + __setInstanceHomeTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const setInstanceHomeParams = { + instanceId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + ibmAnalyticsEngineApiService.setInstanceHome(setInstanceHomeParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.setInstanceHome({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.setInstanceHome(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); }); }); }); @@ -172,22 +407,30 @@ describe('IbmAnalyticsEngineApiV3', () => { // ApplicationRequestApplicationDetails const applicationRequestApplicationDetailsModel = { application: 'cos://bucket_name.my_cos/my_spark_app.py', + jars: 'cos://cloud-object-storage/jars/tests.jar', + packages: 'testString', + repositories: 'testString', + files: 'testString', + archives: 'testString', + name: 'spark-app', class: 'com.company.path.ClassName', arguments: ['[arg1, arg2, arg3]'], conf: { 'key1': 'testString' }, env: { 'key1': 'testString' }, }; - test('should pass the right params to createRequest', () => { + function __createApplicationTest() { // Construct the params object for operation createApplication const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; const applicationDetails = applicationRequestApplicationDetailsModel; - const params = { + const createApplicationParams = { instanceId: instanceId, applicationDetails: applicationDetails, }; - const createApplicationResult = ibmAnalyticsEngineApiService.createApplication(params); + const createApplicationResult = ibmAnalyticsEngineApiService.createApplication( + createApplicationParams + ); // all methods should return a Promise expectToBePromise(createApplicationResult); @@ -207,6 +450,25 @@ describe('IbmAnalyticsEngineApiV3', () => { checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); expect(mockRequestOptions.body.application_details).toEqual(applicationDetails); expect(mockRequestOptions.path.instance_id).toEqual(instanceId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __createApplicationTest(); + + // enable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.enableRetries(); + // !!! End of custom content to be copied !!! + __createApplicationTest(); + + // disable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.disableRetries(); + // !!! End of custom content to be copied !!! + __createApplicationTest(); }); test('should prioritize user-given headers', () => { @@ -214,7 +476,7 @@ describe('IbmAnalyticsEngineApiV3', () => { const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; const userAccept = 'fake/accept'; const userContentType = 'fake/contentType'; - const params = { + const createApplicationParams = { instanceId, headers: { Accept: userAccept, @@ -222,13 +484,13 @@ describe('IbmAnalyticsEngineApiV3', () => { }, }; - ibmAnalyticsEngineApiService.createApplication(params); + ibmAnalyticsEngineApiService.createApplication(createApplicationParams); checkMediaHeaders(createRequestMock, userAccept, userContentType); }); }); describe('negative tests', () => { - test('should enforce required parameters', async done => { + test('should enforce required parameters', async () => { let err; try { await ibmAnalyticsEngineApiService.createApplication({}); @@ -237,30 +499,32 @@ describe('IbmAnalyticsEngineApiV3', () => { } expect(err.message).toMatch(/Missing required parameters/); - done(); }); - test('should reject promise when required params are not given', done => { - const createApplicationPromise = ibmAnalyticsEngineApiService.createApplication(); - expectToBePromise(createApplicationPromise); + test('should reject promise when required params are not given', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.createApplication(); + } catch (e) { + err = e; + } - createApplicationPromise.catch(err => { - expect(err.message).toMatch(/Missing required parameters/); - done(); - }); + expect(err.message).toMatch(/Missing required parameters/); }); }); }); describe('listApplications', () => { describe('positive tests', () => { - test('should pass the right params to createRequest', () => { + function __listApplicationsTest() { // Construct the params object for operation listApplications const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; - const params = { + const listApplicationsParams = { instanceId: instanceId, }; - const listApplicationsResult = ibmAnalyticsEngineApiService.listApplications(params); + const listApplicationsResult = ibmAnalyticsEngineApiService.listApplications( + listApplicationsParams + ); // all methods should return a Promise expectToBePromise(listApplicationsResult); @@ -279,6 +543,25 @@ describe('IbmAnalyticsEngineApiV3', () => { const expectedContentType = undefined; checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); expect(mockRequestOptions.path.instance_id).toEqual(instanceId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __listApplicationsTest(); + + // enable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.enableRetries(); + // !!! End of custom content to be copied !!! + __listApplicationsTest(); + + // disable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.disableRetries(); + // !!! End of custom content to be copied !!! + __listApplicationsTest(); }); test('should prioritize user-given headers', () => { @@ -286,7 +569,7 @@ describe('IbmAnalyticsEngineApiV3', () => { const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; const userAccept = 'fake/accept'; const userContentType = 'fake/contentType'; - const params = { + const listApplicationsParams = { instanceId, headers: { Accept: userAccept, @@ -294,13 +577,13 @@ describe('IbmAnalyticsEngineApiV3', () => { }, }; - ibmAnalyticsEngineApiService.listApplications(params); + ibmAnalyticsEngineApiService.listApplications(listApplicationsParams); checkMediaHeaders(createRequestMock, userAccept, userContentType); }); }); describe('negative tests', () => { - test('should enforce required parameters', async done => { + test('should enforce required parameters', async () => { let err; try { await ibmAnalyticsEngineApiService.listApplications({}); @@ -309,32 +592,34 @@ describe('IbmAnalyticsEngineApiV3', () => { } expect(err.message).toMatch(/Missing required parameters/); - done(); }); - test('should reject promise when required params are not given', done => { - const listApplicationsPromise = ibmAnalyticsEngineApiService.listApplications(); - expectToBePromise(listApplicationsPromise); + test('should reject promise when required params are not given', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.listApplications(); + } catch (e) { + err = e; + } - listApplicationsPromise.catch(err => { - expect(err.message).toMatch(/Missing required parameters/); - done(); - }); + expect(err.message).toMatch(/Missing required parameters/); }); }); }); describe('getApplication', () => { describe('positive tests', () => { - test('should pass the right params to createRequest', () => { + function __getApplicationTest() { // Construct the params object for operation getApplication const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; const applicationId = 'ff48cc19-0e7e-4627-aac6-0b4ad080397b'; - const params = { + const getApplicationParams = { instanceId: instanceId, applicationId: applicationId, }; - const getApplicationResult = ibmAnalyticsEngineApiService.getApplication(params); + const getApplicationResult = ibmAnalyticsEngineApiService.getApplication( + getApplicationParams + ); // all methods should return a Promise expectToBePromise(getApplicationResult); @@ -354,6 +639,25 @@ describe('IbmAnalyticsEngineApiV3', () => { checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); expect(mockRequestOptions.path.instance_id).toEqual(instanceId); expect(mockRequestOptions.path.application_id).toEqual(applicationId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getApplicationTest(); + + // enable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.enableRetries(); + // !!! End of custom content to be copied !!! + __getApplicationTest(); + + // disable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.disableRetries(); + // !!! End of custom content to be copied !!! + __getApplicationTest(); }); test('should prioritize user-given headers', () => { @@ -362,7 +666,7 @@ describe('IbmAnalyticsEngineApiV3', () => { const applicationId = 'ff48cc19-0e7e-4627-aac6-0b4ad080397b'; const userAccept = 'fake/accept'; const userContentType = 'fake/contentType'; - const params = { + const getApplicationParams = { instanceId, applicationId, headers: { @@ -371,13 +675,13 @@ describe('IbmAnalyticsEngineApiV3', () => { }, }; - ibmAnalyticsEngineApiService.getApplication(params); + ibmAnalyticsEngineApiService.getApplication(getApplicationParams); checkMediaHeaders(createRequestMock, userAccept, userContentType); }); }); describe('negative tests', () => { - test('should enforce required parameters', async done => { + test('should enforce required parameters', async () => { let err; try { await ibmAnalyticsEngineApiService.getApplication({}); @@ -386,32 +690,34 @@ describe('IbmAnalyticsEngineApiV3', () => { } expect(err.message).toMatch(/Missing required parameters/); - done(); }); - test('should reject promise when required params are not given', done => { - const getApplicationPromise = ibmAnalyticsEngineApiService.getApplication(); - expectToBePromise(getApplicationPromise); + test('should reject promise when required params are not given', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.getApplication(); + } catch (e) { + err = e; + } - getApplicationPromise.catch(err => { - expect(err.message).toMatch(/Missing required parameters/); - done(); - }); + expect(err.message).toMatch(/Missing required parameters/); }); }); }); describe('deleteApplication', () => { describe('positive tests', () => { - test('should pass the right params to createRequest', () => { + function __deleteApplicationTest() { // Construct the params object for operation deleteApplication const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; const applicationId = 'ff48cc19-0e7e-4627-aac6-0b4ad080397b'; - const params = { + const deleteApplicationParams = { instanceId: instanceId, applicationId: applicationId, }; - const deleteApplicationResult = ibmAnalyticsEngineApiService.deleteApplication(params); + const deleteApplicationResult = ibmAnalyticsEngineApiService.deleteApplication( + deleteApplicationParams + ); // all methods should return a Promise expectToBePromise(deleteApplicationResult); @@ -431,6 +737,25 @@ describe('IbmAnalyticsEngineApiV3', () => { checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); expect(mockRequestOptions.path.instance_id).toEqual(instanceId); expect(mockRequestOptions.path.application_id).toEqual(applicationId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __deleteApplicationTest(); + + // enable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.enableRetries(); + // !!! End of custom content to be copied !!! + __deleteApplicationTest(); + + // disable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.disableRetries(); + // !!! End of custom content to be copied !!! + __deleteApplicationTest(); }); test('should prioritize user-given headers', () => { @@ -439,7 +764,7 @@ describe('IbmAnalyticsEngineApiV3', () => { const applicationId = 'ff48cc19-0e7e-4627-aac6-0b4ad080397b'; const userAccept = 'fake/accept'; const userContentType = 'fake/contentType'; - const params = { + const deleteApplicationParams = { instanceId, applicationId, headers: { @@ -448,13 +773,13 @@ describe('IbmAnalyticsEngineApiV3', () => { }, }; - ibmAnalyticsEngineApiService.deleteApplication(params); + ibmAnalyticsEngineApiService.deleteApplication(deleteApplicationParams); checkMediaHeaders(createRequestMock, userAccept, userContentType); }); }); describe('negative tests', () => { - test('should enforce required parameters', async done => { + test('should enforce required parameters', async () => { let err; try { await ibmAnalyticsEngineApiService.deleteApplication({}); @@ -463,32 +788,34 @@ describe('IbmAnalyticsEngineApiV3', () => { } expect(err.message).toMatch(/Missing required parameters/); - done(); }); - test('should reject promise when required params are not given', done => { - const deleteApplicationPromise = ibmAnalyticsEngineApiService.deleteApplication(); - expectToBePromise(deleteApplicationPromise); + test('should reject promise when required params are not given', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.deleteApplication(); + } catch (e) { + err = e; + } - deleteApplicationPromise.catch(err => { - expect(err.message).toMatch(/Missing required parameters/); - done(); - }); + expect(err.message).toMatch(/Missing required parameters/); }); }); }); describe('getApplicationState', () => { describe('positive tests', () => { - test('should pass the right params to createRequest', () => { + function __getApplicationStateTest() { // Construct the params object for operation getApplicationState const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; const applicationId = 'ff48cc19-0e7e-4627-aac6-0b4ad080397b'; - const params = { + const getApplicationStateParams = { instanceId: instanceId, applicationId: applicationId, }; - const getApplicationStateResult = ibmAnalyticsEngineApiService.getApplicationState(params); + const getApplicationStateResult = ibmAnalyticsEngineApiService.getApplicationState( + getApplicationStateParams + ); // all methods should return a Promise expectToBePromise(getApplicationStateResult); @@ -508,6 +835,25 @@ describe('IbmAnalyticsEngineApiV3', () => { checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); expect(mockRequestOptions.path.instance_id).toEqual(instanceId); expect(mockRequestOptions.path.application_id).toEqual(applicationId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getApplicationStateTest(); + + // enable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.enableRetries(); + // !!! End of custom content to be copied !!! + __getApplicationStateTest(); + + // disable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.disableRetries(); + // !!! End of custom content to be copied !!! + __getApplicationStateTest(); }); test('should prioritize user-given headers', () => { @@ -516,7 +862,7 @@ describe('IbmAnalyticsEngineApiV3', () => { const applicationId = 'ff48cc19-0e7e-4627-aac6-0b4ad080397b'; const userAccept = 'fake/accept'; const userContentType = 'fake/contentType'; - const params = { + const getApplicationStateParams = { instanceId, applicationId, headers: { @@ -525,13 +871,13 @@ describe('IbmAnalyticsEngineApiV3', () => { }, }; - ibmAnalyticsEngineApiService.getApplicationState(params); + ibmAnalyticsEngineApiService.getApplicationState(getApplicationStateParams); checkMediaHeaders(createRequestMock, userAccept, userContentType); }); }); describe('negative tests', () => { - test('should enforce required parameters', async done => { + test('should enforce required parameters', async () => { let err; try { await ibmAnalyticsEngineApiService.getApplicationState({}); @@ -540,17 +886,485 @@ describe('IbmAnalyticsEngineApiV3', () => { } expect(err.message).toMatch(/Missing required parameters/); - done(); }); - test('should reject promise when required params are not given', done => { - const getApplicationStatePromise = ibmAnalyticsEngineApiService.getApplicationState(); - expectToBePromise(getApplicationStatePromise); + test('should reject promise when required params are not given', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.getApplicationState(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + describe('configurePlatformLogging', () => { + describe('positive tests', () => { + function __configurePlatformLoggingTest() { + // Construct the params object for operation configurePlatformLogging + const instanceGuid = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; + const enable = true; + const configurePlatformLoggingParams = { + instanceGuid: instanceGuid, + enable: enable, + }; + + const configurePlatformLoggingResult = ibmAnalyticsEngineApiService.configurePlatformLogging( + configurePlatformLoggingParams + ); + + // all methods should return a Promise + expectToBePromise(configurePlatformLoggingResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod( + mockRequestOptions, + '/v3/analytics_engines/{instance_guid}/logging', + 'PUT' + ); + const expectedAccept = 'application/json'; + const expectedContentType = 'application/json'; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.body.enable).toEqual(enable); + expect(mockRequestOptions.path.instance_guid).toEqual(instanceGuid); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __configurePlatformLoggingTest(); + + // enable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.enableRetries(); + // !!! End of custom content to be copied !!! + __configurePlatformLoggingTest(); + + // disable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.disableRetries(); + // !!! End of custom content to be copied !!! + __configurePlatformLoggingTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const instanceGuid = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const configurePlatformLoggingParams = { + instanceGuid, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + ibmAnalyticsEngineApiService.configurePlatformLogging(configurePlatformLoggingParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.configurePlatformLogging({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.configurePlatformLogging(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + describe('getLoggingConfiguration', () => { + describe('positive tests', () => { + function __getLoggingConfigurationTest() { + // Construct the params object for operation getLoggingConfiguration + const instanceGuid = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; + const getLoggingConfigurationParams = { + instanceGuid: instanceGuid, + }; + + const getLoggingConfigurationResult = ibmAnalyticsEngineApiService.getLoggingConfiguration( + getLoggingConfigurationParams + ); + + // all methods should return a Promise + expectToBePromise(getLoggingConfigurationResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod( + mockRequestOptions, + '/v3/analytics_engines/{instance_guid}/logging', + 'GET' + ); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.instance_guid).toEqual(instanceGuid); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getLoggingConfigurationTest(); + + // enable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.enableRetries(); + // !!! End of custom content to be copied !!! + __getLoggingConfigurationTest(); + + // disable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.disableRetries(); + // !!! End of custom content to be copied !!! + __getLoggingConfigurationTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const instanceGuid = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getLoggingConfigurationParams = { + instanceGuid, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + ibmAnalyticsEngineApiService.getLoggingConfiguration(getLoggingConfigurationParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.getLoggingConfiguration({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.getLoggingConfiguration(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + describe('startSparkHistoryServer', () => { + describe('positive tests', () => { + function __startSparkHistoryServerTest() { + // Construct the params object for operation startSparkHistoryServer + const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; + const startSparkHistoryServerParams = { + instanceId: instanceId, + }; + + const startSparkHistoryServerResult = ibmAnalyticsEngineApiService.startSparkHistoryServer( + startSparkHistoryServerParams + ); + + // all methods should return a Promise + expectToBePromise(startSparkHistoryServerResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod( + mockRequestOptions, + '/v3/analytics_engines/{instance_id}/spark_history_server', + 'POST' + ); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.instance_id).toEqual(instanceId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __startSparkHistoryServerTest(); + + // enable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.enableRetries(); + // !!! End of custom content to be copied !!! + __startSparkHistoryServerTest(); + + // disable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.disableRetries(); + // !!! End of custom content to be copied !!! + __startSparkHistoryServerTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const startSparkHistoryServerParams = { + instanceId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + ibmAnalyticsEngineApiService.startSparkHistoryServer(startSparkHistoryServerParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.startSparkHistoryServer({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.startSparkHistoryServer(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + describe('getSparkHistoryServer', () => { + describe('positive tests', () => { + function __getSparkHistoryServerTest() { + // Construct the params object for operation getSparkHistoryServer + const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; + const getSparkHistoryServerParams = { + instanceId: instanceId, + }; - getApplicationStatePromise.catch(err => { - expect(err.message).toMatch(/Missing required parameters/); - done(); - }); + const getSparkHistoryServerResult = ibmAnalyticsEngineApiService.getSparkHistoryServer( + getSparkHistoryServerParams + ); + + // all methods should return a Promise + expectToBePromise(getSparkHistoryServerResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod( + mockRequestOptions, + '/v3/analytics_engines/{instance_id}/spark_history_server', + 'GET' + ); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.instance_id).toEqual(instanceId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getSparkHistoryServerTest(); + + // enable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.enableRetries(); + // !!! End of custom content to be copied !!! + __getSparkHistoryServerTest(); + + // disable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.disableRetries(); + // !!! End of custom content to be copied !!! + __getSparkHistoryServerTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getSparkHistoryServerParams = { + instanceId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + ibmAnalyticsEngineApiService.getSparkHistoryServer(getSparkHistoryServerParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.getSparkHistoryServer({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.getSparkHistoryServer(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + describe('stopSparkHistoryServer', () => { + describe('positive tests', () => { + function __stopSparkHistoryServerTest() { + // Construct the params object for operation stopSparkHistoryServer + const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; + const stopSparkHistoryServerParams = { + instanceId: instanceId, + }; + + const stopSparkHistoryServerResult = ibmAnalyticsEngineApiService.stopSparkHistoryServer( + stopSparkHistoryServerParams + ); + + // all methods should return a Promise + expectToBePromise(stopSparkHistoryServerResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod( + mockRequestOptions, + '/v3/analytics_engines/{instance_id}/spark_history_server', + 'DELETE' + ); + const expectedAccept = undefined; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.instance_id).toEqual(instanceId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __stopSparkHistoryServerTest(); + + // enable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.enableRetries(); + // !!! End of custom content to be copied !!! + __stopSparkHistoryServerTest(); + + // disable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.disableRetries(); + // !!! End of custom content to be copied !!! + __stopSparkHistoryServerTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const stopSparkHistoryServerParams = { + instanceId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + ibmAnalyticsEngineApiService.stopSparkHistoryServer(stopSparkHistoryServerParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.stopSparkHistoryServer({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.stopSparkHistoryServer(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); }); }); });