Skip to content

Commit

Permalink
display error message if cannot connect to db controller service
Browse files Browse the repository at this point in the history
  • Loading branch information
scottreisdorf committed Nov 29, 2018
1 parent 3ff32e2 commit 973f6e7
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</mat-form-field>

<div *ngIf="databaseConnectionError == true" fxLayout="column">
<div class="layout-padding-top-bottom">Unable to connect to selected data source.</div>
<div class="layout-padding-top-bottom">{{databaseConnectionErrorMessage}}</div>

<mat-form-field class="layout-padding-top-bottom" *ngIf="renderLoadStrategyOptions" fxFill>
<input matInput placeholder="Table Name" [(ngModel)]="tableProperty.value" (change)="onManualTableNameChange()">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export class TablePropertiesComponent implements OnChanges, OnInit {
*/
databaseConnectionError = false;

databaseConnectionErrorMessage: string;

dbConnectionProperty: any;

deleteSourceProperty: any;
Expand Down Expand Up @@ -232,12 +234,12 @@ export class TablePropertiesComponent implements OnChanges, OnInit {
const hintSuffix = ". ** indicates an existing catalog data source";
if(this.dbConnectionProperty) {
let desc = this.dbConnectionProperty.propertyDescriptor.origDescription || this.dbConnectionProperty.propertyDescriptor.description;
if (!this.processor.form.disabled) {
if (desc != undefined && !this.processor.form.disabled) {
if(desc.indexOf(hintSuffix) == -1){
this.dbConnectionProperty.propertyDescriptor.origDescription = desc;
this.dbConnectionProperty.propertyDescriptor.description = desc+hintSuffix;
}
} else {
} else if(desc != undefined){
this.dbConnectionProperty.propertyDescriptor.description = desc;
}
}
Expand Down Expand Up @@ -464,7 +466,11 @@ export class TablePropertiesComponent implements OnChanges, OnInit {
}
}

console.log("get ",this.tableSchemaService.LIST_TABLES_URL(this.dbConnectionProperty.value), 'with ',httpOptions.params)
return this.http.get(this.tableSchemaService.LIST_TABLES_URL(this.dbConnectionProperty.value), httpOptions).pipe(
catchError((error: any) => {
return Observable.throw(error);
}),
map((data: any) => {
if (Array.isArray(data)) {
return data;
Expand All @@ -481,6 +487,15 @@ export class TablePropertiesComponent implements OnChanges, OnInit {
}),
catchError<any, any[]>((error: any) => {
this.databaseConnectionError = true;
if(error && error.error && error.error.message){
this.databaseConnectionErrorMessage = error.error.message;
}
else if(error && error.message ){
this.databaseConnectionErrorMessage = error.message;
}
else {
this.databaseConnectionErrorMessage = "Unable to connecto to data source";
}
throw error;
})
);
Expand Down Expand Up @@ -540,8 +555,9 @@ export class TablePropertiesComponent implements OnChanges, OnInit {
this.tableSchema = response;
this.tableFields = this.tableSchema.fields;
this.filteredFieldDates = this.tableFields.filter(this.filterFieldDates);
}, () => {
}, (error:any) => {
this.databaseConnectionError = true;
console.error("error",error)
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ public QueryResult executeQueryForDatasource(@Nonnull final JdbcDatasource datas
* Executes the specified SELECT query in the context of the specified data source.
*
* @param datasource the JDBC datasource
* @param query the query to execute
* @return the query results
* @throws DataAccessException if the query cannot be executed
* @throws IllegalArgumentException if the datasource is invalid
Expand Down Expand Up @@ -492,7 +491,7 @@ private List<String> getTableNamesForControllerService(DescribeTableControllerSe
return null;
}

private boolean evaluateWithUserDefinedDatasources(PoolingDataSourceService.DataSourceProperties dataSourceProperties, AbstractControllerServiceRequest serviceProperties) {
private boolean evaluateWithUserDefinedDatasources(PoolingDataSourceService.DataSourceProperties dataSourceProperties, AbstractControllerServiceRequest serviceProperties) throws InvalidControllerServiceLookupException {
boolean valid = !isMasked(dataSourceProperties.getPassword());
if (!valid) {
List<Datasource> matchingDatasources = metadataAccess.read(() -> {
Expand Down Expand Up @@ -523,6 +522,8 @@ private boolean evaluateWithUserDefinedDatasources(PoolingDataSourceService.Data
String example = propertyKey + "=PASSWORD";
log.error("Unable to connect to Controller Service {}, {}. You need to specify a configuration property as {} with the password for user: {}. ",
serviceProperties.getControllerServiceName(), serviceProperties.getControllerServiceId(), example, dataSourceProperties.getUser());

throw new InvalidControllerServiceLookupException("Unable to connect to Controller Service "+serviceProperties.getControllerServiceName()+". Please ensure Kylo has a configuration property matching ["+example+"] to connect to this source ");
}
}
return valid;
Expand Down Expand Up @@ -569,7 +570,7 @@ public PoolingDataSourceService.DataSourceProperties parseControllerService(Cont
}


private TableSchema describeTableForControllerService(DescribeTableControllerServiceRequest serviceProperties) {
private TableSchema describeTableForControllerService(DescribeTableControllerServiceRequest serviceProperties) throws InvalidControllerServiceLookupException {

String type = serviceProperties.getControllerServiceType();
if (serviceProperties.getControllerServiceType() != null && serviceProperties.getControllerServiceType().equalsIgnoreCase(type)) {
Expand All @@ -586,8 +587,6 @@ private TableSchema describeTableForControllerService(DescribeTableControllerSer
DataSource dataSource = PoolingDataSourceService.getDataSource(dataSourceProperties);
DBSchemaParser schemaParser = new DBSchemaParser(dataSource, kerberosHiveConfiguration);
return schemaParser.describeTable(serviceProperties.getSchemaName(), serviceProperties.getTableName());
} else {
return null;
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.thinkbiganalytics.feedmgr.nifi.controllerservice;

/*-
* #%L
* kylo-feed-manager-controller
* %%
* Copyright (C) 2017 ThinkBig Analytics
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

public class InvalidControllerServiceLookupException extends RuntimeException {

public InvalidControllerServiceLookupException() {
super();
}

public InvalidControllerServiceLookupException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver;
import com.thinkbiganalytics.feedmgr.nifi.TemplateConnectionUtil;
import com.thinkbiganalytics.feedmgr.nifi.controllerservice.DBCPConnectionPoolService;
import com.thinkbiganalytics.feedmgr.nifi.controllerservice.InvalidControllerServiceLookupException;
import com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl;
import com.thinkbiganalytics.feedmgr.service.datasource.DatasourceService;
import com.thinkbiganalytics.feedmgr.service.template.FeedManagerTemplateService;
Expand Down Expand Up @@ -461,13 +462,18 @@ public Response getTableNames(@PathParam("serviceId") String serviceId, @QueryPa
log.info("Query for Table Names against data source: {}", dataSource.get().getId());
try {
tables = catalogTableManager.getTableNames(dataSource.get(), schema, tableName);
} catch (final SQLException e) {
} catch (final SQLException | InvalidControllerServiceLookupException e) {
log.error("Unable to list table names for data source: {}", dataSource.get().getId(), e);
throw new InternalServerErrorException("Unable to connect to data source. " + e.getMessage(), e);
throw new InternalServerErrorException(e.getMessage(), e);
}
} else {
log.info("Query for Table Names against service: {}({})", serviceName, serviceId);
try {
tables = dbcpConnectionPoolTableInfo.getTableNamesForControllerService(serviceId, serviceName, schema, tableName);
} catch (final InvalidControllerServiceLookupException e) {
log.error("Unable to list table names for controller service: {}", serviceName, e);
throw new InternalServerErrorException(e.getMessage(), e);
}
}

return Response.ok(tables).build();
Expand Down

0 comments on commit 973f6e7

Please sign in to comment.