You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2013/04/01 20:00:39 UTC

svn commit: r1463227 - in /incubator/ambari/trunk: ./ ambari-agent/src/main/python/ambari_agent/ ambari-server/src/main/java/org/apache/ambari/server/api/services/ ambari-server/src/main/java/org/apache/ambari/server/controller/ ambari-server/src/main/...

Author: smohanty
Date: Mon Apr  1 18:00:39 2013
New Revision: 1463227

URL: http://svn.apache.org/r1463227
Log:
AMBARI-1759. Error in creating host component. (smohanty)

Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/Register.py
    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/AmbariManagementControllerImpl.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1463227&r1=1463226&r2=1463227&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Mon Apr  1 18:00:39 2013
@@ -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)

Modified: incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/Register.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/Register.py?rev=1463227&r1=1463226&r2=1463227&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/Register.py (original)
+++ incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/Register.py Mon Apr  1 18:00:39 2013
@@ -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
 

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=1463227&r1=1463226&r2=1463227&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 Mon Apr  1 18:00:39 2013
@@ -47,645 +47,628 @@ import java.util.*;
 @Singleton
 public class AmbariMetaInfo {
 
-    private String serverVersion = "undefined";
-    private List<StackInfo> stacksResult = new ArrayList<StackInfo>();
-    private File stackRoot;
-    private File serverVersionFile;
-    private final static Logger LOG = LoggerFactory
-            .getLogger(AmbariMetaInfo.class);
-    
-    private static final String STACK_METAINFO_FILE_NAME = "metainfo.xml";
-    private static final String STACK_XML_MAIN_BLOCK_NAME = "metainfo";
-    private static final String STACK_XML_PROPERTY_UPGRADE = "upgrade";
-
-    private static final String SERVICES_FOLDER_NAME = "services";
-    private static final String SERVICE_METAINFO_FILE_NAME = "metainfo.xml";
-    private static final String SERVICE_CONFIG_FOLDER_NAME = "configuration";
-    private static final String SERVICE_CONFIG_FILE_NAME_POSTFIX = "-site.xml";
-
-    private static final String REPOSITORY_FILE_NAME = "repoinfo.xml";
-    private static final String REPOSITORY_FOLDER_NAME = "repos";
-    private static final String REPOSITORY_XML_MAIN_BLOCK_NAME = "os";
-    private static final String REPOSITORY_XML_ATTRIBUTE_OS_TYPE = "type";
-    private static final String REPOSITORY_XML_REPO_BLOCK_NAME = "repo";
-    private static final String REPOSITORY_XML_PROPERTY_BASEURL = "baseurl";
-    private static final String REPOSITORY_XML_PROPERTY_REPOID = "repoid";
-    private static final String REPOSITORY_XML_PROPERTY_REPONAME = "reponame";
-    private static final String REPOSITORY_XML_PROPERTY_MIRRORSLIST = "mirrorslist";
-
-    private static final String METAINFO_XML_MAIN_BLOCK_NAME = "metainfo";
-    private static final String METAINFO_XML_PROPERTY_VERSION = "version";
-    private static final String METAINFO_XML_PROPERTY_USER = "user";
-    private static final String METAINFO_XML_PROPERTY_COMMENT = "comment";
-    private static final String METAINFO_XML_PROPERTY_COMPONENT_MAIN = "component";
-    private static final String METAINFO_XML_PROPERTY_COMPONENT_NAME = "name";
-    private static final String METAINFO_XML_PROPERTY_COMPONENT_CATEGORY = "category";
-
-    private static final String PROPERTY_XML_MAIN_BLOCK_NAME = "property";
-    private static final String PROPERTY_XML_PROPERTY_NAME = "name";
-    private static final String PROPERTY_XML_PROPERTY_VALUE = "value";
-    private static final String PROPERTY_XML_PROPERTY_DESCRIPTION = "description";
-    private static final FilenameFilter FILENAME_FILTER = new FilenameFilter() {
-      @Override
-      public boolean accept(File dir, String s) {
-        if (s.equals(".svn") || s.equals(".git"))
-          return false;
-        return true;
+  private final static Logger LOG = LoggerFactory
+      .getLogger(AmbariMetaInfo.class);
+  private static final String STACK_METAINFO_FILE_NAME = "metainfo.xml";
+  private static final String STACK_XML_MAIN_BLOCK_NAME = "metainfo";
+  private static final String STACK_XML_PROPERTY_UPGRADE = "upgrade";
+  private static final String SERVICES_FOLDER_NAME = "services";
+  private static final String SERVICE_METAINFO_FILE_NAME = "metainfo.xml";
+  private static final String SERVICE_CONFIG_FOLDER_NAME = "configuration";
+  private static final String SERVICE_CONFIG_FILE_NAME_POSTFIX = "-site.xml";
+  private static final String REPOSITORY_FILE_NAME = "repoinfo.xml";
+  private static final String REPOSITORY_FOLDER_NAME = "repos";
+  private static final String REPOSITORY_XML_MAIN_BLOCK_NAME = "os";
+  private static final String REPOSITORY_XML_ATTRIBUTE_OS_TYPE = "type";
+  private static final String REPOSITORY_XML_REPO_BLOCK_NAME = "repo";
+  private static final String REPOSITORY_XML_PROPERTY_BASEURL = "baseurl";
+  private static final String REPOSITORY_XML_PROPERTY_REPOID = "repoid";
+  private static final String REPOSITORY_XML_PROPERTY_REPONAME = "reponame";
+  private static final String REPOSITORY_XML_PROPERTY_MIRRORSLIST = "mirrorslist";
+  private static final String METAINFO_XML_MAIN_BLOCK_NAME = "metainfo";
+  private static final String METAINFO_XML_PROPERTY_VERSION = "version";
+  private static final String METAINFO_XML_PROPERTY_USER = "user";
+  private static final String METAINFO_XML_PROPERTY_COMMENT = "comment";
+  private static final String METAINFO_XML_PROPERTY_COMPONENT_MAIN = "component";
+  private static final String METAINFO_XML_PROPERTY_COMPONENT_NAME = "name";
+  private static final String METAINFO_XML_PROPERTY_COMPONENT_CATEGORY = "category";
+  private static final String PROPERTY_XML_MAIN_BLOCK_NAME = "property";
+  private static final String PROPERTY_XML_PROPERTY_NAME = "name";
+  private static final String PROPERTY_XML_PROPERTY_VALUE = "value";
+  private static final String PROPERTY_XML_PROPERTY_DESCRIPTION = "description";
+  private static final FilenameFilter FILENAME_FILTER = new FilenameFilter() {
+    @Override
+    public boolean accept(File dir, String s) {
+      if (s.equals(".svn") || s.equals(".git"))
+        return false;
+      return true;
+    }
+  };
+
+  private String serverVersion = "undefined";
+  private List<StackInfo> stacksResult = new ArrayList<StackInfo>();
+  private File stackRoot;
+  private File serverVersionFile;
+
+  /**
+   * Ambari Meta Info Object
+   *
+   * @param conf Configuration API to be used.
+   * @throws Exception
+   */
+  @Inject
+  public AmbariMetaInfo(Configuration conf) throws Exception {
+    String stackPath = conf.getMetadataPath();
+    String serverVersionFilePath = conf.getServerVersionFilePath();
+    this.stackRoot = new File(stackPath);
+    this.serverVersionFile = new File(serverVersionFilePath);
+  }
+
+  @Inject
+  public AmbariMetaInfo(File stackRoot, File serverVersionFile) throws Exception {
+    this.stackRoot = stackRoot;
+    this.serverVersionFile = serverVersionFile;
+  }
+
+  /**
+   * Initialize the Ambari Meta Info
+   *
+   * @throws Exception throws exception if not able to parse the Meta data.
+   */
+  @Inject
+  public void init() throws Exception {
+    readServerVersion();
+    getConfigurationInformation(stackRoot);
+  }
+
+  /**
+   * Get component category
+   *
+   * @param stackName
+   * @param version
+   * @param serviceName
+   * @param componentName
+   * @return component component Info
+   * @throws AmbariException
+   */
+  public ComponentInfo getComponentCategory(String stackName, String version,
+                                            String serviceName, String componentName) throws AmbariException {
+    ComponentInfo component = null;
+    List<ComponentInfo> components = getComponentsByService(stackName, version,
+        serviceName);
+    if (components != null)
+      for (ComponentInfo cmp : components) {
+        if (cmp.getName().equals(componentName)) {
+          component = cmp;
+          break;
+        }
       }
-    };
-    
+    return component;
+  }
 
-    /**
-     * Ambari Meta Info Object
-     *
-     * @param conf Configuration API to be used.
-     * @throws Exception
-     */
-    @Inject
-    public AmbariMetaInfo(Configuration conf) throws Exception {
-      String stackPath = conf.getMetadataPath();
-      String serverVersionFilePath = conf.getServerVersionFilePath();
-      this.stackRoot = new File(stackPath);
-      this.serverVersionFile = new File(serverVersionFilePath);
-    }
-
-    @Inject
-    public AmbariMetaInfo(File stackRoot, File serverVersionFile) throws Exception {
-      this.stackRoot = stackRoot;
-      this.serverVersionFile = serverVersionFile;
+  /**
+   * Get components by service
+   *
+   * @param stackName
+   * @param version
+   * @param serviceName
+   * @return
+   * @throws AmbariException
+   */
+  public List<ComponentInfo> getComponentsByService(String stackName,
+                                                    String version, String serviceName) throws AmbariException {
+    List<ComponentInfo> componentsResult = null;
+    ServiceInfo service = getServiceInfo(stackName, version, serviceName);
+    if (service != null)
+      componentsResult = service.getComponents();
+
+    return componentsResult;
+  }
+
+  public ComponentInfo getComponent(String stackName, String version, String serviceName,
+                                    String componentName) throws AmbariException {
+
+    List<ComponentInfo> componentsByService = getComponentsByService(stackName, version, serviceName);
+
+    if (componentsByService.size() == 0)
+      throw new StackAccessException("stackName=" + stackName
+          + ", stackVersion=" + version
+          + ", stackVersion=" + serviceName
+          + ", componentName=" + componentName);
+
+    ComponentInfo componentResult = null;
+
+    for (ComponentInfo component : componentsByService) {
+      if (component.getName().equals(componentName))
+        componentResult = component;
     }
 
+    if (componentResult == null)
+      throw new StackAccessException("stackName=" + stackName
+          + ", stackVersion=" + version
+          + ", stackVersion=" + serviceName
+          + ", componentName=" + componentName);
+
+    return componentResult;
+  }
 
-    /**
-     * Initialize the Ambari Meta Info
-     *
-     * @throws Exception throws exception if not able to parse the Meta data.
-     */
-    @Inject
-    public void init() throws Exception {
-        readServerVersion();
-        getConfigurationInformation(stackRoot);
+  public Map<String, List<RepositoryInfo>> getRepository(String stackName,
+                                                         String version) throws AmbariException {
+    Map<String, List<RepositoryInfo>> reposResult = null;
+    StackInfo stack = getStackInfo(stackName, version);
+    if (stack != null) {
+      List<RepositoryInfo> repository = stack.getRepositories();
+      reposResult = new HashMap<String, List<RepositoryInfo>>();
+      for (RepositoryInfo repo : repository) {
+        if (!reposResult.containsKey(repo.getOsType())) {
+          reposResult.put(repo.getOsType(),
+              new ArrayList<RepositoryInfo>());
+        }
+        reposResult.get(repo.getOsType()).add(repo);
+      }
     }
+    return reposResult;
+  }
 
+  public List<RepositoryInfo> getRepositories(String stackName,
+                                              String version, String osType) throws AmbariException {
 
-    /**
-     * Get component category
-     *
-     * @param stackName
-     * @param version
-     * @param serviceName
-     * @param componentName
-     * @return component component Info
-     * @throws AmbariException 
-     */
-    public ComponentInfo getComponentCategory(String stackName, String version,
-                                              String serviceName, String componentName) throws AmbariException {
-        ComponentInfo component = null;
-        List<ComponentInfo> components = getComponentsByService(stackName, version,
-                serviceName);
-        if (components != null)
-            for (ComponentInfo cmp : components) {
-                if (cmp.getName().equals(componentName)) {
-                    component = cmp;
-                    break;
-                }
-            }
-        return component;
+    StackInfo stack = getStackInfo(stackName, version);
+    List<RepositoryInfo> repositories = stack.getRepositories();
+
+    List<RepositoryInfo> repositoriesResult = new ArrayList<RepositoryInfo>();
+    for (RepositoryInfo repository : repositories) {
+      if (repository.getOsType().equals(osType))
+        repositoriesResult.add(repository);
     }
+    return repositoriesResult;
+  }
 
+  public RepositoryInfo getRepository(String stackName,
+                                      String version, String osType, String repoId) throws AmbariException {
 
-    /**
-     * Get components by service
-     *
-     * @param stackName
-     * @param version
-     * @param serviceName
-     * @return
-     * @throws AmbariException 
-     */
-    public List<ComponentInfo> getComponentsByService(String stackName,
-                                                      String version, String serviceName) throws AmbariException {
-        List<ComponentInfo> componentsResult = null;
-        ServiceInfo service = getServiceInfo(stackName, version, serviceName);
-        if (service != null)
-            componentsResult = service.getComponents();
-
-        return componentsResult;
-    }
-    
-    public ComponentInfo getComponent(String stackName, String version, String serviceName,
-        String componentName) throws AmbariException {
-      
-      List<ComponentInfo> componentsByService = getComponentsByService(stackName, version, serviceName);
-      
-      if (componentsByService.size() == 0)
-        throw new StackAccessException("stackName=" + stackName 
-                                     + ", stackVersion=" + version 
-                                     + ", stackVersion=" + serviceName 
-                                     + ", componentName=" + componentName);
-      
-      ComponentInfo componentResult = null;
-      
-      for (ComponentInfo component: componentsByService) {
-        if (component.getName().equals(componentName))
-          componentResult = component;
-      }
-      
-      if (componentResult == null)
-        throw new StackAccessException("stackName=" + stackName 
-                                     + ", stackVersion=" + version 
-                                     + ", stackVersion=" + serviceName 
-                                     + ", componentName=" + componentName);
-      
-      return componentResult; 
-    }
-
-    public Map<String, List<RepositoryInfo>> getRepository(String stackName,
-                                                           String version) throws AmbariException {
-        Map<String, List<RepositoryInfo>> reposResult = null;
-        StackInfo stack = getStackInfo(stackName, version);
-        if (stack != null) {
-            List<RepositoryInfo> repository = stack.getRepositories();
-            reposResult = new HashMap<String, List<RepositoryInfo>>();
-            for (RepositoryInfo repo : repository) {
-                if (!reposResult.containsKey(repo.getOsType())) {
-                    reposResult.put(repo.getOsType(),
-                            new ArrayList<RepositoryInfo>());
-                }
-                reposResult.get(repo.getOsType()).add(repo);
-            }
+    List<RepositoryInfo> repositories = getRepositories(stackName, version, osType);
+
+    if (repositories.size() == 0)
+      throw new StackAccessException("stackName=" + stackName
+          + ", stackVersion=" + version
+          + ", osType=" + osType
+          + ", repoId=" + repoId);
+
+    RepositoryInfo repoResult = null;
+    for (RepositoryInfo repository : repositories) {
+      if (repository.getRepoId().equals(repoId))
+        repoResult = repository;
+    }
+    if (repoResult == null)
+      throw new StackAccessException("stackName=" + stackName
+          + ", stackName= " + version
+          + ", osType=" + osType
+          + ", repoId= " + repoId);
+    return repoResult;
+  }
+
+  /*
+   * function for given a stack name and version, is it a supported stack
+   */
+  public boolean isSupportedStack(String stackName, String version) throws AmbariException {
+    boolean exist = false;
+    try {
+      getStackInfo(stackName, version);
+      exist = true;
+    } catch (ObjectNotFoundException e) {
+    }
+    return exist;
+  }
+
+  /*
+   * support isValidService(), isValidComponent for a given stack/version
+   */
+  public boolean isValidService(String stackName, String version,
+                                String serviceName) throws AmbariException {
+
+    boolean exist = false;
+    try {
+      getServiceInfo(stackName, version, serviceName);
+      exist = true;
+    } catch (ObjectNotFoundException e) {
+    }
+    return exist;
+  }
+
+  /*
+   * support isValidService(), isValidComponent for a given stack/version
+   */
+  public boolean isValidServiceComponent(String stackName, String version,
+                                         String serviceName, String componentName) throws AmbariException {
+    ServiceInfo service = getServiceInfo(stackName, version, serviceName);
+    if (service == null) {
+      return false;
+    }
+    for (ComponentInfo compInfo : service.getComponents()) {
+      if (compInfo.getName().equals(componentName)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  /**
+   * Get the name of a service given the component name.
+   *
+   * @param stackName     the stack name
+   * @param version       the stack version
+   * @param componentName the component name
+   * @return the service name
+   * @throws AmbariException
+   */
+  public String getComponentToService(String stackName, String version,
+                                      String componentName) throws AmbariException {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Looking for service for component"
+          + ", stackName=" + stackName
+          + ", stackVersion=" + version
+          + ", componentName=" + componentName);
+    }
+    Map<String, ServiceInfo> services = getServices(stackName, version);
+    String retService = null;
+    if (services == null
+        || services.isEmpty()) {
+      return retService;
+    }
+    boolean found = false;
+    for (Map.Entry<String, ServiceInfo> entry : services.entrySet()) {
+      for (ComponentInfo compInfo : entry.getValue().getComponents()) {
+        if (compInfo.getName().equals(componentName)) {
+          retService = entry.getKey();
+          found = true;
+          break;
         }
-        return reposResult;
+      }
+      if (found)
+        break;
     }
-    
-    
-    public List<RepositoryInfo> getRepositories(String stackName,
-        String version, String osType) throws AmbariException {
-      
-      StackInfo stack = getStackInfo(stackName, version);
-      List<RepositoryInfo> repositories = stack.getRepositories();
-      
-      List<RepositoryInfo> repositoriesResult = new ArrayList<RepositoryInfo>();
-      for (RepositoryInfo repository : repositories) {
-        if (repository.getOsType().equals(osType))
-          repositoriesResult.add(repository);
-      }
-      return repositoriesResult;
-    }
-    
-    
-    public RepositoryInfo getRepository(String stackName,
-        String version, String osType, String repoId) throws AmbariException {
-      
-      List<RepositoryInfo> repositories = getRepositories(stackName, version, osType);
-      
-      if (repositories.size() == 0)
-        throw new StackAccessException("stackName=" + stackName 
-                                     + ", stackVersion=" + version 
-                                     + ", osType=" + osType
-                                     + ", repoId=" + repoId);
-
-      RepositoryInfo repoResult = null;
-      for (RepositoryInfo repository : repositories) {
-        if (repository.getRepoId().equals(repoId))
-          repoResult = repository;
-      }
-      if (repoResult == null )
-        throw new StackAccessException("stackName=" + stackName 
-                                       + ", stackName= " + version
-                                       + ", osType=" + osType 
-                                       + ", repoId= " + repoId);
-      return repoResult;
-    }
-    
-
-    /*
-     * function for given a stack name and version, is it a supported stack
-     */
-    public boolean isSupportedStack(String stackName, String version) throws AmbariException {
-        boolean exist = false;
-        try {
-          getStackInfo(stackName, version);
-          exist = true;
-        } catch (ObjectNotFoundException e) { }
-        return exist;
-    }
-
-    /*
-     * support isValidService(), isValidComponent for a given stack/version
-     */
-    public boolean isValidService(String stackName, String version,
-                                  String serviceName) throws AmbariException {
-      
-      boolean exist = false;
-      try {
-        getServiceInfo(stackName, version, serviceName);
-        exist = true;
-      } catch (ObjectNotFoundException e) { }
-      return exist;
-    }
-
-    /*
-     * support isValidService(), isValidComponent for a given stack/version
-     */
-    public boolean isValidServiceComponent(String stackName, String version,
-                                           String serviceName, String componentName) throws AmbariException {
-        ServiceInfo service = getServiceInfo(stackName, version, serviceName);
-        if (service == null) {
-            return false;
-        }
-        for (ComponentInfo compInfo : service.getComponents()) {
-            if (compInfo.getName().equals(componentName)) {
-                return true;
+    return retService;
+  }
+
+  /**
+   * Get the service configs supported for a service in a particular stack
+   *
+   * @param stackName   the stack name
+   * @param version     the version of the stack
+   * @param serviceName the name of the service in the stack
+   * @return the config knobs supported for the service
+   * @throws AmbariException
+   */
+  public Map<String, Map<String, String>> getSupportedConfigs(String stackName,
+                                                              String version, String serviceName) throws AmbariException {
+    Map<String, Map<String, String>> propertiesResult = new HashMap<String, Map<String, String>>();
+
+    ServiceInfo service = getServiceInfo(stackName, version, serviceName);
+    if (service != null)
+      if (serviceName.equals(service.getName())) {
+        List<PropertyInfo> properties = service.getProperties();
+        if (properties != null)
+          for (PropertyInfo propertyInfo : properties) {
+            Map<String, String> fileProperties = propertiesResult
+                .get(propertyInfo.getFilename());
+            if (fileProperties == null) {
+              fileProperties = new HashMap<String, String>();
+              fileProperties.put(propertyInfo.getName(),
+                  propertyInfo.getValue());
+              propertiesResult.put(propertyInfo.getFilename(), fileProperties);
+
+            } else {
+              fileProperties.put(propertyInfo.getName(),
+                  propertyInfo.getValue());
             }
+
+          }
+      }
+
+    return propertiesResult;
+  }
+
+  /**
+   * Given a stack name and version return all the services with info
+   *
+   * @param stackName the stack name
+   * @param version   the version of the stack
+   * @return the information of abt varios services that are supported in the
+   *         stack
+   * @throws AmbariException
+   */
+  public Map<String, ServiceInfo> getServices(String stackName, String version) throws AmbariException {
+
+    Map<String, ServiceInfo> servicesInfoResult = new HashMap<String, ServiceInfo>();
+
+    List<ServiceInfo> services = null;
+    StackInfo stack = getStackInfo(stackName, version);
+    if (stack == null)
+      return null;
+    services = stack.getServices();
+    if (services != null)
+      for (ServiceInfo service : services) {
+        servicesInfoResult.put(service.getName(), service);
+      }
+    return servicesInfoResult;
+  }
+
+  public ServiceInfo getService(String stackName, String version, String serviceName) throws AmbariException {
+
+    Map<String, ServiceInfo> services = getServices(stackName, version);
+
+    if (services.size() == 0)
+      throw new StackAccessException("stackName=" + stackName + ", stackVersion=" + version + ", serviceName=" + serviceName);
+
+    ServiceInfo serviceInfo = services.get(serviceName);
+
+    if (serviceInfo == null)
+      throw new StackAccessException("stackName=" + stackName + ", stackVersion=" + version + ", serviceName=" + serviceName);
+
+    return serviceInfo;
+
+  }
+
+  public ServiceInfo getServiceInfo(String stackName, String version,
+                                    String serviceName) throws AmbariException {
+    ServiceInfo serviceInfoResult = null;
+    List<ServiceInfo> services = null;
+    StackInfo stack = getStackInfo(stackName, version);
+    if (stack == null)
+      return null;
+    services = stack.getServices();
+    if (services != null)
+      for (ServiceInfo service : services) {
+        if (serviceName.equals(service.getName())) {
+          serviceInfoResult = service;
+          break;
         }
-        return false;
+      }
+    return serviceInfoResult;
+  }
+
+  public List<ServiceInfo> getSupportedServices(String stackName, String version) throws AmbariException {
+    List<ServiceInfo> servicesResulr = null;
+    StackInfo stack = getStackInfo(stackName, version);
+    if (stack != null)
+      servicesResulr = stack.getServices();
+    return servicesResulr;
+  }
+
+  public List<StackInfo> getSupportedStacks() {
+    return stacksResult;
+  }
+
+  public Set<Stack> getStackNames() {
+
+    Set<Stack> stacks = new HashSet<Stack>();
+    List<StackInfo> supportedStacks = getSupportedStacks();
+
+    for (StackInfo stackInfo : supportedStacks) {
+      Stack stack = new Stack(stackInfo.getName());
+      stacks.add(stack);
     }
 
+    return stacks;
+  }
+
+  public Stack getStack(String stackName) throws AmbariException {
 
-    /**
-     * Get the name of a service given the component name.
-     *
-     * @param stackName     the stack name
-     * @param version       the stack version
-     * @param componentName the component name
-     * @return the service name
-     * @throws AmbariException 
-     */
-    public String getComponentToService(String stackName, String version,
-                                        String componentName) throws AmbariException {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Looking for service for component"
-                    + ", stackName=" + stackName
-                    + ", stackVersion=" + version
-                    + ", componentName=" + componentName);
-        }
-        Map<String, ServiceInfo> services = getServices(stackName, version);
-        String retService = null;
-        if (services == null
-                || services.isEmpty()) {
-            return retService;
-        }
-        boolean found = false;
-        for (Map.Entry<String, ServiceInfo> entry : services.entrySet()) {
-            for (ComponentInfo compInfo : entry.getValue().getComponents()) {
-                if (compInfo.getName().equals(componentName)) {
-                    retService = entry.getKey();
-                    found = true;
-                    break;
-                }
-            }
-            if (found)
-                break;
-        }
-        return retService;
+    Set<Stack> supportedStackNames = getStackNames();
+
+    if (supportedStackNames.size() == 0)
+      throw new StackAccessException("stackName=" + stackName);
+
+    Stack stackResult = null;
+
+    for (Stack stack : supportedStackNames) {
+      if (stack.getStackName().equals(stackName))
+        stackResult = stack;
     }
 
-    /**
-     * Get the service configs supported for a service in a particular stack
-     *
-     * @param stackName   the stack name
-     * @param version     the version of the stack
-     * @param serviceName the name of the service in the stack
-     * @return the config knobs supported for the service
-     * @throws AmbariException 
-     */
-    public Map<String, Map<String, String>> getSupportedConfigs(String stackName,
-                                                                String version, String serviceName) throws AmbariException {
-        Map<String, Map<String, String>> propertiesResult = new HashMap<String, Map<String, String>>();
-
-        ServiceInfo service = getServiceInfo(stackName, version, serviceName);
-        if (service != null)
-            if (serviceName.equals(service.getName())) {
-                List<PropertyInfo> properties = service.getProperties();
-                if (properties != null)
-                    for (PropertyInfo propertyInfo : properties) {
-                        Map<String, String> fileProperties = propertiesResult
-                                .get(propertyInfo.getFilename());
-                        if (fileProperties == null) {
-                            fileProperties = new HashMap<String, String>();
-                            fileProperties.put(propertyInfo.getName(),
-                                    propertyInfo.getValue());
-                            propertiesResult.put(propertyInfo.getFilename(), fileProperties);
-
-                        } else {
-                            fileProperties.put(propertyInfo.getName(),
-                                    propertyInfo.getValue());
-                        }
+    if (stackResult == null)
+      throw new StackAccessException("stackName=" + stackName);
 
-                    }
-            }
+    return stackResult;
+  }
+
+  public Set<StackInfo> getStackInfos(String stackName) {
 
-        return propertiesResult;
+    Set<StackInfo> stackVersions = new HashSet<StackInfo>();
+    for (StackInfo stackInfo : stacksResult) {
+      if (stackName.equals(stackInfo.getName()))
+        stackVersions.add(stackInfo);
     }
+    return stackVersions;
+  }
 
-    /**
-     * Given a stack name and version return all the services with info
-     *
-     * @param stackName the stack name
-     * @param version   the version of the stack
-     * @return the information of abt varios services that are supported in the
-     *         stack
-     * @throws AmbariException 
-     */
-    public Map<String, ServiceInfo> getServices(String stackName, String version) throws AmbariException {
-
-        Map<String, ServiceInfo> servicesInfoResult = new HashMap<String, ServiceInfo>();
-
-        List<ServiceInfo> services = null;
-        StackInfo stack = getStackInfo(stackName, version);
-        if (stack == null)
-            return null;
-        services = stack.getServices();
-        if (services != null)
-            for (ServiceInfo service : services) {
-                servicesInfoResult.put(service.getName(), service);
-            }
-        return servicesInfoResult;
+  public StackInfo getStackInfo(String stackName, String version) throws AmbariException {
+    StackInfo stackInfoResult = null;
+
+    for (StackInfo stack : stacksResult) {
+      if (stackName.equals(stack.getName())
+          && version.equals(stack.getVersion())) {
+        stackInfoResult = stack;
+        break;
+      }
     }
-    
-    
-    public ServiceInfo getService(String stackName, String version, String serviceName) throws AmbariException {
-
-      Map<String, ServiceInfo> services = getServices(stackName, version);
-      
-      if (services.size() == 0)
-        throw new StackAccessException("stackName=" + stackName +", stackVersion=" + version + ", serviceName=" + serviceName);
-      
-      ServiceInfo serviceInfo = services.get(serviceName);
-      
-      if (serviceInfo == null)
-        throw new StackAccessException("stackName=" + stackName +", stackVersion=" + version + ", serviceName=" + serviceName);
-      
-      return serviceInfo;
-        
-  }
-    
-    
-    public ServiceInfo getServiceInfo(String stackName, String version,
-                                      String serviceName) throws AmbariException {
-        ServiceInfo serviceInfoResult = null;
-        List<ServiceInfo> services = null;
-        StackInfo stack = getStackInfo(stackName, version);
-        if (stack == null)
-            return null;
-        services = stack.getServices();
-        if (services != null)
-            for (ServiceInfo service : services) {
-                if (serviceName.equals(service.getName())) {
-                    serviceInfoResult = service;
-                    break;
-                }
-            }
-        return serviceInfoResult;
+
+    if (stackInfoResult == null)
+      throw new StackAccessException("stackName=" + stackName
+          + ", stackVersion=" + version);
+
+    return stackInfoResult;
+  }
+
+  public Set<PropertyInfo> getProperties(String stackName, String version, String serviceName)
+      throws AmbariException {
+
+    ServiceInfo serviceInfo = getServiceInfo(stackName, version, serviceName);
+    List<PropertyInfo> properties = serviceInfo.getProperties();
+    Set<PropertyInfo> propertiesResult = new HashSet<PropertyInfo>(properties);
+
+    return propertiesResult;
+  }
+
+  public PropertyInfo getProperty(String stackName, String version, String serviceName, String propertyName)
+      throws AmbariException {
+    Set<PropertyInfo> properties = getProperties(stackName, version, serviceName);
+
+    if (properties.size() == 0)
+      throw new StackAccessException("stackName=" + stackName
+          + ", stackVersion=" + version
+          + ", serviceName=" + serviceName
+          + ", propertyName=" + propertyName);
+
+    PropertyInfo propertyResult = null;
+
+    for (PropertyInfo property : properties) {
+      if (property.getName().equals(propertyName))
+        propertyResult = property;
+    }
+
+    if (propertyResult == null)
+      throw new StackAccessException("stackName=" + stackName
+          + ", stackVersion=" + version
+          + ", serviceName=" + serviceName
+          + ", propertyName=" + propertyName);
+
+    return propertyResult;
+  }
+
+  public Set<OperatingSystemInfo> getOperatingSystems(String stackName, String version)
+      throws AmbariException {
+
+    Set<OperatingSystemInfo> operatingSystems = new HashSet<OperatingSystemInfo>();
+    StackInfo stack = getStackInfo(stackName, version);
+    List<RepositoryInfo> repositories = stack.getRepositories();
+    for (RepositoryInfo repository : repositories) {
+      operatingSystems.add(new OperatingSystemInfo(repository.getOsType()));
     }
 
-    public List<ServiceInfo> getSupportedServices(String stackName, String version) throws AmbariException {
-        List<ServiceInfo> servicesResulr = null;
-        StackInfo stack = getStackInfo(stackName, version);
-        if (stack != null)
-            servicesResulr = stack.getServices();
-        return servicesResulr;
-    }
-
-    public List<StackInfo> getSupportedStacks() {
-        return stacksResult;
-    }
-    
-    public Set<Stack> getStackNames() {
-      
-      Set<Stack> stacks = new HashSet<Stack>();
-      List<StackInfo> supportedStacks = getSupportedStacks();
-      
-      for(StackInfo stackInfo : supportedStacks) {
-        Stack stack = new Stack(stackInfo.getName());
-        stacks.add(stack);
-      }
-      
-      return stacks;
-  }
-    
-    
-    public Stack getStack(String stackName) throws AmbariException {
-      
-      Set<Stack> supportedStackNames = getStackNames();   
-      
-      if (supportedStackNames.size()==0)
-        throw new StackAccessException("stackName=" + stackName);
-
-      Stack stackResult = null;
-      
-      for (Stack stack: supportedStackNames) {
-        if (stack.getStackName().equals(stackName))
-          stackResult = stack;
-      }
-      
-      if (stackResult == null)
-        throw new StackAccessException("stackName=" + stackName);
-
-      return stackResult;
-  }
-    
-
-    
-    public Set<StackInfo> getStackInfos(String stackName) {
-      
-      Set<StackInfo> stackVersions = new HashSet<StackInfo>();
-      for (StackInfo stackInfo : stacksResult ) {
-        if (stackName.equals(stackInfo.getName()))
-          stackVersions.add(stackInfo);
-      }
-      return stackVersions;
-
-    }
-    
-    public StackInfo getStackInfo(String stackName, String version) throws AmbariException {
-      StackInfo stackInfoResult = null;
-
-      for (StackInfo stack : stacksResult) {
-          if (stackName.equals(stack.getName())
-                  && version.equals(stack.getVersion())) {
-              stackInfoResult = stack;
-              break;
-          }
-      }
-      
-      if (stackInfoResult == null)
-        throw new StackAccessException("stackName=" + stackName
-                                     + ", stackVersion=" + version);
-      
-      return stackInfoResult;
-  }
-    
-    
-    public Set<PropertyInfo> getProperties(String stackName, String version, String serviceName) throws AmbariException {
-
-      ServiceInfo serviceInfo = getServiceInfo(stackName, version, serviceName);
-      List<PropertyInfo> properties = serviceInfo.getProperties();
-      Set<PropertyInfo> propertiesResult = new HashSet<PropertyInfo>(properties);
-      
-      return propertiesResult;
-      
-  }
-    
-    public PropertyInfo getProperty(String stackName, String version, String serviceName, String propertyName) throws AmbariException {
-      Set<PropertyInfo> properties = getProperties(stackName, version, serviceName);
-      
-      if (properties.size() == 0)
-        throw new StackAccessException("stackName=" + stackName 
-                                     + ", stackVersion=" + version
-                                     + ", serviceName=" + serviceName
-                                     + ", propertyName=" +  propertyName);
-
-      PropertyInfo propertyResult = null;
-
-      for (PropertyInfo property : properties) {
-        if (property.getName().equals(propertyName))
-          propertyResult = property;
-      }
-      
-      if (propertyResult == null)
-        throw new StackAccessException("stackName=" + stackName 
-            + ", stackVersion=" + version
-            + ", serviceName=" + serviceName
-            + ", propertyName=" +  propertyName);
-      
-      return propertyResult;  
-  }
-
-
-    public Set<OperatingSystemInfo> getOperatingSystems(String stackName, String version) throws AmbariException {
-      
-      Set<OperatingSystemInfo> operatingSystems = new HashSet<OperatingSystemInfo>();;
-      StackInfo stack = getStackInfo(stackName, version);
-      List<RepositoryInfo> repositories = stack.getRepositories();
-      for (RepositoryInfo repository: repositories ) {
-        operatingSystems.add(new OperatingSystemInfo(repository.getOsType()));
-      }
-      
-      return operatingSystems;
-  }
-    
-    public OperatingSystemInfo getOperatingSystem(String stackName, String version, String osType) throws AmbariException {
-      
-      Set<OperatingSystemInfo> operatingSystems = getOperatingSystems(stackName, version);
-      
-      if (operatingSystems.size() == 0)
-        throw new StackAccessException("stackName=" + stackName
-                                     + ", stackVersion=" + version
-                                     + ", osType=" + osType);
-      
-      OperatingSystemInfo resultOperatingSystem = null;
-      
-      for (OperatingSystemInfo operatingSystem : operatingSystems) {
-        if (operatingSystem.getOsType().equals(osType))
-          resultOperatingSystem = operatingSystem;
-      }
-      
-      if (resultOperatingSystem==null)
-        throw new StackAccessException("stackName=" + stackName
-                                     + ", stackVersion=" + version
-                                     + ", osType=" + osType);
-      
-      return resultOperatingSystem;
-  }
-
-
-    private void readServerVersion() throws  Exception{
-      File versionFile = this.serverVersionFile;
-      String t = (new File(".")).getAbsolutePath();
-      if (! versionFile.exists()) {
-        throw new AmbariException("Server version file does not exist");
-      }
-      serverVersion = new Scanner(versionFile).useDelimiter("\\Z").next();
+    return operatingSystems;
+  }
+
+  public OperatingSystemInfo getOperatingSystem(String stackName, String version, String osType)
+      throws AmbariException {
+
+    Set<OperatingSystemInfo> operatingSystems = getOperatingSystems(stackName, version);
+
+    if (operatingSystems.size() == 0)
+      throw new StackAccessException("stackName=" + stackName
+          + ", stackVersion=" + version
+          + ", osType=" + osType);
+
+    OperatingSystemInfo resultOperatingSystem = null;
+
+    for (OperatingSystemInfo operatingSystem : operatingSystems) {
+      if (operatingSystem.getOsType().equals(osType))
+        resultOperatingSystem = operatingSystem;
     }
 
-    private void getConfigurationInformation(File stackRoot) throws Exception {
+    if (resultOperatingSystem == null)
+      throw new StackAccessException("stackName=" + stackName
+          + ", stackVersion=" + version
+          + ", osType=" + osType);
 
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Loading stack information"
-                    + ", stackRoot=" + stackRoot.getAbsolutePath());
-        }
+    return resultOperatingSystem;
+  }
 
-        if (!stackRoot.isDirectory() && !stackRoot.exists())
-            throw new IOException("" + Configuration.METADETA_DIR_PATH
-                    + " should be a directory with stack"
-                    + ", stackRoot=" + stackRoot.getAbsolutePath());
-        File[] stacks = stackRoot.listFiles(FILENAME_FILTER);
-        for (File stackFolder : stacks) {
-            if (stackFolder.isFile())
-                continue;
-            File[] concretStacks = stackFolder.listFiles(FILENAME_FILTER);
-            for (File stack : concretStacks) {
-                if (stack.isFile())
-                    continue;
-
-                StackInfo stackInfo = getStackInfo(stack);
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Adding new stack to known stacks"
-                            + ", stackName=" + stackFolder.getName()
-                            + ", stackVersion=" + stack.getName());
-                }
+  private void readServerVersion() throws Exception {
+    File versionFile = this.serverVersionFile;
+    if (!versionFile.exists()) {
+      throw new AmbariException("Server version file does not exist.");
+    }
+    serverVersion = new Scanner(versionFile).useDelimiter("\\Z").next();
+  }
 
-                stacksResult.add(stackInfo);
-                // get repository data for current stack of techs
-                File repositoryFolder = new File(stack.getAbsolutePath()
-                        + File.separator + REPOSITORY_FOLDER_NAME + File.separator
-                        + REPOSITORY_FILE_NAME);
-
-                if (repositoryFolder.exists()) {
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("Adding repositories to stack"
-                                + ", stackName=" + stackFolder.getName()
-                                + ", stackVersion=" + stack.getName()
-                                + ", repoFolder=" + repositoryFolder.getPath());
-                    }
-                    List<RepositoryInfo> repositoryInfoList = getRepository(repositoryFolder);
-                    stackInfo.getRepositories().addAll(repositoryInfoList);
-                }
+  private void getConfigurationInformation(File stackRoot) throws Exception {
+
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Loading stack information"
+          + ", stackRoot=" + stackRoot.getAbsolutePath());
+    }
+
+    if (!stackRoot.isDirectory() && !stackRoot.exists())
+      throw new IOException("" + Configuration.METADETA_DIR_PATH
+          + " should be a directory with stack"
+          + ", stackRoot=" + stackRoot.getAbsolutePath());
+    File[] stacks = stackRoot.listFiles(FILENAME_FILTER);
+    for (File stackFolder : stacks) {
+      if (stackFolder.isFile())
+        continue;
+      File[] concretStacks = stackFolder.listFiles(FILENAME_FILTER);
+      for (File stack : concretStacks) {
+        if (stack.isFile())
+          continue;
+
+        StackInfo stackInfo = getStackInfo(stack);
+        if (LOG.isDebugEnabled()) {
+          LOG.debug("Adding new stack to known stacks"
+              + ", stackName=" + stackFolder.getName()
+              + ", stackVersion=" + stack.getName());
+        }
+
+        stacksResult.add(stackInfo);
+        // get repository data for current stack of techs
+        File repositoryFolder = new File(stack.getAbsolutePath()
+            + File.separator + REPOSITORY_FOLDER_NAME + File.separator
+            + REPOSITORY_FILE_NAME);
+
+        if (repositoryFolder.exists()) {
+          if (LOG.isDebugEnabled()) {
+            LOG.debug("Adding repositories to stack"
+                + ", stackName=" + stackFolder.getName()
+                + ", stackVersion=" + stack.getName()
+                + ", repoFolder=" + repositoryFolder.getPath());
+          }
+          List<RepositoryInfo> repositoryInfoList = getRepository(repositoryFolder);
+          stackInfo.getRepositories().addAll(repositoryInfoList);
+        }
 
-                // Get services for this stack
-                File servicesRootFolder = new File(stack.getAbsolutePath()
-                        + File.separator + SERVICES_FOLDER_NAME);
-                File[] servicesFolders = servicesRootFolder.listFiles(FILENAME_FILTER);
-
-                if (servicesFolders != null) {
-                    for (File serviceFolder : servicesFolders) {
-                        // Get information about service
-                        ServiceInfo serviceInfo = new ServiceInfo();
-                        serviceInfo.setName(serviceFolder.getName());
-                        stackInfo.getServices().add(serviceInfo);
-
-                        if (LOG.isDebugEnabled()) {
-                            LOG.debug("Adding new service to stack"
-                                    + ", stackName=" + stackFolder.getName()
-                                    + ", stackVersion=" + stack.getName()
-                                    + ", serviceName=" + serviceInfo.getName());
-                        }
-
-                        // Get metainfo data from metainfo.xml
-                        File metainfoFile = new File(serviceFolder.getAbsolutePath()
-                                + File.separator + SERVICE_METAINFO_FILE_NAME);
-                        if (metainfoFile.exists()) {
-                            setMetaInfo(metainfoFile, serviceInfo);
-                        }
-
-                        // Get all properties from all "configs/*-site.xml" files
-                        File serviceConfigFolder = new File(serviceFolder.getAbsolutePath()
-                                + File.separator + SERVICE_CONFIG_FOLDER_NAME);
-                        File[] configFiles = serviceConfigFolder.listFiles(FILENAME_FILTER);
-                        if (configFiles != null) {
-                            for (File config : configFiles) {
-                                if (config.getName().endsWith(SERVICE_CONFIG_FILE_NAME_POSTFIX)) {
-                                    serviceInfo.getProperties().addAll(getProperties(config));
-                                }
-                            }
-                        }
-                    }
+        // Get services for this stack
+        File servicesRootFolder = new File(stack.getAbsolutePath()
+            + File.separator + SERVICES_FOLDER_NAME);
+        File[] servicesFolders = servicesRootFolder.listFiles(FILENAME_FILTER);
+
+        if (servicesFolders != null) {
+          for (File serviceFolder : servicesFolders) {
+            // Get information about service
+            ServiceInfo serviceInfo = new ServiceInfo();
+            serviceInfo.setName(serviceFolder.getName());
+            stackInfo.getServices().add(serviceInfo);
+
+            if (LOG.isDebugEnabled()) {
+              LOG.debug("Adding new service to stack"
+                  + ", stackName=" + stackFolder.getName()
+                  + ", stackVersion=" + stack.getName()
+                  + ", serviceName=" + serviceInfo.getName());
+            }
+
+            // Get metainfo data from metainfo.xml
+            File metainfoFile = new File(serviceFolder.getAbsolutePath()
+                + File.separator + SERVICE_METAINFO_FILE_NAME);
+            if (metainfoFile.exists()) {
+              setMetaInfo(metainfoFile, serviceInfo);
+            }
+
+            // Get all properties from all "configs/*-site.xml" files
+            File serviceConfigFolder = new File(serviceFolder.getAbsolutePath()
+                + File.separator + SERVICE_CONFIG_FOLDER_NAME);
+            File[] configFiles = serviceConfigFolder.listFiles(FILENAME_FILTER);
+            if (configFiles != null) {
+              for (File config : configFiles) {
+                if (config.getName().endsWith(SERVICE_CONFIG_FILE_NAME_POSTFIX)) {
+                  serviceInfo.getProperties().addAll(getProperties(config));
                 }
+              }
             }
+          }
         }
+      }
     }
+  }
 
   public String getServerVersion() {
     return serverVersion;
@@ -720,7 +703,7 @@ public class AmbariMetaInfo {
         for (int index = 0; index < stackNodes.getLength(); index++) {
 
           Node node = stackNodes.item(index);
-          
+
           if (node.getNodeType() == Node.ELEMENT_NODE) {
             Element property = (Element) node;
 
@@ -734,223 +717,218 @@ public class AmbariMetaInfo {
       }
 
     }
-
     return stackInfo;
-
   }
 
-    private List<RepositoryInfo> getRepository(File repositoryFile) throws ParserConfigurationException, IOException, SAXException {
+  private List<RepositoryInfo> getRepository(File repositoryFile)
+      throws ParserConfigurationException, IOException, SAXException {
 
-        List<RepositoryInfo> repositorysInfo = new ArrayList<RepositoryInfo>();
+    List<RepositoryInfo> repositorysInfo = new ArrayList<RepositoryInfo>();
 //    try {
 
-        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
-        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
-        Document doc = dBuilder.parse(repositoryFile);
-
-        NodeList osNodes = doc
-                .getElementsByTagName(REPOSITORY_XML_MAIN_BLOCK_NAME);
-
-        for (int index = 0; index < osNodes.getLength(); index++) {
-            Node osNode = osNodes.item(index);
-
-            if (osNode.getNodeType() == Node.ELEMENT_NODE) {
-                if (!osNode.getNodeName().equals(REPOSITORY_XML_MAIN_BLOCK_NAME)) {
-                    continue;
-                }
-                NamedNodeMap attrs = osNode.getAttributes();
-                Node osAttr = attrs.getNamedItem(REPOSITORY_XML_ATTRIBUTE_OS_TYPE);
-                if (osAttr == null) {
-                    continue;
-                }
-                String osType = osAttr.getNodeValue();
-
-                NodeList repoNodes = osNode.getChildNodes();
-                for (int j = 0; j < repoNodes.getLength(); j++) {
-                    Node repoNode = repoNodes.item(j);
-                    if (repoNode.getNodeType() != Node.ELEMENT_NODE
-                            || !repoNode.getNodeName().equals(
-                            REPOSITORY_XML_REPO_BLOCK_NAME)) {
-                        continue;
-                    }
-                    Element property = (Element) repoNode;
-                    String repoId = getTagValue(REPOSITORY_XML_PROPERTY_REPOID,
-                            property);
-                    String repoName = getTagValue(REPOSITORY_XML_PROPERTY_REPONAME,
-                            property);
-                    String baseUrl = getTagValue(
-                            REPOSITORY_XML_PROPERTY_BASEURL, property);
-                    String mirrorsList = getTagValue(
-                            REPOSITORY_XML_PROPERTY_MIRRORSLIST, property);
-
-                    String[] osTypes = osType.split(",");
-
-                    for (String os : osTypes) {
-                        RepositoryInfo repositoryInfo = new RepositoryInfo();
-                        repositoryInfo.setOsType(os.trim());
-                        repositoryInfo.setRepoId(repoId);
-                        repositoryInfo.setRepoName(repoName);
-                        repositoryInfo.setBaseUrl(baseUrl);
-                        repositoryInfo.setMirrorsList(mirrorsList);
-
-                        if (LOG.isDebugEnabled()) {
-                            LOG.debug("Adding repo to stack"
-                                    + ", repoInfo=" + repositoryInfo.toString());
-                        }
-                        repositorysInfo.add(repositoryInfo);
-                    }
-                }
+    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+    Document doc = dBuilder.parse(repositoryFile);
+
+    NodeList osNodes = doc
+        .getElementsByTagName(REPOSITORY_XML_MAIN_BLOCK_NAME);
+
+    for (int index = 0; index < osNodes.getLength(); index++) {
+      Node osNode = osNodes.item(index);
+
+      if (osNode.getNodeType() == Node.ELEMENT_NODE) {
+        if (!osNode.getNodeName().equals(REPOSITORY_XML_MAIN_BLOCK_NAME)) {
+          continue;
+        }
+        NamedNodeMap attrs = osNode.getAttributes();
+        Node osAttr = attrs.getNamedItem(REPOSITORY_XML_ATTRIBUTE_OS_TYPE);
+        if (osAttr == null) {
+          continue;
+        }
+        String osType = osAttr.getNodeValue();
+
+        NodeList repoNodes = osNode.getChildNodes();
+        for (int j = 0; j < repoNodes.getLength(); j++) {
+          Node repoNode = repoNodes.item(j);
+          if (repoNode.getNodeType() != Node.ELEMENT_NODE
+              || !repoNode.getNodeName().equals(
+              REPOSITORY_XML_REPO_BLOCK_NAME)) {
+            continue;
+          }
+          Element property = (Element) repoNode;
+          String repoId = getTagValue(REPOSITORY_XML_PROPERTY_REPOID,
+              property);
+          String repoName = getTagValue(REPOSITORY_XML_PROPERTY_REPONAME,
+              property);
+          String baseUrl = getTagValue(
+              REPOSITORY_XML_PROPERTY_BASEURL, property);
+          String mirrorsList = getTagValue(
+              REPOSITORY_XML_PROPERTY_MIRRORSLIST, property);
+
+          String[] osTypes = osType.split(",");
+
+          for (String os : osTypes) {
+            RepositoryInfo repositoryInfo = new RepositoryInfo();
+            repositoryInfo.setOsType(os.trim());
+            repositoryInfo.setRepoId(repoId);
+            repositoryInfo.setRepoName(repoName);
+            repositoryInfo.setBaseUrl(baseUrl);
+            repositoryInfo.setMirrorsList(mirrorsList);
+
+            if (LOG.isDebugEnabled()) {
+              LOG.debug("Adding repo to stack"
+                  + ", repoInfo=" + repositoryInfo.toString());
             }
+            repositorysInfo.add(repositoryInfo);
+          }
         }
+      }
+    }
 //    } catch (Exception e) {
 //      e.printStackTrace();
 //    }
 
-        return repositorysInfo;
+    return repositorysInfo;
+  }
+
+  private void setMetaInfo(File metainfoFile, ServiceInfo serviceInfo) {
+
+    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+
+    Document doc = null;
+    DocumentBuilder dBuilder = null;
+    try {
+      dBuilder = dbFactory.newDocumentBuilder();
+      doc = dBuilder.parse(metainfoFile);
+    } catch (SAXException e) {
+      LOG.error("Error while parsing metainf.xml", e);
+    } catch (IOException e) {
+      LOG.error("Error while open metainf.xml", e);
+    } catch (ParserConfigurationException e) {
+      LOG.error("Error while parsing metainf.xml", e);
     }
 
-    private void setMetaInfo(File metainfoFile, ServiceInfo serviceInfo) {
+    if (doc == null) return;
 
-        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+    doc.getDocumentElement().normalize();
 
-        Document doc = null;
-        DocumentBuilder dBuilder = null;
-        try {
-            dBuilder = dbFactory.newDocumentBuilder();
-            doc = dBuilder.parse(metainfoFile);
-        } catch (SAXException e) {
-            LOG.error("Error while parsing metainf.xml", e);
-        } catch (IOException e) {
-            LOG.error("Error while open metainf.xml", e);
-        } catch (ParserConfigurationException e) {
-            LOG.error("Error while parsing metainf.xml", e);
-        }
+    NodeList metaInfoNodes = doc
+        .getElementsByTagName(METAINFO_XML_MAIN_BLOCK_NAME);
 
-        if(doc==null) return;
+    if (metaInfoNodes.getLength() > 0) {
+      Node metaInfoNode = metaInfoNodes.item(0);
+      if (metaInfoNode.getNodeType() == Node.ELEMENT_NODE) {
 
-        doc.getDocumentElement().normalize();
+        Element metaInfoElem = (Element) metaInfoNode;
 
-        NodeList metaInfoNodes = doc
-                .getElementsByTagName(METAINFO_XML_MAIN_BLOCK_NAME);
+        serviceInfo.setVersion(getTagValue(METAINFO_XML_PROPERTY_VERSION,
+            metaInfoElem));
+        serviceInfo.setUser(getTagValue(METAINFO_XML_PROPERTY_USER,
+            metaInfoElem));
+        serviceInfo.setComment(getTagValue(METAINFO_XML_PROPERTY_COMMENT,
+            metaInfoElem));
+      }
+    }
 
-        if (metaInfoNodes.getLength() > 0) {
-            Node metaInfoNode = metaInfoNodes.item(0);
-            if (metaInfoNode.getNodeType() == Node.ELEMENT_NODE) {
-
-                Element metaInfoElem = (Element) metaInfoNode;
-
-                serviceInfo.setVersion(getTagValue(METAINFO_XML_PROPERTY_VERSION,
-                        metaInfoElem));
-                serviceInfo.setUser(getTagValue(METAINFO_XML_PROPERTY_USER,
-                        metaInfoElem));
-                serviceInfo.setComment(getTagValue(METAINFO_XML_PROPERTY_COMMENT,
-                        metaInfoElem));
-            }
-        }
+    NodeList componentInfoNodes = doc
+        .getElementsByTagName(METAINFO_XML_PROPERTY_COMPONENT_MAIN);
 
-        NodeList componentInfoNodes = doc
-                .getElementsByTagName(METAINFO_XML_PROPERTY_COMPONENT_MAIN);
+    if (componentInfoNodes.getLength() > 0) {
+      for (int index = 0; index < componentInfoNodes.getLength(); index++) {
+        Node componentInfoNode = componentInfoNodes.item(index);
+        if (componentInfoNode.getNodeType() == Node.ELEMENT_NODE) {
+          Element componentInfoElem = (Element) componentInfoNode;
 
-        if (componentInfoNodes.getLength() > 0) {
-            for (int index = 0; index < componentInfoNodes.getLength(); index++) {
-                Node componentInfoNode = componentInfoNodes.item(index);
-                if (componentInfoNode.getNodeType() == Node.ELEMENT_NODE) {
-                    Element componentInfoElem = (Element) componentInfoNode;
-
-                    ComponentInfo componentInfo = new ComponentInfo();
-                    componentInfo.setName(getTagValue(
-                            METAINFO_XML_PROPERTY_COMPONENT_NAME, componentInfoElem));
-                    componentInfo.setCategory(getTagValue(
-                            METAINFO_XML_PROPERTY_COMPONENT_CATEGORY, componentInfoElem));
-                    serviceInfo.getComponents().add(componentInfo);
+          ComponentInfo componentInfo = new ComponentInfo();
+          componentInfo.setName(getTagValue(
+              METAINFO_XML_PROPERTY_COMPONENT_NAME, componentInfoElem));
+          componentInfo.setCategory(getTagValue(
+              METAINFO_XML_PROPERTY_COMPONENT_CATEGORY, componentInfoElem));
+          serviceInfo.getComponents().add(componentInfo);
 
-                }
-            }
         }
-
+      }
     }
+  }
 
-    private List<PropertyInfo> getProperties(File propertyFile) {
+  private List<PropertyInfo> getProperties(File propertyFile) {
 
-        List<PropertyInfo> resultPropertyList = new ArrayList<PropertyInfo>();
-        try {
-            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
-            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
-            Document doc = dBuilder.parse(propertyFile);
-            doc.getDocumentElement().normalize();
-
-            NodeList propertyNodes = doc
-                    .getElementsByTagName(PROPERTY_XML_MAIN_BLOCK_NAME);
-
-            for (int index = 0; index < propertyNodes.getLength(); index++) {
-
-                Node node = propertyNodes.item(index);
-                if (node.getNodeType() == Node.ELEMENT_NODE) {
-                    Element property = (Element) node;
-                    PropertyInfo propertyInfo = new PropertyInfo();
-                    propertyInfo
-                            .setName(getTagValue(PROPERTY_XML_PROPERTY_NAME, property));
-                    propertyInfo.setValue(getTagValue(PROPERTY_XML_PROPERTY_VALUE,
-                            property));
-
-                    propertyInfo.setDescription(getTagValue(
-                            PROPERTY_XML_PROPERTY_DESCRIPTION, property));
-                    propertyInfo.setFilename(propertyFile.getName());
+    List<PropertyInfo> resultPropertyList = new ArrayList<PropertyInfo>();
+    try {
+      DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+      DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+      Document doc = dBuilder.parse(propertyFile);
+      doc.getDocumentElement().normalize();
 
-                    if (propertyInfo.getName() == null || propertyInfo.getValue() == null)
-                        continue;
+      NodeList propertyNodes = doc
+          .getElementsByTagName(PROPERTY_XML_MAIN_BLOCK_NAME);
 
-                    resultPropertyList.add(propertyInfo);
-                }
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-            return null;
-        }
-        return resultPropertyList;
-    }
+      for (int index = 0; index < propertyNodes.getLength(); index++) {
 
-    private String getTagValue(String sTag, Element rawElement) {
-        String result = null;
+        Node node = propertyNodes.item(index);
+        if (node.getNodeType() == Node.ELEMENT_NODE) {
+          Element property = (Element) node;
+          PropertyInfo propertyInfo = new PropertyInfo();
+          propertyInfo
+              .setName(getTagValue(PROPERTY_XML_PROPERTY_NAME, property));
+          propertyInfo.setValue(getTagValue(PROPERTY_XML_PROPERTY_VALUE,
+              property));
 
-        if (rawElement.getElementsByTagName(sTag) != null && rawElement.getElementsByTagName(sTag).getLength() > 0) {
-            if (rawElement.getElementsByTagName(sTag).item(0) != null) {
-                NodeList element = rawElement.getElementsByTagName(sTag).item(0).getChildNodes();
+          propertyInfo.setDescription(getTagValue(
+              PROPERTY_XML_PROPERTY_DESCRIPTION, property));
+          propertyInfo.setFilename(propertyFile.getName());
 
-                if (element != null && element.item(0)!=null) {
-                    Node value = (Node) element.item(0);
+          if (propertyInfo.getName() == null || propertyInfo.getValue() == null)
+            continue;
 
-                    result = value.getNodeValue();
-                }
-            }
+          resultPropertyList.add(propertyInfo);
         }
-
-        return result;
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      return null;
     }
+    return resultPropertyList;
+  }
 
-    public boolean areOsTypesCompatible(String type1, String type2) {
-        if (type1 == null || type2 == null) {
-            return false;
-        }
-        if (type1.equals(type2)) {
-            return true;
-        }
-        if (type1.equals("redhat5") || type1.equals("centos5") ||
-            type1.equals("oraclelinux5")) {
-            if (type2.equals("centos5") || type2.equals("redhat5") ||
-                type2.equals("oraclelinux5")) {
-                return true;
-            }
-        } else if (type1.equals("redhat6") || type1.equals("centos6") ||
-            type1.equals("oraclelinux6")) {
-            if (type2.equals("centos6") || type2.equals("redhat6") ||
-                type2.equals("oraclelinux6")) {
-                return true;
-            }
+  private String getTagValue(String sTag, Element rawElement) {
+    String result = null;
+
+    if (rawElement.getElementsByTagName(sTag) != null && rawElement.getElementsByTagName(sTag).getLength() > 0) {
+      if (rawElement.getElementsByTagName(sTag).item(0) != null) {
+        NodeList element = rawElement.getElementsByTagName(sTag).item(0).getChildNodes();
+
+        if (element != null && element.item(0) != null) {
+          Node value = (Node) element.item(0);
+
+          result = value.getNodeValue();
         }
-        return false;
+      }
     }
 
+    return result;
+  }
 
-
+  public boolean areOsTypesCompatible(String type1, String type2) {
+    if (type1 == null || type2 == null) {
+      return false;
+    }
+    if (type1.equals(type2)) {
+      return true;
+    }
+    if (type1.equals("redhat5") || type1.equals("centos5") ||
+        type1.equals("oraclelinux5")) {
+      if (type2.equals("centos5") || type2.equals("redhat5") ||
+          type2.equals("oraclelinux5")) {
+        return true;
+      }
+    } else if (type1.equals("redhat6") || type1.equals("centos6") ||
+        type1.equals("oraclelinux6")) {
+      if (type2.equals("centos6") || type2.equals("redhat6") ||
+          type2.equals("oraclelinux6")) {
+        return true;
+      }
+    }
+    return false;
+  }
 }

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java?rev=1463227&r1=1463226&r2=1463227&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java Mon Apr  1 18:00:39 2013
@@ -3415,7 +3415,7 @@ public class AmbariManagementControllerI
       }
 
       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 AmbariManagementControllerI
       }
 
       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 AmbariManagementControllerI
             + ", 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()) {

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java?rev=1463227&r1=1463226&r2=1463227&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java Mon Apr  1 18:00:39 2013
@@ -71,8 +71,6 @@ public class ServiceComponentImpl implem
 
   private final boolean isClientComponent;
 
-
-
   private void init() {
     // TODO load during restart
     // initialize from DB
@@ -117,7 +115,6 @@ public class ServiceComponentImpl implem
     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 implem
       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 implem
     }
     sch.delete();
     hostComponents.remove(hostname);
+
+    // FIXME need a better approach of caching components by host
+    ClusterImpl clusterImpl = (ClusterImpl) service.getCluster();
+    clusterImpl.removeServiceComponentHost(sch);
   }
 
   @Override

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=1463227&r1=1463226&r2=1463227&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 Mon Apr  1 18:00:39 2013
@@ -295,19 +295,19 @@ public class ClusterImpl implements Clus
       }
       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 Clus
     }
   }
 
+  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();

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java?rev=1463227&r1=1463226&r2=1463227&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java Mon Apr  1 18:00:39 2013
@@ -1532,7 +1532,6 @@ public class AmbariManagementControllerI
     );
     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 AmbariManagementControllerI
 
     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 AmbariManagementControllerI
     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 AmbariManagementControllerI
     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();