|
@@ -15,7 +15,6 @@
|
|
|
# See the License for the specific language governing permissions and
|
|
|
# limitations under the License.
|
|
|
|
|
|
-"""This module has apis to create and remove a blockade cluster"""
|
|
|
|
|
|
from subprocess import call
|
|
|
import subprocess
|
|
@@ -36,11 +35,13 @@ class ClusterUtils(object):
|
|
|
logger.info("compose file :%s", docker_compose_file)
|
|
|
logger.info("number of DNs :%d", datanode_count)
|
|
|
call(["docker-compose", "-f", docker_compose_file, "down"])
|
|
|
- call(["docker-compose", "-f", docker_compose_file, "up", "-d", "--scale", "datanode=" + str(datanode_count)])
|
|
|
+ call(["docker-compose", "-f", docker_compose_file, "up", "-d",
|
|
|
+ "--scale", "datanode=" + str(datanode_count)])
|
|
|
|
|
|
logger.info("Waiting 30s for cluster start up...")
|
|
|
time.sleep(30)
|
|
|
- output = subprocess.check_output(["docker-compose", "-f", docker_compose_file, "ps"])
|
|
|
+ output = subprocess.check_output(["docker-compose", "-f",
|
|
|
+ docker_compose_file, "ps"])
|
|
|
output_array = output.split("\n")[2:-1]
|
|
|
|
|
|
container_list = []
|
|
@@ -51,23 +52,31 @@ class ClusterUtils(object):
|
|
|
time.sleep(2)
|
|
|
|
|
|
assert container_list, "no container found!"
|
|
|
- logger.info("blockade created with containers %s", ' '.join(container_list))
|
|
|
+ logger.info("blockade created with containers %s",
|
|
|
+ ' '.join(container_list))
|
|
|
|
|
|
return container_list
|
|
|
|
|
|
@classmethod
|
|
|
def cluster_destroy(cls, docker_compose_file):
|
|
|
+ logger.info("Running docker-compose -f %s down", docker_compose_file)
|
|
|
call(["docker-compose", "-f", docker_compose_file, "down"])
|
|
|
|
|
|
@classmethod
|
|
|
- def run_freon(cls, docker_compose_file, num_volumes, num_buckets, num_keys, key_size,
|
|
|
- replication_type, replication_factor):
|
|
|
+ def run_freon(cls, docker_compose_file, num_volumes, num_buckets,
|
|
|
+ num_keys, key_size, replication_type, replication_factor):
|
|
|
# run freon
|
|
|
- cmd = "docker-compose -f %s exec ozoneManager /opt/hadoop/bin/ozone freon rk " \
|
|
|
- "--numOfVolumes %s --numOfBuckets %s --numOfKeys %s --keySize %s " \
|
|
|
- "--replicationType %s --factor %s" % (docker_compose_file, num_volumes,
|
|
|
- num_buckets, num_keys, key_size, replication_type,
|
|
|
- replication_factor)
|
|
|
+ cmd = "docker-compose -f %s " \
|
|
|
+ "exec ozoneManager /opt/hadoop/bin/ozone " \
|
|
|
+ "freon rk " \
|
|
|
+ "--numOfVolumes %s " \
|
|
|
+ "--numOfBuckets %s " \
|
|
|
+ "--numOfKeys %s " \
|
|
|
+ "--keySize %s " \
|
|
|
+ "--replicationType %s " \
|
|
|
+ "--factor %s" % (docker_compose_file, num_volumes,
|
|
|
+ num_buckets, num_keys, key_size,
|
|
|
+ replication_type, replication_factor)
|
|
|
exit_code, output = cls.run_cmd(cmd)
|
|
|
return exit_code, output
|
|
|
|
|
@@ -78,7 +87,8 @@ class ClusterUtils(object):
|
|
|
command = ' '.join(cmd)
|
|
|
logger.info(" RUNNING: " + command)
|
|
|
all_output = ""
|
|
|
- myprocess = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
|
|
|
+ myprocess = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
|
|
+ stderr=subprocess.STDOUT, shell=True)
|
|
|
while myprocess.poll() is None:
|
|
|
op = myprocess.stdout.readline()
|
|
|
if op:
|
|
@@ -97,38 +107,49 @@ class ClusterUtils(object):
|
|
|
|
|
|
@classmethod
|
|
|
def get_ozone_confkey_value(cls, docker_compose_file, key_name):
|
|
|
- cmd = "docker-compose -f %s exec ozoneManager /opt/hadoop/bin/ozone getconf -confKey %s" \
|
|
|
- %(docker_compose_file, key_name)
|
|
|
+ cmd = "docker-compose -f %s " \
|
|
|
+ "exec ozoneManager /opt/hadoop/bin/ozone " \
|
|
|
+ "getconf -confKey %s" \
|
|
|
+ % (docker_compose_file, key_name)
|
|
|
exit_code, output = cls.run_cmd(cmd)
|
|
|
- assert exit_code == 0, "getconf of key=[%s] failed with output=[%s]" %(key_name, output)
|
|
|
- return output
|
|
|
+ assert exit_code == 0, "getconf of key=[%s] failed with output=[%s]" \
|
|
|
+ %(key_name, output)
|
|
|
+ return str(output).strip()
|
|
|
|
|
|
@classmethod
|
|
|
def find_scm_uuid(cls, docker_compose_file):
|
|
|
"""
|
|
|
This function returns scm uuid.
|
|
|
"""
|
|
|
- ozone_metadata_dir = cls.get_ozone_confkey_value(docker_compose_file, "ozone.metadata.dirs")
|
|
|
- cmd = "docker-compose -f %s exec scm cat %s/scm/current/VERSION" % (docker_compose_file, ozone_metadata_dir)
|
|
|
+ ozone_metadata_dir = cls.get_ozone_confkey_value(docker_compose_file,
|
|
|
+ "ozone.metadata.dirs")
|
|
|
+ cmd = "docker-compose -f %s exec scm cat %s/scm/current/VERSION" % \
|
|
|
+ (docker_compose_file, ozone_metadata_dir)
|
|
|
exit_code, output = cls.run_cmd(cmd)
|
|
|
assert exit_code == 0, "get scm UUID failed with output=[%s]" % output
|
|
|
output_list = output.split("\n")
|
|
|
- output_list = list(filter(lambda x: re.search("\w+=\w+", x), output_list))
|
|
|
+ output_list = list(filter(lambda x: re.search("\w+=\w+", x),
|
|
|
+ output_list))
|
|
|
output_dict = dict(map(lambda x: x.split("="), output_list))
|
|
|
return str(output_dict['scmUuid']).strip()
|
|
|
|
|
|
@classmethod
|
|
|
- def find_datanode_container_status(cls, docker_compose_file, datanode_index):
|
|
|
+ def find_datanode_container_status(cls, docker_compose_file,
|
|
|
+ datanode_index):
|
|
|
"""
|
|
|
This function returns the datanode's container replica state.
|
|
|
"""
|
|
|
- datanode_dir = cls.get_ozone_confkey_value(docker_compose_file, "hdds.datanode.dir")
|
|
|
+ datanode_dir = cls.get_ozone_confkey_value(docker_compose_file,
|
|
|
+ "hdds.datanode.dir")
|
|
|
scm_uuid = cls.find_scm_uuid(docker_compose_file)
|
|
|
- container_parent_path = "%s/hdds/%s/current/containerDir0" %(datanode_dir, scm_uuid)
|
|
|
- cmd = "docker-compose -f %s exec --index=%s datanode find %s -type f -name '*.container'" \
|
|
|
+ container_parent_path = "%s/hdds/%s/current/containerDir0" % \
|
|
|
+ (datanode_dir, scm_uuid)
|
|
|
+ cmd = "docker-compose -f %s exec --index=%s datanode find %s -type f " \
|
|
|
+ "-name '*.container'" \
|
|
|
% (docker_compose_file, datanode_index, container_parent_path)
|
|
|
exit_code, output = cls.run_cmd(cmd)
|
|
|
- assert exit_code == 0, "command=[%s] failed with output=[%s]" % (cmd, output)
|
|
|
+ assert exit_code == 0, "command=[%s] failed with output=[%s]" % \
|
|
|
+ (cmd, output)
|
|
|
assert output, "No container info present"
|
|
|
container_list = map(str.strip, output.split("\n"))
|
|
|
container_state = None
|
|
@@ -136,9 +157,12 @@ class ClusterUtils(object):
|
|
|
cmd = "docker-compose -f %s exec --index=%s datanode cat %s" \
|
|
|
% (docker_compose_file, datanode_index, container_path)
|
|
|
exit_code, output = cls.run_cmd(cmd)
|
|
|
- assert exit_code == 0, "command=[%s] failed with output=[%s]" % (cmd, output)
|
|
|
+ assert exit_code == 0, "command=[%s] failed with output=[%s]" % \
|
|
|
+ (cmd, output)
|
|
|
container_db_list = output.split("\n")
|
|
|
- container_db_list = list(filter(lambda x: re.search("\w+:\s\w+", x), container_db_list))
|
|
|
+ container_db_list = \
|
|
|
+ list(filter(lambda x: re.search("\w+:\s\w+", x),
|
|
|
+ container_db_list))
|
|
|
container_db_info = "\n".join(container_db_list)
|
|
|
container_db_dict = yaml.load(container_db_info)
|
|
|
for key, value in container_db_dict.items():
|
|
@@ -146,7 +170,8 @@ class ClusterUtils(object):
|
|
|
if not container_state:
|
|
|
container_state = container_db_dict['state']
|
|
|
else:
|
|
|
- assert container_db_dict['state'] == container_state, "all containers are not in same state"
|
|
|
+ assert container_db_dict['state'] == container_state, \
|
|
|
+ "all containers are not in same state"
|
|
|
|
|
|
return container_state
|
|
|
|
|
@@ -157,7 +182,10 @@ class ClusterUtils(object):
|
|
|
"""
|
|
|
all_datanode_container_status = []
|
|
|
for index in range(scale):
|
|
|
- all_datanode_container_status.append(cls.find_datanode_container_status(docker_compose_file, index+1))
|
|
|
- logger.info("All datanodes container status: %s", ' '.join(all_datanode_container_status))
|
|
|
+ all_datanode_container_status.append(
|
|
|
+ cls.find_datanode_container_status(docker_compose_file,
|
|
|
+ index+1))
|
|
|
+ logger.info("All datanodes container status: %s",
|
|
|
+ ' '.join(all_datanode_container_status))
|
|
|
|
|
|
return all_datanode_container_status
|