You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sw...@apache.org on 2013/03/02 01:29:27 UTC

svn commit: r1451789 - in /incubator/ambari/trunk: ./ ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ ambari-server/src/main/java/org/apache/ambari/server/agent/rest/ ambari-server/src/main/java/org/apache/ambari/server/api/ ambari-...

Author: swagle
Date: Sat Mar  2 00:29:27 2013
New Revision: 1451789

URL: http://svn.apache.org/r1451789
Log:
AMBARI-1539. Stage creation takes on an average 1.5 minutes on large cluster. (Siddharth Wagle)

Added:
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/AmbariPersistFilter.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/GsonJsonProvider.java
Removed:
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentJackSonJsonProvider.java
Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapper.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostRoleCommand.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1451789&r1=1451788&r2=1451789&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Sat Mar  2 00:29:27 2013
@@ -400,8 +400,11 @@ Trunk (unreleased changes):
 
  BUG FIXES
 
+ AMBARI-1539. Stage creation takes on an average 1.5 minutes on large 
+ cluster. (Siddharth Wagle) 
+
  AMBARI-1485. Server throws exception when trying to stop a service which is 
- in stopping state (Siddharth Wagle) 
+ in stopping state. (Siddharth Wagle) 
 
  AMBARI-1526. State fields are not returned by default for services.
  (tbeerbower)

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java?rev=1451789&r1=1451788&r2=1451789&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java Sat Mar  2 00:29:27 2013
@@ -160,11 +160,11 @@ public class ActionDBAccessorImpl implem
       ClusterEntity clusterEntity = clusterDAO.findById(cluster.getClusterId());
 
       stageEntity.setCluster(clusterEntity);
-      clusterEntity.getStages().add(stageEntity);
+      stageDAO.create(stageEntity);
 
       for (HostRoleCommand hostRoleCommand : stage.getOrderedHostRoleCommands()) {
         HostRoleCommandEntity hostRoleCommandEntity = hostRoleCommand.constructNewPersistenceEntity();
-        stageEntity.getHostRoleCommands().add(hostRoleCommandEntity);
+
         hostRoleCommandEntity.setStage(stageEntity);
 
         HostEntity hostEntity = hostDAO.findByName(hostRoleCommandEntity.getHostName());
@@ -172,7 +172,6 @@ public class ActionDBAccessorImpl implem
           LOG.error("Host {} doesn't exists in database" + hostRoleCommandEntity.getHostName());
           throw new RuntimeException("Host '"+hostRoleCommandEntity.getHostName()+"' doesn't exists in database");
         }
-        hostEntity.getHostRoleCommandEntities().add(hostRoleCommandEntity);
         hostRoleCommandEntity.setHost(hostEntity);
         hostRoleCommandDAO.create(hostRoleCommandEntity);
 
@@ -194,8 +193,6 @@ public class ActionDBAccessorImpl implem
         roleSuccessCriteriaDAO.create(roleSuccessCriteriaEntity);
       }
 
-      stageDAO.create(stageEntity);
-      clusterDAO.merge(clusterEntity);
     }
   }
 

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java?rev=1451789&r1=1451788&r2=1451789&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java Sat Mar  2 00:29:27 2013
@@ -71,7 +71,9 @@ public class ActionManager {
   public void sendActions(List<Stage> stages) {
     
     for (Stage s: stages) {
-      LOG.info("Persisting stage into db: " + s.toString());
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("Persisting stage into db: " + s.toString());
+      }
     }
     db.persistActions(stages);
 

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapper.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapper.java?rev=1451789&r1=1451788&r2=1451789&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapper.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapper.java Sat Mar  2 00:29:27 2013
@@ -42,12 +42,12 @@ public class ExecutionCommandWrapper {
     if (executionCommand != null) {
       return executionCommand;
     } else if (jsonExecutionCommand != null) {
-      try {
-        executionCommand = StageUtils.stringToExecutionCommand(jsonExecutionCommand);
+//      try {
+        executionCommand = StageUtils.getGson().fromJson(jsonExecutionCommand, ExecutionCommand.class);
         return executionCommand;
-      } catch (IOException e) {
-        throw new RuntimeException(e);
-      }
+//      } catch (IOException e) {
+//        throw new RuntimeException(e);
+//      }
     } else {
       throw new RuntimeException(
           "Invalid ExecutionCommandWrapper, both object and string"
@@ -59,14 +59,14 @@ public class ExecutionCommandWrapper {
     if (jsonExecutionCommand != null) {
       return jsonExecutionCommand;
     } else if (executionCommand != null) {
-      try {
-        jsonExecutionCommand = StageUtils.jaxbToString(executionCommand);
+//      try {
+        jsonExecutionCommand = StageUtils.getGson().toJson(executionCommand);
         return jsonExecutionCommand;
-      } catch (JAXBException e) {
-        throw new RuntimeException(e);
-      } catch (IOException e) {
-        throw new RuntimeException(e);
-      }
+//      } catch (JAXBException e) {
+//        throw new RuntimeException(e);
+//      } catch (IOException e) {
+//        throw new RuntimeException(e);
+//      }
     } else {
       throw new RuntimeException(
           "Invalid ExecutionCommandWrapper, both object and string"

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostRoleCommand.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostRoleCommand.java?rev=1451789&r1=1451788&r2=1451789&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostRoleCommand.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostRoleCommand.java Sat Mar  2 00:29:27 2013
@@ -100,10 +100,10 @@ public class HostRoleCommand {
     hostRoleCommandEntity.setRoleCommand(roleCommand);
 
     hostRoleCommandEntity.setEvent(event.getEventJson());
-    ExecutionCommandEntity executionCommandEntity = new ExecutionCommandEntity();
-    executionCommandEntity.setCommand(executionCommandWrapper.getJson().getBytes());
-    executionCommandEntity.setHostRoleCommand(hostRoleCommandEntity);
-    hostRoleCommandEntity.setExecutionCommand(executionCommandEntity);
+//    ExecutionCommandEntity executionCommandEntity = new ExecutionCommandEntity();
+//    executionCommandEntity.setCommand(executionCommandWrapper.getJson().getBytes());
+//    executionCommandEntity.setHostRoleCommand(hostRoleCommandEntity);
+//    hostRoleCommandEntity.setExecutionCommand(executionCommandEntity);
 
     return hostRoleCommandEntity;
   }

Added: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/AmbariPersistFilter.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/AmbariPersistFilter.java?rev=1451789&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/AmbariPersistFilter.java (added)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/AmbariPersistFilter.java Sat Mar  2 00:29:27 2013
@@ -0,0 +1,57 @@
+/*
+ * 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.api;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import com.google.inject.persist.PersistService;
+import com.google.inject.persist.UnitOfWork;
+
+import javax.servlet.*;
+import java.io.IOException;
+
+/**
+ * Replacement for Guice built-in PersistFilter as PersistService is started on Ambari start
+ */
+@Singleton
+public class AmbariPersistFilter implements Filter {
+  private final UnitOfWork unitOfWork;
+
+  @Inject
+  public AmbariPersistFilter(UnitOfWork unitOfWork) {
+    this.unitOfWork = unitOfWork;
+  }
+
+  @Override
+  public void init(FilterConfig filterConfig) throws ServletException {
+  }
+
+  @Override
+  public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+    unitOfWork.begin();
+    try {
+      filterChain.doFilter(servletRequest, servletResponse);
+    } finally {
+      unitOfWork.end();
+    }
+  }
+
+  @Override
+  public void destroy() {
+  }
+}

Added: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/GsonJsonProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/GsonJsonProvider.java?rev=1451789&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/GsonJsonProvider.java (added)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/GsonJsonProvider.java Sat Mar  2 00:29:27 2013
@@ -0,0 +1,88 @@
+/*
+ * 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.api;
+
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+import java.io.*;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+@Provider
+@Consumes({MediaType.APPLICATION_JSON, "text/json"})
+@Produces({MediaType.APPLICATION_JSON, "text/json"})
+public class GsonJsonProvider implements MessageBodyReader<Object>,
+    MessageBodyWriter<Object> {
+
+  private static final Logger log = LoggerFactory.getLogger(GsonJsonProvider.class);
+
+  static final Gson gson = new GsonBuilder()
+//      .setPrettyPrinting()
+      .create();
+
+  @Override
+  public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+    return true;
+  }
+
+  @Override
+  public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
+    Reader reader = new InputStreamReader(entityStream);
+    try {
+      return gson.fromJson(reader, genericType);
+    } finally {
+      reader.close();
+    }
+  }
+
+  @Override
+  public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+    return true;
+  }
+
+  @Override
+  /**
+   * Not known
+   */
+  public long getSize(Object o, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+    return -1;
+  }
+
+  @Override
+  public void writeTo(Object o, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
+    Writer writer = new OutputStreamWriter(entityStream);
+    try {
+      gson.toJson(o, genericType, writer);
+    } finally {
+      writer.close();
+    }
+  }
+}

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java?rev=1451789&r1=1451788&r2=1451789&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java Sat Mar  2 00:29:27 2013
@@ -108,6 +108,7 @@ public class AmbariMetaInfo {
      *
      * @throws Exception throws exception if not able to parse the Meta data.
      */
+    @Inject
     public void init() throws Exception {
         getConfigurationInformation(stackRoot);
     }

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java?rev=1451789&r1=1451788&r2=1451789&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java Sat Mar  2 00:29:27 2013
@@ -23,10 +23,13 @@ import java.io.File;
 import java.net.BindException;
 import java.util.Map;
 
+import com.google.inject.persist.PersistFilter;
+import com.google.gson.Gson;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.agent.HeartBeatHandler;
 import org.apache.ambari.server.agent.rest.AgentResource;
+import org.apache.ambari.server.api.AmbariPersistFilter;
 import org.apache.ambari.server.api.rest.BootStrapResource;
 import org.apache.ambari.server.api.services.*;
 import org.apache.ambari.server.bootstrap.BootStrapImpl;
@@ -42,6 +45,7 @@ import org.apache.ambari.server.security
 import org.apache.ambari.server.security.unsecured.rest.CertificateDownload;
 import org.apache.ambari.server.security.unsecured.rest.CertificateSign;
 import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.utils.StageUtils;
 import org.eclipse.jetty.server.Connector;
 import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.nio.SelectChannelConnector;
@@ -163,6 +167,9 @@ public class AmbariServer {
       DelegatingFilterProxy springSecurityFilter = new DelegatingFilterProxy();
       springSecurityFilter.setTargetBeanName("springSecurityFilterChain");
 
+      //session-per-request strategy for api
+      root.addFilter(new FilterHolder(injector.getInstance(AmbariPersistFilter.class)), "/api/*", 1);
+
       if (configs.getApiAuthentication()) {
         root.addFilter(new FilterHolder(springSecurityFilter), "/api/*", 1);
       }
@@ -224,7 +231,10 @@ public class AmbariServer {
       sh.setInitParameter("com.sun.jersey.config.property.packages",
           "org.apache.ambari.server.api.rest;" +
               "org.apache.ambari.server.api.services;" +
-          "org.apache.ambari.eventdb.webservice");
+              "org.apache.ambari.eventdb.webservice;" +
+              "org.apache.ambari.server.api");
+      sh.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature",
+          "true");
       root.addServlet(sh, "/api/v1/*");
       sh.setInitOrder(2);
 
@@ -232,7 +242,7 @@ public class AmbariServer {
       agent.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
           "com.sun.jersey.api.core.PackagesResourceConfig");
       agent.setInitParameter("com.sun.jersey.config.property.packages",
-          "org.apache.ambari.server.agent.rest");
+          "org.apache.ambari.server.agent.rest;" + "org.apache.ambari.server.api");
       agent.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature",
           "true");
       agentroot.addServlet(agent, "/agent/v1/*");
@@ -242,7 +252,9 @@ public class AmbariServer {
       cert.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
           "com.sun.jersey.api.core.PackagesResourceConfig");
       cert.setInitParameter("com.sun.jersey.config.property.packages",
-          "org.apache.ambari.server.security.unsecured.rest");
+          "org.apache.ambari.server.security.unsecured.rest;" + "org.apache.ambari.server.api");
+      cert.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature",
+          "true");
       agentroot.addServlet(cert, "/*");
       cert.setInitOrder(4);
 
@@ -250,7 +262,9 @@ public class AmbariServer {
       resources.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
           "com.sun.jersey.api.core.PackagesResourceConfig");
       resources.setInitParameter("com.sun.jersey.config.property.packages",
-          "org.apache.ambari.server.resources.api.rest");
+          "org.apache.ambari.server.resources.api.rest;" + "org.apache.ambari.server.api");
+      resources.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature",
+          "true");
       root.addServlet(resources, "/resources/*");
       resources.setInitOrder(6);
 
@@ -377,6 +391,7 @@ public class AmbariServer {
     KeyService.init(injector.getInstance(PersistKeyValueImpl.class));
     AmbariMetaService.init(injector.getInstance(AmbariMetaInfo.class));
     BootStrapResource.init(injector.getInstance(BootStrapImpl.class));
+    StageUtils.setGson(injector.getInstance(Gson.class));
   }
 
   public static void main(String[] args) throws Exception {

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java?rev=1451789&r1=1451788&r2=1451789&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java Sat Mar  2 00:29:27 2013
@@ -28,7 +28,7 @@ import java.util.Arrays;
 @Table(name = "host_role_command", schema = "ambari", catalog = "")
 @Entity
 @Cacheable(false)
-@SequenceGenerator(name = "ambari.host_role_command_task_id_seq", allocationSize = 1)
+@SequenceGenerator(name = "ambari.host_role_command_task_id_seq", allocationSize = 50)
 public class HostRoleCommandEntity {
   private Long taskId;
 
@@ -257,7 +257,7 @@ public class HostRoleCommandEntity {
 
   private StageEntity stage;
 
-  @ManyToOne
+  @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
   @JoinColumns({@JoinColumn(name = "request_id", referencedColumnName = "request_id", nullable = false), @JoinColumn(name = "stage_id", referencedColumnName = "stage_id", nullable = false)})
   public StageEntity getStage() {
     return stage;
@@ -269,7 +269,7 @@ public class HostRoleCommandEntity {
 
   private HostEntity host;
 
-  @ManyToOne
+  @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
   @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
   public HostEntity getHost() {
     return host;

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java?rev=1451789&r1=1451788&r2=1451789&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java Sat Mar  2 00:29:27 2013
@@ -99,7 +99,7 @@ public class StageEntity {
 
   private ClusterEntity cluster;
 
-  @ManyToOne
+  @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
   @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id")
   public ClusterEntity getCluster() {
     return cluster;

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java?rev=1451789&r1=1451788&r2=1451789&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java Sat Mar  2 00:29:27 2013
@@ -1,4 +1,4 @@
-/**
+ /**
  * 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
@@ -197,7 +197,8 @@ public class ClusterImpl implements Clus
   }
 
   private void loadServices() {
-    LOG.info("clusterEntity " + clusterEntity.getClusterServiceEntities());
+    //logging here takes too much time
+//    LOG.info("clusterEntity " + clusterEntity.getClusterServiceEntities() );
     if (services == null) {
       writeLock.lock();
       try {
@@ -682,6 +683,7 @@ public class ClusterImpl implements Clus
     } finally {
       readWriteLock.readLock().unlock();
     }
+
   }
 
   @Override

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java?rev=1451789&r1=1451788&r2=1451789&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java Sat Mar  2 00:29:27 2013
@@ -32,6 +32,7 @@ import java.util.TreeMap;
 
 import javax.xml.bind.JAXBException;
 
+import com.google.gson.Gson;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.actionmanager.Stage;
@@ -49,11 +50,33 @@ import org.codehaus.jackson.map.ObjectMa
 import org.codehaus.jackson.map.SerializationConfig;
 
 public class StageUtils {
-  private static Log LOG = LogFactory.getLog(StageUtils.class);
-  
-  private static Map<String, String> componentToClusterInfoKeyMap = 
+  private static final Log LOG = LogFactory.getLog(StageUtils.class);
+
+  private static Map<String, String> componentToClusterInfoKeyMap =
       new HashMap<String, String>();
-  
+
+  private volatile static Gson gson;
+
+  public static void setGson(Gson gson) {
+    if (gson==null) {
+      StageUtils.gson = gson;
+    }
+  }
+
+  public static Gson getGson() {
+    if (gson != null) {
+      return gson;
+    } else {
+      synchronized (LOG) {
+        if (gson==null) {
+          gson = new Gson();
+        }
+        return gson;
+      }
+    }
+  }
+
+
   static {
     componentToClusterInfoKeyMap.put("NAMENODE", "namenode_host");
     componentToClusterInfoKeyMap.put("JOBTRACKER", "jtnode_host");
@@ -78,13 +101,13 @@ public class StageUtils {
     componentToClusterInfoKeyMap.put("KERBEROS_ADMIN_CLIENT",
         "kerberos_adminclient_host");
   }
-  
+
   public static String getActionId(long requestId, long stageId) {
     return requestId + "-" + stageId;
   }
 
   public static long[] getRequestStage(String actionId) {
-    String [] fields = actionId.split("-");
+    String[] fields = actionId.split("-");
     long[] requestStageIds = new long[2];
     requestStageIds[0] = Long.parseLong(fields[0]);
     requestStageIds[1] = Long.parseLong(fields[1]);
@@ -100,7 +123,7 @@ public class StageUtils {
     }
     return getATestStage(requestId, stageId, hostname);
   }
-  
+
   //For testing only
   public static Stage getATestStage(long requestId, long stageId, String hostname) {
     Stage s = new Stage(requestId, "/tmp", "cluster1");
@@ -132,15 +155,12 @@ public class StageUtils {
     execCmd.setRoleParams(roleParams);
     return s;
   }
-  
+
   public static String jaxbToString(Object jaxbObj) throws JAXBException,
   JsonGenerationException, JsonMappingException, IOException {
-    ObjectMapper mapper = new ObjectMapper();
-    mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
-    mapper.configure(SerializationConfig.Feature.USE_ANNOTATIONS, true);
-    return mapper.writeValueAsString(jaxbObj);
+    return getGson().toJson(jaxbObj);
   }
-  
+
   public static ExecutionCommand stringToExecutionCommand(String json)
       throws JsonParseException, JsonMappingException, IOException {
     ObjectMapper mapper = new ObjectMapper();
@@ -157,8 +177,8 @@ public class StageUtils {
     InputStream is = new ByteArrayInputStream(json.getBytes(Charset.forName("UTF8")));
     return mapper.readValue(is, clazz);
   }
-  
-  
+
+
   public static Map<String, List<String>> getClusterHostInfo(Cluster cluster, HostsMap hostsMap) {
     Map<String, List<String>> info = new HashMap<String, List<String>>();
     if (cluster.getServices() != null) {
@@ -199,7 +219,7 @@ public class StageUtils {
       return "localhost";
     }
   }
-  
+
   public static String getHostsToDecommission(List<String> hosts) {
     StringBuilder builder = new StringBuilder();
     builder.append("[");