-
Notifications
You must be signed in to change notification settings - Fork 1.8k
PAI quota management #1021
PAI quota management #1021
Changes from all commits
d77a99c
695d866
b7e9799
7cb03f9
44d1565
7ab7386
d9e1ea8
2c225a8
be23f55
6f760ab
9161209
e661c55
4e5d836
f80e737
aefc219
4fec2cc
dc45661
11fec6f
a03a191
7c7832c
2c862dc
85c015d
85cb472
3784355
d91c980
9786650
ef176d2
1089e80
627e823
b633c26
035d58b
cd549df
964743a
8422992
40391ec
1d84526
1852457
754a354
1ee9735
9f4485c
b1c3774
5d7923e
281f3dc
2ce9157
571a7af
f09d51a
41a9a59
21165b5
d25f7b5
17e719e
e25ffbd
5e777d2
6ff24a5
ccf6c04
eb5e21c
f796c60
e1ae623
ec41d56
080ae00
f0a2d39
77526d3
d95c351
346d49d
6af4b86
cf5336d
aec4977
b1dfaff
6c9360a
0663218
5187b2c
5032694
edf6b3b
01904eb
5951a63
439dfb7
03be709
3a3bfb9
c577553
0f57ca0
2f83c6b
7976205
c18ac6c
0aa038d
93d6502
b5eab4b
f39d69e
d2c7c8f
a030505
c7ca451
df2f99b
40bae6e
a2617b6
c5acd8c
0b85482
ccad629
dc2cd24
9f1fef7
a684a64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import json | ||
import shutil | ||
from .constants import NNICTL_HOME_DIR | ||
from .common_utils import print_error | ||
|
||
class Config: | ||
'''a util class to load and save config''' | ||
|
@@ -119,4 +120,26 @@ def read_file(self): | |
return json.load(file) | ||
except ValueError: | ||
return {} | ||
return {} | ||
return {} | ||
|
||
class HDFSConfig: | ||
'''manage hdfs configuration''' | ||
def __init__(self): | ||
os.makedirs(NNICTL_HOME_DIR, exist_ok=True) | ||
self.hdfs_config_file = os.path.join(NNICTL_HOME_DIR, '.hdfs') | ||
|
||
def get_config(self): | ||
if os.path.exists(self.hdfs_config_file): | ||
try: | ||
with open(self.hdfs_config_file, 'r') as file: | ||
return json.load(file) | ||
except Exception as exception: | ||
print_error(exception) | ||
return None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exception should be logged. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. |
||
else: | ||
return None | ||
|
||
def set_config(self, host, user_name): | ||
with open(self.hdfs_config_file, 'w') as file: | ||
json.dump({'host':host, 'userName': user_name}, file) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,8 @@ | |
import time | ||
from subprocess import call, check_output | ||
from .rest_utils import rest_get, rest_delete, check_rest_server_quick, check_response | ||
from .config_utils import Config, Experiments | ||
from pyhdfs import HdfsClient, HdfsFileNotFoundException | ||
from .config_utils import Config, Experiments, HDFSConfig | ||
from .url_utils import trial_jobs_url, experiment_url, trial_job_id_url | ||
from .constants import NNICTL_HOME_DIR, EXPERIMENT_INFORMATION_FORMAT, EXPERIMENT_DETAIL_FORMAT, \ | ||
EXPERIMENT_MONITOR_INFO, TRIAL_MONITOR_HEAD, TRIAL_MONITOR_CONTENT, TRIAL_MONITOR_TAIL, REST_TIME_OUT | ||
|
@@ -505,3 +506,35 @@ def export_trials_data(args): | |
print_error('Export failed...') | ||
else: | ||
print_error('Restful server is not Running') | ||
|
||
def hdfs_set(args): | ||
hdfsConfig = HDFSConfig() | ||
hdfsConfig.set_config(args.host, args.user_name) | ||
print_normal('HDFS account update success!') | ||
|
||
def hdfs_clean(args): | ||
hdfsConfig = HDFSConfig() | ||
if not hdfsConfig.get_config(): | ||
print_error('Please use \'nnictl hdfs set\' command to set hdfs account first!') | ||
exit(1) | ||
host = hdfsConfig.get_config().get('host') | ||
user_name = hdfsConfig.get_config().get('userName') | ||
hdfs_client = HdfsClient(hosts='{0}:80'.format(host), user_name=user_name, webhdfs_path='/webhdfs/api/v1', timeout=5) | ||
root_path = os.path.join('/', user_name, 'nni', 'experiments') | ||
while True: | ||
inputs = input('INFO: clean up all files in {0}, do you want to continue?[Y/N]:'.format(root_path)) | ||
if inputs.lower() not in ['y', 'n', 'yes', 'no']: | ||
print_warning('please input Y or N!') | ||
elif inputs.lower() in ['n', 'no']: | ||
exit(0) | ||
else: | ||
break | ||
path_list = hdfs_client.listdir(root_path) | ||
for path in path_list: | ||
full_path = os.path.join(root_path, path) | ||
print_normal('deleting {0}'.format(full_path)) | ||
if hdfs_client.delete(full_path, recursive=True): | ||
print_normal('delete success!') | ||
else: | ||
print_normal('delete failed!') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to show why failed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to use <root_path>/* ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, but we want to show the details of deleting process, so we do not delete root_path directly, instead we traverse the paths under root_path, and show the paths to users. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, this function return false if delete failed, but do not give error message and do not throw any exception. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
print_normal('DONE') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please give simple example about what is the format of hdfs host
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given an example in the grid.