You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2012/11/07 09:13:24 UTC

svn commit: r1406489 [8/19] - in /incubator/ambari/branches/AMBARI-666: ./ ambari-agent/ ambari-agent/conf/ ambari-agent/conf/unix/ ambari-agent/src/main/puppet/manifestloader/ ambari-agent/src/main/puppet/modules/configgenerator/manifests/ ambari-agen...

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java Wed Nov  7 08:13:12 2012
@@ -27,6 +27,7 @@ import org.codehaus.jackson.map.ObjectMa
 import org.codehaus.jackson.type.TypeReference;
 
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -235,6 +236,16 @@ public class PropertyHelper {
   }
 
   /**
+   * Factory method to create a read request from the given set of property ids.  The set of
+   * property ids represents the properties of interest for the query.
+   *
+   * @param propertyIds  the property ids associated with the request; may be null
+   */
+  public static Request getReadRequest(PropertyId ... propertyIds) {
+    return new RequestImpl(new HashSet<PropertyId>(Arrays.asList(propertyIds)),  null);
+  }
+
+  /**
    * Factory method to create an update request from the given map of properties.
    * The properties values in the given map are used to update the resource.
    *

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/metadata/ActionMetadata.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/metadata/ActionMetadata.java?rev=1406489&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/metadata/ActionMetadata.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/metadata/ActionMetadata.java Wed Nov  7 08:13:12 2012
@@ -0,0 +1,99 @@
+/*
+ * 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.server.metadata;
+
+import com.google.inject.Singleton;
+import org.apache.ambari.server.Role;
+
+import java.util.*;
+
+/**
+ * Contains metadata about actions supported by services
+ */
+@Singleton
+public class ActionMetadata {
+  private final Map<String, List<String>> serviceActions = new HashMap<String, List<String>>();
+  private final Map<String, String> serviceClients = new HashMap<String, String>();
+  private final Map<String, String> serviceCheckActions =
+      new HashMap<String, String>();
+
+  public ActionMetadata() {
+    fillServiceActions();
+    fillServiceClients();
+    fillServiceCheckActions();
+  }
+
+  private void fillServiceClients() {
+    serviceClients.put("hdfs"       , Role.HDFS_CLIENT.toString());
+    serviceClients.put("hbase"      , Role.HBASE_CLIENT.toString());
+    serviceClients.put("mapreduce"  , Role.MAPREDUCE_CLIENT.toString());
+    serviceClients.put("zookeeper"  , Role.ZOOKEEPER_CLIENT.toString());
+    serviceClients.put("hive"       , Role.HIVE_CLIENT.toString());
+    serviceClients.put("hcat"       , Role.HCAT.toString());
+    serviceClients.put("oozie"      , Role.OOZIE_CLIENT.toString());
+    serviceClients.put("pig"        , Role.PIG.toString());
+    serviceClients.put("sqoop"      , Role.SQOOP.toString());
+  }
+
+  private void fillServiceActions() {
+    serviceActions.put("hdfs"       , Arrays.asList(Role.HDFS_SERVICE_CHECK.toString()));
+    serviceActions.put("hbase"      , Arrays.asList(Role.HBASE_SERVICE_CHECK.toString()));
+    serviceActions.put("mapreduce"  , Arrays.asList(Role.MAPREDUCE_SERVICE_CHECK.toString()));
+    serviceActions.put("zookeeper"  , Arrays.asList(Role.ZOOKEEPER_QUORUM_SERVICE_CHECK.toString()));
+    serviceActions.put("hive"       , Arrays.asList(Role.HIVE_SERVICE_CHECK.toString()));
+    serviceActions.put("hcat"       , Arrays.asList(Role.HCAT_SERVICE_CHECK.toString()));
+    serviceActions.put("oozie"      , Arrays.asList(Role.OOZIE_SERVICE_CHECK.toString()));
+    serviceActions.put("pig"        , Arrays.asList(Role.PIG_SERVICE_CHECK.toString()));
+    serviceActions.put("sqoop"      , Arrays.asList(Role.SQOOP_SERVICE_CHECK.toString()));
+    serviceActions.put("templeton"  , Arrays.asList(Role.TEMPLETON_SERVICE_CHECK.toString()));
+  }
+
+  private void fillServiceCheckActions() {
+    serviceCheckActions.put("hdfs", Role.HDFS_SERVICE_CHECK.toString());
+    serviceCheckActions.put("hbase", Role.HBASE_SERVICE_CHECK.toString());
+    serviceCheckActions.put("mapreduce",
+        Role.MAPREDUCE_SERVICE_CHECK.toString());
+    serviceCheckActions.put("zookeeper",
+        Role.ZOOKEEPER_QUORUM_SERVICE_CHECK.toString());
+    serviceCheckActions.put("hive", Role.HIVE_SERVICE_CHECK.toString());
+    serviceCheckActions.put("hcat", Role.HCAT_SERVICE_CHECK.toString());
+    serviceCheckActions.put("oozie", Role.OOZIE_SERVICE_CHECK.toString());
+    serviceCheckActions.put("pig", Role.PIG_SERVICE_CHECK.toString());
+    serviceCheckActions.put("sqoop", Role.SQOOP_SERVICE_CHECK.toString());
+    serviceCheckActions.put("templeton",
+        Role.TEMPLETON_SERVICE_CHECK.toString());
+  }
+
+  public List<String> getActions(String serviceName) {
+    List<String> result = serviceActions.get(serviceName.toLowerCase());
+    if (result != null) {
+      return result;
+    } else {
+      return Collections.emptyList();
+    }
+  }
+
+  public String getClient(String serviceName) {
+    return serviceClients.get(serviceName.toLowerCase());
+  }
+
+  public String getServiceCheckAction(String serviceName) {
+    return serviceCheckActions.get(serviceName.toLowerCase());
+  }
+}

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java Wed Nov  7 08:13:12 2012
@@ -87,7 +87,9 @@ public class RoleCommandOrder {
         RoleCommand.START);
     addDependency(Role.JOBTRACKER, RoleCommand.START, Role.DATANODE,
         RoleCommand.START);
-    addDependency(Role.TASKTRACKER, RoleCommand.START, Role.JOBTRACKER,
+    addDependency(Role.TASKTRACKER, RoleCommand.START, Role.NAMENODE,
+        RoleCommand.START);
+    addDependency(Role.TASKTRACKER, RoleCommand.START, Role.DATANODE,
         RoleCommand.START);
     addDependency(Role.OOZIE_SERVER, RoleCommand.START, Role.JOBTRACKER,
         RoleCommand.START);
@@ -95,6 +97,55 @@ public class RoleCommandOrder {
         RoleCommand.START);
     addDependency(Role.TEMPLETON_SERVER, RoleCommand.START, Role.TASKTRACKER,
         RoleCommand.START);
+
+    // Service checks
+    addDependency(Role.HDFS_SERVICE_CHECK, RoleCommand.EXECUTE, Role.NAMENODE,
+        RoleCommand.START);
+    addDependency(Role.HDFS_SERVICE_CHECK, RoleCommand.EXECUTE, Role.DATANODE,
+        RoleCommand.START);
+    addDependency(Role.MAPREDUCE_SERVICE_CHECK, RoleCommand.EXECUTE,
+        Role.JOBTRACKER, RoleCommand.START);
+    addDependency(Role.MAPREDUCE_SERVICE_CHECK, RoleCommand.EXECUTE,
+        Role.TASKTRACKER, RoleCommand.START);
+    addDependency(Role.OOZIE_SERVICE_CHECK, RoleCommand.EXECUTE,
+        Role.OOZIE_SERVER, RoleCommand.START);
+    addDependency(Role.TEMPLETON_SERVICE_CHECK, RoleCommand.EXECUTE,
+        Role.TEMPLETON_SERVER, RoleCommand.START);
+    addDependency(Role.HBASE_SERVICE_CHECK, RoleCommand.EXECUTE,
+        Role.HBASE_MASTER, RoleCommand.START);
+    addDependency(Role.HBASE_SERVICE_CHECK, RoleCommand.EXECUTE,
+        Role.HBASE_REGIONSERVER, RoleCommand.START);
+    addDependency(Role.HIVE_SERVICE_CHECK, RoleCommand.EXECUTE,
+        Role.HIVE_SERVER, RoleCommand.START);
+    addDependency(Role.HCAT_SERVICE_CHECK, RoleCommand.EXECUTE,
+        Role.HIVE_SERVER, RoleCommand.START);
+    addDependency(Role.PIG_SERVICE_CHECK, RoleCommand.EXECUTE,
+        Role.JOBTRACKER, RoleCommand.START);
+    addDependency(Role.PIG_SERVICE_CHECK, RoleCommand.EXECUTE,
+        Role.TASKTRACKER, RoleCommand.START);
+    addDependency(Role.SQOOP_SERVICE_CHECK, RoleCommand.EXECUTE,
+        Role.JOBTRACKER, RoleCommand.START);
+    addDependency(Role.SQOOP_SERVICE_CHECK, RoleCommand.EXECUTE,
+        Role.TASKTRACKER, RoleCommand.START);
+    
+    addDependency(Role.ZOOKEEPER_SERVER, RoleCommand.STOP,
+        Role.HBASE_MASTER, RoleCommand.STOP);
+    addDependency(Role.ZOOKEEPER_SERVER, RoleCommand.STOP,
+        Role.HBASE_REGIONSERVER, RoleCommand.STOP);
+    addDependency(Role.NAMENODE, RoleCommand.STOP,
+        Role.HBASE_MASTER, RoleCommand.STOP);
+    addDependency(Role.DATANODE, RoleCommand.STOP,
+        Role.HBASE_MASTER, RoleCommand.STOP);
+    addDependency(Role.HBASE_MASTER, RoleCommand.STOP,
+        Role.HBASE_REGIONSERVER, RoleCommand.STOP);
+    addDependency(Role.NAMENODE, RoleCommand.STOP,
+        Role.JOBTRACKER, RoleCommand.STOP);
+    addDependency(Role.NAMENODE, RoleCommand.STOP,
+        Role.TASKTRACKER, RoleCommand.STOP);
+    addDependency(Role.DATANODE, RoleCommand.STOP,
+        Role.JOBTRACKER, RoleCommand.STOP);
+    addDependency(Role.DATANODE, RoleCommand.STOP,
+        Role.TASKTRACKER, RoleCommand.STOP);
   }
 
   /**
@@ -116,25 +167,32 @@ public class RoleCommandOrder {
         && (dependencies.get(rcp2).contains(rcp1))) {
       return -1;
     } else if (!rgn2.getCommand().equals(rgn1.getCommand())) {
-      return compareCommands(rgn1.getCommand(), rgn2.getCommand());
+      return compareCommands(rgn1, rgn2);
     }
     return 0;
   }
 
-  private int compareCommands(RoleCommand rc1, RoleCommand rc2) {
+  private int compareCommands(RoleGraphNode rgn1, RoleGraphNode rgn2) {
+    RoleCommand rc1 = rgn1.getCommand();
+    RoleCommand rc2 = rgn2.getCommand();
     if (rc1.equals(rc2)) {
-      throw new IllegalArgumentException("rc1 and rc2 are same");
-    } else if (rc1.equals(RoleCommand.INSTALL)) {
+      //If its coming here means roles have no dependencies.
+      return 0;
+    }
+   
+    if ((rc1.equals(RoleCommand.START) && rc2.equals(RoleCommand.EXECUTE)) ||
+        (rc2.equals(RoleCommand.START) && rc1.equals(RoleCommand.EXECUTE))) {
+      //START and execute are independent, role order matters
+      return 0;
+    }
+    
+    if (rc1.equals(RoleCommand.INSTALL)) {
       return -1;
     } else if (rc2.equals(RoleCommand.INSTALL)) {
       return 1;
-    } else if (rc1.equals(RoleCommand.START)) {
-      return -1;
-    } else if (rc2.equals(RoleCommand.START)) {
-      return 1;
-    } else if (rc1.equals(RoleCommand.EXECUTE)) {
+    } else if (rc1.equals(RoleCommand.START) || rc1.equals(RoleCommand.EXECUTE)) {
       return -1;
-    } else if (rc2.equals(RoleCommand.EXECUTE)) {
+    } else if (rc2.equals(RoleCommand.START) || rc2.equals(RoleCommand.EXECUTE)) {
       return 1;
     } else if (rc1.equals(RoleCommand.STOP)) {
       return -1;

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClearEntityManagerInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClearEntityManagerInterceptor.java?rev=1406489&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClearEntityManagerInterceptor.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClearEntityManagerInterceptor.java Wed Nov  7 08:13:12 2012
@@ -0,0 +1,49 @@
+/*
+ * 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.server.orm.dao;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+
+/**
+ * Interceptors clears EntityManager before method call
+ */
+public class ClearEntityManagerInterceptor implements MethodInterceptor {
+  private static final Logger log = LoggerFactory.getLogger(ClearEntityManagerInterceptor.class);
+
+  @Inject
+  Provider<EntityManager> entityManagerProvider;
+
+  @Override
+  public Object invoke(MethodInvocation methodInvocation) throws Throwable {
+    try {
+      return methodInvocation.proceed();
+    } finally {
+      if (!entityManagerProvider.get().getTransaction().isActive()) {
+        log.debug("Transaction is not active any more - clearing Entity Manager");
+        entityManagerProvider.get().clear();
+      }
+    }
+  }
+}

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java Wed Nov  7 08:13:12 2012
@@ -45,10 +45,12 @@ public class ClusterDAO {
    * @param id ID of Cluster
    * @return Found entity or NULL
    */
+  @Transactional
   public ClusterEntity findById(long id) {
     return entityManagerProvider.get().find(ClusterEntity.class, id);
   }
 
+  @Transactional
   public ClusterEntity findByName(String clusterName) {
     TypedQuery<ClusterEntity> query = entityManagerProvider.get().createNamedQuery("clusterByName", ClusterEntity.class);
     query.setParameter("clusterName", clusterName);
@@ -59,6 +61,7 @@ public class ClusterDAO {
     }
   }
 
+  @Transactional
   public List<ClusterEntity> findAll() {
     TypedQuery<ClusterEntity> query = entityManagerProvider.get().createNamedQuery("allClusters", ClusterEntity.class);
     try {
@@ -89,6 +92,7 @@ public class ClusterDAO {
    * Retrieve entity data from DB
    * @param clusterEntity entity to refresh
    */
+  @Transactional
   public void refresh(ClusterEntity clusterEntity) {
     entityManagerProvider.get().refresh(clusterEntity);
   }
@@ -100,7 +104,7 @@ public class ClusterDAO {
 
   @Transactional
   public void remove(ClusterEntity clusterEntity) {
-    entityManagerProvider.get().remove(clusterEntity);
+    entityManagerProvider.get().remove(merge(clusterEntity));
   }
 
   @Transactional
@@ -108,13 +112,4 @@ public class ClusterDAO {
     remove(findByName(clusterName));
   }
 
-  @Transactional
-  public void rename(ClusterEntity clusterEntity, String newName) {
-    entityManagerProvider.get().unwrap(JpaEntityManager.class).getUnitOfWork().setShouldPerformDeletesFirst(true);
-    remove(clusterEntity);
-    entityManagerProvider.get().detach(clusterEntity);
-    clusterEntity.setClusterName(newName);
-    create(clusterEntity);
-  }
-
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterServiceDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterServiceDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterServiceDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterServiceDAO.java Wed Nov  7 08:13:12 2012
@@ -32,10 +32,12 @@ public class ClusterServiceDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
+  @Transactional
   public ClusterServiceEntity findByPK(ClusterServiceEntityPK clusterServiceEntityPK) {
     return entityManagerProvider.get().find(ClusterServiceEntity.class, clusterServiceEntityPK);
   }
 
+  @Transactional
   public ClusterServiceEntity findByClusterAndServiceNames(String  clusterName, String serviceName) {
     TypedQuery<ClusterServiceEntity> query = entityManagerProvider.get()
             .createNamedQuery("clusterServiceByClusterAndServiceNames", ClusterServiceEntity.class);
@@ -49,6 +51,7 @@ public class ClusterServiceDAO {
     }
   }
 
+  @Transactional
   public void refresh(ClusterServiceEntity clusterServiceEntity) {
     entityManagerProvider.get().refresh(clusterServiceEntity);
   }
@@ -65,7 +68,7 @@ public class ClusterServiceDAO {
 
   @Transactional
   public void remove(ClusterServiceEntity clusterServiceEntity) {
-    entityManagerProvider.get().remove(clusterServiceEntity);
+    entityManagerProvider.get().remove(merge(clusterServiceEntity));
   }
 
   @Transactional

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterStateDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterStateDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterStateDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterStateDAO.java Wed Nov  7 08:13:12 2012
@@ -29,10 +29,12 @@ public class ClusterStateDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
+  @Transactional
   public ClusterStateEntity findByPK(String clusterName) {
     return entityManagerProvider.get().find(ClusterStateEntity.class, clusterName);
   }
 
+  @Transactional
   public void refresh(ClusterStateEntity clusterStateEntity) {
     entityManagerProvider.get().refresh(clusterStateEntity);
   }
@@ -49,7 +51,7 @@ public class ClusterStateDAO {
 
   @Transactional
   public void remove(ClusterStateEntity clusterStateEntity) {
-    entityManagerProvider.get().remove(clusterStateEntity);
+    entityManagerProvider.get().remove(merge(clusterStateEntity));
   }
 
   @Transactional

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ExecutionCommandDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ExecutionCommandDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ExecutionCommandDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ExecutionCommandDAO.java Wed Nov  7 08:13:12 2012
@@ -29,8 +29,9 @@ public class ExecutionCommandDAO {
 
   @Inject
   Provider<EntityManager> entityManagerProvider;
-  
-  public ExecutionCommandEntity findByPK(int taskId) {
+
+  @Transactional
+  public ExecutionCommandEntity findByPK(long taskId) {
     return entityManagerProvider.get().find(ExecutionCommandEntity.class, taskId);
   }
 
@@ -46,7 +47,7 @@ public class ExecutionCommandDAO {
 
   @Transactional
   public void remove(ExecutionCommandEntity stageEntity) {
-    entityManagerProvider.get().remove(stageEntity);
+    entityManagerProvider.get().remove(merge(stageEntity));
   }
 
   @Transactional

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java Wed Nov  7 08:13:12 2012
@@ -30,10 +30,12 @@ public class HostComponentDesiredStateDA
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
+  @Transactional
   public HostComponentDesiredStateEntity findByPK(HostComponentDesiredStateEntityPK primaryKey) {
     return entityManagerProvider.get().find(HostComponentDesiredStateEntity.class, primaryKey);
   }
 
+  @Transactional
   public void refresh(HostComponentDesiredStateEntity hostComponentDesiredStateEntity) {
     entityManagerProvider.get().refresh(hostComponentDesiredStateEntity);
   }
@@ -50,7 +52,7 @@ public class HostComponentDesiredStateDA
 
   @Transactional
   public void remove(HostComponentDesiredStateEntity hostComponentDesiredStateEntity) {
-    entityManagerProvider.get().remove(hostComponentDesiredStateEntity);
+    entityManagerProvider.get().remove(merge(hostComponentDesiredStateEntity));
   }
 
   @Transactional

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentMappingDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentMappingDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentMappingDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentMappingDAO.java Wed Nov  7 08:13:12 2012
@@ -30,10 +30,12 @@ public class HostComponentMappingDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
+  @Transactional
   public HostComponentMappingEntity findByPK(HostComponentStateEntityPK primaryKey) {
     return entityManagerProvider.get().find(HostComponentMappingEntity.class, primaryKey);
   }
 
+  @Transactional
   public void refresh(HostComponentMappingEntity hostComponentMappingEntity) {
     entityManagerProvider.get().refresh(hostComponentMappingEntity);
   }
@@ -50,7 +52,7 @@ public class HostComponentMappingDAO {
 
   @Transactional
   public void remove(HostComponentMappingEntity hostComponentMappingEntity) {
-    entityManagerProvider.get().remove(hostComponentMappingEntity);
+    entityManagerProvider.get().remove(merge(hostComponentMappingEntity));
   }
 
   @Transactional

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java Wed Nov  7 08:13:12 2012
@@ -30,10 +30,12 @@ public class HostComponentStateDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
+  @Transactional
   public HostComponentStateEntity findByPK(HostComponentStateEntityPK primaryKey) {
     return entityManagerProvider.get().find(HostComponentStateEntity.class, primaryKey);
   }
 
+  @Transactional
   public void refresh(HostComponentStateEntity hostComponentStateEntity) {
     entityManagerProvider.get().refresh(hostComponentStateEntity);
   }
@@ -50,7 +52,7 @@ public class HostComponentStateDAO {
 
   @Transactional
   public void remove(HostComponentStateEntity hostComponentStateEntity) {
-    entityManagerProvider.get().remove(hostComponentStateEntity);
+    entityManagerProvider.get().remove(merge(hostComponentStateEntity));
   }
 
   @Transactional

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.java Wed Nov  7 08:13:12 2012
@@ -35,10 +35,12 @@ public class HostDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
+  @Transactional
   public HostEntity findByName(String hostName) {
     return entityManagerProvider.get().find(HostEntity.class, hostName);
   }
 
+  @Transactional
   public List<HostEntity> findAll() {
     TypedQuery<HostEntity> query = entityManagerProvider.get().createQuery("SELECT host FROM HostEntity host", HostEntity.class);
     try {
@@ -48,6 +50,7 @@ public class HostDAO {
     }
   }
 
+  @Transactional
   public List<HostEntity> findByStage(StageEntity stageEntity) {
     TypedQuery<HostEntity> query = entityManagerProvider.get().createQuery(
         "SELECT DISTINCT host FROM HostEntity host JOIN host.hostRoleCommandEntities command JOIN command.stage stage " +
@@ -64,6 +67,7 @@ public class HostDAO {
    * Refreshes entity state from database
    * @param hostEntity entity to refresh
    */
+  @Transactional
   public void refresh(HostEntity hostEntity) {
     entityManagerProvider.get().refresh(hostEntity);
   }
@@ -80,7 +84,7 @@ public class HostDAO {
 
   @Transactional
   public void remove(HostEntity hostEntity) {
-    entityManagerProvider.get().remove(hostEntity);
+    entityManagerProvider.get().remove(merge(hostEntity));
   }
 
   @Transactional

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java Wed Nov  7 08:13:12 2012
@@ -26,12 +26,17 @@ import org.apache.ambari.server.actionma
 import org.apache.ambari.server.orm.entities.HostEntity;
 import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
 import org.apache.ambari.server.orm.entities.StageEntity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
 import javax.persistence.TypedQuery;
+
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.Set;
 
 public class HostRoleCommandDAO {
 
@@ -39,11 +44,24 @@ public class HostRoleCommandDAO {
   Provider<EntityManager> entityManagerProvider;
   @Inject
   DaoUtils daoUtils;
+  private static Logger LOG = LoggerFactory.getLogger(HostRoleCommandDAO.class);
 
-  public HostRoleCommandEntity findByPK(int taskId) {
+  @Transactional
+  public HostRoleCommandEntity findByPK(long taskId) {
     return entityManagerProvider.get().find(HostRoleCommandEntity.class, taskId);
   }
 
+  @Transactional
+  public List<HostRoleCommandEntity> findByPKs(Collection<Long> taskIds) {
+    LOG.info("HostRole Command Entity  " + entityManagerProvider.get());
+    TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery(
+        "SELECT task FROM HostRoleCommandEntity task WHERE task.taskId IN ?1 " +
+            "ORDER BY task.taskId",
+        HostRoleCommandEntity.class);
+    return daoUtils.selectList(query, taskIds);
+  }
+
+  @Transactional
   public List<HostRoleCommandEntity> findSortedCommandsByStageAndHost(StageEntity stageEntity, HostEntity hostEntity) {
     TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery("SELECT hostRoleCommand " +
         "FROM HostRoleCommandEntity hostRoleCommand " +
@@ -52,16 +70,29 @@ public class HostRoleCommandDAO {
     return daoUtils.selectList(query, stageEntity, hostEntity);
   }
 
+  @Transactional
   public List<HostRoleCommandEntity> findByHostRole(String hostName, long requestId, long stageId, Role role) {
+    LOG.info("HostRole Command Entity  " + entityManagerProvider.get());
     TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery("SELECT command " +
         "FROM HostRoleCommandEntity command " +
         "WHERE command.hostName=?1 AND command.requestId=?2 " +
-        "AND command.stageId=?3 AND command.role=?4", HostRoleCommandEntity.class);
+        "AND command.stageId=?3 AND command.role=?4 " +
+        "ORDER BY command.taskId", HostRoleCommandEntity.class);
 
     return daoUtils.selectList(query, hostName, requestId, stageId, role);
   }
 
   @Transactional
+  public List<Long> getRequests() {
+    String queryStr = "SELECT DISTINCT command.requestId " +
+        "FROM HostRoleCommandEntity command ORDER BY command.requestId DESC";
+    TypedQuery<Long> query = entityManagerProvider.get().createQuery(queryStr,
+        Long.class);
+    query.setMaxResults(20);
+    return daoUtils.selectList(query);
+  }
+
+  @Transactional
   public int updateStatusByRequestId(long requestId, HostRoleStatus target, Collection<HostRoleStatus> sources) {
     Query query = entityManagerProvider.get().createQuery("UPDATE HostRoleCommandEntity command " +
         "SET command.status=?1 " +
@@ -71,18 +102,28 @@ public class HostRoleCommandDAO {
   }
 
   @Transactional
+  public List<HostRoleCommandEntity> findByRequest(long requestId) {
+    TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery("SELECT command " +
+        "FROM HostRoleCommandEntity command " +
+        "WHERE command.requestId=?1 ORDER BY command.taskId", HostRoleCommandEntity.class);
+    return daoUtils.selectList(query, requestId);
+  }
+
+  @Transactional
   public void create(HostRoleCommandEntity stageEntity) {
     entityManagerProvider.get().persist(stageEntity);
   }
 
   @Transactional
   public HostRoleCommandEntity merge(HostRoleCommandEntity stageEntity) {
-    return entityManagerProvider.get().merge(stageEntity);
+    HostRoleCommandEntity entity = entityManagerProvider.get().merge(stageEntity);
+    return entity;
+
   }
 
   @Transactional
   public void remove(HostRoleCommandEntity stageEntity) {
-    entityManagerProvider.get().remove(stageEntity);
+    entityManagerProvider.get().remove(merge(stageEntity));
   }
 
   @Transactional

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostStateDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostStateDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostStateDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostStateDAO.java Wed Nov  7 08:13:12 2012
@@ -29,10 +29,12 @@ public class HostStateDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
+  @Transactional
   public HostStateEntity findByHostName(String hostName) {
     return entityManagerProvider.get().find(HostStateEntity.class, hostName);
   }
 
+  @Transactional
   public void refresh(HostStateEntity hostStateEntity) {
     entityManagerProvider.get().refresh(hostStateEntity);
   }
@@ -49,7 +51,7 @@ public class HostStateDAO {
 
   @Transactional
   public void remove(HostStateEntity hostStateEntity) {
-    entityManagerProvider.get().remove(hostStateEntity);
+    entityManagerProvider.get().remove(merge(hostStateEntity));
   }
 
   @Transactional

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RoleDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RoleDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RoleDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RoleDAO.java Wed Nov  7 08:13:12 2012
@@ -29,12 +29,14 @@ public class RoleDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
+  @Transactional
   public RoleEntity findByName(String roleName) {
-    return entityManagerProvider.get().find(RoleEntity.class, roleName);
+    return entityManagerProvider.get().find(RoleEntity.class, roleName.toLowerCase());
   }
 
   @Transactional
   public void create(RoleEntity role) {
+    role.setRoleName(role.getRoleName().toLowerCase());
     entityManagerProvider.get().persist(role);
   }
 
@@ -45,7 +47,7 @@ public class RoleDAO {
 
   @Transactional
   public void remove(RoleEntity role) {
-    entityManagerProvider.get().remove(role);
+    entityManagerProvider.get().remove(merge(role));
   }
 
   @Transactional

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RoleSuccessCriteriaDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RoleSuccessCriteriaDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RoleSuccessCriteriaDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RoleSuccessCriteriaDAO.java Wed Nov  7 08:13:12 2012
@@ -31,7 +31,9 @@ public class RoleSuccessCriteriaDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
+  @Transactional
   public RoleSuccessCriteriaEntity findByPK(RoleSuccessCriteriaEntityPK roleSuccessCriteriaEntityPK) {
+    entityManagerProvider.get().clear();
     return entityManagerProvider.get().find(RoleSuccessCriteriaEntity.class, roleSuccessCriteriaEntityPK);
   }
 
@@ -47,7 +49,7 @@ public class RoleSuccessCriteriaDAO {
 
   @Transactional
   public void remove(RoleSuccessCriteriaEntity stageEntity) {
-    entityManagerProvider.get().remove(stageEntity);
+    entityManagerProvider.get().remove(merge(stageEntity));
   }
 
   @Transactional

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentConfigDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentConfigDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentConfigDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentConfigDAO.java Wed Nov  7 08:13:12 2012
@@ -29,10 +29,12 @@ public class ServiceComponentConfigDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
+  @Transactional
   public ServiceComponentConfigEntity findByPK(Integer primaryKey) {
     return entityManagerProvider.get().find(ServiceComponentConfigEntity.class, primaryKey);
   }
 
+  @Transactional
   public void refresh(ServiceComponentConfigEntity serviceComponentConfigEntity) {
     entityManagerProvider.get().refresh(serviceComponentConfigEntity);
   }
@@ -49,7 +51,7 @@ public class ServiceComponentConfigDAO {
 
   @Transactional
   public void remove(ServiceComponentConfigEntity serviceComponentConfigEntity) {
-    entityManagerProvider.get().remove(serviceComponentConfigEntity);
+    entityManagerProvider.get().remove(merge(serviceComponentConfigEntity));
   }
 
   @Transactional

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java Wed Nov  7 08:13:12 2012
@@ -30,10 +30,12 @@ public class ServiceComponentDesiredStat
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
+  @Transactional
   public ServiceComponentDesiredStateEntity findByPK(ServiceComponentDesiredStateEntityPK primaryKey) {
     return entityManagerProvider.get().find(ServiceComponentDesiredStateEntity.class, primaryKey);
   }
 
+  @Transactional
   public void refresh(ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity) {
     entityManagerProvider.get().refresh(serviceComponentDesiredStateEntity);
   }
@@ -50,7 +52,7 @@ public class ServiceComponentDesiredStat
 
   @Transactional
   public void remove(ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity) {
-    entityManagerProvider.get().remove(serviceComponentDesiredStateEntity);
+    entityManagerProvider.get().remove(merge(serviceComponentDesiredStateEntity));
   }
 
   @Transactional

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentHostConfigDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentHostConfigDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentHostConfigDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentHostConfigDAO.java Wed Nov  7 08:13:12 2012
@@ -29,10 +29,12 @@ public class ServiceComponentHostConfigD
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
+  @Transactional
   public ServiceComponentHostConfigEntity findByPK(Integer primaryKey) {
     return entityManagerProvider.get().find(ServiceComponentHostConfigEntity.class, primaryKey);
   }
 
+  @Transactional
   public void refresh(ServiceComponentHostConfigEntity serviceComponentHostConfigEntity) {
     entityManagerProvider.get().refresh(serviceComponentHostConfigEntity);
   }
@@ -49,7 +51,7 @@ public class ServiceComponentHostConfigD
 
   @Transactional
   public void remove(ServiceComponentHostConfigEntity serviceComponentHostConfigEntity) {
-    entityManagerProvider.get().remove(serviceComponentHostConfigEntity);
+    entityManagerProvider.get().remove(merge(serviceComponentHostConfigEntity));
   }
 
   @Transactional

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigDAO.java Wed Nov  7 08:13:12 2012
@@ -32,10 +32,12 @@ public class ServiceConfigDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
+  @Transactional
   public ServiceConfigEntity findByPK(Integer primaryKey) {
     return entityManagerProvider.get().find(ServiceConfigEntity.class, primaryKey);
   }
 
+  @Transactional
   public List<ServiceConfigEntity> findByClusterService(ClusterServiceEntity clusterServiceEntity) {
     TypedQuery<ServiceConfigEntity> query = entityManagerProvider.get().createQuery("select config " +
             "from ServiceConfigEntity config " +
@@ -45,12 +47,14 @@ public class ServiceConfigDAO {
     return query.getResultList();
   }
 
+  @Transactional
   public List<ServiceConfigEntity> findAll() {
     TypedQuery<ServiceConfigEntity> query = entityManagerProvider.get().createQuery("select c from ServiceConfigEntity c"
             , ServiceConfigEntity.class);
     return query.getResultList();
   }
 
+  @Transactional
   public void refresh(ServiceConfigEntity serviceConfigEntity) {
     entityManagerProvider.get().refresh(serviceConfigEntity);
   }
@@ -67,7 +71,7 @@ public class ServiceConfigDAO {
 
   @Transactional
   public void remove(ServiceConfigEntity serviceConfigEntity) {
-    entityManagerProvider.get().remove(serviceConfigEntity);
+    entityManagerProvider.get().remove(merge(serviceConfigEntity));
   }
 
   @Transactional

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceDesiredStateDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceDesiredStateDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceDesiredStateDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceDesiredStateDAO.java Wed Nov  7 08:13:12 2012
@@ -30,10 +30,12 @@ public class ServiceDesiredStateDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
+  @Transactional
   public ServiceDesiredStateEntity findByPK(ServiceDesiredStateEntityPK primaryKey) {
     return entityManagerProvider.get().find(ServiceDesiredStateEntity.class, primaryKey);
   }
 
+  @Transactional
   public void refresh(ServiceDesiredStateEntity serviceDesiredStateEntity) {
     entityManagerProvider.get().refresh(serviceDesiredStateEntity);
   }
@@ -50,7 +52,7 @@ public class ServiceDesiredStateDAO {
 
   @Transactional
   public void remove(ServiceDesiredStateEntity serviceDesiredStateEntity) {
-    entityManagerProvider.get().remove(serviceDesiredStateEntity);
+    entityManagerProvider.get().remove(merge(serviceDesiredStateEntity));
   }
 
   @Transactional

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/StageDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/StageDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/StageDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/StageDAO.java Wed Nov  7 08:13:12 2012
@@ -38,6 +38,7 @@ public class StageDAO {
   @Inject
   DaoUtils daoUtils;
 
+  @Transactional
   public StageEntity findByPK(StageEntityPK stageEntityPK) {
     return entityManagerProvider.get().find(StageEntity.class, stageEntityPK);
   }
@@ -54,6 +55,7 @@ public class StageDAO {
     }
   }
 
+  @Transactional
   public StageEntity findByActionId(String actionId) {
     long[] ids = StageUtils.getRequestStage(actionId);
     StageEntityPK pk = new StageEntityPK();
@@ -62,15 +64,21 @@ public class StageDAO {
     return findByPK(pk);
   }
 
+  @Transactional
   public List<StageEntity> findByRequestId(long requestId) {
-    TypedQuery<StageEntity> query = entityManagerProvider.get().createQuery("SELECT stage FROM StageEntity stage WHERE stage.requestId=?1", StageEntity.class);
+    TypedQuery<StageEntity> query = entityManagerProvider.get().createQuery("SELECT stage " +
+        "FROM StageEntity stage " +
+        "WHERE stage.requestId=?1 " +
+        "ORDER BY stage.stageId", StageEntity.class);
     return daoUtils.selectList(query, requestId);
   }
 
+  @Transactional
   public List<StageEntity> findByCommandStatuses(Collection<HostRoleStatus> statuses) {
     TypedQuery<StageEntity> query = entityManagerProvider.get().createQuery("SELECT stage " +
         "FROM StageEntity stage JOIN stage.hostRoleCommands command " +
-        "WHERE command.status IN ?1", StageEntity.class);
+        "WHERE command.status IN ?1 " +
+        "ORDER BY stage.requestId, stage.stageId", StageEntity.class);
     return daoUtils.selectList(query, statuses);
   }
 
@@ -86,7 +94,7 @@ public class StageDAO {
 
   @Transactional
   public void remove(StageEntity stageEntity) {
-    entityManagerProvider.get().remove(stageEntity);
+    entityManagerProvider.get().remove(merge(stageEntity));
   }
 
   @Transactional

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UserDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UserDAO.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UserDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UserDAO.java Wed Nov  7 08:13:12 2012
@@ -26,11 +26,14 @@ import org.apache.ambari.server.orm.enti
 import javax.persistence.EntityManager;
 import javax.persistence.NoResultException;
 import javax.persistence.TypedQuery;
+import java.util.List;
 
 public class UserDAO {
 
   @Inject
   Provider<EntityManager> entityManagerProvider;
+  @Inject
+  DaoUtils daoUtils;
 
   @Transactional
   public UserEntity findByPK(UserEntityPK userPK) {
@@ -39,6 +42,12 @@ public class UserDAO {
   }
 
   @Transactional
+  public List<UserEntity> findAll() {
+    TypedQuery<UserEntity> query = entityManagerProvider.get().createQuery("SELECT user FROM UserEntity user", UserEntity.class);
+    return daoUtils.selectList(query);
+  }
+
+  @Transactional
   public UserEntity findLocalUserByName(String userName) {
     TypedQuery<UserEntity> query = entityManagerProvider.get().createNamedQuery("localUserByName", UserEntity.class);
     query.setParameter("username", userName.toLowerCase());
@@ -49,6 +58,7 @@ public class UserDAO {
     }
   }
 
+  @Transactional
   public UserEntity findLdapUserByName(String userName) {
     TypedQuery<UserEntity> query = entityManagerProvider.get().createNamedQuery("ldapUserByName", UserEntity.class);
     query.setParameter("username", userName.toLowerCase());
@@ -72,8 +82,8 @@ public class UserDAO {
   }
 
   @Transactional
-  public void remove(UserEntity userName) {
-    entityManagerProvider.get().remove(userName);
+  public void remove(UserEntity user) {
+    entityManagerProvider.get().remove(merge(user));
   }
 
   @Transactional

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ExecutionCommandEntity.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ExecutionCommandEntity.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ExecutionCommandEntity.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ExecutionCommandEntity.java Wed Nov  7 08:13:12 2012
@@ -23,15 +23,15 @@ import javax.persistence.*;
 @Table(name = "execution_command", schema = "ambari", catalog = "")
 @Entity
 public class ExecutionCommandEntity {
-  private Integer taskId;
+  private Long taskId;
 
   @Column(name = "task_id", insertable = false, updatable = false, nullable = false)
   @Id
-  public Integer getTaskId() {
+  public Long getTaskId() {
     return taskId;
   }
 
-  public void setTaskId(Integer taskId) {
+  public void setTaskId(Long taskId) {
     this.taskId = taskId;
   }
 

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentConfigMappingEntityPK.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentConfigMappingEntityPK.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentConfigMappingEntityPK.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentConfigMappingEntityPK.java Wed Nov  7 08:13:12 2012
@@ -18,17 +18,14 @@
 package org.apache.ambari.server.orm.entities;
 
 import javax.persistence.Column;
-import javax.persistence.Entity;
 import javax.persistence.Id;
-import javax.persistence.IdClass;
-import javax.persistence.Table;
 
 public class HostComponentConfigMappingEntityPK {
   private Long clusterId;
   private String serviceName;
   private String componentName;
   private String hostName;
-  
+
   @Id
   @Column(name = "cluster_id", insertable = true, updatable = true, nullable = false, length = 10)
   public Long getClusterId() {
@@ -48,28 +45,28 @@ public class HostComponentConfigMappingE
   public void setServiceName(String serviceName) {
     this.serviceName = serviceName;
   }
-  
+
   @Column(name = "component_name", insertable = true, updatable = true, nullable = false)
   @Id
   public String getComponentName() {
     return componentName;
   }
-  
+
   public void setComponentName(String name) {
     componentName = name;
   }
-  
+
   @Column(name = "host_name", insertable = true, updatable = true, nullable = false)
   @Id
   public String getHostName() {
     return hostName;
   }
-  
+
   public void setHostName(String name) {
     hostName = name;
   }
-  
-  
+
+
   @Override
   public boolean equals(Object o) {
     if (this == o) return true;
@@ -92,7 +89,7 @@ public class HostComponentConfigMappingE
     result = 31 * result + (componentName != null ? componentName.hashCode() : 0);
     result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
     return result;
-  }  
-  
-  
+  }
+
+
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java Wed Nov  7 08:13:12 2012
@@ -25,18 +25,19 @@ import javax.persistence.*;
 
 @Table(name = "host_role_command", schema = "ambari", catalog = "")
 @Entity
+@Cacheable(false)
 @SequenceGenerator(name = "ambari.host_role_command_task_id_seq", allocationSize = 1)
 public class HostRoleCommandEntity {
-  private Integer taskId;
+  private Long taskId;
 
   @Column(name = "task_id")
   @Id
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ambari.host_role_command_task_id_seq")
-  public Integer getTaskId() {
+  public Long getTaskId() {
     return taskId;
   }
 
-  public void setTaskId(Integer taskId) {
+  public void setTaskId(Long taskId) {
     this.taskId = taskId;
   }
 
@@ -138,7 +139,7 @@ public class HostRoleCommandEntity {
 
   private String stdError = "";
 
-  @Column(name = "std_error", nullable = false)
+  @Column(name = "std_error", nullable = false, length=32000)
   @Basic
   public String getStdError() {
     return stdError;
@@ -150,7 +151,7 @@ public class HostRoleCommandEntity {
 
   private String stdOut = "";
 
-  @Column(name = "std_out", nullable = false)
+  @Column(name = "std_out", nullable = false, length=32000)
   @Basic
   public String getStdOut() {
     return stdOut;

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/UserEntity.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/UserEntity.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/UserEntity.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/UserEntity.java Wed Nov  7 08:13:12 2012
@@ -109,7 +109,7 @@ public class UserEntity {
           joinColumns = {@JoinColumn(name = "user_name", referencedColumnName = "user_name"),
                   @JoinColumn(name = "ldap_user", referencedColumnName = "ldap_user")},
           inverseJoinColumns = {@JoinColumn(name = "role_name", referencedColumnName = "role_name")})
-  @ManyToMany
+  @ManyToMany(cascade = CascadeType.ALL)
   public Set<RoleEntity> getRoleEntities() {
     return roleEntities;
   }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/CertificateManager.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/CertificateManager.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/CertificateManager.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/CertificateManager.java Wed Nov  7 08:13:12 2012
@@ -21,6 +21,7 @@ import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.nio.charset.Charset;
 import java.text.MessageFormat;
 import java.util.Map;
 
@@ -96,13 +97,14 @@ public class CertificateManager {
    * @return command execution exit code
    */
   private int runCommand(String command) {
-	  LOG.info("Executing command:" + command);
-	  String line = null;
-      Process process = null;
-      try {
-        process = Runtime.getRuntime().exec(command);
-        BufferedReader br = new BufferedReader(new InputStreamReader(
-            process.getInputStream()));
+    LOG.info("Executing command:" + command);
+    String line = null;
+    Process process = null;
+    BufferedReader br= null;
+    try {
+      process = Runtime.getRuntime().exec(command);
+      br = new BufferedReader(new InputStreamReader(
+          process.getInputStream(), Charset.forName("UTF8")));
 
       while ((line = br.readLine()) != null) {
         LOG.info(line);
@@ -110,14 +112,23 @@ public class CertificateManager {
 
       try {
         process.waitFor();
-        ShellCommandUtil.LogOpenSslExitCode(command, process.exitValue());
+        ShellCommandUtil.logOpenSslExitCode(command, process.exitValue());
         return process.exitValue(); //command is executed
       } catch (InterruptedException e) {
         e.printStackTrace();
       }
     } catch (IOException e) {
       e.printStackTrace();
+    } finally {
+      if (br != null) {
+        try {
+          br.close();
+        } catch (IOException ioe) {
+          ioe.printStackTrace();
+        }
+      }
     }
+
     return -1;//some exception occurred
 
   }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthoritiesPopulator.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthoritiesPopulator.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthoritiesPopulator.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthoritiesPopulator.java Wed Nov  7 08:13:12 2012
@@ -68,7 +68,7 @@ public class AmbariLdapAuthoritiesPopula
       newUser.setLdapUser(true);
       newUser.setUserName(username);
 
-      String roleName = (configuration.getConfigsMap().get(Configuration.LDAP_USER_DEFAULT_ROLE_KEY));
+      String roleName = (configuration.getConfigsMap().get(Configuration.USER_ROLE_NAME_KEY));
       log.info("Using default role name " + roleName);
 
       RoleEntity role = roleDAO.findByName(roleName);

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariLocalUserDetailsService.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariLocalUserDetailsService.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariLocalUserDetailsService.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariLocalUserDetailsService.java Wed Nov  7 08:13:12 2012
@@ -66,7 +66,7 @@ public class AmbariLocalUserDetailsServi
     if (user == null) {
       log.info("user not found ");
       throw new UsernameNotFoundException("Username " + username + " not found");
-    } else if (user.getRoleEntities().isEmpty()) {
+    }else if (user.getRoleEntities().isEmpty()) {
       log.info("No authorities for user");
       throw new UsernameNotFoundException("Username " + username + " has no roles");
     }

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/User.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/User.java?rev=1406489&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/User.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/User.java Wed Nov  7 08:13:12 2012
@@ -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
+ *
+ *     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.server.security.authorization;
+
+import org.apache.ambari.server.orm.entities.RoleEntity;
+import org.apache.ambari.server.orm.entities.UserEntity;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+
+/**
+ * Describes user of web-services
+ */
+public class User {
+  final String userName;
+  final boolean ldapUser;
+  final Date createTime;
+  final Collection<String> roles = new ArrayList<String>();
+
+  User(UserEntity userEntity) {
+    userName = userEntity.getUserName();
+    createTime = userEntity.getCreateTime();
+    ldapUser = userEntity.getLdapUser();
+    for (RoleEntity roleEntity : userEntity.getRoleEntities()) {
+      roles.add(roleEntity.getRoleName());
+    }
+  }
+
+  public String getUserName() {
+    return userName;
+  }
+
+  public boolean isLdapUser() {
+    return ldapUser;
+  }
+
+  public Date getCreateTime() {
+    return createTime;
+  }
+
+  public Collection<String> getRoles() {
+    return roles;
+  }
+
+  @Override
+  public String toString() {
+    return (ldapUser ? "[LDAP]" : "[LOCAL]") + userName;
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/Users.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/Users.java?rev=1406489&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/Users.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/Users.java Wed Nov  7 08:13:12 2012
@@ -0,0 +1,229 @@
+/*
+ * 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.server.security.authorization;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.orm.dao.RoleDAO;
+import org.apache.ambari.server.orm.dao.UserDAO;
+import org.apache.ambari.server.orm.entities.RoleEntity;
+import org.apache.ambari.server.orm.entities.UserEntity;
+import org.apache.ambari.server.orm.entities.UserEntityPK;
+import org.springframework.security.crypto.password.PasswordEncoder;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+
+/**
+ * Provides high-level access to Users and Roles in database
+ */
+@Singleton
+public class Users {
+
+  @Inject
+  protected UserDAO userDAO;
+  @Inject
+  protected RoleDAO roleDAO;
+  @Inject
+  protected PasswordEncoder passwordEncoder;
+  @Inject
+  protected Configuration configuration;
+
+
+  public List<User> getAllUsers() {
+    List<UserEntity> userEntities = userDAO.findAll();
+    List<User> users = new ArrayList<User>(userEntities.size());
+
+    for (UserEntity userEntity : userEntities) {
+      users.add(new User(userEntity));
+    }
+
+    return users;
+  }
+
+  public User getLocalUser(String userName) throws AmbariException{
+    UserEntity userEntity = userDAO.findLocalUserByName(userName);
+    if (userEntity == null) {
+      throw new AmbariException("User doesn't exist");
+    }
+    return new User(userEntity);
+  }
+
+  public User getLdapUser(String userName) throws AmbariException{
+    UserEntity userEntity = userDAO.findLdapUserByName(userName);
+    if (userEntity == null) {
+      throw new AmbariException("User doesn't exist");
+    }
+    return new User(userEntity);
+  }
+
+  /**
+   * Modifies password of local user
+   * @throws AmbariException
+   */
+  public synchronized void modifyPassword(String userName, String oldPassword, String newPassword) throws AmbariException {
+    UserEntity userEntity = userDAO.findLocalUserByName(userName);
+    if (userEntity != null) {
+      if (passwordEncoder.matches(oldPassword, userEntity.getUserPassword())) {
+        userEntity.setUserPassword(passwordEncoder.encode(newPassword));
+        userDAO.merge(userEntity);
+      } else {
+        throw new AmbariException("Wrong password provided");
+      }
+
+    } else {
+      userEntity = userDAO.findLdapUserByName(userName);
+      if (userEntity != null) {
+        throw new AmbariException("Password of LDAP user cannot be modified");
+      } else {
+        throw new AmbariException("User " + userName + " not found");
+      }
+    }
+  }
+
+  /**
+   * Creates new local user with provided userName and password
+   */
+  @Transactional
+  public synchronized void createUser(String userName, String password) {
+    UserEntity userEntity = new UserEntity();
+    userEntity.setUserName(userName);
+    userEntity.setUserPassword(passwordEncoder.encode(password));
+    userEntity.setRoleEntities(new HashSet<RoleEntity>());
+
+    RoleEntity roleEntity = roleDAO.findByName(getUserRole());
+    if (roleEntity == null) {
+      createRole(getUserRole());
+    }
+
+    userEntity.getRoleEntities().add(roleDAO.findByName(getUserRole()));
+
+    userDAO.create(userEntity);
+  }
+
+  @Transactional
+  public synchronized void removeUser(User user) throws AmbariException {
+    UserEntity userEntity = userDAO.findByPK(getPK(user));
+    if (userEntity != null) {
+      userDAO.remove(userEntity);
+    } else {
+      throw new AmbariException("User " + user + " doesn't exist");
+    }
+  }
+
+  /**
+   * Grants ADMIN role to provided user
+   * @throws AmbariException
+   */
+  public synchronized void promoteToAdmin(User user) throws AmbariException{
+    addRoleToUser(user, getAdminRole());
+  }
+
+  /**
+   * Removes ADMIN role form provided user
+   * @throws AmbariException
+   */
+  public synchronized void demoteAdmin(User user) throws AmbariException {
+    removeRoleFromUser(user, getAdminRole());
+  }
+
+  @Transactional
+  public synchronized void addRoleToUser(User user, String role) throws AmbariException {
+    UserEntityPK pk = getPK(user);
+
+    UserEntity userEntity = userDAO.findByPK(pk);
+    if (userEntity == null) {
+      throw new AmbariException("User " + user + " doesn't exist");
+    }
+
+    RoleEntity roleEntity = roleDAO.findByName(role);
+    if (roleEntity == null) {
+      throw new AmbariException("Role " + role + " doesn't exist");
+    }
+
+    if (!userEntity.getRoleEntities().contains(roleEntity)) {
+      userEntity.getRoleEntities().add(roleEntity);
+      userDAO.merge(userEntity);
+    } else {
+      throw new AmbariException("User " + user + " already owns role " + role);
+    }
+
+  }
+
+  @Transactional
+  public synchronized void removeRoleFromUser(User user, String role) throws AmbariException {
+    UserEntityPK pk = getPK(user);
+    UserEntity userEntity = userDAO.findByPK(pk);
+    if (userEntity == null) {
+      throw new AmbariException("User " + user + " doesn't exist");
+    }
+
+    RoleEntity roleEntity = roleDAO.findByName(role);
+    if (roleEntity == null) {
+      throw new AmbariException("Role " + role + " doesn't exist");
+    }
+
+    if (userEntity.getRoleEntities().contains(roleEntity)) {
+      userEntity.getRoleEntities().remove(roleEntity);
+      userDAO.merge(userEntity);
+    } else {
+      throw new AmbariException("User " + user + " doesn't own role " + role);
+    }
+
+  }
+
+  public String getUserRole() {
+    return configuration.getConfigsMap().get(Configuration.USER_ROLE_NAME_KEY);
+  }
+
+  public String getAdminRole() {
+    return configuration.getConfigsMap().get(Configuration.ADMIN_ROLE_NAME_KEY);
+  }
+
+  /**
+   * Creates new role
+   */
+  public void createRole(String role) {
+    RoleEntity roleEntity = new RoleEntity();
+    roleEntity.setRoleName(role);
+    roleDAO.create(roleEntity);
+  }
+
+  /**
+   * Creates ADMIN adn USER roles if not present
+   */
+  public synchronized void createDefaultRoles() {
+    if (roleDAO.findByName(getUserRole()) == null) {
+      createRole(getUserRole());
+    }
+    if (roleDAO.findByName(getAdminRole()) == null) {
+      createRole(getAdminRole());
+    }
+  }
+
+  private UserEntityPK getPK(User user) {
+    UserEntityPK pk = new UserEntityPK();
+    pk.setUserName(user.getUserName());
+    pk.setLdapUser(user.isLdapUser());
+    return pk;
+  }
+}

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/AgentVersion.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/AgentVersion.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/AgentVersion.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/AgentVersion.java Wed Nov  7 08:13:12 2012
@@ -45,7 +45,7 @@ public class AgentVersion {
       return true;
     }
     AgentVersion a = (AgentVersion) object;
-    return a.equals(this.version);
+    return a.version.equals(this.version);
   }
 
   @Override

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java Wed Nov  7 08:13:12 2012
@@ -72,13 +72,13 @@ public interface Cluster {
    * Get Stack Version
    * @return
    */
-  public StackVersion getDesiredStackVersion();
+  public StackId getDesiredStackVersion();
 
   /**
    * Set stack version
    * @param stackVersion
    */
-  public void setDesiredStackVersion(StackVersion stackVersion);
+  public void setDesiredStackVersion(StackId stackVersion);
 
   public Map<String, Config> getDesiredConfigsByType(String configType);
 

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ComponentInfo.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ComponentInfo.java?rev=1406489&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ComponentInfo.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ComponentInfo.java Wed Nov  7 08:13:12 2012
@@ -0,0 +1,49 @@
+/**
+ * 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.server.state;
+
+public class ComponentInfo {
+  private String name;
+  private String category;
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String getCategory() {
+    return category;
+  }
+
+  public void setCategory(String category) {
+    this.category = category;
+  }
+
+  public boolean isClient() {
+    return "CLIENT".equals(category);
+  }
+
+  public boolean isMaster() {
+    return "MASTER".equals(category);
+  }
+
+}

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java Wed Nov  7 08:13:12 2012
@@ -118,10 +118,10 @@ public class ConfigImpl implements Confi
     entity.setClusterEntity(clusterEntity);
     entity.setClusterId(Long.valueOf(cluster.getClusterId()));
     entity.setType(type);
-    entity.setTag(versionTag);
+    entity.setTag(getVersionTag());
     entity.setTimestamp(new Date().getTime());
     
-    entity.setData(gson.toJson(properties));
+    entity.setData(gson.toJson(getProperties()));
     clusterDAO.createConfig(entity);
 
     clusterEntity.getClusterConfigEntities().add(entity);

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java Wed Nov  7 08:13:12 2012
@@ -25,7 +25,6 @@ import org.apache.ambari.server.agent.Di
 import org.apache.ambari.server.agent.HostInfo;
 import org.apache.ambari.server.controller.HostResponse;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
-import org.apache.ambari.server.state.job.Job;
 
 public interface Host {
 
@@ -212,13 +211,6 @@ public interface Host {
   public void setAgentVersion(AgentVersion agentVersion);
 
   /**
-   * Get the list of Jobs that are currently being tracked at the
-   * Host level
-   * @return List of Jobs
-   */
-  public List<Job> getJobs();
-
-  /**
    * Get Current Host State
    * @return HostState
    */

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/RepositoryInfo.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/RepositoryInfo.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/RepositoryInfo.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/RepositoryInfo.java Wed Nov  7 08:13:12 2012
@@ -19,46 +19,90 @@
 package org.apache.ambari.server.state;
 
 public class RepositoryInfo {
-  private String url;
-  private String os;
-  private String description;
-//  private String gpgKey;
+  private String baseUrl;
+  private String osType;
+  private String repoId;
+  private String repoName;
+  private String mirrorsList;
 
-  public String getUrl() {
-    return url;
+  /**
+   * @return the baseUrl
+   */
+  public String getBaseUrl() {
+    return baseUrl;
   }
 
-  public void setUrl(String url) {
-    this.url = url;
+  /**
+   * @param baseUrl the baseUrl to set
+   */
+  public void setBaseUrl(String baseUrl) {
+    this.baseUrl = baseUrl;
   }
 
-//  public String getGpgKey() {
-//    return gpgKey;
-//  }
-//
-//  public void setGpgKey(String gpgKey) {
-//    this.gpgKey = gpgKey;
-//  }
+  /**
+   * @return the osType
+   */
+  public String getOsType() {
+    return osType;
+  }
+
+  /**
+   * @param osType the osType to set
+   */
+  public void setOsType(String osType) {
+    this.osType = osType;
+  }
 
+  /**
+   * @return the repoId
+   */
+  public String getRepoId() {
+    return repoId;
+  }
+
+  /**
+   * @param repoId the repoId to set
+   */
+  public void setRepoId(String repoId) {
+    this.repoId = repoId;
+  }
 
-  public String getOs() {
-    return os;
+  /**
+   * @return the repoName
+   */
+  public String getRepoName() {
+    return repoName;
   }
 
-  public void setOs(String os) {
-    this.os = os;
+  /**
+   * @param repoName the repoName to set
+   */
+  public void setRepoName(String repoName) {
+    this.repoName = repoName;
   }
 
-  public String getDescription() {
-    return description;
+  /**
+   * @return the mirrorsList
+   */
+  public String getMirrorsList() {
+    return mirrorsList;
   }
 
-  public void setDescription(String description) {
-    this.description = description;
+  /**
+   * @param mirrorsList the mirrorsList to set
+   */
+  public void setMirrorsList(String mirrorsList) {
+    this.mirrorsList = mirrorsList;
   }
 
   @Override
   public String toString() {
-    return "url="+ url + "\tos="+os+"\tdescription="+ description;
+    return "[ repoInfo: "
+        + ", osType=" + osType
+        + ", repoId=" + repoId
+        + ", baseUrl=" + baseUrl
+        + ", repoName=" + repoName
+        + ", mirrorsList=" + mirrorsList
+        + " ]";
   }
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java Wed Nov  7 08:13:12 2012
@@ -51,9 +51,9 @@ public interface Service {
 
   public void updateDesiredConfigs(Map<String, Config> configs);
 
-  public StackVersion getDesiredStackVersion();
+  public StackId getDesiredStackVersion();
 
-  public void setDesiredStackVersion(StackVersion stackVersion);
+  public void setDesiredStackVersion(StackId stackVersion);
 
   public ServiceResponse convertToResponse();
 

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java Wed Nov  7 08:13:12 2012
@@ -42,9 +42,9 @@ public interface ServiceComponent {
 
   public void updateDesiredConfigs(Map<String, Config> configs);
 
-  public StackVersion getDesiredStackVersion();
+  public StackId getDesiredStackVersion();
 
-  public void setDesiredStackVersion(StackVersion stackVersion);
+  public void setDesiredStackVersion(StackId stackVersion);
 
   public Map<String, ServiceComponentHost> getServiceComponentHosts();
 
@@ -77,4 +77,6 @@ public interface ServiceComponent {
   public void removeServiceComponentHosts(String hostname)
       throws AmbariException;
 
+  ServiceComponentHost addServiceComponentHost(
+      String hostName) throws AmbariException;
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java Wed Nov  7 08:13:12 2012
@@ -18,13 +18,11 @@
 
 package org.apache.ambari.server.state;
 
-import java.util.List;
 import java.util.Map;
 
 import com.google.inject.persist.Transactional;
 import org.apache.ambari.server.controller.ServiceComponentHostResponse;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
-import org.apache.ambari.server.state.job.Job;
 
 
 public interface ServiceComponentHost {
@@ -58,13 +56,6 @@ public interface ServiceComponentHost {
   public String getHostName();
 
   /**
-   * Get the list of Jobs that are currently being tracked at the
-   * ServiceComponentHost level
-   * @return List of Jobs
-   */
-  public List<Job> getJobs();
-
-  /**
    * Send a ServiceComponentHostState event to the StateMachine
    * @param event Event to handle
    * @throws InvalidStateTransitionException
@@ -80,9 +71,9 @@ public interface ServiceComponentHost {
 
   public void updateDesiredConfigs(Map<String, Config> configs);
 
-  public StackVersion getDesiredStackVersion();
+  public StackId getDesiredStackVersion();
 
-  public void setDesiredStackVersion(StackVersion stackVersion);
+  public void setDesiredStackVersion(StackId stackVersion);
 
   public State getState();
 
@@ -92,9 +83,9 @@ public interface ServiceComponentHost {
 
   public void updateConfigs(Map<String, Config> configs);
 
-  public StackVersion getStackVersion();
+  public StackId getStackVersion();
 
-  public void setStackVersion(StackVersion stackVersion);
+  public void setStackVersion(StackId stackVersion);
 
   public ServiceComponentHostResponse convertToResponse();