Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugin_config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id: 18f4ff11-b758-4bf2-9a37-719a22f5a4b8
name: sc:couchbase
externalVersion: "1.3.0"
buildNumber: 1.3.0
externalVersion: "1.3.1"
buildNumber: 1.3.1
language: PYTHON38
hostTypes:
- UNIX
Expand Down
65 changes: 58 additions & 7 deletions src/controller/couchbase_operation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2020-2023 by Delphix. All rights reserved.
# Copyright (c) 2020-2024 by Delphix. All rights reserved.
#

##############################################################################
Expand Down Expand Up @@ -195,6 +195,9 @@ def run_os_command(self, os_command, **kwargs):
stdout, stderr, exit_code = utilities.execute_bash(
self.connection, command
)
logger.debug(f"os_command stdout: {stdout}")
logger.debug(f"os_command stderr: {stderr}")
logger.debug(f"os_command exit_code: {exit_code}")
return [stdout, stderr, exit_code]

def restart_couchbase(self, provision=False):
Expand Down Expand Up @@ -430,6 +433,53 @@ def make_directory(self, directory_path, force_env_user=False):

logger.debug("Changed the permission of directory")

def check_stale_mountpoint(self, path):

output, stderr, exit_code = self.run_os_command(
os_command="df", path=path
)
if exit_code != 0:
if "No such file or directory" in stderr:
# this is actually OK
return False
else:
logger.error(
"df retured error - stale mount point or other error"
)
logger.error(
"stdout: {} stderr: {} exit_code: {}".format(
output, stderr, exit_code
)
)
return True
else:
return False

def get_db_size(self, path: str) -> str:
"""
Get the size of the dataset.

:param connection: Staging connection.
:param path: Mount location corresponding to dataset

:return: du command output.

"""
logger.debug("Started db sizing")
du_std, du_stderr, du_exit_code = self.run_os_command(
os_command="du", mount_path=path
)
if du_exit_code != 0:
logger.error("Unable to calculate the dataset size")
logger.error(f"stderr: {du_stderr}")
raise UserError(
"Problem with measuring mounted file system",
"Ask OS admin to check mount",
du_stderr,
)
logger.debug(f"Completed db sizing {du_std}")
return du_std

def create_config_dir(self):
"""create and return the hidden folder directory with name 'delphix'"""

Expand Down Expand Up @@ -494,8 +544,9 @@ def source_bucket_list(self):

def get_backup_date(self, x):
w = x.replace(
"{}/{}".format(
"{}/{}/{}".format(
self.parameters.couchbase_bak_loc,
self.parameters.archive_name,
self.parameters.couchbase_bak_repo,
),
"",
Expand Down Expand Up @@ -1018,11 +1069,11 @@ def delete_config_folder(self):
srcname=config_directory_path,
trgname=target_folder,
)
logger.debug(
f"mv directory >> command_output=={command_output}"
f" , command_stderr=={command_stderr} , "
f"command_exit_code=={command_exit_code}"
)
# logger.debug(
# f"mv directory >> command_output=={command_output}"
# f" , command_stderr=={command_stderr} , "
# f"command_exit_code=={command_exit_code}"
# )

def delete_xdcr_config(self):
if self.parameters.d_source_type == "XDCR":
Expand Down
29 changes: 1 addition & 28 deletions src/controller/helper_lib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2020-2023 by Delphix. All rights reserved.
# Copyright (c) 2020-2024 by Delphix. All rights reserved.
#

##############################################################################
Expand Down Expand Up @@ -34,7 +34,6 @@
from internal_exceptions.plugin_exceptions import SourceConfigDiscoveryError
from internal_exceptions.plugin_exceptions import UnmountFileSystemError
from utils import utilities
from dlpx.virtualization.common import RemoteConnection

# Global logger object for this file
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -522,29 +521,3 @@ def clean_stale_mountpoint(connection, path):
"Ask OS admin to check mount points",
umount_stderr,
)


def get_db_size(connection: RemoteConnection, path: str) -> str:
"""
Get the size of the dataset.

:param connection: Staging connection.
:param path: Mount location corresponding to dataset

:return: du command output.

"""
logger.debug("Started db sizing")
du_std, du_stderr, du_exit_code = utilities.execute_bash(
connection, CommandFactory.du(mount_path=path)
)
if du_exit_code != 0:
logger.error("Unable to calculate the dataset size")
logger.error(f"stderr: {du_stderr}")
raise UserError(
"Problem with measuring mounted file system",
"Ask OS admin to check mount",
du_stderr,
)
logger.debug(f"Completed db sizing {du_std}")
return du_std
30 changes: 22 additions & 8 deletions src/db_commands/commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2020-2023 by Delphix. All rights reserved.
# Copyright (c) 2020-2024 by Delphix. All rights reserved.
#

##############################################################################
Expand Down Expand Up @@ -90,8 +90,13 @@ def check_file(file_path, sudo=False, uid=None, **kwargs):
)

@staticmethod
def write_file(filename, data, **kwargs):
return "echo {data} > {filename}".format(filename=filename, data=data)
def write_file(filename, data, sudo=False, uid=None, **kwargs):
if sudo:
return f"sudo -u \#{uid} echo {data} > {filename}"
else:
return "echo {data} > {filename}".format(
filename=filename, data=data
)

@staticmethod
def get_ip_of_hostname(**kwargs):
Expand Down Expand Up @@ -196,11 +201,14 @@ def cat(path, sudo=False, uid=None, **kwargs):
return "cat {path}".format(path=path)

@staticmethod
def df(mount_path, **kwargs):
return "df -h {mount_path}".format(mount_path=mount_path)
def df(path, sudo=False, uid=None, **kwargs):
if sudo:
return f"sudo -u \#{uid} df -h {path}"
else:
return f"df -h {path}"

@staticmethod
def mount(**kwargs):
def mount(sudo=False, uid=None, **kwargs):
return "mount"

@staticmethod
Expand All @@ -211,15 +219,21 @@ def resolve_name(hostname, **kwargs):
)

@staticmethod
def du(mount_path: str, **kwargs) -> str:
def du(mount_path: str, sudo=False, uid=None, **kwargs) -> str:
"""
Returns command string to get size of dataset.

:param mount_path: The path whose size is to be calculated

:return: The du command string
"""
return f"du -s --block-size=1 --apparent-size {mount_path}"
if sudo:
return (
f"sudo -u \#{uid} du -s --block-size=1 --apparent-size "
f"{mount_path}"
)
else:
return f"du -s --block-size=1 --apparent-size {mount_path}"


class DatabaseCommand(object):
Expand Down
16 changes: 8 additions & 8 deletions src/operations/linked.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2020-2023 by Delphix. All rights reserved.
# Copyright (c) 2020-2024 by Delphix. All rights reserved.
#
#############################################################################
# In this module, all dSource related operations are implemented
Expand Down Expand Up @@ -229,7 +229,7 @@ def _cleanup_in_exception_case(rx_connection, is_sync, is_snap_sync):
raise


def source_size(source_obj: StagedSource):
def source_size(source_obj: StagedSource, repository, source_config):
"""
Returns space occupied by the dataset on the mount point in bytes.

Expand All @@ -244,13 +244,18 @@ def source_size(source_obj: StagedSource):
"Begin operation: Calculation of source"
f" sizing for dSource {cluster_name}."
)
srcsize_obj = CouchbaseOperation(
Resource.ObjectBuilder.set_staged_source(source_obj)
.set_repository(repository)
.build()
)
try:
if not helper_lib.check_stale_mountpoint(
connection=connection, path=mount_path
) and helper_lib.check_server_is_used(
connection=connection, path=mount_path
):
db_size_output = helper_lib.get_db_size(connection, mount_path)
db_size_output = srcsize_obj.get_db_size(path=mount_path)
if db_size_output:
db_size = int(db_size_output.split()[0])
logger.debug(
Expand All @@ -267,8 +272,3 @@ def source_size(source_obj: StagedSource):
except Exception as error:
logger.debug("Exception: {}".format(str(error)))
raise
finally:
logger.info(
"End operation: Calculation of source"
f" sizing for dSource {cluster_name} couldn't be completed."
)
4 changes: 2 additions & 2 deletions src/plugin_runner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2020-2023 by Delphix. All rights reserved.
# Copyright (c) 2020-2024 by Delphix. All rights reserved.
#
#

Expand Down Expand Up @@ -298,4 +298,4 @@ def add_node_to_virtual1(old_virtual_source):

@plugin.linked.source_size()
def linked_source_size(staged_source, repository, source_config):
return linked.source_size(staged_source)
return linked.source_size(staged_source, repository, source_config)