def wrapper(*args, **kwargs): resp = fct(*args, **kwargs) if not resp.ok: raise iex.IntelPluginException( "Request to manager returned with code '%s', reason '%s' and " "response '%s'" % (resp.status_code, resp.reason, resp.text)) else: return json.loads(resp.text)
def get_datanode_status(self, datanode): stats = self.get_datanodes_status() for stat in stats: if stat['hostname'] == datanode: return stat['status'].strip() raise iex.IntelPluginException( "Datanode service is is not installed on node '%s'" % datanode)
def status(self): url = '/cluster/%s/services' % self.cluster_name statuses = self.rest.get(url)['items'] for st in statuses: if st['serviceName'] == self.service: return st['status'] raise iex.IntelPluginException( "Service '%s' is not installed on cluster '%s'" % (self.service, self.cluster_name))
def start(self): url = ('/cluster/%s/services/%s/commands/start' % (self.cluster_name, self.service)) self.rest.post(url) #TODO(alazarev) make timeout configurable (bug #1262897) timeout = 600 cur_time = 0 while cur_time < timeout: context.sleep(2) if self.status() == 'running': break else: cur_time += 2 else: raise iex.IntelPluginException( "Service '%s' has failed to start in %s seconds" % (self.service, timeout))
def wait(ctx, session_id): #TODO(lazarev) add check on savanna cluster state (exit on delete) #TODO(alazarev) make configurable (bug #1262897) timeout = 4 * 60 * 60 # 4 hours cur_time = 0 while cur_time < timeout: info_items = get(ctx, session_id)['items'] for item in info_items: progress = item['nodeprogress'] if progress['info'].strip() == '_ALLFINISH': return else: context.sleep(10) cur_time += 10 debug_msg = 'Hostname: %s\nInfo: %s' debug_msg = debug_msg % (progress['hostname'], progress['info']) LOG.debug(debug_msg) else: raise iex.IntelPluginException( "Cluster '%s' has failed to start in %s minutes" % (ctx.cluster_name, timeout / 60))
def add(self, nodes, rack, username, path_to_key, keypass=''): hosts = { 'method': 'useauthzkeyfile', 'nodeinfo': map( lambda host: { 'hostname': host, 'username': username, 'passphrase': keypass, 'authzkeyfile': path_to_key, 'rackName': rack }, nodes) } url = '/cluster/%s/nodes' % self.cluster_name resp = self.rest.post(url, hosts)['items'] for node_info in resp: if node_info['info'] != 'Connected': raise iex.IntelPluginException('Error adding nodes: %s' % node_info['iporhostname'])
def install_manager(cluster): LOG.info("Starting Install Manager Process") mng_instance = u.get_instance(cluster, 'manager') idh_tarball_path = c_helper.get_config_value( cluster.cluster_configs.get('general'), c_helper.IDH_TARBALL_URL) idh_tarball_filename = idh_tarball_path.rsplit('/', 1)[-1] idh_dir = idh_tarball_filename[:idh_tarball_filename.find('.tar.gz')] LOG.info("IDH tgz will be retrieved from: \'%s\'", idh_tarball_path) idh_repo = c_helper.get_config_value( cluster.cluster_configs.get('general'), c_helper.IDH_REPO_URL) os_repo = c_helper.get_config_value(cluster.cluster_configs.get('general'), c_helper.OS_REPO_URL) idh_install_cmd = 'sudo ./%s/install.sh --mode=silent 2>&1' % idh_dir with mng_instance.remote() as r: LOG.info("Download IDH manager ") try: r.execute_command('curl -O %s 2>&1' % idh_tarball_path) except Exception as e: raise RuntimeError("Unable to download IDH manager from %s", idh_tarball_path, e) # unpack archive LOG.info("Unpack manager %s ", idh_tarball_filename) try: r.execute_command('tar xzf %s 2>&1' % idh_tarball_filename) except Exception as e: raise RuntimeError("Unable to unpack tgz %s", idh_tarball_filename, e) # install idh LOG.debug("Install manager with %s : ", idh_install_cmd) inst_conf = _INST_CONF_TEMPLATE % (os_repo, idh_repo) r.write_file_to('%s/ui-installer/conf' % idh_dir, inst_conf) #TODO(alazarev) make timeout configurable (bug #1262897) r.execute_command(idh_install_cmd, timeout=3600) # fix nginx persimmions bug r.execute_command('sudo chmod o+x /var/lib/nginx/ /var/lib/nginx/tmp ' '/var/lib/nginx/tmp/client_body') # waiting start idh manager #TODO(alazarev) make timeout configurable (bug #1262897) timeout = 600 LOG.debug("Waiting %s seconds for Manager to start : ", timeout) while timeout: try: telnetlib.Telnet(mng_instance.management_ip, 9443) break except IOError: timeout -= 2 context.sleep(2) else: message = ("IDH Manager failed to start in %s minutes on node '%s' " "of cluster '%s'" % (timeout / 60, mng_instance.management_ip, cluster.name)) LOG.error(message) raise iex.IntelPluginException(message)