Coverage Report - com.aurea.maven.plugins.sonic.utils.SonicInvoker
 
Classes in this File Line Coverage Branch Coverage Complexity
SonicInvoker
0%
0/74
0%
0/10
2.125
 
 1  
 package com.aurea.maven.plugins.sonic.utils;
 2  
 
 3  
 import java.io.BufferedReader;
 4  
 import java.io.File;
 5  
 import java.io.InputStreamReader;
 6  
 import java.util.Hashtable;
 7  
 
 8  
 import javax.management.ObjectName;
 9  
 
 10  
 import com.sonicsw.mf.jmx.client.JMSConnectorAddress;
 11  
 import com.sonicsw.mf.jmx.client.JMSConnectorClient;
 12  
 import com.sonicsw.mf.mgmtapi.runtime.IAgentProxy;
 13  
 import com.sonicsw.mf.mgmtapi.runtime.IDirectoryServiceProxy;
 14  
 import com.sonicsw.mf.mgmtapi.runtime.MFProxyFactory;
 15  
 import com.sonicsw.mf.mgmtapi.runtime.ProxyRuntimeException;
 16  
 import com.sonicsw.mq.mgmtapi.runtime.IBrokerProxy;
 17  
 import com.sonicsw.mq.mgmtapi.runtime.MQProxyFactory;
 18  
 
 19  
 /**
 20  
  *
 21  
  */
 22  
 public class SonicInvoker extends JavaInvoker {
 23  
   
 24  
 
 25  
   /**
 26  
    * @param _sonicDirectory
 27  
    *          _sonicDirectory
 28  
    * @throws Exception
 29  
    *           Exception
 30  
    */
 31  
   public SonicInvoker(final String _sonicDirectory) throws Exception {
 32  
 
 33  0
     super("com.sonicsw.mf.framework.agent.ci.LaunchContainer");
 34  0
     setWorkingDir(_sonicDirectory);
 35  0
     configureSonicRuntime();
 36  0
   }
 37  
   
 38  
   /**
 39  
    * @throws Exception
 40  
    *           Exception
 41  
    */
 42  
   public final void configureSonicRuntime() throws Exception {
 43  
 
 44  0
     File sonicDir = new File(getWorkdir());
 45  0
     checkDir(sonicDir);
 46  0
     File sonicLib = new File(sonicDir, "lib");
 47  0
     checkDir(sonicLib);
 48  
     
 49  0
     addToBootClassPath(new File(sonicLib, "jmxri.jar").getAbsolutePath());
 50  
     
 51  0
     addToClassPath(new File(sonicLib, "MFLaunch.jar").getAbsolutePath());
 52  0
     addToClassPath(new File(sonicLib, "rsa_ssl.jar").getAbsolutePath());
 53  
     
 54  0
     setProperty("java.protocol.handler.pkgs", "progress.message.net");
 55  0
     setProperty("SSL_CA_CERTIFICATES_DIR", new File(sonicDir, "certs/CA").getAbsolutePath());
 56  0
     setProperty("sonicsw.home", getWorkdir());
 57  0
     setProperty("sonicsw.mf.allowRestart", "true");
 58  
     
 59  0
     addArgument("container.xml");
 60  0
     addArgument("ds.xml");
 61  0
   }
 62  
   
 63  
   private void checkDir(final File _dir) throws Exception {
 64  
 
 65  0
     if (!_dir.exists()) {
 66  0
       throw new Exception("Directory " + _dir.getAbsolutePath() + " does not exist.");
 67  
     }
 68  
     
 69  0
     if (!_dir.isDirectory()) {
 70  0
       throw new Exception("Directory " + _dir.getAbsolutePath() + " is not a directory.");
 71  
     }
 72  0
   }
 73  
   
 74  
   /**
 75  
    * @param _args
 76  
    *          command line arguments
 77  
    */
 78  
   @SuppressWarnings("deprecation")
 79  
 public static void main(final String[] _args) {
 80  
 
 81  
     try {
 82  0
       System.out.println("Invoking");
 83  
       // SonicInvoker invoker = new
 84  
       // SonicInvoker("C:\\Playground\\Development\\ESBPlugin\\SonicBin\\MQ7.6");
 85  
       // invoker.invoke();
 86  0
       ProcessBuilder process = new ProcessBuilder("C:\\Software\\Sonic7.6\\TestImage\\SonicData\\startCtManagement.bat");
 87  0
       process.directory(new File("C:\\Software\\Sonic7.6\\TestImage\\SonicData"));
 88  0
       Process p = process.start();
 89  0
       BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
 90  
       String input;
 91  0
       while (!(input = br.readLine()).toUpperCase().contains("STARTUP COMPLETE")) {
 92  0
         System.out.println("Sonic: " + input);
 93  
       }
 94  
       
 95  0
       System.out.println("Found: " + input + "\nContinuing");
 96  
       
 97  0
       System.out.println("Done Invoking");
 98  0
       br.close();
 99  0
       System.out.println("Sleeping");
 100  0
       Thread.sleep(10000);
 101  
       
 102  
       // performing the configuration
 103  0
       System.out.println("Performing the configuration");
 104  0
       OffLineDSConfigurator ods = new OffLineDSConfigurator();
 105  0
       ods.go();
 106  
       
 107  0
       System.out.println("Sleeping for shutdown");
 108  0
       Thread.sleep(10000);
 109  
       
 110  0
       System.out.println("Shutting Down");
 111  
       
 112  
 
 113  
 
 114  0
       JMSConnectorClient connector = null;
 115  
       
 116  
       try {
 117  
         // get a JMX connector
 118  0
         System.out.println("Get Connector");
 119  0
         connector = getConnector("tcp://localhost:3506", "Administrator", "Administrator");
 120  
         // create a proxy to the broker component
 121  0
         System.out.println("Agent Proxy");
 122  0
         IAgentProxy agent = getAgentProxy(connector, "Domain1", "ctManagement");
 123  
         // shutdown the container
 124  0
         System.out.println("shutdown");
 125  0
         agent.shutdown();
 126  0
         System.out.println("Shutdown Done");
 127  0
       } catch (Throwable t) {
 128  0
         t.printStackTrace();
 129  0
         if (t instanceof ProxyRuntimeException) {
 130  0
           System.err.println("Caused by:");
 131  0
           ((ProxyRuntimeException) t).getTargetException().printStackTrace();
 132  
         }
 133  
       } finally {
 134  0
         if (connector != null) {
 135  0
           connector.disconnect();
 136  
         }
 137  
       }
 138  0
     } catch (Exception e) {
 139  0
       e.printStackTrace();
 140  0
     }
 141  0
   }
 142  
   
 143  
   /**
 144  
    * Gets a connected JMS/JMX Connector Client for management communications with components exposed as JMX MBeans. The
 145  
    * urls, user and pwd (password) parameters define connection parameters to the broker(s) through which management
 146  
    * communications will travel.
 147  
    * 
 148  
    * @param _urls
 149  
    *          urls
 150  
    * @param _user
 151  
    *          user
 152  
    * @param _pwd
 153  
    *          pwd
 154  
    * @return JMSConnectorClient
 155  
    * @throws Exception
 156  
    *           Exception
 157  
    */
 158  
   public static JMSConnectorClient getConnector(final String _urls, final String _user, final String _pwd)
 159  
     throws Exception {
 160  
 
 161  0
     Hashtable<String, String> env = new Hashtable<String, String>();
 162  0
     env.put("ConnectionURLs", _urls);
 163  0
     env.put("DefaultUser", _user);
 164  0
     env.put("DefaultPassword", _pwd);
 165  
     
 166  0
     JMSConnectorAddress address = new JMSConnectorAddress(env);
 167  0
     JMSConnectorClient connector = new JMSConnectorClient();
 168  0
     connector.connect(address, 10000);
 169  
     
 170  0
     return connector;
 171  
   }
 172  
   
 173  
   /**
 174  
    * Gets a management proxy for an AGENT component; the AGENT component is used to manage a container.
 175  
    * 
 176  
    * @param _connector
 177  
    *          _connector
 178  
    * @param _domain
 179  
    *          _domain
 180  
    * @param _container
 181  
    *          _container
 182  
    * @return IAgentProxy
 183  
    * @throws Exception
 184  
    *           Exception
 185  
    */
 186  
   public static IAgentProxy getAgentProxy(final JMSConnectorClient _connector, final String _domain,
 187  
     final String _container) throws Exception {
 188  
 
 189  0
     ObjectName jmxName = new ObjectName(_domain + "." + _container + ":ID=AGENT");
 190  0
     return MFProxyFactory.createAgentProxy(_connector, jmxName);
 191  
   }
 192  
   
 193  
   /**
 194  
    * Gets a management proxy for the Directory Service component; the DS component is used to manage the domain
 195  
    * configuration store.
 196  
    * 
 197  
    * @param _connector
 198  
    *          _connector
 199  
    * @param _domain
 200  
    *          _domain
 201  
    * @return IDirectoryServiceProxy
 202  
    * @throws Exception
 203  
    *           Exception
 204  
    */
 205  
   public static IDirectoryServiceProxy getDirectoryServiceProxy(final JMSConnectorClient _connector,
 206  
     final String _domain) throws Exception {
 207  
 
 208  0
     ObjectName jmxName = new ObjectName(_domain + ".DIRECTORY SERVICE:ID=DIRECTORY SERVICE");
 209  0
     return MFProxyFactory.createDirectoryServiceProxy(_connector, jmxName);
 210  
   }
 211  
   
 212  
   /**
 213  
    * Gets a management proxy for a SOnicMQ broker component.
 214  
    * 
 215  
    * @param _connector
 216  
    *          _connector
 217  
    * @param _domain
 218  
    *          _domain
 219  
    * @param _container
 220  
    *          _container
 221  
    * @param _id
 222  
    *          _id
 223  
    * @return IBrokerProxy
 224  
    * @throws Exception
 225  
    *           Exception
 226  
    */
 227  
   public static IBrokerProxy getBrokerProxy(final JMSConnectorClient _connector, final String _domain,
 228  
     final String _container, final String _id) throws Exception {
 229  
 
 230  0
     ObjectName jmxName = new ObjectName(_domain + "." + _container + ":ID=" + _id);
 231  0
     return MQProxyFactory.createBrokerProxy(_connector, jmxName);
 232  
   }
 233  
 }