You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by al...@apache.org on 2015/03/12 20:31:28 UTC

[3/6] ambari git commit: AMBARI-10035. Hive View: Retrieve history from ATS (alexantonenko)

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobImpl.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobImpl.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobImpl.java
new file mode 100644
index 0000000..1858b3e
--- /dev/null
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobImpl.java
@@ -0,0 +1,226 @@
+/**
+ * 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.
+ */
+
+package org.apache.ambari.view.hive.resources.jobs.viewJobs;
+
+import org.apache.commons.beanutils.PropertyUtils;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Map;
+
+/**
+ * Bean to represent saved query
+ */
+public class JobImpl implements Job {
+  private String title = null;
+  private String queryFile = null;
+  private String statusDir = null;
+  private Long dateSubmitted = 0L;
+  private Long duration = 0L;
+  private String status = JOB_STATE_UNKNOWN;
+  private String forcedContent = null;
+  private String dataBase = null;
+  private String queryId = null;
+
+  private String applicationId;
+  private String dagName;
+
+  private String id = null;
+  private String owner = null;
+
+  private String logFile;
+  private String confFile;
+
+  public JobImpl() {}
+  public JobImpl(Map<String, Object> stringObjectMap) throws InvocationTargetException, IllegalAccessException {
+    for (Map.Entry<String, Object> entry : stringObjectMap.entrySet())  {
+      try {
+        PropertyUtils.setProperty(this, entry.getKey(), entry.getValue());
+      } catch (NoSuchMethodException e) {
+        //do nothing, skip
+      }
+    }
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof Job)) return false;
+
+    JobImpl job = (JobImpl) o;
+
+    if (id != null ? !id.equals(job.id) : job.id != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return id != null ? id.hashCode() : 0;
+  }
+
+  @Override
+  public String getId() {
+    return id;
+  }
+
+  @Override
+  public void setId(String id) {
+    this.id = id;
+  }
+
+  @Override
+  public String getOwner() {
+    return owner;
+  }
+
+  @Override
+  public void setOwner(String owner) {
+    this.owner = owner;
+  }
+
+  @Override
+  public String getTitle() {
+    return title;
+  }
+
+  @Override
+  public void setTitle(String title) {
+    this.title = title;
+  }
+
+  @Override
+  public String getQueryFile() {
+    return queryFile;
+  }
+
+  @Override
+  public void setQueryFile(String queryFile) {
+    this.queryFile = queryFile;
+  }
+
+  @Override
+  public Long getDateSubmitted() {
+    return dateSubmitted;
+  }
+
+  @Override
+  public void setDateSubmitted(Long dateSubmitted) {
+    this.dateSubmitted = dateSubmitted;
+  }
+
+  @Override
+  public Long getDuration() {
+    return duration;
+  }
+
+  @Override
+  public void setDuration(Long duration) {
+    this.duration = duration;
+  }
+
+  @Override
+  public String getStatus() {
+    return status;
+  }
+
+  @Override
+  public void setStatus(String status) {
+    this.status = status;
+  }
+
+  @Override
+  public String getForcedContent() {
+    return forcedContent;
+  }
+
+  @Override
+  public void setForcedContent(String forcedContent) {
+    this.forcedContent = forcedContent;
+  }
+
+  @Override
+  public String getQueryId() {
+    return queryId;
+  }
+
+  @Override
+  public void setQueryId(String queryId) {
+    this.queryId = queryId;
+  }
+
+  @Override
+  public String getStatusDir() {
+    return statusDir;
+  }
+
+  @Override
+  public void setStatusDir(String statusDir) {
+    this.statusDir = statusDir;
+  }
+
+  @Override
+  public String getDataBase() {
+    return dataBase;
+  }
+
+  @Override
+  public void setDataBase(String dataBase) {
+    this.dataBase = dataBase;
+  }
+
+  @Override
+  public String getLogFile() {
+    return logFile;
+  }
+
+  @Override
+  public void setLogFile(String logFile) {
+    this.logFile = logFile;
+  }
+
+  @Override
+  public String getConfFile() {
+    return confFile;
+  }
+
+  @Override
+  public void setConfFile(String confFile) {
+    this.confFile = confFile;
+  }
+
+  @Override
+  public String getApplicationId() {
+    return applicationId;
+  }
+
+  @Override
+  public void setApplicationId(String applicationId) {
+    this.applicationId = applicationId;
+  }
+
+  @Override
+  public String getDagName() {
+    return dagName;
+  }
+
+  @Override
+  public void setDagName(String DagName) {
+    this.dagName = DagName;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobResourceManager.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobResourceManager.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobResourceManager.java
new file mode 100644
index 0000000..101e328
--- /dev/null
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobResourceManager.java
@@ -0,0 +1,107 @@
+/**
+ * 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.
+ */
+
+package org.apache.ambari.view.hive.resources.jobs.viewJobs;
+
+import org.apache.ambari.view.ViewContext;
+import org.apache.ambari.view.hive.client.*;
+import org.apache.ambari.view.hive.persistence.utils.FilteringStrategy;
+import org.apache.ambari.view.hive.persistence.utils.ItemNotFound;
+import org.apache.ambari.view.hive.resources.PersonalCRUDResourceManager;
+import org.apache.ambari.view.hive.utils.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+
+/**
+ * Object that provides CRUD operations for query objects
+ */
+public class JobResourceManager extends PersonalCRUDResourceManager<Job> {
+  private final static Logger LOG =
+      LoggerFactory.getLogger(JobResourceManager.class);
+
+  private IJobControllerFactory jobControllerFactory;
+
+  /**
+   * Constructor
+   * @param context View Context instance
+   */
+  public JobResourceManager(SharedObjectsFactory sharedObjectsFactory, ViewContext context) {
+    super(JobImpl.class, sharedObjectsFactory, context);
+    jobControllerFactory = sharedObjectsFactory.getJobControllerFactory();
+  }
+
+  @Override
+  public Job create(Job object) {
+    super.create(object);
+    JobController jobController = jobControllerFactory.createControllerForJob(object);
+
+    try {
+
+      jobController.afterCreation();
+      saveIfModified(jobController);
+
+    } catch (ServiceFormattedException e) {
+      cleanupAfterErrorAndThrowAgain(object, e);
+    }
+
+    return object;
+  }
+
+  public void saveIfModified(JobController jobController) {
+    if (jobController.isModified()) {
+      save(jobController.getJobPOJO());
+      jobController.clearModified();
+    }
+  }
+
+
+  @Override
+  public Job read(Object id) throws ItemNotFound {
+    Job job = super.read(id);
+    JobController jobController =  jobControllerFactory.createControllerForJob(job);
+    jobController.update();
+    saveIfModified(jobController);
+    return job;
+  }
+
+  @Override
+  public List<Job> readAll(FilteringStrategy filteringStrategy) {
+    return super.readAll(filteringStrategy);
+  }
+
+  @Override
+  public void delete(Object resourceId) throws ItemNotFound {
+    super.delete(resourceId);
+  }
+
+  public JobController readController(Object id) throws ItemNotFound {
+    Job job = read(id);
+    return jobControllerFactory.createControllerForJob(job);
+  }
+
+  public Cursor getJobResultsCursor(Job job) {
+    try {
+      JobController jobController = jobControllerFactory.createControllerForJob(job);
+      return jobController.getResults();
+    } catch (ItemNotFound itemNotFound) {
+      throw new NotFoundFormattedException("Job results are expired", null);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceItem.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceItem.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceItem.java
index ddd9990..c7ed078 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceItem.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceItem.java
@@ -32,7 +32,7 @@ public class FileResourceItem implements Serializable, PersonalResource {
   private String name;
   private String path;
 
-  private Integer id;
+  private String id;
   private String owner;
 
   public FileResourceItem() {}
@@ -41,12 +41,12 @@ public class FileResourceItem implements Serializable, PersonalResource {
   }
 
   @Override
-  public Integer getId() {
+  public String getId() {
     return id;
   }
 
   @Override
-  public void setId(Integer id) {
+  public void setId(String id) {
     this.id = id;
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceManager.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceManager.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceManager.java
index 31d9e23..822ae3c 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceManager.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceManager.java
@@ -19,6 +19,7 @@
 package org.apache.ambari.view.hive.resources.resources;
 
 import org.apache.ambari.view.ViewContext;
+import org.apache.ambari.view.hive.persistence.IStorageFactory;
 import org.apache.ambari.view.hive.persistence.utils.FilteringStrategy;
 import org.apache.ambari.view.hive.persistence.utils.ItemNotFound;
 import org.apache.ambari.view.hive.resources.PersonalCRUDResourceManager;
@@ -38,8 +39,8 @@ public class FileResourceResourceManager extends PersonalCRUDResourceManager<Fil
    * Constructor
    * @param context View Context instance
    */
-  public FileResourceResourceManager(ViewContext context) {
-    super(FileResourceItem.class, context);
+  public FileResourceResourceManager(IStorageFactory storageFactory, ViewContext context) {
+    super(FileResourceItem.class, storageFactory, context);
   }
 
   @Override
@@ -48,12 +49,12 @@ public class FileResourceResourceManager extends PersonalCRUDResourceManager<Fil
   }
 
   @Override
-  public FileResourceItem read(Integer id) throws ItemNotFound {
+  public FileResourceItem read(Object id) throws ItemNotFound {
     return super.read(id);
   }
 
   @Override
-  public void delete(Integer resourceId) throws ItemNotFound {
+  public void delete(Object resourceId) throws ItemNotFound {
     super.delete(resourceId);
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceProvider.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceProvider.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceProvider.java
index 5b9fc65..76b77dd 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceProvider.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceProvider.java
@@ -22,7 +22,7 @@ import com.google.inject.Inject;
 import org.apache.ambari.view.*;
 import org.apache.ambari.view.hive.persistence.utils.ItemNotFound;
 import org.apache.ambari.view.hive.persistence.utils.OnlyOwnersFilteringStrategy;
-import org.apache.ambari.view.hive.resources.PersonalCRUDResourceManager;
+import org.apache.ambari.view.hive.utils.SharedObjectsFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -44,7 +44,7 @@ public class FileResourceResourceProvider implements ResourceProvider<FileResour
 
   protected synchronized FileResourceResourceManager getResourceManager() {
     if (resourceManager == null) {
-      resourceManager = new FileResourceResourceManager(context);
+      resourceManager = new FileResourceResourceManager(new SharedObjectsFactory(context), context);
     }
     return resourceManager;
   }
@@ -52,7 +52,7 @@ public class FileResourceResourceProvider implements ResourceProvider<FileResour
   @Override
   public FileResourceItem getResource(String resourceId, Set<String> properties) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
     try {
-      return getResourceManager().read(Integer.valueOf(resourceId));
+      return getResourceManager().read(resourceId);
     } catch (ItemNotFound itemNotFound) {
       throw new NoSuchResourceException(resourceId);
     }
@@ -88,7 +88,7 @@ public class FileResourceResourceProvider implements ResourceProvider<FileResour
       throw new SystemException("error on updating resource", e);
     }
     try {
-      getResourceManager().update(item, Integer.valueOf(resourceId));
+      getResourceManager().update(item, resourceId);
     } catch (ItemNotFound itemNotFound) {
       throw new NoSuchResourceException(resourceId);
     }
@@ -98,7 +98,7 @@ public class FileResourceResourceProvider implements ResourceProvider<FileResour
   @Override
   public boolean deleteResource(String resourceId) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
     try {
-      getResourceManager().delete(Integer.valueOf(resourceId));
+      getResourceManager().delete(resourceId);
     } catch (ItemNotFound itemNotFound) {
       throw new NoSuchResourceException(resourceId);
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceService.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceService.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceService.java
index 2993280..222cf03 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceService.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceService.java
@@ -57,7 +57,7 @@ public class FileResourceService extends BaseService {
 
   protected synchronized FileResourceResourceManager getResourceManager() {
     if (resourceManager == null) {
-      resourceManager = new FileResourceResourceManager(context);
+      resourceManager = new FileResourceResourceManager(getSharedObjectsFactory(), context);
     }
     return resourceManager;
   }
@@ -70,10 +70,9 @@ public class FileResourceService extends BaseService {
   @Produces(MediaType.APPLICATION_JSON)
   public Response getOne(@PathParam("id") String id) {
     try {
-      FileResourceItem FileResourceItem = null;
-      FileResourceItem = getResourceManager().read(Integer.valueOf(id));
+      FileResourceItem fileResourceItem = getResourceManager().read(id);
       JSONObject object = new JSONObject();
-      object.put("fileResource", FileResourceItem);
+      object.put("fileResource", fileResourceItem);
       return Response.ok(object).build();
     } catch (WebApplicationException ex) {
       throw ex;
@@ -91,7 +90,7 @@ public class FileResourceService extends BaseService {
   @Path("{id}")
   public Response delete(@PathParam("id") String id) {
     try {
-      getResourceManager().delete(Integer.valueOf(id));
+      getResourceManager().delete(id);
       return Response.status(204).build();
     } catch (WebApplicationException ex) {
       throw ex;
@@ -132,7 +131,7 @@ public class FileResourceService extends BaseService {
   public Response update(ResourceRequest request,
                          @PathParam("id") String id) {
     try {
-      getResourceManager().update(request.fileResource, Integer.valueOf(id));
+      getResourceManager().update(request.fileResource, id);
       return Response.status(204).build();
     } catch (WebApplicationException ex) {
       throw ex;

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQuery.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQuery.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQuery.java
index fd75714..25a7748 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQuery.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQuery.java
@@ -34,7 +34,7 @@ public class SavedQuery implements Serializable, PersonalResource {
   private String title;
   private String shortQuery;
 
-  private Integer id;
+  private String id;
   private String owner;
 
   public SavedQuery() {}
@@ -43,12 +43,12 @@ public class SavedQuery implements Serializable, PersonalResource {
   }
 
   @Override
-  public Integer getId() {
+  public String getId() {
     return id;
   }
 
   @Override
-  public void setId(Integer id) {
+  public void setId(String id) {
     this.id = id;
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceManager.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceManager.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceManager.java
index a3c0f1b..c032bb1 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceManager.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceManager.java
@@ -19,6 +19,7 @@
 package org.apache.ambari.view.hive.resources.savedQueries;
 
 import org.apache.ambari.view.ViewContext;
+import org.apache.ambari.view.hive.persistence.IStorageFactory;
 import org.apache.ambari.view.hive.persistence.utils.FilteringStrategy;
 import org.apache.ambari.view.hive.persistence.utils.ItemNotFound;
 import org.apache.ambari.view.hive.resources.PersonalCRUDResourceManager;
@@ -41,23 +42,15 @@ public class SavedQueryResourceManager extends PersonalCRUDResourceManager<Saved
   private final static Logger LOG =
       LoggerFactory.getLogger(SavedQueryResourceManager.class);
 
+  private SharedObjectsFactory sharedObjectsFactory;
+
   /**
    * Constructor
    * @param context View Context instance
    */
-  private SavedQueryResourceManager(ViewContext context) {
-    super(SavedQuery.class, context);
-  }
-
-  //TODO: move all context-singletones to ContextController or smth like that
-  private static Map<String, SavedQueryResourceManager> viewSingletonObjects = new HashMap<String, SavedQueryResourceManager>();
-  public static SavedQueryResourceManager getInstance(ViewContext context) {
-    if (!viewSingletonObjects.containsKey(context.getInstanceName()))
-      viewSingletonObjects.put(context.getInstanceName(), new SavedQueryResourceManager(context));
-    return viewSingletonObjects.get(context.getInstanceName());
-  }
-  static Map<String, SavedQueryResourceManager> getViewSingletonObjects() {
-    return viewSingletonObjects;
+  public SavedQueryResourceManager(ViewContext context, SharedObjectsFactory sharedObjectsFactory) {
+    super(SavedQuery.class, sharedObjectsFactory, context);
+    this.sharedObjectsFactory = sharedObjectsFactory;
   }
 
   @Override
@@ -83,20 +76,20 @@ public class SavedQueryResourceManager extends PersonalCRUDResourceManager<Saved
       throw new MisconfigurationFormattedException("scripts.dir");
     }
 
-    String normalizedName = String.format("hive-query-%d", object.getId());
+    String normalizedName = String.format("hive-query-%s", object.getId());
     String timestamp = new SimpleDateFormat("yyyy-MM-dd_hh-mm").format(new Date());
     String baseFileName = String.format(userScriptsPath +
         "/%s-%s", normalizedName, timestamp);
 
-    String newFilePath = HdfsUtil.findUnallocatedFileName(context, baseFileName, ".hql");
-    HdfsUtil.putStringToFile(context, newFilePath, "");
+    String newFilePath = HdfsUtil.findUnallocatedFileName(sharedObjectsFactory.getHdfsApi(), baseFileName, ".hql");
+    HdfsUtil.putStringToFile(sharedObjectsFactory.getHdfsApi(), newFilePath, "");
 
     object.setQueryFile(newFilePath);
-    getStorage().store(SavedQuery.class, object);
+    storageFabric.getStorage().store(SavedQuery.class, object);
   }
 
   @Override
-  public SavedQuery read(Integer id) throws ItemNotFound {
+  public SavedQuery read(Object id) throws ItemNotFound {
     SavedQuery savedQuery = super.read(id);
     fillShortQueryField(savedQuery);
     return savedQuery;
@@ -104,7 +97,7 @@ public class SavedQueryResourceManager extends PersonalCRUDResourceManager<Saved
 
   private void fillShortQueryField(SavedQuery savedQuery) {
     if (savedQuery.getQueryFile() != null) {
-      FilePaginator paginator = new FilePaginator(savedQuery.getQueryFile(), context);
+      FilePaginator paginator = new FilePaginator(savedQuery.getQueryFile(), sharedObjectsFactory.getHdfsApi());
       String query = null;
       try {
         query = paginator.readPage(0);
@@ -117,7 +110,14 @@ public class SavedQueryResourceManager extends PersonalCRUDResourceManager<Saved
       }
       savedQuery.setShortQuery(query.substring(0, (query.length() > 42)?42:query.length()));
     }
-    getStorage().store(SavedQuery.class, savedQuery);
+    storageFabric.getStorage().store(SavedQuery.class, savedQuery);
+  }
+
+  @Override
+  public SavedQuery update(SavedQuery newObject, String id) throws ItemNotFound {
+    SavedQuery savedQuery = super.update(newObject, id);
+    fillShortQueryField(savedQuery);
+    return savedQuery;
   }
 
   @Override
@@ -126,7 +126,7 @@ public class SavedQueryResourceManager extends PersonalCRUDResourceManager<Saved
   }
 
   @Override
-  public void delete(Integer resourceId) throws ItemNotFound {
+  public void delete(Object resourceId) throws ItemNotFound {
     super.delete(resourceId);
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceProvider.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceProvider.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceProvider.java
index 20df9e6..a5561aa 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceProvider.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceProvider.java
@@ -22,7 +22,7 @@ import com.google.inject.Inject;
 import org.apache.ambari.view.*;
 import org.apache.ambari.view.hive.persistence.utils.ItemNotFound;
 import org.apache.ambari.view.hive.persistence.utils.OnlyOwnersFilteringStrategy;
-import org.apache.ambari.view.hive.resources.PersonalCRUDResourceManager;
+import org.apache.ambari.view.hive.utils.SharedObjectsFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -38,18 +38,24 @@ public class SavedQueryResourceProvider implements ResourceProvider<SavedQuery>
   @Inject
   ViewContext context;
 
-  protected SavedQueryResourceManager resourceManager = null;
   protected final static Logger LOG =
       LoggerFactory.getLogger(SavedQueryResourceProvider.class);
+  private SharedObjectsFactory sharedObjectsFactory;
+
+  public SharedObjectsFactory getSharedObjectsFactory() {
+    if (sharedObjectsFactory == null)
+      sharedObjectsFactory = new SharedObjectsFactory(context);
+    return sharedObjectsFactory;
+  }
 
   protected synchronized SavedQueryResourceManager getResourceManager() {
-    return SavedQueryResourceManager.getInstance(context);
+    return getSharedObjectsFactory().getSavedQueryResourceManager();
   }
 
   @Override
   public SavedQuery getResource(String resourceId, Set<String> properties) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
     try {
-      return getResourceManager().read(Integer.valueOf(resourceId));
+      return getResourceManager().read(resourceId);
     } catch (ItemNotFound itemNotFound) {
       throw new NoSuchResourceException(resourceId);
     }
@@ -85,7 +91,7 @@ public class SavedQueryResourceProvider implements ResourceProvider<SavedQuery>
       throw new SystemException("error on updating resource", e);
     }
     try {
-      getResourceManager().update(item, Integer.valueOf(resourceId));
+      getResourceManager().update(item, resourceId);
     } catch (ItemNotFound itemNotFound) {
       throw new NoSuchResourceException(resourceId);
     }
@@ -95,7 +101,7 @@ public class SavedQueryResourceProvider implements ResourceProvider<SavedQuery>
   @Override
   public boolean deleteResource(String resourceId) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
     try {
-      getResourceManager().delete(Integer.valueOf(resourceId));
+      getResourceManager().delete(resourceId);
     } catch (ItemNotFound itemNotFound) {
       throw new NoSuchResourceException(resourceId);
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryService.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryService.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryService.java
index f6d5f41..338457a 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryService.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryService.java
@@ -23,7 +23,6 @@ import org.apache.ambari.view.ViewResourceHandler;
 import org.apache.ambari.view.hive.BaseService;
 import org.apache.ambari.view.hive.persistence.utils.ItemNotFound;
 import org.apache.ambari.view.hive.persistence.utils.OnlyOwnersFilteringStrategy;
-import org.apache.ambari.view.hive.resources.PersonalCRUDResourceManager;
 import org.apache.ambari.view.hive.utils.NotFoundFormattedException;
 import org.apache.ambari.view.hive.utils.ServiceFormattedException;
 import org.json.simple.JSONObject;
@@ -58,7 +57,7 @@ public class SavedQueryService extends BaseService {
       LoggerFactory.getLogger(SavedQueryService.class);
 
   protected synchronized SavedQueryResourceManager getResourceManager() {
-    return SavedQueryResourceManager.getInstance(context);
+    return getSharedObjectsFactory().getSavedQueryResourceManager();
   }
 
   protected void setResourceManager(SavedQueryResourceManager resourceManager) {
@@ -73,8 +72,7 @@ public class SavedQueryService extends BaseService {
   @Produces(MediaType.APPLICATION_JSON)
   public Response getOne(@PathParam("queryId") String queryId) {
     try {
-      SavedQuery savedQuery = null;
-      savedQuery = getResourceManager().read(Integer.valueOf(queryId));
+      SavedQuery savedQuery = getResourceManager().read(queryId);
       JSONObject object = new JSONObject();
       object.put("savedQuery", savedQuery);
       return Response.ok(object).build();
@@ -94,7 +92,7 @@ public class SavedQueryService extends BaseService {
   @Path("{queryId}")
   public Response delete(@PathParam("queryId") String queryId) {
     try {
-      getResourceManager().delete(Integer.valueOf(queryId));
+      getResourceManager().delete(queryId);
       return Response.status(204).build();
     } catch (WebApplicationException ex) {
       throw ex;
@@ -135,7 +133,7 @@ public class SavedQueryService extends BaseService {
   public Response update(SavedQueryRequest request,
                          @PathParam("queryId") String queryId) {
     try {
-      getResourceManager().update(request.savedQuery, Integer.valueOf(queryId));
+      getResourceManager().update(request.savedQuery, queryId);
       return Response.status(204).build();
     } catch (WebApplicationException ex) {
       throw ex;

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDF.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDF.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDF.java
index 4a58e38..2dafcf4 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDF.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDF.java
@@ -33,7 +33,7 @@ public class UDF implements Serializable, PersonalResource {
   private String classname;
   private Integer fileResource;
 
-  private Integer id;
+  private String id;
   private String owner;
 
   public UDF() {}
@@ -42,12 +42,12 @@ public class UDF implements Serializable, PersonalResource {
   }
 
   @Override
-  public Integer getId() {
+  public String getId() {
     return id;
   }
 
   @Override
-  public void setId(Integer id) {
+  public void setId(String id) {
     this.id = id;
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceManager.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceManager.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceManager.java
index cb4264f..98a21b3 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceManager.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceManager.java
@@ -19,6 +19,7 @@
 package org.apache.ambari.view.hive.resources.udfs;
 
 import org.apache.ambari.view.ViewContext;
+import org.apache.ambari.view.hive.persistence.IStorageFactory;
 import org.apache.ambari.view.hive.persistence.utils.FilteringStrategy;
 import org.apache.ambari.view.hive.persistence.utils.ItemNotFound;
 import org.apache.ambari.view.hive.resources.PersonalCRUDResourceManager;
@@ -38,12 +39,12 @@ public class UDFResourceManager extends PersonalCRUDResourceManager<UDF> {
    * Constructor
    * @param context View Context instance
    */
-  public UDFResourceManager(ViewContext context) {
-    super(UDF.class, context);
+  public UDFResourceManager(IStorageFactory storageFactory, ViewContext context) {
+    super(UDF.class, storageFactory, context);
   }
 
   @Override
-  public UDF read(Integer id) throws ItemNotFound {
+  public UDF read(Object id) throws ItemNotFound {
     return super.read(id);
   }
 
@@ -58,7 +59,7 @@ public class UDFResourceManager extends PersonalCRUDResourceManager<UDF> {
   }
 
   @Override
-  public void delete(Integer resourceId) throws ItemNotFound {
+  public void delete(Object resourceId) throws ItemNotFound {
     super.delete(resourceId);
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceProvider.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceProvider.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceProvider.java
index 70994eb..4117678 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceProvider.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceProvider.java
@@ -22,7 +22,7 @@ import com.google.inject.Inject;
 import org.apache.ambari.view.*;
 import org.apache.ambari.view.hive.persistence.utils.ItemNotFound;
 import org.apache.ambari.view.hive.persistence.utils.OnlyOwnersFilteringStrategy;
-import org.apache.ambari.view.hive.resources.PersonalCRUDResourceManager;
+import org.apache.ambari.view.hive.utils.SharedObjectsFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -42,9 +42,10 @@ public class UDFResourceProvider implements ResourceProvider<UDF> {
   protected final static Logger LOG =
       LoggerFactory.getLogger(UDFResourceProvider.class);
 
+
   protected synchronized UDFResourceManager getResourceManager() {
     if (resourceManager == null) {
-      resourceManager = new UDFResourceManager(context);
+      resourceManager = new UDFResourceManager(new SharedObjectsFactory(context), context);
     }
     return resourceManager;
   }
@@ -52,7 +53,7 @@ public class UDFResourceProvider implements ResourceProvider<UDF> {
   @Override
   public UDF getResource(String resourceId, Set<String> properties) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
     try {
-      return getResourceManager().read(Integer.valueOf(resourceId));
+      return getResourceManager().read(resourceId);
     } catch (ItemNotFound itemNotFound) {
       throw new NoSuchResourceException(resourceId);
     }
@@ -88,7 +89,7 @@ public class UDFResourceProvider implements ResourceProvider<UDF> {
       throw new SystemException("error on updating resource", e);
     }
     try {
-      getResourceManager().update(item, Integer.valueOf(resourceId));
+      getResourceManager().update(item, resourceId);
     } catch (ItemNotFound itemNotFound) {
       throw new NoSuchResourceException(resourceId);
     }
@@ -98,7 +99,7 @@ public class UDFResourceProvider implements ResourceProvider<UDF> {
   @Override
   public boolean deleteResource(String resourceId) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
     try {
-      getResourceManager().delete(Integer.valueOf(resourceId));
+      getResourceManager().delete(resourceId);
     } catch (ItemNotFound itemNotFound) {
       throw new NoSuchResourceException(resourceId);
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFService.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFService.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFService.java
index 864d5b0..aa170c9 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFService.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFService.java
@@ -23,8 +23,6 @@ import org.apache.ambari.view.ViewResourceHandler;
 import org.apache.ambari.view.hive.BaseService;
 import org.apache.ambari.view.hive.persistence.utils.ItemNotFound;
 import org.apache.ambari.view.hive.persistence.utils.OnlyOwnersFilteringStrategy;
-import org.apache.ambari.view.hive.resources.PersonalCRUDResourceManager;
-import org.apache.ambari.view.hive.resources.resources.FileResourceItem;
 import org.apache.ambari.view.hive.resources.resources.FileResourceResourceManager;
 import org.apache.ambari.view.hive.utils.NotFoundFormattedException;
 import org.apache.ambari.view.hive.utils.ServiceFormattedException;
@@ -61,14 +59,14 @@ public class UDFService extends BaseService {
 
   protected synchronized UDFResourceManager getResourceManager() {
     if (resourceManager == null) {
-      resourceManager = new UDFResourceManager(context);
+      resourceManager = new UDFResourceManager(getSharedObjectsFactory(), context);
     }
     return resourceManager;
   }
 
   protected synchronized FileResourceResourceManager getFileResourceResourceManager() {
     if (fileResourceResourceManager == null) {
-      fileResourceResourceManager = new FileResourceResourceManager(context);
+      fileResourceResourceManager = new FileResourceResourceManager(getSharedObjectsFactory(), context);
     }
     return fileResourceResourceManager;
   }
@@ -81,10 +79,9 @@ public class UDFService extends BaseService {
   @Produces(MediaType.APPLICATION_JSON)
   public Response getOne(@PathParam("id") String id) {
     try {
-      UDF UDF = null;
-      UDF = getResourceManager().read(Integer.valueOf(id));
+      UDF udf = getResourceManager().read(id);
       JSONObject object = new JSONObject();
-      object.put("udf", UDF);
+      object.put("udf", udf);
       return Response.ok(object).build();
     } catch (WebApplicationException ex) {
       throw ex;
@@ -102,7 +99,7 @@ public class UDFService extends BaseService {
   @Path("{id}")
   public Response delete(@PathParam("id") String id) {
     try {
-      getResourceManager().delete(Integer.valueOf(id));
+      getResourceManager().delete(id);
       return Response.status(204).build();
     } catch (WebApplicationException ex) {
       throw ex;
@@ -145,7 +142,7 @@ public class UDFService extends BaseService {
     try {
       if (request.udf.getFileResource() != null)
         getFileResourceResourceManager().read(request.udf.getFileResource());
-      getResourceManager().update(request.udf, Integer.valueOf(id));
+      getResourceManager().update(request.udf, id);
       return Response.status(204).build();
     } catch (WebApplicationException ex) {
       throw ex;

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/FilePaginator.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/FilePaginator.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/FilePaginator.java
index f27e1f9..6282fc9 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/FilePaginator.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/FilePaginator.java
@@ -40,11 +40,11 @@ public class FilePaginator {
   /**
    * Constructor
    * @param filePath Path to file on HDFS
-   * @param context View Context instance
+   * @param hdfsApi hdfs api
    */
-  public FilePaginator(String filePath, ViewContext context) {
+  public FilePaginator(String filePath, HdfsApi hdfsApi) {
     this.filePath = filePath;
-    hdfsApi = HdfsApi.getInstance(context);
+    this.hdfsApi = hdfsApi;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/HdfsApi.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/HdfsApi.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/HdfsApi.java
index 9a120fa..e5e3593 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/HdfsApi.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/HdfsApi.java
@@ -102,7 +102,7 @@ public class HdfsApi {
    * @throws java.io.IOException
    * @throws InterruptedException
    */
-  public FileStatus[] listdir(final String path) throws FileNotFoundException,
+  public synchronized FileStatus[] listdir(final String path) throws FileNotFoundException,
       IOException, InterruptedException {
     return ugi.doAs(new PrivilegedExceptionAction<FileStatus[]>() {
       public FileStatus[] run() throws FileNotFoundException, Exception {
@@ -119,7 +119,7 @@ public class HdfsApi {
    * @throws java.io.FileNotFoundException
    * @throws InterruptedException
    */
-  public FileStatus getFileStatus(final String path) throws IOException,
+  public synchronized FileStatus getFileStatus(final String path) throws IOException,
       FileNotFoundException, InterruptedException {
     return ugi.doAs(new PrivilegedExceptionAction<FileStatus>() {
       public FileStatus run() throws FileNotFoundException, IOException {
@@ -135,7 +135,7 @@ public class HdfsApi {
    * @throws java.io.IOException
    * @throws InterruptedException
    */
-  public boolean mkdir(final String path) throws IOException,
+  public synchronized boolean mkdir(final String path) throws IOException,
       InterruptedException {
     return ugi.doAs(new PrivilegedExceptionAction<Boolean>() {
       public Boolean run() throws Exception {
@@ -152,7 +152,7 @@ public class HdfsApi {
    * @throws java.io.IOException
    * @throws InterruptedException
    */
-  public boolean rename(final String src, final String dst) throws IOException,
+  public synchronized boolean rename(final String src, final String dst) throws IOException,
       InterruptedException {
     return ugi.doAs(new PrivilegedExceptionAction<Boolean>() {
       public Boolean run() throws Exception {
@@ -169,7 +169,7 @@ public class HdfsApi {
    * @throws java.io.IOException
    * @throws InterruptedException
    */
-  public boolean delete(final String path, final boolean recursive)
+  public synchronized boolean delete(final String path, final boolean recursive)
       throws IOException, InterruptedException {
     return ugi.doAs(new PrivilegedExceptionAction<Boolean>() {
       public Boolean run() throws Exception {
@@ -183,7 +183,7 @@ public class HdfsApi {
    * @return home directory
    * @throws Exception
    */
-  public Path getHomeDir() throws Exception {
+  public synchronized Path getHomeDir() throws Exception {
     return ugi.doAs(new PrivilegedExceptionAction<Path>() {
       public Path run() throws IOException {
         return fs.getHomeDirectory();
@@ -196,7 +196,7 @@ public class HdfsApi {
    * @return home directory
    * @throws Exception
    */
-  public FsStatus getStatus() throws Exception {
+  public synchronized FsStatus getStatus() throws Exception {
     return ugi.doAs(new PrivilegedExceptionAction<FsStatus>() {
       public FsStatus run() throws IOException {
         return fs.getStatus();
@@ -212,7 +212,7 @@ public class HdfsApi {
    * @throws java.io.IOException
    * @throws InterruptedException
    */
-  public FSDataOutputStream create(final String path, final boolean overwrite)
+  public synchronized FSDataOutputStream create(final String path, final boolean overwrite)
       throws IOException, InterruptedException {
     return ugi.doAs(new PrivilegedExceptionAction<FSDataOutputStream>() {
       public FSDataOutputStream run() throws Exception {
@@ -228,7 +228,7 @@ public class HdfsApi {
    * @throws java.io.IOException
    * @throws InterruptedException
    */
-  public FSDataInputStream open(final String path) throws IOException,
+  public synchronized FSDataInputStream open(final String path) throws IOException,
       InterruptedException {
     return ugi.doAs(new PrivilegedExceptionAction<FSDataInputStream>() {
       public FSDataInputStream run() throws Exception {
@@ -245,7 +245,7 @@ public class HdfsApi {
    * @throws java.io.IOException
    * @throws InterruptedException
    */
-  public void copy(final String src, final String dest) throws IOException,
+  public synchronized void copy(final String src, final String dest) throws IOException,
       InterruptedException {
     boolean result = ugi.doAs(new PrivilegedExceptionAction<Boolean>() {
       public Boolean run() throws Exception {
@@ -257,7 +257,7 @@ public class HdfsApi {
     }
   }
 
-  public boolean exists(final String newFilePath) throws IOException, InterruptedException {
+  public synchronized boolean exists(final String newFilePath) throws IOException, InterruptedException {
     return ugi.doAs(new PrivilegedExceptionAction<Boolean>() {
       public Boolean run() throws Exception {
         return fs.exists(new Path(newFilePath));
@@ -326,24 +326,7 @@ public class HdfsApi {
     return json;
   }
 
-
-  private static Map<String, HdfsApi> viewSingletonObjects = new HashMap<String, HdfsApi>();
-  /**
-   * Returns HdfsApi object specific to instance
-   * @param context View Context instance
-   * @return Hdfs business delegate object
-   */
-  public static HdfsApi getInstance(ViewContext context) {
-    if (!viewSingletonObjects.containsKey(context.getInstanceName()))
-      viewSingletonObjects.put(context.getInstanceName(), connectToHDFSApi(context));
-    return viewSingletonObjects.get(context.getInstanceName());
-  }
-
-  public static void setInstance(ViewContext context, HdfsApi api) {
-    viewSingletonObjects.put(context.getInstanceName(), api);
-  }
-
-  public static HdfsApi connectToHDFSApi(ViewContext context) {
+  public static synchronized HdfsApi connectToHDFSApi(ViewContext context) {
     HdfsApi api = null;
     Thread.currentThread().setContextClassLoader(null);
 
@@ -392,8 +375,4 @@ public class HdfsApi {
       userName = context.getUsername();
     return userName;
   }
-
-  public static void dropAllConnections() {
-    viewSingletonObjects.clear();
-  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/HdfsUtil.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/HdfsUtil.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/HdfsUtil.java
index c1c5495..3120958 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/HdfsUtil.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/HdfsUtil.java
@@ -19,7 +19,6 @@
 package org.apache.ambari.view.hive.utils;
 
 
-import org.apache.ambari.view.ViewContext;
 import org.apache.hadoop.fs.FSDataOutputStream;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -35,14 +34,14 @@ public class HdfsUtil {
    * @param filePath path to file
    * @param content new content of file
    */
-  public static void putStringToFile(ViewContext context, String filePath, String content) {
-    HdfsApi hdfs = HdfsApi.getInstance(context);
-
+  public static void putStringToFile(HdfsApi hdfs, String filePath, String content) {
     FSDataOutputStream stream;
     try {
-      stream = hdfs.create(filePath, true);
-      stream.writeBytes(content);
-      stream.close();
+      synchronized (hdfs) {
+        stream = hdfs.create(filePath, true);
+        stream.writeBytes(content);
+        stream.close();
+      }
     } catch (IOException e) {
       throw new ServiceFormattedException("Could not write file " + filePath, e);
     } catch (InterruptedException e) {
@@ -57,9 +56,7 @@ public class HdfsUtil {
    * @param extension file extension
    * @return if fullPathAndFilename="/tmp/file",extension=".txt" then filename will be like "/tmp/file_42.txt"
    */
-  public static String findUnallocatedFileName(ViewContext context, String fullPathAndFilename, String extension) {
-    HdfsApi hdfs = HdfsApi.getInstance(context);
-
+  public static String findUnallocatedFileName(HdfsApi hdfs, String fullPathAndFilename, String extension) {
     int triesCount = 0;
     String newFilePath;
     boolean isUnallocatedFilenameFound;

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/SharedObjectsFactory.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/SharedObjectsFactory.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/SharedObjectsFactory.java
new file mode 100644
index 0000000..2c7e242
--- /dev/null
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/SharedObjectsFactory.java
@@ -0,0 +1,163 @@
+/**
+ * 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.
+ */
+
+package org.apache.ambari.view.hive.utils;
+
+import org.apache.ambari.view.ViewContext;
+import org.apache.ambari.view.hive.client.Connection;
+import org.apache.ambari.view.hive.client.ConnectionFactory;
+import org.apache.ambari.view.hive.client.IConnectionFactory;
+import org.apache.ambari.view.hive.persistence.IStorageFactory;
+import org.apache.ambari.view.hive.persistence.Storage;
+import org.apache.ambari.view.hive.persistence.utils.StorageFactory;
+import org.apache.ambari.view.hive.resources.jobs.ConnectionController;
+import org.apache.ambari.view.hive.resources.jobs.OperationHandleControllerFactory;
+import org.apache.ambari.view.hive.resources.jobs.atsJobs.ATSParser;
+import org.apache.ambari.view.hive.resources.jobs.atsJobs.ATSParserFactory;
+import org.apache.ambari.view.hive.resources.jobs.viewJobs.IJobControllerFactory;
+import org.apache.ambari.view.hive.resources.jobs.viewJobs.JobControllerFactory;
+import org.apache.ambari.view.hive.resources.savedQueries.SavedQueryResourceManager;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Generates shared connections. Clients with same tag will get the same connection.
+ * e.g. user 'admin' using view instance 'HIVE1' will use one connection, another user
+ * will use different connection.
+ */
+public class SharedObjectsFactory implements IStorageFactory, IConnectionFactory {
+  private ViewContext context;
+  private IConnectionFactory hiveConnectionFactory;
+  private IStorageFactory storageFactory;
+  private ATSParserFactory atsParserFactory;
+
+  private static final Map<Class, Map<String, Object>> localObjects = new HashMap<Class, Map<String, Object>>();
+
+  public SharedObjectsFactory(ViewContext context) {
+    this.context = context;
+    this.hiveConnectionFactory = new ConnectionFactory(context);
+    this.storageFactory = new StorageFactory(context);
+    this.atsParserFactory = new ATSParserFactory(context);
+
+    synchronized (localObjects) {
+      if (localObjects.size() == 0) {
+        localObjects.put(Connection.class, new HashMap<String, Object>());
+        localObjects.put(OperationHandleControllerFactory.class, new HashMap<String, Object>());
+        localObjects.put(Storage.class, new HashMap<String, Object>());
+        localObjects.put(IJobControllerFactory.class, new HashMap<String, Object>());
+        localObjects.put(ATSParser.class, new HashMap<String, Object>());
+        localObjects.put(SavedQueryResourceManager.class, new HashMap<String, Object>());
+        localObjects.put(HdfsApi.class, new HashMap<String, Object>());
+      }
+    }
+  }
+
+  /**
+   * Returns Connection object specific to unique tag
+   * @return Hdfs business delegate object
+   */
+  @Override
+  public Connection getHiveConnection() {
+    if (!localObjects.get(Connection.class).containsKey(getTagName())) {
+      Connection newConnection = hiveConnectionFactory.getHiveConnection();
+      localObjects.get(Connection.class).put(getTagName(), newConnection);
+    }
+    return (Connection) localObjects.get(Connection.class).get(getTagName());
+  }
+
+  public ConnectionController getHiveConnectionController() {
+    return new ConnectionController(getOperationHandleControllerFactory(), getHiveConnection());
+  }
+
+  // =============================
+
+  public OperationHandleControllerFactory getOperationHandleControllerFactory() {
+    if (!localObjects.get(OperationHandleControllerFactory.class).containsKey(getTagName()))
+      localObjects.get(OperationHandleControllerFactory.class).put(getTagName(), new OperationHandleControllerFactory(this));
+    return (OperationHandleControllerFactory) localObjects.get(OperationHandleControllerFactory.class).get(getTagName());
+  }
+
+  // =============================
+  @Override
+  public Storage getStorage() {
+    if (!localObjects.get(Storage.class).containsKey(getTagName()))
+      localObjects.get(Storage.class).put(getTagName(), storageFactory.getStorage());
+    return (Storage) localObjects.get(Storage.class).get(getTagName());
+  }
+
+  // =============================
+  public IJobControllerFactory getJobControllerFactory() {
+    if (!localObjects.get(IJobControllerFactory.class).containsKey(getTagName()))
+      localObjects.get(IJobControllerFactory.class).put(getTagName(), new JobControllerFactory(context, this));
+    return (IJobControllerFactory) localObjects.get(IJobControllerFactory.class).get(getTagName());
+  }
+
+  // =============================
+
+  public SavedQueryResourceManager getSavedQueryResourceManager() {
+    if (!localObjects.get(SavedQueryResourceManager.class).containsKey(getTagName()))
+      localObjects.get(SavedQueryResourceManager.class).put(getTagName(), new SavedQueryResourceManager(context, this));
+    return (SavedQueryResourceManager) localObjects.get(SavedQueryResourceManager.class).get(getTagName());
+  }
+
+  // =============================
+  public ATSParser getATSParser() {
+    if (!localObjects.get(ATSParser.class).containsKey(getTagName()))
+      localObjects.get(ATSParser.class).put(getTagName(), atsParserFactory.getATSParser());
+    return (ATSParser) localObjects.get(ATSParser.class).get(getTagName());
+  }
+
+  // =============================
+  public HdfsApi getHdfsApi() {
+    if (!localObjects.get(HdfsApi.class).containsKey(getTagName()))
+      localObjects.get(HdfsApi.class).put(getTagName(), HdfsApi.connectToHDFSApi(context));
+    return (HdfsApi) localObjects.get(HdfsApi.class).get(getTagName());
+  }
+
+  /**
+   * Generates tag name. Clients with same tag will share one connection.
+   * @return tag name
+   */
+  public String getTagName() {
+    return String.format("%s:%s", context.getInstanceName(), context.getUsername());
+  }
+
+  /**
+   * For testing purposes, ability to substitute some local object
+   */
+  public void setInstance(Class clazz, Object object) {
+    localObjects.get(clazz).put(getTagName(), object);
+  }
+
+  /**
+   * For testing purposes, ability to clear all local objects of particular class
+   */
+  public void clear(Class clazz) {
+    localObjects.get(clazz).clear();
+  }
+
+  /**
+   * For testing purposes, ability to clear all connections
+   */
+  public void clear() {
+    for(Map<String, Object> map : localObjects.values()) {
+      map.clear();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/resources/ui/hive-web/app/components/typeahead-widget.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/typeahead-widget.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/typeahead-widget.js
index 8226c9c..34c1f4b 100644
--- a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/typeahead-widget.js
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/typeahead-widget.js
@@ -19,7 +19,7 @@
 import Typeahead from 'ember-cli-selectize/components/ember-selectize';
 import Ember from 'ember';
 
-export default Typeahead.extend({
+export default Typeahead.extend(Ember.I18n.TranslateableProperties, {
   didInsertElement: function() {
     this._super();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/history.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/history.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/history.js
index 157b917..a5de342 100644
--- a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/history.js
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/history.js
@@ -23,8 +23,8 @@ import constants from 'hive/utils/constants';
 export default Ember.ArrayController.extend(FilterableMixin, {
   itemController: constants.namingConventions.job,
 
-  sortAscending: true,
-  sortProperties: ['dateSubmitted'],
+  sortAscending: false,
+  sortProperties: ['dateSubmittedTimestamp'],
 
   init: function () {
     var oneMonthAgo = new Date();
@@ -40,12 +40,11 @@ export default Ember.ArrayController.extend(FilterableMixin, {
       }),
       Ember.Object.create({
         caption: 'columns.status',
-        property: 'status',
-        classBinding: 'status'
+        property: 'status'
       }),
       Ember.Object.create({
         caption: 'columns.date',
-        property: 'dateSubmitted',
+        property: 'dateSubmittedTimestamp',
         dateRange: Ember.Object.create({
           min: oneMonthAgo,
           max: new Date()

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index.js
index 6f93b11..592bb06 100644
--- a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index.js
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index.js
@@ -18,6 +18,7 @@
 
 import Ember from 'ember';
 import constants from 'hive/utils/constants';
+import utils from 'hive/utils/functions';
 
 export default Ember.Controller.extend({
   needs: [ constants.namingConventions.openQueries,
@@ -26,7 +27,9 @@ export default Ember.Controller.extend({
            constants.namingConventions.jobLogs,
            constants.namingConventions.jobResults,
            constants.namingConventions.jobExplain,
-           constants.namingConventions.settings
+           constants.namingConventions.settings,
+           constants.namingConventions.visualExplain,
+           constants.namingConventions.tezUI
   ],
 
   openQueries: Ember.computed.alias('controllers.' + constants.namingConventions.openQueries),
@@ -36,6 +39,8 @@ export default Ember.Controller.extend({
   results: Ember.computed.alias('controllers.' + constants.namingConventions.jobResults),
   explain: Ember.computed.alias('controllers.' + constants.namingConventions.jobExplain),
   settings: Ember.computed.alias('controllers.' + constants.namingConventions.settings),
+  visualExplain: Ember.computed.alias('controllers.' + constants.namingConventions.visualExplain),
+  tezUI: Ember.computed.alias('controllers.' + constants.namingConventions.tezUI),
 
   canExecute: function () {
     var isModelRunning = this.get('model.isRunning');
@@ -77,7 +82,6 @@ export default Ember.Controller.extend({
 
   _executeQuery: function (shouldExplain) {
     var queryId,
-        self = this,
         query,
         finalQuery,
         job,
@@ -166,8 +170,6 @@ export default Ember.Controller.extend({
     }
 
     queries = queries.map(function (query) {
-      var explainIndex = query.indexOf(constants.namingConventions.explainPrefix);
-
       if (shouldExplain) {
         if (query.indexOf(constants.namingConventions.explainPrefix) === -1) {
           return constants.namingConventions.explainPrefix + query;
@@ -213,7 +215,7 @@ export default Ember.Controller.extend({
     this._super();
 
     // initialize queryParams with an empty array
-    this.set('queryParams', Ember.ArrayProxy.create({ content: Ember.A([]) }))
+    this.set('queryParams', Ember.ArrayProxy.create({ content: Ember.A([]) }));
 
     this.set('queryProcessTabs', Ember.ArrayProxy.create({ content: Ember.A([
       Ember.Object.create({
@@ -232,20 +234,27 @@ export default Ember.Controller.extend({
   },
 
   displayJobTabs: function () {
-    return this.get('content.constructor.typeKey') === constants.namingConventions.job;
+    return this.get('content.constructor.typeKey') === constants.namingConventions.job &&
+           utils.isInteger(this.get('content.id'));
   }.property('content'),
 
   modelChanged: function () {
     var self = this;
     var content = this.get('content');
     var openQueries = this.get('openQueries');
+    var database = this.get('databases').findBy('name', this.get('content.dataBase'));
+
+    if (database) {
+      this.set('databases.selectedDatabase', database);
+    }
 
     //update open queries list when current query model changes
     openQueries.update(content).then(function (isExplainedQuery) {
       var newId = content.get('id');
       var tab = openQueries.getTabForModel(content);
 
-      if (content.get('constructor.typeKey') === constants.namingConventions.job) {
+      //if not an ATS job
+      if (content.get('constructor.typeKey') === constants.namingConventions.job && utils.isInteger(newId)) {
         self.get('queryProcessTabs').forEach(function (queryTab) {
           queryTab.set('id', newId);
         });
@@ -269,7 +278,7 @@ export default Ember.Controller.extend({
       return;
     }
 
-    if (this.get('content.status') !== constants.statuses.finished) {
+    if (!utils.insensitiveCompare(this.get('content.status'), constants.statuses.succeeded)) {
       return;
     }
 
@@ -285,7 +294,7 @@ export default Ember.Controller.extend({
     var tabs = this.get('queryProcessTabs');
     var isResultsTabVisible = tabs.findBy('path', constants.namingConventions.subroutes.jobResults).get('visible');
 
-    if (this.get('content.status') === constants.statuses.finished && isResultsTabVisible) {
+    if (utils.insensitiveCompare(this.get('content.status'), constants.statuses.succeeded) && isResultsTabVisible) {
       items.push({
         title: Ember.I18n.t('buttons.saveHdfs'),
         action: 'saveToHDFS'
@@ -320,7 +329,7 @@ export default Ember.Controller.extend({
   saveToHDFS: function () {
     var job = this.get('content');
 
-    if (job.get('status') !== constants.statuses.finished) {
+    if (!utils.insensitiveCompare(job.get('status'), constants.statuses.succeeded)) {
       return;
     }
 
@@ -347,7 +356,7 @@ export default Ember.Controller.extend({
 
     Ember.run.later(function () {
       Ember.$.getJSON(url).then(function (response) {
-        if (response.status !== constants.results.statuses.terminated) {
+        if (!utils.insensitiveCompare(response.status, constants.results.statuses.terminated)) {
           self.pollSaveToHDFS(response);
         } else {
           self.set('content.isRunning', false);
@@ -413,6 +422,10 @@ export default Ember.Controller.extend({
           id: 'fixture_' + idCounter
         });
 
+        if (idCounter) {
+          model.set('title', model.get('title') + ' (' + idCounter + ')')
+        }
+
         idCounter++;
 
         this.transitionToRoute(constants.namingConventions.subroutes.savedQuery, model);
@@ -424,6 +437,8 @@ export default Ember.Controller.extend({
           wasNew = this.get('model.isNew'),
           defer = Ember.RSVP.defer();
 
+      this.set('model.dataBase', this.get('databases.selectedDatabase.name'));
+
       this.send('openModal', 'modal-save', {
         heading: "modals.save.heading",
         text: this.get('content.title'),
@@ -446,7 +461,7 @@ export default Ember.Controller.extend({
       var subroute;
 
       this._executeQuery().then(function (job) {
-        if (job.get('status') !== constants.statuses.finished) {
+        if (job.get('status') !== constants.statuses.succeeded) {
           subroute = constants.namingConventions.subroutes.jobLogs;
         } else {
           subroute = constants.namingConventions.subroutes.jobResults;
@@ -470,6 +485,23 @@ export default Ember.Controller.extend({
       }, function (err) {
         self.send('addAlert', constants.alerts.error, err.responseText, "alerts.errors.save.query");
       });
+    },
+
+    toggleOverlay: function (targetController) {
+      if (this.get('visualExplain.showOverlay') && targetController !== 'visualExplain') {
+        this.set('visualExplain.showOverlay', false);
+      } else if (this.get('tezUI.showOverlay') && targetController !== 'tezUI') {
+        this.set('tezUI.showOverlay', false);
+      } else if (this.get('settings.showOverlay') && targetController !== 'settings') {
+        this.set('settings.showOverlay', false);
+      }
+
+      if (targetController !== 'settings') {
+        //set content for visual explain and tez ui.
+        this.set(targetController + '.content', this.get('content'));
+      }
+
+      this.toggleProperty(targetController + '.showOverlay');
     }
   }
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index/history-query/logs.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index/history-query/logs.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index/history-query/logs.js
index f633dd4..02edc86 100644
--- a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index/history-query/logs.js
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index/history-query/logs.js
@@ -18,6 +18,7 @@
 
 import Ember from 'ember';
 import constants from 'hive/utils/constants';
+import utils from 'hive/utils/functions';
 
 export default Ember.ObjectController.extend({
   needs: [ constants.namingConventions.loadedFiles ],
@@ -73,12 +74,11 @@ export default Ember.ObjectController.extend({
   },
 
   isJobRunning: function (job) {
-    var status = job.get('status');
-
-    return status !== constants.statuses.finished &&
-           status !== constants.statuses.canceled &&
-           status !== constants.statuses.closed &&
-           status !== constants.statuses.error;
+    return utils.insensitiveCompare(job.get('status'),
+                                    constants.statuses.unknown,
+                                    constants.statuses.initialized,
+                                    constants.statuses.running,
+                                    constants.statuses.pending);
   },
 
   getLogs: function () {

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index/history-query/results.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index/history-query/results.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index/history-query/results.js
index 34e69bd..7977541 100644
--- a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index/history-query/results.js
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index/history-query/results.js
@@ -18,6 +18,7 @@
 
 import Ember from 'ember';
 import constants from 'hive/utils/constants';
+import utils from 'hive/utils/functions';
 
 export default Ember.ObjectController.extend({
   cachedResults: [],
@@ -51,7 +52,7 @@ export default Ember.ObjectController.extend({
   initResults: function () {
     var existingJob;
 
-    if (this.get('content.status') !== constants.statuses.finished) {
+    if (!utils.insensitiveCompare(this.get('content.status'), constants.statuses.succeeded)) {
       return;
     }
 
@@ -131,4 +132,4 @@ export default Ember.ObjectController.extend({
       }
     }
   }
-});
\ No newline at end of file
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/job.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/job.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/job.js
index 5bb1cd5..7e62c20 100644
--- a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/job.js
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/job.js
@@ -18,6 +18,7 @@
 
 import Ember from 'ember';
 import constants from 'hive/utils/constants';
+import utils from 'hive/utils/functions';
 
 export default Ember.ObjectController.extend({
   needs: [ constants.namingConventions.history, constants.namingConventions.loadedFiles ],
@@ -25,9 +26,7 @@ export default Ember.ObjectController.extend({
   files: Ember.computed.alias('controllers.' + constants.namingConventions.loadedFiles),
 
   canStop: function () {
-    return this.get('status') === constants.statuses.running ||
-           this.get('status') === constants.statuses.initialized ||
-           this.get('status') === constants.statuses.pending;
+    return utils.insensitiveCompare(this.get('status'), constants.statuses.running, constants.statuses.initialized, constants.statuses.pending)
   }.property('status'),
 
   actions: {

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/open-queries.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/open-queries.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/open-queries.js
index e97c0e6..2abfff6 100644
--- a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/open-queries.js
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/open-queries.js
@@ -18,6 +18,7 @@
 
 import Ember from 'ember';
 import constants from 'hive/utils/constants';
+import utils from 'hive/utils/functions';
 
 export default Ember.ArrayController.extend({
   needs: [ constants.namingConventions.databases,
@@ -91,7 +92,9 @@ export default Ember.ArrayController.extend({
           var isExplainedQuery,
               subroute;
 
-          if (model.get('constructor.typeKey') === constants.namingConventions.job) {
+          //jobs that were run from hive ui (exclude ats jobs)
+          if (model.get('constructor.typeKey') === constants.namingConventions.job &&
+              utils.isInteger(model.get('id'))) {
             isExplainedQuery = self.get('currentQuery.fileContent').indexOf(constants.namingConventions.explainPrefix) > -1;
 
             if (isExplainedQuery) {
@@ -251,13 +254,9 @@ export default Ember.ArrayController.extend({
     var hasQueryParams = this.get('index.queryParams.length');
     var hasSettings = this.get('settings').hasSettings(jobId);
 
-    if ( selected && selected[0] !== "" ||
+    return selected && selected[0] !== "" ||
          hasQueryParams ||
-         hasSettings ) {
-      return true;
-    }
-
-    return false;
+         hasSettings;
   },
 
   actions: {

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/queries.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/queries.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/queries.js
index 85730a4..0195dc2 100644
--- a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/queries.js
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/queries.js
@@ -63,10 +63,7 @@ export default Ember.ArrayController.extend(FilterableMixin, {
   ],
 
   model: function () {
-    var queries = this.get('queries');
-    queries = queries ? queries.filterBy('isNew', false) : queries;
-
-    return this.filter(queries);
+    return this.filter(this.get('queries'));
   }.property('queries', 'filters.@each'),
 
   actions: {

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/settings.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/settings.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/settings.js
index 51101c5..c59fc88 100644
--- a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/settings.js
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/settings.js
@@ -28,19 +28,28 @@ export default Ember.ArrayController.extend({
   index: Ember.computed.alias('controllers.' + constants.namingConventions.index),
   openQueries: Ember.computed.alias('controllers.' + constants.namingConventions.openQueries),
 
-  showSettingsOverlay: false,
+  predefinedSettings: constants.hiveParameters,
 
-  querySettings: function () {
+  currentSettings: function () {
     var currentId = this.get('index.model.id');
-    return this.findBy('id', currentId);
-  }.property('model.[]', 'index.model.id'),
+    var targetSettings = this.findBy('id', currentId);
+
+   if (!targetSettings) {
+      targetSettings = this.pushObject(Ember.Object.create({
+        id: currentId,
+        settings: []
+      }));
+    }
+
+    return targetSettings;
+  }.property('index.model.id'),
 
   updateSettingsId: function (oldId, newId) {
     this.filterBy('id', oldId).setEach('id', newId);
   },
 
-  getSettingsString: function (id) {
-    var currentId = id ? id : this.get('index.model.id');
+  getSettingsString: function () {
+    var currentId = this.get('index.model.id');
 
     var querySettings = this.findBy('id', currentId);
 
@@ -49,13 +58,9 @@ export default Ember.ArrayController.extend({
     }
 
     var settings = querySettings.get('settings').map(function (setting) {
-      return 'set %@ = %@;'.fmt(setting.key, setting.value);
+      return 'set %@ = %@;'.fmt(setting.get('key.name'), setting.get('value'));
     });
 
-    if (querySettings.get('runOnTez')) {
-      settings.push('set %@ = tez;'.fmt(constants.settings.executionEngine));
-    }
-
     return settings.join("\n");
   },
 
@@ -70,8 +75,7 @@ export default Ember.ArrayController.extend({
     var id = this.get('index.model.id');
     var query = this.get('openQueries.currentQuery');
     var content = query.get('fileContent');
-    var runOnTez = false;
-
+    var self = this;
 
     var regex = new RegExp(/^set\s+[\w-.]+(\s+|\s?)=(\s+|\s?)[\w-.]+(\s+|\s?);/gim);
     var settings = content.match(regex);
@@ -83,68 +87,97 @@ export default Ember.ArrayController.extend({
     query.set('fileContent', content.replace(regex, '').trim());
     settings = settings.map(function (setting) {
       var KV = setting.split('=');
-
-      return {
-        key: KV[0].replace('set', '').trim(),
+      var obj = {
+        key: {
+          name: KV[0].replace('set', '').trim()
+        },
         value: KV[1].replace(';', '').trim()
       };
-    });
 
-    // remove runOnTez from settings
-    settings = settings.findBy('key', constants.settings.executionEngine).without(false);
+      if (!self.get('predefinedSettings').findBy('name', obj.key.name)) {
+        self.get('predefinedSettings').pushObject({
+          name: obj.key.name
+        });
+      }
 
-    this.setSettingForQuery(id, settings, !!runOnTez);
+      return obj;
+    });
+
+    this.setSettingForQuery(id, settings);
   }.observes('openQueries.currentQuery', 'openQueries.tabUpdated'),
 
-  setSettingForQuery: function (id, settings, runOnTez) {
+  setSettingForQuery: function (id, settings) {
     var querySettings = this.findBy('id', id);
 
     if (!querySettings) {
       this.pushObject(Ember.Object.create({
         id: id,
-        settings: settings,
-        runOnTez: runOnTez
+        settings: settings
       }));
     } else {
       querySettings.setProperties({
-        'settings': settings,
-        'runOnTez': runOnTez
+        'settings': settings
       });
     }
   },
 
-  createSettingsForQuery: function () {
-    var currentId = this.get('index.model.id');
+  validate: function() {
+    var settings = this.get('currentSettings.settings') || [];
+    var predefinedSettings = this.get('predefinedSettings');
+
+    settings.forEach(function(setting) {
+      var predefined = predefinedSettings.filterProperty('name', setting.get('key.name'));
+      if (!predefined.length) {
+        return;
+      } else {
+        predefined = predefined[0];
+      }
+
+      if (predefined.values && predefined.values.contains(setting.get('value'))) {
+        setting.set('valid', true);
+        return;
+      }
+
+      if (predefined.validate && predefined.validate.test(setting.get('value'))) {
+        setting.set('valid', true);
+        return;
+      }
+
+      setting.set('valid', false);
+    });
+  }.observes('currentSettings.[]', 'currentSettings.settings.@each.value', 'currentSettings.settings.@each.key'),
 
-    if (!this.findBy('id', currentId)) {
-      this.pushObject(Ember.Object.create({
-        id: currentId,
-        settings: [],
-        runOnTez: false
-      }));
-    }
-  },
+  currentSettingsAreValid: function() {
+    var currentSettings = this.get('currentSettings.settings');
+    var invalid = currentSettings.filterProperty('valid', false);
 
-  actions: {
-    toggleOverlay: function () {
-      // create a setting object if its not already there
-      this.createSettingsForQuery();
-      this.toggleProperty('showSettingsOverlay');
-    },
+    return invalid.length ? false : true;
+  }.property('currentSettings.settings.@each.value', 'currentSettings.settings.@each.key'),
 
+  actions: {
     add: function () {
       var currentId = this.get('index.model.id'),
-       querySettings = this.findBy('id', currentId);
+          querySettings = this.findBy('id', currentId);
 
-      querySettings.settings.pushObject(Ember.Object.create({
-        key: '',
-        value: ''
-      }));
+      var Setting = Ember.Object.extend({
+        valid: true,
+        selection: Ember.Object.create(),
+        value: Ember.computed.alias('selection.value')
+      });
+
+      querySettings.get('settings').pushObject(Setting.create({}));
     },
 
     remove: function (setting) {
-      var currentId = this.get('index.model.id');
-      this.findBy('id', currentId).settings.removeObject(setting);
+      this.findBy('id', this.get('index.model.id')).settings.removeObject(setting);
+    },
+
+    addKey: function (param) {
+      var newKey = this.get('predefinedSettings').pushObject({
+        name: param
+      });
+
+      this.get('currentSettings.settings').findBy('key', null).set('key', newKey);
     }
   }
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/tez-ui.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/tez-ui.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/tez-ui.js
new file mode 100644
index 0000000..dc99fd1
--- /dev/null
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/tez-ui.js
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+
+import Ember from 'ember';
+
+export default Ember.Controller.extend({
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/visual-explain.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/visual-explain.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/visual-explain.js
new file mode 100644
index 0000000..5275a9b
--- /dev/null
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/visual-explain.js
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+
+import Ember from 'ember';
+
+export default Ember.ObjectController.extend({
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/resources/ui/hive-web/app/helpers/all-uppercase.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/helpers/all-uppercase.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/helpers/all-uppercase.js
new file mode 100644
index 0000000..e5ea321
--- /dev/null
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/helpers/all-uppercase.js
@@ -0,0 +1,25 @@
+/**
+ * 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.
+ */
+
+import Ember from 'ember';
+
+export function allUppercase(input) {
+  return input.toUpperCase();
+};
+
+export default Ember.Handlebars.makeBoundHelper(allUppercase);

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/resources/ui/hive-web/app/initializers/i18n.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/initializers/i18n.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/initializers/i18n.js
index 0040307..a87bf78 100644
--- a/contrib/views/hive/src/main/resources/ui/hive-web/app/initializers/i18n.js
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/initializers/i18n.js
@@ -64,7 +64,9 @@ TRANSLATIONS = {
     query: {
       editor: 'Query Editor',
       process: 'Query Process Results',
-      parameters: 'Parameters'
+      parameters: 'Parameters',
+      visualExplain: 'Visual Explain',
+      tez: 'TEZ'
     },
     download: 'Save results...'
   },
@@ -77,7 +79,8 @@ TRANSLATIONS = {
       database: 'Select Database...',
       udfs: 'Insert udfs',
       file: 'Select File Resource...',
-      noFileResource: '(no file)'
+      noFileResource: '(no file)',
+      value: "Select value..."
     },
     fileResource: {
       name: "resource name",

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/resources/ui/hive-web/app/models/job.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/models/job.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/models/job.js
index 95e5d57..73fcc20 100644
--- a/contrib/views/hive/src/main/resources/ui/hive-web/app/models/job.js
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/models/job.js
@@ -28,5 +28,17 @@ export default DS.Model.extend({
   status: DS.attr('string'),
   dateSubmitted: DS.attr('date'),
   forcedContent: DS.attr('string'),
-  logFile: DS.attr('string')
+  logFile: DS.attr('string'),
+
+  dateSubmittedTimestamp: function () {
+    var date = this.get('dateSubmitted');
+
+    return date ? date * 1000 : date;
+  }.property('dateSubmitted'),
+
+  uppercaseStatus: function () {
+    var status = this.get('status');
+
+    return status ? status.toUpperCase() : status;
+  }.property('status')
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/db973127/contrib/views/hive/src/main/resources/ui/hive-web/app/routes/application.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/routes/application.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/routes/application.js
index 8def09e..2f9a5ae 100644
--- a/contrib/views/hive/src/main/resources/ui/hive-web/app/routes/application.js
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/routes/application.js
@@ -20,7 +20,7 @@ import Ember from 'ember';
 import constants from 'hive/utils/constants';
 
 export default Ember.Route.extend({
-  setupController: function() {
+  setupController: function () {
     var self = this;
 
     this.controllerFor(constants.namingConventions.databases).set('model', this.store.find(constants.namingConventions.database));
@@ -31,7 +31,7 @@ export default Ember.Route.extend({
   },
 
   actions: {
-    openModal: function(modalTemplate, options) {
+    openModal: function (modalTemplate, options) {
       this.controllerFor(modalTemplate).setProperties({
         heading: options.heading,
         text: options.text,