Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package org.wso2.carbon.cluster.ui; import java.io.File; import java.sql.Connection; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.filechooser.FileNameExtensionFilter; import org.apache.commons.io.FilenameUtils; import org.wso2.carbon.cluster.bean.Axis2XMLBean; import org.wso2.carbon.cluster.bean.CarbonXMLBean; import org.wso2.carbon.cluster.bean.DatasourceBean; import org.wso2.carbon.cluster.bean.RegistryXMLBean; import org.wso2.carbon.cluster.utils.ClusterConstants; import org.wso2.carbon.cluster.utils.DBConnection; import org.wso2.carbon.cluster.utils.FileUtils; import org.wso2.carbon.cluster.utils.XMLUtils; /** * * @author aruna */ public class ClusterWizard extends javax.swing.JFrame { private String zipAbsFilePath; private String clusterAbsFolderPath; private String zipFileName; /** * Creates new form ClusterWizard */ public ClusterWizard() { initComponents(); FileUtils.textArea = this.jTextArea1; } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { mainPanel = new javax.swing.JPanel(); jPanel1 = new javax.swing.JPanel(); btnZipFileSelect = new javax.swing.JButton(); btnFolderPathSelect = new javax.swing.JButton(); txtZipFilePath = new javax.swing.JTextField(); txtFolderPath = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); jPanel2 = new javax.swing.JPanel(); jLabel2 = new javax.swing.JLabel(); managerPanel = new javax.swing.JPanel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); mgrPortOffset = new javax.swing.JComboBox(); mgrDomain = new javax.swing.JTextField(); mgrLocalMemberHost = new javax.swing.JTextField(); mgrLocalMemberPort = new javax.swing.JComboBox(); mgrMembershipScheme = new javax.swing.JComboBox(); jLabel18 = new javax.swing.JLabel(); txtMgtHostName = new javax.swing.JTextField(); jPanel3 = new javax.swing.JPanel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jLabel10 = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); wkrPortOffset = new javax.swing.JComboBox(); wkrDomain = new javax.swing.JTextField(); wkrLocalMemberHost = new javax.swing.JTextField(); wkrLocalMemberPort = new javax.swing.JComboBox(); wkrMembershipScheme = new javax.swing.JComboBox(); txddtHostName = new javax.swing.JLabel(); txtHostName = new javax.swing.JTextField(); regEnable = new javax.swing.JPanel(); jLabel13 = new javax.swing.JLabel(); enableRegistry = new javax.swing.JComboBox(); jLabel14 = new javax.swing.JLabel(); jLabel15 = new javax.swing.JLabel(); jLabel16 = new javax.swing.JLabel(); jLabel17 = new javax.swing.JLabel(); regHostName = new javax.swing.JTextField(); regPort = new javax.swing.JTextField(); regDbUsername = new javax.swing.JTextField(); regDbPassword = new javax.swing.JPasswordField(); btnTestDBCon = new javax.swing.JButton(); logPanel = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); btnExit = new javax.swing.JButton(); btnExecute = new javax.swing.JButton(); bttnClear = new javax.swing.JButton(); jSeparator1 = new javax.swing.JSeparator(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenutemExit = new javax.swing.JMenuItem(); jMenu2 = new javax.swing.JMenu(); jMenu3 = new javax.swing.JMenu(); jMenuItem2 = new javax.swing.JMenuItem(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("WSO2 Cluster Wizard - 1.0.0"); getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); mainPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); btnZipFileSelect.setText("Select a Product Zip File"); btnZipFileSelect.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnZipFileSelectActionPerformed(evt); } }); jPanel1.add(btnZipFileSelect, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 40, 230, -1)); btnFolderPathSelect.setText("Select Target Folder Path"); btnFolderPathSelect.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnFolderPathSelectActionPerformed(evt); } }); jPanel1.add(btnFolderPathSelect, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 80, 230, -1)); txtZipFilePath.setEditable(false); txtZipFilePath.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N jPanel1.add(txtZipFilePath, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 40, 870, 25)); txtFolderPath.setEditable(false); txtFolderPath.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N jPanel1.add(txtFolderPath, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 80, 870, 25)); jLabel1.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N jLabel1.setText("Select Product Zip File and Path for Cluster"); jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 0, 310, 30)); mainPanel.add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 1180, 130)); jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jLabel2.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N jLabel2.setText("Cluster Settings"); jPanel2.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 0, 120, 30)); managerPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Manager Node")); managerPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jLabel3.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N jLabel3.setText("PortOffset"); managerPanel.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, 130, -1)); jLabel4.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N jLabel4.setText("Domain"); managerPanel.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 80, -1, -1)); jLabel5.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N jLabel5.setText("Local Member Host"); jLabel5.setToolTipText("put the host IP address e.g 10.100.5.41"); managerPanel.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 120, 140, -1)); jLabel6.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N jLabel6.setText("Local Member Port"); managerPanel.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 160, 130, -1)); jLabel7.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N jLabel7.setText("Membership Scheme"); managerPanel.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 200, 150, -1)); mgrPortOffset.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" })); managerPanel.add(mgrPortOffset, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 35, 180, -1)); mgrDomain.setText("wso2.as.domain"); mgrDomain.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { mgrDomainKeyTyped(evt); } }); managerPanel.add(mgrDomain, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 75, 180, -1)); mgrLocalMemberHost.setText("10.100.5.41"); mgrLocalMemberHost.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { mgrLocalMemberHostKeyTyped(evt); } }); managerPanel.add(mgrLocalMemberHost, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 115, 180, -1)); mgrLocalMemberPort.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "4000", "4001", "4002", "4003", "4004", "4005", "4006", "4007", "4008", "4009", "4010" })); managerPanel.add(mgrLocalMemberPort, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 155, 180, -1)); mgrMembershipScheme.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "wka", "multicast" })); mgrMembershipScheme.setEnabled(false); managerPanel.add(mgrMembershipScheme, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 200, 180, -1)); jLabel18.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N jLabel18.setText("MgtHostName"); managerPanel.add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 240, 130, -1)); txtMgtHostName.setText("mgt.appserver.wso2.com"); managerPanel.add(txtMgtHostName, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 240, 180, -1)); jPanel2.add(managerPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, 380, 280)); jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(" Worker Node")); jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jLabel8.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N jLabel8.setText("PortOffset"); jPanel3.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, 130, -1)); jLabel9.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N jLabel9.setText("Domain"); jPanel3.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 80, -1, -1)); jLabel10.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N jLabel10.setText("Local Member Host"); jPanel3.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 120, 140, -1)); jLabel11.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N jLabel11.setText("Local Member Port"); jPanel3.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 160, 130, -1)); jLabel12.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N jLabel12.setText("Membership Scheme"); jPanel3.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 200, 150, -1)); wkrPortOffset.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" })); wkrPortOffset.setSelectedIndex(1); jPanel3.add(wkrPortOffset, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 35, 180, -1)); wkrDomain.setText("wso2.as.domain"); jPanel3.add(wkrDomain, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 75, 180, -1)); wkrLocalMemberHost.setText("10.100.5.41"); jPanel3.add(wkrLocalMemberHost, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 115, 180, -1)); wkrLocalMemberPort.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "4000", "4001", "4002", "4003", "4004", "4005", "4006", "4007", "4008", "4009", "4010" })); wkrLocalMemberPort.setSelectedIndex(1); jPanel3.add(wkrLocalMemberPort, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 155, 180, -1)); wkrMembershipScheme.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "wka", "multicast" })); wkrMembershipScheme.setEnabled(false); jPanel3.add(wkrMembershipScheme, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 200, 180, -1)); txddtHostName.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N txddtHostName.setText("HostName"); jPanel3.add(txddtHostName, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 240, -1, -1)); txtHostName.setText("appserver.wso2.com"); jPanel3.add(txtHostName, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 240, 180, -1)); jPanel2.add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 20, 380, 280)); regEnable.setBorder(javax.swing.BorderFactory.createTitledBorder("Database")); regEnable.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jLabel13.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N jLabel13.setText("Enable Registry"); regEnable.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, -1, -1)); enableRegistry.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "enabled", "disabled" })); enableRegistry.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { enableRegistryActionPerformed(evt); } }); regEnable.add(enableRegistry, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 35, 190, -1)); jLabel14.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N jLabel14.setText("Hostname"); regEnable.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 80, -1, -1)); jLabel15.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N jLabel15.setText("Port"); regEnable.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 120, -1, -1)); jLabel16.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N jLabel16.setText("Username"); regEnable.add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 160, -1, -1)); jLabel17.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N jLabel17.setText("Password"); regEnable.add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 200, -1, -1)); regHostName.setText("localhost"); regEnable.add(regHostName, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 75, 190, -1)); regPort.setText("3306"); regEnable.add(regPort, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 115, 190, -1)); regDbUsername.setText("root"); regEnable.add(regDbUsername, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 155, 190, -1)); regEnable.add(regDbPassword, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 195, 190, -1)); btnTestDBCon.setText("TestDB Connection"); btnTestDBCon.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnTestDBConActionPerformed(evt); } }); regEnable.add(btnTestDBCon, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 235, 190, -1)); jPanel2.add(regEnable, new org.netbeans.lib.awtextra.AbsoluteConstraints(790, 20, 380, 280)); mainPanel.add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 150, 1180, 310)); logPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); logPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jTextArea1.setEditable(false); jTextArea1.setColumns(20); jTextArea1.setRows(5); jScrollPane1.setViewportView(jTextArea1); logPanel.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 1160, 250)); mainPanel.add(logPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 470, 1180, 270)); btnExit.setText("Exit"); btnExit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnExitActionPerformed(evt); } }); mainPanel.add(btnExit, new org.netbeans.lib.awtextra.AbsoluteConstraints(1050, 750, 140, -1)); btnExecute.setText("Execute"); btnExecute.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnExecuteActionPerformed(evt); } }); mainPanel.add(btnExecute, new org.netbeans.lib.awtextra.AbsoluteConstraints(900, 750, 140, -1)); bttnClear.setText("Clear"); mainPanel.add(bttnClear, new org.netbeans.lib.awtextra.AbsoluteConstraints(750, 750, 140, -1)); mainPanel.add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 786, 1210, 20)); getContentPane().add(mainPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 1200, 800)); jMenu1.setText("File"); jMenutemExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK)); jMenutemExit.setText("Exit"); jMenutemExit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenutemExitActionPerformed(evt); } }); jMenu1.add(jMenutemExit); jMenuBar1.add(jMenu1); jMenu2.setText("Edit"); jMenuBar1.add(jMenu2); jMenu3.setText("Help"); jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F2, 0)); jMenuItem2.setText("About"); jMenuItem2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem2ActionPerformed(evt); } }); jMenu3.add(jMenuItem2); jMenuBar1.add(jMenu3); setJMenuBar(jMenuBar1); pack(); }// </editor-fold>//GEN-END:initComponents private void jMenutemExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenutemExitActionPerformed System.exit(0); }//GEN-LAST:event_jMenutemExitActionPerformed private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed JOptionPane.showMessageDialog(null, "This Program creates a Worker-Manager Cluster", "About WSO2 Cluster Manager", JOptionPane.INFORMATION_MESSAGE); }//GEN-LAST:event_jMenuItem2ActionPerformed private void btnZipFileSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnZipFileSelectActionPerformed JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Zip File", "zip"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(getParent()); if (returnVal == JFileChooser.APPROVE_OPTION) { zipAbsFilePath = chooser.getSelectedFile().getAbsolutePath(); txtZipFilePath.setText(zipAbsFilePath); zipFileName = FilenameUtils.removeExtension(chooser.getSelectedFile().getName()); } }//GEN-LAST:event_btnZipFileSelectActionPerformed private void btnFolderPathSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFolderPathSelectActionPerformed JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = chooser.showOpenDialog(getParent()); if (returnVal == JFileChooser.APPROVE_OPTION) { clusterAbsFolderPath = chooser.getSelectedFile().getAbsolutePath(); txtFolderPath.setText(clusterAbsFolderPath); } }//GEN-LAST:event_btnFolderPathSelectActionPerformed private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitActionPerformed System.exit(0); }//GEN-LAST:event_btnExitActionPerformed private void btnExecuteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExecuteActionPerformed if (zipAbsFilePath == null || zipAbsFilePath.equals("") || clusterAbsFolderPath == null || clusterAbsFolderPath.equals("")) { showErrorMessage("Error Message", "Please select a valid zipfile and a valid folder...!!!"); } else { //check all the values are filled if (!checkFields()) { showErrorMessage("Error", "Fill all the worker - manager deails...!!!"); return; } if (!checkRegistryFields()) { showErrorMessage("Error Message", "Fill all the DB details...!!!"); return; } //if already exist worker -manager folder delete them if (!FileUtils.deleteProducts(clusterAbsFolderPath, zipFileName)) { JOptionPane.showMessageDialog(null, "Please backup current folders and try again...!!!", "Message", JOptionPane.INFORMATION_MESSAGE); return; } //extract product to a given location if (FileUtils.unzipFile(zipAbsFilePath, clusterAbsFolderPath)) { //rename folder with PREFIX_MANAGER FileUtils.renameFolder(clusterAbsFolderPath, zipFileName, ClusterConstants.PREFIX_MANAGER); File mgrFodler = new File( clusterAbsFolderPath + File.separator + ClusterConstants.PREFIX_MANAGER + zipFileName); File wkrFodler = new File( clusterAbsFolderPath + File.separator + ClusterConstants.PREFIX_WORKER + zipFileName); //make copy with PREFIX_WORKER FileUtils.makeCopy(mgrFodler, wkrFodler); logMessage("INFO :: Successfully Created Worker Manager Folders... "); //populate carbon.xml and axis2.xml files in manager and worker try { populateCarbonXmlFiles(); populateAxis2XmlFiles(); if (enableRegistry.getSelectedItem().toString().equalsIgnoreCase("enabled")) { //mount registry if enabled logMessage("INFO :: Registry Mounting Enabled ... "); mountRegistry(); logMessage("INFO :: All Done ...!!! "); JOptionPane.showMessageDialog(null, "All Done.. !!!\nRememebr to copy mysql-connector.jar to <server>/repository/components/lib folder in both nodes.. :)"); } else { logMessage("INFO :: Registry Mounting Disabled ... "); } } catch (Exception e) { jTextArea1.append("Error occurred :: " + e.getMessage()); showErrorMessage("Error Message", e.getMessage()); } } else { showErrorMessage("Error Message", "Error extracting the zip file...!!!"); } } }//GEN-LAST:event_btnExecuteActionPerformed private void mountRegistry() throws Exception { //test DB connnection if (testDBConnection()) { //chnage master datasources.xml populateDatasourcesXML(); //change registry.xml populateRegistryXML(); //change user-mgt.xml populateUserMgtXML(); //create databases and execute mysql.sql file populateDatabases(); } } private void populateDatabases() throws Exception { //create databases; Connection con; con = DBConnection.connect(regHostName.getText(), regPort.getText(), regDbUsername.getText(), regDbPassword.getText()); populateDBWithScripts(con, ClusterConstants.USER_DB_NAME); logMessage("INFO :: Successfully configured database:" + ClusterConstants.USER_DB_NAME); populateDBWithScripts(con, ClusterConstants.REGISTRY_DB_NAME); logMessage("INFO :: Successfully configured database:" + ClusterConstants.REGISTRY_DB_NAME); populateDBWithScripts(con, ClusterConstants.LOCAL_REGISTRY1_DB_NAME); logMessage("INFO :: Successfully configured database:" + ClusterConstants.LOCAL_REGISTRY1_DB_NAME); populateDBWithScripts(con, ClusterConstants.LOCAL_REGISTRY2_DB_NAME); logMessage("INFO :: Successfully configured database:" + ClusterConstants.LOCAL_REGISTRY2_DB_NAME); } private void populateDBWithScripts(Connection con, String dbName) throws Exception { if (!DBConnection.dbAlreadyExists(con, dbName)) { DBConnection.createDatabase(con, dbName); } else { int option = JOptionPane.showConfirmDialog(null, dbName + " DB already exists and it will be Dropped...!!! ", "Warning", JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.OK_OPTION) { DBConnection.dropDatabase(con, dbName); DBConnection.createDatabase(con, dbName); } else { logMessage("ERROR :: Aborting cluster Wizard, DB Already Exists " + dbName); throw new Exception(dbName + " Already Exisits..!!!"); } } //run script file DBConnection.useDatabase(con, dbName); DBConnection.runScript(con, new File(getMgrSQLScriptFilePath())); //DBConnection.grantPermission(con, dbName, regDbUsername.getText(), regHostName.getText()); } private void populateUserMgtXML() throws Exception { String mgrUserMgtXMLFilePath = getManagerAbsConfpath() + "user-mgt.xml"; String wkrUserMgtXMLFilePath = getManagerAbsConfpath() + "user-mgt.xml"; XMLUtils.updateUserMgtXML(new File(mgrUserMgtXMLFilePath), "jdbc/WSO2UMDB"); XMLUtils.updateUserMgtXML(new File(wkrUserMgtXMLFilePath), "jdbc/WSO2UMDB"); logMessage("INFO :: Successfully configured user-mgt.xml ... "); } private void populateRegistryXML() throws Exception { String mgrRegistryXMLFilePath = getManagerAbsConfpath() + "registry.xml"; String wkrRegistryXMLFilePath = getWorkerAbsConfPath() + "registry.xml"; XMLUtils.updateRegistryXML(new File(mgrRegistryXMLFilePath), getRegistryXMLBean(false)); XMLUtils.updateRegistryXML(new File(wkrRegistryXMLFilePath), getRegistryXMLBean(true)); logMessage("INFO :: Successfully configured registry.xml ... "); } private RegistryXMLBean getRegistryXMLBean(boolean isWorkerNode) { RegistryXMLBean registryXMLBean = new RegistryXMLBean(); registryXMLBean.setDbConfigName("sharedregistry"); registryXMLBean.setDataSource("jdbc/WSO2RegistryDB"); registryXMLBean.setRemoteInstanceURL("https://localhost:9443/registry"); registryXMLBean.setRemoteInstanceID("instanceid"); registryXMLBean.setRemoteInstanceDbConfig("sharedregistry"); registryXMLBean.setRemoteInstanceReadOnly(isWorkerNode); registryXMLBean.setRemoteInstanceEnableCache(true); registryXMLBean.setRemoteInstanceRegistryRoot("/"); registryXMLBean.setRemoteInstanceCacheID(regDbUsername.getText() + "@jdbc:mysql://" + regHostName.getText() + ":" + regPort.getText() + "/" + ClusterConstants.REGISTRY_DB_NAME + "?autoReconnect=true"); registryXMLBean.setMountPathSystemOverwrite(true); registryXMLBean.setMountPathSystemConfig("/_system/config"); registryXMLBean.setMountSystemConfigInstanceID("instanceid"); registryXMLBean.setMountSystemConfigTargetPath("/_system/asNodes"); registryXMLBean.setMountPathSystemGovernance("/_system/governance"); registryXMLBean.setMountPathGovernanceOverwrite(true); registryXMLBean.setMountSystemGovernanceInstanceID("instanceid"); registryXMLBean.setMountSystemGovernanceTargetPath("/_system/governance"); return registryXMLBean; } private void populateDatasourcesXML() throws Exception { String mgrDatasourceXMLpath = getManagerAbsConfpath() + "datasources" + File.separator; String wkrDatasourceXMLpath = getWorkerAbsConfPath() + "datasources" + File.separator; XMLUtils.updataMasterDatasourcesXML(new File(mgrDatasourceXMLpath + "master-datasources.xml"), getRegistryLocal1DatasourceBean());//local-mgr XMLUtils.updataMasterDatasourcesXML(new File(wkrDatasourceXMLpath + "master-datasources.xml"), getRegistryLocal2DatasourceBean());//local-wkr XMLUtils.updataMasterDatasourcesXML(new File(mgrDatasourceXMLpath + "master-datasources.xml"), getRegistryDbDatasourceBean());//regDB-mgr XMLUtils.updataMasterDatasourcesXML(new File(wkrDatasourceXMLpath + "master-datasources.xml"), getRegistryDbDatasourceBean());//regDB-wkr XMLUtils.updataMasterDatasourcesXML(new File(mgrDatasourceXMLpath + "master-datasources.xml"), getUserDbDatasourceBean());//userDB-mgr XMLUtils.updataMasterDatasourcesXML(new File(wkrDatasourceXMLpath + "master-datasources.xml"), getUserDbDatasourceBean());//userDB-wkr logMessage("INFO :: Successfully configured master-datasources.xml ... "); } private DatasourceBean getDefaultDatasourceBean() { DatasourceBean datasourceBean = new DatasourceBean(); datasourceBean.setDriverClassName("com.mysql.jdbc.Driver"); datasourceBean.setMaxActive(50); datasourceBean.setMaxWait(60000); datasourceBean.setTestOnBorrow(true); datasourceBean.setValidationQuery("SELECT 1"); datasourceBean.setValidationInterval(30000); return datasourceBean; } private DatasourceBean getRegistryDbDatasourceBean() { DatasourceBean datasourceBean = getDefaultDatasourceBean(); datasourceBean.setName("REGISTRY_DB"); datasourceBean.setDescription("The datasource used for registry- config/governance"); datasourceBean.setJndiConfigName("jdbc/WSO2RegistryDB"); datasourceBean.setDefinitionType("RDBMS"); datasourceBean.setUrl("jdbc:mysql://" + regHostName.getText() + ":" + regPort.getText() + "/" + ClusterConstants.REGISTRY_DB_NAME + "?autoReconnect=true"); datasourceBean.setUsername(regDbUsername.getText()); datasourceBean.setPassword(regDbPassword.getText()); return datasourceBean; } private DatasourceBean getUserDbDatasourceBean() { DatasourceBean datasourceBean = getDefaultDatasourceBean(); datasourceBean.setName("WSO2_USER_DB"); datasourceBean.setDescription("The datasource used for registry and user manager"); datasourceBean.setJndiConfigName("jdbc/WSO2UMDB"); datasourceBean.setDefinitionType("RDBMS"); datasourceBean.setUrl("jdbc:mysql://" + regHostName.getText() + ":" + regPort.getText() + "/" + ClusterConstants.USER_DB_NAME); datasourceBean.setUsername(regDbUsername.getText()); datasourceBean.setPassword(regDbPassword.getText()); return datasourceBean; } private DatasourceBean getRegistryLocal1DatasourceBean() { DatasourceBean datasourceBean = getDefaultDatasourceBean(); datasourceBean.setName("REGISTRY_LOCAL1"); datasourceBean.setDescription("The datasource used for registry- local"); datasourceBean.setJndiConfigName("jdbc/WSO2CarbonDB"); datasourceBean.setDefinitionType("RDBMS"); datasourceBean.setUrl("jdbc:mysql://" + regHostName.getText() + ":" + regPort.getText() + "/" + ClusterConstants.LOCAL_REGISTRY1_DB_NAME + "?autoReconnect=true"); datasourceBean.setUsername(regDbUsername.getText()); datasourceBean.setPassword(regDbPassword.getText()); return datasourceBean; } private DatasourceBean getRegistryLocal2DatasourceBean() { DatasourceBean datasourceBean = getDefaultDatasourceBean(); datasourceBean.setName("REGISTRY_LOCAL2"); datasourceBean.setDescription("The datasource used for registry- local"); datasourceBean.setJndiConfigName("jdbc/WSO2CarbonDB"); datasourceBean.setDefinitionType("RDBMS"); datasourceBean.setUrl("jdbc:mysql://" + regHostName.getText() + ":" + regPort.getText() + "/" + ClusterConstants.LOCAL_REGISTRY1_DB_NAME + "?autoReconnect=true"); datasourceBean.setUsername(regDbUsername.getText()); datasourceBean.setPassword(regDbPassword.getText()); return datasourceBean; } private boolean testDBConnection() { boolean isConnected = false; if (enableRegistry.getSelectedItem().toString().equalsIgnoreCase("enabled")) { String host = regHostName.getText(); String port = regPort.getText(); String username = regDbUsername.getText(); String password = regDbPassword.getText(); if (host != null && !host.equals("") && username != null && port != null && !port.equals("") && !username.equals("") && password != null && !password.equals("")) { try { Connection con = DBConnection.connect(host, port, username, password); if (con != null) { isConnected = true; } } catch (Exception e) { showErrorMessage("Error Message", e.getMessage()); } } else { showErrorMessage("Error Message", "Fill all the DB details...!!!"); } } return isConnected; } private void populateAxis2XmlFiles() throws Exception { String mgrConfAbsPath = getManagerAbsConfpath() + "axis2" + File.separator; String wkrConfAbsPath = getWorkerAbsConfPath() + "axis2" + File.separator; //update manager axis2.xml XMLUtils.updateAxis2XML(new File(mgrConfAbsPath + "axis2.xml"), getManagerAxis2XMLBean()); //update worker axis2.xml XMLUtils.updateAxis2XML(new File(wkrConfAbsPath + "axis2.xml"), getWorkerAxis2XMLBean()); logMessage("INFO :: Successfully configured axis2.xml ... "); } private Axis2XMLBean getManagerAxis2XMLBean() { Axis2XMLBean managerAxis2XMLBean = new Axis2XMLBean(); managerAxis2XMLBean.setDomain(mgrDomain.getText()); managerAxis2XMLBean.setLocalMemberHost(mgrLocalMemberHost.getText()); managerAxis2XMLBean.setLocalMemberPort(Integer.parseInt(mgrLocalMemberPort.getSelectedItem().toString())); managerAxis2XMLBean.setMembershipScheme(mgrMembershipScheme.getSelectedItem().toString()); managerAxis2XMLBean.setOtherLocalMemberHost(wkrLocalMemberHost.getText()); managerAxis2XMLBean .setOtherLocalMemberPort(Integer.parseInt(wkrLocalMemberPort.getSelectedItem().toString())); //managerAxis2XMLBean.getString(); return managerAxis2XMLBean; } private Axis2XMLBean getWorkerAxis2XMLBean() { Axis2XMLBean workerAxis2XMLBean = new Axis2XMLBean(); workerAxis2XMLBean.setDomain(wkrDomain.getText()); workerAxis2XMLBean.setLocalMemberHost(wkrLocalMemberHost.getText()); workerAxis2XMLBean.setLocalMemberPort(Integer.parseInt(wkrLocalMemberPort.getSelectedItem().toString())); workerAxis2XMLBean.setMembershipScheme(wkrMembershipScheme.getSelectedItem().toString()); workerAxis2XMLBean.setOtherLocalMemberHost(mgrLocalMemberHost.getText()); workerAxis2XMLBean .setOtherLocalMemberPort(Integer.parseInt(mgrLocalMemberPort.getSelectedItem().toString())); //workerAxis2XMLBean.getString(); return workerAxis2XMLBean; } private void populateCarbonXmlFiles() throws Exception { String managerConfAbsPath = clusterAbsFolderPath + File.separator + ClusterConstants.PREFIX_MANAGER + zipFileName + File.separator + "repository" + File.separator + "conf" + File.separator; String workerConfAbsPath = clusterAbsFolderPath + File.separator + ClusterConstants.PREFIX_WORKER + zipFileName + File.separator + "repository" + File.separator + "conf" + File.separator; //update manager carbon.xml XMLUtils.updateCarbonXML(new File(managerConfAbsPath + "carbon.xml"), getManagerCarbonXMLBean()); //update worker carbon.xml XMLUtils.updateCarbonXML(new File(workerConfAbsPath + "carbon.xml"), getWorkerCarbonXMLBean()); logMessage("INFO :: Successfully configured carbon.xml ... "); } private CarbonXMLBean getManagerCarbonXMLBean() { CarbonXMLBean managerCarbonXMLBean = new CarbonXMLBean(); managerCarbonXMLBean.setHostName(txtHostName.getText()); managerCarbonXMLBean.setMgtHostName(txtMgtHostName.getText()); Integer portOffset = Integer.parseInt(mgrPortOffset.getSelectedItem().toString()); managerCarbonXMLBean.setPortOffset(portOffset); return managerCarbonXMLBean; } private CarbonXMLBean getWorkerCarbonXMLBean() { CarbonXMLBean workerCarbonXMLBean = new CarbonXMLBean(); workerCarbonXMLBean.setHostName(txtHostName.getText()); workerCarbonXMLBean.setMgtHostName(txtMgtHostName.getText()); Integer portOffset = Integer.parseInt(wkrPortOffset.getSelectedItem().toString()); workerCarbonXMLBean.setPortOffset(portOffset); return workerCarbonXMLBean; } private void showErrorMessage(String title, String message) { JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE); } private String getManagerAbsConfpath() { return clusterAbsFolderPath + File.separator + ClusterConstants.PREFIX_MANAGER + zipFileName + File.separator + "repository" + File.separator + "conf" + File.separator; } private String getWorkerAbsConfPath() { return clusterAbsFolderPath + File.separator + ClusterConstants.PREFIX_WORKER + zipFileName + File.separator + "repository" + File.separator + "conf" + File.separator; } private String getMgrSQLScriptFilePath() { return clusterAbsFolderPath + File.separator + ClusterConstants.PREFIX_MANAGER + zipFileName + File.separator + "dbscripts" + File.separator + "mysql.sql"; } private boolean checkFields() { String txtMgerDomain = mgrDomain.getText().trim(); String txtmgrLocalHost = mgrLocalMemberHost.getText().trim(); String txtmgerHost = "" + txtMgtHostName.getText().trim(); String txtWkrDomain = wkrDomain.getText().trim(); String txtwkrLocalHost = wkrLocalMemberHost.getText().trim(); String txtwkrHost = "" + txtHostName.getText().trim(); if (txtMgerDomain == null || txtMgerDomain.equals("") || txtmgrLocalHost == null || txtmgrLocalHost.equals("") || txtmgerHost == null || txtmgerHost.equals("") || txtWkrDomain == null || txtWkrDomain.equals("") || txtwkrLocalHost == null || txtwkrLocalHost.equals("") || txtwkrHost == null || txtwkrHost.equals("")) { return false; } return true; } private boolean checkRegistryFields() { if (enableRegistry.getSelectedItem().toString().equalsIgnoreCase("enabled")) { String host = regHostName.getText(); String port = regPort.getText(); String username = regDbUsername.getText(); String password = regDbPassword.getText(); if (host == null || host.equals("") || username == null || port == null || port.equals("") || username.equals("") || password == null || password.equals("")) { return false; } } return true; } private void enableRegistryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enableRegistryActionPerformed if (enableRegistry.getSelectedItem().toString().equalsIgnoreCase("disabled")) { regDbPassword.disable(); regDbUsername.disable(); regHostName.disable(); regPort.disable(); } else { regDbPassword.enable(); regDbUsername.enable(); regHostName.enable(); regPort.enable(); } }//GEN-LAST:event_enableRegistryActionPerformed private void btnTestDBConActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTestDBConActionPerformed if (testDBConnection()) { JOptionPane.showMessageDialog(null, "Connection successful...!!!"); } }//GEN-LAST:event_btnTestDBConActionPerformed private void mgrLocalMemberHostKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_mgrLocalMemberHostKeyTyped // TODO add your handling code here: wkrLocalMemberHost.setText(mgrLocalMemberHost.getText()); }//GEN-LAST:event_mgrLocalMemberHostKeyTyped private void mgrDomainKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_mgrDomainKeyTyped // TODO add your handling code here: wkrDomain.setText(mgrDomain.getText()); }//GEN-LAST:event_mgrDomainKeyTyped private void logMessage(String message) { jTextArea1.append(message + "\n"); jTextArea1.append("========================================================================" + "\n"); } /** * @param args the command line arguments */ // public static void main(String args[]) { // /* Set the Nimbus look and feel */ // //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> // /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. // * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html // */ // try { // for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { // if ("Nimbus".equals(info.getName())) { // javax.swing.UIManager.setLookAndFeel(info.getClassName()); // break; // } // } // } catch (ClassNotFoundException ex) { // java.util.logging.Logger.getLogger(ClusterWizard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); // } catch (InstantiationException ex) { // java.util.logging.Logger.getLogger(ClusterWizard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); // } catch (IllegalAccessException ex) { // java.util.logging.Logger.getLogger(ClusterWizard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); // } catch (javax.swing.UnsupportedLookAndFeelException ex) { // java.util.logging.Logger.getLogger(ClusterWizard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); // } // //</editor-fold> // // /* Create and display the form */ // java.awt.EventQueue.invokeLater(new Runnable() { // public void run() { // new ClusterWizard().setVisible(true); // } // }); // } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnExecute; private javax.swing.JButton btnExit; private javax.swing.JButton btnFolderPathSelect; private javax.swing.JButton btnTestDBCon; private javax.swing.JButton btnZipFileSelect; private javax.swing.JButton bttnClear; private javax.swing.JComboBox enableRegistry; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel16; private javax.swing.JLabel jLabel17; private javax.swing.JLabel jLabel18; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenu jMenu3; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JMenuItem jMenutemExit; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JSeparator jSeparator1; private javax.swing.JTextArea jTextArea1; private javax.swing.JPanel logPanel; private javax.swing.JPanel mainPanel; private javax.swing.JPanel managerPanel; private javax.swing.JTextField mgrDomain; private javax.swing.JTextField mgrLocalMemberHost; private javax.swing.JComboBox mgrLocalMemberPort; private javax.swing.JComboBox mgrMembershipScheme; private javax.swing.JComboBox mgrPortOffset; private javax.swing.JPasswordField regDbPassword; private javax.swing.JTextField regDbUsername; private javax.swing.JPanel regEnable; private javax.swing.JTextField regHostName; private javax.swing.JTextField regPort; private javax.swing.JLabel txddtHostName; private javax.swing.JTextField txtFolderPath; private javax.swing.JTextField txtHostName; private javax.swing.JTextField txtMgtHostName; private javax.swing.JTextField txtZipFilePath; private javax.swing.JTextField wkrDomain; private javax.swing.JTextField wkrLocalMemberHost; private javax.swing.JComboBox wkrLocalMemberPort; private javax.swing.JComboBox wkrMembershipScheme; private javax.swing.JComboBox wkrPortOffset; // End of variables declaration//GEN-END:variables }