You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by mr...@apache.org on 2018/09/28 21:20:37 UTC

[ambari] 06/20: AMBARI-21796 : Clear versionDefinition map during new mpack registration and mpack deletion (mradhakrishnan)

This is an automated email from the ASF dual-hosted git repository.

mradhakrishnan pushed a commit to branch AMBARI-24711
in repository https://gitbox.apache.org/repos/asf/ambari.git

commit 32023fb66ab0e0b163bf4c4d4937e0d846d3b2ca
Author: Madhuvanthi Radhakrishnan <mr...@hortonworks.com>
AuthorDate: Wed Aug 23 15:04:52 2017 -0700

    AMBARI-21796 : Clear versionDefinition map during new mpack registration and mpack deletion (mradhakrishnan)
---
 .../ambari/server/api/services/AmbariMetaInfo.java |  6 +-
 .../org/apache/ambari/server/state/MpackTest.java  | 96 ++++++++++++++++++++++
 2 files changed, 100 insertions(+), 2 deletions(-)

diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
index 1ea5369..6812bf2 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
@@ -665,6 +665,7 @@ public class AmbariMetaInfo {
    * @throws ResourceAlreadyExistsException
    */
   public MpackResponse registerMpack(MpackRequest mpackRequest) throws IOException, ResourceAlreadyExistsException {
+    versionDefinitions.clear();
     return mpackManager.registerMpack(mpackRequest);
   }
 
@@ -1453,7 +1454,8 @@ public class AmbariMetaInfo {
    */
   private synchronized void ensureVersionDefinitions() {
     if (null != versionDefinitions) {
-      return;
+      if(versionDefinitions.size() > 0)
+        return;
     }
 
     versionDefinitions = new HashMap<>();
@@ -1552,7 +1554,7 @@ public class AmbariMetaInfo {
    * @throws IOException
    */
   public void removeMpack(MpackEntity mpackEntity, StackEntity stackEntity) throws IOException {
-
+    versionDefinitions.clear();
     boolean stackDelete = mpackManager.removeMpack(mpackEntity, stackEntity);
 
     if(stackDelete) {
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/MpackTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/MpackTest.java
new file mode 100644
index 0000000..388c256
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/MpackTest.java
@@ -0,0 +1,96 @@
+/**
+ * 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;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.gson.Gson;
+
+public class MpackTest {
+  @Test
+  public void testMpacks() {
+    Mpacks mpack = new Mpacks();
+    mpack.setName("name");
+    mpack.setMpackId((long)100);
+    mpack.setDescription("desc");
+    mpack.setVersion("3.0");
+    mpack.setMpacksUri("abc.tar.gz");
+    mpack.setRegistryId(new Long(100));
+
+    Assert.assertEquals("name", mpack.getName());
+    Assert.assertEquals(new Long(100), mpack.getMpackId());
+    Assert.assertEquals("desc", mpack.getDescription());
+    Assert.assertEquals("abc.tar.gz", mpack.getMpacksUri());
+    Assert.assertEquals(new Long(100), mpack.getRegistryId());
+
+  }
+
+  @Test
+  public void testMpacksUsingGson() {
+    String mpackJsonContents = "{\n" +
+            "  \"name\" : \"hdf-ambari-mpack\",\n" +
+            "  \"version\": \"3.0.0.0-111\",\n" +
+            "  \"description\" : \"HDF 3.0.0 Ambari Management Pack\",\n" +
+            "  \"prerequisites\": {\n" +
+            "    \"min-ambari-version\" : \"3.0.0.0\"\n" +
+            "  },\n" +
+            "  \"packlets\": [\n" +
+            "    {\n" +
+            "      \"type\" : \"service-packlet\",\n" +
+            "      \"name\" : \"NIFI\",\n" +
+            "      \"version\" : \"1.2.0.0-123\",\n" +
+            "      \"source_location\": \"packlets/NIFI-1.2.0.0-123.tar.gz\"\n" +
+            "    },\n" +
+            "    {\n" +
+            "      \"type\" : \"service-packlet\",\n" +
+            "      \"name\" : \"STREAMLINE\",\n" +
+            "      \"version\" : \"1.0.0.0-100\",\n" +
+            "      \"source_location\": \"packlets/STREAMLINE-1.0.0.0-100.tar.gz\"\n" +
+            "    }\n" +
+            "  ]\n" +
+            "}\n";
+    HashMap<String, String> expectedPrereq = new HashMap<>();
+    expectedPrereq.put("min-ambari-version","3.0.0.0");
+    ArrayList<Packlet> expectedPacklets = new ArrayList<>();
+    Packlet nifi = new Packlet();
+    nifi.setType("SERVICE_PACKLET");
+    nifi.setVersion("1.2.0.0-123");
+    nifi.setSourceLocation("packlets/NIFI-1.2.0.0-123.tar.gz");
+    nifi.setName("NIFI");
+    Packlet streamline = new Packlet();
+    streamline.setName("STREAMLINE");
+    streamline.setType(Packlet.PackletType.SERVICE_PACKLET);
+    streamline.setSourceLocation("packlets/STREAMLINE-1.0.0.0-100.tar.gz");
+    streamline.setVersion("1.0.0.0-100");
+    expectedPacklets.add(nifi);
+    expectedPacklets.add(streamline);
+
+    Gson gson = new Gson();
+    Mpack mpack = gson.fromJson(mpackJsonContents, Mpack.class);
+    Assert.assertEquals("hdf-ambari-mpack", mpack.getName());
+    Assert.assertEquals("3.0.0.0-111", mpack.getVersion());
+    Assert.assertEquals("HDF 3.0.0 Ambari Management Pack", mpack.getDescription());
+    Assert.assertEquals(expectedPrereq, mpack.getPrerequisites());
+    Assert.assertEquals(expectedPacklets.toString(), mpack.getPacklets().toString());
+  }
+
+}