Skip to content

Commit

Permalink
Merge pull request #1064 from anmolsachan/master
Browse files Browse the repository at this point in the history
Moved profiling to the begining of import flow
  • Loading branch information
shtripat authored Jan 8, 2019
2 parents 07677cf + 615452d commit 55edf1a
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
68 changes: 68 additions & 0 deletions tendrl/commons/flows/import_cluster/gluster_help.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import subprocess
import time

import pkg_resources
from ruamel import yaml
Expand Down Expand Up @@ -186,3 +188,69 @@ def import_gluster(parameters):
)

return True, ""


def enable_disable_volume_profiling(volumes, parameters):
try:
cluster = NS.tendrl.objects.Cluster(
integration_id=NS.tendrl_context.integration_id
).load()
# Enable / disable based on cluster flag volume_profiling_flag
# should be done only once while first sync. Later the volume
# level volume_profiling_state should be set based on individual
# volume level values
if cluster.volume_profiling_flag == "enable":
logger.log("info",
NS.publisher_id,
{"message": "Starting profiling for volumes"},
job_id=parameters['job_id'],
flow_id=parameters['flow_id']
)
for volume in volumes:
p = subprocess.Popen(
["gluster",
"volume",
"profile",
volume,
"start"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
retry = 1
while True:
if p.poll() is not None:
break
elif retry > 10 and p.poll() is None:
p.kill()
break
retry += 1
time.sleep(0.5)
if cluster.volume_profiling_flag == "disable":
logger.log("info",
NS.publisher_id,
{"message": "Stopping profiling for volumes"},
job_id=parameters['job_id'],
flow_id=parameters['flow_id']
)
for volume in volumes:
p = subprocess.Popen(
["gluster",
"volume",
"profile",
volume,
"stop"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
retry = 1
while True:
if p.poll() is not None:
break
elif retry > 10 and p.poll() is None:
p.kill()
break
retry += 1
time.sleep(0.5)
return True, ""
except Exception as ex:
return False, str(ex)
30 changes: 30 additions & 0 deletions tendrl/commons/objects/cluster/atoms/import_cluster/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import uuid

from tendrl.commons.event import Event
from tendrl.commons.flows.import_cluster.gluster_help \
import enable_disable_volume_profiling
from tendrl.commons.flows.import_cluster.gluster_help import import_gluster
from tendrl.commons.flows import utils as flow_utils
from tendrl.commons.message import ExceptionMessage
Expand Down Expand Up @@ -36,6 +38,34 @@ def run(self):
cluster_nodes = []
if len(node_list) > 1:
# This is the master node for this flow
# Find number of volumes in the cluster to run profiling job
cmd = cmd_utils.Command('gluster volume list')
out, err, rc = cmd.run()
if not err:
volumes = filter(None, out.split("\n"))
ret_val, err = enable_disable_volume_profiling(
volumes, self.parameters)
if not ret_val:
logger.log(
"error",
NS.publisher_id,
{"message": "Failed to %s profiling. Error: %s"
% (_cluster.volume_profiling_flag, err)
},
job_id=self.parameters['job_id'],
flow_id=self.parameters['flow_id']
)
return False
else:
logger.log(
"error",
NS.publisher_id,
{"message": "Failed to fetch volumes info for "
"enable/disable profiling."},
job_id=self.parameters['job_id'],
flow_id=self.parameters['flow_id']
)
return False
for node in node_list:
if NS.node_context.node_id != node:
new_params = self.parameters.copy()
Expand Down

0 comments on commit 55edf1a

Please sign in to comment.