Quellcode durchsuchen

AMBARI-1759. Error in creating host component. (smohanty)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1463227 13f79535-47bb-0310-9956-ffa450edef68
Sumit Mohanty vor 12 Jahren
Ursprung
Commit
28ef6579b5

+ 2 - 0
CHANGES.txt

@@ -541,6 +541,8 @@ Trunk (unreleased changes):
 
  BUG FIXES
 
+ AMBARI-1759. Error in creating host component. (smohanty)
+
  AMBARI-1757. Add support for Stack 1.2.2 to Ambari. (smohanty)
 
  AMBARI-1749. Set default heap size for zookeeper. (swagle)

+ 1 - 1
ambari-agent/src/main/python/ambari_agent/Register.py

@@ -62,7 +62,7 @@ class Register:
     data_dir = self.config.get('agent', 'prefix')
     ver_file = os.path.join(data_dir, 'version')
     f = open(ver_file, "r")
-    version = f.read()
+    version = f.read().strip()
     f.close()
     return version
 

Datei-Diff unterdrückt, da er zu groß ist
+ 583 - 600
ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java


+ 3 - 7
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java

@@ -3415,7 +3415,7 @@ public class AmbariManagementControllerImpl implements
       }
 
       if (LOG.isDebugEnabled()) {
-        LOG.debug("Received a createHostComponent DELETE request request"
+        LOG.debug("Received a hostComponent DELETE request"
             + ", clusterName=" + request.getClusterName()
             + ", serviceName=" + request.getServiceName()
             + ", componentName=" + request.getComponentName()
@@ -3424,9 +3424,7 @@ public class AmbariManagementControllerImpl implements
       }
 
       Service service = cluster.getService(request.getServiceName());
-
       ServiceComponent component = service.getServiceComponent(request.getComponentName());
-
       ServiceComponentHost componentHost = component.getServiceComponentHost(request.getHostname());
 
       if (!componentHost.canBeRemoved()) {
@@ -3438,19 +3436,17 @@ public class AmbariManagementControllerImpl implements
             + ", request=" + request);
       }
 
-
       //Only allow removing master components in MAINTENANCE state without stages generation
       if (component.isClientComponent() ||
           componentHost.getState() != State.MAINTENANCE) {
-        throw new AmbariException("Only master component in MAINTENANCE state can be removed");
+        throw new AmbariException("Only master or slave component can be removed. They must be in " +
+            "MAINTENANCE state in order to be removed.");
       }
 
       if (!safeToRemoveSCHs.containsKey(component)) {
         safeToRemoveSCHs.put(component, new HashSet<ServiceComponentHost>());
       }
-
       safeToRemoveSCHs.get(component).add(componentHost);
-
     }
 
     for (Entry<ServiceComponent, Set<ServiceComponentHost>> entry : safeToRemoveSCHs.entrySet()) {

+ 5 - 4
ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java

@@ -71,8 +71,6 @@ public class ServiceComponentImpl implements ServiceComponent {
 
   private final boolean isClientComponent;
 
-
-
   private void init() {
     // TODO load during restart
     // initialize from DB
@@ -117,7 +115,6 @@ public class ServiceComponentImpl implements ServiceComponent {
     this.service = service;
     this.desiredStateEntity = serviceComponentDesiredStateEntity;
 
-
     this.desiredConfigs = new HashMap<String, String>();
 
     this.hostComponents = new HashMap<String, ServiceComponentHost>();
@@ -133,7 +130,7 @@ public class ServiceComponentImpl implements ServiceComponent {
       hostComponents.put(hostComponentStateEntity.getHostName(),
           serviceComponentHostFactory.createExisting(this,
               hostComponentStateEntity, hostComponentDesiredStateEntity));
-   }
+    }
 
     for (ComponentConfigMappingEntity entity : desiredStateEntity.getComponentConfigMappingEntities()) {
       desiredConfigs.put(entity.getConfigType(), entity.getVersionTag());
@@ -516,6 +513,10 @@ public class ServiceComponentImpl implements ServiceComponent {
     }
     sch.delete();
     hostComponents.remove(hostname);
+
+    // FIXME need a better approach of caching components by host
+    ClusterImpl clusterImpl = (ClusterImpl) service.getCluster();
+    clusterImpl.removeServiceComponentHost(sch);
   }
 
   @Override

+ 94 - 11
ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java

@@ -295,19 +295,19 @@ public class ClusterImpl implements Cluster {
       }
       if (!clusterFound) {
         throw new AmbariException("Host does not belong this cluster"
-                + ", hostname=" + hostname
-                + ", clusterName=" + getClusterName()
-                + ", clusterId=" + getClusterId());
+            + ", hostname=" + hostname
+            + ", clusterName=" + getClusterName()
+            + ", clusterId=" + getClusterId());
       }
 
-    if (!serviceComponentHosts.containsKey(serviceName)) {
-      serviceComponentHosts.put(serviceName,
-          new HashMap<String, Map<String,ServiceComponentHost>>());
-    }
-    if (!serviceComponentHosts.get(serviceName).containsKey(componentName)) {
-      serviceComponentHosts.get(serviceName).put(componentName,
-          new HashMap<String, ServiceComponentHost>());
-    }
+      if (!serviceComponentHosts.containsKey(serviceName)) {
+        serviceComponentHosts.put(serviceName,
+            new HashMap<String, Map<String, ServiceComponentHost>>());
+      }
+      if (!serviceComponentHosts.get(serviceName).containsKey(componentName)) {
+        serviceComponentHosts.get(serviceName).put(componentName,
+            new HashMap<String, ServiceComponentHost>());
+      }
 
       if (serviceComponentHosts.get(serviceName).get(componentName).
           containsKey(hostname)) {
@@ -339,6 +339,89 @@ public class ClusterImpl implements Cluster {
     }
   }
 
+  public void removeServiceComponentHost(ServiceComponentHost svcCompHost)
+      throws AmbariException {
+    loadServiceHostComponents();
+    writeLock.lock();
+    try {
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("Trying to remove ServiceComponentHost to ClusterHostMap cache"
+            + ", serviceName=" + svcCompHost.getServiceName()
+            + ", componentName=" + svcCompHost.getServiceComponentName()
+            + ", hostname=" + svcCompHost.getHostName());
+      }
+
+      final String hostname = svcCompHost.getHostName();
+      final String serviceName = svcCompHost.getServiceName();
+      final String componentName = svcCompHost.getServiceComponentName();
+      Set<Cluster> cs = clusters.getClustersForHost(hostname);
+      boolean clusterFound = false;
+      Iterator<Cluster> iter = cs.iterator();
+      while (iter.hasNext()) {
+        Cluster c = iter.next();
+        if (c.getClusterId() == this.getClusterId()) {
+          clusterFound = true;
+          break;
+        }
+      }
+      if (!clusterFound) {
+        throw new AmbariException("Host does not belong this cluster"
+            + ", hostname=" + hostname
+            + ", clusterName=" + getClusterName()
+            + ", clusterId=" + getClusterId());
+      }
+
+      if (!serviceComponentHosts.containsKey(serviceName)
+          || !serviceComponentHosts.get(serviceName).containsKey(componentName)
+          || !serviceComponentHosts.get(serviceName).get(componentName).
+          containsKey(hostname)) {
+        throw new AmbariException("Invalid entry for ServiceComponentHost"
+            + ", serviceName=" + serviceName
+            + ", serviceComponentName" + componentName
+            + ", hostname= " + hostname);
+      }
+      if (!serviceComponentHostsByHost.containsKey(hostname)) {
+        throw new AmbariException("Invalid host entry for ServiceComponentHost"
+            + ", serviceName=" + serviceName
+            + ", serviceComponentName" + componentName
+            + ", hostname= " + hostname);
+      }
+
+      ServiceComponentHost schToRemove = null;
+      for (ServiceComponentHost sch : serviceComponentHostsByHost.get(hostname)) {
+        if (sch.getServiceName().equals(serviceName)
+            && sch.getServiceComponentName().equals(componentName)
+            && sch.getHostName().equals(hostname)) {
+          schToRemove = sch;
+          break;
+        }
+      }
+
+      if (schToRemove == null) {
+        LOG.warn("Unavailable in per host cache. ServiceComponentHost"
+            + ", serviceName=" + serviceName
+            + ", serviceComponentName" + componentName
+            + ", hostname= " + hostname);
+      }
+
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("Removing a ServiceComponentHost"
+            + ", clusterName=" + getClusterName()
+            + ", clusterId=" + getClusterId()
+            + ", serviceName=" + serviceName
+            + ", serviceComponentName" + componentName
+            + ", hostname= " + hostname);
+      }
+
+      serviceComponentHosts.get(serviceName).get(componentName).remove(hostname);
+      if(schToRemove != null) {
+        serviceComponentHostsByHost.get(hostname).remove(schToRemove);
+      }
+    } finally {
+      writeLock.unlock();
+    }
+  }
+
   @Override
   public long getClusterId() {
     readLock.lock();

+ 17 - 5
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java

@@ -1532,7 +1532,6 @@ public class AmbariManagementControllerImplTest {
     );
     amc.createConfiguration(configurationRequest);
 
-
     serviceRequests.clear();
     serviceRequests.add(new ServiceRequest("c1", "HDFS",
         gson.<Map<String, String>>fromJson("{\"core-site\": \"version1\", \"hdfs-site\": \"version1\", \"global\" : \"version1\" }", confType)
@@ -1549,7 +1548,6 @@ public class AmbariManagementControllerImplTest {
 
     amc.updateServices(serviceRequests, mapRequestProps, true);
 
-
     Set<ServiceComponentRequest> serviceComponentRequests = new HashSet<ServiceComponentRequest>();
     serviceComponentRequests.add(new ServiceComponentRequest("c1", "HDFS", "NAMENODE", null, null));
     serviceComponentRequests.add(new ServiceComponentRequest("c1", "HDFS", "SECONDARY_NAMENODE", null, null));
@@ -1572,7 +1570,6 @@ public class AmbariManagementControllerImplTest {
     componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "DATANODE", "host2", null, null));
     componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "DATANODE", "host3", null, null));
 
-
     amc.createHostComponents(componentHostRequests);
 
     serviceRequests.clear();
@@ -1654,11 +1651,26 @@ public class AmbariManagementControllerImplTest {
     componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "NAMENODE", "host1", null, null));
 
     amc.deleteHostComponents(componentHostRequests);
-
     namenodes = cluster.getService("HDFS").getServiceComponent("NAMENODE").getServiceComponentHosts();
-
     assertEquals(1, namenodes.size());
 
+    // testing the behavior for runSmokeTest flag
+    // piggybacking on this test to avoid setting up the mock cluster
+    testRunSmokeTestFlag(mapRequestProps, amc, serviceRequests);
+
+    // should be able to add the host component back
+    componentHostRequests.clear();
+    componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "NAMENODE", "host1", null, null));
+    amc.createHostComponents(componentHostRequests);
+    namenodes = cluster.getService("HDFS").getServiceComponent("NAMENODE").getServiceComponentHosts();
+    assertEquals(2, namenodes.size());
+  }
+
+  private void testRunSmokeTestFlag(Map<String, String> mapRequestProps,
+                                    AmbariManagementController amc,
+                                    Set<ServiceRequest> serviceRequests)
+      throws AmbariException {
+    RequestStatusResponse response;//Starting HDFS service. No run_smoke_test flag is set, smoke
 
     //Stopping HDFS service
     serviceRequests.clear();

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.