ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From magyari_san...@apache.org
Subject [1/4] ambari git commit: Blueprint V2 data model (benyoka)
Date Thu, 19 Oct 2017 12:35:36 GMT
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 = "";
+
+
+
+}


Mime
View raw message