From 2f7426932d756ef04acede525010f370cc71c967 Mon Sep 17 00:00:00 2001 From: silpidhua Date: Thu, 3 Mar 2022 11:30:15 +0530 Subject: [PATCH 1/5] feat: Added Spark history server apis feat: Added Spark history server apis --- test/HOW_TO_TEST.md => HOW_TO_TEST.md | 2 +- examples/ibm-analytics-engine-api.v3.test.js | 620 +++++++++- ibm-analytics-engine-api/v3.ts | 767 +++++++++++- .../ibm-analytics-engine-api.v3.test.js | 238 +++- test/resources/auth.example.js | 6 + test/unit/ibm-analytics-engine-api.v3.test.js | 1077 +++++++++++++++-- 6 files changed, 2532 insertions(+), 178 deletions(-) rename test/HOW_TO_TEST.md => HOW_TO_TEST.md (93%) diff --git a/test/HOW_TO_TEST.md b/HOW_TO_TEST.md similarity index 93% rename from test/HOW_TO_TEST.md rename to HOW_TO_TEST.md index 8ee64bd..071e898 100644 --- a/test/HOW_TO_TEST.md +++ b/HOW_TO_TEST.md @@ -14,7 +14,7 @@ ## 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. Update `auth.js` file with your own **Service URL**, **APIKEY**, **INSTANCE GUID** and other details. 1. Go to `/test/integartion/` directory. 1. Run `jest ibm-analytics-engine-api.v2.test.js`. diff --git a/examples/ibm-analytics-engine-api.v3.test.js b/examples/ibm-analytics-engine-api.v3.test.js index 588dfe4..4a9b476 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 -const authHelper = require('../test/resources/auth-helper.js'); + +//!!! Start of custom content to be copied !!! +// const authHelper = require('../resources/auth-helper.js'); +const authHelper = require('../test/resources/auth.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,674 @@ 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 - // 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 !!! + let ibmAnalyticsEngineApiService; + + 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('createInstanceHome 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('createInstanceHome() result:'); + // begin-create_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 + .createInstanceHome(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-create_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 - .getApplicationState(params) - .then((res) => { - console.log(JSON.stringify(res.result, null, 2)); - }) - .catch((err) => { - console.warn(err); - }); + .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 + }); - // end-get_application_state + //!!! 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 + .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 }); + + // //!!! 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('deleteLoggingConfiguration 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-delete_logging_configuration + + const params = { + instanceGuid: instanceGuid, + }; + //!!! Start of custom content to be copied !!! + ibmAnalyticsEngineApiService + .deleteLoggingConfiguration(params) + .then((res) => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch((err) => { + console.warn(err); + }); + // try { + // await ibmAnalyticsEngineApiService.deleteLoggingConfiguration(params); + // } catch (err) { + // console.warn(err); + // } + // !!! End of custom content to be copied !!! + // end-delete_logging_configuration + }); + + //!!! 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..1f9a0a4 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.45.1-632ec580-20220210-190638 */ 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,21 @@ class IbmAnalyticsEngineApiV3 extends BaseService { static DEFAULT_SERVICE_NAME: string = 'ibm_analytics_engine_api'; + 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'], + ]); + + /** + * 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 ************************/ @@ -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,146 @@ 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); + } + + /** + * Edit instance home details. + * + * Update details of the Object Storage associated as 'instance home' for an Analytics Engine instance. + * + * @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 + * updated. + * @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 createInstanceHome( + params: IbmAnalyticsEngineApiV3.CreateInstanceHomeParams + ): 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', + 'createInstanceHome' + ); + + 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 +328,19 @@ 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 +383,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 +394,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 +444,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 +456,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 +518,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 +578,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 +623,366 @@ class IbmAnalyticsEngineApiV3 extends BaseService { return this.createRequest(parameters); } + + /** + * Enable or disable log fowarding. + * + * 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); + } + + /** + * Delete logging configuration of a given instance id. + * + * Delete 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 instance for which log configuration is to be deleted. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public deleteLoggingConfiguration( + params: IbmAnalyticsEngineApiV3.DeleteLoggingConfigurationParams + ): 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', + 'deleteLoggingConfiguration' + ); + + const parameters = { + options: { + url: '/v3/analytics_engines/{instance_guid}/logging', + method: 'DELETE', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Start Spark history server. + * + * Start the Spark history server for a given serverless Spark instance. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.instanceId - The identifier of the instance for which the Spark history server is 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 by ID. + * + * Retrieve the Spark history server details for an Analytics Engine instance by the instance ID. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.instanceId - The identifier of the instance for which the Spark history server is started. + * @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 for a given serverless Spark instance. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.instanceId - The identifier of the instance for which the Spark history server is 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 +1020,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 `createInstanceHome` operation. */ + export interface CreateInstanceHomeParams { + /** GUID of the Analytics Engine instance for which 'instance home' is to be updated. */ + 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 +1091,50 @@ 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 `deleteLoggingConfiguration` operation. */ + export interface DeleteLoggingConfigurationParams { + /** GUID of the instance for which log configuration is to be deleted. */ + instanceGuid: string; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `startSparkHistoryServer` operation. */ + export interface StartSparkHistoryServerParams { + /** The identifier of the instance for which the Spark history server is started. */ + instanceId: string; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `getSparkHistoryServer` operation. */ + export interface GetSparkHistoryServerParams { + /** The identifier of the instance for which the Spark history server is started. */ + instanceId: string; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `stopSparkHistoryServer` operation. */ + export interface StopSparkHistoryServerParams { + /** The identifier of the instance for which the Spark history server is stopped. */ + instanceId: string; + headers?: OutgoingHttpHeaders; + } + /************************* * model interfaces ************************/ @@ -526,10 +1161,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 +1221,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 +1293,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 +1320,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 Spark history server. */ + export interface SparkHistoryServerResponse { + /** State of Spark history server. */ + state?: string; + /** Number of cores used for the Spark history server. */ + cores?: string; + /** Memory used for 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; + } + + /** Spark history server started response. */ + export interface SparkHistoryServerStartResponse { + /** State of Spark history server. */ + state?: string; + /** Number of cores used for the Spark history server. */ + cores?: string; + /** Memory used for the Spark history server. */ + memory?: string; + /** Time when the Spark history server was started. */ + start_time?: string; + } } export = IbmAnalyticsEngineApiV3; diff --git a/test/integration/ibm-analytics-engine-api.v3.test.js b/test/integration/ibm-analytics-engine-api.v3.test.js index aa4c5d6..5d9db63 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,37 +14,59 @@ * limitations under the License. */ +/* eslint-disable no-console */ + const IbmAnalyticsEngineApiV3 = require('../../dist/ibm-analytics-engine-api/v3'); const { readExternalSources } = require('ibm-cloud-sdk-core'); -const authHelper = require('../resources/auth-helper.js'); -// const authHelper = require('../resources/auth.js'); + +// !!! Start of custom content to be copied !!! +// 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 !!! 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(); + 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 = { instanceId: instanceGuid, }; + const res = await ibmAnalyticsEngineApiService.getInstance(params); expect(res).toBeDefined(); expect(res.status).toBe(200); @@ -62,18 +83,71 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { // 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. + // + // 400 + // 401 + // 403 + // 404 + // 500 + // + }); + test('createInstanceHome()', 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.createInstanceHome(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('createApplication()', async () => { // Request models needed by this operation. // 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 +156,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(); @@ -163,6 +239,136 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { // 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. + // + // 400 + // 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(); + // console.log('startSparkHistoryServer'); + // console.log(res); + // // + // // 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(); + // console.log('getSparkHistoryServer'); + // console.log(res); + // // + // // 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(); + // console.log('stopSparkHistoryServer'); + // console.log(res); + // // + // // The following status codes aren't covered by tests. + // // Please provide integration tests for these too. + // // + // // 400 + // // 401 + // // 403 + // // 404 + // // 500 + // // + // }); + test('deleteLoggingConfiguration()', async () => { + const params = { + instanceGuid: instanceGuid, + }; + + const res = await ibmAnalyticsEngineApiService.deleteLoggingConfiguration(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. + // + // 400 + // 401 + // 403 + // 404 + // 500 + // + }); test('deleteApplication()', async () => { const params = { instanceId: instanceGuid, 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..ab28c73 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('createInstanceHome', () => { + describe('positive tests', () => { + function __createInstanceHomeTest() { + // Construct the params object for operation createInstanceHome + 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 createInstanceHomeParams = { + instanceId: instanceId, + newInstanceId: newInstanceId, + newProvider: newProvider, + newType: newType, + newRegion: newRegion, + newEndpoint: newEndpoint, + newHmacAccessKey: newHmacAccessKey, + newHmacSecretKey: newHmacSecretKey, + }; + + const createInstanceHomeResult = ibmAnalyticsEngineApiService.createInstanceHome( + createInstanceHomeParams + ); + + // all methods should return a Promise + expectToBePromise(createInstanceHomeResult); + + // 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 + __createInstanceHomeTest(); + + // enable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.enableRetries(); + // !!! End of custom content to be copied !!! + __createInstanceHomeTest(); + + // disable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.disableRetries(); + // !!! End of custom content to be copied !!! + __createInstanceHomeTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const createInstanceHomeParams = { + instanceId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + ibmAnalyticsEngineApiService.createInstanceHome(createInstanceHomeParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.createInstanceHome({}); + } 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.createInstanceHome(); + } 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,578 @@ 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); + }); + }); - getApplicationStatePromise.catch(err => { - expect(err.message).toMatch(/Missing required parameters/); - done(); - }); + 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('deleteLoggingConfiguration', () => { + describe('positive tests', () => { + function __deleteLoggingConfigurationTest() { + // Construct the params object for operation deleteLoggingConfiguration + const instanceGuid = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; + const deleteLoggingConfigurationParams = { + instanceGuid: instanceGuid, + }; + + const deleteLoggingConfigurationResult = ibmAnalyticsEngineApiService.deleteLoggingConfiguration( + deleteLoggingConfigurationParams + ); + + // all methods should return a Promise + expectToBePromise(deleteLoggingConfigurationResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod( + mockRequestOptions, + '/v3/analytics_engines/{instance_guid}/logging', + 'DELETE' + ); + const expectedAccept = undefined; + 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 + __deleteLoggingConfigurationTest(); + + // enable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.enableRetries(); + // !!! End of custom content to be copied !!! + __deleteLoggingConfigurationTest(); + + // disable retries and test again + createRequestMock.mockClear(); + // !!! Start of custom content to be copied !!! + // ibmAnalyticsEngineApiService.disableRetries(); + // !!! End of custom content to be copied !!! + __deleteLoggingConfigurationTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const instanceGuid = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const deleteLoggingConfigurationParams = { + instanceGuid, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + ibmAnalyticsEngineApiService.deleteLoggingConfiguration(deleteLoggingConfigurationParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await ibmAnalyticsEngineApiService.deleteLoggingConfiguration({}); + } 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.deleteLoggingConfiguration(); + } 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, + }; + + 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/); }); }); }); From 8dca79140481d3b325c6511e1fa409422ee5495f Mon Sep 17 00:00:00 2001 From: silpidhua Date: Thu, 3 Mar 2022 11:40:47 +0530 Subject: [PATCH 2/5] fix linting error fix linting error --- ibm-analytics-engine-api/v3.ts | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/ibm-analytics-engine-api/v3.ts b/ibm-analytics-engine-api/v3.ts index 1f9a0a4..762da57 100644 --- a/ibm-analytics-engine-api/v3.ts +++ b/ibm-analytics-engine-api/v3.ts @@ -24,8 +24,8 @@ import { Authenticator, BaseService, getAuthenticatorFromEnvironment, - //!!! Start of custom content to be copied !!! - //validateParams, + // !!! Start of custom content to be copied !!! + // validateParams, getMissingParams, // !!! End of custom content to be copied !!! UserOptions, @@ -43,11 +43,6 @@ class IbmAnalyticsEngineApiV3 extends BaseService { static DEFAULT_SERVICE_NAME: string = 'ibm_analytics_engine_api'; - 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'], - ]); - /** * Returns the service URL associated with the specified region. * @param region a string representing the region @@ -89,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. * @@ -128,7 +128,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.GetInstanceParams ): Promise> { const _params = { ...params }; - //!!! Start of custom content to be copied !!! + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceId']; const missingParams = getMissingParams(_params, requiredParams); @@ -187,7 +187,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.GetInstanceStateParams ): Promise> { const _params = { ...params }; - //!!! Start of custom content to be copied !!! + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceId']; const missingParams = getMissingParams(_params, requiredParams); @@ -256,7 +256,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.CreateInstanceHomeParams ): Promise> { const _params = { ...params }; - //!!! Start of custom content to be copied !!! + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceId']; const missingParams = getMissingParams(_params, requiredParams); @@ -328,7 +328,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.CreateApplicationParams ): Promise> { const _params = { ...params }; - //!!! Start of custom content to be copied !!! + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceId']; const missingParams = getMissingParams(_params, requiredParams); @@ -394,7 +394,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.ListApplicationsParams ): Promise> { const _params = { ...params }; - //!!! Start of custom content to be copied !!! + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceId']; @@ -456,7 +456,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.GetApplicationParams ): Promise> { const _params = { ...params }; - //!!! Start of custom content to be copied !!! + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceId', 'applicationId']; const missingParams = getMissingParams(_params, requiredParams); @@ -518,7 +518,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.DeleteApplicationParams ): Promise> { const _params = { ...params }; - //!!! Start of custom content to be copied !!! + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceId', 'applicationId']; const missingParams = getMissingParams(_params, requiredParams); @@ -578,7 +578,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.GetApplicationStateParams ): Promise> { const _params = { ...params }; - //!!! Start of custom content to be copied !!! + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceId', 'applicationId']; const missingParams = getMissingParams(_params, requiredParams); @@ -639,7 +639,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.ConfigurePlatformLoggingParams ): Promise> { const _params = { ...params }; - //!!! Start of custom content to be copied !!! + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceGuid']; const missingParams = getMissingParams(_params, requiredParams); @@ -705,7 +705,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.GetLoggingConfigurationParams ): Promise> { const _params = { ...params }; - //!!! Start of custom content to be copied !!! + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceGuid']; const missingParams = getMissingParams(_params, requiredParams); @@ -764,7 +764,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.DeleteLoggingConfigurationParams ): Promise> { const _params = { ...params }; - //!!! Start of custom content to be copied !!! + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceGuid']; const missingParams = getMissingParams(_params, requiredParams); @@ -822,7 +822,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.StartSparkHistoryServerParams ): Promise> { const _params = { ...params }; - //!!! Start of custom content to be copied !!! + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceId']; const missingParams = getMissingParams(_params, requiredParams); @@ -881,7 +881,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.GetSparkHistoryServerParams ): Promise> { const _params = { ...params }; - //!!! Start of custom content to be copied !!! + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceId']; const missingParams = getMissingParams(_params, requiredParams); @@ -940,7 +940,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { params: IbmAnalyticsEngineApiV3.StopSparkHistoryServerParams ): Promise> { const _params = { ...params }; - //!!! Start of custom content to be copied !!! + // !!! Start of custom content to be copied !!! const requiredParams = ['instanceId']; const missingParams = getMissingParams(_params, requiredParams); From ead063804323a694a2b3a210827b5bed6d4d0d83 Mon Sep 17 00:00:00 2001 From: silpidhua Date: Thu, 3 Mar 2022 12:37:53 +0530 Subject: [PATCH 3/5] Modified HOW_TO_TEST.md Modified HOW_TO_TEST.md --- HOW_TO_TEST.md | 41 ++- examples/ibm-analytics-engine-api.v3.test.js | 262 +++++++++--------- .../ibm-analytics-engine-api.v3.test.js | 136 ++++----- 3 files changed, 227 insertions(+), 212 deletions(-) diff --git a/HOW_TO_TEST.md b/HOW_TO_TEST.md index 071e898..ffc9d3e 100644 --- a/HOW_TO_TEST.md +++ b/HOW_TO_TEST.md @@ -1,24 +1,39 @@ # How to run tests ## Pre-requisites -1. Change to this packages root directory. -1. Install jest. +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. 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` +4. Change to this packages root directory. +5. Exceute ``` - npm install jest - ``` -1. Build the package. - ``` - npm run build + npm install ``` ## Integration Tests +1. 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 + +2. 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. +3. Update `auth.js` file with your own **APIKEY** and other details. +4. Execute the following command: + `npm install` + `npm run build` + `npm run lint-fix` +5. Go to Project's root directory `ibm-iae-node-sdk/` directory. + Run `yarn jest ibm-analytics-engine-api.v3.test.js` -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**, **INSTANCE GUID** and other details. -1. Go to `/test/integartion/` directory. -1. Run `jest ibm-analytics-engine-api.v2.test.js`. +6. 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. Go to `/test/unit/` directory. -1. Run `jest ibm-analytics-engine-api.v2.test.js`. \ No newline at end of file +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 4a9b476..a19e9d9 100644 --- a/examples/ibm-analytics-engine-api.v3.test.js +++ b/examples/ibm-analytics-engine-api.v3.test.js @@ -23,8 +23,8 @@ const IbmAnalyticsEngineApiV3 = require('../dist/ibm-analytics-engine-api/v3'); // eslint-disable-next-line node/no-unpublished-require //!!! Start of custom content to be copied !!! -// const authHelper = require('../resources/auth-helper.js'); -const authHelper = require('../test/resources/auth.js'); +// Replace auth-helper.js with auth.js +const authHelper = require('../resources/auth-helper.js'); const { IamAuthenticator } = require('../dist/auth'); const timeout = 200000; // !!! End of custom content to be copied !!! @@ -503,135 +503,135 @@ describe('IbmAnalyticsEngineApiV3', () => { // end-get_logging_configuration }); - // //!!! 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('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('deleteLoggingConfiguration request example', (done) => { diff --git a/test/integration/ibm-analytics-engine-api.v3.test.js b/test/integration/ibm-analytics-engine-api.v3.test.js index 5d9db63..3fc2e41 100644 --- a/test/integration/ibm-analytics-engine-api.v3.test.js +++ b/test/integration/ibm-analytics-engine-api.v3.test.js @@ -20,8 +20,8 @@ const IbmAnalyticsEngineApiV3 = require('../../dist/ibm-analytics-engine-api/v3' const { readExternalSources } = require('ibm-cloud-sdk-core'); // !!! Start of custom content to be copied !!! -// const authHelper = require('../resources/auth-helper.js'); -const authHelper = require('../resources/auth.js'); +// Replace auth-helper.js with auth.js +const authHelper = require('../resources/auth-helper.js'); const { IamAuthenticator } = require('../../dist/auth'); // !!! End of custom content to be copied !!! @@ -282,72 +282,72 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { // 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(); - // console.log('startSparkHistoryServer'); - // console.log(res); - // // - // // 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(); - // console.log('getSparkHistoryServer'); - // console.log(res); - // // - // // 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(); - // console.log('stopSparkHistoryServer'); - // console.log(res); - // // - // // The following status codes aren't covered by tests. - // // Please provide integration tests for these too. - // // - // // 400 - // // 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(); + console.log('startSparkHistoryServer'); + console.log(res); + // + // 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(); + console.log('getSparkHistoryServer'); + console.log(res); + // + // 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(); + console.log('stopSparkHistoryServer'); + console.log(res); + // + // The following status codes aren't covered by tests. + // Please provide integration tests for these too. + // + // 400 + // 401 + // 403 + // 404 + // 500 + // + }); test('deleteLoggingConfiguration()', async () => { const params = { instanceGuid: instanceGuid, From 685f2fdc7dc5b4543b2b04f93ad14f135e6397e9 Mon Sep 17 00:00:00 2001 From: Silpi Dhua Date: Tue, 8 Mar 2022 17:39:50 +0530 Subject: [PATCH 4/5] Modification as per review comment Modification as per review comment --- HOW_TO_TEST.md | 22 +++++++++++-------- .../ibm-analytics-engine-api.v3.test.js | 1 + 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/HOW_TO_TEST.md b/HOW_TO_TEST.md index ffc9d3e..e59e01b 100644 --- a/HOW_TO_TEST.md +++ b/HOW_TO_TEST.md @@ -3,16 +3,20 @@ ## 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. Generate the sdk code with: +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` -4. Change to this packages root directory. -5. Exceute +5. Change to this packages root directory. +6. Exceute ``` npm install ``` ## Integration Tests -1. To merge with remote version pick the code marked between + +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: @@ -21,16 +25,16 @@ c. test/integration/ibm-analytics-engine-api.v3.test.js d. examples/ibm-analytics-engine-api.v3.test.js -2. 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. -3. Update `auth.js` file with your own **APIKEY** and other details. -4. Execute the following command: +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` -5. Go to Project's root directory `ibm-iae-node-sdk/` directory. +6. Go to Project's root directory `ibm-iae-node-sdk/` directory. Run `yarn jest ibm-analytics-engine-api.v3.test.js` -6. To execute individual tests +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`. diff --git a/test/integration/ibm-analytics-engine-api.v3.test.js b/test/integration/ibm-analytics-engine-api.v3.test.js index 3fc2e41..e2f420f 100644 --- a/test/integration/ibm-analytics-engine-api.v3.test.js +++ b/test/integration/ibm-analytics-engine-api.v3.test.js @@ -37,6 +37,7 @@ const timeout = 200000; 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, url: options.apiAuthUrl }); const instanceGuid = options.instance_guid; From c2ad46cf179ccc0de9699bee3ebccb07b4e9936d Mon Sep 17 00:00:00 2001 From: silpidhua Date: Thu, 19 May 2022 10:08:01 +0530 Subject: [PATCH 5/5] Renamed createInstanceHome to setInstanceHome (#41) * Renamed createInstanceHome to setInstanceHome Renamed createInstanceHome to setInstanceHome * Fixed lint error Fixed lint error Co-authored-by: Silpi Dhua --- examples/ibm-analytics-engine-api.v3.test.js | 95 ++++-------- ibm-analytics-engine-api/v3.ts | 139 +++++------------- .../ibm-analytics-engine-api.v3.test.js | 46 +----- test/unit/ibm-analytics-engine-api.v3.test.js | 121 ++------------- 4 files changed, 85 insertions(+), 316 deletions(-) diff --git a/examples/ibm-analytics-engine-api.v3.test.js b/examples/ibm-analytics-engine-api.v3.test.js index a19e9d9..c009fcc 100644 --- a/examples/ibm-analytics-engine-api.v3.test.js +++ b/examples/ibm-analytics-engine-api.v3.test.js @@ -23,8 +23,8 @@ 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 -const authHelper = require('../resources/auth-helper.js'); +// 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 !!! @@ -60,6 +60,9 @@ const consoleLogMock = jest.spyOn(console, 'log'); const consoleWarnMock = jest.spyOn(console, 'warn'); describe('IbmAnalyticsEngineApiV3', () => { + // 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); @@ -73,7 +76,6 @@ describe('IbmAnalyticsEngineApiV3', () => { let applicationId = ''; jest.setTimeout(timeout); // !!! End of custom content to be copied !!! - let ibmAnalyticsEngineApiService; test('Initialize services', async () => { // begin-common @@ -152,7 +154,6 @@ describe('IbmAnalyticsEngineApiV3', () => { const params = { instanceId: instanceGuid, }; - //!!! Start of custom content to be copied !!! ibmAnalyticsEngineApiService .getInstanceState(params) @@ -174,7 +175,7 @@ describe('IbmAnalyticsEngineApiV3', () => { }); //!!! Start of custom content to be copied !!! - test('createInstanceHome request example', (done) => { + test('setInstanceHome request example', (done) => { // !!! End of custom content to be copied !!! consoleLogMock.mockImplementation((output) => { originalLog(output); @@ -191,8 +192,8 @@ describe('IbmAnalyticsEngineApiV3', () => { // !!! End of custom content to be copied !!! }); - originalLog('createInstanceHome() result:'); - // begin-create_instance_home + originalLog('setInstanceHome() result:'); + // begin-set_instance_home //!!! Start of custom content to be copied !!! const params = { instanceId: instanceIdInstanceHome, @@ -207,7 +208,7 @@ describe('IbmAnalyticsEngineApiV3', () => { // !!! End of custom content to be copied !!! //!!! Start of custom content to be copied !!! ibmAnalyticsEngineApiService - .createInstanceHome(params) + .setInstanceHome(params) .then((res)=>{ console.log(JSON.stringify(res.result, null, 2)); }) @@ -222,7 +223,7 @@ describe('IbmAnalyticsEngineApiV3', () => { // console.warn(err); // } // !!! End of custom content to be copied !!! - // end-create_instance_home + // end-set_instance_home }); //!!! Start of custom content to be copied !!! @@ -272,7 +273,6 @@ describe('IbmAnalyticsEngineApiV3', () => { // console.warn(err); // } // !!! End of custom content to be copied !!! - // end-create_application }); @@ -511,7 +511,6 @@ describe('IbmAnalyticsEngineApiV3', () => { //!!! 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 @@ -616,72 +615,31 @@ describe('IbmAnalyticsEngineApiV3', () => { 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('deleteLoggingConfiguration 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(); + 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 }); - // begin-delete_logging_configuration - - const params = { - instanceGuid: instanceGuid, - }; - //!!! Start of custom content to be copied !!! - ibmAnalyticsEngineApiService - .deleteLoggingConfiguration(params) - .then((res) => { - console.log(JSON.stringify(res.result, null, 2)); - }) - .catch((err) => { - console.warn(err); - }); - // try { - // await ibmAnalyticsEngineApiService.deleteLoggingConfiguration(params); - // } catch (err) { - // console.warn(err); - // } - // !!! End of custom content to be copied !!! - // end-delete_logging_configuration - }); - //!!! Start of custom content to be copied !!! test('deleteApplication request example', (done) => { - // !!! End of custom content to be copied !!! + // !!! 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 !!! + // !!! End of custom content to be copied !!! }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test @@ -698,6 +656,7 @@ describe('IbmAnalyticsEngineApiV3', () => { instanceId: instanceGuid, applicationId: applicationId, }; + //!!! Start of custom content to be copied !!! ibmAnalyticsEngineApiService .deleteApplication(params) diff --git a/ibm-analytics-engine-api/v3.ts b/ibm-analytics-engine-api/v3.ts index 762da57..a4859c9 100644 --- a/ibm-analytics-engine-api/v3.ts +++ b/ibm-analytics-engine-api/v3.ts @@ -15,7 +15,7 @@ */ /** - * IBM OpenAPI SDK Code Generator Version: 3.45.1-632ec580-20220210-190638 + * IBM OpenAPI SDK Code Generator Version: 3.49.0-be9b22fb-20220504-154308 */ import * as extend from 'extend'; @@ -198,8 +198,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { // const _validationErrors = validateParams(_params, _requiredParams, _validParams); // if (_validationErrors) { // return Promise.reject(_validationErrors); - // !!! End of custom content to be copied !!! - + // !!! End of custom content to be copied !!! } const path = { @@ -234,13 +233,13 @@ class IbmAnalyticsEngineApiV3 extends BaseService { } /** - * Edit instance home details. + * Set instance home. * - * Update details of the Object Storage associated as 'instance home' for an Analytics Engine instance. + * 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 - * updated. + * @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 @@ -252,8 +251,8 @@ class IbmAnalyticsEngineApiV3 extends BaseService { * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ - public createInstanceHome( - params: IbmAnalyticsEngineApiV3.CreateInstanceHomeParams + public setInstanceHome( + params: IbmAnalyticsEngineApiV3.SetInstanceHomeParams ): Promise> { const _params = { ...params }; // !!! Start of custom content to be copied !!! @@ -287,7 +286,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { const sdkHeaders = getSdkHeaders( IbmAnalyticsEngineApiV3.DEFAULT_SERVICE_NAME, 'v3', - 'createInstanceHome' + 'setInstanceHome' ); const parameters = { @@ -339,8 +338,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { // const _validationErrors = validateParams(_params, _requiredParams, _validParams); // if (_validationErrors) { // return Promise.reject(_validationErrors); - // !!! End of custom content to be copied !!! - + // !!! End of custom content to be copied !!! } const body = { @@ -625,7 +623,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { } /** - * Enable or disable log fowarding. + * Enable or disable log forwarding. * * Enable or disable log forwarding from IBM Analytics Engine to IBM Log Analysis server. * @@ -651,7 +649,6 @@ class IbmAnalyticsEngineApiV3 extends BaseService { // if (_validationErrors) { // return Promise.reject(_validationErrors); // !!! End of custom content to be copied !!! - } const body = { @@ -716,7 +713,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { // const _validationErrors = validateParams(_params, _requiredParams, _validParams); // if (_validationErrors) { // return Promise.reject(_validationErrors); - // !!! End of custom content to be copied !!! + // !!! End of custom content to be copied !!! } const path = { @@ -750,71 +747,14 @@ class IbmAnalyticsEngineApiV3 extends BaseService { return this.createRequest(parameters); } - /** - * Delete logging configuration of a given instance id. - * - * Delete 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 instance for which log configuration is to be deleted. - * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers - * @returns {Promise>} - */ - public deleteLoggingConfiguration( - params: IbmAnalyticsEngineApiV3.DeleteLoggingConfigurationParams - ): 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', - 'deleteLoggingConfiguration' - ); - - const parameters = { - options: { - url: '/v3/analytics_engines/{instance_guid}/logging', - method: 'DELETE', - path, - }, - defaultOptions: extend(true, {}, this.baseOptions, { - headers: extend( - true, - sdkHeaders, - { - }, - _params.headers - ), - }), - }; - - return this.createRequest(parameters); - } - /** * Start Spark history server. * - * Start the Spark history server for a given serverless Spark instance. + * 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 identifier of the instance for which the Spark history server is started. + * @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>} */ @@ -833,7 +773,7 @@ class IbmAnalyticsEngineApiV3 extends BaseService { // const _validationErrors = validateParams(_params, _requiredParams, _validParams); // if (_validationErrors) { // return Promise.reject(_validationErrors); - // !!! End of custom content to be copied !!! + // !!! End of custom content to be copied !!! } const path = { @@ -868,12 +808,13 @@ class IbmAnalyticsEngineApiV3 extends BaseService { } /** - * Retrieve Spark history server details by ID. + * Retrieve Spark history server details. * - * Retrieve the Spark history server details for an Analytics Engine instance by the instance ID. + * 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 identifier of the instance for which the Spark history server is started. + * @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>} */ @@ -929,10 +870,11 @@ class IbmAnalyticsEngineApiV3 extends BaseService { /** * Stop Spark history server. * - * Stop the Spark history server for a given serverless Spark instance. + * 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 identifier of the instance for which the Spark history server is stopped. + * @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>} */ @@ -1027,9 +969,9 @@ namespace IbmAnalyticsEngineApiV3 { headers?: OutgoingHttpHeaders; } - /** Parameters for the `createInstanceHome` operation. */ - export interface CreateInstanceHomeParams { - /** GUID of the Analytics Engine instance for which 'instance home' is to be updated. */ + /** 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; @@ -1107,30 +1049,23 @@ namespace IbmAnalyticsEngineApiV3 { headers?: OutgoingHttpHeaders; } - /** Parameters for the `deleteLoggingConfiguration` operation. */ - export interface DeleteLoggingConfigurationParams { - /** GUID of the instance for which log configuration is to be deleted. */ - instanceGuid: string; - headers?: OutgoingHttpHeaders; - } - /** Parameters for the `startSparkHistoryServer` operation. */ export interface StartSparkHistoryServerParams { - /** The identifier of the instance for which the Spark history server is started. */ + /** 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 identifier of the instance for which the Spark history server is started. */ + /** 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 identifier of the instance for which the Spark history server is stopped. */ + /** The ID of the Analytics Engine instance whose Spark history server is to be stopped. */ instanceId: string; headers?: OutgoingHttpHeaders; } @@ -1355,13 +1290,13 @@ namespace IbmAnalyticsEngineApiV3 { type?: string; } - /** State of Spark history server. */ + /** State of the Spark history server. */ export interface SparkHistoryServerResponse { - /** State of Spark history server. */ + /** State of the Spark history server. */ state?: string; - /** Number of cores used for the Spark history server. */ + /** Number of cpu cores used by the Spark history server. */ cores?: string; - /** Memory used for the Spark history server. */ + /** Amount of memory used by the Spark history server. */ memory?: string; /** Time when the Spark history server was started. */ start_time?: string; @@ -1369,13 +1304,13 @@ namespace IbmAnalyticsEngineApiV3 { stop_time?: string; } - /** Spark history server started response. */ + /** Response of the request to start the Spark history server. */ export interface SparkHistoryServerStartResponse { - /** State of Spark history server. */ + /** State of the Spark history server. */ state?: string; - /** Number of cores used for the Spark history server. */ + /** Number of cpu cores used by the Spark history server. */ cores?: string; - /** Memory used for the Spark history server. */ + /** Amount of memory used by the Spark history server. */ memory?: string; /** Time when the Spark history server was started. */ start_time?: string; diff --git a/test/integration/ibm-analytics-engine-api.v3.test.js b/test/integration/ibm-analytics-engine-api.v3.test.js index e2f420f..2260185 100644 --- a/test/integration/ibm-analytics-engine-api.v3.test.js +++ b/test/integration/ibm-analytics-engine-api.v3.test.js @@ -18,9 +18,8 @@ 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 +// Replace auth-helper.js with auth.js for integration testing const authHelper = require('../resources/auth-helper.js'); const { IamAuthenticator } = require('../../dist/auth'); // !!! End of custom content to be copied !!! @@ -31,7 +30,6 @@ const timeout = 200000; // !!! 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 !!! @@ -49,6 +47,7 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { jest.setTimeout(timeout); + // Service instance let ibmAnalyticsEngineApiService; test('Initialise service', async () => { @@ -59,7 +58,6 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { const config = readExternalSources(IbmAnalyticsEngineApiV3.DEFAULT_SERVICE_NAME); expect(config).not.toBeNull(); - // ibmAnalyticsEngineApiService.enableRetries(); }); @@ -67,7 +65,6 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { const params = { instanceId: instanceGuid, }; - const res = await ibmAnalyticsEngineApiService.getInstance(params); expect(res).toBeDefined(); expect(res.status).toBe(200); @@ -77,7 +74,6 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { // The following status codes aren't covered by tests. // Please provide integration tests for these too. // - // 400 // 401 // 403 // 404 @@ -98,14 +94,13 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { // The following status codes aren't covered by tests. // Please provide integration tests for these too. // - // 400 // 401 // 403 // 404 // 500 // }); - test('createInstanceHome()', async () => { + test('setInstanceHome()', async () => { const params = { instanceId: instanceIdInstanceHome, newInstanceId: 'testString', @@ -117,7 +112,7 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { newHmacSecretKey: hmacSecretKey, }; - const res = await ibmAnalyticsEngineApiService.createInstanceHome(params); + const res = await ibmAnalyticsEngineApiService.setInstanceHome(params); expect(res).toBeDefined(); expect(res.status).toBe(200); expect(res.result).toBeDefined(); @@ -130,6 +125,7 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { // 401 // 403 // 404 + // 409 // 500 // }); @@ -189,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 @@ -211,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 @@ -233,7 +227,6 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { // The following status codes aren't covered by tests. // Please provide integration tests for these too. // - // 400 // 401 // 403 // 404 @@ -276,7 +269,6 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { // The following status codes aren't covered by tests. // Please provide integration tests for these too. // - // 400 // 401 // 403 // 404 @@ -292,8 +284,7 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { expect(res).toBeDefined(); expect(res.status).toBe(201); expect(res.result).toBeDefined(); - console.log('startSparkHistoryServer'); - console.log(res); + // // The following status codes aren't covered by tests. // Please provide integration tests for these too. @@ -314,8 +305,7 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { expect(res).toBeDefined(); expect(res.status).toBe(200); expect(res.result).toBeDefined(); - console.log('getSparkHistoryServer'); - console.log(res); + // // The following status codes aren't covered by tests. // Please provide integration tests for these too. @@ -336,28 +326,6 @@ describe('IbmAnalyticsEngineApiV3_integration', () => { expect(res).toBeDefined(); expect(res.status).toBe(204); expect(res.result).toBeDefined(); - console.log('stopSparkHistoryServer'); - console.log(res); - // - // The following status codes aren't covered by tests. - // Please provide integration tests for these too. - // - // 400 - // 401 - // 403 - // 404 - // 500 - // - }); - test('deleteLoggingConfiguration()', async () => { - const params = { - instanceGuid: instanceGuid, - }; - - const res = await ibmAnalyticsEngineApiService.deleteLoggingConfiguration(params); - expect(res).toBeDefined(); - expect(res.status).toBe(204); - expect(res.result).toBeDefined(); // // The following status codes aren't covered by tests. diff --git a/test/unit/ibm-analytics-engine-api.v3.test.js b/test/unit/ibm-analytics-engine-api.v3.test.js index ab28c73..3ef9a86 100644 --- a/test/unit/ibm-analytics-engine-api.v3.test.js +++ b/test/unit/ibm-analytics-engine-api.v3.test.js @@ -286,10 +286,10 @@ describe('IbmAnalyticsEngineApiV3', () => { }); }); }); - describe('createInstanceHome', () => { + describe('setInstanceHome', () => { describe('positive tests', () => { - function __createInstanceHomeTest() { - // Construct the params object for operation createInstanceHome + function __setInstanceHomeTest() { + // Construct the params object for operation setInstanceHome const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; const newInstanceId = 'testString'; const newProvider = 'ibm-cos'; @@ -298,7 +298,7 @@ describe('IbmAnalyticsEngineApiV3', () => { const newEndpoint = 's3.direct.us-south.cloud-object-storage.appdomain.cloud'; const newHmacAccessKey = '821**********0ae'; const newHmacSecretKey = '03e****************4fc3'; - const createInstanceHomeParams = { + const setInstanceHomeParams = { instanceId: instanceId, newInstanceId: newInstanceId, newProvider: newProvider, @@ -309,12 +309,12 @@ describe('IbmAnalyticsEngineApiV3', () => { newHmacSecretKey: newHmacSecretKey, }; - const createInstanceHomeResult = ibmAnalyticsEngineApiService.createInstanceHome( - createInstanceHomeParams + const setInstanceHomeResult = ibmAnalyticsEngineApiService.setInstanceHome( + setInstanceHomeParams ); // all methods should return a Promise - expectToBePromise(createInstanceHomeResult); + expectToBePromise(setInstanceHomeResult); // assert that create request was called expect(createRequestMock).toHaveBeenCalledTimes(1); @@ -341,21 +341,21 @@ describe('IbmAnalyticsEngineApiV3', () => { test('should pass the right params to createRequest with enable and disable retries', () => { // baseline test - __createInstanceHomeTest(); + __setInstanceHomeTest(); // enable retries and test again createRequestMock.mockClear(); // !!! Start of custom content to be copied !!! // ibmAnalyticsEngineApiService.enableRetries(); // !!! End of custom content to be copied !!! - __createInstanceHomeTest(); + __setInstanceHomeTest(); // disable retries and test again createRequestMock.mockClear(); // !!! Start of custom content to be copied !!! // ibmAnalyticsEngineApiService.disableRetries(); // !!! End of custom content to be copied !!! - __createInstanceHomeTest(); + __setInstanceHomeTest(); }); test('should prioritize user-given headers', () => { @@ -363,7 +363,7 @@ describe('IbmAnalyticsEngineApiV3', () => { const instanceId = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; const userAccept = 'fake/accept'; const userContentType = 'fake/contentType'; - const createInstanceHomeParams = { + const setInstanceHomeParams = { instanceId, headers: { Accept: userAccept, @@ -371,7 +371,7 @@ describe('IbmAnalyticsEngineApiV3', () => { }, }; - ibmAnalyticsEngineApiService.createInstanceHome(createInstanceHomeParams); + ibmAnalyticsEngineApiService.setInstanceHome(setInstanceHomeParams); checkMediaHeaders(createRequestMock, userAccept, userContentType); }); }); @@ -380,7 +380,7 @@ describe('IbmAnalyticsEngineApiV3', () => { test('should enforce required parameters', async () => { let err; try { - await ibmAnalyticsEngineApiService.createInstanceHome({}); + await ibmAnalyticsEngineApiService.setInstanceHome({}); } catch (e) { err = e; } @@ -391,7 +391,7 @@ describe('IbmAnalyticsEngineApiV3', () => { test('should reject promise when required params are not given', async () => { let err; try { - await ibmAnalyticsEngineApiService.createInstanceHome(); + await ibmAnalyticsEngineApiService.setInstanceHome(); } catch (e) { err = e; } @@ -1089,99 +1089,6 @@ describe('IbmAnalyticsEngineApiV3', () => { }); }); }); - describe('deleteLoggingConfiguration', () => { - describe('positive tests', () => { - function __deleteLoggingConfigurationTest() { - // Construct the params object for operation deleteLoggingConfiguration - const instanceGuid = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; - const deleteLoggingConfigurationParams = { - instanceGuid: instanceGuid, - }; - - const deleteLoggingConfigurationResult = ibmAnalyticsEngineApiService.deleteLoggingConfiguration( - deleteLoggingConfigurationParams - ); - - // all methods should return a Promise - expectToBePromise(deleteLoggingConfigurationResult); - - // assert that create request was called - expect(createRequestMock).toHaveBeenCalledTimes(1); - - const mockRequestOptions = getOptions(createRequestMock); - - checkUrlAndMethod( - mockRequestOptions, - '/v3/analytics_engines/{instance_guid}/logging', - 'DELETE' - ); - const expectedAccept = undefined; - 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 - __deleteLoggingConfigurationTest(); - - // enable retries and test again - createRequestMock.mockClear(); - // !!! Start of custom content to be copied !!! - // ibmAnalyticsEngineApiService.enableRetries(); - // !!! End of custom content to be copied !!! - __deleteLoggingConfigurationTest(); - - // disable retries and test again - createRequestMock.mockClear(); - // !!! Start of custom content to be copied !!! - // ibmAnalyticsEngineApiService.disableRetries(); - // !!! End of custom content to be copied !!! - __deleteLoggingConfigurationTest(); - }); - - test('should prioritize user-given headers', () => { - // parameters - const instanceGuid = 'e64c907a-e82f-46fd-addc-ccfafbd28b09'; - const userAccept = 'fake/accept'; - const userContentType = 'fake/contentType'; - const deleteLoggingConfigurationParams = { - instanceGuid, - headers: { - Accept: userAccept, - 'Content-Type': userContentType, - }, - }; - - ibmAnalyticsEngineApiService.deleteLoggingConfiguration(deleteLoggingConfigurationParams); - checkMediaHeaders(createRequestMock, userAccept, userContentType); - }); - }); - - describe('negative tests', () => { - test('should enforce required parameters', async () => { - let err; - try { - await ibmAnalyticsEngineApiService.deleteLoggingConfiguration({}); - } 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.deleteLoggingConfiguration(); - } catch (e) { - err = e; - } - - expect(err.message).toMatch(/Missing required parameters/); - }); - }); - }); describe('startSparkHistoryServer', () => { describe('positive tests', () => { function __startSparkHistoryServerTest() {