Skip to content

Commit

Permalink
add failure handling permission denied
Browse files Browse the repository at this point in the history
  • Loading branch information
Limmen committed Aug 20, 2023
1 parent 1e9edb8 commit 02b469c
Showing 1 changed file with 47 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,11 @@ def getLogFile(self, request: csle_cluster.cluster_manager.cluster_manager_pb2.G
logging.info("Getting log file: {request.name}")
data = []
if os.path.exists(request.name):
with open(request.name, 'r') as fp:
data = ClusterManagerUtil.tail(fp, window=100).split("\n")
try:
with open(request.name, 'r') as fp:
data = ClusterManagerUtil.tail(fp, window=100).split("\n")
except Exception as e:
logging.info(f"Exception reading log file: {request.name}. Stacktrace: {str(e)}, {repr(e)}")
logs = data
return csle_cluster.cluster_manager.cluster_manager_pb2.LogsDTO(logs=logs)

Expand All @@ -407,9 +410,12 @@ def getFlaskLogs(self, request: csle_cluster.cluster_manager.cluster_manager_pb2
path = config.flask_log_file
logs = []
if os.path.exists(path):
with open(path, 'r') as fp:
data = ClusterManagerUtil.tail(fp, window=100).split("\n")
logs = data
try:
with open(path, 'r') as fp:
data = ClusterManagerUtil.tail(fp, window=100).split("\n")
logs = data
except Exception as e:
logging.info(f"Exception reading log file: {path}. Stacktrace: {str(e)}, {repr(e)}")
return csle_cluster.cluster_manager.cluster_manager_pb2.LogsDTO(logs=logs)

def getPostrgreSQLLogs(self, request: csle_cluster.cluster_manager.cluster_manager_pb2.GetPostgreSQLLogsMsg,
Expand All @@ -430,9 +436,12 @@ def getPostrgreSQLLogs(self, request: csle_cluster.cluster_manager.cluster_manag
item = os.path.join(path, f)
if os.path.isfile(item) and constants.FILE_PATTERNS.LOG_SUFFIX in item and \
constants.FILE_PATTERNS.GZ_SUFFIX not in item:
with open(item, 'r') as fp:
data = ClusterManagerUtil.tail(fp, window=100).split("\n")
logs = data
try:
with open(item, 'r') as fp:
data = ClusterManagerUtil.tail(fp, window=100).split("\n")
logs = data
except Exception as e:
logging.info(f"Exception reading log file: {item}. Stacktrace: {str(e)}, {repr(e)}")
return csle_cluster.cluster_manager.cluster_manager_pb2.LogsDTO(logs=logs)

def getDockerLogs(self, request: csle_cluster.cluster_manager.cluster_manager_pb2.GetDockerLogsMsg,
Expand Down Expand Up @@ -479,9 +488,12 @@ def getNginxLogs(self, request: csle_cluster.cluster_manager.cluster_manager_pb2
item = os.path.join(path, f)
if os.path.isfile(item) and constants.FILE_PATTERNS.LOG_SUFFIX in item \
and constants.FILE_PATTERNS.GZ_SUFFIX not in item:
with open(item, 'r') as fp:
data = ClusterManagerUtil.tail(fp, window=100).split("\n")
logs = data
try:
with open(item, 'r') as fp:
data = ClusterManagerUtil.tail(fp, window=100).split("\n")
logs = logs + data
except Exception as e:
logging.info(f"Exception reading log file: {item}. Stacktrace: {str(e)}, {repr(e)}")
return csle_cluster.cluster_manager.cluster_manager_pb2.LogsDTO(logs=logs)

def getGrafanaLogs(self, request: csle_cluster.cluster_manager.cluster_manager_pb2.GetGrafanaLogsMsg,
Expand Down Expand Up @@ -556,9 +568,12 @@ def getNodeExporterLogs(self, request: csle_cluster.cluster_manager.cluster_mana
path = config.node_exporter_log_file
logs = []
if os.path.exists(path):
with open(path, 'r') as fp:
data = ClusterManagerUtil.tail(fp, window=100).split("\n")
logs = data
try:
with open(path, 'r') as fp:
data = ClusterManagerUtil.tail(fp, window=100).split("\n")
logs = data
except Exception as e:
logging.info(f"Exception reading log file: {path}. Stacktrace: {str(e)}, {repr(e)}")
return csle_cluster.cluster_manager.cluster_manager_pb2.LogsDTO(logs=logs)

def getPrometheusLogs(self, request: csle_cluster.cluster_manager.cluster_manager_pb2.GetPrometheusLogsMsg,
Expand All @@ -576,9 +591,12 @@ def getPrometheusLogs(self, request: csle_cluster.cluster_manager.cluster_manage
path = config.prometheus_log_file
logs = []
if os.path.exists(path):
with open(path, 'r') as fp:
data = ClusterManagerUtil.tail(fp, window=100).split("\n")
logs = data
try:
with open(path, 'r') as fp:
data = ClusterManagerUtil.tail(fp, window=100).split("\n")
logs = data
except Exception as e:
logging.info(f"Exception reading log file: {path}. Stacktrace: {str(e)}, {repr(e)}")
return csle_cluster.cluster_manager.cluster_manager_pb2.LogsDTO(logs=logs)

def getDockerStatsManagerLogs(
Expand All @@ -596,9 +614,12 @@ def getDockerStatsManagerLogs(
path = config.docker_stats_manager_log_dir + config.docker_stats_manager_log_file
logs = []
if os.path.exists(path):
with open(path, 'r') as fp:
data = ClusterManagerUtil.tail(fp, window=100).split("\n")
logs = data
try:
with open(path, 'r') as fp:
data = ClusterManagerUtil.tail(fp, window=100).split("\n")
logs = data
except Exception as e:
logging.info(f"Exception reading log file: {path}. Stacktrace: {str(e)}, {repr(e)}")
return csle_cluster.cluster_manager.cluster_manager_pb2.LogsDTO(logs=logs)

def getCsleLogFiles(self, request: csle_cluster.cluster_manager.cluster_manager_pb2.GetCsleLogFilesMsg,
Expand Down Expand Up @@ -4429,9 +4450,12 @@ def getClusterManagerLogs(self, request: csle_cluster.cluster_manager.cluster_ma
path = config.cluster_manager_log_file
logs = []
if os.path.exists(path):
with open(path, 'r') as fp:
data = ClusterManagerUtil.tail(fp, window=100).split("\n")
logs = data
try:
with open(path, 'r') as fp:
data = ClusterManagerUtil.tail(fp, window=100).split("\n")
logs = data
except Exception as e:
logging.info(f"Exception reading log file: {path}. Stacktrace: {str(e)}, {repr(e)}")
return csle_cluster.cluster_manager.cluster_manager_pb2.LogsDTO(logs=logs)

def getExecutionTimeSeriesData(
Expand Down

0 comments on commit 02b469c

Please sign in to comment.