'endpoint that refreshes druid datasources metadata'

@has_access
@expose('/refresh_datasources/')
def refresh_datasources(self):

    session = db.session()
    DruidCluster = ConnectorRegistry.sources['druid'].cluster_class
    for cluster in session.query(DruidCluster).all():
        cluster_name = cluster.cluster_name
        try:
            cluster.refresh_datasources()
        except Exception as e:
            flash("Error    while    processing    cluster    '{}'\n{}".format(cluster_name, utils.error_msg_from_exception(e)), 'danger')
            logging.exception(e)
            return redirect('/druidclustermodelview/list/')
        cluster.metadata_last_refreshed = datetime.now()
        flash((('Refreshed    metadata    from    cluster    [' + cluster.cluster_name) + ']'), 'info')
    session.commit()
    return redirect('/druiddatasourcemodelview/list/')
