Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
Logging statements for service actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacBlanco committed Jul 6, 2016
1 parent 04fc170 commit d743eca
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion scripts/ambari.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ def load_output(output):

def service_action(self, cluster_name, service_name, action):

logger.debug('Service Action: ' + action + '; Service Name: ' + service_name)
logger.info('Attempting Service Action: ' + action + '; Service Name: ' + service_name)
if not (action == 'START' or action == 'RESTART' or action == 'STOP'):
logger.error('Service actions was not one of START, STOP, or RESTART')
raise ValueError('Service action must be one of: START, STOP, or RESTART')

logger.info(action + 'ing ' + service_name + ' via Ambari REST API')
Expand All @@ -48,6 +49,7 @@ def service_action(self, cluster_name, service_name, action):

service_info = self.get_service(cluster_name, service_name, 'fields=ServiceInfo')[0]
before_state = service_info['ServiceInfo']['state']
logger.debug('Service state before attempting to change: ' + str(before_state))
after_state = ''

if action == 'STOP':
Expand All @@ -67,13 +69,16 @@ def service_action(self, cluster_name, service_name, action):
res = self.client.make_request('PUT', '/api/v1/clusters/' + cluster_name + '/services/' + service_name, '-i -d \'' + payload + '\' -H "X-Requested-By:ambari"', 'fields=ServiceInfo')

if not ('202 Accepted' in res[0] or '200 OK' in res[0]):
logger.error('No 200 Level status when attempting to change service state')
return False

service_state = ''
t = 0
while t < self.service_wait_time:
logger.debug('Checking for a change in service state')
service_state = self.get_service(cluster_name, service_name, 'fields=ServiceInfo')[0]['ServiceInfo']['state']
if service_state == after_state:
logger.info('Service action completed successfully')
return True
t += 1
time.sleep(1)
Expand Down

0 comments on commit d743eca

Please sign in to comment.