Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions airflow/hooks/jdbc_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def get_conn(self):
host = conn.host
login = conn.login
psw = conn.password
jdbc_driver_loc = conn.extra_dejson.get('jdbc_drv_path')
jdbc_driver_name = conn.extra_dejson.get('jdbc_drv_clsname')
jdbc_driver_loc = conn.extra_dejson.get('extra__jdbc__drv_path')
jdbc_driver_name = conn.extra_dejson.get('extra__jdbc__drv_clsname')

conn = jaydebeapi.connect(jdbc_driver_name,
[str(host), str(login), str(psw)],
Expand All @@ -52,4 +52,4 @@ def set_autocommit(self, conn, autocommit):
:param conn: The connection
:return:
"""
conn.jconn.autocommit = autocommit
conn.jconn.autocommit = autocommit
39 changes: 24 additions & 15 deletions airflow/www/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1586,9 +1586,15 @@ class ConnectionModelView(wwwutils.SuperUserMixin, AirflowModelView):
column_default_sort = ('conn_id', False)
column_list = ('conn_id', 'conn_type', 'host', 'port')
form_overrides = dict(password=VisiblePasswordField)
form_extra_fields = { 'jdbc_drv_path' : StringField('Driver Path'),
'jdbc_drv_clsname': StringField('Driver Class'),
}
# Used to customized the form, the forms elements get rendered
# and results are stored in the extra field as json. All of these
# need to be prefixed with extra__ and then the conn_type ___ as in
# extra__{conn_type}__name. You can also hide form elements and rename
# others from the connection_form.js file
form_extra_fields = {
'extra__jdbc__drv_path' : StringField('Driver Path'),
'extra__jdbc__drv_clsname': StringField('Driver Class'),
}
form_choices = {
'conn_type': [
('ftp', 'FTP',),
Expand All @@ -1607,24 +1613,27 @@ class ConnectionModelView(wwwutils.SuperUserMixin, AirflowModelView):
('sqlite', 'Sqlite',),
('mssql', 'Microsoft SQL Server'),
]

}

def on_model_change(self, form, model, is_created):
formdata = form.data
if formdata['conn_type'] == 'jdbc':
jdbc = {key:formdata[key] for key in ('jdbc_drv_path','jdbc_drv_clsname'
#, 'jdbc_conn_url'
) if key in formdata}
model.extra = json.dumps(jdbc)
if formdata['conn_type'] in ['jdbc']:
extra = {
key:formdata[key]
for key in self.form_extra_fields.keys() if key in formdata}
model.extra = json.dumps(extra)

def on_form_prefill(self, form, id):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the bug as not all extra configs have jdbc_drv_path

data = form.data
if 'extra' in data and data['extra'] != None:
d = json.loads(data['extra'])
#form.jdbc_conn_url.data = d['jdbc_conn_url']
form.jdbc_drv_path.data = d['jdbc_drv_path']
form.jdbc_drv_clsname.data = d['jdbc_drv_clsname']
try:
d = json.loads(form.data.get('extra', '{}'))
except Exception as e:
d = {}

for field in self.form_extra_fields.keys():
value = d.get(field, '')
if value:
field = getattr(form, field)
field.data = value

mv = ConnectionModelView(
models.Connection, Session,
Expand Down
42 changes: 42 additions & 0 deletions airflow/www/static/connection_form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Created by janomar on 23/07/15.
*/

$(document).ready(function() {
var config = {
jdbc: {
hidden_fields: ['port', 'schema', 'extra'],
relabeling: {'host': 'Connection URL'},
}
}
function connTypeChange(connectionType) {
$("div.form_group").removeClass("hide");
$.each($("[id^='extra__']"), function() {
$(this).parent().parent().addClass('hide')
});
// Somehow the previous command doesn't honor __
$("#extra").parent().parent().removeClass('hide')
$.each($("[id^='extra__"+connectionType+"']"), function() {
$(this).parent().parent().removeClass('hide')
});
$("label[orig_text]").each(function(){
$(this).text($(this).attr("orig_text"));
});
if (config[connectionType] != undefined){
$.each(config[connectionType].hidden_fields, function(i, field){
$("#" + field).parent().parent().addClass('hide')
});
$.each(config[connectionType].relabeling, function(k, v){
lbl = $("label[for='" + k + "']")
lbl.attr("orig_text", lbl.text());
$("label[for='" + k + "']").text(v);
});
}
}
var connectionType=$("#conn_type").val();
$("#conn_type").on('change', function(e) {
connectionType = $("#conn_type").val();
connTypeChange(connectionType);
});
connTypeChange(connectionType);
});
26 changes: 0 additions & 26 deletions airflow/www/static/jdbc.js

This file was deleted.

2 changes: 1 addition & 1 deletion airflow/www/templates/airflow/conn_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

{% block tail %}
{{ super() }}
<script src="{{ url_for('static', filename='jdbc.js') }}"></script>
<script src="{{ url_for('static', filename='connection_form.js') }}"></script>
{% endblock %}
2 changes: 1 addition & 1 deletion airflow/www/templates/airflow/conn_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

{% block tail %}
{{ super() }}
<script src="{{ url_for('static', filename='jdbc.js') }}"></script>
<script src="{{ url_for('static', filename='connection_form.js') }}"></script>
{% endblock %}