Sandro Bonazzola has uploaded a new change for review. Change subject: WIP: packaging: setup: re-write using otopi ......................................................................
WIP: packaging: setup: re-write using otopi OUTLINE We introduce a complete rewrite of ovirt-engine-dwh-setup as a plugin for ovirt-engine-stup. The new implementation is installed side-by-side, user may have a choice which implementation to use. MAJOR FEATURES Implementation Pluggable, mission centric, consistent, modern, customizable implementation. Reuse the otopi infrastructure that is also used for host-deploy, and reuse ovirt-engine-setup common components. Localization ready. Requires: http://gerrit.ovirt.org/20293 Bug-Url: https://bugzilla.redhat.com/967350 Change-Id: I0f07eb3f93d884f806603e5e9c7f2c577c17dc98 Signed-off-by: Sandro Bonazzola <sbona...@redhat.com> --- M .gitignore M Makefile A build/python-check.sh.in A ovirt-engine-dwh.spec.in D packaging/ovirt-engine-dwh.spec.in D packaging/ovirt-engine-dwh.spec.tmpl A packaging/setup/ovirt_engine_setup/dwh_config.py.in A packaging/setup/ovirt_engine_setup/dwh_constants.py A packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/config/__init__.py A packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/config/db_connectivity.py A packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/core/__init__.py A packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/core/compatibility.py A packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/core/config.py A packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/db/__init__.py A packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/db/connection.py A packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/db/engine_db.py 16 files changed, 1,294 insertions(+), 192 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-dwh refs/changes/80/21380/1 diff --git a/.gitignore b/.gitignore index 88f2d96..0d99d18 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ +build/python-check.sh +ovirt-engine-dwh.spec +packaging/setup/ovirt_engine_setup/dwh_config.py target tmp.* diff --git a/Makefile b/Makefile index b08e21b..f686ff9 100644 --- a/Makefile +++ b/Makefile @@ -21,20 +21,20 @@ # information on the Apache Software Foundation, please see # <http://www.apache.org/>. -include version.mak -# major, minor, seq -POM_VERSION:=$(shell cat pom.xml | grep '<ovirt-dwh.version>' | sed -e 's/.*>\(.*\)<.*/\1/' -e 's/-SNAPSHOT//') -# major, minor from pom and fix -APP_VERSION=$(shell echo $(POM_VERSION) | sed 's/\([^.]*\.[^.]\)\..*/\1/').$(FIX_RELEASE) -RPM_VERSION=$(APP_VERSION) -PACKAGE_VERSION=$(APP_VERSION)$(if $(MILESTONE),_$(MILESTONE)) -PACKAGE_NAME=ovirt-engine-dwh -DISPLAY_VERSION=$(PACKAGE_VERSION) - -MVN=mvn -EXTRA_BUILD_FLAGS= +# +# CUSTOMIZATION-BEGIN +# BUILD_FLAGS= +EXTRA_BUILD_FLAGS= +BUILD_PYTHON_VALIDATION=1 + +PACKAGE_NAME=ovirt-engine-dwh OVIRT_DWH_NAME=$(PACKAGE_NAME) +MVN=mvn +RPMBUILD=rpmbuild +PYTHON=python +PYFLAKES=pyflakes +PEP8=pep8 PREFIX=/usr/local BIN_DIR=$(PREFIX)/bin SYSCONF_DIR=$(PREFIX)/etc @@ -43,30 +43,75 @@ MAVENPOM_DIR=$(DATAROOT_DIR)/maven-poms JAVA_DIR=$(DATAROOT_DIR)/java PKG_JAVA_DIR=$(JAVA_DIR)/$(OVIRT_DWH_NAME) -RPMBUILD=rpmbuild -PYTHON=python -PYTHON_DIR:=$(shell $(PYTHON) -c "from distutils.sysconfig import get_python_lib as f;print(f())") +PYTHON_DIR=$(PYTHON_SYS_DIR) +# +# CUSTOMIZATION-END +# -SPEC_FILE_IN=packaging/ovirt-engine-dwh.spec.in -SPEC_FILE=$(PACKAGE_NAME).spec +include version.mak +# major, minor, seq +POM_VERSION:=$(shell cat pom.xml | grep '<ovirt-dwh.version>' | sed -e 's/.*>\(.*\)<.*/\1/' -e 's/-SNAPSHOT//') +# major, minor from pom and fix +APP_VERSION=$(shell echo $(POM_VERSION) | sed 's/\([^.]*\.[^.]\)\..*/\1/').$(FIX_RELEASE) +RPM_VERSION=$(APP_VERSION) +PACKAGE_VERSION=$(APP_VERSION)$(if $(MILESTONE),_$(MILESTONE)) +DISPLAY_VERSION=$(PACKAGE_VERSION) + +PYTHON_SYS_DIR:=$(shell $(PYTHON) -c "from distutils.sysconfig import get_python_lib as f;print(f())") OUTPUT_RPMBUILD=$(shell pwd -P)/tmp.rpmbuild OUTPUT_DIR=output TARBALL=$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz -SRPM=$(OUTPUT_DIR)/$(PACKAGE_NAME)-$(RPM_VERSION)*.src.rpm ARCH=noarch BUILD_FILE=tmp.built MAVEN_OUTPUT_DIR_DEFAULT=$(shell pwd -P)/tmp.repos MAVEN_OUTPUT_DIR=$(MAVEN_OUTPUT_DIR_DEFAULT) - +SOURCEDIR= +TARGETDIR= +EXCLUDE_GEN= ARTIFACTS = \ historyETLProcedure \ talendRoutines \ advancedPersistentLookupLib \ $(NULL) -all: $(BUILD_FILE) +# Don't use any of the bultin rules, in particular don't use the rule +# for .sh files, as that means that we can't generate .sh files from +# templates: +.SUFFIXES: +.SUFFIXES: .in -$(BUILD_FILE): +# Rule to generate files from templates: +.in: + sed \ + -e 's|@DATA_DIR@|$(DATA_DIR)|g' \ + -e 's|@DISPLAY_VERSION@|$(DISPLAY_VERSION)|g' \ + -e 's|@OVIRT_DWH_NAME@|$(OVIRT_DWH_NAME)|g' \ + -e 's|@PACKAGE_NAME@|$(PACKAGE_NAME)|g' \ + -e 's|@PACKAGE_VERSION@|$(PACKAGE_VERSION)|g' \ + -e 's|@PEP8@|$(PEP8)|g' \ + -e 's|@PYFLAKES@|$(PYFLAKES)|g' \ + -e 's|@RPM_VERSION@|$(RPM_VERSION)|g' \ + -e 's|@RPM_RELEASE@|$(RPM_RELEASE)|g' \ + -e 's|@SYSCONF_DIR@|$(SYSCONF_DIR)|g' \ + $< > $@ + +# List of files that will be generated from templates: +GENERATED = \ + build/python-check.sh \ + ovirt-engine-dwh.spec \ + packaging/setup/ovirt_engine_setup/dwh_config.py \ + $(NULL) + +all: \ + generated-files \ + $(BUILD_FILE) \ + $(NULL) + +generated-files: $(GENERATED) + chmod a+x build/python-check.sh + +# support force run of maven +maven: export MAVEN_OPTS="${MAVEN_OPTS} -XX:MaxPermSize=512m" $(MVN) \ $(BUILD_FLAGS) \ @@ -78,12 +123,19 @@ -D skipTests \ -D altDeploymentRepository=install::default::file://$(MAVEN_OUTPUT_DIR) \ deploy - touch $(BUILD_FILE) + touch "$(BUILD_FILE)" + +$(BUILD_FILE): + $(MAKE) maven clean: + # Clean maven generated stuff: $(MVN) clean $(EXTRA_BUILD_FLAGS) - rm -rf $(OUTPUT_RPMBUILD) $(SPEC_FILE) $(OUTPUT_DIR) $(BUILD_FILE) + rm -rf $(OUTPUT_RPMBUILD) ovirt-engine-dwh.spec $(OUTPUT_DIR) $(BUILD_FILE) [ "$(MAVEN_OUTPUT_DIR_DEFAULT)" = "$(MAVEN_OUTPUT_DIR)" ] && rm -fr "$(MAVEN_OUTPUT_DIR)" + + # Clean files generated from templates: + rm -rf $(GENERATED) test: $(MVN) install $(BUILD_FLAGS) $(EXTRA_BUILD_FLAGS) @@ -92,44 +144,77 @@ all \ install_artifacts \ install_files \ + install-packaging-files \ $(NULL) -# legacy -tarball: dist -dist: - sed \ - -e 's/@PACKAGE_NAME@/$(PACKAGE_NAME)/g' \ - -e 's/@PACKAGE_VERSION@/$(PACKAGE_VERSION)/g' \ - -e 's/@RPM_VERSION@/$(RPM_VERSION)/g' \ - -e 's/@RPM_RELEASE@/$(RPM_RELEASE)/g' \ - $(SPEC_FILE_IN) > $(SPEC_FILE) - git ls-files | tar --files-from /proc/self/fd/0 -czf $(TARBALL) $(SPEC_FILE) - rm -f $(SPEC_FILE) +.PHONY: ovirt-engine-dwh.spec.in +ovirt-engine.spec: version.mak + +dist: ovirt-engine-dwh.spec + git ls-files | tar --files-from /proc/self/fd/0 -czf "$(TARBALL)" ovirt-engine-dwh.spec @echo @echo You can use $(RPMBUILD) -tb $(TARBALL) to produce rpms @echo +# legacy +tarball: dist + srpm: dist - rm -rf $(OUTPUT_RPMBUILD) - mkdir -p $(OUTPUT_RPMBUILD)/{SPECS,RPMS,SRPMS,SOURCES,BUILD,BUILDROOT} - mkdir -p $(OUTPUT_DIR) - $(RPMBUILD) -ts --define="_topdir $(OUTPUT_RPMBUILD)" $(TARBALL) - mv $(OUTPUT_RPMBUILD)/SRPMS/*.rpm $(OUTPUT_DIR) - rm -rf $(OUTPUT_RPMBUILD) + rm -rf "$(OUTPUT_RPMBUILD)" + mkdir -p "$(OUTPUT_RPMBUILD)"/{SPECS,RPMS,SRPMS,SOURCES,BUILD,BUILDROOT} + mkdir -p "$(OUTPUT_DIR)" + $(RPMBUILD) -ts --define="_topdir $(OUTPUT_RPMBUILD)" "$(TARBALL)" + mv "$(OUTPUT_RPMBUILD)/SRPMS"/*.rpm "$(OUTPUT_DIR)" + rm -rf "$(OUTPUT_RPMBUILD)" @echo @echo srpm is ready at $(OUTPUT_DIR) @echo rpm: srpm - rm -rf $(OUTPUT_RPMBUILD) - mkdir -p $(OUTPUT_RPMBUILD)/{SPECS,RPMS,SRPMS,SOURCES,BUILD,BUILDROOT} - mkdir -p $(OUTPUT_DIR) - $(RPMBUILD) --define="_topdir $(OUTPUT_RPMBUILD)" $(RPMBUILD_EXTRA_ARGS) --rebuild $(SRPM) - mv $(OUTPUT_RPMBUILD)/RPMS/$(ARCH)/*.rpm $(OUTPUT_DIR) - rm -rf $(OUTPUT_RPMBUILD) + rm -rf "$(OUTPUT_RPMBUILD)" + mkdir -p "$(OUTPUT_RPMBUILD)"/{SPECS,RPMS,SRPMS,SOURCES,BUILD,BUILDROOT} + mkdir -p "$(OUTPUT_DIR)" + $(RPMBUILD) --define="_topdir $(OUTPUT_RPMBUILD)" $(RPMBUILD_EXTRA_ARGS) --rebuild "$(OUTPUT_DIR)/$(PACKAGE_NAME)-$(RPM_VERSION)"*.src.rpm + mv $(OUTPUT_RPMBUILD)/RPMS/$(ARCH)/*.rpm "$(OUTPUT_DIR)" + rm -rf "$(OUTPUT_RPMBUILD)" @echo @echo rpms are ready at $(OUTPUT_DIR) @echo + +# copy SOURCEDIR to TARGETDIR +# exclude EXCLUDEGEN a list of files to exclude with .in +# exclude EXCLUDE a list of files. +copy-recursive: + ( cd "$(SOURCEDIR)" && find . -type d -printf '%P\n' ) | while read d; do \ + install -d -m 755 "$(TARGETDIR)/$${d}"; \ + done + ( \ + cd "$(SOURCEDIR)" && find . -type f -printf '%P\n' | \ + while read f; do \ + exclude=false; \ + for x in $(EXCLUDE_GEN); do \ + if [ "$(SOURCEDIR)/$${f}" = "$${x}.in" ]; then \ + exclude=true; \ + break; \ + fi; \ + done; \ + for x in $(EXCLUDE); do \ + if [ "$(SOURCEDIR)/$${f}" = "$${x}" ]; then \ + exclude=true; \ + break; \ + fi; \ + done; \ + $${exclude} || echo "$${f}"; \ + done \ + ) | while read f; do \ + [ -x "$(SOURCEDIR)/$${f}" ] && MASK=0755 || MASK=0644; \ + install -m "$${MASK}" "$(SOURCEDIR)/$${f}" "$$(dirname "$(TARGETDIR)/$${f}")"; \ + done + +python-validation: + if [ "$(BUILD_PYTHON_VALIDATION)" != 0 ]; then \ + build/python-check.sh; \ + fi install_artifacts: install -dm 755 $(DESTDIR)$(PKG_JAVA_DIR) @@ -151,6 +236,7 @@ install -d $(DESTDIR)$(DATA_DIR) install -d $(DESTDIR)$(DATA_DIR)/etl install -d $(DESTDIR)$(DATA_DIR)/db-scripts + install -d $(DESTDIR)$(SYSCONF_DIR)/$(OVIRT_DWH_NAME)/engine-dwh.conf.d install -d $(DESTDIR)$(SYSCONF_DIR)/ovirt-engine/$(OVIRT_DWH_NAME) install -d $(DESTDIR)$(SYSCONF_DIR)/$(OVIRT_DWH_NAME)/engine-dwh.conf.d install -d $(DESTDIR)$(SYSCONF_DIR)/cron.hourly @@ -174,3 +260,9 @@ # TODO # this should go into /var/lib or /var/run echo > $(DESTDIR)$(DATA_DIR)/etl/kill + +install-packaging-files: \ + $(GENERATED) \ + $(NULL) + $(MAKE) copy-recursive SOURCEDIR=packaging/setup TARGETDIR="$(DESTDIR)$(DATAROOT_DIR)/ovirt-engine/setup" EXCLUDE_GEN="$(GENERATED)" + diff --git a/build/python-check.sh.in b/build/python-check.sh.in new file mode 100755 index 0000000..cf55697 --- /dev/null +++ b/build/python-check.sh.in @@ -0,0 +1,23 @@ +#!/bin/sh + +PEP8="@PEP8@" +PYFLAKES="@PYFLAKES@" +SRCDIR="$(dirname "$0")/.." + +cd "${SRCDIR}" + +ret=0 +FILES="$( + find build packaging -name '*.py' | while read f; do + [ -e "${f}.in" ] || echo "${f}" + done +)" + +for exe in "${PYFLAKES}" "${PEP8}"; do + if ! which "${exe}" > /dev/null 2>&1; then + echo "WARNING: tool '${exe}' is missing" >&2 + else + "${exe}" ${FILES} || ret=1 + fi +done +exit ${ret} diff --git a/ovirt-engine-dwh.spec.in b/ovirt-engine-dwh.spec.in new file mode 100644 index 0000000..359f24e --- /dev/null +++ b/ovirt-engine-dwh.spec.in @@ -0,0 +1,169 @@ +# Settings +%global product_name Data warehouse package for oVirt Virtualization Suite +%global product_description oVirt virtualization manager data warehouse +%global install_poms 1 + +%global dwh_name ovirt-engine-dwh +%global dwh_java %{_javadir}/%{dwh_name} +%global ovirt_product_group Virtualization/Management +%global engine_name ovirt-engine +%global engine_data %{_datadir}/%{engine_name} +%global engine_group ovirt +%global engine_user ovirt + +%global make_common_opts \\\ + -j1 \\\ + PACKAGE_NAME=%{name} \\\ + RPM_VERSION=%{version} \\\ + RPM_RELEASE=%{release} \\\ + OVIRT_DWH_NAME=%{dwh_name} \\\ + PREFIX=%{_prefix} \\\ + SYSCONF_DIR=%{_sysconfdir} \\\ + BIN_DIR=%{_bindir} \\\ + DATAROOT_DIR=%{_datadir} \\\ + PYTHON=%{__python} \\\ + PYTHON_DIR=%{python_sitelib} \\\ + JAVA_DIR=%{_javadir} \\\ + MAVENPOM_DIR=%{_mavenpomdir} \\\ + PKG_JAVA_DIR=%{dwh_java} \\\ + %{?BUILD_FLAGS:BUILD_FLAGS="%{BUILD_FLAGS}"} \\\ + %{?EXTRA_BUILD_FLAGS:EXTRA_BUILD_FLAGS="%{EXTRA_BUILD_FLAGS}"} + +Name: @PACKAGE_NAME@ +Version: @RPM_VERSION@ +Release: @RPM_RELEASE@%{?release_suffix}%{?dist} +Summary: %{product_name} +Group: %{ovirt_product_group} +License: GPLv2 +URL: http://www.ovirt.org +Source0: http://ovirt.org/releases/stable/src/@PACKAGE_NAME@-@package_vers...@.tar.gz + +BuildArch: noarch + +BuildRequires: apache-commons-collections +BuildRequires: jpackage-utils +BuildRequires: log4j +BuildRequires: make +BuildRequires: maven +BuildRequires: maven-antrun-plugin +BuildRequires: maven-compiler-plugin +BuildRequires: maven-dependency-plugin +BuildRequires: postgresql-jdbc + +Requires: apache-commons-collections >= 3.2 +Requires: dom4j >= 1.6.1 +Requires: java-1.7.0-openjdk +Requires: jpackage-utils +Requires: log4j +Requires: logrotate +#Requires: ovirt-engine +Requires: python +Requires: postgresql-contrib >= 8.4.7 +Requires: postgresql-jdbc +Requires: postgresql-server >= 8.4.7 + +# We can't require exactly the same version and release of the +# setup package because it needs to be updated independently as part +# of the update process implemented in the engine-upgrade script: +Requires: %{name}-ovirt-engine-setup-plugin-dwh >= %{version}-%{release} + +%description +The %{product_description} package provides +the ETL process and DB scripts to create a historic database API. +Enables SQL BI reports creation for management and monitoring. + +%package ovirt-engine-setup-plugin-dwh +Summary: Setup and upgrade specific plugins for DWH +Group: %{ovirt_product_group} +License: ASL 2.0 +Requires: ovirt-engine-setup +Requires: ovirt-engine-setup-plugin-ovirt-engine-common + +%description ovirt-engine-setup-plugin-dwh +Setup and upgrade specific plugins for DWH + +%prep +%setup -c -q + +%build +make %{make_common_opts} + +%install +rm -fr "%{buildroot}" + +make %{make_common_opts} install DESTDIR=%{buildroot} + +install -d %{buildroot}%{_initddir} +install -p -m 755 data-warehouse/history_etl/history_service/%{dwh_name}d %{buildroot}%{_initddir} + +# Needed for compatibility if package is different than the directory structure +%if "%{name}" != "%{dwh_name}" +ln -s "%{dwh_name}" "%{buildroot}%{dwh_java}/../%{name}" +%endif + +# Register poms +%if !%{install_poms} +rm -fr "%{buildroot}%{_mavenpomdir}" +%else +for pom in %{buildroot}%{_mavenpomdir}/*.pom +do + pomdir=`dirname "${pom}"` + pom=`basename "${pom}"` + jpppom="JPP.${pom}" + mv "${pomdir}/${pom}" "${pomdir}/${jpppom}" + artifact_id=`echo "${pom}" | sed -e 's/^%{name}-//' -e 's/\.pom//'` + if [ -f "%{buildroot}%{dwh_java}/${artifact_id}.jar" ] + then + %add_maven_depmap "${jpppom}" "%{name}/${artifact_id}.jar" + else + %add_maven_depmap "${jpppom}" + fi +done +%endif + +%post +/sbin/chkconfig --add %{dwh_name}d > /dev/null 2>&1 +/sbin/chkconfig %{dwh_name}d off > /dev/null 2>&1 +/sbin/service %{dwh_name}d stop > /dev/null 2>&1 +/usr/sbin/logrotate /etc/logrotate.conf > /dev/null || /bin/true + +%preun +if [ "$1" -eq 0 ]; then + /sbin/service %{dwh_name}d stop > /dev/null 2>&1 + /sbin/chkconfig --list %{dwh_name}d > /dev/null 2>&1 + if [ $? -eq 0 ] + then + /sbin/chkconfig --del %{dwh_name}d > /dev/null 2>&1 + fi +fi + +%files + +%{dwh_java} +%{_datadir}/%{dwh_name} +%if "%{name}" != "%{dwh_name}" +%{_javadir}/%{name} +%endif +%if %{install_poms} +%{_mavendepmapfragdir}/%{name} +%{_mavenpomdir}/JPP.%{name}-* +%endif + +%dir %attr(-, %{engine_user}, %{engine_group}) %{_sysconfdir}/%{dwh_name}/engine-dwh.conf.d +%config(noreplace) %{_sysconfdir}/%{dwh_name}/engine-dwh.conf.d/10-setup-database-dwh.conf + +%dir %{_sysconfdir}/ovirt-engine/%{dwh_name} +%{_initddir}/%{dwh_name}d +%config(noreplace) %{_sysconfdir}/logrotate.d/%{dwh_name}d +%{_bindir}/%{dwh_name}-setup +%{_sysconfdir}/cron.hourly/ovirt_engine_dwh_watchdog.cron +%config(noreplace) %attr(-, %{engine_user}, %{engine_group}) %{_sysconfdir}/ovirt-engine/%{dwh_name}/Default.properties + +%files ovirt-engine-setup-plugin-dwh + +%{engine_data}/setup/ovirt_engine_setup/ +%{engine_data}/setup/plugins/ovirt-engine-setup/ + +%changelog +* Thu Apr 19 2012 Yaniv Dary <yd...@redhat.com> - 3.0.0-1.fc16 +- Added packaging to dwh diff --git a/packaging/ovirt-engine-dwh.spec.in b/packaging/ovirt-engine-dwh.spec.in deleted file mode 100644 index 69977df..0000000 --- a/packaging/ovirt-engine-dwh.spec.in +++ /dev/null @@ -1,145 +0,0 @@ -# Settings -%global product_name Data warehouse package for oVirt Virtualization Suite -%global product_description oVirt virtualization manager data warehouse -%global install_poms 1 - -%global dwh_name ovirt-engine-dwh -%global dwh_java %{_javadir}/%{dwh_name} -%global engine_group ovirt -%global engine_user ovirt - -%global make_common_opts \\\ - -j1 \\\ - PACKAGE_NAME=%{name} \\\ - RPM_VERSION=%{version} \\\ - RPM_RELEASE=%{release} \\\ - OVIRT_DWH_NAME=%{dwh_name} \\\ - PREFIX=%{_prefix} \\\ - SYSCONF_DIR=%{_sysconfdir} \\\ - BIN_DIR=%{_bindir} \\\ - DATAROOT_DIR=%{_datadir} \\\ - PYTHON=%{__python} \\\ - PYTHON_DIR=%{python_sitelib} \\\ - JAVA_DIR=%{_javadir} \\\ - MAVENPOM_DIR=%{_mavenpomdir} \\\ - PKG_JAVA_DIR=%{dwh_java} \\\ - %{?BUILD_FLAGS:BUILD_FLAGS="%{BUILD_FLAGS}"} \\\ - %{?EXTRA_BUILD_FLAGS:EXTRA_BUILD_FLAGS="%{EXTRA_BUILD_FLAGS}"} - -Name: @PACKAGE_NAME@ -Version: @RPM_VERSION@ -Release: @RPM_RELEASE@%{?release_suffix}%{dist} -License: GPLv2 -Summary: %{product_name} -Group: Virtualization/Management -URL: http://www.ovirt.org -BuildArch: noarch -Source: @PACKAGE_NAME@-@package_vers...@.tar.gz - -BuildRequires: jpackage-utils -BuildRequires: make -BuildRequires: maven -BuildRequires: maven-dependency-plugin -BuildRequires: maven-antrun-plugin -BuildRequires: maven-compiler-plugin -BuildRequires: apache-commons-collections -BuildRequires: log4j -BuildRequires: postgresql-jdbc -Requires: python -Requires: java-1.7.0-openjdk -Requires: jpackage-utils -Requires: apache-commons-collections >= 3.2 -Requires: log4j -Requires: dom4j >= 1.6.1 -Requires: postgresql-jdbc -Requires: postgresql-server >= 8.4.7 -Requires: postgresql-contrib >= 8.4.7 -Requires: logrotate -Requires: ovirt-engine - -%description -The %{product_description} package provides -the ETL process and DB scripts to create a historic database API. -Enables SQL BI reports creation for management and monitoring. - -%prep -%setup -c -q - -%build - -make %{make_common_opts} - -%install -rm -fr "%{buildroot}" - -make %{make_common_opts} install DESTDIR=%{buildroot} - -install -d %{buildroot}%{_initddir} -install -p -m 755 data-warehouse/history_etl/history_service/%{dwh_name}d %{buildroot}%{_initddir} - -# Needed for compatibility if package is different than the directory structure -%if "%{name}" != "%{dwh_name}" -ln -s "%{dwh_name}" "%{buildroot}%{dwh_java}/../%{name}" -%endif - -# Register poms -%if !%{install_poms} -rm -fr "%{buildroot}%{_mavenpomdir}" -%else -for pom in %{buildroot}%{_mavenpomdir}/*.pom -do - pomdir=`dirname "${pom}"` - pom=`basename "${pom}"` - jpppom="JPP.${pom}" - mv "${pomdir}/${pom}" "${pomdir}/${jpppom}" - artifact_id=`echo "${pom}" | sed -e 's/^%{name}-//' -e 's/\.pom//'` - if [ -f "%{buildroot}%{dwh_java}/${artifact_id}.jar" ] - then - %add_maven_depmap "${jpppom}" "%{name}/${artifact_id}.jar" - else - %add_maven_depmap "${jpppom}" - fi -done -%endif - -%post -/sbin/chkconfig --add %{dwh_name}d > /dev/null 2>&1 -/sbin/chkconfig %{dwh_name}d off > /dev/null 2>&1 -/sbin/service %{dwh_name}d stop > /dev/null 2>&1 -/usr/sbin/logrotate /etc/logrotate.conf > /dev/null || /bin/true - -%preun -if [ "$1" -eq 0 ] -then - /sbin/service %{dwh_name}d stop > /dev/null 2>&1 - /sbin/chkconfig --list %{dwh_name}d > /dev/null 2>&1 - if [ $? -eq 0 ] - then - /sbin/chkconfig --del %{dwh_name}d > /dev/null 2>&1 - fi -fi - -%files -%{dwh_java} -%{_datadir}/%{dwh_name} -%if "%{name}" != "%{dwh_name}" -%{_javadir}/%{name} -%endif -%if %{install_poms} -%{_mavendepmapfragdir}/%{name} -%{_mavenpomdir}/JPP.%{name}-* -%endif - -%dir %attr(-, %{engine_user}, %{engine_group}) %{_sysconfdir}/%{dwh_name}/engine-dwh.conf.d -%config(noreplace) %{_sysconfdir}/%{dwh_name}/engine-dwh.conf.d/10-setup-database-dwh.conf - -%dir %{_sysconfdir}/ovirt-engine/%{dwh_name} -%{_initddir}/%{dwh_name}d -%config(noreplace) %{_sysconfdir}/logrotate.d/%{dwh_name}d -%{_bindir}/%{dwh_name}-setup -%{_sysconfdir}/cron.hourly/ovirt_engine_dwh_watchdog.cron -%config(noreplace) %attr(-, %{engine_user}, %{engine_group}) %{_sysconfdir}/ovirt-engine/%{dwh_name}/Default.properties - -%changelog -* Thu Apr 19 2012 Yaniv Dary <yd...@redhat.com> - 3.0.0-1.fc16 -- Added packaging to dwh diff --git a/packaging/ovirt-engine-dwh.spec.tmpl b/packaging/ovirt-engine-dwh.spec.tmpl deleted file mode 120000 index 7e84739..0000000 --- a/packaging/ovirt-engine-dwh.spec.tmpl +++ /dev/null @@ -1 +0,0 @@ -ovirt-engine-dwh.spec.in \ No newline at end of file diff --git a/packaging/setup/ovirt_engine_setup/dwh_config.py.in b/packaging/setup/ovirt_engine_setup/dwh_config.py.in new file mode 100644 index 0000000..09bca94 --- /dev/null +++ b/packaging/setup/ovirt_engine_setup/dwh_config.py.in @@ -0,0 +1,31 @@ +# +# 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. +# + + +"""Config.""" + + +DWH_DATADIR = '@DATA_DIR@' +DWH_SYSCONFDIR = '@SYSCONF_DIR@/@OVIRT_DWH_NAME@' +PACKAGE_NAME = '@PACKAGE_NAME@' +PACKAGE_VERSION = '@PACKAGE_VERSION@' +DISPLAY_VERSION = '@DISPLAY_VERSION@' +RPM_VERSION = '@RPM_VERSION@' +RPM_RELEASE = '@RPM_RELEASE@' + + +# vim: expandtab tabstop=4 shiftwidth=4 diff --git a/packaging/setup/ovirt_engine_setup/dwh_constants.py b/packaging/setup/ovirt_engine_setup/dwh_constants.py new file mode 100644 index 0000000..86c30eb --- /dev/null +++ b/packaging/setup/ovirt_engine_setup/dwh_constants.py @@ -0,0 +1,159 @@ +# +# 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. +# + + +"""Constants.""" + + +import os +import gettext +_ = lambda m: gettext.dgettext(message=m, domain='ovirt-dwh') + + +from otopi import util + + +from ovirt_engine_setup import constants as osetupcons +from ovirt_engine_setup import dwh_config + + +@util.export +@util.codegen +@osetupcons.osetupattrsclass +class ConfigEnv(object): + @osetupcons.osetupattrs( + answerfile=True, + summary=True, + description=_('Configure DWH Service'), + postinstallfile=True, + ) + def DWH_CONFIG(self): + return 'OVESETUP_DWH_CONFIG/DWHConfig' + + +@util.export +class Defaults(object): + DEFAULT_DB_HOST = 'localhost' + DEFAULT_DB_PORT = 5432 + DEFAULT_DB_DATABASE = 'ovirt_engine_history' + DEFAULT_DB_USER = 'engine_history' + DEFAULT_DB_PASSWORD = '' + DEFAULT_DB_SECURED = False + DEFAULT_DB_SECURED_HOST_VALIDATION = False + + +@util.export +@util.codegen +@osetupcons.osetupattrsclass +class DBEnv(object): + + @osetupcons.osetupattrs( + answerfile=True, + summary=True, + description=_('DWH Database host'), + ) + def HOST(self): + return 'DWHSETUP_DB/host' + + @osetupcons.osetupattrs( + answerfile=True, + summary=True, + description=_('DWH Database port'), + ) + def PORT(self): + return 'DWHSETUP_DB/port' + + @osetupcons.osetupattrs( + answerfile=True, + summary=True, + description=_('DWH Database secured connection'), + ) + def SECURED(self): + return 'DWHSETUP_DB/secured' + + @osetupcons.osetupattrs( + answerfile=True, + summary=True, + description=_('DWH Database host name validation'), + ) + def SECURED_HOST_VALIDATION(self): + return 'DWHSETUP_DB/securedHostValidation' + + @osetupcons.osetupattrs( + answerfile=True, + summary=True, + description=_('DWH Database name'), + ) + def DATABASE(self): + return 'DWHSETUP_DB/database' + + @osetupcons.osetupattrs( + answerfile=True, + summary=True, + description=_('DWH Database user name'), + ) + def USER(self): + return 'DWHSETUP_DB/user' + + @osetupcons.osetupattrs( + answerfile=True, + ) + def PASSWORD(self): + return 'DWHSETUP_DB/password' + + CONNECTION = 'DWHSETUP_DB/connection' + STATEMENT = 'DWHSETUP_DB/statement' + PGPASS_FILE = 'DWHSETUP_DB/pgPassFile' + NEW_DATABASE = 'DWHSETUP_DB/newDatabase' + + +@util.export +class FileLocations(object): + SYSCONFDIR = '/etc' + LOCALSTATEDIR = '/var' + DATADIR = '/usr/share' + + DWH_CONFIG_DIR = dwh_config.DWH_SYSCONFDIR + DWH_DB_SCRIPT_DIR = os.path.join( + dwh_config.DWH_DATADIR, + 'db-scripts', + ) + #FIXME: this path is hardcoded in data-warehouse java sources. + #It should be moved under $SYSCONFDIR/ovirt-engine-dwh + DB_CONNECTION_PROPERTIES_FILE = os.path.join( + '/etc/ovirt-engine/ovirt-engine-dwh', + 'Default.properties' + ) + + DWH_SERVICE_CONFIG = os.path.join( + DWH_CONFIG_DIR, + 'engine-dwh.conf' + ) + DWH_SERVICE_CONFIGD = '%s.d' % DWH_SERVICE_CONFIG + DWH_SERVICE_CONFIG_DATABASE = os.path.join( + DWH_SERVICE_CONFIGD, + '10-setup-database-dwh.conf', + ) + + +@util.export +class Stages(object): + DB_CONNECTION_AVAILABLE = 'osetup.db.connection.available' + DB_SCHEMA = 'osetup.db.schema' + + +# vim: expandtab tabstop=4 shiftwidth=4 diff --git a/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/config/__init__.py b/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/config/__init__.py new file mode 100644 index 0000000..80ef2ba --- /dev/null +++ b/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/config/__init__.py @@ -0,0 +1,33 @@ +# +# ovirt-engine-dwh -- ovirt engine dwh 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. +# + + +"""ovirt-engine-setup DWH plugin.""" + + +from otopi import util + + +from . import db_connectivity + + +@util.export +def createPlugins(context): + db_connectivity.Plugin(context=context) + + +# vim: expandtab tabstop=4 shiftwidth=4 diff --git a/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/config/db_connectivity.py b/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/config/db_connectivity.py new file mode 100644 index 0000000..923a556 --- /dev/null +++ b/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/config/db_connectivity.py @@ -0,0 +1,149 @@ +# +# ovirt-engine-dwh -- ovirt engine dwh 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. +# + + +"""ovirt-engine-setup DWH DB connectivity plugin.""" + + +import gettext +import os + + +from otopi import constants as otopicons +from otopi import filetransaction +from otopi import plugin +from otopi import util + + +from ovirt_engine_setup import constants as osetupcons +from ovirt_engine_setup import dwh_config +from ovirt_engine_setup import dwh_constants +from ovirt_engine_setup import util as osetuputil + + +_ = lambda m: gettext.dgettext(message=m, domain='ovirt-dwh') + + +@util.export +class Plugin(plugin.PluginBase): + """ovirt-engine-setup DWH DB connectivity plugin.""" + + def __init__(self, context): + super(Plugin, self).__init__(context=context) + + @plugin.event( + stage=plugin.Stages.STAGE_INIT, + ) + def _init(self): + self.environment.setdefault( + dwh_constants.DBEnv.HOST, + None + ) + self.environment.setdefault( + dwh_constants.DBEnv.PORT, + None + ) + self.environment.setdefault( + dwh_constants.DBEnv.DATABASE, + None + ) + self.environment.setdefault( + dwh_constants.DBEnv.USER, + None + ) + self.environment.setdefault( + dwh_constants.DBEnv.PASSWORD, + None + ) + + @plugin.event( + stage=plugin.Stages.STAGE_MISC, + condition=lambda self: self.environment[ + dwh_constants.ConfigEnv.DWH_CONFIG + ], + ) + def _misc(self): + """ + Updates DWH DB connectivity file + """ + changed_lines = [] + content = [] + if os.path.exists( + dwh_constants.FileLocations.DB_CONNECTION_PROPERTIES_FILE + ): + with open( + dwh_constants.FileLocations.DB_CONNECTION_PROPERTIES_FILE, + 'r' + ) as f: + content = f.read().splitlines() + self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( + filetransaction.FileTransaction( + name=dwh_constants.FileLocations.DB_CONNECTION_PROPERTIES_FILE, + content=osetuputil.editConfigContent( + content=content, + params={ + 'etlVersion': dwh_config.RPM_VERSION, + 'ovirtEngineHistoryDbPassword': self.environment[ + dwh_constants.DBEnv.PASSWORD + ], + 'ovirtEngineHistoryDbUser': self.environment[ + dwh_constants.DBEnv.USER + ], + 'ovirtEngineDbPassword': self.environment[ + osetupcons.DBEnv.PASSWORD + ], + 'ovirtEngineDbUser': self.environment[ + osetupcons.DBEnv.USER + ], + 'ovirtEngineDbJdbcConnection': ( + 'jdbc\:postgresql\://{host}\:{port}/' + '{dbname}?stringtype\=unspecified' + ).format( + host=self.environment[osetupcons.DBEnv.HOST], + port=self.environment[osetupcons.DBEnv.PORT], + dbname=self.environment[osetupcons.DBEnv.DATABASE], + ), + 'ovirtEngineHistoryDbJdbcConnection': ( + 'jdbc\:postgresql\://{host}\:{port}/{dbname}?' + 'stringtype\=unspecified' + ).format( + host=self.environment[dwh_constants.DBEnv.HOST], + port=self.environment[dwh_constants.DBEnv.PORT], + dbname=self.environment[ + dwh_constants.DBEnv.DATABASE + ], + ), + }, + changed_lines=changed_lines, + new_line_tpl='{param}={value}', + ) + ) + ) + self.environment[ + osetupcons.CoreEnv.REGISTER_UNINSTALL_GROUPS + ].createGroup( + group='dwh_db_config', + description='DWH DB Configuration', + optional=False + ).addChanges( + 'dwh_db_config', + dwh_constants.FileLocations.DB_CONNECTION_PROPERTIES_FILE, + changed_lines, + ) + + +# vim: expandtab tabstop=4 shiftwidth=4 diff --git a/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/core/__init__.py b/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/core/__init__.py new file mode 100644 index 0000000..4c6b99d --- /dev/null +++ b/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/core/__init__.py @@ -0,0 +1,34 @@ +# +# ovirt-engine-dwh -- ovirt engine dwh 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. +# + + +"""ovirt-engine-setup DWH plugin.""" + + +from otopi import util + +from . import compatibility +from . import config + + +@util.export +def createPlugins(context): + compatibility.Plugin(context=context) + config.Plugin(context=context) + + +# vim: expandtab tabstop=4 shiftwidth=4 diff --git a/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/core/compatibility.py b/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/core/compatibility.py new file mode 100644 index 0000000..952a157 --- /dev/null +++ b/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/core/compatibility.py @@ -0,0 +1,92 @@ +# +# ovirt-engine-dwh -- ovirt engine dwh 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. +# + + +"""ovirt-engine-setup ETL compatibility plugin.""" + + +import distutils.version +import gettext + + +from otopi import plugin +from otopi import util + + +from ovirt_engine_setup import constants as osetupcons +from ovirt_engine_setup import database +from ovirt_engine_setup import dwh_config + + +_ = lambda m: gettext.dgettext(message=m, domain='ovirt-dwh') + + +@util.export +class Plugin(plugin.PluginBase): + """ovirt-engine-setup ETL compatibility plugin.""" + + def __init__(self, context): + super(Plugin, self).__init__(context=context) + + @plugin.event( + stage=plugin.Stages.STAGE_VALIDATION, + after=( + osetupcons.Stages.DB_CREDENTIALS_AVAILABLE_EARLY, + ), + ) + def _validation(self): + """ + Check installed version with minimal support version + """ + if ( + osetupcons.ProvisioningEnv.POSTGRES_PROVISIONING_ENABLED in + self.environment + ): + #We're installing ovirt-engine-dwh on the same host where we're + #installing ovirt-engine. + dbovirtutils = database.OvirtUtils(plugin=self) + try: + dbovirtutils.tryDatabaseConnect(self.environment) + except RuntimeError: + self.logger.debug( + 'Database not yet created, skipping ETL version validation' + ) + return + current = distutils.version.LooseVersion(dwh_config.RPM_VERSION) + minimal = distutils.version.LooseVersion( + database.Statement( + environment=self.environment, + ).getVdcOption( + name='MinimalETLVersion', + ownConnection=True, + ) + ) + if minimal > current: + raise RuntimeError( + _( + 'Minimal supported version ({minimal}) is higher than ' + 'installed version ({current}), please update the ' + '{package} package' + ).format( + minimal=str(minimal), + current=str(current), + package=dwh_config.PACKAGE_NAME, + ) + ) + + +# vim: expandtab tabstop=4 shiftwidth=4 diff --git a/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/core/config.py b/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/core/config.py new file mode 100644 index 0000000..40b4cc5 --- /dev/null +++ b/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/core/config.py @@ -0,0 +1,86 @@ +# +# ovirt-engine-dwh -- ovirt engine dwh 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. +# + + +"""ovirt-engine-setup DWH config plugin.""" + + +import gettext + + +from otopi import util +from otopi import plugin + + +from ovirt_engine_setup import dwh_constants +from ovirt_engine_setup import dialog +from ovirt_engine_setup import constants as osetupcons + + +_ = lambda m: gettext.dgettext(message=m, domain='ovirt-dwh') + + +@util.export +class Plugin(plugin.PluginBase): + """ovirt-engine-setup DWH config plugin.""" + + def __init__(self, context): + super(Plugin, self).__init__(context=context) + self._enabled = True + + @plugin.event( + stage=plugin.Stages.STAGE_INIT, + ) + def _init(self): + self.environment.setdefault( + dwh_constants.ConfigEnv.DWH_CONFIG, + None + ) + + @plugin.event( + stage=plugin.Stages.STAGE_CUSTOMIZATION, + condition=lambda self: self._enabled, + before=( + osetupcons.Stages.DIALOG_TITLES_E_SYSTEM, + ), + after=( + osetupcons.Stages.DB_CONNECTION_STATUS, + osetupcons.Stages.DIALOG_TITLES_S_SYSTEM, + ), + ) + def _customization(self): + if self.environment[ + dwh_constants.ConfigEnv.DWH_CONFIG + ] is None: + self.environment[ + dwh_constants.ConfigEnv.DWH_CONFIG + ] = dialog.queryBoolean( + dialog=self.dialog, + name='OVESETUP_CONFIG_DWH', + note=_( + 'Configure DWH service on this machine? ' + '(@VALUES@) [@DEFAULT@]: ' + ), + prompt=True, + default=True, + ) + self._enabled = self.environment[ + dwh_constants.ConfigEnv.DWH_CONFIG + ] + + +# vim: expandtab tabstop=4 shiftwidth=4 diff --git a/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/db/__init__.py b/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/db/__init__.py new file mode 100644 index 0000000..bf51e88 --- /dev/null +++ b/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/db/__init__.py @@ -0,0 +1,35 @@ +# +# ovirt-engine-dwh -- ovirt engine dwh 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. +# + + +"""ovirt-engine-setup DWH plugin.""" + + +from otopi import util + + +from . import connection +from . import engine_db + + +@util.export +def createPlugins(context): + connection.Plugin(context=context) + engine_db.Plugin(context=context) + + +# vim: expandtab tabstop=4 shiftwidth=4 diff --git a/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/db/connection.py b/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/db/connection.py new file mode 100644 index 0000000..448fc3f --- /dev/null +++ b/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/db/connection.py @@ -0,0 +1,281 @@ +# +# ovirt-engine-dwh -- ovirt engine dwh 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. +# + + +"""ovirt-engine-setup DWH DB customization plugin.""" + + +import socket +import gettext + + +import psycopg2 + + +from otopi import constants as otopicons +from otopi import util +from otopi import plugin + + +from ovirt_engine_setup import util as osetuputil +from ovirt_engine_setup import database +from ovirt_engine_setup import dialog +from ovirt_engine_setup import dwh_constants + + +_ = lambda m: gettext.dgettext(message=m, domain='ovirt-dwh') + + +@util.export +class Plugin(plugin.PluginBase): + """ovirt-engine-setup DWH DB customization plugin.""" + + def __init__(self, context): + super(Plugin, self).__init__(context=context) + + @plugin.event( + stage=plugin.Stages.STAGE_INIT, + ) + def _init(self): + self.environment.setdefault( + dwh_constants.DBEnv.STATEMENT, + None + ) + self.environment.setdefault( + dwh_constants.DBEnv.CONNECTION, + None + ) + self.environment.setdefault( + dwh_constants.DBEnv.SECURED_HOST_VALIDATION, + None + ) + self.environment.setdefault( + dwh_constants.DBEnv.SECURED, + None + ) + self.environment.setdefault( + dwh_constants.DBEnv.NEW_DATABASE, + None + ) + + @plugin.event( + stage=plugin.Stages.STAGE_CUSTOMIZATION, + condition=lambda self: self.environment[ + dwh_constants.ConfigEnv.DWH_CONFIG + ], + ) + def _customization(self): + dbovirtutils = database.OvirtUtils(plugin=self) + + interactive = None in ( + self.environment[dwh_constants.DBEnv.HOST], + self.environment[dwh_constants.DBEnv.PORT], + self.environment[dwh_constants.DBEnv.DATABASE], + self.environment[dwh_constants.DBEnv.USER], + self.environment[dwh_constants.DBEnv.PASSWORD], + ) + + if interactive: + self.dialog.note( + text=_( + "\n" + "ATTENTION\n" + "\n" + "Manual action required.\n" + "Please create database for ovirt-engine-dwh use. " + "Use the following commands as an example:\n" + "\n" + "create user engine_history password 'engine';\n" + "create database ovirt_engine_history " + "owner engine_history template template0\n" + "encoding 'UTF8' lc_collate 'en_US.UTF-8'\n" + "lc_ctype 'en_US.UTF-8';\n" + "\n" + "Make sure that database can be accessed remotely.\n" + "\n" + ), + ) + else: + self.dialog.note( + text=_( + 'Using existing credentials for accessing DWH database' + ), + ) + + connectionValid = False + while not connectionValid: + host = self.environment[dwh_constants.DBEnv.HOST] + port = self.environment[dwh_constants.DBEnv.PORT] + secured = self.environment[dwh_constants.DBEnv.SECURED] + securedHostValidation = self.environment[ + dwh_constants.DBEnv.SECURED_HOST_VALIDATION + ] + db = self.environment[dwh_constants.DBEnv.DATABASE] + user = self.environment[dwh_constants.DBEnv.USER] + password = self.environment[dwh_constants.DBEnv.PASSWORD] + + if host is None: + while True: + host = self.dialog.queryString( + name='OVESETUP_DB_HOST', + note=_('Database host [@DEFAULT@]: '), + prompt=True, + default=dwh_constants.Defaults.DEFAULT_DB_HOST, + ) + try: + socket.getaddrinfo(host, None) + break # do while missing in python + except socket.error as e: + self.logger.error( + _('Host is invalid: {error}').format( + error=e.strerror + ) + ) + + if port is None: + while True: + try: + port = osetuputil.parsePort( + self.dialog.queryString( + name='OVESETUP_DB_PORT', + note=_('Database port [@DEFAULT@]: '), + prompt=True, + default=dwh_constants.Defaults.DEFAULT_DB_PORT, + ) + ) + break # do while missing in python + except ValueError: + pass + + if secured is None: + secured = dialog.queryBoolean( + dialog=self.dialog, + name='OVESETUP_DB_SECURED', + note=_( + 'Database secured connection (@VALUES@) ' + '[@DEFAULT@]: ' + ), + prompt=True, + default=dwh_constants.Defaults.DEFAULT_DB_SECURED, + ) + + if not secured: + securedHostValidation = False + + if securedHostValidation is None: + securedHostValidation = dialog.queryBoolean( + dialog=self.dialog, + name='OVESETUP_DB_SECURED_HOST_VALIDATION', + note=_( + 'Validate host name in secured connection (@VALUES@) ' + '[@DEFAULT@]: ' + ), + prompt=True, + default=True, + ) == 'yes' + + if db is None: + db = self.dialog.queryString( + name='OVESETUP_DB_DATABASE', + note=_('Database name [@DEFAULT@]: '), + prompt=True, + default=dwh_constants.Defaults.DEFAULT_DB_DATABASE, + ) + + if user is None: + user = self.dialog.queryString( + name='OVESETUP_DB_USER', + note=_('Database user [@DEFAULT@]: '), + prompt=True, + default=dwh_constants.Defaults.DEFAULT_DB_USER, + ) + + if password is None: + password = self.dialog.queryString( + name='OVESETUP_DB_PASSWORD', + note=_('Database password: '), + prompt=True, + hidden=True, + ) + + self.environment[otopicons.CoreEnv.LOG_FILTER].append(password) + + dbenv = { + dwh_constants.DBEnv.HOST: host, + dwh_constants.DBEnv.PORT: port, + dwh_constants.DBEnv.SECURED: secured, + dwh_constants.DBEnv.SECURED_HOST_VALIDATION: ( + securedHostValidation + ), + dwh_constants.DBEnv.USER: user, + dwh_constants.DBEnv.PASSWORD: password, + dwh_constants.DBEnv.DATABASE: db, + } + + if interactive: + try: + #FIXME: need to be refactored for allow DWH db testing + #dbovirtutils.tryDatabaseConnect(dbenv) + self.environment.update(dbenv) + connectionValid = True + except RuntimeError as e: + self.logger.error( + _('Cannot connect to database: {error}').format( + error=e, + ) + ) + else: + # this is usally reached in provisioning + # or if full ansewr file + self.environment.update(dbenv) + connectionValid = True + + try: + self.environment[ + dwh_constants.DBEnv.NEW_DATABASE + ] = dbovirtutils.isNewDatabase() + except: + self.logger.debug('database connection failed', exc_info=True) + + @plugin.event( + stage=plugin.Stages.STAGE_MISC, + name=dwh_constants.Stages.DB_CONNECTION_AVAILABLE, + after=( + dwh_constants.Stages.DB_SCHEMA, + ), + ) + def _connection(self): + pass + #FIXME: complete this after schema + # must be here as we do not have database at validation + #self.environment[ + #dwh_constants.DBEnv.CONNECTION + #] = psycopg2.connect( + #host=self.environment[dwh_constants.DBEnv.HOST], + #port=self.environment[dwh_constants.DBEnv.PORT], + #user=self.environment[dwh_constants.DBEnv.USER], + #password=self.environment[dwh_constants.DBEnv.PASSWORD], + #database=self.environment[dwh_constants.DBEnv.DATABASE], + #) + #self.environment[ + #dwh_constants.DBEnv.STATEMENT + #] = database.Statement( + #environment=self.environment, + #) + + +# vim: expandtab tabstop=4 shiftwidth=4 diff --git a/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/db/engine_db.py b/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/db/engine_db.py new file mode 100644 index 0000000..579ca47 --- /dev/null +++ b/packaging/setup/plugins/ovirt-engine-setup/ovirt-dwh/db/engine_db.py @@ -0,0 +1,61 @@ +# +# ovirt-engine-dwh -- ovirt engine dwh 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. +# + + +"""ovirt-engine-setup engine DB customization plugin.""" + + +import gettext + + +from otopi import plugin +from otopi import util + + +from ovirt_engine_setup import constants as osetupcons + + +_ = lambda m: gettext.dgettext(message=m, domain='ovirt-dwh') + + +@util.export +class Plugin(plugin.PluginBase): + """ovirt-engine-setup engine DB customization plugin.""" + + def __init__(self, context): + super(Plugin, self).__init__(context=context) + + @plugin.event( + stage=plugin.Stages.STAGE_CUSTOMIZATION, + before=( + osetupcons.Stages.DB_CONNECTION_CUSTOMIZATION, + ), + after=( + osetupcons.Stages.DIALOG_TITLES_S_DATABASE, + ), + ) + def _customization(self): + if ( + not osetupcons.ProvisioningEnv.POSTGRES_PROVISIONING_ENABLED in + self.environment + ): + #We're not installing ovirt-engine-dwh on the same host where we're + #installing ovirt-engine. + self.environment[osetupcons.DBEnv.MANUAL_CREATION_REQUIRED] = False + + +# vim: expandtab tabstop=4 shiftwidth=4 -- To view, visit http://gerrit.ovirt.org/21380 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0f07eb3f93d884f806603e5e9c7f2c577c17dc98 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-dwh Gerrit-Branch: master Gerrit-Owner: Sandro Bonazzola <sbona...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches