|
@@ -114,8 +114,7 @@ class Command(NoArgsCommand):
|
|
|
|
|
|
|
|
for table_dict in table_list:
|
|
for table_dict in table_list:
|
|
|
table = SampleTable(table_dict)
|
|
table = SampleTable(table_dict)
|
|
|
- if not table.install(django_user):
|
|
|
|
|
- raise InstallException('Failed to install sample table %s' % (table.name,))
|
|
|
|
|
|
|
+ table.install(django_user)
|
|
|
LOG.info('Successfully created sample tables with data')
|
|
LOG.info('Successfully created sample tables with data')
|
|
|
|
|
|
|
|
def _install_reports(self, django_user):
|
|
def _install_reports(self, django_user):
|
|
@@ -128,8 +127,7 @@ class Command(NoArgsCommand):
|
|
|
|
|
|
|
|
for design_dict in design_list:
|
|
for design_dict in design_list:
|
|
|
design = SampleDesign(design_dict)
|
|
design = SampleDesign(design_dict)
|
|
|
- if not design.install(django_user):
|
|
|
|
|
- raise InstallException('Failed to install sample query %s' % (design.name,))
|
|
|
|
|
|
|
+ design.install(django_user)
|
|
|
LOG.info('Successfully installed all sample queries')
|
|
LOG.info('Successfully installed all sample queries')
|
|
|
|
|
|
|
|
|
|
|
|
@@ -161,34 +159,37 @@ class SampleTable(object):
|
|
|
raise ValueError(msg)
|
|
raise ValueError(msg)
|
|
|
|
|
|
|
|
def install(self, django_user):
|
|
def install(self, django_user):
|
|
|
- return self.create(django_user) and self.load(django_user)
|
|
|
|
|
|
|
+ self.create(django_user)
|
|
|
|
|
+ self.load(django_user)
|
|
|
|
|
|
|
|
def create(self, django_user):
|
|
def create(self, django_user):
|
|
|
"""
|
|
"""
|
|
|
- Create in Hive. Returns True/False.
|
|
|
|
|
|
|
+ Create in Hive. Raise InstallException on failure.
|
|
|
"""
|
|
"""
|
|
|
# Create table
|
|
# Create table
|
|
|
LOG.info('Creating table "%s"' % (self.name,))
|
|
LOG.info('Creating table "%s"' % (self.name,))
|
|
|
try:
|
|
try:
|
|
|
# Already exists?
|
|
# Already exists?
|
|
|
tables = db_utils.meta_client().get_table("default", self.name)
|
|
tables = db_utils.meta_client().get_table("default", self.name)
|
|
|
- LOG.error('Table "%s" already exists' % (self.name,))
|
|
|
|
|
- return False
|
|
|
|
|
|
|
+ msg = 'Table "%s" already exists' % (self.name,)
|
|
|
|
|
+ LOG.error(msg)
|
|
|
|
|
+ raise InstallException(msg)
|
|
|
except hive_metastore.ttypes.NoSuchObjectException:
|
|
except hive_metastore.ttypes.NoSuchObjectException:
|
|
|
query_msg = _make_query_msg(self.hql)
|
|
query_msg = _make_query_msg(self.hql)
|
|
|
try:
|
|
try:
|
|
|
results = db_utils.execute_and_wait(django_user, query_msg)
|
|
results = db_utils.execute_and_wait(django_user, query_msg)
|
|
|
if not results:
|
|
if not results:
|
|
|
- LOG.error('Error creating table %s: Operation timeout' % (self.name,))
|
|
|
|
|
- return False
|
|
|
|
|
|
|
+ msg = 'Error creating table %s: Operation timeout' % (self.name,)
|
|
|
|
|
+ LOG.error(msg)
|
|
|
|
|
+ raise InstallException(msg)
|
|
|
except BeeswaxException, ex:
|
|
except BeeswaxException, ex:
|
|
|
- LOG.error('Error creating table %s: %s' % (self.name, ex))
|
|
|
|
|
- return False
|
|
|
|
|
- return True
|
|
|
|
|
|
|
+ msg = 'Error creating table %s: %s' % (self.name, ex)
|
|
|
|
|
+ LOG.error(msg)
|
|
|
|
|
+ raise InstallException(msg)
|
|
|
|
|
|
|
|
def load(self, django_user):
|
|
def load(self, django_user):
|
|
|
"""
|
|
"""
|
|
|
- Load data into table.
|
|
|
|
|
|
|
+ Load data into table. Raise InstallException on failure.
|
|
|
"""
|
|
"""
|
|
|
LOAD_HQL = \
|
|
LOAD_HQL = \
|
|
|
"""
|
|
"""
|
|
@@ -202,12 +203,13 @@ class SampleTable(object):
|
|
|
try:
|
|
try:
|
|
|
results = db_utils.execute_and_wait(django_user, query_msg)
|
|
results = db_utils.execute_and_wait(django_user, query_msg)
|
|
|
if not results:
|
|
if not results:
|
|
|
- LOG.error('Error loading table %s: Operation timeout' % (self.name,))
|
|
|
|
|
- return False
|
|
|
|
|
|
|
+ msg = 'Error loading table %s: Operation timeout' % (self.name,)
|
|
|
|
|
+ LOG.error(msg)
|
|
|
|
|
+ raise InstallException(msg)
|
|
|
except BeeswaxException, ex:
|
|
except BeeswaxException, ex:
|
|
|
- LOG.error('Error loading table %s: %s' % (self.name, ex))
|
|
|
|
|
- return False
|
|
|
|
|
- return True
|
|
|
|
|
|
|
+ msg = 'Error loading table %s: %s' % (self.name, ex)
|
|
|
|
|
+ LOG.error(msg)
|
|
|
|
|
+ raise InstallException(msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
class SampleDesign(object):
|
|
class SampleDesign(object):
|
|
@@ -219,12 +221,16 @@ class SampleDesign(object):
|
|
|
self.data = data_dict['data']
|
|
self.data = data_dict['data']
|
|
|
|
|
|
|
|
def install(self, django_user):
|
|
def install(self, django_user):
|
|
|
|
|
+ """
|
|
|
|
|
+ Install design. Raise InstallException on failure.
|
|
|
|
|
+ """
|
|
|
LOG.info('Installing sample design: %s' % (self.name,))
|
|
LOG.info('Installing sample design: %s' % (self.name,))
|
|
|
try:
|
|
try:
|
|
|
# Don't overwrite
|
|
# Don't overwrite
|
|
|
model = models.SavedQuery.objects.get(owner=django_user, name=self.name)
|
|
model = models.SavedQuery.objects.get(owner=django_user, name=self.name)
|
|
|
- LOG.error('Sample design %s already exists' % (self.name,))
|
|
|
|
|
- return False
|
|
|
|
|
|
|
+ msg = 'Sample design %s already exists' % (self.name,)
|
|
|
|
|
+ LOG.error(msg)
|
|
|
|
|
+ raise InstallException(msg)
|
|
|
except models.SavedQuery.DoesNotExist:
|
|
except models.SavedQuery.DoesNotExist:
|
|
|
model = models.SavedQuery(owner=django_user, name=self.name)
|
|
model = models.SavedQuery(owner=django_user, name=self.name)
|
|
|
model.type = self.type
|
|
model.type = self.type
|
|
@@ -234,4 +240,3 @@ class SampleDesign(object):
|
|
|
model.desc = self.desc
|
|
model.desc = self.desc
|
|
|
model.save()
|
|
model.save()
|
|
|
LOG.info('Successfully installed sample design: %s' % (self.name,))
|
|
LOG.info('Successfully installed sample design: %s' % (self.name,))
|
|
|
- return True
|
|
|