Skip to main content

AEM - Workaround Solution for Clean up of Packages from Package Manager in AEM

AEM Packages Clean up from Package Manager 

Most of the times, the repository spaces get occupied with a lot of content and as well as packages. We create the packages to bring down the content from higher environments to lower environments or vice-versa and most of the times, we don't delete them from the environment. This will also increase the usage of the repository and cleaning up at some point later is very painful, as there is no direct way to check the larger packages and delete them.

There is no sorting option available in the package manager and when you have hundreds of packages, it will be a tedious process to go through every package and clean it up. Currently, only below sort options are available in the system.
  • Name
  • Last modified
  • Installation date
  • Recently added

Below solution is also a manual process but it will provide the packages which are of a size more than 30/40/50 MB(this can be configurable) by running a small script in java using any IDE. I tried it from my end and it worked fine.

This is really a weird way of getting the data, but still works :)


I tried the below steps:

Open the Package manager http://localhost:1502/crx/packmgr/index.jsp

  • Select all the data using "Ctrl + A" option (regular selection of all the text on the page
  • Paste the copied text into a text file and save the file

    the file will have a lot of unused data, but you can ignore them. The packages data will be shown as below in the file.
  • 
    
    aem-flash.ui.content-1.0-SNAPSHOT.zip
    Version: 1.0-SNAPSHOT | Last installed Sep 9 | admin
    
    UI content package for aem-flash
    
    Share  |  754.5 KB
    
    core.wcm.components.content-2.0.4.zip
    Version: 2.0.4 | Last installed Sep 9 | admin
    
    Adobe Experience Manager Core WCM Components Content Package
    
    Share  |  335.3 KB
    
    core.wcm.components.config-2.0.4.zip
    Version: 2.0.4 | Last installed Sep 9 | admin
    
    Adobe Experience Manager Core WCM Components Configurations
    
    Share  |  12.3 KB
    
    core.wcm.components.all-2.0.4.zip
    Version: 2.0.4 | Last installed Sep 9 | admin
    
    Adobe Experience Manager Core WCM Components Full Package
    
    Share  |  374.6 KB
    
    aem-flash.ui.apps-1.0-SNAPSHOT.zip
    Version: 1.0-SNAPSHOT | Last installed Sep 9 | admin
    
    UI apps package for aem-flash
    
    Share  |  443.5 KB
    
    

Line 1: Package Name (with .zip extension)
Line 2: Version and installation details
Line 3: Description of the Package
Line 4: Size of the package and Share status

We should be interested in Line 1 and Line 4 of all the packages. As the format is almost similar I made use of the structure as-is.


Java Class to read the file and get the required package data


MAX_SIZE  -- variable is the size of the package.

I have given it as 3 in the current sample which will display all the files which are greater than 3 MB. Update the number to a bigger number to retrieve the packages greater than that number like 100 MB or more.

public static final int MAX_SIZE = 100; --> Will return all the packages greater than 100 MB




package com.local;



import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;



/**

 * The Class ExtractPackageData.

 *

 * @author sudheerdvn

 */

public class ExtractPackageData {



 /** The Constant MAX_SIZE. Update the constant to the display the files greater than the max size. */

 public static final int MAX_SIZE = 3;



 /**

  * The main method.

  *

  * @param args the arguments

  * @throws IOException Signals that an I/O exception has occurred.

  */

 public static void main(String[] args) throws IOException {

  readFileData();

 }



 /**

  * Read file data.

  */

 private static void readFileData() {

  File file = new File("C:\\data\\packagesinfo.txt");

  BufferedReader bufferredReader = null;

  try {

   bufferredReader = new BufferedReader(new FileReader(file));

   String line;

   String zipFileName = null;

   int count = 0;

   while ((line = bufferredReader.readLine()) != null) {

    if (line.contains(".zip")) {

     zipFileName = line;

    }

    if (line.contains(" MB")) {

     String packageSize = line.substring(line.indexOf("|  ") + 3, line.length());

     /*

      * Printing only the packages which are more than a specific size, if you want all of them you can

      * remove the condition

      */

     if (checkPackageSize(packageSize)) {

      count++;

      System.out.println(zipFileName);

      System.out.println(packageSize);

     }

     zipFileName = null;

    }

   }

   System.out.println("number of mb packages are : " + count);

  } catch (IOException e) {

   e.printStackTrace();

  } finally {

   if (null != bufferredReader) {

    try {

     bufferredReader.close();

    } catch (IOException e) {

     e.printStackTrace();

    }

   }

  }

 }



 /**

  * Check package size.

  *

  * @param packageSize the package size

  * @return true, if successful

  */

 private static boolean checkPackageSize(String packageSize) {

 boolean isBig = false;
 String size = packageSize.substring(0, packageSize.indexOf(" MB"));
       try {
    Float sizeInFloat = Float.parseFloat(size);
    if (sizeInFloat > MAX_SIZE) {
  isBig = true;
    }
 } catch (Exception e) {
     e.printStackTrace();
 }
 return isBig;
   }

}




Result:

aem-groovy-console-12.0.0.zip
6.6 MB
we.retail.community.enablement.common-1.11.84.zip
6.5 MB
we.retail.commons.content-3.0.0.zip
92.9 MB
we.retail.all-3.0.0.zip
95 MB
aemds-guide-content-5.0.118.zip
3.5 MB
cq-social-thirdparty-pkg-1.4.4.zip
3.8 MB
cq-projects-content-1.4.108.zip
3.6 MB
cq-dam-scene7-viewers-content-2.2.52.zip
3.5 MB
cq-dam-sample-content-1.3.26.zip
13.7 MB
cq-dam-content-2.4.708.zip
5.7 MB
....
...
..



Sometimes, we may not know which packages to be deleted, so it's a better option to search the package name in the package manager by using the browser search (which is faster) than searching in the search box and just delete the required packages. Using the above-mentioned solution, there will be no impact on the server and it is completely offline process and does not impact AEM performance during the script execution.
We can also automate the process by using the CURL commands

curl -u admin:admin -F cmd=delete http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/test.zip
But one problem over here is to get the actual path of the package. We will not get the path in the above solution.

Another way to get this automated is to read the /etc/packages path either by iterating through the nodes or using the JSON format available by default and get the package names along with the path.

You can combine both these solutions to automate this and generate the curl commands or delete it using API.

You can also try directly getting the size of the packages by reading the node data instead of the above process.


Hope this helps for many like me :)


Comments

Popular posts from this blog

Delete DAM Asset using Workflow

This article shows you to create a simple workflow process step and use it for deleting an DAM Asset. You can ask me why do I need a workflow when I can delete it directly using the delete button :) The intention is to validate the asset information before deleting the asset or trigger any other workflow for the asset and do manipulations like updating the asset data to an user before the deletion as you will not be able to get that post deletion. you can catch the events in the Event Listeners, but there will be no data by then. Simple Workflow Process Step Create a workflow process step by using the below example package com.flash.aem.core.workflow; import java.util.HashMap; import java.util.Map; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.Session; import org.apache.sling.api.resource.LoginException; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.ResourceResolverFactory; import org.osgi.

Groovy Console Integration and executing scripts in AEM

Steps to install Groovy in AEM. Below Github have the steps to install the latest Groovy console https://github.com/icfnext/aem-groovy-console You can also navigate to the releases section and download the required package. https://github.com/icfnext/aem-groovy-console/releases I have used 12.0.0 version for this demo. Download the Groovy Package ( Direct link to the package  ) Upload the package to AEM via Package manager  http://localhost:4502/crx/packmgr/index.jsp Once the package is installed, you should be able to access the groovy console  http://localhost:4502/etc/groovyconsole.html Note: From 13.0.0 release, the paths were changed from /etc/ to /apps/ to access Groovy Console Sample Groovy Scripts: Printing a simple String println 'Hello World'; Click on Run Script Displays Hello World in the Console Get a Page Object final def page = getPage('/content/aem-flash') println 'page path is: ' + page.path; Re

AEM Project Maven Build - Easy setup and steps to run commands via command line

We generally run maven commands every day to deploy the bundles or any other changes in the project to AEM server. There are a lot of options to sync them automatically like using Brackets or AEM Server plugin configurations in IDE's etc.. These are very faster for deployments and changes to be reflected in AEM server In case if you would like to do a complete build, we can run the same from Eclipse by using the run commands or via command prompt using the complete maven command but IDE's generally occupy lot of memory and might slow down sometimes. I generally use Command prompt for the builds. I generally navigate to the repo folder and type the maven command " mvn clean install -PautoInstallPackage,adobe-public " Note: adobe-public can be ignored if you already set the repo in the maven settings I work on different projects and repositories every day and navigating to different folders and typing the same command (You can always copy and paste the comman