Name:        oozie
Version:     5.2.1
Release:     2
Summary:     A work-flow scheduling system for Apache Hadoop
License:     Apache 2.0
URL:         http://oozie.apache.org
Source0:     https://github.com/apache/%{name}/archive/refs/tags/release-%{version}.tar.gz
Source1:     fluent-job-api-target.tar.gz 
Source2:     %{name}.logrotate
Patch0000:   fix-oozie-command-not-found-jar-path.patch
BuildArch:   noarch
BuildRequires:   java-1.8.0-openjdk-devel maven xmvn xmvn-install gradle-local maven-local 
Requires:     java-1.8.0-openjdk-devel hostname tomcat


%description
Apache Oozie is an extensible, scalable and reliable system to define,
manage, schedule, and execute complex Apache Hadoop workloads via
web services


%prep
%setup -qn %{name}-release-%{version}  
%patch0 -p1

tar xf %{SOURCE1}
cp -arf target   fluent-job/fluent-job-api/
rm -rf  target

%pom_disable_module fluent-job-api fluent-job

%build
export LC_ALL=en_US.UTF-8

mvn  clean package assembly:single -DskipTests 

%install

install -d -m 0755 %{buildroot}/%{_bindir}
install -d -m 0755 %{buildroot}/%{_datadir}/%{name}/bin
install -d -m 0755 %{buildroot}/%{_datadir}/%{name}/libtools
install -d -m 0755 %{buildroot}/%{_sysconfdir}/%{name}/action-conf
install -d -m 0755 %{buildroot}/%{_sysconfdir}/%{name}/tomcat/Catalina/localhost
install -d -m 0755 %{buildroot}/%{_sysconfdir}/logrotate.d
install -d -m 0755 %{buildroot}/%{_sysconfdir}/sysconfig
install -d -m 0755 %{buildroot}/%{_var}/cache/%{name}/data
install -d -m 0755 %{buildroot}/%{_var}/cache/%{name}/temp
install -d -m 0755 %{buildroot}/%{_var}/cache/%{name}/work
install -d -m 0755 %{buildroot}/%{_var}/log/%{name}
install -d -m 0755 %{buildroot}%{_datadir}/doc/%{name}
install -d -m 0755 %{buildroot}%{_datadir}/java/%{name}
install -d -m 0755 %{buildroot}%{_mavenpomdir}/%{name}
install -d -m 0755 %{buildroot}%{_datadir}/%{name}/embedded-%{name}-server
pushd distro/target/oozie-%{version}-distro/oozie-%{version}
  i=`find ~ -name .m2`
  for a in `find  $i/repository/org/apache/hadoop/ -name *.jar`; do 
  \cp $a libtools/;
  done
  cp $i/repository/commons-configuration/commons-configuration/1.6/commons-configuration-1.6.jar libtools/
 
  cp -arf bin/* %{buildroot}%{_datadir}/%{name}/bin
  cp -arf libtools/* %{buildroot}%{_datadir}/%{name}/libtools
  cp -arf oozie-core/* %{buildroot}%{_datadir}/%{name}/libtools 
  cp -arf embedded-oozie-server/* %{buildroot}%{_datadir}/%{name}/embedded-%{name}-server
popd

pushd client/target/%{name}-client-%{version}-client/%{name}-client-%{version}
     cp -arf bin/* %{buildroot}%{_datadir}/%{name}/bin
     cp -arf conf/* %{buildroot}%{_sysconfdir}/%{name}
     cp -arf lib/* %{buildroot}%{_datadir}/%{name}/libtools
popd
     
pushd sharelib/target
    tar xf %{name}-sharelib-%{version}.tar.gz
    for b in `find ./share/lib -name "*sharelib*jar"`;do
     cp $b %{buildroot}%{_datadir}/%{name}/libtools
    done
popd

for f in LICENSE.txt NOTICE.txt README.md ;do
   cp -f ${f} %{buildroot}%{_datadir}/doc/%{name}
done

for  z in client core tools distro examples server ;do
install -pm 0644 $z/pom.xml %{buildroot}%{_mavenpomdir}/%{name}/%{name}-$z.pom
install -pm 0644 $z/target/%{name}-$z-%{version}.jar %{buildroot}%{_javadir}/%{name}/%{name}-$z.jar
%add_maven_depmap %{name}/%{name}-$z.pom  %{name}/%{name}-$z.jar 
done

pushd sharelib/
for  x in distcp hcatalog  hive hive2 oozie git pig spark sqoop streaming ;do
install -pm 0644 $x/pom.xml %{buildroot}%{_mavenpomdir}/%{name}/%{name}-sharelib-$x.pom
install -pm 0644 $x/target/%{name}-sharelib-$x-%{version}.jar %{buildroot}%{_javadir}/%{name}/%{name}-sharelib-$x.jar
%add_maven_depmap %{name}/%{name}-sharelib-$x.pom  %{name}/%{name}-sharelib-$x.jar
done
popd

pushd fluent-job/
for y in api client ;do
install -pm 0644  fluent-job-$y/pom.xml %{buildroot}%{_mavenpomdir}/%{name}/%{name}-fluent-job-$y.pom
install -pm 0644 fluent-job-$y/target/%{name}-fluent-job-$y-%{version}.jar \
 %{buildroot}%{_javadir}/%{name}/%{name}-fluent-job-$y.jar
%add_maven_depmap %{name}/%{name}-fluent-job-$y.pom  %{name}/%{name}-fluent-job-$y.jar
done
popd

pushd minitest/
install -pm 0644  pom.xml %{buildroot}%{_mavenpomdir}/%{name}/%{name}-mini.pom
install -pm 0644  target/%{name}-mini-%{version}.jar %{buildroot}%{_javadir}/%{name}/%{name}-mini.jar
 %add_maven_depmap %{name}/%{name}-mini.pom %{name}/%{name}-mini.jar
popd


pushd %{buildroot}%{_datadir}/%{name}/bin
  ls | awk '{print $1}'|grep .sh | for line in `xargs`;do
    ln -s %{_datadir}/%{name}/bin/${line} %{buildroot}%{_bindir}/${line}
  done
popd

pushd %{buildroot}%{_datadir}/%{name}/bin
   ln -s  %{_datadir}/%{name}/bin/%{name} %{buildroot}%{_bindir}/%{name}
popd



pushd %{buildroot}/%{_datadir}/%{name}/embedded-%{name}-server
  %{__ln_s} %{_var}/cache/%{name}/temp temp
  %{__ln_s} %{_var}/cache/%{name}/work work
  %{__ln_s} %{_var}/log/%{name} logs
popd


cp -arf  distro/target/oozie-%{version}-distro/oozie-%{version}/conf/*  %{buildroot}/%{_sysconfdir}/%{name}/
pushd %{buildroot}/%{_datadir}/%{name}
  %{__ln_s} %{_sysconfdir}/%{name} conf
  %{__ln_s} %{_var}/cache/%{name}/data data
  %{__ln_s} %{_var}/log/%{name} logs
popd

cp -arf webapp/target/%{name}-webapp-%{version}/WEB-INF/web.xml \
  %{buildroot}/%{_datadir}/%{name}/embedded-%{name}-server/webapp/WEB-INF

sed -i "s|\(path=.*\)>|\1 allowLinking=\"true\">|" \
 %{buildroot}/%{_datadir}/%{name}/embedded-%{name}-server/webapp/META-INF/context.xml

install -m 0644 %{SOURCE2} %{buildroot}/%{_sysconfdir}/logrotate.d/%{name}

%files
%doc %{_datadir}/doc/%{name}/*
%{_bindir}/*
%{_datadir}/%{name}/*
%{_sysconfdir}/%{name}/
%{_datadir}/java/%{name}/*
%{_mavenpomdir}/%{name}/*
%{_datadir}/maven-metadata/%{name}.xml
%attr(0775,root,tomcat) %dir %{_var}/log/%{name}
%attr(0775,root,tomcat) %dir %{_var}/cache/%{name}
%attr(0775,root,tomcat) %dir %{_var}/cache/%{name}/data
%attr(0775,root,tomcat) %dir %{_var}/cache/%{name}/temp
%attr(0775,root,tomcat) %dir %{_var}/cache/%{name}/work
%config(noreplace) %{_sysconfdir}/%{name}/adminusers.txt
%config(noreplace) %{_sysconfdir}/%{name}/oozie-site.xml
%config(noreplace) %{_sysconfdir}/%{name}/oozie-log4j.properties
%config(noreplace) %{_sysconfdir}/%{name}/oozie-env.sh
%config(noreplace) %{_sysconfdir}/%{name}/action-conf
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%config(noreplace) %{_sysconfdir}/%{name}/hadoop-conf/core-site.xml
%config(noreplace) %{_sysconfdir}/%{name}/hadoop-config.xml
%config(noreplace) %{_sysconfdir}/%{name}/action-conf/hive.xml
%attr(0775,root,tomcat) %dir %{_sysconfdir}/%{name}/tomcat
%attr(0775,root,tomcat) %dir %{_sysconfdir}/%{name}/tomcat/Catalina
%attr(0775,root,tomcat) %dir %{_sysconfdir}/%{name}/tomcat/Catalina/localhost

%changelog
* Thu Sep 30 2021 liyanan <liyanan32@huawei.com> - 5.2.1-2
- fix oozie command not found jar path

* Mon Jul 12 2021 liyanan <liyanan32@huawei.com> - 5.2.1-1
- package init
