ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject ambari git commit: AMBARI-13326. Service and Component info for repo_versions (ncole)
Date Wed, 07 Oct 2015 13:52:58 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-dev-patch-upgrade 15ac28364 -> 4e12263b9


AMBARI-13326. Service and Component info for repo_versions (ncole)


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

Branch: refs/heads/branch-dev-patch-upgrade
Commit: 4e12263b91743174386f348bb5b77b13694c714a
Parents: 15ac283
Author: Nate Cole <ncole@hortonworks.com>
Authored: Wed Oct 7 06:52:52 2015 -0700
Committer: Nate Cole <ncole@hortonworks.com>
Committed: Wed Oct 7 06:52:52 2015 -0700

----------------------------------------------------------------------
 .../RepositoryVersionResourceProvider.java      | 70 +++++++++++++++----
 .../server/orm/dao/RepositoryVersionDAO.java    | 28 ++++++--
 .../orm/entities/RepositoryVersionEntity.java   | 72 ++++++++++++++++++++
 .../ambari/server/state/RepositoryType.java     | 37 ++++++++++
 .../main/resources/Ambari-DDL-MySQL-CREATE.sql  | 10 +++
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql | 10 +++
 .../resources/Ambari-DDL-Postgres-CREATE.sql    | 10 +++
 .../Ambari-DDL-Postgres-EMBEDDED-CREATE.sql     | 11 +++
 .../resources/Ambari-DDL-SQLAnywhere-CREATE.sql | 10 +++
 .../resources/Ambari-DDL-SQLServer-CREATE.sql   | 10 +++
 .../RepositoryVersionResourceProviderTest.java  | 48 ++++++++++++-
 11 files changed, 297 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4e12263b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
index 06291dd..be78cb6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
@@ -19,13 +19,14 @@ package org.apache.ambari.server.controller.internal;
 
 import java.text.MessageFormat;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 
-import com.google.inject.persist.Transactional;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ObjectNotFoundException;
 import org.apache.ambari.server.api.resources.OperatingSystemResourceDefinition;
@@ -51,6 +52,7 @@ import org.apache.ambari.server.orm.entities.RepositoryEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.state.OperatingSystemInfo;
+import org.apache.ambari.server.state.RepositoryType;
 import org.apache.ambari.server.state.RepositoryVersionState;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.StackInfo;
@@ -59,8 +61,10 @@ import org.apache.commons.lang.ObjectUtils;
 import org.apache.commons.lang.StringUtils;
 
 import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
 import com.google.gson.Gson;
 import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
 
 /**
  * Resource provider for repository versions resources.
@@ -75,6 +79,8 @@ public class RepositoryVersionResourceProvider extends AbstractResourceProvider
   public static final String REPOSITORY_VERSION_REPOSITORY_VERSION_PROPERTY_ID = PropertyHelper.getPropertyId("RepositoryVersions",
"repository_version");
   public static final String REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID       = PropertyHelper.getPropertyId("RepositoryVersions",
"display_name");
   public static final String REPOSITORY_VERSION_UPGRADE_PACK_PROPERTY_ID       = PropertyHelper.getPropertyId("RepositoryVersions",
"upgrade_pack");
+  public static final String REPOSITORY_VERSION_TYPE_PROPERTY_ID               = "RepositoryVersions/type";
+  public static final String REPOSITORY_VERSION_COMPONENTS                     = "RepositoryVersions/components";
   public static final String SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID         = new OperatingSystemResourceDefinition().getPluralName();
   public static final String SUBRESOURCE_REPOSITORIES_PROPERTY_ID              = new RepositoryResourceDefinition().getPluralName();
 
@@ -86,17 +92,16 @@ public class RepositoryVersionResourceProvider extends AbstractResourceProvider
   };
 
   @SuppressWarnings("serial")
-  public static Set<String> propertyIds = new HashSet<String>() {
-    {
-      add(REPOSITORY_VERSION_ID_PROPERTY_ID);
-      add(REPOSITORY_VERSION_REPOSITORY_VERSION_PROPERTY_ID);
-      add(REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID);
-      add(REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID);
-      add(REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID);
-      add(REPOSITORY_VERSION_UPGRADE_PACK_PROPERTY_ID);
-      add(SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID);
-    }
-  };
+  public static Set<String> propertyIds = Sets.newHashSet(
+      REPOSITORY_VERSION_ID_PROPERTY_ID,
+      REPOSITORY_VERSION_REPOSITORY_VERSION_PROPERTY_ID,
+      REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID,
+      REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID,
+      REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID,
+      REPOSITORY_VERSION_UPGRADE_PACK_PROPERTY_ID,
+      SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID,
+      REPOSITORY_VERSION_TYPE_PROPERTY_ID,
+      REPOSITORY_VERSION_COMPONENTS);
 
   @SuppressWarnings("serial")
   public static Map<Type, String> keyPropertyIds = new HashMap<Type, String>()
{
@@ -217,6 +222,22 @@ public class RepositoryVersionResourceProvider extends AbstractResourceProvider
       setResourceProperty(resource, REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID, entity.getDisplayName(),
requestedIds);
       setResourceProperty(resource, REPOSITORY_VERSION_UPGRADE_PACK_PROPERTY_ID, entity.getUpgradePackage(),
requestedIds);
       setResourceProperty(resource, REPOSITORY_VERSION_REPOSITORY_VERSION_PROPERTY_ID, entity.getVersion(),
requestedIds);
+      setResourceProperty(resource, REPOSITORY_VERSION_TYPE_PROPERTY_ID, entity.getType(),
requestedIds);
+
+      if (isPropertyRequested(REPOSITORY_VERSION_COMPONENTS, requestedIds)) {
+        Map<String, List<String>> map = new HashMap<>();
+
+        // !!! sort via ordering first?
+
+        for (RepositoryVersionEntity.Component comp : entity.getComponents()) {
+          if (!map.containsKey(comp.getService())) {
+            map.put(comp.getService(), new ArrayList<String>());
+          }
+          map.get(comp.getService()).add(comp.getComponent());
+        }
+
+        setResourceProperty(resource, REPOSITORY_VERSION_COMPONENTS, map, requestedIds);
+      }
 
       resources.add(resource);
     }
@@ -449,6 +470,31 @@ public class RepositoryVersionResourceProvider extends AbstractResourceProvider
     }
     entity.setOperatingSystems(operatingSystemsJson);
     entity.setUpgradePackage(repositoryVersionHelper.getUpgradePackageName(stackName, stackVersion,
entity.getVersion()));
+
+
+    List<RepositoryVersionEntity.Component> components = null;
+    int i = 1;
+
+    for (Entry<String, Object> entry : properties.entrySet()) {
+      if (entry.getKey().startsWith(REPOSITORY_VERSION_COMPONENTS)) {
+        if (null == components) {
+          components = new ArrayList<>();
+        }
+
+        String serviceName = PropertyHelper.getPropertyName(entry.getKey());
+        Collection<String> componentNames = (Collection<String>) entry.getValue();
+
+        for (String componentName : componentNames) {
+          components.add(new RepositoryVersionEntity.Component(serviceName, componentName,
i++));
+        }
+      }
+    }
+
+    if (null != components) {
+      entity.setType(RepositoryType.PATCH);
+      entity.setComponents(components);
+    }
+
     return entity;
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/4e12263b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAO.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAO.java
index 4ac1314..1e2b187 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAO.java
@@ -18,21 +18,19 @@
 package org.apache.ambari.server.orm.dao;
 
 import java.text.MessageFormat;
-import java.util.Collections;
-import java.util.Comparator;
 import java.util.List;
 
 import javax.persistence.TypedQuery;
 
-import com.google.inject.persist.Transactional;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.orm.RequiresSession;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
+import org.apache.ambari.server.state.RepositoryType;
 import org.apache.ambari.server.state.StackId;
-import org.apache.ambari.server.utils.VersionUtils;
 
 import com.google.inject.Singleton;
+import com.google.inject.persist.Transactional;
 
 /**
  * DAO for repository versions.
@@ -134,10 +132,29 @@ public class RepositoryVersionDAO extends CrudDAO<RepositoryVersionEntity,
Long>
    * @return Returns the object created if successful, and throws an exception otherwise.
    * @throws AmbariException
    */
-  @Transactional
   public RepositoryVersionEntity create(StackEntity stackEntity,
       String version, String displayName, String upgradePack,
       String operatingSystems) throws AmbariException {
+      return create(stackEntity, version, displayName, upgradePack, operatingSystems,
+          RepositoryType.STANDARD);
+  }
+
+  /**
+   * Validates and creates an object.
+   * The version must be unique within this stack name (e.g., HDP, HDPWIN, BIGTOP).
+   * @param stackEntity Stack entity.
+   * @param version Stack version, e.g., 2.2 or 2.2.0.1-885
+   * @param displayName Unique display name
+   * @param upgradePack Optional upgrade pack, e.g, upgrade-2.2
+   * @param operatingSystems JSON structure of repository URLs for each OS
+   * @param type  the repository type
+   * @return Returns the object created if successful, and throws an exception otherwise.
+   * @throws AmbariException
+   */
+  @Transactional
+  public RepositoryVersionEntity create(StackEntity stackEntity,
+      String version, String displayName, String upgradePack,
+      String operatingSystems, RepositoryType type) throws AmbariException {
 
     if (stackEntity == null || version == null || version.isEmpty()
         || displayName == null || displayName.isEmpty()) {
@@ -165,6 +182,7 @@ public class RepositoryVersionDAO extends CrudDAO<RepositoryVersionEntity,
Long>
 
     RepositoryVersionEntity newEntity = new RepositoryVersionEntity(
         stackEntity, version, displayName, upgradePack, operatingSystems);
+    newEntity.setType(type);
     this.create(newEntity);
     return newEntity;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/4e12263b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
index dafd4b2..9713eff 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
@@ -17,13 +17,19 @@
  */
 package org.apache.ambari.server.orm.entities;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
 import javax.persistence.CascadeType;
+import javax.persistence.CollectionTable;
 import javax.persistence.Column;
+import javax.persistence.ElementCollection;
+import javax.persistence.Embeddable;
 import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
@@ -38,6 +44,7 @@ import javax.persistence.TableGenerator;
 import javax.persistence.UniqueConstraint;
 
 import org.apache.ambari.server.StaticallyInject;
+import org.apache.ambari.server.state.RepositoryType;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
 import org.apache.commons.lang.StringUtils;
@@ -97,12 +104,20 @@ public class RepositoryVersionEntity {
   @Column(name = "repositories")
   private String operatingSystems;
 
+  @Column(name = "repo_type", nullable = false, insertable = true, updatable = true)
+  @Enumerated(value = EnumType.STRING)
+  private RepositoryType type = RepositoryType.STANDARD;
+
   @OneToMany(cascade = CascadeType.REMOVE, mappedBy = "repositoryVersion")
   private Collection<ClusterVersionEntity> clusterVersionEntities;
 
   @OneToMany(cascade = CascadeType.REMOVE, mappedBy = "repositoryVersion")
   private Collection<HostVersionEntity> hostVersionEntities;
 
+  @ElementCollection(targetClass = Component.class)
+  @CollectionTable(name = "repo_version_component", joinColumns = @JoinColumn(name = "repo_version_id"))
+  private List<Component> components = new ArrayList<>();
+
   // ----- RepositoryVersionEntity -------------------------------------------------------
 
   public RepositoryVersionEntity() {
@@ -210,6 +225,20 @@ public class RepositoryVersionEntity {
     return new StackId(stack.getStackName(), stack.getStackVersion());
   }
 
+  /**
+   * @return the type
+   */
+  public RepositoryType getType() {
+    return type;
+  }
+
+  /**
+   * @param type the repo type
+   */
+  public void setType(RepositoryType type) {
+    this.type = type;
+  }
+
   @Override
   public boolean equals(Object o) {
     if (this == o) {
@@ -280,4 +309,47 @@ public class RepositoryVersionEntity {
     }
     return false;
   }
+
+
+  /**
+   * Used to identify the components associated with a repository.
+   */
+  @Embeddable
+  public static class Component {
+    private String service;
+    private String component;
+    private int component_order;
+
+    public Component() {
+    }
+
+    public Component(String serviceName, String componentName, int order) {
+      service = serviceName;
+      component = componentName;
+      component_order = order;
+    }
+
+    public String getService() {
+      return service;
+    }
+
+    public String getComponent() {
+      return component;
+    }
+
+  }
+
+
+  /**
+   * @param components
+   */
+  public void setComponents(List<Component> components) {
+    // TODO Auto-generated method stub
+    this.components = components;
+  }
+
+  public List<Component> getComponents() {
+    return components;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/4e12263b/ambari-server/src/main/java/org/apache/ambari/server/state/RepositoryType.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/RepositoryType.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/RepositoryType.java
new file mode 100644
index 0000000..4cc79e5
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/RepositoryType.java
@@ -0,0 +1,37 @@
+/**
+ * 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.state;
+
+/**
+ * Identifies the type of repository
+ */
+public enum RepositoryType {
+
+  /**
+   * Repository should be considered to have all components for a cluster
+   * deployment
+   */
+  STANDARD,
+
+  /**
+   * Repository may have only minimum components and is used for patching
+   * purposes
+   */
+  PATCH
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/4e12263b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index 1511385..2b8958c 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -543,9 +543,18 @@ CREATE TABLE repo_version (
   display_name VARCHAR(128) NOT NULL,
   upgrade_package VARCHAR(255) NOT NULL,
   repositories LONGTEXT NOT NULL,
+  repo_type VARCHAR(255) DEFAULT 'STANDARD' NOT NULL,
   PRIMARY KEY(repo_version_id)
 );
 
+CREATE TABLE repo_version_component (
+  repo_version_id BIGINT NOT NULL,
+  service VARCHAR(255) NOT NULL,
+  component VARCHAR(255) NOT NULL,
+  component_order BIGINT NOT NULL,
+  PRIMARY KEY(repo_version_id, service, component)
+);
+
 CREATE TABLE widget (
   id BIGINT NOT NULL,
   widget_name VARCHAR(255) NOT NULL,
@@ -744,6 +753,7 @@ ALTER TABLE servicecomponentdesiredstate ADD CONSTRAINT FK_scds_desired_stack_id
 ALTER TABLE servicedesiredstate ADD CONSTRAINT FK_sds_desired_stack_id FOREIGN KEY (desired_stack_id)
REFERENCES stack(stack_id);
 ALTER TABLE blueprint ADD CONSTRAINT FK_blueprint_stack_id FOREIGN KEY (stack_id) REFERENCES
stack(stack_id);
 ALTER TABLE repo_version ADD CONSTRAINT FK_repoversion_stack_id FOREIGN KEY (stack_id) REFERENCES
stack(stack_id);
+ALTER TABLE repo_version_component ADD CONSTRAINT FK_repo_version_id FOREIGN KEY (repo_version_id)
REFERENCES repo_version(repo_version_id);
 
 -- Kerberos
 CREATE TABLE kerberos_principal (

http://git-wip-us.apache.org/repos/asf/ambari/blob/4e12263b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
index a3c1625..74f8675 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -532,9 +532,18 @@ CREATE TABLE repo_version (
   display_name VARCHAR2(128) NOT NULL,
   upgrade_package VARCHAR2(255) NOT NULL,
   repositories CLOB NOT NULL,
+  repo_type VARCHAR2(255) DEFAULT 'STANDARD' NOT NULL,
   PRIMARY KEY(repo_version_id)
 );
 
+CREATE TABLE repo_version_component (
+  repo_version_id NUMBER(19) NOT NULL,
+  service VARCHAR2(255) NOT NULL,
+  component VARCHAR2(255) NOT NULL,
+  component_order NUMBER(19) NOT NULL,
+  PRIMARY KEY(repo_version_id, service, component)
+);
+
 CREATE TABLE widget (
   id NUMBER(19) NOT NULL,
   widget_name VARCHAR2(255) NOT NULL,
@@ -733,6 +742,7 @@ ALTER TABLE servicecomponentdesiredstate ADD CONSTRAINT FK_scds_desired_stack_id
 ALTER TABLE servicedesiredstate ADD CONSTRAINT FK_sds_desired_stack_id FOREIGN KEY (desired_stack_id)
REFERENCES stack(stack_id);
 ALTER TABLE blueprint ADD CONSTRAINT FK_blueprint_stack_id FOREIGN KEY (stack_id) REFERENCES
stack(stack_id);
 ALTER TABLE repo_version ADD CONSTRAINT FK_repoversion_stack_id FOREIGN KEY (stack_id) REFERENCES
stack(stack_id);
+ALTER TABLE repo_version_component ADD CONSTRAINT FK_repo_version_id FOREIGN KEY (repo_version_id)
REFERENCES repo_version(repo_version_id);
 
 -- Kerberos
 CREATE TABLE kerberos_principal (

http://git-wip-us.apache.org/repos/asf/ambari/blob/4e12263b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
index 2636eef..7f03e6a 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -537,9 +537,18 @@ CREATE TABLE repo_version (
   display_name VARCHAR(128) NOT NULL,
   upgrade_package VARCHAR(255) NOT NULL,
   repositories TEXT NOT NULL,
+  repo_type VARCHAR(255) DEFAULT 'STANDARD' NOT NULL,
   PRIMARY KEY(repo_version_id)
 );
 
+CREATE TABLE repo_version_component (
+  repo_version_id BIGINT NOT NULL,
+  service VARCHAR(255) NOT NULL,
+  component VARCHAR(255) NOT NULL,
+  component_order BIGINT NOT NULL,
+  PRIMARY KEY (repo_version_id, service, component)
+);
+
 CREATE TABLE widget (
   id BIGINT NOT NULL,
   widget_name VARCHAR(255) NOT NULL,
@@ -735,6 +744,7 @@ ALTER TABLE servicecomponentdesiredstate ADD CONSTRAINT FK_scds_desired_stack_id
 ALTER TABLE servicedesiredstate ADD CONSTRAINT FK_sds_desired_stack_id FOREIGN KEY (desired_stack_id)
REFERENCES stack(stack_id);
 ALTER TABLE blueprint ADD CONSTRAINT FK_blueprint_stack_id FOREIGN KEY (stack_id) REFERENCES
stack(stack_id);
 ALTER TABLE repo_version ADD CONSTRAINT FK_repoversion_stack_id FOREIGN KEY (stack_id) REFERENCES
stack(stack_id);
+ALTER TABLE repo_version_component ADD CONSTRAINT FK_repo_version_id FOREIGN KEY (repo_version_id)
REFERENCES repo_version(repo_version_id);
 
 -- Kerberos
 CREATE TABLE kerberos_principal (

http://git-wip-us.apache.org/repos/asf/ambari/blob/4e12263b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
index d515fa6..77f9563 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
@@ -604,10 +604,20 @@ CREATE TABLE ambari.repo_version (
   display_name VARCHAR(128) NOT NULL,
   upgrade_package VARCHAR(255) NOT NULL,
   repositories TEXT NOT NULL,
+  repo_type VARCHAR(255) DEFAULT 'STANDARD' NOT NULL,
   PRIMARY KEY(repo_version_id)
 );
 GRANT ALL PRIVILEGES ON TABLE ambari.repo_version TO :username;
 
+CREATE TABLE ambari.repo_version_component (
+  repo_version_id BIGINT NOT NULL,
+  service VARCHAR(255) NOT NULL,
+  component VARCHAR(255) NOT NULL,
+  component_order BIGINT NOT NULL,
+  PRIMARY KEY (repo_version_id, service, component)
+);
+GRANT ALL PRIVILEGES ON TABLE ambari.repo_version_component TO :username;
+
 CREATE TABLE ambari.artifact (
   artifact_name VARCHAR(255) NOT NULL,
   artifact_data TEXT NOT NULL,
@@ -814,6 +824,7 @@ ALTER TABLE ambari.servicecomponentdesiredstate ADD CONSTRAINT FK_scds_desired_s
 ALTER TABLE ambari.servicedesiredstate ADD CONSTRAINT FK_sds_desired_stack_id FOREIGN KEY
(desired_stack_id) REFERENCES ambari.stack(stack_id);
 ALTER TABLE ambari.blueprint ADD CONSTRAINT FK_blueprint_stack_id FOREIGN KEY (stack_id)
REFERENCES ambari.stack(stack_id);
 ALTER TABLE ambari.repo_version ADD CONSTRAINT FK_repoversion_stack_id FOREIGN KEY (stack_id)
REFERENCES ambari.stack(stack_id);
+ALTER TABLE ambari.repo_version_component ADD CONSTRAINT FK_repo_version_id FOREIGN KEY (repo_version_id)
REFERENCES ambari.repo_version(repo_version_id);
 
 -- Kerberos
 CREATE TABLE ambari.kerberos_principal (

http://git-wip-us.apache.org/repos/asf/ambari/blob/4e12263b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
index 807ccd5..7d62546 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
@@ -532,9 +532,18 @@ CREATE TABLE repo_version (
   display_name VARCHAR(128) NOT NULL,
   upgrade_package VARCHAR(255) NOT NULL,
   repositories TEXT NOT NULL,
+  repo_type VARCHAR(255) DEFAULT 'STANDARD' NOT NULL,
   PRIMARY KEY(repo_version_id)
 );
 
+CREATE TABLE repo_version_component (
+  repo_version_id NUMERIC(19) NOT NULL,
+  service VARCHAR(255) NOT NULL,
+  component VARCHAR(255) NOT NULL,
+  component_order NUMERIC(19) NOT NULL,
+  PRIMARY KEY(repo_version_id, service, component)
+);
+
 CREATE TABLE widget (
   id NUMERIC(19) NOT NULL,
   widget_name VARCHAR(255) NOT NULL,
@@ -733,6 +742,7 @@ ALTER TABLE servicecomponentdesiredstate ADD CONSTRAINT FK_scds_desired_stack_id
 ALTER TABLE servicedesiredstate ADD CONSTRAINT FK_sds_desired_stack_id FOREIGN KEY (desired_stack_id)
REFERENCES stack(stack_id);
 ALTER TABLE blueprint ADD CONSTRAINT FK_blueprint_stack_id FOREIGN KEY (stack_id) REFERENCES
stack(stack_id);
 ALTER TABLE repo_version ADD CONSTRAINT FK_repoversion_stack_id FOREIGN KEY (stack_id) REFERENCES
stack(stack_id);
+ALTER TABLE repo_version_component ADD CONSTRAINT FK_repo_version_id FOREIGN KEY (repo_version_id)
REFERENCES repo_version(repo_version_id);
 
 -- Kerberos
 CREATE TABLE kerberos_principal (

http://git-wip-us.apache.org/repos/asf/ambari/blob/4e12263b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
index 1f95f0f..0d68790 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
@@ -643,9 +643,18 @@ CREATE TABLE repo_version (
   display_name VARCHAR(128) NOT NULL,
   upgrade_package VARCHAR(255) NOT NULL,
   repositories VARCHAR(MAX) NOT NULL,
+  repo_type VARCHAR(255) DEFAULT 'STANDARD' NOT NULL,
   PRIMARY KEY CLUSTERED (repo_version_id)
   );
 
+CREATE TABLE repo_version_component (
+  repo_version_id BIGINT NOT NULL,
+  service VARCHAR(255) NOT NULL,
+  component VARCHAR(255) NOT NULL,
+  component_order BIGINT NOT NULL,
+  PRIMARY KEY CLUSTERED (repo_version_id, service, component)
+  );
+
 CREATE TABLE artifact (
   artifact_name VARCHAR(255) NOT NULL,
   artifact_data TEXT NOT NULL,
@@ -850,6 +859,7 @@ ALTER TABLE servicecomponentdesiredstate ADD CONSTRAINT FK_scds_desired_stack_id
 ALTER TABLE servicedesiredstate ADD CONSTRAINT FK_sds_desired_stack_id FOREIGN KEY (desired_stack_id)
REFERENCES stack(stack_id);
 ALTER TABLE blueprint ADD CONSTRAINT FK_blueprint_stack_id FOREIGN KEY (stack_id) REFERENCES
stack(stack_id);
 ALTER TABLE repo_version ADD CONSTRAINT FK_repoversion_stack_id FOREIGN KEY (stack_id) REFERENCES
stack(stack_id);
+ALTER TABLE repo_version_component ADD CONSTRAINT FK_repo_version_id FOREIGN KEY (repo_version_id)
REFERENCES repo_version(repo_version_id);
 
 -- Kerberos
 CREATE TABLE kerberos_principal (

http://git-wip-us.apache.org/repos/asf/ambari/blob/4e12263b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
index 41d0175..88c2bf6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
@@ -19,6 +19,8 @@
 package org.apache.ambari.server.controller.internal;
 
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
@@ -27,13 +29,12 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import junit.framework.Assert;
-
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.controller.ResourceProviderFactory;
 import org.apache.ambari.server.controller.predicate.AndPredicate;
 import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.spi.ResourceProvider;
 import org.apache.ambari.server.controller.utilities.PredicateBuilder;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
@@ -49,6 +50,7 @@ import org.apache.ambari.server.orm.entities.RepositoryEntity;
 import org.apache.ambari.server.orm.entities.OperatingSystemEntity;
 import org.apache.ambari.server.state.OperatingSystemInfo;
 import org.apache.ambari.server.state.RepositoryInfo;
+import org.apache.ambari.server.state.RepositoryType;
 import org.apache.ambari.server.state.RepositoryVersionState;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.StackInfo;
@@ -67,6 +69,8 @@ import com.google.inject.Guice;
 import com.google.inject.Injector;
 import com.google.inject.persist.PersistService;
 
+import junit.framework.Assert;
+
 /**
  * RepositoryVersionResourceProvider tests.
  */
@@ -441,6 +445,46 @@ public class RepositoryVersionResourceProviderTest {
     Assert.assertEquals(false, RepositoryVersionEntity.isVersionInStack(sid2, "2.1"));
   }
 
+  @Test
+  public void testCreateResourcesWithComponents() throws Exception {
+    final ResourceProvider provider = injector.getInstance(ResourceProviderFactory.class).getRepositoryVersionResourceProvider();
+
+    final Set<Map<String, Object>> propertySet = new LinkedHashSet<Map<String,
Object>>();
+    final Map<String, Object> properties = new LinkedHashMap<String, Object>();
+    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID,
"name");
+    properties.put(RepositoryVersionResourceProvider.SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID,
new Gson().fromJson("[{\"OperatingSystems/os_type\":\"redhat6\",\"repositories\":[{\"Repositories/repo_id\":\"1\",\"Repositories/repo_name\":\"1\",\"Repositories/base_url\":\"1\"}]}]",
Object.class));
+    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID,
"HDP");
+    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_UPGRADE_PACK_PROPERTY_ID,
"pack1");
+    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID,
"1.1");
+    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_REPOSITORY_VERSION_PROPERTY_ID,
"1.1.1.1");
+    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_COMPONENTS + "/HDFS",
Arrays.asList("NAMENODE", "DATANODE"));
+    propertySet.add(properties);
+
+    final Predicate predicateStackName = new PredicateBuilder().property(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID).equals("HDP").toPredicate();
+    final Predicate predicateStackVersion = new PredicateBuilder().property(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID).equals("1.1").toPredicate();
+    final Request getRequest = PropertyHelper.getReadRequest("RepositoryVersions");
+    Assert.assertEquals(0, provider.getResources(getRequest, new AndPredicate(predicateStackName,
predicateStackVersion)).size());
+
+    final Request createRequest = PropertyHelper.getCreateRequest(propertySet, null);
+    provider.createResources(createRequest);
+
+    Set<Resource> resources = provider.getResources(getRequest, new AndPredicate(predicateStackName,
predicateStackVersion));
+
+    Assert.assertEquals(1, resources.size());
+
+    Resource r = resources.iterator().next();
+
+    Assert.assertEquals(RepositoryType.PATCH,
+        r.getPropertyValue(RepositoryVersionResourceProvider.REPOSITORY_VERSION_TYPE_PROPERTY_ID));
+
+    Object o = r.getPropertyValue(RepositoryVersionResourceProvider.REPOSITORY_VERSION_COMPONENTS
+ "/HDFS");
+
+    Assert.assertTrue(Collection.class.isInstance(o));
+    Assert.assertTrue(((Collection) o).contains("NAMENODE"));
+    Assert.assertTrue(((Collection) o).contains("DATANODE"));
+  }
+
+
   @After
   public void after() {
     injector.getInstance(PersistService.class).stop();


Mime
View raw message