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
28 changes: 27 additions & 1 deletion src/controller/helper_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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 @@ -503,7 +504,6 @@ def check_server_is_used(connection, path):


def clean_stale_mountpoint(connection, path):

umount_std, umount_stderr, umount_exit_code = utilities.execute_bash(
connection,
CommandFactory.unmount_file_system(mount_path=path, options="-lf"),
Expand All @@ -516,3 +516,29 @@ 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
11 changes: 11 additions & 0 deletions src/db_commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,17 @@ def resolve_name(hostname, **kwargs):
"cut -d ' ' -f 1".format(hostname=hostname)
)

@staticmethod
def du(mount_path: str, **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}"


class DatabaseCommand(object):
def __init__(self):
Expand Down
10 changes: 10 additions & 0 deletions src/internal_exceptions/plugin_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ def __init__(self, message=""):
)


class MountPathStaleError(PluginException):
def __init__(self, message=""):
message = "Failed to get the stale mount path information " + message
super(MountPathStaleError, self).__init__(
message,
"Please clean the stale mount point.",
"Please check the logs for more details",
)


ERR_RESPONSE_DATA = {
"ERR_INSUFFICIENT_RAMQUOTA": {
"MESSAGE": "Provided bucket size is not suffice to proceed",
Expand Down
47 changes: 47 additions & 0 deletions src/operations/linked.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from internal_exceptions.base_exceptions import GenericUserError
from internal_exceptions.base_exceptions import PluginException
from internal_exceptions.plugin_exceptions import MultipleSnapSyncError
from internal_exceptions.plugin_exceptions import MountPathStaleError
from dlpx.virtualization.platform import StagedSource
from operations import config
from operations import link_cbbkpmgr
from operations import link_xdcr
Expand Down Expand Up @@ -227,3 +229,48 @@ def _cleanup_in_exception_case(rx_connection, is_sync, is_snap_sync):
except Exception as err:
logger.debug("Failed to clean up the lock files {}".format(str(err)))
raise


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

:param source_obj: staged_source object corresponding to dsource

:return: Storage occupied in the mount point in bytes
"""
connection = source_obj.staged_connection
mount_path = source_obj.parameters.mount_path
cluster_name = source_obj.parameters.stg_cluster_name
logger.info(
"Begin operation: Calculation of source"
f" sizing for dSource {cluster_name}."
)
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)
if db_size_output:
db_size = int(db_size_output.split()[0])
logger.debug(
f"mount_point={mount_path} , "
f"db_size_calculated={db_size}"
)
logger.info(
"End operation: Calculation of source"
f" sizing for dSource {cluster_name}."
)
return db_size
else:
raise MountPathStaleError(message=mount_path)
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."
)
5 changes: 5 additions & 0 deletions src/plugin_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,8 @@ def add_node_to_virtual1(old_virtual_source):
logger.debug("After changes")
logger.debug(new_virt)
return new_virt


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