Browse Source

AMBARI-16230. Sporadic errors when deploying the cluster (oleewere)

oleewere 9 years ago
parent
commit
5f9c8bb045

+ 0 - 1
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java

@@ -356,7 +356,6 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
       s.setDesiredState(state);
       s.setDesiredStackVersion(cluster.getDesiredStackVersion());
       s.persist();
-      cluster.addService(s);
       // Initialize service widgets
       getManagementController().initializeWidgetsAndLayouts(cluster, s);
     }

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java

@@ -66,7 +66,7 @@ public interface Cluster {
    * Add a service to a cluster
    * @param service
    */
-  void addService(Service service) throws AmbariException;
+  void addService(Service service);
 
   /**
    * Get a service

+ 1 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java

@@ -475,6 +475,7 @@ public class ServiceImpl implements Service {
 
           // publish the service installed event
           StackId stackId = cluster.getDesiredStackVersion();
+          cluster.addService(this);
 
           ServiceInstalledEvent event = new ServiceInstalledEvent(
               getClusterId(), stackId.getStackName(),

+ 1 - 7
ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java

@@ -944,8 +944,7 @@ public class ClusterImpl implements Cluster {
   }
 
   @Override
-  public void addService(Service service)
-    throws AmbariException {
+  public void addService(Service service) {
     loadServices();
     clusterGlobalLock.writeLock().lock();
     try {
@@ -954,11 +953,6 @@ public class ClusterImpl implements Cluster {
           + ", clusterId=" + getClusterId() + ", serviceName="
           + service.getName());
       }
-      if (services.containsKey(service.getName())) {
-        throw new AmbariException("Service already exists" + ", clusterName="
-            + getClusterName() + ", clusterId=" + getClusterId()
-            + ", serviceName=" + service.getName());
-      }
       services.put(service.getName(), service);
     } finally {
       clusterGlobalLock.writeLock().unlock();

+ 0 - 1
ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java

@@ -382,7 +382,6 @@ public class EventsTest {
   private void installHdfsService() throws Exception {
     String serviceName = "HDFS";
     Service service = m_serviceFactory.createNew(m_cluster, serviceName);
-    m_cluster.addService(service);
     service.persist();
     service = m_cluster.getService(serviceName);
     Assert.assertNotNull(service);

+ 6 - 2
ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java

@@ -58,6 +58,7 @@ import org.apache.ambari.server.orm.entities.AlertGroupEntity;
 import org.apache.ambari.server.orm.entities.AlertTargetEntity;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
 import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
+import org.apache.ambari.server.orm.entities.ClusterStateEntity;
 import org.apache.ambari.server.orm.entities.HostEntity;
 import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
 import org.apache.ambari.server.orm.entities.HostStateEntity;
@@ -347,6 +348,11 @@ public class OrmTestHelper {
 
     clusterDAO.create(clusterEntity);
 
+    ClusterStateEntity clusterStateEntity = new ClusterStateEntity();
+    clusterStateEntity.setCurrentStack(stackEntity);
+    clusterStateEntity.setClusterEntity(clusterEntity);
+    getEntityManager().persist(clusterStateEntity);
+
     clusterEntity = clusterDAO.findByName(clusterEntity.getClusterName());
     assertNotNull(clusterEntity);
     assertTrue(clusterEntity.getClusterId() > 0);
@@ -415,7 +421,6 @@ public class OrmTestHelper {
       ServiceComponentHostFactory schFactory, String hostName) throws Exception {
     String serviceName = "HDFS";
     Service service = serviceFactory.createNew(cluster, serviceName);
-    cluster.addService(service);
     service.persist();
     service = cluster.getService(serviceName);
     assertNotNull(service);
@@ -461,7 +466,6 @@ public class OrmTestHelper {
       ServiceComponentHostFactory schFactory, String hostName) throws Exception {
     String serviceName = "YARN";
     Service service = serviceFactory.createNew(cluster, serviceName);
-    cluster.addService(service);
     service.persist();
     service = cluster.getService(serviceName);
     assertNotNull(service);

+ 0 - 1
ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java

@@ -304,7 +304,6 @@ public class AlertEventPublisherTest {
   private void installHdfsService() throws Exception {
     String serviceName = "HDFS";
     Service service = serviceFactory.createNew(cluster, serviceName);
-    cluster.addService(service);
     service.persist();
     service = cluster.getService(serviceName);
 

+ 0 - 1
ambari-server/src/test/java/org/apache/ambari/server/state/alerts/InitialAlertEventTest.java

@@ -175,7 +175,6 @@ public class InitialAlertEventTest {
   private void installHdfsService() throws Exception {
     String serviceName = "HDFS";
     Service service = m_serviceFactory.createNew(m_cluster, serviceName);
-    m_cluster.addService(service);
     service.persist();
     service = m_cluster.getService(serviceName);
 

+ 0 - 12
ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java

@@ -685,21 +685,9 @@ public class ClusterTest {
     Service s1 = serviceFactory.createNew(c1, "HDFS");
     Service s2 = serviceFactory.createNew(c1, "MAPREDUCE");
 
-    c1.addService(s1);
-    c1.addService(s2);
-
     s1.persist();
     s2.persist();
 
-    Service s3 = serviceFactory.createNew(c1, "MAPREDUCE");
-
-    try {
-      c1.addService(s3);
-      fail("Expected error on adding dup service");
-    } catch (Exception e) {
-      // Expected
-    }
-
     Service s = c1.getService("HDFS");
     Assert.assertNotNull(s);
     Assert.assertEquals("HDFS", s.getName());