summaryrefslogtreecommitdiffstats
path: root/geo-replication/syncdaemon/gsyncdstatus.py
diff options
context:
space:
mode:
Diffstat (limited to 'geo-replication/syncdaemon/gsyncdstatus.py')
-rw-r--r--geo-replication/syncdaemon/gsyncdstatus.py53
1 files changed, 36 insertions, 17 deletions
diff --git a/geo-replication/syncdaemon/gsyncdstatus.py b/geo-replication/syncdaemon/gsyncdstatus.py
index dd363baf181..1a655ff8887 100644
--- a/geo-replication/syncdaemon/gsyncdstatus.py
+++ b/geo-replication/syncdaemon/gsyncdstatus.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
#
# Copyright (c) 2011-2014 Red Hat, Inc. <http://www.redhat.com>
# This file is part of GlusterFS.
@@ -9,18 +9,22 @@
# cases as published by the Free Software Foundation.
#
+from __future__ import print_function
import fcntl
import os
import tempfile
-import urllib
+try:
+ import urllib.parse as urllib
+except ImportError:
+ import urllib
import json
import time
from datetime import datetime
from errno import EACCES, EAGAIN, ENOENT
import logging
-from syncdutils import EVENT_GEOREP_ACTIVE, EVENT_GEOREP_PASSIVE, gf_event
-from syncdutils import EVENT_GEOREP_CHECKPOINT_COMPLETED
+from syncdutils import (EVENT_GEOREP_ACTIVE, EVENT_GEOREP_PASSIVE, gf_event,
+ EVENT_GEOREP_CHECKPOINT_COMPLETED, lf)
DEFAULT_STATUS = "N/A"
MONITOR_STATUS = ("Created", "Started", "Paused", "Stopped")
@@ -99,6 +103,7 @@ class LockedOpen(object):
return f
def __exit__(self, _exc_type, _exc_value, _traceback):
+ fcntl.flock(self.fileobj, fcntl.LOCK_UN)
self.fileobj.close()
@@ -152,11 +157,12 @@ class GeorepStatus(object):
**kwargs)
def _update(self, mergerfunc):
+ data = self.default_values
with LockedOpen(self.filename, 'r+') as f:
try:
- data = json.load(f)
+ data.update(json.load(f))
except ValueError:
- data = self.default_values
+ pass
data = mergerfunc(data)
# If Data is not changed by merger func
@@ -225,10 +231,10 @@ class GeorepStatus(object):
data["checkpoint_time"] = checkpoint_time
data["checkpoint_completion_time"] = curr_time
data["checkpoint_completed"] = "Yes"
- logging.info("Checkpoint completed. Checkpoint "
- "Time: %s, Completion Time: %s" % (
- human_time_utc(checkpoint_time),
- human_time_utc(curr_time)))
+ logging.info(lf("Checkpoint completed",
+ checkpoint_time=human_time_utc(
+ checkpoint_time),
+ completion_time=human_time_utc(curr_time)))
self.trigger_gf_event_checkpoint_completion(
checkpoint_time, curr_time)
@@ -238,11 +244,13 @@ class GeorepStatus(object):
def set_worker_status(self, status):
if self.set_field("worker_status", status):
- logging.info("Worker Status: %s" % status)
+ logging.info(lf("Worker Status Change",
+ status=status))
def set_worker_crawl_status(self, status):
if self.set_field("crawl_status", status):
- logging.info("Crawl Status: %s" % status)
+ logging.info(lf("Crawl Status Change",
+ status=status))
def set_slave_node(self, slave_node):
def merger(data):
@@ -269,12 +277,14 @@ class GeorepStatus(object):
def set_active(self):
if self.set_field("worker_status", "Active"):
- logging.info("Worker Status: Active")
+ logging.info(lf("Worker Status Change",
+ status="Active"))
self.send_event(EVENT_GEOREP_ACTIVE)
def set_passive(self):
if self.set_field("worker_status", "Passive"):
- logging.info("Worker Status: Passive")
+ logging.info(lf("Worker Status Change",
+ status="Passive"))
self.send_event(EVENT_GEOREP_PASSIVE)
def get_monitor_status(self):
@@ -395,6 +405,15 @@ class GeorepStatus(object):
return data
- def print_status(self, checkpoint_time=0):
- for key, value in self.get_status(checkpoint_time).items():
- print ("%s: %s" % (key, value))
+ def print_status(self, checkpoint_time=0, json_output=False):
+ status_out = self.get_status(checkpoint_time)
+ if json_output:
+ out = {}
+ # Convert all values as string
+ for k, v in status_out.items():
+ out[k] = str(v)
+ print(json.dumps(out))
+ return
+
+ for key, value in status_out.items():
+ print(("%s: %s" % (key, value)))