def __configure_celery(self, params): ''' Private method used for uploading the current celery configuration to each instance that is running and ssh connectable. Args parameters A dictionary of parameters ''' # Update celery config file...it should have the correct IP # of the Queue head node, which should already be running. # Pass it line by line so theres no weird formatting errors from # trying to echo a multi-line file directly on the command line logging.debug('__configure_celery() params={0}'.format(params)) flex_cloud_machine_info = params[self.PARAM_FLEX_CLOUD_MACHINE_INFO] instance_types = [] for machine in flex_cloud_machine_info: vm = VMStateModel.get_by_ip( machine['ip'], reservation_id=params['reservation_id']) commands = [] my_ins_type = 'Unknown' commands.append('source ~/.bashrc') if vm is None: logging.error('VMStateModel.get_by_ip({0}) in None'.format( machine['ip'])) continue else: my_ins_type = vm.ins_type commands.append('export INSTANCE_TYPE={0}'.format(vm.ins_type)) if vm.ins_type not in instance_types: instance_types.append(vm.ins_type) ip = machine['ip'] keyfile = machine['keyfile'] username = machine['username'] success = helper.start_celery_on_vm(instance_type=my_ins_type, ip=ip, key_file=keyfile, username=username, agent_type=self.agent_type, worker_name=ip.replace( '.', '_'), prepend_commands=commands) if success == 0: # update db with successful running vms logging.info("celery started on host ip: {0}".format(ip)) else: raise Exception("Fail to start celery on {0}".format(ip)) # get all intstance types and configure the celeryconfig.py locally logging.info('For local celery setup, instance_types = {0}'.format( instance_types)) helper.config_celery_queues(agent_type=self.agent_type, instance_types=instance_types)
def update_flex_cloud_machine_info_from_db(self, service): logging.debug('update_flex_cloud_machine_info_from_db') if self.is_flex_cloud_info_set: flex_cloud_machine_info = self.get_flex_cloud_machine_info() if flex_cloud_machine_info is None or len(flex_cloud_machine_info) == 0: return all_vms = self.__get_all_vms(AgentTypes.FLEX, service) #logging.debug('flex: all_vms =\n{0}'.format(pprint.pformat(all_vms))) logging.debug('flex: all_vms =\n{0}'.format(all_vms)) all_vms_map = {vm['pub_ip']: vm for vm in all_vms} #logging.debug('flex: all_vms_map =\n{0}'.format(pprint.pformat(all_vms_map))) logging.debug('flex: all_vms_map =\n{0}'.format(all_vms_map)) for machine in flex_cloud_machine_info: vms = VMStateModel.get_by_ip(machine['ip'], reservation_id=self.reservation_id) if vms is None: logging.debug('machine={0} vms=NONE'.format(machine)) else: logging.debug('machine={0} vms={1} {2}'.format(machine, vms.pub_ip, vms.state)) if vms and vms.res_id == self.reservation_id: machine['state'] = vms.state machine['description'] = vms.description else: if vms: logging.error('From VMStateModel, reservation_id = {0} != user_data.reservation_id'.format( vms.res_id )) machine['state'] = VMStateModel.STATE_UNKNOWN machine['description'] = VMStateModel.STATE_UNKNOWN for machine in flex_cloud_machine_info: machine['key_file_id'] = int(machine['key_file_id']) logging.debug('After updating from VMStateModel, flex_cloud_machine_info =\n{0}'.format( pprint.pformat(flex_cloud_machine_info))) # Update Flex Cloud Status valid_flex_cloud_info = False for machine in flex_cloud_machine_info: if machine['queue_head'] and machine['state'] == VMStateModel.STATE_RUNNING: valid_flex_cloud_info = True self.valid_flex_cloud_info = valid_flex_cloud_info self.set_flex_cloud_machine_info(flex_cloud_machine_info) self.put() logging.debug('valid_flex_cloud_info = {0}'.format(self.valid_flex_cloud_info)) else: # for clearing out db syn requests all_vms = self.__get_all_vms(AgentTypes.FLEX, service) logging.debug('flex: all_vms =\n{0}'.format(pprint.pformat(all_vms)))
def __configure_celery(self, params): """ Private method used for uploading the current celery configuration to each instance that is running and ssh connectable. Args parameters A dictionary of parameters """ # Update celery config file...it should have the correct IP # of the Queue head node, which should already be running. # Pass it line by line so theres no weird formatting errors from # trying to echo a multi-line file directly on the command line logging.debug("__configure_celery() params={0}".format(params)) flex_cloud_machine_info = params[self.PARAM_FLEX_CLOUD_MACHINE_INFO] instance_types = [] for machine in flex_cloud_machine_info: vm = VMStateModel.get_by_ip(machine["ip"], reservation_id=params["reservation_id"]) commands = [] my_ins_type = "Unknown" commands.append("source ~/.bashrc") if vm is None: logging.error("VMStateModel.get_by_ip({0}) in None".format(machine["ip"])) continue else: my_ins_type = vm.ins_type commands.append("export INSTANCE_TYPE={0}".format(vm.ins_type)) if vm.ins_type not in instance_types: instance_types.append(vm.ins_type) ip = machine["ip"] keyfile = machine["keyfile"] username = machine["username"] success = helper.start_celery_on_vm( instance_type=my_ins_type, ip=ip, key_file=keyfile, username=username, agent_type=self.agent_type, worker_name=ip.replace(".", "_"), prepend_commands=commands, ) if success == 0: # update db with successful running vms logging.info("celery started on host ip: {0}".format(ip)) else: raise Exception("Fail to start celery on {0}".format(ip)) # get all intstance types and configure the celeryconfig.py locally logging.info("For local celery setup, instance_types = {0}".format(instance_types)) helper.config_celery_queues(agent_type=self.agent_type, instance_types=instance_types)