I am looking for the capability to add clusters to Jmanage. 

I couldnt find any API's to do this.

We have quite a heterogeneous environment and serveral apps. It is not possible to add applications and associate each of them individually to clusters.

Looked around and found the code for config/src/main/java/org/jmanage/core/config/ApplicationConfigManager.java and tried to hack around a bit.

Here is the code snippet I have -

-------------------------------------------------

import java.util.*;
import java.lang.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jmanage.core.crypto.Crypto;
//import org.apache.struts.action.*;
import org.jmanage.core.auth.User;
import org.jmanage.core.*;
import org.jmanage.core.config.*;
import org.jmanage.core.services.AccessController;
import org.jmanage.core.util.UserActivityLogger;
import org.jmanage.util.StringUtils;
import org.jmanage.webui.actions.BaseAction;
import org.jmanage.webui.forms.ApplicationClusterForm;
import org.jmanage.webui.util.WebContext;
import org.jmanage.core.services.*;
import org.jmanage.core.data.ApplicationConfigData;
import org.jmanage.core.remote.client.HttpServiceProxy;

public class AddCluster
{

    public AddCluster()
    {
    }
    public static void main (String args[]) throws Exception{

        String username = "shekar";
        String password = "XXXXX";
      

        HttpServiceProxy.login(username, password.toCharArray());
        //HttpServiceProxy.login("sureshv","Ruckmani123");
        RemoteServiceContextFactory.setJManageURL("https://localhost:9999/");
        ServiceContext context = RemoteServiceContextFactory.getServiceContext(username,password,null, null);

        ConfigurationService configService = ServiceFactory.getConfigurationService();
        ApplicationConfigData configData = new ApplicationConfigData();
        configData.setHost("localhost");
        configData.setPort(new Integer(1098));
        configData.setName("testApp");
        configData.setType("jboss");
        configData.setUsername("");
        configData.setPassword("");
        String applicationId=configData.getApplicationId();
        /* initialize crypto */
        //Crypto.init(getPassword());

        /* update the password for admin */

        System.out.println("ApplicationId:" +  applicationId);
        //System.exit(0);

          String childAppIds[] = StringUtils.csvToStringArray("");
              List newChildApplications = getNewChildApplications(childAppIds);
              //String applicationId = clusterForm.getApplicationId();
              if(applicationId != null)        {
                  ApplicationClusterConfig clusterConfig = (ApplicationClusterConfig)ApplicationConfigManager.getApplicationConfig(applicationId);
                  if(!$assertionsDisabled && clusterConfig == null)
                      throw new AssertionError();
                  clusterConfig.setName("shekartest");
                  clusterConfig.setPassword(password);
                  List oldChildApplications = clusterConfig.getApplications();
                  Iterator it = oldChildApplications.iterator();
                  do
                  {
                      if(!it.hasNext())
                          break;
                      ApplicationConfig appConfig = (ApplicationConfig)it.next();
                      if(!newChildApplications.contains(appConfig))
                      {
                          ApplicationConfigManager.addApplication(appConfig);
                          appConfig.setClusterConfig(null);
                      }
                  } while(true);
                  it = newChildApplications.iterator();
                  do
                  {
                      if(!it.hasNext())
                          break;
                      ApplicationConfig appConfig = (ApplicationConfig)it.next();
                      if(!oldChildApplications.contains(appConfig))
                      {
                          ApplicationConfigManager.deleteApplication(appConfig);
                          appConfig.setClusterConfig(clusterConfig);
                      }
                  } while(true);
                  clusterConfig.setApplications(newChildApplications);
                  try{
                        Crypto.hash(password.toCharArray());
                        Crypto.init(password.toCharArray());
                  }catch (Exception e){ e.printStackTrace();}
                  try{
                        ApplicationConfigManager.updateApplication(clusterConfig);
                  }catch (Exception e){ e.printStackTrace();}
              } else
              {
                  ApplicationClusterConfig clusterConfig = new ApplicationClusterConfig(ApplicationConfig.getNextApplicationId(), "shekartest");
                    ApplicationConfig appConfig;

                  for(Iterator it = newChildApplications.iterator(); it.hasNext(); ApplicationConfigManager.deleteApplication(appConfig, true))
                  {
                      appConfig = (ApplicationConfig)it.next();
                      appConfig.setClusterConfig(clusterConfig);
                  }

                  clusterConfig.setApplications(newChildApplications);
                  try{
                        clusterConfig.setPassword(Crypto.hash(password.toCharArray()));
                  }catch (Exception e){ e.printStackTrace();}
                  try{
                  //ApplicationConfigManager.addApplication(clusterConfig);
                  ApplicationConfigManager.addApplication(clusterConfig);
                  }catch (Exception e){ e.printStackTrace();}
              }
      
    }

    public static List getNewChildApplications(String childAppIds[])
    {
        List newChildApplications = new LinkedList();
        if(childAppIds != null)
        {
            for(int i = 0; i < childAppIds.length; i++)
            {
                ApplicationConfig newChildApplication = ApplicationConfigManager.getApplicationConfig(childAppIds[i]);
                newChildApplications.add(newChildApplication);
            }

        }
        return newChildApplications;
    }

  

    //static final boolean $assertionsDisabled = !org/jmanage/webui/actions/config/SaveApplicationClusterAction.desiredAssertionStatus();
    static final boolean $assertionsDisabled = true;
}

-------------------------------------------------

This does get compiled but I get the following runtime error:

Exception in thread "main" java.lang.ExceptionInInitializerError
        at addCluster.main(addCluster.java:121)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
        at org.jmanage.core.crypto.Crypto.decrypt(Crypto.java:73)
        at org.jmanage.core.crypto.Crypto.decrypt(Crypto.java:78)
        at org.jmanage.core.config.ConfigReader.getApplicationConfig(ConfigReader.java:136)
        at org.jmanage.core.config.ConfigReader.getApplicationConfigList(ConfigReader.java:108)
        at org.jmanage.core.config.ConfigReader.getApplicationClusterConfig(ConfigReader.java:170)
        at org.jmanage.core.config.ConfigReader.getApplicationConfigList(ConfigReader.java:112)
        at org.jmanage.core.config.ConfigReader.read(ConfigReader.java:86)
        at org.jmanage.core.config.ApplicationConfigManager.<clinit>(ApplicationConfigManager.java:45)
        ... 1 more
Caused by: java.lang.NullPointerException
        at org.jmanage.core.crypto.Crypto.decrypt(Crypto.java:71)
        ... 8 more

I have tried to use the crypto module. Not sure what to do. I am stuck with this for about a week now.

I really appreciate any help in this regard.

Also as a next step, I would like to associate a application to a cluster. Any pointers on this?