Yedidyah Bar David has uploaded a new change for review.

Change subject: packaging: setup: Stop remote dwh
......................................................................

packaging: setup: Stop remote dwh

Change-Id: Ib7e345bf71c2a5ecdddc777487d67fcae9d4b84a
Bug-Url: https://bugzilla.redhat.com/1024028
Signed-off-by: Yedidyah Bar David <d...@redhat.com>
---
A packaging/setup/ovirt_engine_setup/engine_common/dwh_history_timekeeping.py
M packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/upgrade/__init__.py
A packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/upgrade/dwh.py
3 files changed, 220 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/66/34566/1

diff --git 
a/packaging/setup/ovirt_engine_setup/engine_common/dwh_history_timekeeping.py 
b/packaging/setup/ovirt_engine_setup/engine_common/dwh_history_timekeeping.py
new file mode 100644
index 0000000..c247645
--- /dev/null
+++ 
b/packaging/setup/ovirt_engine_setup/engine_common/dwh_history_timekeeping.py
@@ -0,0 +1,74 @@
+#
+# ovirt-engine-setup -- ovirt engine setup
+# Copyright (C) 2014 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+import gettext
+_ = lambda m: gettext.dgettext(message=m, domain='ovirt-engine-setup')
+
+
+from otopi import util
+
+
+DB_KEY_RUNNING = 'DwhCurrentlyRunning'
+DB_KEY_HOSTNAME = 'dwhHostname'
+DB_KEY_UUID = 'dwhUuid'
+
+
+@util.export
+def getValueFromTimekeeping(statement, name, raise_if_empty=False):
+    result = statement.execute(
+        statement="""
+            select * from GetDwhHistoryTimekeepingByVarName(
+                %(name)s
+            )
+        """,
+        args=dict(
+            name=name,
+        ),
+        ownConnection=True,
+    )
+    if not result and raise_if_empty:
+        raise RuntimeError(
+            _(
+                'Missing row {name} in the table dwh_history_timekeeping '
+                'in the engine database'
+            ).format(
+                name=name,
+            )
+        )
+    return result[0]['var_value'] if result else None
+
+
+def updateValueInTimekeeping(statement, name, value):
+    getValueFromTimekeeping(statement, name, raise_if_empty=True)
+    statement.execute(
+        statement="""
+            select UpdateDwhHistoryTimekeeping(
+                %(name)s,
+                %(value)s,
+                NULL
+            )
+        """,
+        args=dict(
+            name=name,
+            value=value,
+        ),
+        ownConnection=False,
+    )
+
+
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git 
a/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/upgrade/__init__.py 
b/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/upgrade/__init__.py
index ee20db6..b705449 100644
--- 
a/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/upgrade/__init__.py
+++ 
b/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/upgrade/__init__.py
@@ -1,6 +1,6 @@
 #
 # ovirt-engine-setup -- ovirt engine setup
-# Copyright (C) 2013 Red Hat, Inc.
+# Copyright (C) 2014 Red Hat, Inc.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
 from . import dbvalidations
 from . import asynctasks
 from . import answerfile_fixup
+from . import dwh
 
 
 @util.export
@@ -32,6 +33,7 @@
     dbvalidations.Plugin(context=context)
     asynctasks.Plugin(context=context)
     answerfile_fixup.Plugin(context=context)
+    dwh.Plugin(context=context)
 
 
 # vim: expandtab tabstop=4 shiftwidth=4
diff --git 
a/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/upgrade/dwh.py 
b/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/upgrade/dwh.py
new file mode 100644
index 0000000..75499be
--- /dev/null
+++ b/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/upgrade/dwh.py
@@ -0,0 +1,143 @@
+#
+# ovirt-engine-setup -- ovirt engine setup
+# Copyright (C) 2013 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+"""dwh plugin."""
+
+
+import time
+import gettext
+_ = lambda m: gettext.dgettext(message=m, domain='ovirt-engine-setup')
+
+
+from otopi import constants as otopicons
+from otopi import util
+from otopi import plugin
+
+
+from ovirt_engine_setup import constants as osetupcons
+from ovirt_engine_setup.engine import constants as oenginecons
+from ovirt_engine_setup.engine_common import constants as oengcommcons
+from ovirt_engine_setup.engine_common import dwh_history_timekeeping
+from ovirt_engine_setup.engine_common import database
+from ovirt_engine_setup import dialog
+from ovirt_engine_setup.engine import vdcoption
+
+
+@util.export
+class Plugin(plugin.PluginBase):
+    """dwh plugin."""
+
+    RETRIES = 30
+    DELAY = 2
+
+    def __init__(self, context):
+        super(Plugin, self).__init__(context=context)
+
+    def _remote_dwh_is_up(self):
+        return dwh_history_timekeeping.getValueFromTimekeeping(
+            statement=self._statement,
+            name=dwh_history_timekeeping.DB_KEY_RUNNING
+        ) == '1'
+
+    def _update_DisconnectDwh(self, value):
+        vdcoption.VdcOption(
+            statement=self._statement,
+        ).updateVdcOptions(
+            options=(
+                {
+                    'name': 'DisconnectDwh',
+                    'value': value,
+                },
+            ),
+            ownConnection=True,
+        )
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_INIT,
+    )
+    def _init(self):
+        self._remote_dwh_stopped = False
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_MISC,
+        before=(
+            oengcommcons.Stages.DB_SCHEMA,
+        ),
+        condition=lambda self: (
+            self.environment[oenginecons.CoreEnv.ENABLE] and
+            not self.environment[oenginecons.EngineDBEnv.NEW_DATABASE]
+        ),
+    )
+    def _misc_stop_remote_dwh(self):
+        self._statement = database.Statement(
+            dbenvkeys=oenginecons.Const.ENGINE_DB_ENV_KEYS,
+            environment=self.environment,
+        )
+        self._dwh_host = dwh_history_timekeeping.getValueFromTimekeeping(
+            statement=self._statement,
+            name=dwh_history_timekeeping.DB_KEY_HOSTNAME
+        )
+        if self._remote_dwh_is_up():
+            self.logger.info(
+                _(
+                    'Stopping DWH service on host {hostname}...'
+                ).format(
+                    hostname=self._dwh_host,
+                )
+            )
+            self._update_DisconnectDwh('1')
+            retries = self.RETRIES
+            while self._remote_dwh_is_up() and retries > 0:
+                retries -= 1
+                time.sleep(self.DELAY)
+            if self._remote_dwh_is_up():
+                self.logger.error(
+                    _(
+                        'dwhd is currently running.\n'
+                        'Its hostname is {hostname}.\n'
+                        'Please stop it before running Setup.'
+                    ).format(
+                        hostname=self._dwh_host,
+                    )
+                )
+                raise RuntimeError(_('dwhd is currently running'))
+            self._update_DisconnectDwh('0')
+            self.logger.info(_('Stopped DWH'))
+            self._remote_dwh_stopped = True
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_CLOSEUP,
+        before=(
+            osetupcons.Stages.DIALOG_TITLES_E_SUMMARY,
+        ),
+        after=(
+            osetupcons.Stages.DIALOG_TITLES_S_SUMMARY,
+        ),
+        condition=lambda self: self._remote_dwh_stopped,
+    )
+    def _closeup(self):
+        self.dialog.note(
+            text=_(
+                "Please start the DWH service on the host '{hostname}'."
+            ).format(
+                hostname=self._dwh_host,
+            ),
+        )
+
+
+# vim: expandtab tabstop=4 shiftwidth=4


-- 
To view, visit http://gerrit.ovirt.org/34566
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib7e345bf71c2a5ecdddc777487d67fcae9d4b84a
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Yedidyah Bar David <d...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to