ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmitriu...@apache.org
Subject ambari git commit: AMBARI-8716. RU: The default repo version / stack version do not have any OS / base repo URL information (dlysnichenko)
Date Fri, 19 Dec 2014 11:04:49 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk f13beb866 -> 91700e782


AMBARI-8716. RU: The default repo version / stack version do not have any OS / base repo URL
information (dlysnichenko)


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

Branch: refs/heads/trunk
Commit: 91700e7828e1564809c291a3cd4ad16308c8a6f6
Parents: f13beb8
Author: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Authored: Fri Dec 19 13:02:44 2014 +0200
Committer: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Committed: Fri Dec 19 13:02:44 2014 +0200

----------------------------------------------------------------------
 .../AmbariManagementControllerImpl.java         |  9 +++--
 .../RepositoryVersionResourceProvider.java      | 38 ++++++++++++++++++--
 .../orm/entities/RepositoryVersionEntity.java   |  9 ++++-
 .../server/upgrade/UpgradeCatalog200.java       |  2 +-
 .../Ambari-DDL-Postgres-EMBEDDED-CREATE.sql     |  2 +-
 .../RepositoryVersionResourceProviderTest.java  | 17 +++++++++
 6 files changed, 69 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/91700e78/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index a907276..19ee6d9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -75,6 +75,7 @@ import org.apache.ambari.server.actionmanager.StageFactory;
 import org.apache.ambari.server.agent.ExecutionCommand;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.controller.internal.RepositoryVersionResourceProvider;
 import org.apache.ambari.server.controller.internal.RequestOperationLevel;
 import org.apache.ambari.server.controller.internal.RequestStageContainer;
 import org.apache.ambari.server.controller.internal.URLStreamProvider;
@@ -144,6 +145,7 @@ import com.google.inject.Inject;
 import com.google.inject.Injector;
 import com.google.inject.Singleton;
 import com.google.inject.persist.Transactional;
+
 import org.apache.ambari.server.controller.internal.RequestResourceFilter;
 import org.apache.ambari.server.state.HostComponentAdminState;
 
@@ -361,13 +363,14 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
       StackId newStackId = new StackId(request.getStackVersion());
       c.setDesiredStackVersion(newStackId);
       clusters.setCurrentStackVersion(request.getClusterName(), newStackId);
-      
+
       try {
         // Because Ambari may eventually support multiple clusters, it may be possible that
a previously installed cluster
         // already inserted the Repository Version for this stack and version.
-        RepositoryVersionEntity existingRepositoryVersion = repositoryVersionDAO.findByStackAndVersion(newStackId.getStackId(),
 newStackId.getStackVersion());
+        RepositoryVersionEntity existingRepositoryVersion = repositoryVersionDAO.findByStackAndVersion(newStackId.getStackId(),
newStackId.getStackVersion());
         if (existingRepositoryVersion == null) {
-          repositoryVersionDAO.create(newStackId.getStackId(), newStackId.getStackVersion(),
newStackId.getStackId(), "", "");
+          repositoryVersionDAO.create(newStackId.getStackId(), newStackId.getStackVersion(),
newStackId.getStackId(),
+              "", RepositoryVersionResourceProvider.serializeOperatingSystems(stackInfo.getRepositories()));
         }
         c.createClusterVersion(stackId.getStackId(), stackId.getStackVersion(), getAuthName(),
RepositoryVersionState.CURRENT);
       } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/91700e78/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 4cf844d..58817a8 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
@@ -18,6 +18,7 @@
 package org.apache.ambari.server.controller.internal;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -28,7 +29,6 @@ import java.util.regex.Pattern;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ObjectNotFoundException;
-import org.apache.ambari.server.api.resources.OperatingSystemResourceDefinition;
 import org.apache.ambari.server.api.resources.RepositoryResourceDefinition;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
@@ -49,14 +49,18 @@ import org.apache.ambari.server.orm.entities.OperatingSystemEntity;
 import org.apache.ambari.server.orm.entities.RepositoryEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.OperatingSystemInfo;
+import org.apache.ambari.server.state.RepositoryInfo;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.StackInfo;
 import org.apache.ambari.server.state.stack.UpgradePack;
 import org.apache.commons.lang.StringUtils;
 
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
 import com.google.gson.Gson;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
 import com.google.inject.Inject;
 
@@ -73,7 +77,7 @@ 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 SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID         = "operating_systems";
//TODO should be replaced with resource definition when we get rid of Stacks2Service 
+  public static final String SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID         = "operating_systems";
//TODO should be replaced with resource definition when we get rid of Stacks2Service
   public static final String SUBRESOURCE_REPOSITORIES_PROPERTY_ID              = new RepositoryResourceDefinition().getPluralName();
 
   @SuppressWarnings("serial")
@@ -452,6 +456,36 @@ public class RepositoryVersionResourceProvider extends AbstractResourceProvider
     return operatingSystems;
   }
 
+  /**
+   * Serializes repository info to json for storing to DB.
+   * Produces json like:
+   *
+   * @param repositories list of repository infos
+   * @return serialized list of operating systems
+   */
+  public static String serializeOperatingSystems(List<RepositoryInfo> repositories)
{
+    final JsonArray rootJson = new JsonArray();
+    final Multimap<String, RepositoryInfo> operatingSystems = ArrayListMultimap.create();
+    for (RepositoryInfo repository: repositories) {
+      operatingSystems.put(repository.getOsType(), repository);
+    }
+    for (Entry<String, Collection<RepositoryInfo>> operatingSystem : operatingSystems.asMap().entrySet())
{
+      final JsonObject operatingSystemJson = new JsonObject();
+      final JsonArray repositoriesJson = new JsonArray();
+      for (RepositoryInfo repository : operatingSystem.getValue()) {
+        final JsonObject repositoryJson = new JsonObject();
+        repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID,
repository.getBaseUrl());
+        repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_REPO_NAME_PROPERTY_ID,
repository.getRepoName());
+        repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_REPO_ID_PROPERTY_ID,
repository.getRepoId());
+        repositoriesJson.add(repositoryJson);
+      }
+      operatingSystemJson.add(SUBRESOURCE_REPOSITORIES_PROPERTY_ID, repositoriesJson);
+      operatingSystemJson.addProperty(OperatingSystemResourceProvider.OPERATING_SYSTEM_OS_TYPE_PROPERTY_ID,
operatingSystem.getKey());
+      rootJson.add(operatingSystemJson);
+    }
+    return gson.toJson(rootJson);
+  }
+
   protected StackId getStackInformationFromUrl(Map<String, Object> propertyMap) {
     if (propertyMap.containsKey(REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID) && propertyMap.containsKey(REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID))
{
       return new StackId(propertyMap.get(REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID).toString(),
propertyMap.get(REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID).toString());

http://git-wip-us.apache.org/repos/asf/ambari/blob/91700e78/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 8931e8c..4efb794 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
@@ -25,6 +25,7 @@ import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
+import javax.persistence.Lob;
 import javax.persistence.NamedQueries;
 import javax.persistence.NamedQuery;
 import javax.persistence.Table;
@@ -76,6 +77,7 @@ public class RepositoryVersionEntity {
   @Column(name = "upgrade_package")
   private String upgradePackage;
 
+  @Lob
   @Column(name = "repositories")
   private String operatingSystems;
 
@@ -141,6 +143,11 @@ public class RepositoryVersionEntity {
     this.operatingSystems = repositories;
   }
 
+  /**
+   * Getter which hides json nature of operating systems and returns them as entities.
+   *
+   * @return empty list if stored json is invalid
+   */
   public List<OperatingSystemEntity> getOperatingSystems() {
     if (StringUtils.isNotBlank(operatingSystems)) {
       try {
@@ -148,7 +155,7 @@ public class RepositoryVersionEntity {
       } catch (Exception ex) {
         // Should never happen as we validate json before storing it to DB
         LOG.error("Could not parse operating systems json stored in database:" + operatingSystems,
ex);
-      }  
+      }
     }
     return Collections.emptyList();
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/91700e78/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
index 9201f52..d59d8a1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
@@ -163,7 +163,7 @@ public class UpgradeCatalog200 extends AbstractUpgradeCatalog {
     columns.add(new DBColumnInfo("version",         String.class,  255,   null, false));
     columns.add(new DBColumnInfo("display_name",    String.class,  128,   null, false));
     columns.add(new DBColumnInfo("upgrade_package", String.class,  255,   null, false));
-    columns.add(new DBColumnInfo("repositories",    char[].class,  32672, null, false));
+    columns.add(new DBColumnInfo("repositories",    char[].class,  null,  null, false));
     dbAccessor.createTable("repo_version", columns, "repo_version_id");
     dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, sequence_value)
VALUES('repo_version_id_seq', 0)", false);
     dbAccessor.executeQuery("ALTER TABLE repo_version ADD CONSTRAINT UQ_repo_version_display_name
UNIQUE (display_name)");

http://git-wip-us.apache.org/repos/asf/ambari/blob/91700e78/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 cc33ae6..1e6631e 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
@@ -573,7 +573,7 @@ CREATE TABLE ambari.repo_version (
   version VARCHAR(255) NOT NULL,
   display_name VARCHAR(128) NOT NULL,
   upgrade_package VARCHAR(255) NOT NULL,
-  repositories VARCHAR NOT NULL,
+  repositories TEXT NOT NULL,
   PRIMARY KEY(repo_version_id)
 );
 GRANT ALL PRIVILEGES ON TABLE ambari.repo_version TO :username;

http://git-wip-us.apache.org/repos/asf/ambari/blob/91700e78/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 6c89671..76ba75b 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
@@ -18,10 +18,12 @@
 
 package org.apache.ambari.server.controller.internal;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -40,6 +42,7 @@ import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.OperatingSystemInfo;
+import org.apache.ambari.server.state.RepositoryInfo;
 import org.apache.ambari.server.state.StackInfo;
 import org.apache.ambari.server.state.stack.UpgradePack;
 import org.junit.After;
@@ -70,6 +73,7 @@ public class RepositoryVersionResourceProviderTest {
     final Set<String> validVersions = Sets.newHashSet("1.1", "1.1-17", "1.1.1.1", "1.1.343432.2",
"1.1.343432.2-234234324");
     final AmbariMetaInfo ambariMetaInfo = Mockito.mock(AmbariMetaInfo.class);
     final InMemoryDefaultTestModule injectorModule = new InMemoryDefaultTestModule() {
+      @Override
       protected void configure() {
         super.configure();
         bind(AmbariMetaInfo.class).toInstance(ambariMetaInfo);
@@ -309,6 +313,19 @@ public class RepositoryVersionResourceProviderTest {
     Assert.assertEquals("name2", provider.getResources(getRequest, new AndPredicate(predicateStackName,
predicateStackVersion)).iterator().next().getPropertyValue(RepositoryVersionResourceProvider.REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID));
   }
 
+  @Test
+  public void testSerializeOperatingSystems() throws Exception {
+    final List<RepositoryInfo> repositories = new ArrayList<RepositoryInfo>();
+    final RepositoryInfo repository = new RepositoryInfo();
+    repository.setBaseUrl("baseurl");
+    repository.setOsType("os");
+    repository.setRepoId("repoId");
+    repositories.add(repository);
+
+    final String serialized = RepositoryVersionResourceProvider.serializeOperatingSystems(repositories);
+    Assert.assertEquals("[{\"repositories\":[{\"Repositories/base_url\":\"baseurl\",\"Repositories/repo_id\":\"repoId\"}],\"OperatingSystems/os_type\":\"os\"}]",
serialized);
+  }
+
   @After
   public void after() {
     injector.getInstance(PersistService.class).stop();


Mime
View raw message