You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2017/10/19 12:35:36 UTC

[1/4] ambari git commit: Blueprint V2 data model (benyoka)

Repository: ambari
Updated Branches:
  refs/heads/branch-feature-AMBARI-14714 17e4330db -> 841cc7e12


http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java
new file mode 100644
index 0000000..351351b
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java
@@ -0,0 +1,124 @@
+package org.apache.ambari.server.topology;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import javax.annotation.Nullable;
+
+import org.apache.ambari.server.controller.internal.ProvisionAction;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.google.common.base.Function;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+
+public class HostGroupV2Impl implements HostGroupV2, Configurable {
+
+  private String name;
+  private String blueprintName;
+  private List<ComponentV2> components;
+  private List<ServiceId> services;
+  private Configuration configuration;
+  private String cardinality;
+  private boolean containsMasterComponent;
+
+  public HostGroupV2Impl() { }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+
+  @Override
+  public String getBlueprintName() {
+    return blueprintName;
+  }
+
+  @Override
+  public String getFullyQualifiedName() {
+    return blueprintName + ":" + name;
+  }
+
+  @Override
+  public Collection<ComponentV2> getComponents() {
+    return components;
+  }
+
+  @Override
+  public Collection<String> getComponentNames() {
+    return getComponentNames(components);
+  }
+
+  private Collection<String> getComponentNames(List<ComponentV2> components) {
+    return Lists.transform(components,
+      new Function<ComponentV2, String>() {
+        @Override public String apply(@Nullable ComponentV2 input) { return input.getName(); }
+      });
+  }
+
+  @Override
+  public Collection<String> getComponentNames(ProvisionAction provisionAction) {
+    List<ComponentV2> filtered =
+      ImmutableList.copyOf(Collections2.filter(components, Predicates.equalTo(provisionAction)));
+    return getComponentNames(filtered);
+  }
+
+  @Override
+  public Collection<ComponentV2> getComponents(ServiceId serviceId) {
+    return components.stream().filter(c -> c.getServiceId().equals(serviceId)).collect(Collectors.toList());
+  }
+
+  @Override
+  public boolean containsMasterComponent() {
+    return containsMasterComponent;
+  }
+
+  @Override
+  @JsonIgnore
+  public Collection<ServiceId> getServices() {
+    return services;
+  }
+
+  @Override
+  @JsonIgnore
+  public Collection<String> getServiceNames() {
+    return services.stream().map(s -> s.getName()).collect(Collectors.toList());
+  }
+
+  @Override
+  public Configuration getConfiguration() {
+    return configuration;
+  }
+
+  @Override
+  public String getCardinality() {
+    return cardinality;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public void setBlueprintName(String blueprintName) {
+    this.blueprintName = blueprintName;
+  }
+
+  public void setComponents(List<ComponentV2> components) {
+    this.components = components;
+    this.containsMasterComponent = components.stream().anyMatch(c -> c.isMasterComponent());
+    this.services = components.stream().map(c -> c.getServiceId()).collect(Collectors.toList());
+  }
+
+  public void setConfiguration(Configuration configuration) {
+    this.configuration = configuration;
+  }
+
+  public void setCardinality(String cardinality) {
+    this.cardinality = cardinality;
+  }
+
+}
+

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/topology/RepositoryVersion.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/RepositoryVersion.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/RepositoryVersion.java
new file mode 100644
index 0000000..8eb6663
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/RepositoryVersion.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distribut
+ * ed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.topology;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class RepositoryVersion {
+  @JsonProperty("stack_id")
+  private String stackId;
+
+  @JsonProperty("repository_version")
+  private String repositoryVersion;
+
+  public RepositoryVersion() { }
+
+  public RepositoryVersion(String stackId, String repositoryVersion) {
+    this.stackId = stackId;
+    this.repositoryVersion = repositoryVersion;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    RepositoryVersion that = (RepositoryVersion) o;
+
+    if (stackId != null ? !stackId.equals(that.stackId) : that.stackId != null) return false;
+    return repositoryVersion != null ? repositoryVersion.equals(that.repositoryVersion) : that.repositoryVersion == null;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = stackId != null ? stackId.hashCode() : 0;
+    result = 31 * result + (repositoryVersion != null ? repositoryVersion.hashCode() : 0);
+    return result;
+  }
+
+  public String getStackId() {
+    return stackId;
+  }
+
+  public void setStackId(String stackId) {
+    this.stackId = stackId;
+  }
+
+  public String getRepositoryVersion() {
+    return repositoryVersion;
+  }
+
+  public void setRepositoryVersion(String repositoryVersion) {
+    this.repositoryVersion = repositoryVersion;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/topology/SecurityConfiguration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/SecurityConfiguration.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/SecurityConfiguration.java
index 4ff5504..7955169 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/SecurityConfiguration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/SecurityConfiguration.java
@@ -21,6 +21,9 @@ package org.apache.ambari.server.topology;
 
 import org.apache.ambari.server.state.SecurityType;
 
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
 /**
  * Holds security related properties, the securityType and security descriptor (in case of KERBEROS
  * kerberos_descriptor) either contains the whole descriptor or just the reference to it.
@@ -43,7 +46,9 @@ public class SecurityConfiguration {
    */
   private String descriptor;
 
-  public SecurityConfiguration(SecurityType type) {
+
+  @JsonCreator
+  public SecurityConfiguration(@JsonProperty("type") SecurityType type) {
     this.type = type;
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/topology/Service.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/Service.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/Service.java
index 1505107..1dde7ea 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/Service.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/Service.java
@@ -21,45 +21,19 @@ package org.apache.ambari.server.topology;
 
 import java.util.Set;
 
-import org.apache.ambari.server.controller.internal.StackV2;
+import com.fasterxml.jackson.annotation.JsonProperty;
 
-public class Service {
+public class Service implements Configurable {
 
-  private final String type;
+  private String type;
 
-  private final String name;
+  private ServiceId id = new ServiceId();
 
-  private final StackV2 stack;
+  private String stackId;
 
-  private final Configuration configuration;
+  private Configuration configuration;
 
-  private final ServiceGroup serviceGroup;
-
-  private final Set<Service> dependentServices;
-
-  public Service(String type, StackV2 stack, ServiceGroup serviceGroup) {
-    this(type, type, stack, serviceGroup,  null, null);
-  }
-
-  /**
-   * In case there's no name specified name will be set to type.
-   * @param type
-   * @param name
-   * @param stack
-   * @param configuration
-   */
-  public Service(String type, String name, StackV2 stack, ServiceGroup serviceGroup, Configuration configuration, Set<Service> dependentServices) {
-    this.type = type;
-    if (name == null) {
-      this.name = type;
-    } else {
-      this.name = name;
-    }
-    this.stack = stack;
-    this.serviceGroup = serviceGroup;
-    this.configuration = configuration;
-    this.dependentServices = dependentServices;
-  }
+  private Set<ServiceId> dependencies;
 
   /**
    * Gets the name of this service
@@ -67,26 +41,57 @@ public class Service {
    * @return component name
    */
   public String getName() {
-    return this.name;
+    return this.id.getName();
+  }
+
+  public String getServiceGroup() {
+    return this.id.getServiceGroup();
   }
 
   public String getType() {
     return type;
   }
 
-  public StackV2 getStack() {
-    return stack;
+  public String getStackId() {
+    return stackId;
+  }
+
+  public Set<ServiceId> getDependencies() {
+    return dependencies;
   }
 
   public Configuration getConfiguration() {
     return configuration;
   }
 
-  public ServiceGroup getServiceGroup() {
-    return serviceGroup;
+
+  public void setType(String type) {
+    this.type = type;
+  }
+
+  public void setName(String name) {
+    this.id.setName(name);
   }
 
-  public Set<Service> getDependentServices() {
-    return dependentServices;
+  public void setServiceGroup(String serviceGroup) {
+    this.id.setServiceGroup(serviceGroup);
   }
+
+  @JsonProperty("stack_id")
+  public void setStackId(String stackId) {
+    this.stackId = stackId;
+  }
+
+  public void setConfiguration(Configuration configuration) {
+    this.configuration = configuration;
+  }
+
+  public void setDependencies(Set<ServiceId> dependencies) {
+    this.dependencies = dependencies;
+  }
+
+  public ServiceId getId() {
+    return id;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceGroup.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceGroup.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceGroup.java
index 4b59293..13967c0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceGroup.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceGroup.java
@@ -19,29 +19,22 @@
 package org.apache.ambari.server.topology;
 
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.Set;
 
 public class ServiceGroup {
 
-  private final String name;
+  private String name = null;
 
-  private final Collection<Service> services;
+  private Collection<Service> services = new ArrayList<>();
 
-  private final Configuration configuration;
+  private Configuration configuration = null;
 
-  private final Set<ServiceGroup> dependencies;
+  private Set<String> dependencies = new HashSet<>();
 
-  public ServiceGroup(String name, Collection<Service> services) {
-    this(name, services, null, null);
-  }
-
-  public ServiceGroup(String name, Collection<Service> services, Configuration configuration, Set<ServiceGroup> dependencies) {
-    this.name = name;
-    this.services = services;
-    this.configuration = configuration;
-    this.dependencies = dependencies;
-  }
+  public ServiceGroup() { }
 
   /**
    * Gets the name of this service group
@@ -52,7 +45,6 @@ public class ServiceGroup {
     return this.name;
   }
 
-
   public Collection<Service> getServices() {
     return services;
   }
@@ -61,8 +53,26 @@ public class ServiceGroup {
     return configuration;
   }
 
-  public Set<ServiceGroup> getDependencies() {
+  public Set<String> getDependencies() {
     return dependencies;
   }
 
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public void setServices(Collection<Service> services) {
+    this.services = services;
+    services.forEach(s -> s.setServiceGroup(this.name));
+  }
+
+  public void setConfiguration(Configuration configuration) {
+    this.configuration = configuration;
+  }
+
+  public void setDependencies(Set<String> dependencies) {
+    this.dependencies = dependencies;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceId.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceId.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceId.java
new file mode 100644
index 0000000..2aae1d3
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceId.java
@@ -0,0 +1,52 @@
+package org.apache.ambari.server.topology;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class ServiceId {
+  private String serviceGroup;
+  private String name;
+
+  public static ServiceId of(String name, String serviceGroup) {
+    ServiceId id = new ServiceId();
+    id.name = name;
+    id.serviceGroup = serviceGroup;
+    return id;
+  }
+
+  public String getServiceGroup() {
+    return serviceGroup;
+  }
+
+  @JsonProperty("service_group")
+  public void setServiceGroup(String serviceGroup) {
+    this.serviceGroup = serviceGroup;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  @JsonProperty("service_name")
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ServiceId serviceId = (ServiceId) o;
+
+    if (serviceGroup != null ? !serviceGroup.equals(serviceId.serviceGroup) : serviceId.serviceGroup != null)
+      return false;
+    return name != null ? name.equals(serviceId.name) : serviceId.name == null;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = serviceGroup != null ? serviceGroup.hashCode() : 0;
+    result = 31 * result + (name != null ? name.hashCode() : 0);
+    return result;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/BlueprintImplV2Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/BlueprintImplV2Test.java b/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/BlueprintImplV2Test.java
new file mode 100644
index 0000000..dbe269a
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/BlueprintImplV2Test.java
@@ -0,0 +1,9 @@
+package org.apache.ambari.server.topology.validators;
+
+public class BlueprintImplV2Test {
+
+  private static final String BLUEPRINT_LOCATION = "";
+
+
+
+}


[4/4] ambari git commit: AMBARI-22253. Modify TopologyManager to create service groups (magyari_sandor)

Posted by ma...@apache.org.
AMBARI-22253. Modify TopologyManager to create service groups (magyari_sandor)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/841cc7e1
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/841cc7e1
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/841cc7e1

Branch: refs/heads/branch-feature-AMBARI-14714
Commit: 841cc7e12c9f6e689b7b97b7b75b92ed7744fa87
Parents: 37b1e6e
Author: Sandor Magyari <sm...@hortonworks.com>
Authored: Thu Oct 19 14:20:39 2017 +0200
Committer: Sandor Magyari <sm...@hortonworks.com>
Committed: Thu Oct 19 14:30:31 2017 +0200

----------------------------------------------------------------------
 .../StackAdvisorBlueprintProcessor.java         |   2 +-
 .../ambari/server/controller/AmbariServer.java  |   3 +-
 .../ambari/server/controller/StackV2.java       |  47 +-
 .../server/controller/StackV2Factory.java       |  10 +-
 .../controller/internal/BaseClusterRequest.java |   8 +-
 .../BlueprintConfigurationProcessor.java        |   4 +-
 .../internal/ConfigurationContext.java          |   1 +
 .../internal/ProvisionClusterRequest.java       |   7 +-
 .../internal/ScaleClusterRequest.java           |   6 +
 .../server/controller/internal/StackV2.java     | 834 -------------------
 .../server/controller/internal/UnitUpdater.java |   1 +
 .../ambari/server/topology/AmbariContext.java   |   5 +-
 .../server/topology/BlueprintFactory.java       |   4 +-
 .../ambari/server/topology/BlueprintImplV2.java |  49 +-
 .../ambari/server/topology/BlueprintV2.java     |  10 +-
 .../topology/ClusterConfigurationRequest.java   |   5 +-
 .../ambari/server/topology/ComponentV2.java     |  12 +-
 .../ambari/server/topology/HostGroupV2.java     |  11 +-
 .../ambari/server/topology/HostGroupV2Impl.java |  21 +-
 .../ambari/server/topology/HostRequest.java     |   2 +-
 .../server/topology/PersistedStateImpl.java     |   9 +-
 .../apache/ambari/server/topology/Service.java  |  21 +-
 .../ambari/server/topology/TopologyManager.java |   2 +-
 .../validators/ClusterConfigTypeValidator.java  |   5 +-
 .../RequiredConfigPropertiesValidator.java      |   2 +-
 .../validators/RequiredPasswordValidator.java   |   2 +-
 .../topology/validators/UnitValidator.java      |  12 +-
 27 files changed, 178 insertions(+), 917 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorBlueprintProcessor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorBlueprintProcessor.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorBlueprintProcessor.java
index ba35cce..2e9ac9f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorBlueprintProcessor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorBlueprintProcessor.java
@@ -28,8 +28,8 @@ import java.util.Set;
 import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorRequest.StackAdvisorRequestType;
 import org.apache.ambari.server.api.services.stackadvisor.recommendations.RecommendationResponse;
 import org.apache.ambari.server.api.services.stackadvisor.recommendations.RecommendationResponse.BlueprintConfigurations;
+import org.apache.ambari.server.controller.StackV2;
 import org.apache.ambari.server.controller.internal.ConfigurationTopologyException;
-import org.apache.ambari.server.controller.internal.StackV2;
 import org.apache.ambari.server.state.ValueAttributesInfo;
 import org.apache.ambari.server.topology.AdvisedConfiguration;
 import org.apache.ambari.server.topology.BlueprintV2;

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
index 6d4d1c9..f900452 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
@@ -115,6 +115,7 @@ import org.apache.ambari.server.stack.UpdateActiveRepoVersionOnStartup;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.topology.AmbariContext;
 import org.apache.ambari.server.topology.BlueprintFactory;
+import org.apache.ambari.server.topology.BlueprintV2Factory;
 import org.apache.ambari.server.topology.SecurityConfigurationFactory;
 import org.apache.ambari.server.topology.TopologyManager;
 import org.apache.ambari.server.topology.TopologyRequestFactoryImpl;
@@ -926,7 +927,7 @@ public class AmbariServer {
             .class), injector.getInstance(Gson.class));
     HostResourceProvider.setTopologyManager(injector.getInstance(TopologyManager.class));
     BlueprintFactory.init(injector.getInstance(BlueprintDAO.class));
-    BaseClusterRequest.init(injector.getInstance(BlueprintFactory.class));
+    BaseClusterRequest.init(injector.getInstance(BlueprintV2Factory.class));
     AmbariContext.init(injector.getInstance(HostRoleCommandFactory.class));
 
     PermissionResourceProvider.init(injector.getInstance(PermissionDAO.class));

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java
index 8d7de5d..169bf6a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java
@@ -26,6 +26,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.ambari.server.state.AutoDeployInfo;
+import org.apache.ambari.server.state.ComponentInfo;
 import org.apache.ambari.server.state.DependencyInfo;
 import org.apache.ambari.server.state.PropertyDependencyInfo;
 import org.apache.ambari.server.state.PropertyInfo;
@@ -165,28 +166,28 @@ public class StackV2 {
         return serviceComponents;
     }
 
-//  /**
-//   * Get info for the specified component.
-//   *
-//   * @param component  component name
-//   *
-//   * @return component information for the requested component
-//   *         or null if the component doesn't exist in the stack
-//   */
-//  @Deprecated
-//  public ComponentInfo getComponentInfo(String component) {
-//    ComponentInfo componentInfo = null;
-//    String service = getServiceForComponent(component);
-//    if (service != null) {
-//      try {
-//        componentInfo = controller.getAmbariMetaInfo().getComponent(
-//            getName(), getVersion(), service, component);
-//      } catch (AmbariException e) {
-//        // just return null if component doesn't exist
-//      }
-//    }
-//    return componentInfo;
-//  }
+      /**
+       * Get info for the specified component.
+       *
+       * @param component  component name
+       *
+       * @return component information for the requested component
+       *         or null if the component doesn't exist in the stack
+       */
+      @Deprecated
+      public ComponentInfo getComponentInfo(String component) {
+        ComponentInfo componentInfo = null;
+//        String service = getServiceForComponent(component);
+//        if (service != null) {
+//          try {
+//            componentInfo = controller.getAmbariMetaInfo().getComponent(
+//                getName(), getVersion(), service, component);
+//          } catch (AmbariException e) {
+//            // just return null if component doesn't exist
+//          }
+//        }
+        return componentInfo;
+      }
 
     /**
      * Get all configuration types, including excluded types for the specified service.
@@ -586,7 +587,7 @@ public class StackV2 {
             this.attributes = attributes;
         }
 
-        Set<PropertyDependencyInfo> getDependsOnProperties() {
+        public Set<PropertyDependencyInfo> getDependsOnProperties() {
             return this.dependsOnProperties;
         }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java
index 54e1e62..ed1bbf8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java
@@ -85,14 +85,14 @@ public class StackV2Factory {
     stackData.serviceConfigurations.put(service, mapServiceConfig);
     stackData.requiredServiceConfigurations.put(service, mapRequiredServiceConfig);
 
-    Set<StackConfigurationResponse> serviceConfigs = controller.getStackConfigurations(
+    Set<ReadOnlyConfigurationResponse> serviceConfigs = controller.getStackConfigurations(
       Collections.singleton(new StackConfigurationRequest(stackData.stackName, stackData.stackVersion, service, null)));
-    Set<StackConfigurationResponse> stackLevelConfigs = controller.getStackLevelConfigurations(
+    Set<ReadOnlyConfigurationResponse> stackLevelConfigs = controller.getStackLevelConfigurations(
       Collections.singleton(new StackLevelConfigurationRequest(stackData.stackName, stackData.stackVersion, null)));
     serviceConfigs.addAll(stackLevelConfigs);
 
     // shouldn't have any required properties in stack level configuration
-    for (StackConfigurationResponse config : serviceConfigs) {
+    for (ReadOnlyConfigurationResponse config : serviceConfigs) {
       StackV2.ConfigProperty configProperty = new StackV2.ConfigProperty(config);
       String type = configProperty.getType();
 
@@ -118,10 +118,10 @@ public class StackV2Factory {
   }
 
   private void parseStackConfigurations (StackData stackData) throws AmbariException {
-    Set<StackConfigurationResponse> stackLevelConfigs = controller.getStackLevelConfigurations(
+    Set<ReadOnlyConfigurationResponse> stackLevelConfigs = controller.getStackLevelConfigurations(
       Collections.singleton(new StackLevelConfigurationRequest(stackData.stackName, stackData.stackVersion, null)));
 
-    for (StackConfigurationResponse config : stackLevelConfigs) {
+    for (ReadOnlyConfigurationResponse config : stackLevelConfigs) {
       StackV2.ConfigProperty configProperty = new StackV2.ConfigProperty(config);
       String type = configProperty.getType();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseClusterRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseClusterRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseClusterRequest.java
index e3e0aa2..a38f478 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseClusterRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseClusterRequest.java
@@ -30,8 +30,8 @@ import org.apache.ambari.server.api.predicate.Token;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.spi.ResourceProvider;
 import org.apache.ambari.server.controller.utilities.ClusterControllerHelper;
-import org.apache.ambari.server.topology.BlueprintFactory;
 import org.apache.ambari.server.topology.BlueprintV2;
+import org.apache.ambari.server.topology.BlueprintV2Factory;
 import org.apache.ambari.server.topology.Configuration;
 import org.apache.ambari.server.topology.HostGroupInfo;
 import org.apache.ambari.server.topology.InvalidTopologyTemplateException;
@@ -74,7 +74,7 @@ public abstract class BaseClusterRequest implements TopologyRequest {
   /**
    * blueprint factory
    */
-  protected static BlueprintFactory blueprintFactory;
+  protected static BlueprintV2Factory blueprintFactory;
 
   /**
    * List of services
@@ -96,7 +96,7 @@ public abstract class BaseClusterRequest implements TopologyRequest {
    * inject blueprint factory
    * @param factory  blueprint factory
    */
-  public static void init(BlueprintFactory factory) {
+  public static void init(BlueprintV2Factory factory) {
     blueprintFactory = factory;
   }
 
@@ -179,7 +179,7 @@ public abstract class BaseClusterRequest implements TopologyRequest {
   /**
    * Get the blueprint factory.
    */
-  protected BlueprintFactory getBlueprintFactory() {
+  protected BlueprintV2Factory getBlueprintFactory() {
     return blueprintFactory;
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java
index 8c4a5eb..953155d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java
@@ -38,6 +38,7 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.controller.StackV2;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.ConfigHelper;
 import org.apache.ambari.server.state.PropertyDependencyInfo;
@@ -2923,7 +2924,8 @@ public class BlueprintConfigurationProcessor {
     for (Service blueprintService : blueprintServices) {
 
       LOG.debug("Handling excluded properties for blueprint service: {}", blueprintService);
-      StackV2 stack = blueprintService.getStack();
+      String stackId = blueprintService.getStackId();
+      StackV2 stack = clusterTopology.getBlueprint().getStackById(stackId);
       Set<String> excludedConfigTypes = stack.getExcludedConfigurationTypes(blueprintService.getType());
 
       if (excludedConfigTypes.isEmpty()) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigurationContext.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigurationContext.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigurationContext.java
index a313f5e..aa63021 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigurationContext.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigurationContext.java
@@ -20,6 +20,7 @@ package org.apache.ambari.server.controller.internal;
 
 import java.util.Map;
 
+import org.apache.ambari.server.controller.StackV2;
 import org.apache.ambari.server.topology.Configuration;
 
 /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java
index 75ec9ba..bfa46d8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java
@@ -17,6 +17,7 @@
  */
 package org.apache.ambari.server.controller.internal;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -295,7 +296,11 @@ public class ProvisionClusterRequest extends BaseClusterRequest {
   private void parseBlueprint(Map<String, Object> properties) throws NoSuchStackException, NoSuchBlueprintException {
     String blueprintName = String.valueOf(properties.get(ClusterResourceProvider.BLUEPRINT));
     // set blueprint field
-    setBlueprint(getBlueprintFactory().getBlueprint(blueprintName));
+    try {
+      setBlueprint(getBlueprintFactory().getBlueprint(blueprintName));
+    } catch (IOException e) {
+      throw new NoSuchBlueprintException(blueprintName);
+    }
 
     if (blueprint == null) {
       throw new NoSuchBlueprintException(blueprintName);

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
index c5cc061b..1284c26 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
@@ -19,6 +19,7 @@
 
 package org.apache.ambari.server.controller.internal;
 
+import java.io.IOException;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Set;
@@ -29,6 +30,7 @@ import org.apache.ambari.server.topology.BlueprintV2;
 import org.apache.ambari.server.topology.Configuration;
 import org.apache.ambari.server.topology.HostGroupInfo;
 import org.apache.ambari.server.topology.InvalidTopologyTemplateException;
+import org.apache.ambari.server.topology.NoSuchBlueprintException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -201,6 +203,10 @@ public class ScaleClusterRequest extends BaseClusterRequest {
     BlueprintV2 blueprint;
     try {
       blueprint = getBlueprintFactory().getBlueprint(blueprintName);
+    } catch (NoSuchBlueprintException e) {
+      throw new InvalidTopologyTemplateException("Invalid blueprint specified: " + blueprintName);
+    } catch (IOException e) {
+      throw new InvalidTopologyTemplateException("Error reading blueprint: " + blueprintName);
     } catch (NoSuchStackException e) {
       throw new InvalidTopologyTemplateException("Invalid stack specified in the blueprint: " + blueprintName);
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackV2.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackV2.java
deleted file mode 100644
index fb5d02c..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackV2.java
+++ /dev/null
@@ -1,834 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.controller.internal;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.controller.AmbariManagementController;
-import org.apache.ambari.server.controller.ReadOnlyConfigurationResponse;
-import org.apache.ambari.server.controller.StackConfigurationRequest;
-import org.apache.ambari.server.controller.StackLevelConfigurationRequest;
-import org.apache.ambari.server.controller.StackServiceComponentRequest;
-import org.apache.ambari.server.controller.StackServiceComponentResponse;
-import org.apache.ambari.server.controller.StackServiceRequest;
-import org.apache.ambari.server.controller.StackServiceResponse;
-import org.apache.ambari.server.orm.entities.StackEntity;
-import org.apache.ambari.server.state.AutoDeployInfo;
-import org.apache.ambari.server.state.ComponentInfo;
-import org.apache.ambari.server.state.DependencyInfo;
-import org.apache.ambari.server.state.PropertyDependencyInfo;
-import org.apache.ambari.server.state.PropertyInfo;
-import org.apache.ambari.server.state.ValueAttributesInfo;
-import org.apache.ambari.server.topology.Cardinality;
-import org.apache.ambari.server.topology.Configuration;
-
-/**
- * Encapsulates stack information.
- */
-public class StackV2 {
-  /**
-   * Stack name
-   */
-  private String name;
-
-  /**
-   * Stack version
-   */
-  private String version;
-
-  /**
-     * Repo version
-   */
-  private String repoVersion;
-
-  /**
-   * Map of service name to components
-   */
-  private Map<String, Collection<String>> serviceComponents =
-    new HashMap<>();
-
-  /**
-   * Map of component to service
-   */
-  private Map<String, String> componentService = new HashMap<>();
-
-  /**
-   * Map of component to dependencies
-   */
-  private Map<String, Collection<DependencyInfo>> dependencies =
-    new HashMap<>();
-
-  /**
-   * Map of dependency to conditional service
-   */
-  private Map<DependencyInfo, String> dependencyConditionalServiceMap =
-    new HashMap<>();
-
-  /**
-   * Map of database component name to configuration property which indicates whether
-   * the database in to be managed or if it is an external non-managed instance.
-   * If the value of the config property starts with 'New', the database is determined
-   * to be managed, otherwise it is non-managed.
-   */
-  private Map<String, String> dbDependencyInfo = new HashMap<>();
-
-  /**
-   * Map of component to required cardinality
-   */
-  private Map<String, String> cardinalityRequirements = new HashMap<>();
-
-  //todo: instead of all these maps from component -> * ,
-  //todo: we should use a Component object with all of these attributes
-  private Set<String> masterComponents = new HashSet<>();
-
-  /**
-   * Map of component to auto-deploy information
-   */
-  private Map<String, AutoDeployInfo> componentAutoDeployInfo =
-    new HashMap<>();
-
-  /**
-   * Map of service to config type properties
-   */
-  private Map<String, Map<String, Map<String, ConfigProperty>>> serviceConfigurations =
-    new HashMap<>();
-
-  /**
-   * Map of service to required type properties
-   */
-  private Map<String, Map<String, Map<String, ConfigProperty>>> requiredServiceConfigurations =
-    new HashMap<>();
-
-  /**
-   * Map of service to config type properties
-   */
-  private Map<String, Map<String, ConfigProperty>> stackConfigurations =
-    new HashMap<>();
-
-  /**
-   * Map of service to set of excluded config types
-   */
-  private Map<String, Set<String>> excludedConfigurationTypes =
-    new HashMap<>();
-
-  /**
-   * Ambari Management Controller, used to obtain Stack definitions
-   */
-  private final AmbariManagementController controller;
-
-
-  /**
-   * Constructor.
-   *
-   * @param stack
-   *          the stack (not {@code null}).
-   * @param ambariManagementController
-   *          the management controller (not {@code null}).
-   * @throws AmbariException
-   */
-  public StackV2(StackEntity stack, AmbariManagementController ambariManagementController) throws AmbariException {
-    this(stack.getStackName(), stack.getStackVersion(), ambariManagementController);
-  }
-
-  /**
-   * Constructor.
-   *
-   * @param name     stack name
-   * @param version  stack version
-   *
-   * @throws AmbariException an exception occurred getting stack information
-   *                         for the specified name and version
-   */
-  //todo: don't pass management controller in constructor
-  public StackV2(String name, String version, AmbariManagementController controller) throws AmbariException {
-    this.name = name;
-    this.version = version;
-    this.controller = controller;
-
-    Set<StackServiceResponse> stackServices = controller.getStackServices(
-        Collections.singleton(new StackServiceRequest(name, version, null)));
-
-    for (StackServiceResponse stackService : stackServices) {
-      String serviceName = stackService.getServiceName();
-      parseComponents(serviceName);
-      parseExcludedConfigurations(stackService);
-      parseConfigurations(stackService);
-      registerConditionalDependencies();
-    }
-
-    //todo: already done for each service
-    parseStackConfigurations();
-  }
-
-  /**
-   * Obtain stack name.
-   *
-   * @return stack name
-   */
-  public String getName() {
-    return name;
-  }
-
-  /**
-   * Obtain stack version.
-   *
-   * @return stack version
-   */
-  public String getVersion() {
-    return version;
-  }
-
-  /**
-   * Obtain repo version.
-   * @return
-   */
-  public String getRepoVersion() { return repoVersion; }
-
-  Map<DependencyInfo, String> getDependencyConditionalServiceMap() {
-    return dependencyConditionalServiceMap;
-  }
-
-  /**
-   * Get services contained in the stack.
-   *
-   * @return collection of all services for the stack
-   */
-  public Collection<String> getServices() {
-    return serviceComponents.keySet();
-  }
-
-  /**
-   * Get components contained in the stack for the specified service.
-   *
-   * @param service  service name
-   *
-   * @return collection of component names for the specified service
-   */
-  public Collection<String> getComponents(String service) {
-    return serviceComponents.get(service);
-  }
-
-  /**
-   * Get all service components
-   *
-   * @return map of service to associated components
-   */
-  public Map<String, Collection<String>> getComponents() {
-    Map<String, Collection<String>> serviceComponents = new HashMap<>();
-    for (String service : getServices()) {
-      Collection<String> components = new HashSet<>();
-      components.addAll(getComponents(service));
-      serviceComponents.put(service, components);
-    }
-    return serviceComponents;
-  }
-
-  /**
-   * Get info for the specified component.
-   *
-   * @param component  component name
-   *
-   * @return component information for the requested component
-   *         or null if the component doesn't exist in the stack
-   */
-  public ComponentInfo getComponentInfo(String component) {
-    ComponentInfo componentInfo = null;
-    String service = getServiceForComponent(component);
-    if (service != null) {
-      try {
-        componentInfo = controller.getAmbariMetaInfo().getComponent(
-            getName(), getVersion(), service, component);
-      } catch (AmbariException e) {
-        // just return null if component doesn't exist
-      }
-    }
-    return componentInfo;
-  }
-
-  /**
-   * Get all configuration types, including excluded types for the specified service.
-   *
-   * @param service  service name
-   *
-   * @return collection of all configuration types for the specified service
-   */
-  public Collection<String> getAllConfigurationTypes(String service) {
-    return serviceConfigurations.get(service).keySet();
-  }
-
-  /**
-   * Get configuration types for the specified service.
-   * This doesn't include any service excluded types.
-   *
-   * @param service  service name
-   *
-   * @return collection of all configuration types for the specified service
-   */
-  public Collection<String> getConfigurationTypes(String service) {
-    Set<String> serviceTypes = new HashSet<>(serviceConfigurations.get(service).keySet());
-    serviceTypes.removeAll(getExcludedConfigurationTypes(service));
-
-    return serviceTypes;
-  }
-
-  /**
-   * Get the set of excluded configuration types for this service.
-   *
-   * @param service service name
-   *
-   * @return Set of names of excluded config types. Will not return null.
-   */
-  public Set<String> getExcludedConfigurationTypes(String service) {
-    return excludedConfigurationTypes.containsKey(service) ?
-        excludedConfigurationTypes.get(service) :
-        Collections.emptySet();
-  }
-
-  /**
-   * Get config properties for the specified service and configuration type.
-   *
-   * @param service  service name
-   * @param type     configuration type
-   *
-   * @return map of property names to values for the specified service and configuration type
-   */
-  public Map<String, String> getConfigurationProperties(String service, String type) {
-    Map<String, String> configMap = new HashMap<>();
-    Map<String, ConfigProperty> configProperties = serviceConfigurations.get(service).get(type);
-    if (configProperties != null) {
-      for (Map.Entry<String, ConfigProperty> configProperty : configProperties.entrySet()) {
-        configMap.put(configProperty.getKey(), configProperty.getValue().getValue());
-      }
-    }
-    return configMap;
-  }
-
-  public Map<String, ConfigProperty> getConfigurationPropertiesWithMetadata(String service, String type) {
-    return serviceConfigurations.get(service).get(type);
-  }
-
-  /**
-   * Get all required config properties for the specified service.
-   *
-   * @param service  service name
-   *
-   * @return collection of all required properties for the given service
-   */
-  public Collection<ConfigProperty> getRequiredConfigurationProperties(String service) {
-    Collection<ConfigProperty> requiredConfigProperties = new HashSet<>();
-    Map<String, Map<String, ConfigProperty>> serviceProperties = requiredServiceConfigurations.get(service);
-    if (serviceProperties != null) {
-      for (Map.Entry<String, Map<String, ConfigProperty>> typePropertiesEntry : serviceProperties.entrySet()) {
-        requiredConfigProperties.addAll(typePropertiesEntry.getValue().values());
-      }
-    }
-    return requiredConfigProperties;
-  }
-
-  /**
-   * Get required config properties for the specified service which belong to the specified property type.
-   *
-   * @param service       service name
-   * @param propertyType  property type
-   *
-   * @return collection of required properties for the given service and property type
-   */
-  public Collection<ConfigProperty> getRequiredConfigurationProperties(String service, org.apache.ambari.server.state.PropertyInfo.PropertyType propertyType) {
-    Collection<ConfigProperty> matchingProperties = new HashSet<>();
-    Map<String, Map<String, ConfigProperty>> requiredProperties = requiredServiceConfigurations.get(service);
-    if (requiredProperties != null) {
-      for (Map.Entry<String, Map<String, ConfigProperty>> typePropertiesEntry : requiredProperties.entrySet()) {
-        for (ConfigProperty configProperty : typePropertiesEntry.getValue().values()) {
-          if (configProperty.getPropertyTypes().contains(propertyType)) {
-            matchingProperties.add(configProperty);
-          }
-        }
-
-      }
-    }
-    return matchingProperties;
-  }
-
-  public boolean isPasswordProperty(String service, String type, String propertyName) {
-    return (serviceConfigurations.containsKey(service) &&
-            serviceConfigurations.get(service).containsKey(type) &&
-            serviceConfigurations.get(service).get(type).containsKey(propertyName) &&
-            serviceConfigurations.get(service).get(type).get(propertyName).getPropertyTypes().
-                contains(org.apache.ambari.server.state.PropertyInfo.PropertyType.PASSWORD));
-  }
-
-  //todo
-  public Map<String, String> getStackConfigurationProperties(String type) {
-    Map<String, String> configMap = new HashMap<>();
-    Map<String, ConfigProperty> configProperties = stackConfigurations.get(type);
-    if (configProperties != null) {
-      for (Map.Entry<String, ConfigProperty> configProperty : configProperties.entrySet()) {
-        configMap.put(configProperty.getKey(), configProperty.getValue().getValue());
-      }
-    }
-    return configMap;
-  }
-
-  public boolean isKerberosPrincipalNameProperty(String service, String type, String propertyName) {
-    return (serviceConfigurations.containsKey(service) &&
-            serviceConfigurations.get(service).containsKey(type) &&
-            serviceConfigurations.get(service).get(type).containsKey(propertyName) &&
-            serviceConfigurations.get(service).get(type).get(propertyName).getPropertyTypes().
-                contains(org.apache.ambari.server.state.PropertyInfo.PropertyType.KERBEROS_PRINCIPAL));
-  }
-  /**
-   * Get config attributes for the specified service and configuration type.
-   *
-   * @param service  service name
-   * @param type     configuration type
-   *
-   * @return  map of attribute names to map of property names to attribute values
-   *          for the specified service and configuration type
-   */
-  public Map<String, Map<String, String>> getConfigurationAttributes(String service, String type) {
-    Map<String, Map<String, String>> attributesMap = new HashMap<>();
-    Map<String, ConfigProperty> configProperties = serviceConfigurations.get(service).get(type);
-    if (configProperties != null) {
-      for (Map.Entry<String, ConfigProperty> configProperty : configProperties.entrySet()) {
-        String propertyName = configProperty.getKey();
-        Map<String, String> propertyAttributes = configProperty.getValue().getAttributes();
-        if (propertyAttributes != null) {
-          for (Map.Entry<String, String> propertyAttribute : propertyAttributes.entrySet()) {
-            String attributeName = propertyAttribute.getKey();
-            String attributeValue = propertyAttribute.getValue();
-            if (attributeValue != null) {
-              Map<String, String> attributes = attributesMap.get(attributeName);
-              if (attributes == null) {
-                  attributes = new HashMap<>();
-                  attributesMap.put(attributeName, attributes);
-              }
-              attributes.put(propertyName, attributeValue);
-            }
-          }
-        }
-      }
-    }
-    return attributesMap;
-  }
-
-  //todo:
-  public Map<String, Map<String, String>> getStackConfigurationAttributes(String type) {
-    Map<String, Map<String, String>> attributesMap = new HashMap<>();
-    Map<String, ConfigProperty> configProperties = stackConfigurations.get(type);
-    if (configProperties != null) {
-      for (Map.Entry<String, ConfigProperty> configProperty : configProperties.entrySet()) {
-        String propertyName = configProperty.getKey();
-        Map<String, String> propertyAttributes = configProperty.getValue().getAttributes();
-        if (propertyAttributes != null) {
-          for (Map.Entry<String, String> propertyAttribute : propertyAttributes.entrySet()) {
-            String attributeName = propertyAttribute.getKey();
-            String attributeValue = propertyAttribute.getValue();
-            Map<String, String> attributes = attributesMap.get(attributeName);
-            if (attributes == null) {
-              attributes = new HashMap<>();
-              attributesMap.put(attributeName, attributes);
-            }
-            attributes.put(propertyName, attributeValue);
-          }
-        }
-      }
-    }
-    return attributesMap;
-  }
-
-  /**
-   * Get the service for the specified component.
-   *
-   * @param component  component name
-   *
-   * @return service name that contains tha specified component
-   */
-  public String getServiceForComponent(String component) {
-    return componentService.get(component);
-  }
-
-  /**
-   * Get the names of the services which contains the specified components.
-   *
-   * @param components collection of components
-   *
-   * @return collection of services which contain the specified components
-   */
-  public Collection<String> getServicesForComponents(Collection<String> components) {
-    Set<String> services = new HashSet<>();
-    for (String component : components) {
-      services.add(getServiceForComponent(component));
-    }
-
-    return services;
-  }
-
-  /**
-   * Obtain the service name which corresponds to the specified configuration.
-   *
-   * @param config  configuration type
-   *
-   * @return name of service which corresponds to the specified configuration type
-   */
-  public String getServiceForConfigType(String config) {
-    for (Map.Entry<String, Map<String, Map<String, ConfigProperty>>> entry : serviceConfigurations.entrySet()) {
-      Map<String, Map<String, ConfigProperty>> typeMap = entry.getValue();
-      String serviceName = entry.getKey();
-      if (typeMap.containsKey(config) && !getExcludedConfigurationTypes(serviceName).contains(config)) {
-        return serviceName;
-      }
-    }
-    throw new IllegalArgumentException(
-        "Specified configuration type is not associated with any service: " + config);
-  }
-
-  /**
-   * Return the dependencies specified for the given component.
-   *
-   * @param component  component to get dependency information for
-   *
-   * @return collection of dependency information for the specified component
-   */
-  //todo: full dependency graph
-  public Collection<DependencyInfo> getDependenciesForComponent(String component) {
-    return dependencies.containsKey(component) ? dependencies.get(component) :
-        Collections.emptySet();
-  }
-
-  /**
-   * Get the service, if any, that a component dependency is conditional on.
-   *
-   * @param dependency  dependency to get conditional service for
-   *
-   * @return conditional service for provided component or null if dependency
-   *         is not conditional on a service
-   */
-  public String getConditionalServiceForDependency(DependencyInfo dependency) {
-    return dependencyConditionalServiceMap.get(dependency);
-  }
-
-  public String getExternalComponentConfig(String component) {
-    return dbDependencyInfo.get(component);
-  }
-
-  /**
-   * Obtain the required cardinality for the specified component.
-   */
-  public Cardinality getCardinality(String component) {
-    return new Cardinality(cardinalityRequirements.get(component));
-  }
-
-  /**
-   * Obtain auto-deploy information for the specified component.
-   */
-  public AutoDeployInfo getAutoDeployInfo(String component) {
-    return componentAutoDeployInfo.get(component);
-  }
-
-  public boolean isMasterComponent(String component) {
-    return masterComponents.contains(component);
-  }
-
-  public Configuration getConfiguration(Collection<String> services) {
-    Map<String, Map<String, Map<String, String>>> attributes = new HashMap<>();
-    Map<String, Map<String, String>> properties = new HashMap<>();
-
-    for (String service : services) {
-      Collection<String> serviceConfigTypes = getConfigurationTypes(service);
-      for (String type : serviceConfigTypes) {
-        Map<String, String> typeProps = properties.get(type);
-        if (typeProps == null) {
-          typeProps = new HashMap<>();
-          properties.put(type, typeProps);
-        }
-        typeProps.putAll(getConfigurationProperties(service, type));
-
-        Map<String, Map<String, String>> stackTypeAttributes = getConfigurationAttributes(service, type);
-        if (!stackTypeAttributes.isEmpty()) {
-          if (! attributes.containsKey(type)) {
-            attributes.put(type, new HashMap<>());
-          }
-          Map<String, Map<String, String>> typeAttributes = attributes.get(type);
-          for (Map.Entry<String, Map<String, String>> attribute : stackTypeAttributes.entrySet()) {
-            String attributeName = attribute.getKey();
-            Map<String, String> attributeProps = typeAttributes.get(attributeName);
-            if (attributeProps == null) {
-              attributeProps = new HashMap<>();
-              typeAttributes.put(attributeName, attributeProps);
-            }
-            attributeProps.putAll(attribute.getValue());
-          }
-        }
-      }
-    }
-    return new Configuration(properties, attributes);
-  }
-
-  public Configuration getConfiguration() {
-    Map<String, Map<String, Map<String, String>>> stackAttributes = new HashMap<>();
-    Map<String, Map<String, String>> stackConfigs = new HashMap<>();
-
-    for (String service : getServices()) {
-      for (String type : getAllConfigurationTypes(service)) {
-        Map<String, String> typeProps = stackConfigs.get(type);
-        if (typeProps == null) {
-          typeProps = new HashMap<>();
-          stackConfigs.put(type, typeProps);
-        }
-        typeProps.putAll(getConfigurationProperties(service, type));
-
-        Map<String, Map<String, String>> stackTypeAttributes = getConfigurationAttributes(service, type);
-        if (!stackTypeAttributes.isEmpty()) {
-          if (! stackAttributes.containsKey(type)) {
-            stackAttributes.put(type, new HashMap<>());
-          }
-          Map<String, Map<String, String>> typeAttrs = stackAttributes.get(type);
-          for (Map.Entry<String, Map<String, String>> attribute : stackTypeAttributes.entrySet()) {
-            String attributeName = attribute.getKey();
-            Map<String, String> attributes = typeAttrs.get(attributeName);
-            if (attributes == null) {
-              attributes = new HashMap<>();
-              typeAttrs.put(attributeName, attributes);
-            }
-            attributes.putAll(attribute.getValue());
-          }
-        }
-      }
-    }
-    return new Configuration(stackConfigs, stackAttributes);
-  }
-
-  /**
-   * Parse components for the specified service from the stack definition.
-   *
-   * @param service  service name
-   *
-   * @throws AmbariException an exception occurred getting components from the stack definition
-   */
-  private void parseComponents(String service) throws AmbariException{
-    Collection<String> componentSet = new HashSet<>();
-
-    Set<StackServiceComponentResponse> components = controller.getStackComponents(
-        Collections.singleton(new StackServiceComponentRequest(name, version, service, null)));
-
-    // stack service components
-    for (StackServiceComponentResponse component : components) {
-      String componentName = component.getComponentName();
-      componentSet.add(componentName);
-      componentService.put(componentName, service);
-      String cardinality = component.getCardinality();
-      if (cardinality != null) {
-        cardinalityRequirements.put(componentName, cardinality);
-      }
-      AutoDeployInfo autoDeploy = component.getAutoDeploy();
-      if (autoDeploy != null) {
-        componentAutoDeployInfo.put(componentName, autoDeploy);
-      }
-
-      // populate component dependencies
-      //todo: remove usage of AmbariMetaInfo
-      Collection<DependencyInfo> componentDependencies = controller.getAmbariMetaInfo().getComponentDependencies(
-          name, version, service, componentName);
-
-      if (componentDependencies != null && ! componentDependencies.isEmpty()) {
-        dependencies.put(componentName, componentDependencies);
-      }
-      if (component.isMaster()) {
-        masterComponents.add(componentName);
-      }
-    }
-    serviceComponents.put(service, componentSet);
-  }
-
-  /**
-   * Parse configurations for the specified service from the stack definition.
-   *
-   * @param stackService  service to parse the stack configuration for
-   *
-   * @throws AmbariException an exception occurred getting configurations from the stack definition
-   */
-  private void parseConfigurations(StackServiceResponse stackService) throws AmbariException {
-    String service = stackService.getServiceName();
-    Map<String, Map<String, ConfigProperty>> mapServiceConfig = new HashMap<>();
-    Map<String, Map<String, ConfigProperty>> mapRequiredServiceConfig = new HashMap<>();
-
-
-    serviceConfigurations.put(service, mapServiceConfig);
-    requiredServiceConfigurations.put(service, mapRequiredServiceConfig);
-
-    Set<ReadOnlyConfigurationResponse> serviceConfigs = controller.getStackConfigurations(
-        Collections.singleton(new StackConfigurationRequest(name, version, service, null)));
-    Set<ReadOnlyConfigurationResponse> stackLevelConfigs = controller.getStackLevelConfigurations(
-        Collections.singleton(new StackLevelConfigurationRequest(name, version, null)));
-    serviceConfigs.addAll(stackLevelConfigs);
-
-    // shouldn't have any required properties in stack level configuration
-    for (ReadOnlyConfigurationResponse config : serviceConfigs) {
-      ConfigProperty configProperty = new ConfigProperty(config);
-      String type = configProperty.getType();
-
-      Map<String, ConfigProperty> mapTypeConfig = mapServiceConfig.get(type);
-      if (mapTypeConfig == null) {
-        mapTypeConfig = new HashMap<>();
-        mapServiceConfig.put(type, mapTypeConfig);
-      }
-
-      mapTypeConfig.put(config.getPropertyName(), configProperty);
-      if (config.isRequired()) {
-        Map<String, ConfigProperty> requiredTypeConfig = mapRequiredServiceConfig.get(type);
-        if (requiredTypeConfig == null) {
-          requiredTypeConfig = new HashMap<>();
-          mapRequiredServiceConfig.put(type, requiredTypeConfig);
-        }
-        requiredTypeConfig.put(config.getPropertyName(), configProperty);
-      }
-    }
-
-    // So far we added only config types that have properties defined
-    // in stack service definition. Since there might be config types
-    // with no properties defined we need to add those separately
-    Set<String> configTypes = stackService.getConfigTypes().keySet();
-    for (String configType: configTypes) {
-      if (!mapServiceConfig.containsKey(configType)) {
-        mapServiceConfig.put(configType, Collections.emptyMap());
-      }
-    }
-  }
-
-  private void parseStackConfigurations () throws AmbariException {
-
-    Set<ReadOnlyConfigurationResponse> stackLevelConfigs = controller.getStackLevelConfigurations(
-        Collections.singleton(new StackLevelConfigurationRequest(name, version, null)));
-
-    for (ReadOnlyConfigurationResponse config : stackLevelConfigs) {
-      ConfigProperty configProperty = new ConfigProperty(config);
-      String type = configProperty.getType();
-
-      Map<String, ConfigProperty> mapTypeConfig = stackConfigurations.get(type);
-      if (mapTypeConfig == null) {
-        mapTypeConfig = new HashMap<>();
-        stackConfigurations.put(type, mapTypeConfig);
-      }
-
-      mapTypeConfig.put(config.getPropertyName(),
-          configProperty);
-    }
-  }
-
-  /**
-   * Obtain the excluded configuration types from the StackServiceResponse
-   *
-   * @param stackServiceResponse the response object associated with this stack service
-   */
-  private void parseExcludedConfigurations(StackServiceResponse stackServiceResponse) {
-    excludedConfigurationTypes.put(stackServiceResponse.getServiceName(), stackServiceResponse.getExcludedConfigTypes());
-  }
-
-  /**
-   * Register conditional dependencies.
-   */
-  //todo: This information should be specified in the stack definition.
-  void registerConditionalDependencies() {
-    dbDependencyInfo.put("MYSQL_SERVER", "global/hive_database");
-  }
-
-  /**
-   * Contains a configuration property's value and attributes.
-   */
-  public static class ConfigProperty {
-    private ValueAttributesInfo propertyValueAttributes = null;
-    private String name;
-    private String value;
-    private Map<String, String> attributes;
-    private Set<org.apache.ambari.server.state.PropertyInfo.PropertyType> propertyTypes;
-    private String type;
-    private Set<PropertyDependencyInfo> dependsOnProperties =
-      Collections.emptySet();
-
-    public ConfigProperty(ReadOnlyConfigurationResponse config) {
-      this.name = config.getPropertyName();
-      this.value = config.getPropertyValue();
-      this.attributes = config.getPropertyAttributes();
-      this.propertyTypes = config.getPropertyType();
-      this.type = normalizeType(config.getType());
-      this.dependsOnProperties = config.getDependsOnProperties();
-      this.propertyValueAttributes = config.getPropertyValueAttributes();
-    }
-
-    public ConfigProperty(String type, String name, String value) {
-      this.type = type;
-      this.name = name;
-      this.value = value;
-    }
-
-    public String getName() {
-      return name;
-    }
-
-    public String getValue() {
-      return value;
-    }
-
-    public void setValue(String value) {
-      this.value = value;
-    }
-
-    public String getType() {
-      return type;
-    }
-
-    public Set<org.apache.ambari.server.state.PropertyInfo.PropertyType> getPropertyTypes() {
-      return propertyTypes;
-    }
-
-    public void setPropertyTypes(Set<PropertyInfo.PropertyType> propertyTypes) {
-      this.propertyTypes = propertyTypes;
-    }
-
-    public Map<String, String> getAttributes() {
-      return attributes;
-    }
-
-    public void setAttributes(Map<String, String> attributes) {
-      this.attributes = attributes;
-    }
-
-    Set<PropertyDependencyInfo> getDependsOnProperties() {
-      return this.dependsOnProperties;
-    }
-
-    private String normalizeType(String type) {
-      //strip .xml from type
-      if (type.endsWith(".xml")) {
-        type = type.substring(0, type.length() - 4);
-      }
-      return type;
-    }
-
-    public ValueAttributesInfo getPropertyValueAttributes() {
-      return propertyValueAttributes;
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UnitUpdater.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UnitUpdater.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UnitUpdater.java
index a566625..3a70f81 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UnitUpdater.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UnitUpdater.java
@@ -24,6 +24,7 @@ import java.util.Collections;
 import java.util.Map;
 import java.util.Optional;
 
+import org.apache.ambari.server.controller.StackV2;
 import org.apache.ambari.server.topology.ClusterTopology;
 import org.apache.ambari.server.topology.validators.UnitValidatedProperty;
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
index 0434728..9270e7d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
@@ -53,6 +53,7 @@ import org.apache.ambari.server.controller.ServiceComponentHostRequest;
 import org.apache.ambari.server.controller.ServiceComponentRequest;
 import org.apache.ambari.server.controller.ServiceGroupRequest;
 import org.apache.ambari.server.controller.ServiceRequest;
+import org.apache.ambari.server.controller.StackV2;
 import org.apache.ambari.server.controller.internal.AbstractResourceProvider;
 import org.apache.ambari.server.controller.internal.ComponentResourceProvider;
 import org.apache.ambari.server.controller.internal.ConfigGroupResourceProvider;
@@ -62,7 +63,6 @@ import org.apache.ambari.server.controller.internal.ProvisionClusterRequest;
 import org.apache.ambari.server.controller.internal.RequestImpl;
 import org.apache.ambari.server.controller.internal.ServiceGroupResourceProvider;
 import org.apache.ambari.server.controller.internal.ServiceResourceProvider;
-import org.apache.ambari.server.controller.internal.StackV2;
 import org.apache.ambari.server.controller.internal.VersionDefinitionResourceProvider;
 import org.apache.ambari.server.controller.predicate.EqualsPredicate;
 import org.apache.ambari.server.controller.spi.ClusterController;
@@ -242,7 +242,8 @@ public class AmbariContext {
       for (Service service : serviceGroup.getServices()) {
         String credentialStoreEnabled = topology.getBlueprint().getCredentialStoreEnabled(service.getType());
 
-        StackV2 stack = service.getStack();
+        String stackIdStr = service.getStackId();
+        StackV2 stack = topology.getBlueprint().getStackById(stackIdStr);
         StackId stackId = new StackId(stack.getName(), stack.getVersion());
         RepositoryVersionEntity repoVersion = repositoryVersionDAO.findByStackAndVersion(stackId, stack.getRepoVersion());
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintFactory.java
index fc419cb..404068d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintFactory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintFactory.java
@@ -82,10 +82,10 @@ public class BlueprintFactory {
     this.stackFactory = stackFactory;
   }
 
-  public BlueprintV2 getBlueprint(String blueprintName) throws NoSuchStackException {
+  public Blueprint getBlueprint(String blueprintName) throws NoSuchStackException {
     BlueprintEntity entity = blueprintDAO.findByName(blueprintName);
     //todo: just return null?
-    return entity == null ? null : new BlueprintImplV2(entity);
+    return entity == null ? null : new BlueprintImpl(entity);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
index b2119e6..4b7dd32 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
@@ -135,33 +135,45 @@ public class BlueprintImplV2 implements BlueprintV2 {
 
   @Override
   @JsonIgnore
-  public Collection<ServiceId> getAllServices() {
-    return hostGroups.stream().flatMap(hg -> hg.getServices().stream()).collect(Collectors.toSet());
+  public Collection<ServiceId> getAllServiceIds() {
+    return hostGroups.stream().flatMap(hg -> hg.getServiceIds().stream()).collect(Collectors.toSet());
   }
 
   @Override
   @JsonIgnore
-  public Collection<String> getAllServiceTypes() {
+  public Collection<Service> getServicesFromServiceGroup(ServiceGroup serviceGroup, String serviceType) {
+    if (serviceType == null) {
+      return serviceGroup.getServices();
+    } else {
+      return serviceGroup.getServices().stream().filter(
+              service -> service.getType().equalsIgnoreCase(serviceType)).collect(Collectors.toList());
+    }
+  }
+
+  @Override
+  @JsonIgnore
+  public StackV2 getStackById(String stackId) {
     return null;
   }
 
   @Override
   @JsonIgnore
-  public Collection<Service> getServicesByType(String serviceType) {
+  public Collection<Service> getAllServices() {
     return null;
-//    getAllServices().stream().filter(
-//            service -> service.getType().equalsIgnoreCase(serviceType)).collect(Collectors.toList());
   }
 
   @Override
   @JsonIgnore
-  public Collection<Service> getServicesFromServiceGroup(ServiceGroup serviceGroup, String serviceType) {
-    if (serviceType == null) {
-      return serviceGroup.getServices();
-    } else {
-      return serviceGroup.getServices().stream().filter(
-              service -> service.getType().equalsIgnoreCase(serviceType)).collect(Collectors.toList());
-    }
+  public Collection<String> getAllServiceTypes() {
+    return null;
+  }
+
+  @Override
+  @JsonIgnore
+  public Collection<Service> getServicesByType(String serviceType) {
+    return null;
+//    getAllServices().stream().filter(
+//            service -> service.getType().equalsIgnoreCase(serviceType)).collect(Collectors.toList());
   }
 
   @Override
@@ -186,7 +198,7 @@ public class BlueprintImplV2 implements BlueprintV2 {
   @Override
   @JsonIgnore
   public Collection<HostGroupV2> getHostGroupsForService(ServiceId serviceId) {
-    return hostGroups.stream().filter(hg -> !hg.getComponents(serviceId).isEmpty()).collect(Collectors.toList());
+    return hostGroups.stream().filter(hg -> !hg.getComponentsByServiceId(serviceId).isEmpty()).collect(Collectors.toList());
   }
 
   @Override
@@ -205,10 +217,7 @@ public class BlueprintImplV2 implements BlueprintV2 {
     return this.setting;
   }
 
-  @Override
-  public String getRecoveryEnabled(ComponentV2 component) {
-    return null;
-  }
+
 
   @Nonnull
   @Override
@@ -224,6 +233,10 @@ public class BlueprintImplV2 implements BlueprintV2 {
   }
 
   @Override
+  public String getRecoveryEnabled(ComponentV2 component) {
+    return null;
+  }
+
   public String getRecoveryEnabled(String serviceName, String componentName) {
     // If component name was specified in the list of "component_settings",
     // determine if recovery_enabled is true or false and return it.

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java
index ea17e90..29539db 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java
@@ -22,11 +22,9 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
-
 import javax.annotation.Nonnull;
 
 import org.apache.ambari.server.controller.StackV2;
-
 import org.apache.ambari.server.orm.entities.BlueprintEntity;
 
 
@@ -69,6 +67,8 @@ public interface BlueprintV2 {
   **/
   public Collection<String> getStackIds();
 
+  StackV2 getStackById(String stackId);
+
   Collection<ServiceGroup> getServiceGroups();
 
   /**
@@ -76,7 +76,9 @@ public interface BlueprintV2 {
    *
    * @return collection of all represented service names
    */
-  Collection<ServiceId> getAllServices();
+  Collection<ServiceId> getAllServiceIds();
+
+  ;Collection<Service> getAllServices();
 
   /**
    * Get the names of all the services represented in the blueprint.
@@ -129,6 +131,8 @@ public interface BlueprintV2 {
    */
   Collection<ComponentV2> getComponents(ServiceId serviceId);
 
+  Collection<ComponentV2> getComponents(Service service);
+
 
   /**
    * Get components by type from a service.

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java
index 6b86ba5..b3ce044 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java
@@ -33,11 +33,11 @@ import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorBlueprintProcessor;
 import org.apache.ambari.server.controller.ClusterRequest;
 import org.apache.ambari.server.controller.ConfigurationRequest;
+import org.apache.ambari.server.controller.StackV2;
 import org.apache.ambari.server.controller.internal.BlueprintConfigurationProcessor;
 import org.apache.ambari.server.controller.internal.ClusterResourceProvider;
 import org.apache.ambari.server.controller.internal.ConfigurationContext;
 import org.apache.ambari.server.controller.internal.ConfigurationTopologyException;
-import org.apache.ambari.server.controller.internal.StackV2;
 import org.apache.ambari.server.serveraction.kerberos.KerberosInvalidConfigurationException;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.SecurityType;
@@ -361,7 +361,8 @@ public class ClusterConfigurationRequest {
       //todo: remove intermediate request type
       // one bp config request per service
       BlueprintServiceConfigRequest blueprintConfigRequest = new BlueprintServiceConfigRequest(service.getType());
-      StackV2 serviceStack = service.getStack();
+      String serviceStackId = service.getStackId();
+      StackV2 serviceStack = blueprint.getStackById(serviceStackId);
       for (String serviceConfigType : serviceStack.getAllConfigurationTypes(service.getType())) {
         Set<String> excludedConfigTypes = serviceStack.getExcludedConfigurationTypes(service.getType());
         if (!excludedConfigTypes.contains(serviceConfigType)) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java
index 43dda1b..e59b1f9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java
@@ -69,6 +69,16 @@ public class ComponentV2 implements Configurable {
     return serviceId;
   }
 
+  //TODO
+  public Service getService() {
+    return null;
+  }
+
+  //TODO
+  public ServiceGroup getServiceGroup() {
+    return null;
+  }
+
   public Configuration getConfiguration() {
     return configuration;
   }
@@ -88,7 +98,7 @@ public class ComponentV2 implements Configurable {
     this.name = name;
   }
 
-  public String getServiceGroup() {
+  public String getServiceGroupName() {
     return serviceId.getServiceGroup();
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java
index 0922e74..4745f59 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java
@@ -87,7 +87,9 @@ public interface HostGroupV2 {
    *
    * @return collection of component names for the specified service; will not return null
    */
-  Collection<ComponentV2> getComponents(ServiceId serviceId);
+  Collection<ComponentV2> getComponentsByServiceId(ServiceId serviceId);
+
+  Collection<ComponentV2> getComponents(Service serviceId);
 
   /**
    * Determine if the host group contains a master component.
@@ -99,7 +101,12 @@ public interface HostGroupV2 {
   /**
    * @return collection of service ids associated with the host group components.
    */
-  Collection<ServiceId> getServices();
+  Collection<ServiceId> getServiceIds();
+
+  /**
+   * @return collection of service ids associated with the host group components.
+   */
+  Collection<Service> getServices();
 
   /**
    * @return collection of service names associated with the host group components.

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java
index 351351b..e9f4f4b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java
@@ -67,7 +67,12 @@ public class HostGroupV2Impl implements HostGroupV2, Configurable {
   }
 
   @Override
-  public Collection<ComponentV2> getComponents(ServiceId serviceId) {
+  public Collection<ComponentV2> getComponents(Service serviceId) {
+    return null;
+  }
+
+  @Override
+  public Collection<ComponentV2> getComponentsByServiceId(ServiceId serviceId) {
     return components.stream().filter(c -> c.getServiceId().equals(serviceId)).collect(Collectors.toList());
   }
 
@@ -77,13 +82,18 @@ public class HostGroupV2Impl implements HostGroupV2, Configurable {
   }
 
   @Override
-  @JsonIgnore
-  public Collection<ServiceId> getServices() {
+  public Collection<ServiceId> getServiceIds() {
     return services;
   }
 
   @Override
   @JsonIgnore
+  public Collection<Service> getServices() {
+    return null;
+  }
+
+  @Override
+  @JsonIgnore
   public Collection<String> getServiceNames() {
     return services.stream().map(s -> s.getName()).collect(Collectors.toList());
   }
@@ -94,6 +104,11 @@ public class HostGroupV2Impl implements HostGroupV2, Configurable {
   }
 
   @Override
+  public Collection<Service> getServiceConfigs() {
+    return null;
+  }
+
+  @Override
   public String getCardinality() {
     return cardinality;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/topology/HostRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostRequest.java
index 3243359..685d208 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostRequest.java
@@ -31,9 +31,9 @@ import java.util.Map;
 import org.apache.ambari.server.actionmanager.HostRoleCommand;
 import org.apache.ambari.server.api.predicate.InvalidQueryException;
 import org.apache.ambari.server.api.predicate.PredicateCompiler;
+import org.apache.ambari.server.controller.StackV2;
 import org.apache.ambari.server.controller.internal.HostResourceProvider;
 import org.apache.ambari.server.controller.internal.ResourceImpl;
-import org.apache.ambari.server.controller.internal.StackV2;
 import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java
index 8b51fab..a9a132b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.topology;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -93,7 +94,7 @@ public class PersistedStateImpl implements PersistedState {
   private HostRoleCommandDAO physicalTaskDAO;
 
   @Inject
-  private BlueprintFactory blueprintFactory;
+  private BlueprintV2Factory blueprintFactory;
 
   @Inject
   private LogicalRequestFactory logicalRequestFactory;
@@ -382,13 +383,17 @@ public class PersistedStateImpl implements PersistedState {
     private final Collection<Service> services;
     private final Map<String, HostGroupInfo> hostGroupInfoMap = new HashMap<>();
 
-    public ReplayedTopologyRequest(TopologyRequestEntity entity, BlueprintFactory blueprintFactory) {
+    public ReplayedTopologyRequest(TopologyRequestEntity entity, BlueprintV2Factory blueprintFactory) {
       clusterId = entity.getClusterId();
       type = Type.valueOf(entity.getAction());
       description = entity.getDescription();
 
       try {
         blueprint = blueprintFactory.getBlueprint(entity.getBlueprintName());
+      } catch (NoSuchBlueprintException e) {
+        throw new RuntimeException("Unable to load blueprint while replaying topology request: " + e, e);
+      } catch (IOException e) {
+        throw new RuntimeException("Unable to load blueprint while replaying topology request: " + e, e);
       } catch (NoSuchStackException e) {
         throw new RuntimeException("Unable to load blueprint while replaying topology request: " + e, e);
       }

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/topology/Service.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/Service.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/Service.java
index 1dde7ea..81f235c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/Service.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/Service.java
@@ -21,6 +21,8 @@ package org.apache.ambari.server.topology;
 
 import java.util.Set;
 
+import org.apache.ambari.server.controller.StackV2;
+
 import com.fasterxml.jackson.annotation.JsonProperty;
 
 public class Service implements Configurable {
@@ -44,10 +46,15 @@ public class Service implements Configurable {
     return this.id.getName();
   }
 
-  public String getServiceGroup() {
+  public String getServiceGroupId() {
     return this.id.getServiceGroup();
   }
 
+  //TODO
+  public ServiceGroup getServiceGroup() {
+    return null;
+  }
+
   public String getType() {
     return type;
   }
@@ -56,10 +63,20 @@ public class Service implements Configurable {
     return stackId;
   }
 
-  public Set<ServiceId> getDependencies() {
+  //TODO
+  public StackV2 getStack() {
+    return null;
+  }
+
+  public Set<ServiceId> getDependentServiceIds() {
     return dependencies;
   }
 
+  //TODO
+  public Set<Service> getDependencies() {
+    return null;
+  }
+
   public Configuration getConfiguration() {
     return configuration;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
index 7691619..3b7dcc8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
@@ -42,6 +42,7 @@ import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.AmbariServer;
 import org.apache.ambari.server.controller.RequestStatusResponse;
 import org.apache.ambari.server.controller.ShortTaskStatus;
+import org.apache.ambari.server.controller.StackV2;
 import org.apache.ambari.server.controller.internal.ArtifactResourceProvider;
 import org.apache.ambari.server.controller.internal.BaseClusterRequest;
 import org.apache.ambari.server.controller.internal.CalculatedStatus;
@@ -49,7 +50,6 @@ import org.apache.ambari.server.controller.internal.CredentialResourceProvider;
 import org.apache.ambari.server.controller.internal.ProvisionClusterRequest;
 import org.apache.ambari.server.controller.internal.RequestImpl;
 import org.apache.ambari.server.controller.internal.ScaleClusterRequest;
-import org.apache.ambari.server.controller.internal.StackV2;
 import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
 import org.apache.ambari.server.controller.spi.RequestStatus;
 import org.apache.ambari.server.controller.spi.Resource;

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/ClusterConfigTypeValidator.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/ClusterConfigTypeValidator.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/ClusterConfigTypeValidator.java
index 94a1a5c..7ac75e9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/ClusterConfigTypeValidator.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/ClusterConfigTypeValidator.java
@@ -16,6 +16,7 @@ package org.apache.ambari.server.topology.validators;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.ambari.server.controller.StackV2;
 import org.apache.ambari.server.topology.ClusterTopology;
 import org.apache.ambari.server.topology.InvalidTopologyException;
 import org.apache.ambari.server.topology.Service;
@@ -46,7 +47,9 @@ public class ClusterConfigTypeValidator implements TopologyValidator {
     // collecting all config types for services in the blueprint (from the related stack)
     Set<String> stackServiceConfigTypes = new HashSet<>();
     for (Service service : topology.getBlueprint().getAllServices()) {
-      stackServiceConfigTypes.addAll(service.getStack().getConfigurationTypes(service.getType()));
+      String stackId = service.getStackId();
+      StackV2 stack = topology.getBlueprint().getStackById(stackId);
+      stackServiceConfigTypes.addAll(stack.getConfigurationTypes(service.getType()));
     }
 
     // identifying invalid config types

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/RequiredConfigPropertiesValidator.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/RequiredConfigPropertiesValidator.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/RequiredConfigPropertiesValidator.java
index 05c063c..fd07572 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/RequiredConfigPropertiesValidator.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/RequiredConfigPropertiesValidator.java
@@ -21,7 +21,7 @@ import java.util.Map;
 import java.util.TreeMap;
 import java.util.TreeSet;
 
-import org.apache.ambari.server.controller.internal.StackV2;
+import org.apache.ambari.server.controller.StackV2;
 import org.apache.ambari.server.state.PropertyInfo;
 import org.apache.ambari.server.topology.ClusterTopology;
 import org.apache.ambari.server.topology.HostGroupV2;

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/RequiredPasswordValidator.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/RequiredPasswordValidator.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/RequiredPasswordValidator.java
index 41dee07..2258d97 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/RequiredPasswordValidator.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/RequiredPasswordValidator.java
@@ -19,7 +19,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 
-import org.apache.ambari.server.controller.internal.StackV2;
+import org.apache.ambari.server.controller.StackV2;
 import org.apache.ambari.server.state.PropertyInfo;
 import org.apache.ambari.server.topology.BlueprintV2;
 import org.apache.ambari.server.topology.ClusterTopology;

http://git-wip-us.apache.org/repos/asf/ambari/blob/841cc7e1/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/UnitValidator.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/UnitValidator.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/UnitValidator.java
index 8c8475a..00b9838 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/UnitValidator.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/UnitValidator.java
@@ -22,7 +22,7 @@ import static org.apache.ambari.server.controller.internal.UnitUpdater.PropertyV
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.ambari.server.controller.internal.StackV2;
+import org.apache.ambari.server.controller.StackV2;
 import org.apache.ambari.server.controller.internal.UnitUpdater.PropertyUnit;
 import org.apache.ambari.server.topology.ClusterTopology;
 import org.apache.ambari.server.topology.InvalidTopologyException;
@@ -42,11 +42,13 @@ public class UnitValidator implements TopologyValidator {
   @Override
   public void validate(ClusterTopology topology) throws InvalidTopologyException {
     topology.getServiceConfigs().forEach(service -> {
-      validateConfig(service.getConfiguration().getFullProperties(), service.getStack());
-      topology.getHostGroupInfo().values().forEach(hostGroup ->
-        validateConfig(hostGroup.getConfiguration().getFullProperties(), service.getStack()));
+      String stackId = service.getStackId();
+      validateConfig(service.getConfiguration().getFullProperties(), topology.getBlueprint().getStackById(stackId));
+      topology.getHostGroupInfo().values().forEach(hostGroup -> {
+        String stackId2 = service.getStackId();
+        validateConfig(hostGroup.getConfiguration().getFullProperties(), topology.getBlueprint().getStackById(stackId2));
+      });
     });
-
   }
 
   private void validateConfig(Map<String, Map<String, String>> configuration, StackV2 stack) {


[2/4] ambari git commit: Blueprint V2 data model (benyoka)

Posted by ma...@apache.org.
Blueprint V2 data model (benyoka)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f82497d4
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f82497d4
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f82497d4

Branch: refs/heads/branch-feature-AMBARI-14714
Commit: f82497d4d5c8d96dbf5629578a0205de0807e422
Parents: 17e4330
Author: Balazs Bence Sari <be...@apache.org>
Authored: Wed Oct 18 17:39:59 2017 +0200
Committer: Sandor Magyari <sm...@hortonworks.com>
Committed: Thu Oct 19 14:30:14 2017 +0200

----------------------------------------------------------------------
 .../ambari/server/controller/StackV2.java       | 605 +++++++++++++++++++
 .../server/controller/StackV2Factory.java       | 219 +++++++
 .../ambari/server/orm/dao/BlueprintV2DAO.java   | 136 +++++
 .../server/orm/entities/BlueprintEntity.java    |   1 -
 .../server/orm/entities/BlueprintV2Entity.java  | 119 ++++
 .../orm/entities/HostGroupComponentEntity.java  |  17 +-
 .../ambari/server/orm/entities/StackEntity.java |  11 +-
 .../ambari/server/topology/BlueprintImplV2.java | 256 +++++++-
 .../ambari/server/topology/BlueprintV2.java     |  55 +-
 .../server/topology/BlueprintV2Factory.java     | 170 ++++++
 .../server/topology/BlueprintValidatorV2.java   |  43 ++
 .../ambari/server/topology/ComponentV2.java     |  88 ++-
 .../ambari/server/topology/Configurable.java    |  40 ++
 .../ambari/server/topology/Configuration.java   |   7 +
 .../ambari/server/topology/HostGroupImpl.java   |   2 -
 .../ambari/server/topology/HostGroupV2.java     |  15 +-
 .../ambari/server/topology/HostGroupV2Impl.java | 124 ++++
 .../server/topology/RepositoryVersion.java      |  71 +++
 .../server/topology/SecurityConfiguration.java  |   7 +-
 .../apache/ambari/server/topology/Service.java  |  85 +--
 .../ambari/server/topology/ServiceGroup.java    |  42 +-
 .../ambari/server/topology/ServiceId.java       |  52 ++
 .../validators/BlueprintImplV2Test.java         |   9 +
 23 files changed, 2034 insertions(+), 140 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java
new file mode 100644
index 0000000..8d7de5d
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java
@@ -0,0 +1,605 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.controller;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ambari.server.state.AutoDeployInfo;
+import org.apache.ambari.server.state.DependencyInfo;
+import org.apache.ambari.server.state.PropertyDependencyInfo;
+import org.apache.ambari.server.state.PropertyInfo;
+import org.apache.ambari.server.state.ValueAttributesInfo;
+import org.apache.ambari.server.topology.Cardinality;
+import org.apache.ambari.server.topology.Configuration;
+
+/**
+ * Encapsulates stack information.
+ */
+public class StackV2 {
+
+    /** Stack name */
+    private final String name;
+
+    /** Stack version */
+    private final String version;
+
+    /** Repo version */
+    private final String repoVersion;
+
+    /** Map of service name to components */
+    private final Map<String, Collection<String>> serviceComponents;
+
+    /** Map of component to service */
+    private final Map<String, String> componentService;
+
+    /** Map of component to dependencies */
+    private final Map<String, Collection<DependencyInfo>> dependencies;
+
+    /** Map of dependency to conditional service */
+    private final Map<DependencyInfo, String> dependencyConditionalServiceMap;
+
+    /**
+     * Map of database component name to configuration property which indicates whether
+     * the database in to be managed or if it is an external non-managed instance.
+     * If the value of the config property starts with 'New', the database is determined
+     * to be managed, otherwise it is non-managed.
+     */
+    private final Map<String, String> dbDependencyInfo;
+
+    /** Map of component to required cardinality */
+    private final Map<String, String> cardinalityRequirements = new HashMap<>();
+
+    //todo: instead of all these maps from component -> * ,
+    //todo: we should use a Component object with all of these attributes
+    private Set<String> masterComponents = new HashSet<>();
+
+    /** Map of component to auto-deploy information */
+    private final Map<String, AutoDeployInfo> componentAutoDeployInfo;
+
+    /** Map of service to config type properties */
+    private final Map<String, Map<String, Map<String, ConfigProperty>>> serviceConfigurations;
+
+    /** Map of service to required type properties */
+    private final Map<String, Map<String, Map<String, ConfigProperty>>> requiredServiceConfigurations;
+
+    /** Map of service to config type properties */
+    private final Map<String, Map<String, ConfigProperty>> stackConfigurations;
+
+    /** Map of service to set of excluded config types */
+    private final Map<String, Set<String>> excludedConfigurationTypes;
+
+    public StackV2(String name,
+                   String version,
+                   String repoVersion,
+                   Map<String, Collection<String>> serviceComponents,
+                   Map<String, Collection<DependencyInfo>> dependencies,
+                   Map<String, String> dbDependencyInfo,
+                   Map<String, AutoDeployInfo> componentAutoDeployInfo,
+                   Map<String, Map<String, Map<String, ConfigProperty>>> serviceConfigurations,
+                   Map<String, Map<String, Map<String, ConfigProperty>>> requiredServiceConfigurations,
+                   Map<String, Map<String, ConfigProperty>> stackConfigurations,
+                   Map<String, Set<String>> excludedConfigurationTypes) {
+        this.name = name;
+        this.version = version;
+        this.repoVersion = repoVersion;
+
+        this.serviceComponents = serviceComponents;
+        this.componentService = new HashMap<>();
+        for (Map.Entry<String, Collection<String>> entry: serviceComponents.entrySet()) {
+            for (String comp: entry.getValue()) {
+                componentService.put(comp, entry.getKey());
+            }
+        }
+
+        this.dependencies = dependencies;
+        this.dependencyConditionalServiceMap = new HashMap<>();
+        for (Map.Entry<String, Collection<DependencyInfo>> entry: dependencies.entrySet()) {
+            for (DependencyInfo di: entry.getValue()) {
+                dependencyConditionalServiceMap.put(di, entry.getKey());
+            }
+        }
+
+        this.dbDependencyInfo = dbDependencyInfo;
+        this.componentAutoDeployInfo = componentAutoDeployInfo;
+        this.serviceConfigurations = serviceConfigurations;
+        this.requiredServiceConfigurations = requiredServiceConfigurations;
+        this.stackConfigurations = stackConfigurations;
+        this.excludedConfigurationTypes = excludedConfigurationTypes;
+    }
+
+    /** @return stack name */
+    public String getName() {
+        return name;
+    }
+
+    /** @return stack version */
+    public String getVersion() {
+        return version;
+    }
+
+    /** @return repo version */
+    public String getRepoVersion() { return repoVersion; }
+
+    Map<DependencyInfo, String> getDependencyConditionalServiceMap() {
+        return dependencyConditionalServiceMap;
+    }
+
+    /** @return collection of all services for the stack */
+    public Collection<String> getServices() {
+        return serviceComponents.keySet();
+    }
+
+    /**
+     * Get components contained in the stack for the specified service.
+     *
+     * @param service  service name
+     * @return collection of component names for the specified service
+     */
+    public Collection<String> getComponents(String service) {
+        return serviceComponents.get(service);
+    }
+
+    /** @return map of service to associated components */
+    public Map<String, Collection<String>> getComponents() {
+        return serviceComponents;
+    }
+
+//  /**
+//   * Get info for the specified component.
+//   *
+//   * @param component  component name
+//   *
+//   * @return component information for the requested component
+//   *         or null if the component doesn't exist in the stack
+//   */
+//  @Deprecated
+//  public ComponentInfo getComponentInfo(String component) {
+//    ComponentInfo componentInfo = null;
+//    String service = getServiceForComponent(component);
+//    if (service != null) {
+//      try {
+//        componentInfo = controller.getAmbariMetaInfo().getComponent(
+//            getName(), getVersion(), service, component);
+//      } catch (AmbariException e) {
+//        // just return null if component doesn't exist
+//      }
+//    }
+//    return componentInfo;
+//  }
+
+    /**
+     * Get all configuration types, including excluded types for the specified service.
+     *
+     * @param service  service name
+     *
+     * @return collection of all configuration types for the specified service
+     */
+    public Collection<String> getAllConfigurationTypes(String service) {
+        return serviceConfigurations.get(service).keySet();
+    }
+
+    /**
+     * Get configuration types for the specified service.
+     * This doesn't include any service excluded types.
+     *
+     * @param service  service name
+     *
+     * @return collection of all configuration types for the specified service
+     */
+    public Collection<String> getConfigurationTypes(String service) {
+        Set<String> serviceTypes = new HashSet<>(serviceConfigurations.get(service).keySet());
+        serviceTypes.removeAll(getExcludedConfigurationTypes(service));
+        return serviceTypes;
+    }
+
+    /**
+     * Get the set of excluded configuration types for this service.
+     *
+     * @param service service name
+     *
+     * @return Set of names of excluded config types. Will not return null.
+     */
+    public Set<String> getExcludedConfigurationTypes(String service) {
+        return excludedConfigurationTypes.containsKey(service) ?
+                excludedConfigurationTypes.get(service) :
+                Collections.emptySet();
+    }
+
+    /**
+     * Get config properties for the specified service and configuration type.
+     *
+     * @param service  service name
+     * @param type     configuration type
+     *
+     * @return map of property names to values for the specified service and configuration type
+     */
+    public Map<String, String> getConfigurationProperties(String service, String type) {
+        Map<String, String> configMap = new HashMap<>();
+        Map<String, ConfigProperty> configProperties = serviceConfigurations.get(service).get(type);
+        if (configProperties != null) {
+            for (Map.Entry<String, ConfigProperty> configProperty : configProperties.entrySet()) {
+                configMap.put(configProperty.getKey(), configProperty.getValue().getValue());
+            }
+        }
+        return configMap;
+    }
+
+    public Map<String, ConfigProperty> getConfigurationPropertiesWithMetadata(String service, String type) {
+        return serviceConfigurations.get(service).get(type);
+    }
+
+    /**
+     * Get all required config properties for the specified service.
+     *
+     * @param service  service name
+     *
+     * @return collection of all required properties for the given service
+     */
+    public Collection<ConfigProperty> getRequiredConfigurationProperties(String service) {
+        Collection<ConfigProperty> requiredConfigProperties = new HashSet<>();
+        Map<String, Map<String, ConfigProperty>> serviceProperties = requiredServiceConfigurations.get(service);
+        if (serviceProperties != null) {
+            for (Map.Entry<String, Map<String, ConfigProperty>> typePropertiesEntry : serviceProperties.entrySet()) {
+                requiredConfigProperties.addAll(typePropertiesEntry.getValue().values());
+            }
+        }
+        return requiredConfigProperties;
+    }
+
+    /**
+     * Get required config properties for the specified service which belong to the specified property type.
+     *
+     * @param service       service name
+     * @param propertyType  property type
+     *
+     * @return collection of required properties for the given service and property type
+     */
+    public Collection<ConfigProperty> getRequiredConfigurationProperties(String service, PropertyInfo.PropertyType propertyType) {
+        Collection<ConfigProperty> matchingProperties = new HashSet<>();
+        Map<String, Map<String, ConfigProperty>> requiredProperties = requiredServiceConfigurations.get(service);
+        if (requiredProperties != null) {
+            for (Map.Entry<String, Map<String, ConfigProperty>> typePropertiesEntry : requiredProperties.entrySet()) {
+                for (ConfigProperty configProperty : typePropertiesEntry.getValue().values()) {
+                    if (configProperty.getPropertyTypes().contains(propertyType)) {
+                        matchingProperties.add(configProperty);
+                    }
+                }
+            }
+        }
+        return matchingProperties;
+    }
+
+    public boolean isPasswordProperty(String service, String type, String propertyName) {
+        return (serviceConfigurations.containsKey(service) &&
+                serviceConfigurations.get(service).containsKey(type) &&
+                serviceConfigurations.get(service).get(type).containsKey(propertyName) &&
+                serviceConfigurations.get(service).get(type).get(propertyName).getPropertyTypes().
+                        contains(PropertyInfo.PropertyType.PASSWORD));
+    }
+
+    //todo
+    public Map<String, String> getStackConfigurationProperties(String type) {
+        Map<String, String> configMap = new HashMap<>();
+        Map<String, ConfigProperty> configProperties = stackConfigurations.get(type);
+        if (configProperties != null) {
+            for (Map.Entry<String, ConfigProperty> configProperty : configProperties.entrySet()) {
+                configMap.put(configProperty.getKey(), configProperty.getValue().getValue());
+            }
+        }
+        return configMap;
+    }
+
+    public boolean isKerberosPrincipalNameProperty(String service, String type, String propertyName) {
+        return (serviceConfigurations.containsKey(service) &&
+                serviceConfigurations.get(service).containsKey(type) &&
+                serviceConfigurations.get(service).get(type).containsKey(propertyName) &&
+                serviceConfigurations.get(service).get(type).get(propertyName).getPropertyTypes().
+                        contains(PropertyInfo.PropertyType.KERBEROS_PRINCIPAL));
+    }
+    /**
+     * Get config attributes for the specified service and configuration type.
+     *
+     * @param service  service name
+     * @param type     configuration type
+     *
+     * @return  map of attribute names to map of property names to attribute values
+     *          for the specified service and configuration type
+     */
+    public Map<String, Map<String, String>> getConfigurationAttributes(String service, String type) {
+        Map<String, Map<String, String>> attributesMap = new HashMap<>();
+        Map<String, ConfigProperty> configProperties = serviceConfigurations.get(service).get(type);
+        if (configProperties != null) {
+            for (Map.Entry<String, ConfigProperty> configProperty : configProperties.entrySet()) {
+                String propertyName = configProperty.getKey();
+                Map<String, String> propertyAttributes = configProperty.getValue().getAttributes();
+                if (propertyAttributes != null) {
+                    for (Map.Entry<String, String> propertyAttribute : propertyAttributes.entrySet()) {
+                        String attributeName = propertyAttribute.getKey();
+                        String attributeValue = propertyAttribute.getValue();
+                        if (attributeValue != null) {
+                            Map<String, String> attributes = getWithEmptyDefault(attributesMap, attributeName);
+                            attributes.put(propertyName, attributeValue);
+                        }
+                    }
+                }
+            }
+        }
+        return attributesMap;
+    }
+
+    //todo:
+    public Map<String, Map<String, String>> getStackConfigurationAttributes(String type) {
+        Map<String, Map<String, String>> attributesMap = new HashMap<>();
+        Map<String, ConfigProperty> configProperties = stackConfigurations.get(type);
+        if (configProperties != null) {
+            for (Map.Entry<String, ConfigProperty> configProperty : configProperties.entrySet()) {
+                String propertyName = configProperty.getKey();
+                Map<String, String> propertyAttributes = configProperty.getValue().getAttributes();
+                if (propertyAttributes != null) {
+                    for (Map.Entry<String, String> propertyAttribute : propertyAttributes.entrySet()) {
+                        String attributeName = propertyAttribute.getKey();
+                        String attributeValue = propertyAttribute.getValue();
+                        Map<String, String> attributes = getWithEmptyDefault(attributesMap, attributeName);
+                        attributes.put(propertyName, attributeValue);
+                    }
+                }
+            }
+        }
+        return attributesMap;
+    }
+
+    /**
+     * Get the service for the specified component.
+     *
+     * @param component  component name
+     *
+     * @return service name that contains tha specified component
+     */
+    public String getServiceForComponent(String component) {
+        return componentService.get(component);
+    }
+
+    /**
+     * Get the names of the services which contains the specified components.
+     *
+     * @param components collection of components
+     *
+     * @return collection of services which contain the specified components
+     */
+    public Collection<String> getServicesForComponents(Collection<String> components) {
+        Set<String> services = new HashSet<>();
+        for (String component : components) {
+            services.add(getServiceForComponent(component));
+        }
+
+        return services;
+    }
+
+    /**
+     * Obtain the service name which corresponds to the specified configuration.
+     *
+     * @param config  configuration type
+     *
+     * @return name of service which corresponds to the specified configuration type
+     */
+    public String getServiceForConfigType(String config) {
+        for (Map.Entry<String, Map<String, Map<String, ConfigProperty>>> entry : serviceConfigurations.entrySet()) {
+            Map<String, Map<String, ConfigProperty>> typeMap = entry.getValue();
+            String serviceName = entry.getKey();
+            if (typeMap.containsKey(config) && !getExcludedConfigurationTypes(serviceName).contains(config)) {
+                return serviceName;
+            }
+        }
+        throw new IllegalArgumentException(
+                "Specified configuration type is not associated with any service: " + config);
+    }
+
+    /**
+     * Return the dependencies specified for the given component.
+     *
+     * @param component  component to get dependency information for
+     *
+     * @return collection of dependency information for the specified component
+     */
+    //todo: full dependency graph
+    public Collection<DependencyInfo> getDependenciesForComponent(String component) {
+        return dependencies.containsKey(component) ? dependencies.get(component) :
+                Collections.emptySet();
+    }
+
+    /**
+     * Get the service, if any, that a component dependency is conditional on.
+     *
+     * @param dependency  dependency to get conditional service for
+     *
+     * @return conditional service for provided component or null if dependency
+     *         is not conditional on a service
+     */
+    public String getConditionalServiceForDependency(DependencyInfo dependency) {
+        return dependencyConditionalServiceMap.get(dependency);
+    }
+
+    public String getExternalComponentConfig(String component) {
+        return dbDependencyInfo.get(component);
+    }
+
+    /**
+     * Obtain the required cardinality for the specified component.
+     */
+    public Cardinality getCardinality(String component) {
+        return new Cardinality(cardinalityRequirements.get(component));
+    }
+
+    /**
+     * Obtain auto-deploy information for the specified component.
+     */
+    public AutoDeployInfo getAutoDeployInfo(String component) {
+        return componentAutoDeployInfo.get(component);
+    }
+
+    public boolean isMasterComponent(String component) {
+        return masterComponents.contains(component);
+    }
+
+    public Configuration getConfiguration(Collection<String> services) {
+        Map<String, Map<String, Map<String, String>>> attributes = new HashMap<>();
+        Map<String, Map<String, String>> properties = new HashMap<>();
+
+        for (String service : services) {
+            Collection<String> serviceConfigTypes = getConfigurationTypes(service);
+            for (String type : serviceConfigTypes) {
+                Map<String, String> typeProps = getWithEmptyDefault(properties, type);
+                typeProps.putAll(getConfigurationProperties(service, type));
+
+                Map<String, Map<String, String>> stackTypeAttributes = getConfigurationAttributes(service, type);
+                if (!stackTypeAttributes.isEmpty()) {
+                    if (! attributes.containsKey(type)) {
+                        attributes.put(type, new HashMap<>());
+                    }
+                    Map<String, Map<String, String>> typeAttributes = attributes.get(type);
+                    for (Map.Entry<String, Map<String, String>> attribute : stackTypeAttributes.entrySet()) {
+                        String attributeName = attribute.getKey();
+                        Map<String, String> attributeProps = getWithEmptyDefault(typeAttributes, attributeName);
+                        attributeProps.putAll(attribute.getValue());
+                    }
+                }
+            }
+        }
+        return new Configuration(properties, attributes);
+    }
+
+    public Configuration getConfiguration() {
+        Map<String, Map<String, Map<String, String>>> stackAttributes = new HashMap<>();
+        Map<String, Map<String, String>> stackConfigs = new HashMap<>();
+
+        for (String service : getServices()) {
+            for (String type : getAllConfigurationTypes(service)) {
+                Map<String, String> typeProps = getWithEmptyDefault(stackConfigs, type);
+                typeProps.putAll(getConfigurationProperties(service, type));
+
+                Map<String, Map<String, String>> stackTypeAttributes = getConfigurationAttributes(service, type);
+                if (!stackTypeAttributes.isEmpty()) {
+                    if (! stackAttributes.containsKey(type)) {
+                        stackAttributes.put(type, new HashMap<>());
+                    }
+                    Map<String, Map<String, String>> typeAttrs = stackAttributes.get(type);
+                    for (Map.Entry<String, Map<String, String>> attribute : stackTypeAttributes.entrySet()) {
+                        String attributeName = attribute.getKey();
+                        Map<String, String> attributes = getWithEmptyDefault(typeAttrs, attributeName);
+                        attributes.putAll(attribute.getValue());
+                    }
+                }
+            }
+        }
+        return new Configuration(stackConfigs, stackAttributes);
+    }
+
+    static <OK, IK, IV> Map<IK, IV> getWithEmptyDefault(Map<OK, Map<IK, IV>> outerMap, OK outerKey) {
+        Map<IK, IV> innerMap = outerMap.get(outerKey);
+        if (null == innerMap) {
+            innerMap = new HashMap<>();
+            outerMap.put(outerKey, innerMap);
+        }
+        return innerMap;
+    }
+
+
+    /**
+     * Contains a configuration property's value and attributes.
+     */
+    public static class ConfigProperty {
+        private ValueAttributesInfo propertyValueAttributes = null;
+        private String name;
+        private String value;
+        private Map<String, String> attributes;
+        private Set<PropertyInfo.PropertyType> propertyTypes;
+        private String type;
+        private Set<PropertyDependencyInfo> dependsOnProperties =
+                Collections.emptySet();
+
+        public ConfigProperty(ReadOnlyConfigurationResponse config) {
+            this.name = config.getPropertyName();
+            this.value = config.getPropertyValue();
+            this.attributes = config.getPropertyAttributes();
+            this.propertyTypes = config.getPropertyType();
+            this.type = normalizeType(config.getType());
+            this.dependsOnProperties = config.getDependsOnProperties();
+            this.propertyValueAttributes = config.getPropertyValueAttributes();
+        }
+
+        public ConfigProperty(String type, String name, String value) {
+            this.type = type;
+            this.name = name;
+            this.value = value;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public String getValue() {
+            return value;
+        }
+
+        public void setValue(String value) {
+            this.value = value;
+        }
+
+        public String getType() {
+            return type;
+        }
+
+        public Set<PropertyInfo.PropertyType> getPropertyTypes() {
+            return propertyTypes;
+        }
+
+        public void setPropertyTypes(Set<PropertyInfo.PropertyType> propertyTypes) {
+            this.propertyTypes = propertyTypes;
+        }
+
+        public Map<String, String> getAttributes() {
+            return attributes;
+        }
+
+        public void setAttributes(Map<String, String> attributes) {
+            this.attributes = attributes;
+        }
+
+        Set<PropertyDependencyInfo> getDependsOnProperties() {
+            return this.dependsOnProperties;
+        }
+
+        private String normalizeType(String type) {
+            //strip .xml from type
+            if (type.endsWith(".xml")) {
+                type = type.substring(0, type.length() - 4);
+            }
+            return type;
+        }
+
+        public ValueAttributesInfo getPropertyValueAttributes() {
+            return propertyValueAttributes;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java
new file mode 100644
index 0000000..54e1e62
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.controller;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.orm.entities.StackEntity;
+import org.apache.ambari.server.state.AutoDeployInfo;
+import org.apache.ambari.server.state.DependencyInfo;
+import org.apache.ambari.server.state.StackId;
+
+public class StackV2Factory {
+
+  private AmbariManagementController controller;
+
+  public StackV2Factory(AmbariManagementController controller) {
+    this.controller = controller;
+  }
+
+  public StackV2 create(StackEntity stack) throws AmbariException {
+    return create(stack.getStackName(), stack.getStackVersion());
+  }
+
+  public StackV2 create(String stackId) throws AmbariException {
+    StackId id = new StackId(stackId);
+    return create(id.getStackName(), id.getStackVersion());
+  }
+
+  public StackV2 create(String name, String version) throws AmbariException {
+    Set<StackServiceResponse> stackServices = controller.getStackServices(
+      Collections.singleton(new StackServiceRequest(name, version, null)));
+
+    StackData stackData = new StackData(name, version);
+    for (StackServiceResponse stackService : stackServices) {
+      String serviceName = stackService.getServiceName();
+      parseComponents(stackData, serviceName);
+      parseExcludedConfigurations(stackData, stackService);
+      parseConfigurations(stackData, stackService);
+      registerConditionalDependencies(stackData);
+    }
+
+    //todo: already done for each service
+    parseStackConfigurations(stackData);
+
+    return new StackV2(name, version, stackData.repoVersion /* TODO */, stackData.serviceComponents, stackData.dependencies,
+      stackData.dbDependencyInfo, stackData.componentAutoDeployInfo, stackData.serviceConfigurations,
+      stackData.requiredServiceConfigurations, stackData.stackConfigurations, stackData.excludedConfigurationTypes);
+  }
+
+  /**
+   * Parse configurations for the specified service from the stack definition.
+   *
+   * @param stackService  service to parse the stack configuration for
+   *
+   * @throws AmbariException an exception occurred getting configurations from the stack definition
+   */
+  private void parseConfigurations(StackData stackData,
+                                   StackServiceResponse stackService) throws AmbariException {
+    String service = stackService.getServiceName();
+    Map<String, Map<String, StackV2.ConfigProperty>> mapServiceConfig = new HashMap<>();
+    Map<String, Map<String, StackV2.ConfigProperty>> mapRequiredServiceConfig = new HashMap<>();
+
+    stackData.serviceConfigurations.put(service, mapServiceConfig);
+    stackData.requiredServiceConfigurations.put(service, mapRequiredServiceConfig);
+
+    Set<StackConfigurationResponse> serviceConfigs = controller.getStackConfigurations(
+      Collections.singleton(new StackConfigurationRequest(stackData.stackName, stackData.stackVersion, service, null)));
+    Set<StackConfigurationResponse> stackLevelConfigs = controller.getStackLevelConfigurations(
+      Collections.singleton(new StackLevelConfigurationRequest(stackData.stackName, stackData.stackVersion, null)));
+    serviceConfigs.addAll(stackLevelConfigs);
+
+    // shouldn't have any required properties in stack level configuration
+    for (StackConfigurationResponse config : serviceConfigs) {
+      StackV2.ConfigProperty configProperty = new StackV2.ConfigProperty(config);
+      String type = configProperty.getType();
+
+      Map<String, StackV2.ConfigProperty> mapTypeConfig = StackV2.getWithEmptyDefault(mapServiceConfig, type);
+
+      mapTypeConfig.put(config.getPropertyName(), configProperty);
+      if (config.isRequired()) {
+        Map<String, StackV2.ConfigProperty> requiredTypeConfig =
+          StackV2.getWithEmptyDefault(mapRequiredServiceConfig, type);
+        requiredTypeConfig.put(config.getPropertyName(), configProperty);
+      }
+    }
+
+    // So far we added only config types that have properties defined
+    // in stack service definition. Since there might be config types
+    // with no properties defined we need to add those separately
+    Set<String> configTypes = stackService.getConfigTypes().keySet();
+    for (String configType: configTypes) {
+      if (!mapServiceConfig.containsKey(configType)) {
+        mapServiceConfig.put(configType, Collections.emptyMap());
+      }
+    }
+  }
+
+  private void parseStackConfigurations (StackData stackData) throws AmbariException {
+    Set<StackConfigurationResponse> stackLevelConfigs = controller.getStackLevelConfigurations(
+      Collections.singleton(new StackLevelConfigurationRequest(stackData.stackName, stackData.stackVersion, null)));
+
+    for (StackConfigurationResponse config : stackLevelConfigs) {
+      StackV2.ConfigProperty configProperty = new StackV2.ConfigProperty(config);
+      String type = configProperty.getType();
+
+      Map<String, StackV2.ConfigProperty> mapTypeConfig =
+        StackV2.getWithEmptyDefault(stackData.stackConfigurations, type);
+
+      mapTypeConfig.put(config.getPropertyName(),
+        configProperty);
+    }
+  }
+
+  /**
+   * Parse components for the specified service from the stack definition.
+   *
+   * @param service  service name
+   *
+   * @throws AmbariException an exception occurred getting components from the stack definition
+   */
+  private void parseComponents(StackData stackData, String service) throws AmbariException{
+    Collection<String> componentSet = new HashSet<>();
+
+    Set<StackServiceComponentResponse> components = controller.getStackComponents(
+      Collections.singleton(new StackServiceComponentRequest(stackData.stackName, stackData.stackVersion, service, null)));
+
+    // stack service components
+    for (StackServiceComponentResponse component : components) {
+      String componentName = component.getComponentName();
+      componentSet.add(componentName);
+      stackData.componentService.put(componentName, service);
+      String cardinality = component.getCardinality();
+      if (cardinality != null) {
+        stackData.cardinalityRequirements.put(componentName, cardinality);
+      }
+      AutoDeployInfo autoDeploy = component.getAutoDeploy();
+      if (autoDeploy != null) {
+        stackData.componentAutoDeployInfo.put(componentName, autoDeploy);
+      }
+
+      // populate component dependencies
+      //todo: remove usage of AmbariMetaInfo
+      Collection<DependencyInfo> componentDependencies = controller.getAmbariMetaInfo().getComponentDependencies(
+        stackData.stackName, stackData.stackVersion, service, componentName);
+
+      if (componentDependencies != null && ! componentDependencies.isEmpty()) {
+        stackData.dependencies.put(componentName, componentDependencies);
+      }
+      if (component.isMaster()) {
+        stackData.masterComponents.add(componentName);
+      }
+    }
+    stackData.serviceComponents.put(service, componentSet);
+  }
+
+
+  /**
+   * Obtain the excluded configuration types from the StackServiceResponse
+   *
+   * @param stackServiceResponse the response object associated with this stack service
+   */
+  private void parseExcludedConfigurations(StackData stackData, StackServiceResponse stackServiceResponse) {
+    stackData.excludedConfigurationTypes.put(stackServiceResponse.getServiceName(), stackServiceResponse.getExcludedConfigTypes());
+  }
+
+  /**
+   * Register conditional dependencies.
+   */
+  //todo: This information should be specified in the stack definition.
+  void registerConditionalDependencies(StackData stackData) {
+    stackData.dbDependencyInfo.put("MYSQL_SERVER", "global/hive_database");
+  }
+
+
+  private static final class StackData {
+    final String stackName;
+    final String stackVersion;
+
+    public StackData(String stackName, String stackVersion) {
+      this.stackName = stackName;
+      this.stackVersion = stackVersion;
+    }
+
+    String repoVersion;
+    final Map<String, String> componentService = new HashMap<>();
+    final Set<String> masterComponents = new HashSet<>();
+    final Map<String, AutoDeployInfo> componentAutoDeployInfo = new HashMap<>();
+    final Map<String, String> cardinalityRequirements = new HashMap<>();
+    final Map<String, Collection<DependencyInfo>> dependencies = new HashMap<>();
+    final Map<String, Collection<String>> serviceComponents = new HashMap<>();
+    final Map<String, Map<String, Map<String, StackV2.ConfigProperty>>> serviceConfigurations = new HashMap<>();
+    final Map<String, Map<String, Map<String, StackV2.ConfigProperty>>> requiredServiceConfigurations = new HashMap<>();
+    final Map<String, String> dbDependencyInfo = new HashMap<>();
+    final Map<String, Set<String>> excludedConfigurationTypes = new HashMap<>();
+    final Map<String, Map<String, StackV2.ConfigProperty>> stackConfigurations = new HashMap<>();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/BlueprintV2DAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/BlueprintV2DAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/BlueprintV2DAO.java
new file mode 100644
index 0000000..8a21dc1
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/BlueprintV2DAO.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.orm.dao;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.TypedQuery;
+
+import org.apache.ambari.server.orm.RequiresSession;
+import org.apache.ambari.server.orm.entities.BlueprintV2Entity;
+import org.apache.ambari.server.orm.entities.StackEntity;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+import com.google.inject.persist.Transactional;
+
+/**
+ * Blueprint V2 Data Access Object.
+ */
+@Singleton
+public class BlueprintV2DAO {
+
+  /**
+   * JPA entity manager
+   */
+  @Inject
+  Provider<EntityManager> entityManagerProvider;
+
+  @Inject
+  StackDAO stackDAO;
+
+  /**
+   * Find a blueprint with a given name.
+   *
+   * @param blueprint_name name of blueprint to find
+   *
+   * @return  a matching blueprint or null
+   */
+  @RequiresSession
+  public BlueprintV2Entity findByName(String blueprint_name) {
+    return entityManagerProvider.get().find(BlueprintV2Entity.class, blueprint_name);
+  }
+
+  /**
+   * Find all blueprints.
+   *
+   * @return all blueprints or an empty List
+   */
+  @RequiresSession
+  public List<BlueprintV2Entity> findAll() {
+    TypedQuery<BlueprintV2Entity> query = entityManagerProvider.get().
+      createNamedQuery("allBlueprintsv2", BlueprintV2Entity.class);
+    return query.getResultList();
+  }
+
+  /**
+   * Refresh the state of the instance from the database,
+   * overwriting changes made to the entity, if any.
+   *
+   * @param blueprintEntity  entity to refresh
+   */
+  @Transactional
+  public void refresh(BlueprintV2Entity blueprintEntity) {
+    ensureStackIdSet(blueprintEntity);
+    entityManagerProvider.get().refresh(blueprintEntity);
+  }
+
+  /**
+   * Make an instance managed and persistent.
+   *
+   * @param blueprintEntity  entity to persist
+   */
+  @Transactional
+  public void create(BlueprintV2Entity blueprintEntity) {
+    ensureStackIdSet(blueprintEntity);
+    entityManagerProvider.get().persist(blueprintEntity);
+  }
+
+  /**
+   * Merge the state of the given entity into the current persistence context.
+   *
+   * @param blueprintEntity  entity to merge
+   * @return the merged entity
+   */
+  @Transactional
+  public BlueprintV2Entity merge(BlueprintV2Entity blueprintEntity) {
+    ensureStackIdSet(blueprintEntity);
+    return entityManagerProvider.get().merge(blueprintEntity);
+  }
+
+  /**
+   * Remove the entity instance.
+   *
+   * @param blueprintEntity  entity to remove
+   */
+  @Transactional
+  public void remove(BlueprintV2Entity blueprintEntity) {
+    ensureStackIdSet(blueprintEntity);
+    entityManagerProvider.get().remove(merge(blueprintEntity));
+  }
+
+  /**
+   * Remove entity instance by primary key
+   * @param blueprint_name Primary key: blueprint name
+   */
+  @Transactional
+  public void removeByName(String blueprint_name) {
+    entityManagerProvider.get().remove(findByName(blueprint_name));
+  }
+
+  private void ensureStackIdSet(BlueprintV2Entity entity) {
+    StackEntity stack = entity.getStack();
+    if (stack != null && stack.getStackId() == null) {
+      entity.setStack(stackDAO.find(stack.getStackName(), stack.getStackVersion()));
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintEntity.java
index bab393a..8141f07 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintEntity.java
@@ -75,7 +75,6 @@ public class BlueprintEntity {
   @OneToMany(cascade = CascadeType.ALL, mappedBy = "blueprint")
   private Collection<BlueprintSettingEntity> settings;
 
-
   /**
    * Get the blueprint name.
    *

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintV2Entity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintV2Entity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintV2Entity.java
new file mode 100644
index 0000000..046c2e5
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintV2Entity.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.orm.entities;
+
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+
+import org.apache.ambari.server.state.SecurityType;
+
+/**
+ * Entity representing a Blueprint.
+ */
+@Table(name = "blueprintv2")
+@NamedQuery(name = "allBlueprintsv2",
+  query = "SELECT blueprint FROM BlueprintV2Entity blueprint")
+@Entity
+public class BlueprintV2Entity {
+
+  @Id
+  @Column(name = "blueprint_name", nullable = false, insertable = true,
+    updatable = false, unique = true, length = 100)
+  private String blueprintName;
+
+  @Basic
+  @Enumerated(value = EnumType.STRING)
+  @Column(name = "security_type", nullable = false, insertable = true, updatable = true)
+  private SecurityType securityType = SecurityType.NONE;
+
+  @Basic
+  @Column(name = "security_descriptor_reference", nullable = true, insertable = true, updatable = true)
+  private String securityDescriptorReference;
+
+  @Basic
+  @Column(name = "content", nullable = false, insertable = true, updatable = true)
+  private String content;
+
+  /**
+   * Unidirectional one-to-one association to {@link StackEntity}
+   */
+  @OneToOne
+  @JoinColumn(name = "stack_id", unique = false, nullable = false, insertable = true, updatable = false)
+  private StackEntity stack;
+
+  /**
+   * Gets the blueprint's stack.
+   *
+   * @return the stack.
+   */
+  public StackEntity getStack() {
+    return stack;
+  }
+
+  /**
+   * Sets the blueprint's stack.
+   *
+   * @param stack
+   *          the stack to set for the blueprint (not {@code null}).
+   */
+  public void setStack(StackEntity stack) {
+    this.stack = stack;
+  }
+
+
+  public String getBlueprintName() {
+    return blueprintName;
+  }
+
+  public void setBlueprintName(String blueprintName) {
+    this.blueprintName = blueprintName;
+  }
+
+  public SecurityType getSecurityType() {
+    return securityType;
+  }
+
+  public void setSecurityType(SecurityType securityType) {
+    this.securityType = securityType;
+  }
+
+  public String getSecurityDescriptorReference() {
+    return securityDescriptorReference;
+  }
+
+  public void setSecurityDescriptorReference(String securityDescriptorReference) {
+    this.securityDescriptorReference = securityDescriptorReference;
+  }
+
+  public String getContent() {
+    return content;
+  }
+
+  public void setContent(String content) {
+    this.content = content;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostGroupComponentEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostGroupComponentEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostGroupComponentEntity.java
index 6b75df7..186180b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostGroupComponentEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostGroupComponentEntity.java
@@ -44,9 +44,22 @@ public class HostGroupComponentEntity {
   private String blueprintName;
 
   @Id
-  @Column(name = "name", nullable = false, insertable = true, updatable = false)
+  @Column(name = "service_group", nullable = true, insertable = true, updatable = false)
+  private String serviceGroup;
+
+  @Id
+  @Column(name = "service_name", nullable = true, insertable = true, updatable = false)
+  private String serviceName;
+
+  @Id
+  @Column(name = "instance_name", nullable = true, insertable = true, updatable = false)
   private String name;
 
+
+  @Id
+  @Column(name = "type", nullable = false, insertable = true, updatable = false)
+  private String type;
+
   @Column(name = "provision_action", nullable = true, insertable = true, updatable = false)
   private String provisionAction;
 
@@ -130,6 +143,8 @@ public class HostGroupComponentEntity {
     this.blueprintName = blueprintName;
   }
 
+
+
   /**
    * Get the provision action associated with this
    *   component.

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StackEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StackEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StackEntity.java
index bee53b6..c479cdd 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StackEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StackEntity.java
@@ -60,11 +60,12 @@ public class StackEntity {
   @Column(name = "stack_version", length = 255, nullable = false)
   private String stackVersion;
 
+  @Column(name = "repo_version", length = 255, nullable = false)
+  private String repoVersion;
 
   @Column(name = "current_mpack_id")
   private Long currentMpackId;
 
-
   public Long getCurrentMpackId() {
     return currentMpackId;
   }
@@ -127,6 +128,14 @@ public class StackEntity {
     this.stackVersion = stackVersion;
   }
 
+  public String getRepoVersion() {
+    return repoVersion;
+  }
+
+  public void setRepoVersion(String repoVersion) {
+    this.repoVersion = repoVersion;
+  }
+
   /**
    *
    */

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
index 26dc41d..827fa39 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
@@ -19,102 +19,196 @@
 
 package org.apache.ambari.server.topology;
 
+import java.io.File;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
 import java.util.stream.Collectors;
 
-import org.apache.ambari.server.controller.internal.StackV2;
+import javax.annotation.Nonnull;
+
+import org.apache.ambari.server.controller.StackV2;
 import org.apache.ambari.server.orm.entities.BlueprintEntity;
+import org.apache.ambari.server.state.ConfigHelper;
+import org.apache.ambari.server.state.StackId;
+import org.apache.commons.lang.StringUtils;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.Version;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver;
+import com.fasterxml.jackson.databind.module.SimpleModule;
 
 /**
  * Blueprint implementation.
  */
 public class BlueprintImplV2 implements BlueprintV2 {
-  public BlueprintImplV2(BlueprintEntity e) {
+
+  private String name;
+  private SecurityConfiguration securityConfiguration;
+  private Collection<RepositoryVersion> repositoryVersions;
+  private Collection<ServiceGroup> serviceGroups;
+  private Collection<? extends HostGroupV2> hostGroups;
+  private Setting setting;
+
+  // Transient fields
+  @JsonIgnore
+  private Map<String, HostGroupV2> hostGroupMap = new HashMap<>();
+
+
+  @JsonIgnore
+  private Map<StackId, StackV2> stacks;
+
+  @JsonIgnore
+  private List<RepositorySetting> repoSettings;
+
+  public void setStacks(Map<StackId, StackV2> stacks) {
+    this.stacks = stacks;
+  }
+
+  @JsonProperty("Blueprints")
+  public void setBlueprints(Blueprints blueprints) {
+    this.name = blueprints.name;
+    this.securityConfiguration = blueprints.securityConfiguration;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public void setSecurityConfiguration(SecurityConfiguration securityConfiguration) {
+    this.securityConfiguration = securityConfiguration;
+  }
+
+  @JsonProperty("repository_versions")
+  public void setRepositoryVersions(Collection<RepositoryVersion> repositoryVersions) {
+    this.repositoryVersions = repositoryVersions;
+  }
+
+  @JsonProperty("service_groups")
+  public void setServiceGroups(Collection<ServiceGroup> serviceGroups) {
+    this.serviceGroups = serviceGroups;
+  }
+
+  @JsonProperty("host_groups")
+  public void setHostGroups(Collection<HostGroupV2Impl> hostGroups) {
+    this.hostGroups = hostGroups;
+    this.hostGroupMap = hostGroups.stream().collect(Collectors.toMap(
+      hg -> hg.getName(),
+      hg -> hg
+    ));
+  }
+
+  @JsonProperty("cluster-settings")
+  public void setClusterSettings(Map<String, Set<HashMap<String, String>>> properties) {
+    this.setting = new Setting(properties);
   }
 
   @Override
   public String getName() {
-    return null;
+    return name;
   }
 
   @Override
   public HostGroupV2 getHostGroup(String name) {
-    return null;
+    return hostGroupMap.get(name);
   }
 
   @Override
   public Map<String, HostGroupV2> getHostGroups() {
-    return null;
+    return hostGroupMap;
   }
 
   @Override
   public Collection<StackV2> getStacks() {
-    return null;
+    return stacks.values();
+  }
+
+  @Override
+  public Collection<String> getStackIds() {
+    return repositoryVersions.stream().map(rv -> rv.getStackId()).collect(Collectors.toList());
   }
 
   @Override
   public Collection<ServiceGroup> getServiceGroups() {
-    return null;
+    return serviceGroups;
   }
 
   @Override
-  public Collection<Service> getAllServices() {
-    return null;
+  @JsonIgnore
+  public Collection<ServiceId> getAllServices() {
+    return hostGroups.stream().flatMap(hg -> hg.getServices().stream()).collect(Collectors.toSet());
   }
 
   @Override
+  @JsonIgnore
   public Collection<String> getAllServiceTypes() {
     return null;
   }
 
   @Override
+  @JsonIgnore
   public Collection<Service> getServicesByType(String serviceType) {
-    return getAllServices().stream().filter(
-      service -> service.getType().equalsIgnoreCase(serviceType)).collect(Collectors.toList());
+    return null;
+//    getAllServices().stream().filter(
+//            service -> service.getType().equalsIgnoreCase(serviceType)).collect(Collectors.toList());
   }
 
   @Override
+  @JsonIgnore
   public Collection<Service> getServicesFromServiceGroup(ServiceGroup serviceGroup, String serviceType) {
     if (serviceType == null) {
       return serviceGroup.getServices();
     } else {
       return serviceGroup.getServices().stream().filter(
-        service -> service.getType().equalsIgnoreCase(serviceType)).collect(Collectors.toList());
+              service -> service.getType().equalsIgnoreCase(serviceType)).collect(Collectors.toList());
     }
   }
 
   @Override
+  @JsonIgnore
   public Collection<ComponentV2> getComponents(Service service) {
     return null;
   }
 
   @Override
+  @JsonIgnore
   public Collection<ComponentV2> getComponentsByType(Service service, String componentType) {
     return getComponents(service).stream().filter(
-      compnoent -> compnoent.getType().equalsIgnoreCase(componentType)).collect(Collectors.toList());
+            compnoent -> compnoent.getType().equalsIgnoreCase(componentType)).collect(Collectors.toList());
   }
 
   @Override
-  public Collection<HostGroupV2> getHostGroupsForService(Service service) {
-    return null;
+  @JsonIgnore
+  public Collection<ComponentV2> getComponents(ServiceId serviceId) {
+    return getHostGroupsForService(serviceId).stream().flatMap(hg -> hg.getComponents().stream()).collect(Collectors.toSet());
+  }
+
+  @Override
+  @JsonIgnore
+  public Collection<HostGroupV2> getHostGroupsForService(ServiceId serviceId) {
+    return hostGroups.stream().filter(hg -> !hg.getComponents(serviceId).isEmpty()).collect(Collectors.toList());
   }
 
   @Override
+  @JsonIgnore
   public Collection<HostGroupV2> getHostGroupsForComponent(ComponentV2 component) {
-    return null;
+    return hostGroups.stream().filter(hg -> hg.getComponents().contains(component)).collect(Collectors.toList());
   }
 
   @Override
-  @Deprecated
   public Configuration getConfiguration() {
     return null;
   }
 
   @Override
   public Setting getSetting() {
-    return null;
+    return this.setting;
   }
 
   @Override
@@ -122,43 +216,147 @@ public class BlueprintImplV2 implements BlueprintV2 {
     return null;
   }
 
+  @Nonnull
   @Override
-  public String getCredentialStoreEnabled(String serviceName) {
-    return null;
+  @JsonIgnore
+  public Collection<String> getAllServiceNames() {
+    return getAllServices().stream().map(s -> s.getName()).collect(Collectors.toList());
   }
 
+  @Nonnull
   @Override
-  public boolean shouldSkipFailure() {
-    return false;
+  public Collection<String> getComponentNames(ServiceId serviceId) {
+    return getComponents(serviceId).stream().map(c -> c.getName()).collect(Collectors.toList());
   }
 
   @Override
-  public SecurityConfiguration getSecurity() {
+  public String getRecoveryEnabled(String serviceName, String componentName) {
+    // If component name was specified in the list of "component_settings",
+    // determine if recovery_enabled is true or false and return it.
+    Optional<String> recoveryEnabled = getSettingValue(Setting.SETTING_NAME_COMPONENT_SETTINGS,
+      Setting.SETTING_NAME_RECOVERY_ENABLED,
+      Optional.of(componentName));
+    if (recoveryEnabled.isPresent()) {
+      return recoveryEnabled.get();
+    }
+
+    // If component name was specified in the list of "component_settings",
+    // determine if recovery_enabled is true or false and return it.
+    recoveryEnabled = getSettingValue(Setting.SETTING_NAME_SERVICE_SETTINGS,
+      Setting.SETTING_NAME_RECOVERY_ENABLED,
+      Optional.of(serviceName));
+    if (recoveryEnabled.isPresent()) {
+      return recoveryEnabled.get();
+    }
+
+    // If service name is not specified, look up the cluster setting.
+    recoveryEnabled = getSettingValue(Setting.SETTING_NAME_RECOVERY_SETTINGS,
+      Setting.SETTING_NAME_RECOVERY_ENABLED,
+      Optional.empty());
+    if (recoveryEnabled.isPresent()) {
+      return recoveryEnabled.get();
+    }
+
     return null;
   }
 
-  @Override
-  public void validateTopology() throws InvalidTopologyException {
+  private Optional<String> getSettingValue(String settingCategory, String settingName, Optional<String> nameFilter) {
+    if (this.setting != null) {
+      Set<HashMap<String, String>> settingValue = this.setting.getSettingValue(settingCategory);
+      for (Map<String, String> setting : settingValue) {
+        String name = setting.get(Setting.SETTING_NAME_NAME);
+        if (!nameFilter.isPresent() || StringUtils.equals(name, nameFilter.get())) {
+          String value = setting.get(settingName);
+          if (!StringUtils.isEmpty(value)) {
+            return Optional.of(value);
+          }
+        }
+      }
+    }
+    return Optional.empty();
+  }
 
+  @Override
+  public String getCredentialStoreEnabled(String serviceName) {
+    // Look up the service and return the credential_store_enabled value.
+    Optional<String> credentialStoreEnabled = getSettingValue(Setting.SETTING_NAME_SERVICE_SETTINGS,
+      Setting.SETTING_NAME_CREDENTIAL_STORE_ENABLED,
+      Optional.of(serviceName));
+    return  credentialStoreEnabled.isPresent() ? credentialStoreEnabled.get() : null;
   }
 
   @Override
-  public void validateRequiredProperties() throws InvalidTopologyException {
+  public boolean shouldSkipFailure() {
+    Optional<String> shouldSkipFailure = getSettingValue(Setting.SETTING_NAME_DEPLOYMENT_SETTINGS,
+      Setting.SETTING_NAME_SKIP_FAILURE,
+      Optional.empty());
+    return shouldSkipFailure.isPresent() ? shouldSkipFailure.get().equalsIgnoreCase("true") : false;
+  }
 
+  @Override
+  public SecurityConfiguration getSecurity() {
+    return this.securityConfiguration;
   }
 
+
   @Override
   public boolean isValidConfigType(String configType) {
-    return false;
+    if (ConfigHelper.CLUSTER_ENV.equals(configType) || "global".equals(configType)) {
+      return true;
+    }
+    final Set<String> serviceNames =
+      getAllServices().stream().map(s -> s.getName()).collect(Collectors.toSet());
+    return getStacks().stream().anyMatch(
+      stack -> {
+        String service = stack.getServiceForConfigType(configType);
+        return serviceNames.contains(service);
+      }
+    );
   }
 
   @Override
   public BlueprintEntity toEntity() {
-    return null;
+    throw new UnsupportedOperationException("This is not supported here and will be removed. Pls. use BlueprintConverter");
   }
 
   @Override
   public List<RepositorySetting> getRepositorySettings() {
-    return null;
+    return repoSettings;
+  }
+
+  /**
+   * Class to support Jackson data binding. Instances are used only temporarily during serialization
+   */
+  public class Blueprints {
+    @JsonProperty("blueprint_name")
+    public String name;
+    @JsonProperty("security")
+    public SecurityConfiguration securityConfiguration;
+
+    public Blueprints() { }
   }
+
+  public static void main(String[] args) throws Exception {
+    ObjectMapper mapper = new ObjectMapper();
+    SimpleModule module = new SimpleModule("CustomModel", Version.unknownVersion());
+    SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver();
+    resolver.addMapping(HostGroupV2.class, HostGroupV2Impl.class);
+    module.setAbstractTypes(resolver);
+    mapper.registerModule(module);
+    mapper.enable(SerializationFeature.INDENT_OUTPUT);
+    BlueprintImplV2 bp = mapper.readValue(new File("/Users/bsari/develop/blueprints/blueprintv2.json"), BlueprintImplV2.class);
+    String bpJson = mapper.writeValueAsString(bp);
+    System.out.println(bpJson);
+    System.out.println("\n\n====================================================================================\n\n");
+    Map<String, Object> map = mapper.readValue(new File("/Users/bsari/develop/blueprints/blueprintv2.json"), HashMap.class);
+    System.out.println(map);
+    System.out.println("\n\n====================================================================================\n\n");
+    String bpJson2 = mapper.writeValueAsString(map);
+    System.out.println(bpJson2);
+    System.out.println("\n\n====================================================================================\n\n");
+    BlueprintImplV2 bp2 = mapper.readValue(bpJson2, BlueprintImplV2.class);
+    System.out.println(bp2);
+  }
+
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java
index 10fa2fa..ea17e90 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java
@@ -22,7 +22,11 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.ambari.server.controller.internal.StackV2;
+
+import javax.annotation.Nonnull;
+
+import org.apache.ambari.server.controller.StackV2;
+
 import org.apache.ambari.server.orm.entities.BlueprintEntity;
 
 
@@ -60,6 +64,10 @@ public interface BlueprintV2 {
    */
   Collection<StackV2> getStacks();
 
+  /**
+  * @return associated stack ids
+  **/
+  public Collection<String> getStackIds();
 
   Collection<ServiceGroup> getServiceGroups();
 
@@ -68,7 +76,16 @@ public interface BlueprintV2 {
    *
    * @return collection of all represented service names
    */
-  Collection<Service> getAllServices();
+  Collection<ServiceId> getAllServices();
+
+  /**
+   * Get the names of all the services represented in the blueprint.
+   *
+   * @return collection of all represented service names
+   */
+  @Nonnull
+  Collection<String> getAllServiceNames();
+
 
 
   /**
@@ -96,11 +113,22 @@ public interface BlueprintV2 {
   /**
    * Get the components that are included in the blueprint for the specified service.
    *
-   * @param service  service name
+   * @param serviceId  serviceId
+   *
+   * @return collection of component names for the service.  Will not return null.
+   */
+  @Nonnull
+  Collection<String> getComponentNames(ServiceId serviceId);
+
+  /**
+   * Get the component names s that are included in the blueprint for the specified service.
+   *
+   * @param serviceId  serviceId
    *
    * @return collection of component names for the service.  Will not return null.
    */
-  Collection<ComponentV2> getComponents(Service service);
+  Collection<ComponentV2> getComponents(ServiceId serviceId);
+
 
   /**
    * Get components by type from a service.
@@ -114,12 +142,12 @@ public interface BlueprintV2 {
   /**
    * Get the host groups which contain components for the specified service.
    *
-   * @param service  service name
+   * @param serviceId  service Id
    *
    * @return collection of host groups containing components for the specified service;
    *         will not return null
    */
-  Collection<HostGroupV2> getHostGroupsForService(Service service);
+  Collection<HostGroupV2> getHostGroupsForService(ServiceId serviceId);
 
   /**
    * Get the host groups which contain the give component.
@@ -130,6 +158,7 @@ public interface BlueprintV2 {
    */
   Collection<HostGroupV2> getHostGroupsForComponent(ComponentV2 component);
 
+
   /**
    * Get the Blueprint cluster scoped configuration.
    * The blueprint cluster scoped configuration has the stack
@@ -141,6 +170,7 @@ public interface BlueprintV2 {
   @Deprecated
   Configuration getConfiguration();
 
+
   /**
    * Get the Blueprint cluster scoped setting.
    * The blueprint cluster scoped setting has the setting properties
@@ -178,19 +208,6 @@ public interface BlueprintV2 {
 
   SecurityConfiguration getSecurity();
 
-  /**
-   * Validate the blueprint topology.
-   *
-   * @throws InvalidTopologyException if the topology is invalid
-   */
-  void validateTopology() throws InvalidTopologyException;
-
-  /**
-   * Validate that the blueprint contains all of the required properties.
-   *
-   * @throws InvalidTopologyException if the blueprint doesn't contain all required properties
-   */
-  void validateRequiredProperties() throws InvalidTopologyException;
 
   /**
    *

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Factory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Factory.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Factory.java
new file mode 100644
index 0000000..a8c5b4c
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Factory.java
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distribut
+ * ed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.topology;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ObjectNotFoundException;
+import org.apache.ambari.server.StackAccessException;
+import org.apache.ambari.server.controller.StackV2;
+import org.apache.ambari.server.controller.StackV2Factory;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.orm.dao.BlueprintV2DAO;
+import org.apache.ambari.server.orm.dao.StackDAO;
+import org.apache.ambari.server.orm.entities.BlueprintV2Entity;
+import org.apache.ambari.server.orm.entities.StackEntity;
+import org.apache.ambari.server.stack.NoSuchStackException;
+import org.apache.ambari.server.state.StackId;
+
+import com.fasterxml.jackson.core.Version;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.google.inject.Inject;
+
+public class BlueprintV2Factory {
+  // Blueprints
+  protected static final String BLUEPRINT_NAME_PROPERTY_ID =
+    PropertyHelper.getPropertyId("Blueprints", "blueprint_name");
+  protected static final String STACK_NAME_PROPERTY_ID =
+    PropertyHelper.getPropertyId("Blueprints", "stack_name");
+  protected static final String STACK_VERSION_PROPERTY_ID =
+    PropertyHelper.getPropertyId("Blueprints", "stack_version");
+
+  // Host Groups
+  protected static final String HOST_GROUP_PROPERTY_ID = "host_groups";
+  protected static final String HOST_GROUP_NAME_PROPERTY_ID = "name";
+  protected static final String HOST_GROUP_CARDINALITY_PROPERTY_ID = "cardinality";
+
+  // Host Group Components
+  protected static final String COMPONENT_PROPERTY_ID ="components";
+  protected static final String COMPONENT_NAME_PROPERTY_ID ="name";
+  protected static final String COMPONENT_PROVISION_ACTION_PROPERTY_ID = "provision_action";
+
+  // Configurations
+  protected static final String CONFIGURATION_PROPERTY_ID = "configurations";
+  protected static final String PROPERTIES_PROPERTY_ID = "properties";
+  protected static final String PROPERTIES_ATTRIBUTES_PROPERTY_ID = "properties_attributes";
+
+  protected static final String SETTINGS_PROPERTY_ID = "settings";
+
+  private static BlueprintV2DAO blueprintDAO;
+  private static StackDAO stackDao;
+  private ConfigurationFactory configFactory = new ConfigurationFactory();
+
+  private final StackV2Factory stackFactory;
+
+  protected BlueprintV2Factory(StackV2Factory stackFactory) {
+    this.stackFactory = stackFactory;
+  }
+
+  public BlueprintV2 getBlueprint(String blueprintName) throws NoSuchStackException, NoSuchBlueprintException, IOException {
+    BlueprintV2Entity entity =
+      Optional.ofNullable(blueprintDAO.findByName(blueprintName)).orElseThrow(() -> new NoSuchBlueprintException(blueprintName));
+    return convertFromEntity(entity);
+  }
+
+  public BlueprintV2 convertFromEntity(BlueprintV2Entity blueprintEntity) throws NoSuchStackException, IOException {
+    BlueprintImplV2 blueprintV2 = createObjectMapper().readValue(blueprintEntity.getContent(), BlueprintImplV2.class);
+    Map<StackId, StackV2> stacks = new HashMap<>();
+    for (String stackIdString: blueprintV2.getStackIds()) {
+      StackId stackId = new StackId(stackIdString);
+      stacks.put(stackId, parseStack(stackDao.find(stackId)));
+    }
+    blueprintV2.setStacks(stacks);
+    return blueprintV2;
+  }
+
+
+  private StackV2 parseStack(StackEntity stackEntity) throws NoSuchStackException {
+    try {
+      return stackFactory.create(stackEntity.getStackName(), stackEntity.getStackVersion());
+    } catch (StackAccessException e) {
+      throw new NoSuchStackException(stackEntity.getStackName(), stackEntity.getStackVersion());
+    } catch (AmbariException e) {
+      //todo:
+      throw new RuntimeException("An error occurred parsing the stack information.", e);
+    }
+  }
+
+  /**
+   * Convert a map of properties to a blueprint entity.
+   *
+   * @param properties  property map
+   * @param securityConfiguration security related properties
+   * @return new blueprint entity
+   */
+  @SuppressWarnings("unchecked")
+  public BlueprintV2 createBlueprint(Map<String, Object> properties, SecurityConfiguration securityConfiguration) throws NoSuchStackException, IOException {
+    String name = String.valueOf(properties.get(BLUEPRINT_NAME_PROPERTY_ID));
+    // String.valueOf() will return "null" if value is null
+    if (name.equals("null") || name.isEmpty()) {
+      //todo: should throw a checked exception from here
+      throw new IllegalArgumentException("Blueprint name must be provided");
+    }
+    ObjectMapper om = createObjectMapper();
+    String json = om.writeValueAsString(properties);
+    BlueprintImplV2 blueprint = om.readValue(json, BlueprintImplV2.class);
+    Map<String, StackV2> stacks = new HashMap<>();
+    for (String stackId: blueprint.getStackIds()) {
+      stacks.put(stackId, stackFactory.create(stackId));
+    }
+    blueprint.setSecurityConfiguration(securityConfiguration);
+    return blueprint;
+  }
+
+  protected StackV2 createStack(Map<String, Object> properties) throws NoSuchStackException {
+    String stackName = String.valueOf(properties.get(STACK_NAME_PROPERTY_ID));
+    String stackVersion = String.valueOf(properties.get(STACK_VERSION_PROPERTY_ID));
+    try {
+      //todo: don't pass in controller
+      return stackFactory.create(stackName, stackVersion);
+    } catch (ObjectNotFoundException e) {
+      throw new NoSuchStackException(stackName, stackVersion);
+    } catch (AmbariException e) {
+      //todo:
+      throw new RuntimeException("An error occurred parsing the stack information.", e);
+    }
+  }
+
+  static ObjectMapper createObjectMapper() {
+    ObjectMapper mapper = new ObjectMapper();
+    SimpleModule module = new SimpleModule("CustomModel", Version.unknownVersion());
+    SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver();
+    resolver.addMapping(HostGroupV2.class, HostGroupV2Impl.class);
+    module.setAbstractTypes(resolver);
+    mapper.registerModule(module);
+    return mapper;
+  }
+
+  /**
+   * Static initialization.
+   *
+   * @param dao  blueprint data access object
+   */
+  @Inject
+  public static void init(BlueprintV2DAO dao) {
+    blueprintDAO = dao;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintValidatorV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintValidatorV2.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintValidatorV2.java
new file mode 100644
index 0000000..cfe083e
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintValidatorV2.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distribut
+ * ed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.topology;
+
+public interface BlueprintValidatorV2 {
+
+  /**
+   * Validate blueprint topology.
+   *
+   * @param blueprint The blueprint to validate
+   *
+   * @throws InvalidTopologyException if the topology is invalid
+   */
+  void validateTopology(BlueprintV2 blueprint) throws InvalidTopologyException;
+
+  /**
+   * Validate that required properties are provided.
+   * This doesn't include password properties.
+   *
+   * @param blueprint The blueprint to validate
+   *
+   * @throws InvalidTopologyException if required properties are not set in blueprint
+   */
+  void validateRequiredProperties(BlueprintV2 blueprint) throws InvalidTopologyException;
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java
index d7c08f4..43dda1b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java
@@ -18,37 +18,28 @@
 
 package org.apache.ambari.server.topology;
 
-
+import org.apache.ambari.server.controller.StackV2;
 import org.apache.ambari.server.controller.internal.ProvisionAction;
 
-public class ComponentV2 {
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
 
-  private final String type;
+public class ComponentV2 implements Configurable {
 
-  private final String name;
+  private String type;
 
-  private final Service service;
+  private String name;
 
-  private final ProvisionAction provisionAction;
+  private ServiceId serviceId = new ServiceId();
 
-  private final Configuration configuration;
+  private ProvisionAction provisionAction = ProvisionAction.INSTALL_AND_START;
 
-  public ComponentV2(String type, Service service) {
-    this(type, type, service, null, null);
-  }
+  private Configuration configuration;
 
+  private boolean masterComponent = false;
 
-  public ComponentV2(String type, String name, Service service) {
-    this(type, name, service, null, null);
-  }
+  public ComponentV2() { }
 
-  public ComponentV2(String type, String name, Service service, ProvisionAction provisionAction, Configuration configuration) {
-    this.type = type;
-    this.name = name;
-    this.service = service;
-    this.provisionAction = provisionAction;
-    this.configuration = configuration;
-  }
 
   /**
    * Gets the name of this component
@@ -59,8 +50,9 @@ public class ComponentV2 {
     return this.name;
   }
 
-  public String getType() {
-    return type;
+  /** @return the masterComponent flag */
+  public boolean isMasterComponent() {
+    return masterComponent;
   }
 
   /**
@@ -73,11 +65,59 @@ public class ComponentV2 {
     return this.provisionAction;
   }
 
-  public Service getService() {
-    return service;
+  public ServiceId getServiceId() {
+    return serviceId;
   }
 
   public Configuration getConfiguration() {
     return configuration;
   }
+
+  public String getType() {
+    return type;
+  }
+
+  public void setType(String type) {
+    this.type = type;
+    if (null == this.name) {
+      this.name = type;
+    }
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String getServiceGroup() {
+    return serviceId.getServiceGroup();
+  }
+
+  @JsonProperty("service_group")
+  public void setServiceGroup(String serviceGroup) {
+    serviceId.setServiceGroup(serviceGroup);
+  }
+
+  @JsonProperty("service_name")
+  public void setServiceName(String serviceName) {
+    serviceId.setName(serviceName);
+  }
+
+  public String getServiceName() {
+    return serviceId.getName();
+  }
+
+  @JsonProperty("provision_action")
+  public void setProvisionAction(ProvisionAction provisionAction) {
+    this.provisionAction = provisionAction;
+  }
+
+  public void setConfiguration(Configuration configuration) {
+    this.configuration = configuration;
+  }
+
+  @JsonIgnore
+  public void setMasterComponent(StackV2 stack) {
+    this.masterComponent = stack.isMasterComponent(this.type);
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/topology/Configurable.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/Configurable.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/Configurable.java
new file mode 100644
index 0000000..74308ab
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/Configurable.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.topology;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public interface Configurable {
+  void setConfiguration(Configuration configuration);
+
+  @JsonProperty("configurations")
+  default void setConfigs(Collection<Map<String, Map<String, Map<String, String>>>> configs) {
+    Map<String, Map<String, String>> allProps = configs.stream().collect(Collectors.toMap(
+      config -> config.keySet().iterator().next(),
+      config -> config.values().iterator().next().get("properties")
+    ));
+    setConfiguration(new Configuration(allProps, new HashMap<>()));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/topology/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/Configuration.java
index 28b62bc..28dbbaa 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/Configuration.java
@@ -24,6 +24,8 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
 /**
  * Configuration for a topology entity such as a blueprint, hostgroup or cluster.
  */
@@ -98,6 +100,7 @@ public class Configuration {
    *
    * @return complete map of merged properties keyed by config type
    */
+  @JsonIgnore
   public Map<String, Map<String, String>> getFullProperties() {
     return getFullProperties(Integer.MAX_VALUE);
   }
@@ -113,6 +116,7 @@ public class Configuration {
    *
    * @return map of merged properties keyed by config type
    */
+  @JsonIgnore
   public Map<String, Map<String, String>> getFullProperties(int depthLimit) {
     if (depthLimit == 0) {
       HashMap<String, Map<String, String>> propertiesCopy = new HashMap<>();
@@ -156,6 +160,7 @@ public class Configuration {
    *
    * @return complete map of merged attributes {configType -> {attributeName -> {propName, attributeValue}}}
    */
+  @JsonIgnore
   public Map<String, Map<String, Map<String, String>>> getFullAttributes() {
     Map<String, Map<String, Map<String, String>>> mergedAttributeMap = parentConfiguration == null ?
       new HashMap<>() :
@@ -314,6 +319,7 @@ public class Configuration {
    *
    * @return collection of all represented configuration types
    */
+  @JsonIgnore
   public Collection<String> getAllConfigTypes() {
     Collection<String> allTypes = new HashSet<>();
     for (String type : getFullProperties().keySet()) {
@@ -332,6 +338,7 @@ public class Configuration {
    *
    * @return the parent configuration or null if no parent is set
    */
+  @JsonIgnore
   public Configuration getParentConfiguration() {
     return parentConfiguration;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupImpl.java
index 9aeadd1..9d3a1b8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupImpl.java
@@ -255,8 +255,6 @@ public class HostGroupImpl implements HostGroup {
       } else {
         addComponent(componentEntity.getName());
       }
-
-
     }
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f82497d4/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java
index fd0f966..0922e74 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java
@@ -83,11 +83,11 @@ public interface HostGroupV2 {
   /**
    * Get the host group components which belong to the specified service.
    *
-   * @param service  service name
+   * @param serviceId  service id
    *
    * @return collection of component names for the specified service; will not return null
    */
-  Collection<ComponentV2> getComponents(Service service);
+  Collection<ComponentV2> getComponents(ServiceId serviceId);
 
   /**
    * Determine if the host group contains a master component.
@@ -97,11 +97,14 @@ public interface HostGroupV2 {
   boolean containsMasterComponent();
 
   /**
-   * Get all of the services associated with the host group components.
-   *
-   * @return collection of service names
+   * @return collection of service ids associated with the host group components.
+   */
+  Collection<ServiceId> getServices();
+
+  /**
+   * @return collection of service names associated with the host group components.
    */
-  Collection<Service> getServices();
+  Collection<String> getServiceNames();
 
   /**
    * Get the configuration associated with the host group.


[3/4] ambari git commit: Create first unit test for Blueprint v2 data model (benyoka)

Posted by ma...@apache.org.
Create first unit test for Blueprint v2 data model (benyoka)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/37b1e6e5
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/37b1e6e5
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/37b1e6e5

Branch: refs/heads/branch-feature-AMBARI-14714
Commit: 37b1e6e5132823d71b3cfe91ca4c270bd11a2013
Parents: f82497d
Author: Balazs Bence Sari <be...@apache.org>
Authored: Wed Oct 18 18:29:56 2017 +0200
Committer: Sandor Magyari <sm...@hortonworks.com>
Committed: Thu Oct 19 14:30:23 2017 +0200

----------------------------------------------------------------------
 .../ambari/server/topology/BlueprintImplV2.java |  29 ----
 .../validators/BlueprintImplV2Test.java         |  45 +++++-
 .../test/resources/blueprintv2/blueprintv2.json | 152 +++++++++++++++++++
 3 files changed, 196 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/37b1e6e5/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
index 827fa39..b2119e6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
@@ -19,7 +19,6 @@
 
 package org.apache.ambari.server.topology;
 
-import java.io.File;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
@@ -38,11 +37,6 @@ import org.apache.commons.lang.StringUtils;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.core.Version;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver;
-import com.fasterxml.jackson.databind.module.SimpleModule;
 
 /**
  * Blueprint implementation.
@@ -336,27 +330,4 @@ public class BlueprintImplV2 implements BlueprintV2 {
     public Blueprints() { }
   }
 
-  public static void main(String[] args) throws Exception {
-    ObjectMapper mapper = new ObjectMapper();
-    SimpleModule module = new SimpleModule("CustomModel", Version.unknownVersion());
-    SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver();
-    resolver.addMapping(HostGroupV2.class, HostGroupV2Impl.class);
-    module.setAbstractTypes(resolver);
-    mapper.registerModule(module);
-    mapper.enable(SerializationFeature.INDENT_OUTPUT);
-    BlueprintImplV2 bp = mapper.readValue(new File("/Users/bsari/develop/blueprints/blueprintv2.json"), BlueprintImplV2.class);
-    String bpJson = mapper.writeValueAsString(bp);
-    System.out.println(bpJson);
-    System.out.println("\n\n====================================================================================\n\n");
-    Map<String, Object> map = mapper.readValue(new File("/Users/bsari/develop/blueprints/blueprintv2.json"), HashMap.class);
-    System.out.println(map);
-    System.out.println("\n\n====================================================================================\n\n");
-    String bpJson2 = mapper.writeValueAsString(map);
-    System.out.println(bpJson2);
-    System.out.println("\n\n====================================================================================\n\n");
-    BlueprintImplV2 bp2 = mapper.readValue(bpJson2, BlueprintImplV2.class);
-    System.out.println(bp2);
-  }
-
-
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/37b1e6e5/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/BlueprintImplV2Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/BlueprintImplV2Test.java b/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/BlueprintImplV2Test.java
index dbe269a..5a676bc 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/BlueprintImplV2Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/BlueprintImplV2Test.java
@@ -1,9 +1,52 @@
 package org.apache.ambari.server.topology.validators;
 
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.topology.BlueprintImplV2;
+import org.apache.ambari.server.topology.HostGroupV2;
+import org.apache.ambari.server.topology.HostGroupV2Impl;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.fasterxml.jackson.core.Version;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
+
 public class BlueprintImplV2Test {
 
-  private static final String BLUEPRINT_LOCATION = "";
+  static String BLUEPRINT_V2_JSON;
 
+  @BeforeClass
+  public static void setUpClass() throws Exception {
+    BLUEPRINT_V2_JSON = Resources.toString(Resources.getResource("blueprintv2/blueprintv2.json"), Charsets.UTF_8);
+  }
 
+  @Test
+  public void testSerialization() throws Exception {
+    ObjectMapper mapper = new ObjectMapper();
+    SimpleModule module = new SimpleModule("CustomModel", Version.unknownVersion());
+    SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver();
+    resolver.addMapping(HostGroupV2.class, HostGroupV2Impl.class);
+    module.setAbstractTypes(resolver);
+    mapper.registerModule(module);
+    mapper.enable(SerializationFeature.INDENT_OUTPUT);
+    BlueprintImplV2 bp = mapper.readValue(BLUEPRINT_V2_JSON, BlueprintImplV2.class);
+    String bpJson = mapper.writeValueAsString(bp);
+    System.out.println(bpJson);
+    System.out.println("\n\n====================================================================================\n\n");
+    Map<String, Object> map = mapper.readValue(BLUEPRINT_V2_JSON, HashMap.class);
+    System.out.println(map);
+    System.out.println("\n\n====================================================================================\n\n");
+    String bpJson2 = mapper.writeValueAsString(map);
+    System.out.println(bpJson2);
+    System.out.println("\n\n====================================================================================\n\n");
+    BlueprintImplV2 bp2 = mapper.readValue(bpJson2, BlueprintImplV2.class);
+    System.out.println(bp2);
+  }
 
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/37b1e6e5/ambari-server/src/test/resources/blueprintv2/blueprintv2.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/resources/blueprintv2/blueprintv2.json b/ambari-server/src/test/resources/blueprintv2/blueprintv2.json
new file mode 100644
index 0000000..7884abf
--- /dev/null
+++ b/ambari-server/src/test/resources/blueprintv2/blueprintv2.json
@@ -0,0 +1,152 @@
+{
+  "Blueprints": {
+    "blueprint_name": "blueprint-def",
+    "security": {
+      "type": "NONE"
+    }
+  },
+  "cluster-settings": {
+    "deployment_settings": [
+      {"skip_failure":"true"}
+    ],
+    "recovery_settings":[
+      {"recovery_enabled":"true"}
+    ]
+  },
+  "repository_versions": [
+    {
+      "stack_id": "HDPCORE-3.0.0",
+      "repository_version": "3.0.0.0-1"
+    },
+    {
+      "stack_id": "ANALYTICS-1.0.0",
+      "repository_version": "1.0.0.0-12"
+    }
+  ],
+  "service_groups": [
+    {
+      "name": "Core SG",
+      "dependencies": [],
+      "services": [
+        {
+          "type": "ZOOKEEPER",
+          "name": "ZK1",
+          "stack_id": "HDPCORE-3.0.0",
+          "configurations": [
+            {
+              "zoo.cfg" : {
+                "properties" : {
+                  "dataDir" : "/zookeeper1"
+                }
+              }
+            }
+          ]
+        },
+        {
+          "type": "ZOOKEEPER",
+          "name": "ZK2",
+          "stack_id": "HDPCORE-3.0.0",
+          "configurations": [
+            {
+              "zoo.cfg" : {
+                "properties" : {
+                  "dataDir" : "/zookeeper2"
+                }
+              }
+            }
+          ]
+        },
+        {
+          "type": "HDFS",
+          "stack_id": "HDPCORE-3.0.0"
+        },
+        {
+          "type": "YARN",
+          "stack_id": "HDPCORE-3.0.0"
+        },
+        {
+          "type": "HBASE",
+          "stack_id": "HDPCORE-3.0.0"
+        }
+      ]
+    },
+    {
+      "name": "StreamSG",
+      "services": [
+        {
+          "type": "KAFKA",
+          "stack_id": "HDPCORE-3.0.0",
+          "dependencies": [
+            {
+              "service_group" : "CoreSG",
+              "service_name" : "ZK2"
+            }
+          ]
+        },
+        {
+          "type": "NIFI",
+          "stack_id": "HDPCORE-3.0.0"
+        }
+      ],
+      "dependencies": ["Core SG"]
+    }
+  ],
+  "host_groups": [
+    {
+      "cardinality": "1",
+      "name": "host_group_1",
+      "configurations": [],
+      "components": [
+        {
+          "type": "NAMENODE",
+          "service_name": "HDFS",
+          "service_group": "Core SG",
+          "configurations": [],
+          "provision_action": "INSTALL_AND_START"
+        },
+        {
+          "type": "ZOOKEEPER_SERVER",
+          "service_name": "ZK1",
+          "service_group": "Core SG",
+          "configurations": []
+        },
+        {
+          "type": "ZOOKEEPER_SERVER",
+          "service_name": "ZK2",
+          "service_group": "Core SG",
+          "configurations": []
+        },
+        {
+          "type": "RESOURCEMANAGER",
+          "service_name": "YARN",
+          "service_group": "Core SG",
+          "configurations": []
+        },
+        {
+          "type": "HBASE_MASTER",
+          "service_name": "HBASE",
+          "service_group": "Core SG",
+          "configurations": []
+        },
+        {
+          "type": "ZOOKEEPER_SERVER",
+          "service_name": "ZOOKEEPER",
+          "service_group": "Stream SG",
+          "configurations": []
+        },
+        {
+          "type": "KAFKA_MASTER",
+          "service_name": "KAFKA",
+          "service_group": "Stream SG",
+          "configurations": []
+        },
+        {
+          "type": "NIFI_MASTER",
+          "service_name": "NIFI",
+          "service_group": "Stream SG",
+          "configurations": []
+        }
+      ]
+    }
+  ]
+}