def get_active_workers(branch=None): """ Returns workers that may be operated on (i.e. have not been used) """ results = [] master = master_mdl.get_active_master(branch) if master: for item in ANWorker.scan(): if item.status in active_statuses: if item.master_name == master['master_name']: results.append( to_dict_ANW( item ) ) elif branch is None: for item in ANWorker.scan(): if item.status in active_statuses: results.append( to_dict_ANW( item ) ) results.sort( key=lambda x: (x['cluster_type'], x['aws_region'], x['status']) ) return results
def _terminate_single_worker( self, worker_id): worker = wkr.get_ANWorker( worker_id=worker_id ) self.app.logger.info("%r" % worker ) if worker['status'] in [wkr.CONFIG, wkr.NA]: worker = wkr.update_ANWorker( worker_id, status=wkr.TERMINATED) msg = {'status':'complete', 'data' : json_prep( worker )} status = 200 elif wkr.confirm_worker_running( worker ): #we have an active cluster master = mstr.get_active_master() if master: launcher_message = {'action':'terminate', 'worker_id': worker_id} launcher_config = sys_def_mdl.get_system_defaults( setting_name = 'launcher_config', component='Master' ) conn = boto.sqs.connect_to_region('us-east-1') lq = conn.create_queue( launcher_config['launcher_sqs_in'] ) worker = wkr.update_ANWorker( worker_id, status=wkr.MARKED_FOR_TERMINATION) mess = Message(body=json.dumps( launcher_message )) lq.write( mess ) msg = {'status':'complete', 'data' : json_prep( worker ) } status = 200 else: msg = {'status': 'error', 'data' : {'worker_id': worker_id}, 'message' : 'Running Cluster without an active master' } status = 409 #Conflict else: worker = wkr.update_ANWorker( worker_id, status=wkr.TERMINATED_WITH_ERROR) msg = {'status':'complete', 'data' : json_prep( worker )} status = 200 return (msg, status)
def get_master(): """ API Returns currently active master instance """ current_app.logger.info('get_master') import masterdirac.models.master as mstr import masterdirac.models.systemdefaults as sys_def local_settings = sys_def.get_system_defaults('local_settings', 'Master') master = mstr.get_active_master( local_settings['branch'] ) if master is not None: msg = {'status' : 'complete', 'data' : json_prep(master) } status = 200 else: msg = {'status' : 'error', 'data' : '', 'message':'No Active Master'} status = 404 return Response( json.dumps( msg ), mimetype='application/json', status = status )