AMBARI-15933. Views work for Hue to Views Migration Tool (Pradarttana Panda via 
dipayanb)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/af9654ff
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/af9654ff
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/af9654ff

Branch: refs/heads/trunk
Commit: af9654ff12baf24935ac8846435143db50ff04da
Parents: 56e3491
Author: Dipayan Bhowmick <[email protected]>
Authored: Tue Apr 26 22:52:54 2016 +0530
Committer: Dipayan Bhowmick <[email protected]>
Committed: Tue Apr 26 22:52:54 2016 +0530

----------------------------------------------------------------------
 contrib/views/hueambarimigration/pom.xml        | 246 ++++++
 .../configurationcheck/ConfigurationCheck.java  | 182 +++++
 .../configurationcheck/ProgressBarStatus.java   |  54 ++
 .../controller/hive/HiveHistoryMigration.java   | 222 ++++++
 .../hive/HiveSavedQueryMigration.java           | 231 ++++++
 .../controller/pig/PigJobMigration.java         | 201 +++++
 .../controller/pig/PigScriptMigration.java      | 208 +++++
 .../controller/revertchange/RevertChange.java   | 217 ++++++
 .../datasource/DataSourceAmbariDatabase.java    |  65 ++
 .../datasource/DataSourceHueDatabase.java       |  64 ++
 .../huetoambarimigration/model/PojoHive.java    |  51 ++
 .../huetoambarimigration/model/PojoPig.java     |  72 ++
 .../configurationcheck/ConfFileReader.java      | 199 +++++
 .../service/hive/HiveHistoryQueryImpl.java      | 562 ++++++++++++++
 .../service/hive/HiveSavedQueryImpl.java        | 778 +++++++++++++++++++
 .../service/pig/PigJobImpl.java                 | 563 ++++++++++++++
 .../service/pig/PigScriptImpl.java              | 600 ++++++++++++++
 .../src/main/resources/WEB-INF/web.xml          | 123 +++
 .../src/main/resources/image/updateimg.gif      | Bin 0 -> 56233 bytes
 .../src/main/resources/index.jsp                | 119 +++
 .../src/main/resources/ui/.gitignore            |  33 +
 .../src/main/resources/ui/bower.json            |  15 +
 .../main/resources/ui/checkconfiguration.jsp    |  57 ++
 .../resources/ui/hivehistoryquerymigration.jsp  | 229 ++++++
 .../resources/ui/hivesavedquerymigration.jsp    | 240 ++++++
 .../src/main/resources/ui/homepage.jsp          |  31 +
 .../src/main/resources/ui/package.json          |  27 +
 .../src/main/resources/ui/pigjobmigration.jsp   | 233 ++++++
 .../main/resources/ui/pigscriptsmigration.jsp   | 227 ++++++
 .../src/main/resources/ui/revertchange.jsp      | 203 +++++
 .../src/main/resources/view.log4j.properties    |  31 +
 .../src/main/resources/view.xml                 | 129 +++
 contrib/views/pom.xml                           |   1 +
 33 files changed, 6213 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/af9654ff/contrib/views/hueambarimigration/pom.xml
----------------------------------------------------------------------
diff --git a/contrib/views/hueambarimigration/pom.xml 
b/contrib/views/hueambarimigration/pom.xml
new file mode 100644
index 0000000..fbe4032
--- /dev/null
+++ b/contrib/views/hueambarimigration/pom.xml
@@ -0,0 +1,246 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <parent>
+    <groupId>org.apache.ambari.contrib.views</groupId>
+    <artifactId>ambari-contrib-views</artifactId>
+    <version>2.0.0.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>huetoambari-view</artifactId>
+  <packaging>jar</packaging>
+  <name>Hue To Ambari Migration-view</name>
+  <version>2.0.0.0-SNAPSHOT</version>
+  <url>http://maven.apache.org</url>
+  <properties>
+    <ambari.dir>${project.parent.parent.parent.basedir}</ambari.dir>
+  </properties>
+
+
+  <dependencies>
+
+    <dependency>
+      <groupId>org.easymock</groupId>
+      <artifactId>easymock</artifactId>
+      <version>3.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.ambari</groupId>
+      <artifactId>ambari-views</artifactId>
+      <version>[1.7.0.0,)</version>
+    </dependency>
+
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+      <version>2.5</version>
+
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-client</artifactId>
+      <version>2.3.0</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.xerial</groupId>
+      <artifactId>sqlite-jdbc</artifactId>
+      <version>3.7.2</version>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>postgresql</groupId>
+      <artifactId>postgresql</artifactId>
+      <version>8.4-701.jdbc3</version>
+    </dependency>
+    <dependency>
+      <groupId>mysql</groupId>
+      <artifactId>mysql-connector-java</artifactId>
+      <version>5.1.35</version>
+    </dependency>
+
+    <dependency>
+      <groupId>com.googlecode.json-simple</groupId>
+      <artifactId>json-simple</artifactId>
+      <version>1.1.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.json</groupId>
+      <artifactId>json</artifactId>
+      <version>20151123</version>
+    </dependency>
+    <dependency>
+      <groupId>jdom</groupId>
+      <artifactId>jdom</artifactId>
+      <version>1.1</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-configuration</groupId>
+      <artifactId>commons-configuration</artifactId>
+      <version>1.6</version>
+    </dependency>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+      <version>1.2.17</version>
+    </dependency>
+    <dependency>
+      <groupId>c3p0</groupId>
+      <artifactId>c3p0</artifactId>
+      <version>0.9.1.2</version>
+
+    </dependency>
+
+  </dependencies>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-surefire-plugin</artifactId>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+    <plugins>
+
+
+      <plugin>
+        <groupId>com.github.eirslett</groupId>
+        <artifactId>frontend-maven-plugin</artifactId>
+        <version>0.0.16</version>
+        <configuration>
+          <nodeVersion>v0.12.2</nodeVersion>
+          <npmVersion>1.4.8</npmVersion>
+          
<workingDirectory>${project.basedir}/src/main/resources/ui</workingDirectory>
+        </configuration>
+        <executions>
+          <execution>
+            <id>install node and npm</id>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>install-node-and-npm</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>npm install</id>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>npm</goal>
+            </goals>
+            <configuration>
+              <arguments>install 
--python="${project.basedir}/src/main/unix/ambari-python-wrap" --unsafe-perm
+              </arguments>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+
+
+      <plugin>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <executions>
+          <execution>
+            <phase>generate-resources</phase>
+            <goals>
+              <goal>copy-dependencies</goal>
+            </goals>
+            <configuration>
+              
<outputDirectory>${project.build.outputDirectory}/WEB-INF/lib</outputDirectory>
+              <includeScope>runtime</includeScope>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+
+
+    </plugins>
+    <resources>
+
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>true</filtering>
+        <includes>
+          <include>index.jsp</include>
+          <include>image/*.*</include>
+          <include>view.xml</include>
+          <include>view.log4j.properties</include>
+          <include>ui/*.*</include>
+          <include>WEB-INF/web.xml</include>
+        </includes>
+      </resource>
+
+
+      <resource>
+        
<directory>src/main/resources/ui/bower_components/bootstrap/dist/css/</directory>
+        <filtering>false</filtering>
+        <targetPath>${project.build.outputDirectory}/css</targetPath>
+      </resource>
+
+      <resource>
+        
<directory>src/main/resources/ui/bower_components/bootstrap/dist/fonts/</directory>
+        <filtering>false</filtering>
+        <targetPath>${project.build.outputDirectory}/fonts</targetPath>
+      </resource>
+
+
+      <resource>
+        
<directory>src/main/resources/ui/bower_components/eonasdan-bootstrap-datetimepicker/build/css</directory>
+        <filtering>false</filtering>
+        <targetPath>${project.build.outputDirectory}/css</targetPath>
+      </resource>
+
+      <resource>
+        
<directory>src/main/resources/ui//bower_components/moment/min/</directory>
+        <filtering>false</filtering>
+        <targetPath>${project.build.outputDirectory}/js</targetPath>
+      </resource>
+
+
+      <resource>
+        
<directory>src/main/resources/ui/bower_components/eonasdan-bootstrap-datetimepicker/build/js</directory>
+        <filtering>false</filtering>
+        <targetPath>${project.build.outputDirectory}/js</targetPath>
+      </resource>
+
+      <resource>
+        
<directory>src/main/resources/ui/bower_components/jquery/dist/</directory>
+        <filtering>false</filtering>
+        <targetPath>${project.build.outputDirectory}/js</targetPath>
+      </resource>
+      <resource>
+        
<directory>src/main/resources/ui/bower_components/bootstrap/dist/js</directory>
+        <filtering>false</filtering>
+        <targetPath>${project.build.outputDirectory}/js</targetPath>
+      </resource>
+      <resource>
+        <targetPath>WEB-INF/lib</targetPath>
+        <filtering>false</filtering>
+        <directory>target/lib</directory>
+      </resource>
+    </resources>
+  </build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/ambari/blob/af9654ff/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/configurationcheck/ConfigurationCheck.java
----------------------------------------------------------------------
diff --git 
a/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/configurationcheck/ConfigurationCheck.java
 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/configurationcheck/ConfigurationCheck.java
new file mode 100644
index 0000000..4c2f4ad
--- /dev/null
+++ 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/configurationcheck/ConfigurationCheck.java
@@ -0,0 +1,182 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ */
+
+
+package 
org.apache.ambari.view.huetoambarimigration.controller.configurationcheck;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URISyntaxException;
+import java.sql.Connection;
+
+import org.apache.ambari.view.ViewContext;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+
+import org.apache.ambari.view.huetoambarimigration.service.*;
+import 
org.apache.ambari.view.huetoambarimigration.service.configurationcheck.ConfFileReader;
+import org.apache.log4j.Logger;
+
+
+public class ConfigurationCheck extends HttpServlet {
+  private static final long serialVersionUID = 1L;
+
+  ViewContext view;
+
+  @Override
+  public void init(ServletConfig config) throws ServletException {
+
+    super.init(config);
+    ServletContext context = config.getServletContext();
+    view = (ViewContext) context.getAttribute(ViewContext.CONTEXT_ATTRIBUTE);
+
+  }
+
+  protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
+
+    final Logger logger = Logger.getLogger(ConfigurationCheck.class);
+    response.setContentType("text/html");
+    PrintWriter out = response.getWriter();
+
+    out.println("<table class=\"table\">");
+    out.println("<thead><tr><th>Service</th><th>Status</th></tr></thead>");
+    out.println("<tbody>");
+
+    if 
(ConfFileReader.checkConfigurationForHue(view.getProperties().get("Hue_URL"))) {
+      logger.info("Hue URl connection:- Success");
+      out.println("<tr class=\"success\">");
+      out.println("<td><h6>" + "Ambari" + "</h6></td>");
+      out.println("<td><h6>" + "OK" + "</h6></td>");
+      out.println("</tr>");
+    } else {
+      logger.info("Hue URl connection:- Failed");
+      out.println("<tr class=\"danger\">");
+      out.println("<td><h6>" + "Ambari" + "</h6></td>");
+      out.println("<td><h6>" + "ERROR" + "</h6></td>");
+      out.println("</tr>");
+    }
+
+    if 
(ConfFileReader.checkConfigurationForAmbari(view.getProperties().get("Ambari_URL")))
 {
+
+      logger.info("Ambari URl connection:- Success");
+      out.println("<tr class=\"success\">");
+      out.println("<td><h6>" + "Hue" + "</h6></td>");
+      out.println("<td><h6>" + "OK" + "</h6></td>");
+      out.println("</tr>");
+
+    } else {
+
+      logger.info("Ambari URl connection:- Failed");
+      out.println("<tr class=\"danger\">");
+      out.println("<td><h6>" + "Hue" + "</h6></td>");
+      out.println("<td><h6>" + "ERROR" + "</h6></td>");
+      out.println("</tr>");
+
+    }
+
+    if 
(ConfFileReader.checkAmbariDatbaseConection(view.getProperties().get("ambaridrivername"),
 view.getProperties().get("ambarijdbcurl"), 
view.getProperties().get("ambaridbusername"), 
view.getProperties().get("ambaridbpassword"))) {
+
+      logger.info("Ambari Database connection:- Success");
+      out.println("<tr class=\"success\">");
+      out.println("<td><h6>" + "Ambari Database" + "</h6></td>");
+      out.println("<td><h6>" + "OK" + "</h6></td>");
+      out.println("</tr>");
+
+    } else {
+
+      logger.info("Ambari Database connection:- Failed");
+      out.println("<tr class=\"danger\">");
+      out.println("<td><h6>" + "Ambari Database" + "</h6></td>");
+      out.println("<td><h6>" + "ERROR" + "</h6></td>");
+      out.println("</tr>");
+
+    }
+    if 
(ConfFileReader.checkHueDatabaseConnection(view.getProperties().get("huedrivername"),
 view.getProperties().get("huejdbcurl"), 
view.getProperties().get("huedbusername"), 
view.getProperties().get("huedbpassword"))) {
+
+      logger.info("Hue Database connection:- Success");
+      out.println("<tr class=\"success\">");
+      out.println("<td><h6>" + "Hue Database" + "</h6></td>");
+      out.println("<td><h6>" + "OK" + "</h6></td>");
+      out.println("</tr>");
+
+    } else {
+
+      logger.info("Hue Database connection:- Failed");
+      out.println("<tr class=\"danger\">");
+      out.println("<td><h6>" + "Hue Database" + "</h6></td>");
+      out.println("<td><h6>" + "ERROR" + "</h6></td>");
+      out.println("</tr>");
+
+    }
+
+    try {
+
+      if 
(ConfFileReader.checkNamenodeURIConnectionforambari(view.getProperties().get("namenode_URI_Ambari")))
 {
+
+        logger.info("Web hdfs Access to ambari:- Success");
+        out.println("<tr class=\"success\">");
+        out.println("<td><h6>" + "namenodeURIAmbari" + "</h6></td>");
+        out.println("<td><h6>" + "OK" + "</h6></td>");
+        out.println("</tr>");
+
+      } else {
+
+        logger.info("Web hdfs Access to ambari:- Failed");
+        out.println("<tr class=\"danger\">");
+        out.println("<td><h6>" + "namenodeURIAmbari" + "</h6></td>");
+        out.println("<td><h6>" + "ERROR" + "</h6></td>");
+        out.println("</tr>");
+
+      }
+    } catch (URISyntaxException e) {
+      logger.error("Error in accessing Webhdfs of Ambari: ", e);
+    }
+
+    try {
+      if 
(ConfFileReader.checkNamenodeURIConnectionforHue(view.getProperties().get("namenode_URI_Hue")))
 {
+
+        logger.info("Web hdfs Access to hue:- Success");
+        out.println("<tr class=\"success\">");
+        out.println("<td><h6>" + "namenodeURIHue" + "</h6></td>");
+        out.println("<td><h6>" + "OK" + "</h6></td>");
+        out.println("</tr>");
+
+      } else {
+
+        logger.info("Web hdfs Access to hue:- Failed");
+        out.println("<tr class=\"danger\">");
+        out.println("<td><h6>" + "namenodeURIHue" + "</h6></td>");
+        out.println("<td><h6>" + "ERROR" + "</h6></td>");
+        out.println("</tr>");
+
+      }
+    } catch (URISyntaxException e) {
+      logger.error("Error in accessing Webhdfs of Hue: " , e);
+    }
+
+    out.println("</tbody></table>");
+
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af9654ff/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/configurationcheck/ProgressBarStatus.java
----------------------------------------------------------------------
diff --git 
a/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/configurationcheck/ProgressBarStatus.java
 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/configurationcheck/ProgressBarStatus.java
new file mode 100644
index 0000000..40d63df
--- /dev/null
+++ 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/configurationcheck/ProgressBarStatus.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ */
+
+
+package 
org.apache.ambari.view.huetoambarimigration.controller.configurationcheck;
+
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+
+public class ProgressBarStatus extends HttpServlet {
+
+  private static final long serialVersionUID = 1L;
+
+  public static String TASK_PROGRESS_VARIABLE = "task_progress_session";
+
+
+  protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
+
+    HttpSession session = request.getSession(true);
+    Integer param = (Integer) session.getAttribute(TASK_PROGRESS_VARIABLE);
+
+    if (param == null) {
+      param = 0;
+    }
+
+    response.setContentType("text/html");
+    PrintWriter out = response.getWriter();
+    out.println(param + "%");
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af9654ff/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/hive/HiveHistoryMigration.java
----------------------------------------------------------------------
diff --git 
a/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/hive/HiveHistoryMigration.java
 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/hive/HiveHistoryMigration.java
new file mode 100755
index 0000000..46be3fe
--- /dev/null
+++ 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/hive/HiveHistoryMigration.java
@@ -0,0 +1,222 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ */
+
+
+package org.apache.ambari.view.huetoambarimigration.controller.hive;
+
+import java.beans.PropertyVetoException;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URISyntaxException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.text.ParseException;
+
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.ambari.view.ViewContext;
+import 
org.apache.ambari.view.huetoambarimigration.controller.configurationcheck.ConfigurationCheck;
+import 
org.apache.ambari.view.huetoambarimigration.controller.configurationcheck.ProgressBarStatus;
+import org.apache.log4j.Logger;
+
+import 
org.apache.ambari.view.huetoambarimigration.datasource.DataSourceAmbariDatabase;
+import 
org.apache.ambari.view.huetoambarimigration.datasource.DataSourceHueDatabase;
+import 
org.apache.ambari.view.huetoambarimigration.service.configurationcheck.ConfFileReader;
+import 
org.apache.ambari.view.huetoambarimigration.service.hive.HiveHistoryQueryImpl;
+
+public class HiveHistoryMigration extends HttpServlet {
+
+
+  private static final long serialVersionUID = 1031422249396784970L;
+  ViewContext view;
+
+  private String startDate;
+  private String endDate;
+  private String instance;
+  private String username;
+
+  @Override
+  public void init(ServletConfig config) throws ServletException {
+
+    super.init(config);
+    ServletContext context = config.getServletContext();
+    view = (ViewContext) context.getAttribute(ViewContext.CONTEXT_ATTRIBUTE);
+
+  }
+
+  public void doGet(HttpServletRequest req, HttpServletResponse resp)
+    throws ServletException, IOException {
+
+    HttpSession session = req.getSession(true);
+    final Logger logger = Logger.getLogger(HiveHistoryMigration.class);
+    Connection connectionHuedb = null;
+    Connection connectionAmbaridb = null;
+
+    /* fetching the variable from the client */
+    username = req.getParameter("username");
+    startDate = req.getParameter("startdate");
+    endDate = req.getParameter("enddate");
+    instance = req.getParameter("instance");
+
+    logger.info("--------------------------------------");
+    logger.info("Hive History query Migration started");
+    logger.info("--------------------------------------");
+    logger.info("start date: " + startDate);
+    logger.info("enddate date: " + endDate);
+    logger.info("instance is: " + username);
+    logger.info("hue username is : " + instance);
+
+    int maxCountOfAmbariDb, i = 0;
+    String time = null;
+    Long epochTime = null;
+    String dirNameforHiveHistroy;
+
+    HiveHistoryQueryImpl hiveHistoryQueryImpl = new HiveHistoryQueryImpl();// 
creating objects of HiveHistroy implementation
+
+    String[] hiveQuery = new String[1000000];
+
+    try {
+
+      connectionHuedb = 
DataSourceHueDatabase.getInstance(view.getProperties().get("huedrivername"), 
view.getProperties().get("huejdbcurl"), 
view.getProperties().get("huedbusername"), 
view.getProperties().get("huedbpassword")).getConnection();
+
+      hiveQuery = hiveHistoryQueryImpl.fetchFromHue(username, startDate, 
endDate, connectionHuedb);
+
+                  /* if No hive query selected from Hue Database according to 
our search criteria */
+
+      if (hiveQuery[i] == null) {
+
+        logger.info("No queries has been selected acccording to your 
criteria");
+        resp.setContentType("text/html");
+        PrintWriter out = resp.getWriter();
+        out.println("<br>");
+        out.println("<h4>No queries selected according to your criteria</h4>");
+
+      } else {
+        /* If Hive queries are selected based on our search criteria */
+
+        connectionAmbaridb = 
DataSourceAmbariDatabase.getInstance(view.getProperties().get("ambaridrivername"),
 view.getProperties().get("ambarijdbcurl"), 
view.getProperties().get("ambaridbusername"), 
view.getProperties().get("ambaridbpassword")).getConnection();// connecting to 
ambari db
+        connectionAmbaridb.setAutoCommit(false);
+
+        // for each queries fetched from Hue database//
+
+        for (i = 0; hiveQuery[i] != null; i++) {
+
+          float calc = ((float) (i + 1)) / hiveQuery.length * 100;
+          int progressPercentage = Math.round(calc);
+
+          session.setAttribute(ProgressBarStatus.TASK_PROGRESS_VARIABLE, 
progressPercentage);
+
+          logger.info("_____________________");
+          logger.info("Loop No." + (i + 1));
+          logger.info("_____________________");
+          logger.info("Hue query that has been fetched" + hiveQuery[i]);
+          int id = 0;
+
+          id = 
hiveHistoryQueryImpl.fetchInstanceTablename(view.getProperties().get("ambaridrivername"),
 connectionAmbaridb, instance); // feching table name according to the given 
instance name
+
+          logger.info("Table name has been fetched from intance name");
+
+          hiveHistoryQueryImpl.writetoFileQueryhql(hiveQuery[i], 
ConfFileReader.getHomeDir());// writing to .hql file to a temp file on local 
disk
+
+          logger.info(".hql file created in Temp directory");
+
+          hiveHistoryQueryImpl.writetoFileLogs(ConfFileReader.getHomeDir());// 
writing to logs file to a temp file on local disk
+
+          logger.info("Log file created in Temp directory");
+
+          maxCountOfAmbariDb = 
(hiveHistoryQueryImpl.fetchMaximumIdfromAmbaridb(view.getProperties().get("ambaridrivername"),
 connectionAmbaridb, id) + 1);// fetching the maximum count for ambari db to 
insert
+
+          time = hiveHistoryQueryImpl.getTime();// getting the system current 
time.
+
+          epochTime = hiveHistoryQueryImpl.getEpochTime();// getting system 
time as epoch format
+
+          dirNameforHiveHistroy = "/user/admin/hive/jobs/hive-job-" + 
maxCountOfAmbariDb + "-" + time + "/";// creating the directory name
+
+          logger.info("Directory name where .hql will be saved: " + 
dirNameforHiveHistroy);
+
+          
hiveHistoryQueryImpl.insertRowinAmbaridb(view.getProperties().get("ambaridrivername"),
 dirNameforHiveHistroy, maxCountOfAmbariDb, epochTime, connectionAmbaridb, id, 
instance, i);// inserting in ambari database
+
+          if (view.getProperties().get("KerberoseEnabled").equals("y")) {
+
+            logger.info("kerberose enabled");
+            
hiveHistoryQueryImpl.createDirKerberorisedSecured(dirNameforHiveHistroy, 
view.getProperties().get("namenode_URI_Ambari"));// creating directory in 
kerborized secured hdfs
+            logger.info("Directory created in hdfs");
+            
hiveHistoryQueryImpl.putFileinHdfsKerborizedSecured(ConfFileReader.getHomeDir() 
+ "query.hql", dirNameforHiveHistroy, 
view.getProperties().get("namenode_URI_Ambari"));// copying the .hql file to 
kerborized hdfs
+            
hiveHistoryQueryImpl.putFileinHdfsKerborizedSecured(ConfFileReader.getHomeDir() 
+ "logs", dirNameforHiveHistroy, 
view.getProperties().get("namenode_URI_Ambari"));// copying the log file to 
kerborized hdfs
+          } else {
+
+            logger.info("kerberose not enabled");
+            hiveHistoryQueryImpl.createDir(dirNameforHiveHistroy, 
view.getProperties().get("namenode_URI_Ambari"));// creating directory in hdfs
+            logger.info("Directory created in hdfs");
+            hiveHistoryQueryImpl.putFileinHdfs(ConfFileReader.getHomeDir() + 
"query.hql", dirNameforHiveHistroy, 
view.getProperties().get("namenode_URI_Ambari"));// copying the .hql file to 
hdfs
+            hiveHistoryQueryImpl.putFileinHdfs(ConfFileReader.getHomeDir() + 
"logs", dirNameforHiveHistroy, 
view.getProperties().get("namenode_URI_Ambari"));// copying the log file to hdfs
+          }
+
+        }
+        connectionAmbaridb.commit();
+
+      }
+    } catch (SQLException e) {
+      logger.error("Sql exception in ambari database: ", e);
+      try {
+        connectionAmbaridb.rollback();
+        logger.error("Sql statement are Rolledback");
+      } catch (SQLException e1) {
+        logger.error("Sql rollback exception in ambari database",
+          e1);
+      }
+    } catch (ClassNotFoundException e) {
+      logger.error("Class not found :- " ,e);
+    } catch (ParseException e) {
+      logger.error("Parse Exception : " ,e);
+    } catch (URISyntaxException e) {
+      logger.error("URI Syntax Exception: " ,e);
+    } catch (PropertyVetoException e) {
+      logger.error("PropertyVetoException: " ,e);
+    } finally {
+      if (connectionAmbaridb != null) try {
+        connectionAmbaridb.close();
+      } catch (SQLException e) {
+        logger.error("Exception in closing the connection :" ,e);
+      }
+    }
+    //deleteing the temprary files that are created while execution
+    hiveHistoryQueryImpl.deleteFileQueryhql(ConfFileReader.getHomeDir());
+    hiveHistoryQueryImpl.deleteFileQueryLogs(ConfFileReader.getHomeDir());
+
+    session.setAttribute(ProgressBarStatus.TASK_PROGRESS_VARIABLE, 0);
+    logger.info("------------------------------");
+    logger.info("Hive History query Migration Ends");
+    logger.info("------------------------------");
+
+    /* servlet returned to client */
+    resp.setContentType("text/html");
+    PrintWriter out = resp.getWriter();
+    out.println("<br>");
+    out.println("<h4>" + i + " Query has been migrated to  " + instance + 
"</h4>");
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af9654ff/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/hive/HiveSavedQueryMigration.java
----------------------------------------------------------------------
diff --git 
a/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/hive/HiveSavedQueryMigration.java
 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/hive/HiveSavedQueryMigration.java
new file mode 100644
index 0000000..d873744
--- /dev/null
+++ 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/hive/HiveSavedQueryMigration.java
@@ -0,0 +1,231 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ */
+
+
+package org.apache.ambari.view.huetoambarimigration.controller.hive;
+
+import java.beans.PropertyVetoException;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URISyntaxException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.text.ParseException;
+import java.util.ArrayList;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+import org.apache.ambari.view.ViewContext;
+import 
org.apache.ambari.view.huetoambarimigration.controller.configurationcheck.ProgressBarStatus;
+import org.apache.log4j.Logger;
+
+import 
org.apache.ambari.view.huetoambarimigration.datasource.DataSourceAmbariDatabase;
+import 
org.apache.ambari.view.huetoambarimigration.datasource.DataSourceHueDatabase;
+import org.apache.ambari.view.huetoambarimigration.model.*;
+import 
org.apache.ambari.view.huetoambarimigration.service.configurationcheck.ConfFileReader;
+import 
org.apache.ambari.view.huetoambarimigration.service.hive.HiveSavedQueryImpl;
+
+public class HiveSavedQueryMigration extends HttpServlet {
+
+  private static final long serialVersionUID = 1031422249396784970L;
+
+  ViewContext view;
+  private String startDate;
+  private String endDate;
+  private String instance;
+  private String userName;
+
+  @Override
+  public void init(ServletConfig config) throws ServletException {
+    super.init(config);
+    ServletContext context = config.getServletContext();
+    view = (ViewContext) context.getAttribute(ViewContext.CONTEXT_ATTRIBUTE);
+  }
+
+  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws 
ServletException, IOException {
+
+    HttpSession session = req.getSession(true);
+    final Logger logger = Logger.getLogger(HiveSavedQueryMigration.class);
+
+    Connection connectionAmbaridb = null;
+    Connection connectionHuedb = null;
+
+    /* fetching from servlet */
+    userName = req.getParameter("username");
+    startDate = req.getParameter("startdate");
+    endDate = req.getParameter("enddate");
+    instance = req.getParameter("instance");
+
+    int i = 0;
+
+    logger.info("-------------------------------------");
+    logger.info("Hive saved query Migration started");
+    logger.info("-------------------------------------");
+    logger.info("start date: " + startDate);
+    logger.info("enddate date: " + endDate);
+    logger.info("instance is: " + instance);
+    logger.info("hue username is : " + userName);
+
+    HiveSavedQueryImpl hivesavedqueryimpl = new HiveSavedQueryImpl();/* 
creating Implementation object  */
+
+    int maxcountForHivehistroryAmbaridb, maxCountforSavequeryAmbaridb;
+    String time = null;
+    Long epochtime = null;
+    String dirNameforHiveSavedquery;
+    ArrayList<PojoHive> dbpojoHiveSavedQuery = new ArrayList<PojoHive>();
+
+    try {
+
+      connectionHuedb = 
DataSourceHueDatabase.getInstance(view.getProperties().get("huedrivername"), 
view.getProperties().get("huejdbcurl"), 
view.getProperties().get("huedbusername"), 
view.getProperties().get("huedbpassword")).getConnection(); /* fetching 
connection to hue DB */
+
+      dbpojoHiveSavedQuery = hivesavedqueryimpl.fetchFromHuedb(userName, 
startDate, endDate, connectionHuedb); /* fetching data from hue db and storing 
it in to a model */
+
+      if (dbpojoHiveSavedQuery.size() == 0) /* if no data has been fetched 
from hue db according to search criteria */ {
+
+        logger.info("no Hive saved query has been selected from hue according 
to your criteria of searching");
+        resp.setContentType("text/html");
+        PrintWriter out = resp.getWriter();
+        out.println("<br>");
+        out.println("<h4>No queries selected according to your criteria</h4>");
+
+      } else {
+
+        connectionAmbaridb = 
DataSourceAmbariDatabase.getInstance(view.getProperties().get("ambaridrivername"),
 view.getProperties().get("ambarijdbcurl"), 
view.getProperties().get("ambaridbusername"), 
view.getProperties().get("ambaridbpassword")).getConnection();/* connecting to 
ambari DB */
+        connectionAmbaridb.setAutoCommit(false);
+
+        for (i = 0; i < dbpojoHiveSavedQuery.size(); i++) {
+
+          logger.info("_____________________");
+          logger.info("Loop No." + (i + 1));
+          logger.info("_____________________");
+
+          float calc = ((float) (i + 1)) / dbpojoHiveSavedQuery.size() * 100;
+          int progressPercentage = Math.round(calc);
+
+          session.setAttribute(ProgressBarStatus.TASK_PROGRESS_VARIABLE, 
progressPercentage);
+
+          logger.info("query fetched from hue:-  " + 
dbpojoHiveSavedQuery.get(i).getQuery());
+
+          int tableIdSavedQuery = 
hivesavedqueryimpl.fetchInstancetablenameForSavedqueryHive(view.getProperties().get("ambaridrivername"),
 connectionAmbaridb, instance); /* fetching the instance table name for hive 
saved query  from the given instance name */
+
+          int tableIdHistoryHive = 
hivesavedqueryimpl.fetchInstanceTablenameHiveHistory(view.getProperties().get("ambaridrivername"),
 connectionAmbaridb, instance); /* fetching the instance table name for hive 
history query from the given instance name */
+
+          logger.info("Table name are fetched from instance name.");
+
+          
hivesavedqueryimpl.writetoFilequeryHql(dbpojoHiveSavedQuery.get(i).getQuery(), 
ConfFileReader.getHomeDir()); /* writing hive query to a local file*/
+
+          hivesavedqueryimpl.writetoFileLogs(ConfFileReader.getHomeDir());/* 
writing logs to localfile */
+
+          logger.info(".hql and logs file are saved in temporary directory");
+
+          maxcountForHivehistroryAmbaridb = 
(hivesavedqueryimpl.fetchMaxdsidFromHiveHistory(view.getProperties().get("ambaridrivername"),
 connectionAmbaridb, tableIdHistoryHive) + 1);/* fetching the maximum ds_id 
from hive history table*/
+
+          maxCountforSavequeryAmbaridb = 
(hivesavedqueryimpl.fetchMaxidforSavedQueryHive(view.getProperties().get("ambaridrivername"),
 connectionAmbaridb, tableIdSavedQuery) + 1);/* fetching the maximum ds_id from 
hive saved query table*/
+
+          time = hivesavedqueryimpl.getTime();/* getting system time */
+
+          epochtime = hivesavedqueryimpl.getEpochTime();/* getting epoch time 
*/
+
+
+          dirNameforHiveSavedquery = "/user/admin/hive/jobs/hive-job-" + 
maxcountForHivehistroryAmbaridb + "-"
+            + time + "/"; // creating hdfs directory name
+
+          logger.info("Directory will be creted in HDFS" + 
dirNameforHiveSavedquery);
+
+
+          
hivesavedqueryimpl.insertRowHiveHistory(view.getProperties().get("ambaridrivername"),
 dirNameforHiveSavedquery, maxcountForHivehistroryAmbaridb, epochtime, 
connectionAmbaridb, tableIdHistoryHive, instance, i);// inserting to hive 
history table
+
+          logger.info("Row inserted in Hive History table.");
+
+          if (view.getProperties().get("KerberoseEnabled").equals("y")) {
+
+            logger.info("Kerberose Enabled");
+            hivesavedqueryimpl.createDirHiveSecured(dirNameforHiveSavedquery, 
view.getProperties().get("namenode_URI_Ambari"));// creating directory in hdfs 
in kerborized cluster
+            
hivesavedqueryimpl.putFileinHdfsSecured(ConfFileReader.getHomeDir() + 
"query.hql", dirNameforHiveSavedquery, 
view.getProperties().get("namenode_URI_Ambari"));// putting .hql file in hdfs 
in kerberoroized cluster
+            
hivesavedqueryimpl.putFileinHdfsSecured(ConfFileReader.getHomeDir() + "logs", 
dirNameforHiveSavedquery, view.getProperties().get("namenode_URI_Ambari"));// 
putting logs file in hdfs in kerberoroized cluster
+
+          } else {
+
+            logger.info("Kerberose Not Enabled");
+            hivesavedqueryimpl.createDirHive(dirNameforHiveSavedquery, 
view.getProperties().get("namenode_URI_Ambari"));// creating directory in hdfs
+            hivesavedqueryimpl.putFileinHdfs(ConfFileReader.getHomeDir() + 
"query.hql", dirNameforHiveSavedquery, 
view.getProperties().get("namenode_URI_Ambari"));// putting .hql file in hdfs 
directory
+            hivesavedqueryimpl.putFileinHdfs(ConfFileReader.getHomeDir() + 
"logs", dirNameforHiveSavedquery, 
view.getProperties().get("namenode_URI_Ambari"));// putting logs file in hdfs
+          }
+
+          //inserting into hived saved query table
+          
hivesavedqueryimpl.insertRowinSavedQuery(view.getProperties().get("ambaridrivername"),
 maxCountforSavequeryAmbaridb, dbpojoHiveSavedQuery.get(i).getDatabase(), 
dirNameforHiveSavedquery, dbpojoHiveSavedQuery.get(i).getQuery(), 
dbpojoHiveSavedQuery.get(i).getOwner(), connectionAmbaridb, tableIdSavedQuery, 
instance, i);
+
+        }
+        connectionAmbaridb.commit();
+
+      }
+
+
+    } catch (SQLException e) {
+
+      logger.error("SQL exception: ", e);
+      try {
+        connectionAmbaridb.rollback();
+        logger.info("roll back done");
+      } catch (SQLException e1) {
+        logger.error("Rollback error: ", e1);
+
+      }
+    } catch (ClassNotFoundException e1) {
+      logger.error("Class not found : " , e1);
+    } catch (ParseException e) {
+      logger.error("ParseException: " , e);
+    } catch (URISyntaxException e) {
+      logger.error("URISyntaxException: " , e);
+    } catch (PropertyVetoException e) {
+      logger.error("PropertyVetoException:" , e);
+    } finally {
+      if (null != connectionAmbaridb)
+        try {
+          connectionAmbaridb.close();
+        } catch (SQLException e) {
+          logger.error("Error in connection close", e);
+        }
+    }
+
+
+    hivesavedqueryimpl.deleteFileQueryhql(ConfFileReader.getHomeDir());
+    hivesavedqueryimpl.deleteFileQueryLogs(ConfFileReader.getHomeDir());
+    session.setAttribute(ProgressBarStatus.TASK_PROGRESS_VARIABLE, 0);
+
+    logger.info("-------------------------------");
+    logger.info("Hive saved query Migration end");
+    logger.info("--------------------------------");
+
+    resp.setContentType("text/html");
+    PrintWriter out = resp.getWriter();
+    out.println("<br>");
+    out.println("<h4>" + i + " Saved query has been migrated to  " + instance 
+ "</h4>");
+  }
+}
+
+
+
+

http://git-wip-us.apache.org/repos/asf/ambari/blob/af9654ff/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/pig/PigJobMigration.java
----------------------------------------------------------------------
diff --git 
a/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/pig/PigJobMigration.java
 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/pig/PigJobMigration.java
new file mode 100644
index 0000000..4b6afdb
--- /dev/null
+++ 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/pig/PigJobMigration.java
@@ -0,0 +1,201 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ */
+
+
+package org.apache.ambari.view.huetoambarimigration.controller.pig;
+
+import java.beans.PropertyVetoException;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URISyntaxException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.ambari.view.ViewContext;
+import 
org.apache.ambari.view.huetoambarimigration.controller.configurationcheck.ProgressBarStatus;
+import org.apache.log4j.Logger;
+
+import 
org.apache.ambari.view.huetoambarimigration.datasource.DataSourceAmbariDatabase;
+import 
org.apache.ambari.view.huetoambarimigration.datasource.DataSourceHueDatabase;
+import org.apache.ambari.view.huetoambarimigration.service.*;
+import org.apache.ambari.view.huetoambarimigration.model.*;
+import 
org.apache.ambari.view.huetoambarimigration.service.configurationcheck.ConfFileReader;
+import org.apache.ambari.view.huetoambarimigration.service.pig.PigJobImpl;
+
+public class PigJobMigration extends HttpServlet {
+
+  private static final long serialVersionUID = 1031422249396784970L;
+  ViewContext view;
+  int i = 0;
+  private String userName;
+  private String startDate;
+  private String endDate;
+  private String instance;
+
+  @Override
+  public void init(ServletConfig config) throws ServletException {
+
+    super.init(config);
+    ServletContext context = config.getServletContext();
+    view = (ViewContext) context.getAttribute(ViewContext.CONTEXT_ATTRIBUTE);
+
+  }
+
+  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws 
ServletException, IOException {
+
+    HttpSession session = req.getSession(true);
+    final Logger logger = Logger.getLogger(PigJobMigration.class);
+    Connection connectionHuedb = null;
+    Connection connectionAmbaridb = null;
+
+    // fetchinf data from the clients
+    userName = req.getParameter("username");
+    startDate = req.getParameter("startdate");
+    endDate = req.getParameter("enddate");
+    instance = req.getParameter("instance");
+
+    logger.info("------------------------------");
+    logger.info("Pig Jobs Migration started");
+    logger.info("------------------------------");
+    logger.info("start date: " + startDate);
+    logger.info("enddate date: " + endDate);
+    logger.info("instance is: " + userName);
+    logger.info("hue username is : " + instance);
+
+    PigJobImpl pigjobimpl = new PigJobImpl();// creating the implementation 
object
+    int maxCountforPigScript = 0;
+
+    String time = null, timeIndorder = null;
+    Long epochtime = null;
+    String pigJobDirName;
+    ArrayList<PojoPig> pigJobDbPojo = new ArrayList<PojoPig>();
+
+    try {
+
+      connectionHuedb = 
DataSourceHueDatabase.getInstance(view.getProperties().get("huedrivername"), 
view.getProperties().get("huejdbcurl"), 
view.getProperties().get("huedbusername"), 
view.getProperties().get("huedbpassword")).getConnection();//connecting to hue 
database
+      pigJobDbPojo = pigjobimpl.fetchFromHueDB(userName, startDate, endDate, 
connectionHuedb);// fetching the PigJobs details from hue
+
+                       /*No Pig Job details has been fetched accordring to 
search criteria*/
+      if (pigJobDbPojo.size() == 0) {
+
+        logger.info("no Pig Job has been selected from hue according to your 
criteria of searching");
+        resp.setContentType("text/html");
+        PrintWriter out = resp.getWriter();
+        out.println("<br>");
+        out.println("<h4>No Pig Job  selected according to your 
criteria</h4>");
+
+      } else {
+
+        connectionAmbaridb = 
DataSourceAmbariDatabase.getInstance(view.getProperties().get("ambaridrivername"),
 view.getProperties().get("ambarijdbcurl"), 
view.getProperties().get("ambaridbusername"), 
view.getProperties().get("ambaridbpassword")).getConnection();
+        connectionAmbaridb.setAutoCommit(false);
+
+        for (i = 0; i < pigJobDbPojo.size(); i++) {
+
+          float calc = ((float) (i + 1)) / pigJobDbPojo.size() * 100;
+          int progressPercentage = Math.round(calc);
+
+          session.setAttribute(ProgressBarStatus.TASK_PROGRESS_VARIABLE, 
progressPercentage);
+
+          logger.info("Loop No." + (i + 1));
+          logger.info("________________");
+          logger.info("the title of script " + pigJobDbPojo.get(i).getTitle());
+
+          int fetchPigTablenameInstance = 
pigjobimpl.fetchInstanceTablename(view.getProperties().get("ambaridrivername"), 
connectionAmbaridb, instance);
+          maxCountforPigScript = 
(pigjobimpl.fetchMaxIdforPigJob(view.getProperties().get("ambaridrivername"), 
connectionAmbaridb, fetchPigTablenameInstance) + 1);
+
+          time = pigjobimpl.getTime();
+          timeIndorder = pigjobimpl.getTimeInorder();
+          epochtime = pigjobimpl.getEpochTime();
+
+          pigJobDirName = "/user/admin/pig/jobs/" + 
pigJobDbPojo.get(i).getTitle() + "_" + time + "/";
+
+          
pigjobimpl.insertRowPigJob(view.getProperties().get("ambaridrivername"), 
pigJobDirName, maxCountforPigScript, time, timeIndorder, epochtime, 
pigJobDbPojo.get(i).getTitle(), connectionAmbaridb, fetchPigTablenameInstance, 
pigJobDbPojo.get(i).getStatus(), instance, i);
+
+          if (view.getProperties().get("KerberoseEnabled").equals("y")) {
+
+            pigjobimpl.createDirPigJobSecured(pigJobDirName, 
view.getProperties().get("namenode_URI_Ambari"));
+            pigjobimpl.copyFileBetweenHdfsSecured(pigJobDbPojo.get(i).getDir() 
+ "/script.pig", pigJobDirName, 
view.getProperties().get("namenode_URI_Ambari"), 
view.getProperties().get("namenode_URI_Hue"));
+            pigjobimpl.copyFileBetweenHdfsSecured(pigJobDbPojo.get(i).getDir() 
+ "/stderr", pigJobDirName, view.getProperties().get("namenode_URI_Ambari"), 
view.getProperties().get("namenode_URI_Hue"));
+            pigjobimpl.copyFileBetweenHdfsSecured(pigJobDbPojo.get(i).getDir() 
+ "/stdout", pigJobDirName, view.getProperties().get("namenode_URI_Ambari"), 
view.getProperties().get("namenode_URI_Hue"));
+
+          } else {
+
+            pigjobimpl.createDirPigJob(pigJobDirName, 
view.getProperties().get("namenode_URI_Ambari"));
+            pigjobimpl.copyFileBetweenHdfs(pigJobDbPojo.get(i).getDir() + 
"/script.pig", pigJobDirName, view.getProperties().get("namenode_URI_Ambari"), 
view.getProperties().get("namenode_URI_Hue"));
+            pigjobimpl.copyFileBetweenHdfs(pigJobDbPojo.get(i).getDir() + 
"/stderr", pigJobDirName, view.getProperties().get("namenode_URI_Ambari"), 
view.getProperties().get("namenode_URI_Hue"));
+            pigjobimpl.copyFileBetweenHdfs(pigJobDbPojo.get(i).getDir() + 
"/stdout", pigJobDirName, view.getProperties().get("namenode_URI_Ambari"), 
view.getProperties().get("namenode_URI_Hue"));
+
+          }
+
+          logger.info(pigJobDbPojo.get(i).getTitle() + "has been migrated to 
Ambari");
+
+        }
+        connectionAmbaridb.commit();
+      }
+
+    } catch (SQLException e) {
+      logger.error("sql exception in ambari database:", e);
+      try {
+        connectionAmbaridb.rollback();
+        logger.info("roll back done");
+      } catch (SQLException e1) {
+        logger.error("roll back  exception:",e1);
+      }
+    } catch (ClassNotFoundException e2) {
+      logger.error("class not found exception:",e2);
+    } catch (ParseException e) {
+      logger.error("ParseException: " ,e);
+    } catch (URISyntaxException e) {
+      logger.error("URISyntaxException" ,e);
+    } catch (PropertyVetoException e) {
+      logger.error("PropertyVetoException" ,e);
+    } finally {
+      if (null != connectionAmbaridb)
+        try {
+          connectionAmbaridb.close();
+        } catch (SQLException e) {
+          logger.error("connection closing exception ", e);
+        }
+    }
+
+    logger.info("------------------------------");
+    logger.info("Pig Job Migration End");
+    logger.info("------------------------------");
+
+    session.setAttribute(ProgressBarStatus.TASK_PROGRESS_VARIABLE, 0);
+    resp.setContentType("text/html");
+    PrintWriter out = resp.getWriter();
+    out.println("<br>");
+    out.println("<h4>" + i + " Pig jobs has been migrated to  "
+      + instance + "</h4>");
+  }
+
+}
+

http://git-wip-us.apache.org/repos/asf/ambari/blob/af9654ff/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/pig/PigScriptMigration.java
----------------------------------------------------------------------
diff --git 
a/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/pig/PigScriptMigration.java
 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/pig/PigScriptMigration.java
new file mode 100644
index 0000000..bb803f3
--- /dev/null
+++ 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/pig/PigScriptMigration.java
@@ -0,0 +1,208 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ */
+
+
+package org.apache.ambari.view.huetoambarimigration.controller.pig;
+
+import java.beans.PropertyVetoException;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.text.ParseException;
+import java.util.ArrayList;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.ambari.view.ViewContext;
+import 
org.apache.ambari.view.huetoambarimigration.controller.configurationcheck.ProgressBarStatus;
+import org.apache.log4j.Logger;
+
+import 
org.apache.ambari.view.huetoambarimigration.datasource.DataSourceAmbariDatabase;
+import 
org.apache.ambari.view.huetoambarimigration.datasource.DataSourceHueDatabase;
+import org.apache.ambari.view.huetoambarimigration.model.*;
+import 
org.apache.ambari.view.huetoambarimigration.service.configurationcheck.ConfFileReader;
+import org.apache.ambari.view.huetoambarimigration.service.pig.PigScriptImpl;
+
+public class PigScriptMigration extends HttpServlet {
+
+
+  private static final long serialVersionUID = 1031422249396784970L;
+  ViewContext view;
+  private String startDate;
+  private String endDate;
+  private String instance;
+  private String userName;
+
+  @Override
+  public void init(ServletConfig config) throws ServletException {
+
+    super.init(config);
+    ServletContext context = config.getServletContext();
+    view = (ViewContext) context.getAttribute(ViewContext.CONTEXT_ATTRIBUTE);
+
+  }
+
+  public void doGet(HttpServletRequest req, HttpServletResponse resp)
+    throws ServletException, IOException {
+
+    HttpSession session = req.getSession(true);
+    final Logger logger = Logger.getLogger(PigScriptMigration.class);
+    Connection connectionHuedb = null;
+    Connection connectionAmbaridb = null;
+
+    logger.info("-------------------------------------");
+    logger.info("Pig saved script Migration started");
+    logger.info("-------------------------------------");
+
+    //fethcing data from client
+
+    userName = req.getParameter("username");
+    startDate = req.getParameter("startdate");
+    endDate = req.getParameter("enddate");
+    instance = req.getParameter("instance");
+    int i = 0;
+
+    logger.info("start date: " + startDate);
+    logger.info("enddate date: " + endDate);
+    logger.info("instance is: " + userName);
+    logger.info("hue username is : " + instance);
+
+    //Reading the configuration file
+    PigScriptImpl pigsavedscriptmigration = new PigScriptImpl();
+
+    int maxcountforsavequery = 0, maxcountforpigsavedscript;
+    String time = null, timetobeInorder = null;
+    Long epochTime = null;
+    String dirNameForPigScript, completeDirandFilePath, pigscriptFilename="";
+    int pigInstanceTableName;
+
+    ArrayList<PojoPig> dbpojoPigSavedscript = new ArrayList<PojoPig>();
+
+    try {
+      connectionHuedb = 
DataSourceHueDatabase.getInstance(view.getProperties().get("huedrivername"), 
view.getProperties().get("huejdbcurl"), 
view.getProperties().get("huedbusername"), 
view.getProperties().get("huedbpassword")).getConnection();//connection to Hue 
DB
+      dbpojoPigSavedscript = 
pigsavedscriptmigration.fetchFromHueDatabase(userName, startDate, endDate, 
connectionHuedb, view.getProperties().get("huedrivername"));// Fetching Pig 
script details from Hue DB
+
+      /* If No Pig Script has been fetched from Hue db according to our search 
criteria*/
+      if (dbpojoPigSavedscript.size() == 0) {
+
+        logger.info("no Pig script has been selected from hue according to 
your criteria of searching");
+        resp.setContentType("text/html");
+        PrintWriter out = resp.getWriter();
+        out.println("<br>");
+        out.println("<h4>No Pig Script selected according to your 
criteria</h4>");
+
+      } else {
+
+        connectionAmbaridb = 
DataSourceAmbariDatabase.getInstance(view.getProperties().get("ambaridrivername"),
 view.getProperties().get("ambarijdbcurl"), 
view.getProperties().get("ambaridbusername"), 
view.getProperties().get("ambaridbpassword")).getConnection();// connecting to 
ambari db
+        connectionAmbaridb.setAutoCommit(false);
+        logger.info("loop will continue for " + dbpojoPigSavedscript.size() + 
"times");
+
+        //for each pig script found in Hue Database
+
+        for (i = 0; i < dbpojoPigSavedscript.size(); i++) {
+
+
+          float calc = ((float) (i + 1)) / dbpojoPigSavedscript.size() * 100;
+          int progressPercentage = Math.round(calc);
+
+          session.setAttribute(ProgressBarStatus.TASK_PROGRESS_VARIABLE, 
progressPercentage);
+
+          logger.info("Loop No." + (i + 1));
+          logger.info("________________");
+          logger.info("the title of script:  " + 
dbpojoPigSavedscript.get(i).getTitle());
+
+          pigInstanceTableName = 
pigsavedscriptmigration.fetchInstanceTablenamePigScript(view.getProperties().get("ambaridrivername"),
 connectionAmbaridb, instance);// finding the table name in ambari from the 
given instance
+
+          maxcountforpigsavedscript = 
(pigsavedscriptmigration.fetchmaxIdforPigSavedScript(view.getProperties().get("ambaridrivername"),
 connectionAmbaridb, pigInstanceTableName) + 1);// maximum count of the primary 
key of Pig Script table
+
+          time = pigsavedscriptmigration.getTime();
+
+          timetobeInorder = pigsavedscriptmigration.getTimeInorder();
+
+          epochTime = pigsavedscriptmigration.getEpochTime();
+
+          dirNameForPigScript = "/user/admin/pig/scripts/";
+
+          pigscriptFilename = dbpojoPigSavedscript.get(i).getTitle() + "-" + 
time + ".pig";
+
+          completeDirandFilePath = dirNameForPigScript + pigscriptFilename;
+
+          
pigsavedscriptmigration.writetPigScripttoLocalFile(dbpojoPigSavedscript.get(i).getScript(),
 dbpojoPigSavedscript.get(i).getTitle(), dbpojoPigSavedscript.get(i).getDt(), 
ConfFileReader.getHomeDir(), pigscriptFilename);
+
+          
pigsavedscriptmigration.insertRowForPigScript(view.getProperties().get("ambaridrivername"),
 completeDirandFilePath, maxcountforsavequery, maxcountforpigsavedscript, time, 
timetobeInorder, epochTime, dbpojoPigSavedscript.get(i).getTitle(), 
connectionAmbaridb, pigInstanceTableName, instance, i);
+
+          if (view.getProperties().get("KerberoseEnabled").equals("y")) {
+            
pigsavedscriptmigration.putFileinHdfsSecured(ConfFileReader.getHomeDir() + 
pigscriptFilename, dirNameForPigScript, 
view.getProperties().get("namenode_URI_Ambari"));
+          } else {
+            pigsavedscriptmigration.putFileinHdfs(ConfFileReader.getHomeDir() 
+ pigscriptFilename, dirNameForPigScript, 
view.getProperties().get("namenode_URI_Ambari"));
+          }
+
+          logger.info(dbpojoPigSavedscript.get(i).getTitle() + "Migrated to 
Ambari");
+
+          
pigsavedscriptmigration.deletePigScriptLocalFile(ConfFileReader.getHomeDir(), 
pigscriptFilename);
+
+        }
+        connectionAmbaridb.commit();
+
+      }
+
+
+    } catch (SQLException e) {
+      logger.error("Sql exception in ambari database", e);
+      try {
+        connectionAmbaridb.rollback();
+        logger.info("rollback done");
+      } catch (SQLException e1) {
+        logger.error("Sql exception while doing roll back", e);
+      }
+    } catch (ClassNotFoundException e2) {
+      logger.error("class not found exception", e2);
+    } catch (ParseException e) {
+      logger.error("ParseException: " , e);
+    } catch (PropertyVetoException e) {
+      logger.error("PropertyVetoException: " , e);
+    } finally {
+      if (null != connectionAmbaridb)
+        try {
+          connectionAmbaridb.close();
+        } catch (SQLException e) {
+          logger.error("connection close exception: ", e);
+        }
+    }
+
+    session.setAttribute(ProgressBarStatus.TASK_PROGRESS_VARIABLE, 0);
+
+    resp.setContentType("text/html");
+    PrintWriter out = resp.getWriter();
+    out.println("<br>");
+    out.println("<h4>" + i + " Pig Script has been migrated to " + instance + 
"</h4>");
+
+    logger.info("----------------------------------");
+    logger.info("Pig saved script Migration ends");
+    logger.info("----------------------------------");
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af9654ff/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/revertchange/RevertChange.java
----------------------------------------------------------------------
diff --git 
a/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/revertchange/RevertChange.java
 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/revertchange/RevertChange.java
new file mode 100644
index 0000000..2fff19a
--- /dev/null
+++ 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/controller/revertchange/RevertChange.java
@@ -0,0 +1,217 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ */
+
+package org.apache.ambari.view.huetoambarimigration.controller.revertchange;
+
+import java.beans.PropertyVetoException;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URISyntaxException;
+import java.security.PrivilegedExceptionAction;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.ambari.view.ViewContext;
+import 
org.apache.ambari.view.huetoambarimigration.controller.configurationcheck.ProgressBarStatus;
+import org.apache.log4j.Logger;
+import org.jdom.Attribute;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.security.UserGroupInformation;
+
+import 
org.apache.ambari.view.huetoambarimigration.datasource.DataSourceAmbariDatabase;
+import 
org.apache.ambari.view.huetoambarimigration.service.configurationcheck.ConfFileReader;
+
+
+public class RevertChange extends HttpServlet {
+
+  private static final long serialVersionUID = 1L;
+  ViewContext view;
+
+  @Override
+  public void init(ServletConfig config) throws ServletException {
+
+    super.init(config);
+    ServletContext context = config.getServletContext();
+    view = (ViewContext) context.getAttribute(ViewContext.CONTEXT_ATTRIBUTE);
+  }
+
+  public boolean stringtoDatecompare(String datefromservlet,
+                                     String datefromfile) throws 
ParseException {
+
+    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
+    Date date1 = formatter.parse(datefromservlet);
+    Date date2 = formatter.parse(datefromfile);
+    if (date1.compareTo(date2) < 0) {
+      return true;
+    } else {
+      return false;
+    }
+
+  }
+
+  public void removedir(final String dir, final String namenodeuri)
+    throws IOException, URISyntaxException {
+
+    try {
+      UserGroupInformation ugi = UserGroupInformation
+        .createRemoteUser("hdfs");
+
+      ugi.doAs(new PrivilegedExceptionAction<Void>() {
+
+        public Void run() throws Exception {
+
+          Configuration conf = new Configuration();
+          conf.set("fs.hdfs.impl",
+            org.apache.hadoop.hdfs.DistributedFileSystem.class
+              .getName());
+          conf.set("fs.file.impl",
+            org.apache.hadoop.fs.LocalFileSystem.class
+              .getName());
+          conf.set("fs.defaultFS", namenodeuri);
+          conf.set("hadoop.job.ugi", "hdfs");
+
+          FileSystem fs = FileSystem.get(conf);
+          Path src = new Path(dir);
+          fs.delete(src, true);
+          return null;
+        }
+      });
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+  }
+
+  protected void doGet(HttpServletRequest request,
+                       HttpServletResponse response) throws ServletException, 
IOException {
+
+    final Logger logger = Logger.getLogger(RevertChange.class);
+
+    logger.info("------------------------------");
+    logger.info("Reverting the changes Start:");
+    logger.info("------------------------------");
+
+    HttpSession session = request.getSession(true);
+    String revertDate = request.getParameter("revertdate");
+    String instance = request.getParameter("instance");
+
+    logger.info("Revert Date " + revertDate);
+    logger.info("instance name " + instance);
+
+    BufferedReader br = null;
+    Connection connectionAmbariDatabase = null;
+
+    try {
+      connectionAmbariDatabase = 
DataSourceAmbariDatabase.getInstance(view.getProperties().get("ambaridrivername"),
 view.getProperties().get("ambarijdbcurl"), 
view.getProperties().get("ambaridbusername"), 
view.getProperties().get("ambaridbpassword")).getConnection();
+      connectionAmbariDatabase.setAutoCommit(false);
+
+      Statement stmt = null;
+      stmt = connectionAmbariDatabase.createStatement();
+      SAXBuilder builder = new SAXBuilder();
+      File xmlFile = new File(ConfFileReader.getHomeDir() + 
"RevertChange.xml");
+      try {
+
+        Document document = (Document) builder.build(xmlFile);
+        Element rootNode = document.getRootElement();
+        List list = rootNode.getChildren("RevertRecord");
+
+        for (int i = 0; i < list.size(); i++) {
+
+          float calc = ((float) (i + 1)) / list.size() * 100;
+          int progressPercentage = Math.round(calc);
+          session.setAttribute(ProgressBarStatus.TASK_PROGRESS_VARIABLE, 
progressPercentage);
+
+          Element node = (Element) list.get(i);
+
+          if (node.getChildText("instance").equals(instance)) {
+
+            if (stringtoDatecompare(revertDate, 
node.getChildText("datetime").toString())) {
+
+              String sql = node.getChildText("query");
+              logger.info(sql);
+              stmt.executeUpdate(sql);
+              removedir(node.getChildText("dirname").toString(), 
view.getProperties().get("namenode_URI_Ambari"));
+              logger.info(node.getChildText("dirname").toString()+" deleted");
+
+            }
+
+          }
+
+        }
+
+        connectionAmbariDatabase.commit();
+
+        response.setContentType("text/html");
+        PrintWriter out = response.getWriter();
+        out.println("<br>");
+        out.println("<h4>" + " The change has been revert back for "
+          + instance + "</h4>");
+
+        session.setAttribute(ProgressBarStatus.TASK_PROGRESS_VARIABLE, 0);
+
+        logger.info("------------------------------");
+        logger.info("Reverting the changes End");
+        logger.info("------------------------------");
+
+      } catch (IOException e) {
+        logger.error("IOException: ",e);
+      } catch (ParseException e) {
+        logger.error("ParseException: ",e);
+      } catch (JDOMException e) {
+        logger.error("JDOMException: ",e);
+      } catch (URISyntaxException e) {
+        logger.error("URISyntaxException:  ",e);
+      }
+    } catch (SQLException e1) {
+      logger.error("SqlException  ",e1);
+      try {
+        connectionAmbariDatabase.rollback();
+        logger.info("Rollback done");
+      } catch (SQLException e2) {
+        logger.error("SqlException in Rollback  ",e2);
+      }
+    } catch (PropertyVetoException e) {
+      logger.error("PropertyVetoException: ",e);
+    }
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af9654ff/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/datasource/DataSourceAmbariDatabase.java
----------------------------------------------------------------------
diff --git 
a/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/datasource/DataSourceAmbariDatabase.java
 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/datasource/DataSourceAmbariDatabase.java
new file mode 100644
index 0000000..034c4c6
--- /dev/null
+++ 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/datasource/DataSourceAmbariDatabase.java
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ */
+
+package org.apache.ambari.view.huetoambarimigration.datasource;
+
+import 
org.apache.ambari.view.huetoambarimigration.controller.configurationcheck.ConfigurationCheck;
+import 
org.apache.ambari.view.huetoambarimigration.service.configurationcheck.ConfFileReader;
+import com.mchange.v2.c3p0.ComboPooledDataSource;
+
+import java.beans.PropertyVetoException;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+public class DataSourceAmbariDatabase {
+
+  private static DataSourceAmbariDatabase datasource;
+  private ComboPooledDataSource cpds;
+
+  private DataSourceAmbariDatabase(String ambaridatabasedriver, String 
ambarijdbcurl, String ambaridatabaseusename, String ambaridatabasepassword) 
throws IOException, SQLException, PropertyVetoException {
+
+    cpds = new ComboPooledDataSource();
+    cpds.setDriverClass(ambaridatabasedriver); //loads the jdbc driver
+    cpds.setJdbcUrl(ambarijdbcurl);
+    cpds.setUser(ambaridatabaseusename);
+    cpds.setPassword(ambaridatabasepassword);
+
+    // the settings below are optional -- c3p0 can work with defaults
+    cpds.setMinPoolSize(10);
+    cpds.setAcquireIncrement(10);
+    cpds.setMaxPoolSize(20);
+    cpds.setMaxStatements(180);
+
+  }
+
+  public static DataSourceAmbariDatabase getInstance(String ambariDbDriver, 
String ambariDBjadbcURL, String ambaridbUsername, String ambariDBPasswd) throws 
IOException, SQLException, PropertyVetoException {
+    if (datasource == null) {
+      datasource = new DataSourceAmbariDatabase(ambariDbDriver, 
ambariDBjadbcURL, ambaridbUsername, ambariDBPasswd);
+      return datasource;
+    } else {
+      return datasource;
+    }
+  }
+
+  public Connection getConnection() throws SQLException {
+    return this.cpds.getConnection();
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af9654ff/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/datasource/DataSourceHueDatabase.java
----------------------------------------------------------------------
diff --git 
a/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/datasource/DataSourceHueDatabase.java
 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/datasource/DataSourceHueDatabase.java
new file mode 100644
index 0000000..6e40308
--- /dev/null
+++ 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/datasource/DataSourceHueDatabase.java
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ */
+
+package org.apache.ambari.view.huetoambarimigration.datasource;
+
+import 
org.apache.ambari.view.huetoambarimigration.controller.configurationcheck.ConfigurationCheck;
+import 
org.apache.ambari.view.huetoambarimigration.service.configurationcheck.ConfFileReader;
+import com.mchange.v2.c3p0.ComboPooledDataSource;
+
+import java.beans.PropertyVetoException;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+public class DataSourceHueDatabase {
+
+  private static DataSourceHueDatabase datasource;
+
+  private ComboPooledDataSource cpdshue;
+
+  private DataSourceHueDatabase(String huejdbcurlhue, String huejdbcurl, 
String huedbUsername, String huedbPassword) throws IOException, SQLException, 
PropertyVetoException {
+    cpdshue = new ComboPooledDataSource();
+    cpdshue.setDriverClass(huejdbcurlhue); //loads the jdbc driver
+    cpdshue.setJdbcUrl(huejdbcurl);
+    cpdshue.setUser(huedbUsername);
+    cpdshue.setPassword(huedbPassword);
+    // the settings below are optional -- c3p0 can work with defaults
+    cpdshue.setMinPoolSize(10);
+    cpdshue.setAcquireIncrement(10);
+    cpdshue.setMaxPoolSize(20);
+    cpdshue.setMaxStatements(180);
+
+  }
+
+  public static DataSourceHueDatabase getInstance(String hueDrivername, String 
hueJdbcurl, String huedbUsername, String huedbPassword) throws IOException, 
SQLException, PropertyVetoException {
+    if (datasource == null) {
+      datasource = new DataSourceHueDatabase(hueDrivername, hueJdbcurl, 
huedbUsername, huedbPassword);
+      return datasource;
+    } else {
+      return datasource;
+    }
+  }
+
+  public Connection getConnection() throws SQLException {
+    return this.cpdshue.getConnection();
+  }
+
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/af9654ff/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/model/PojoHive.java
----------------------------------------------------------------------
diff --git 
a/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/model/PojoHive.java
 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/model/PojoHive.java
new file mode 100644
index 0000000..f8d731d
--- /dev/null
+++ 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/model/PojoHive.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ */
+
+package org.apache.ambari.view.huetoambarimigration.model;
+
+public class PojoHive {
+
+  private String database;
+  private String owner;
+  private String query;
+
+  public String getDatabase() {
+    return database;
+  }
+
+  public void setDatabase(String database) {
+    this.database = database;
+  }
+
+  public String getOwner() {
+    return owner;
+  }
+
+  public void setOwner(String owner) {
+    this.owner = owner;
+  }
+
+  public String getQuery() {
+    return query;
+  }
+
+  public void setQuery(String query) {
+    this.query = query;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af9654ff/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/model/PojoPig.java
----------------------------------------------------------------------
diff --git 
a/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/model/PojoPig.java
 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/model/PojoPig.java
new file mode 100644
index 0000000..05d0da9
--- /dev/null
+++ 
b/contrib/views/hueambarimigration/src/main/java/org/apache/ambari/view/huetoambarimigration/model/PojoPig.java
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ */
+
+package org.apache.ambari.view.huetoambarimigration.model;
+
+import java.util.Date;
+
+public class PojoPig {
+
+  private Date dt;
+  private String script;
+  private String Status;
+  private String title;
+  private String dir;
+
+  public Date getDt() {
+    return dt;
+  }
+
+  public void setDt(Date dt) {
+    this.dt = dt;
+  }
+
+  public String getScript() {
+    return script;
+  }
+
+  public void setScript(String script) {
+    this.script = script;
+  }
+
+  public String getStatus() {
+    return Status;
+  }
+
+  public void setStatus(String status) {
+    Status = status;
+  }
+
+  public String getTitle() {
+    return title;
+  }
+
+  public void setTitle(String title) {
+    this.title = title;
+  }
+
+  public String getDir() {
+    return dir;
+  }
+
+  public void setDir(String dir) {
+    this.dir = dir;
+  }
+
+
+}

Reply via email to