Skip to content
This repository has been archived by the owner on Nov 22, 2019. It is now read-only.

Commit

Permalink
TEIIDTOOLS-374: VDB naming and model source associated connections
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
phantomjinx committed Mar 26, 2018
1 parent b2cddc2 commit 66b4b8e
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 14 deletions.
8 changes: 8 additions & 0 deletions ngapp/src/app/connections/shared/connection.model.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
*/
Expand Down
27 changes: 20 additions & 7 deletions ngapp/src/app/dataservices/shared/dataservice.service.ts
Expand Up @@ -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";
Expand Down Expand Up @@ -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<string, DeploymentState> > = new ReplaySubject< Map<string, DeploymentState> >(1);

public serviceVdbSuffix = "VDB"; // Don't change - must match komodo naming convention

private http: Http;
private notifierService: NotifierService;
private appSettingsService: AppSettingsService;
Expand Down Expand Up @@ -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
Expand All @@ -325,23 +335,26 @@ export class DataserviceService extends ApiService {
*/
public createDataserviceForSingleSourceTables(dataservice: NewDataservice, sourceTables: Table[]): Observable<boolean> {
// 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));
}
Expand Down
15 changes: 15 additions & 0 deletions ngapp/src/app/dataservices/shared/vdb-model-source.model.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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)
*/
Expand Down Expand Up @@ -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
Expand Down
48 changes: 42 additions & 6 deletions ngapp/src/app/dataservices/shared/vdb.service.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion ngapp/src/app/dataservices/shared/vdbs-constants.ts
Expand Up @@ -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";
Expand Down

0 comments on commit 66b4b8e

Please sign in to comment.