From 66b4b8ea41a8518801e98e6b3d52c0d437b57cf6 Mon Sep 17 00:00:00 2001 From: phantomjinx Date: Thu, 22 Mar 2018 21:37:27 +0000 Subject: [PATCH] TEIIDTOOLS-374: VDB naming and model source associated connections * VDB names should be lower case in acccordance with kubernetes rules * A VDB model source should be associated with its connection explicitly rather than relying on the source name. * dataservice.service vdbservice.service * derive functions for generating the relevant names from the dataservice/connection * The associated connection's data path is applied to the vdb model source prior to transmission to komodo. --- .../connections/shared/connection.model.ts | 8 ++++ .../shared/dataservice.service.ts | 27 ++++++++--- .../shared/vdb-model-source.model.ts | 15 ++++++ .../app/dataservices/shared/vdb.service.ts | 48 ++++++++++++++++--- .../app/dataservices/shared/vdbs-constants.ts | 3 +- 5 files changed, 87 insertions(+), 14 deletions(-) diff --git a/ngapp/src/app/connections/shared/connection.model.ts b/ngapp/src/app/connections/shared/connection.model.ts index 2a656cd9..89f121d9 100644 --- a/ngapp/src/app/connections/shared/connection.model.ts +++ b/ngapp/src/app/connections/shared/connection.model.ts @@ -24,6 +24,7 @@ export class Connection implements Identifiable< string > { public static serviceCatalogSourceProp = "serviceCatalogSource"; private keng__id: string; + private keng__dataPath: string; private dv__jndiName: string; private dv__driverName: string; private dv__type: boolean; @@ -117,6 +118,13 @@ export class Connection implements Identifiable< string > { return this.keng__id; } + /** + * @returns {string} the connection data path (can be null) + */ + public getDataPath(): string { + return this.keng__dataPath; + } + /** * @returns {string} the connection JNDI name (can be null) */ diff --git a/ngapp/src/app/dataservices/shared/dataservice.service.ts b/ngapp/src/app/dataservices/shared/dataservice.service.ts index c7007082..616ea0bd 100644 --- a/ngapp/src/app/dataservices/shared/dataservice.service.ts +++ b/ngapp/src/app/dataservices/shared/dataservice.service.ts @@ -20,6 +20,7 @@ import { Http } from "@angular/http"; import { ApiService } from "@core/api.service"; import { AppSettingsService } from "@core/app-settings.service"; import { LoggerService } from "@core/logger.service"; +import { Connection } from "@connections/shared/connection.model"; import { Dataservice } from "@dataservices/shared/dataservice.model"; import { DataservicesConstants } from "@dataservices/shared/dataservices-constants"; import { DeploymentState } from "@dataservices/shared/deployment-state.enum"; @@ -48,8 +49,6 @@ export class DataserviceService extends ApiService { // Using replay status with cache of 1, so subscribers dont get an initial value on subscription public dataserviceStateChange: Subject< Map > = new ReplaySubject< Map >(1); - public serviceVdbSuffix = "VDB"; // Don't change - must match komodo naming convention - private http: Http; private notifierService: NotifierService; private appSettingsService: AppSettingsService; @@ -317,6 +316,17 @@ export class DataserviceService extends ApiService { .catch( ( error ) => this.handleError( error ) ); } + /** + * Derive the service vdb name from the given dataservice + * + * @param {Dataservice} dataservice + * @returns {string} + */ + public deriveServiceVdbName(dataservice: NewDataservice): string { + let name = dataservice.getId() + VdbsConstants.DATASERVICE_VDB_SUFFIX; + return name.toLowerCase(); + } + /** * Create a dataservice which is a straight passthru to the supplied tables * @param {NewDataservice} dataservice @@ -325,23 +335,26 @@ export class DataserviceService extends ApiService { */ public createDataserviceForSingleSourceTables(dataservice: NewDataservice, sourceTables: Table[]): Observable { // All tables from same connection - const connectionName = sourceTables[0].getConnection().getId(); - const sourceVdbName = connectionName + VdbsConstants.SOURCE_VDB_SUFFIX; - const sourceModelName = connectionName; + const connection: Connection = sourceTables[0].getConnection(); + const sourceVdbName = this.vdbService.deriveVdbName(connection); + const sourceModelName = this.vdbService.deriveVdbModelName(connection); + const sourceModelSourceName = this.vdbService.deriveVdbModelSourceName(connection); const vdbPath = this.getKomodoUserWorkspacePath() + "/" + sourceVdbName; const tablePaths = []; for ( const sourceTable of sourceTables ) { const tablePath = vdbPath + "/" + sourceModelName + "/" + sourceTable.getName(); tablePaths.push(tablePath); } - const modelSourcePath = vdbPath + "/" + sourceModelName + "/vdb:sources/" + sourceModelName; + const modelSourcePath = vdbPath + "/" + sourceModelName + "/vdb:sources/" + sourceModelSourceName; + + const dsVdbName = this.deriveServiceVdbName(dataservice); // Chain the individual calls together in series to build the DataService return this.createDataservice(dataservice) .flatMap((res) => this.vdbService.updateVdbModelFromTeiid(sourceVdbName, sourceModelName, sourceVdbName, sourceModelName)) .flatMap((res) => this.setServiceVdbForSingleSourceTables(dataservice.getId(), tablePaths, modelSourcePath)) - .flatMap((res) => this.createReadonlyDataRole(dataservice.getId(), sourceModelName)) + .flatMap((res) => this.createReadonlyDataRole(dsVdbName, sourceModelName)) .flatMap((res) => this.vdbService.undeployVdb(sourceVdbName)) .flatMap((res) => this.vdbService.deleteVdb(sourceVdbName)); } diff --git a/ngapp/src/app/dataservices/shared/vdb-model-source.model.ts b/ngapp/src/app/dataservices/shared/vdb-model-source.model.ts index b0fae2eb..6d9594ef 100644 --- a/ngapp/src/app/dataservices/shared/vdb-model-source.model.ts +++ b/ngapp/src/app/dataservices/shared/vdb-model-source.model.ts @@ -25,6 +25,7 @@ export class VdbModelSource { private keng__kType = "VdbModelSource"; private vdb__sourceJndiName: string; private vdb__sourceTranslator: string; + private tko__associatedConnection: string; /** * @param {Object} json the JSON representation of a VdbModelSource @@ -75,6 +76,13 @@ export class VdbModelSource { return this.vdb__sourceTranslator; } + /** + * @returns {string} the associated connection path (can be null) + */ + public getAssociatedConnection(): string { + return this.tko__associatedConnection; + } + /** * @param {string} id the vdbModelSource identifier (optional) */ @@ -103,6 +111,13 @@ export class VdbModelSource { this.vdb__sourceTranslator = translator ? translator : null; } + /** + * @param {string} connectionPath the path to the associated connection (optional) + */ + public setAssociatedConnection( connectionPath?: string ): void { + this.tko__associatedConnection = connectionPath ? connectionPath : null; + } + /** * Set all object values using the supplied VdbModelSource json * @param {Object} values diff --git a/ngapp/src/app/dataservices/shared/vdb.service.ts b/ngapp/src/app/dataservices/shared/vdb.service.ts index edbe9daa..3c84b0fb 100644 --- a/ngapp/src/app/dataservices/shared/vdb.service.ts +++ b/ngapp/src/app/dataservices/shared/vdb.service.ts @@ -98,6 +98,39 @@ export class VdbService extends ApiService { .catch( ( error ) => this.handleError( error ) ); } + /** + /** + * Derive the vdb name from the given connection + * + * @param {Connection} connection + * @returns {string} + */ + public deriveVdbName(connection: Connection): string { + let name = connection.getId() + VdbsConstants.SOURCE_VDB_SUFFIX; + return name.toLowerCase(); + } + + /** + * Derive the vdb model name from the given connection + * + * @param {Connection} connection + * @returns {string} + */ + public deriveVdbModelName(connection: Connection): string { + return connection.getId().toLowerCase(); + } + + /** + * Derive the vdb model source name from the given connection + * + * @param {Connection} connection + * @returns {string} + */ + public deriveVdbModelSourceName(connection: Connection): string { + return connection.getServiceCatalogSourceName() ? + connection.getServiceCatalogSourceName() : connection.getId().toLowerCase(); + } + /** * Create a vdb via the komodo rest interface * @param {Vdb} vdb @@ -297,10 +330,12 @@ export class VdbService extends ApiService { // Currently requiring all tables from same connection const connection: Connection = tables[0].getConnection(); + const vdbName = this.deriveVdbName(connection); + const vdbModelName = this.deriveVdbModelName(connection); + const vdbModelSourceName = this.deriveVdbModelSourceName(connection); + // VDB to create const vdb = new Vdb(); - const vdbName = connection.getId() + VdbsConstants.SOURCE_VDB_SUFFIX; - const connName = connection.getId(); vdb.setName(vdbName); vdb.setId(vdbName); const vdbPath = this.getKomodoUserWorkspacePath() + "/" + vdbName; @@ -310,8 +345,8 @@ export class VdbService extends ApiService { // VDB Model to create const vdbModel = new VdbModel(); - vdbModel.setId(connName); - vdbModel.setDataPath(vdbPath + "/" + connName); + vdbModel.setId(vdbModelName); + vdbModel.setDataPath(vdbPath + "/" + vdbModelName); vdbModel.setModelType("PHYSICAL"); // Set the importer properties for the physical model @@ -324,10 +359,11 @@ export class VdbService extends ApiService { // VdbModelSource to create const vdbModelSource = new VdbModelSource(); - vdbModelSource.setId(connName); - vdbModelSource.setDataPath(vdbPath + "/" + connName + "/vdb:sources/" + connName); + vdbModelSource.setId(vdbModelSourceName); + vdbModelSource.setDataPath(vdbPath + "/" + vdbModelName + "/vdb:sources/" + vdbModelSourceName); vdbModelSource.setJndiName(connection.getJndiName()); vdbModelSource.setTranslatorName(connection.getDriverName()); + vdbModelSource.setAssociatedConnection(connection.getDataPath()); // Chain the individual calls together in series to build the Vdb and deploy it return this.deleteVdbIfFound(vdb.getId()) diff --git a/ngapp/src/app/dataservices/shared/vdbs-constants.ts b/ngapp/src/app/dataservices/shared/vdbs-constants.ts index 3ad35860..d040e3e9 100644 --- a/ngapp/src/app/dataservices/shared/vdbs-constants.ts +++ b/ngapp/src/app/dataservices/shared/vdbs-constants.ts @@ -13,7 +13,8 @@ export class VdbsConstants { public static readonly SERVICE_VIEW_MODEL_NAME = "views"; // ** must match KomodoDataserviceService.SERVICE_VDB_VIEW_MODEL ** - public static readonly SOURCE_VDB_SUFFIX = "BtlSource"; + public static readonly SOURCE_VDB_SUFFIX = "btlsource"; + public static readonly DATASERVICE_VDB_SUFFIX = "vdb"; public static readonly DEFAULT_READONLY_DATA_ROLE = "DefaultReadOnlyDataRole"; public static readonly statusPath = "/status";