ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mradhakrish...@apache.org
Subject ambari git commit: AMBARI-21752 : Use Mpack metadata for iterating over list of packlets to expand (mradhakrishnan)
Date Tue, 22 Aug 2017 18:08:18 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-feature-AMBARI-14714 67cacc8ab -> 24f40aa1e


AMBARI-21752 : Use Mpack metadata for iterating over list of packlets to expand (mradhakrishnan)


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

Branch: refs/heads/branch-feature-AMBARI-14714
Commit: 24f40aa1e815a0deedc709a732cef075bef59521
Parents: 67cacc8
Author: Madhuvanthi Radhakrishnan <mradhakrishnan@hortonworks.com>
Authored: Tue Aug 22 11:07:06 2017 -0700
Committer: Madhuvanthi Radhakrishnan <mradhakrishnan@hortonworks.com>
Committed: Tue Aug 22 11:07:06 2017 -0700

----------------------------------------------------------------------
 .../ambari/server/mpack/MpackManager.java       | 40 +++++++++-----------
 .../org/apache/ambari/server/state/Packlet.java | 33 +++++++++-------
 .../AmbariManagementControllerImplTest.java     |  4 +-
 .../internal/MpackResourceProviderTest.java     |  4 +-
 .../apache/ambari/server/state/MpackTest.java   |  8 ++--
 5 files changed, 45 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/24f40aa1/ambari-server/src/main/java/org/apache/ambari/server/mpack/MpackManager.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/mpack/MpackManager.java
b/ambari-server/src/main/java/org/apache/ambari/server/mpack/MpackManager.java
index a8a227b..e475e96 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/mpack/MpackManager.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/mpack/MpackManager.java
@@ -184,7 +184,7 @@ public class MpackManager {
    * @param tarPath
    * @throws IOException
    */
-  private void extractTar(Path tarPath, File tempOutputDirectory) throws IOException{
+  private void extractTar(Path tarPath, File tempOutputDirectory) throws IOException {
     TarArchiveInputStream tarFile = new TarArchiveInputStream(new GzipCompressorInputStream(new
BufferedInputStream(new FileInputStream(new File(String.valueOf(tarPath))))));
     TarArchiveEntry entry = null;
     File outputFile = null;
@@ -228,35 +228,32 @@ public class MpackManager {
             (Paths.get(mpacksStaging + File.separator + mpackTarDirectory.substring(mpackTarDirectory.lastIndexOf('/')
+ 1, mpackTarDirectory.indexOf(".tar")) + File.separator),
                     Paths.get(mpackDirectory), StandardCopyOption.REPLACE_EXISTING);
 
-    createServicesDirectory(extractedMpackDirectory);
+    createServicesDirectory(extractedMpackDirectory, mpack);
     createSymLinks(mpack);
   }
 
   /***
    * Create a services directory and extract all the services tar file inside it. This readies
it for cluster deployment
    * @param extractedMpackDirectory
+   * @param mpack
    * @throws IOException
    */
-  private void createServicesDirectory(Path extractedMpackDirectory) throws IOException {
+  private void createServicesDirectory(Path extractedMpackDirectory, Mpack mpack) throws
IOException {
     File servicesDir = new File(extractedMpackDirectory.toAbsolutePath() + File.separator
+ SERVICES_DIRECTORY);
     if (!servicesDir.exists()) {
       servicesDir.mkdir();
     }
-    File packletDir = new File(extractedMpackDirectory.toAbsolutePath() + File.separator
+ PACKLETS_DIRECTORY);
-    for (final File serviceTar : packletDir.listFiles()) {
-      String serviceName = serviceTar.getName();
-      if (serviceName.contains("tar.gz")) {
-        extractTar(serviceTar.toPath(), packletDir);
-        String serviceTarDirectory = serviceTar.toString();
-        String serviceNameVersion = serviceTarDirectory.substring(serviceTarDirectory.lastIndexOf('/')
+ 1, serviceTarDirectory.indexOf(".tar"));
-        String serviceFolderName = serviceNameVersion.substring(0,serviceNameVersion.indexOf("-packlet"));
//Can we assume the names of the tar files?
-        Path extractedServiceDirectory = Files.move
-                (Paths.get(packletDir + File.separator + serviceNameVersion),
-                        Paths.get(servicesDir.toPath() + File.separator + serviceFolderName
), StandardCopyOption.REPLACE_EXISTING);
+    ArrayList<Packlet> packletArrayList = mpack.getPacklets();
+
+    for (Packlet packlet : packletArrayList) {
+      if (packlet.getType() == Packlet.PackletType.SERVICE_PACKLET) {
+        String packletSourceLocation = packlet.getSourceLocation();
+        File serviceTargetDir = new File(servicesDir + File.separator + packlet.getName());
+        extractTar(Paths.get(extractedMpackDirectory + File.separator + packlet.getSourceLocation())
, servicesDir );
+        Path extractedServiceDirectory = Files.move(Paths.get(servicesDir + File.separator
+ packletSourceLocation.substring(packletSourceLocation.indexOf("/")+1,packletSourceLocation.indexOf(".tar.gz"))),serviceTargetDir.toPath(),
StandardCopyOption.REPLACE_EXISTING);
+        }
       }
     }
-  }
-
 
   /**
    * Reads the mpack.json file within the {mpack-name}.tar.gz file and populates Mpack object.
@@ -302,12 +299,11 @@ public class MpackManager {
           File mpackDirectory = new File(mpacksStaging + File.separator + mpack.getName());
 
           if (!mpackDirectory.exists()) {
-            return mpackDirectory.mkdir();
-          } else {
-            return true;
+            mpackDirectory.mkdir();
           }
+          return true;
         } else {
-          String message = "Mpack :" + mpack.getName() + " version: " + mpack.getVersion()
+ " already exists in server";
+          String message = "Mpack: " + mpack.getName() + " version: " + mpack.getVersion()
+ " already exists in server";
           throw new ResourceAlreadyExistsException(message);
         }
       }
@@ -465,7 +461,7 @@ public class MpackManager {
     File mpackDirToDelete = new File(mpacksStaging + File.separator + mpackEntity.getMpackName()
+ File.separator + mpackEntity.getMpackVersion());
     File mpackDirectory = new File(mpacksStaging + "/" + mpackEntity.getMpackName());
     String mpackName = mpackEntity.getMpackName() + "-" + mpackEntity.getMpackVersion() +
".tar.gz";
-    Path mpackTarFile = Paths.get(mpacksStaging + File.separator + MPACK_TAR_LOCATION +File.separator
+ mpackName);
+    Path mpackTarFile = Paths.get(mpacksStaging + File.separator + MPACK_TAR_LOCATION + File.separator
+ mpackName);
 
     mpackMap.remove(mpackEntity.getMpackId());
     FileUtils.deleteDirectory(mpackDirToDelete);
@@ -488,7 +484,7 @@ public class MpackManager {
       stackDelete = true;
     }
 
-    if (Files.exists(mpackTarFile)){
+    if (Files.exists(mpackTarFile)) {
       Files.delete(mpackTarFile);
     }
     return stackDelete;

http://git-wip-us.apache.org/repos/asf/ambari/blob/24f40aa1/ambari-server/src/main/java/org/apache/ambari/server/state/Packlet.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Packlet.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Packlet.java
index 1fa8dee..9f884d3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Packlet.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Packlet.java
@@ -21,22 +21,27 @@ import com.google.gson.annotations.SerializedName;
 
 
 public class Packlet {
+  public enum PackletType {
+    @SerializedName("service-packlet")
+    SERVICE_PACKLET
+  }
+
   @SerializedName("type")
-  private String type;
+  private PackletType type;
   @SerializedName("name")
   private String name;
   @SerializedName("version")
   private String version;
   @SerializedName("service-id")
   private String serviceId;
-  @SerializedName("source_dir")
-  private String sourceDir;
+  @SerializedName("source_location")
+  private String srcLocation;
 
-  public String getType() {
+  public PackletType getType() {
     return type;
   }
 
-  public void setType(String type) {
+  public void setType(PackletType type) {
     this.type = type;
   }
 
@@ -56,12 +61,12 @@ public class Packlet {
     this.version = version;
   }
 
-  public String getSourceDir() {
-    return sourceDir;
+  public String getSourceLocation() {
+    return srcLocation;
   }
 
-  public void setSourceDir(String sourceDir) {
-    this.sourceDir = sourceDir;
+  public void setSourceLocation(String srcLocation) {
+    this.srcLocation = srcLocation;
   }
 
 
@@ -85,7 +90,7 @@ public class Packlet {
     result = prime * result + ((name == null) ? 0 : name.hashCode());
     result = prime * result + ((version == null) ? 0 : version.hashCode());
     result = prime * result + ((serviceId == null) ? 0 : serviceId.hashCode());
-    result = prime * result + ((sourceDir == null) ? 0 : sourceDir.hashCode());
+    result = prime * result + ((srcLocation == null) ? 0 : srcLocation.hashCode());
     return result;
   }
 
@@ -136,11 +141,11 @@ public class Packlet {
       return false;
     }
 
-    if (sourceDir == null) {
-      if (other.sourceDir != null) {
+    if (srcLocation == null) {
+      if (other.srcLocation != null) {
         return false;
       }
-    } else if (!sourceDir.equals(other.sourceDir)) {
+    } else if (!srcLocation.equals(other.srcLocation)) {
       return false;
     }
     return true;
@@ -154,7 +159,7 @@ public class Packlet {
     sb.append("name=").append(name).append(", ");
     sb.append("version=").append(version).append(", ");
     sb.append("service id=").append(serviceId).append(", ");
-    sb.append("source directory=").append(sourceDir).append(", ");
+    sb.append("source location=").append(srcLocation).append(", ");
     sb.append('}');
     return sb.toString();
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/24f40aa1/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
index e7cc29e..c0254b6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
@@ -2448,10 +2448,10 @@ public class AmbariManagementControllerImplTest {
     ArrayList<Packlet> packletArrayList = new ArrayList<>();
     Packlet samplePacklet = new Packlet();
     Injector injector = createNiceMock(Injector.class);
-    samplePacklet.setType("service");
+    samplePacklet.setType(Packlet.PackletType.SERVICE_PACKLET);
     samplePacklet.setVersion("3.0.0");
     samplePacklet.setName("NIFI");
-    samplePacklet.setSourceDir("/abc/nifi.tar.gz");
+    samplePacklet.setSourceLocation("/abc/nifi.tar.gz");
     packletArrayList.add(samplePacklet);
     expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null).atLeastOnce();
     expect(ambariMetaInfo.getPacklets(mpackId)).andReturn(packletArrayList).atLeastOnce();

http://git-wip-us.apache.org/repos/asf/ambari/blob/24f40aa1/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/MpackResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/MpackResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/MpackResourceProviderTest.java
index f0b81cb..97b2d98 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/MpackResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/MpackResourceProviderTest.java
@@ -164,8 +164,8 @@ public class MpackResourceProviderTest {
     ArrayList<Packlet> packletArrayList = new ArrayList<>();
     Packlet packlet = new Packlet();
     packlet.setName("testService");
-    packlet.setType("service");
-    packlet.setSourceDir("testDir/testDir");
+    packlet.setType(Packlet.PackletType.SERVICE_PACKLET);
+    packlet.setSourceLocation("testDir/testDir");
     packlet.setVersion("3.0");
     packletArrayList.add(packlet);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/24f40aa1/ambari-server/src/test/java/org/apache/ambari/server/state/MpackTest.java
----------------------------------------------------------------------
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
index 266dff5..3b96182 100644
--- 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
@@ -72,14 +72,14 @@ public class MpackTest {
     expectedPrereq.put("min-ambari-version","3.0.0.0");
     ArrayList<Packlet> expectedPacklets = new ArrayList<>();
     Packlet nifi = new Packlet();
-    nifi.setType("service-packlet");
+    nifi.setType(Packlet.PackletType.SERVICE_PACKLET);
     nifi.setVersion("1.2.0.0-123");
-    nifi.setSourceDir("packlets/NIFI-1.2.0.0-123.tar.gz");
+    nifi.setSourceLocation("packlets/NIFI-1.2.0.0-123.tar.gz");
     nifi.setName("NIFI");
     Packlet streamline = new Packlet();
     streamline.setName("STREAMLINE");
-    streamline.setType("service-packlet");
-    streamline.setSourceDir("packlets/STREAMLINE-1.0.0.0-100.tar.gz");
+    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);


Mime
View raw message