2022-06-23 02:20:56 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
2022-08-11 13:56:39 +00:00
|
|
|
import argparse
|
2022-06-23 02:20:56 +00:00
|
|
|
import json
|
2022-11-17 17:08:20 +00:00
|
|
|
from argparse import Namespace
|
|
|
|
|
2022-06-23 02:20:56 +00:00
|
|
|
from concurrent.futures import ProcessPoolExecutor
|
2022-11-17 17:08:20 +00:00
|
|
|
|
|
|
|
from helpers.cmd import random_payload
|
|
|
|
from helpers.neofs_cli import create_container, upload_object
|
2022-06-23 02:20:56 +00:00
|
|
|
|
2022-08-11 13:56:39 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
2022-06-23 02:20:56 +00:00
|
|
|
parser.add_argument('--size', help='Upload objects size in kb')
|
|
|
|
parser.add_argument('--containers', help='Number of containers to create')
|
|
|
|
parser.add_argument('--out', help='JSON file with output')
|
|
|
|
parser.add_argument('--preload_obj', help='Number of pre-loaded objects')
|
2022-08-11 13:56:39 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--policy",
|
|
|
|
help="Container placement policy",
|
2022-11-17 17:08:20 +00:00
|
|
|
default="REP 2 IN X CBF 2 SELECT 2 FROM * AS X"
|
2022-08-11 13:56:39 +00:00
|
|
|
)
|
2022-06-23 02:20:56 +00:00
|
|
|
parser.add_argument('--endpoint', help='Node address')
|
|
|
|
parser.add_argument('--update', help='Save existed containers')
|
|
|
|
|
2022-11-17 17:08:20 +00:00
|
|
|
args: Namespace = parser.parse_args()
|
2022-06-23 02:20:56 +00:00
|
|
|
print(args)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
container_list = []
|
|
|
|
objects_struct = []
|
2022-10-25 14:43:20 +00:00
|
|
|
payload_filepath = '/tmp/data_file'
|
2022-06-23 02:20:56 +00:00
|
|
|
|
|
|
|
if args.update:
|
|
|
|
# Open file
|
|
|
|
with open(args.out) as f:
|
|
|
|
data_json = json.load(f)
|
|
|
|
container_list = data_json['containers']
|
|
|
|
else:
|
|
|
|
print(f"Create containers: {args.containers}")
|
|
|
|
with ProcessPoolExecutor(max_workers=10) as executor:
|
2022-11-17 17:08:20 +00:00
|
|
|
containers_runs = {executor.submit(create_container, args.endpoint, args.policy): _ for _ in
|
|
|
|
range(int(args.containers))}
|
2022-06-23 02:20:56 +00:00
|
|
|
|
|
|
|
for run in containers_runs:
|
2022-11-17 17:08:20 +00:00
|
|
|
if run.result():
|
2022-10-25 14:43:20 +00:00
|
|
|
container_list.append(run.result())
|
2022-06-23 02:20:56 +00:00
|
|
|
|
|
|
|
print("Create containers: Completed")
|
|
|
|
|
|
|
|
print(f" > Containers: {container_list}")
|
2022-10-26 19:30:55 +00:00
|
|
|
if not container_list:
|
|
|
|
return
|
2022-06-23 02:20:56 +00:00
|
|
|
|
|
|
|
print(f"Upload objects to each container: {args.preload_obj} ")
|
2022-11-17 17:08:20 +00:00
|
|
|
random_payload(payload_filepath, args.size)
|
2022-06-23 02:20:56 +00:00
|
|
|
print(" > Create random payload: Completed")
|
|
|
|
|
|
|
|
for container in container_list:
|
|
|
|
print(f" > Upload objects for container {container}")
|
|
|
|
with ProcessPoolExecutor(max_workers=50) as executor:
|
2022-11-17 17:08:20 +00:00
|
|
|
objects_runs = {executor.submit(upload_object, container, payload_filepath, args.endpoint): _ for _ in
|
2022-10-25 14:43:20 +00:00
|
|
|
range(int(args.preload_obj))}
|
2022-06-23 02:20:56 +00:00
|
|
|
|
|
|
|
for run in objects_runs:
|
2022-11-17 17:08:20 +00:00
|
|
|
if run.result():
|
2022-10-25 14:43:20 +00:00
|
|
|
objects_struct.append({'container': container, 'object': run.result()})
|
2022-06-23 02:20:56 +00:00
|
|
|
print(f" > Upload objects for container {container}: Completed")
|
|
|
|
|
|
|
|
print("Upload objects to each container: Completed")
|
|
|
|
|
2022-10-25 14:43:20 +00:00
|
|
|
data = {'containers': container_list, 'objects': objects_struct, 'obj_size': args.size + " Kb"}
|
2022-06-23 02:20:56 +00:00
|
|
|
|
2022-10-25 15:01:08 +00:00
|
|
|
with open(args.out, 'w+') as f:
|
2022-10-25 15:06:43 +00:00
|
|
|
json.dump(data, f, ensure_ascii=False, indent=2)
|
2022-06-23 02:20:56 +00:00
|
|
|
|
|
|
|
print(f"Result:")
|
|
|
|
print(f" > Total Containers has been created: {len(container_list)}.")
|
|
|
|
print(f" > Total Objects has been created: {len(objects_struct)}.")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|