List of usage examples for java.util Properties store
public void store(OutputStream out, String comments) throws IOException
From source file:com.tremolosecurity.provisioning.core.ProvisioningEngineImpl.java
@Override public void initScheduler() throws ProvisioningException { if (this.cfgMgr.getCfg().getProvisioning() == null || this.cfgMgr.getCfg().getProvisioning().getScheduler() == null) { logger.warn("Scheduler not defined"); return;/*from w ww.j av a2s . co m*/ } SchedulingType sct = this.cfgMgr.getCfg().getProvisioning().getScheduler(); Properties scheduleProps = new Properties(); scheduleProps.setProperty("org.quartz.scheduler.instanceName", sct.getInstanceLabel()); String instanceLabel = null; try { Enumeration<NetworkInterface> enumer = NetworkInterface.getNetworkInterfaces(); while (enumer.hasMoreElements()) { NetworkInterface ni = enumer.nextElement(); Enumeration<InetAddress> enumeri = ni.getInetAddresses(); while (enumeri.hasMoreElements()) { InetAddress addr = enumeri.nextElement(); if (addr.getHostAddress().startsWith(sct.getInstanceIPMask())) { instanceLabel = addr.getHostAddress(); } } } } catch (SocketException e) { throw new ProvisioningException("Could not read network addresses", e); } if (instanceLabel == null) { logger.warn("No IP starts with '" + sct.getInstanceIPMask() + "'"); instanceLabel = "AUTO"; } scheduleProps.setProperty("org.quartz.scheduler.instanceId", instanceLabel); scheduleProps.setProperty("org.quartz.threadPool.threadCount", Integer.toString(sct.getThreadCount())); if (sct.isUseDB()) { scheduleProps.setProperty("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX"); scheduleProps.setProperty("org.quartz.jobStore.driverDelegateClass", sct.getScheduleDB().getDelegateClassName()); scheduleProps.setProperty("org.quartz.jobStore.dataSource", "scheduleDB"); scheduleProps.setProperty("org.quartz.dataSource.scheduleDB.driver", sct.getScheduleDB().getDriver()); scheduleProps.setProperty("org.quartz.dataSource.scheduleDB.URL", sct.getScheduleDB().getUrl()); scheduleProps.setProperty("org.quartz.dataSource.scheduleDB.user", sct.getScheduleDB().getUser()); scheduleProps.setProperty("org.quartz.dataSource.scheduleDB.password", sct.getScheduleDB().getPassword()); scheduleProps.setProperty("org.quartz.dataSource.scheduleDB.maxConnections", Integer.toString(sct.getScheduleDB().getMaxConnections())); scheduleProps.setProperty("org.quartz.dataSource.scheduleDB.validationQuery", sct.getScheduleDB().getValidationQuery()); scheduleProps.setProperty("org.quartz.jobStore.useProperties", "true"); scheduleProps.setProperty("org.quartz.jobStore.isClustered", "true"); } else { scheduleProps.setProperty("org.quartz.jobStore.class", "org.quartz.simpl.RAMJobStore"); } try { /*String classpath = System.getProperty("java.class.path"); String[] classpathEntries = classpath.split(File.pathSeparator); for (String cp : classpathEntries) { System.out.println(cp); }*/ PrintStream out = new PrintStream(new FileOutputStream( System.getProperty(OpenUnisonConstants.UNISON_CONFIG_QUARTZDIR) + "/quartz.properties")); scheduleProps.store(out, "Unison internal scheduler properties"); out.flush(); out.close(); } catch (IOException e) { throw new ProvisioningException("Could not write to quartz.properties", e); } try { this.scheduler = StdSchedulerFactory.getDefaultScheduler(); this.scheduler.start(); this.cfgMgr.addThread(new StopScheduler(this.scheduler)); HashSet<String> jobKeys = new HashSet<String>(); for (JobType jobType : sct.getJob()) { jobKeys.add(jobType.getName() + "-" + jobType.getGroup()); JobKey jk = new JobKey(jobType.getName(), jobType.getGroup()); JobDetail jd = this.scheduler.getJobDetail(jk); if (jd == null) { logger.info("Adding new job '" + jobType.getName() + "' / '" + jobType.getGroup() + "'"); try { addJob(jobType, jk); } catch (ClassNotFoundException e) { throw new ProvisioningException("Could not initialize job", e); } } else { //check to see if we need to modify StringBuffer cron = new StringBuffer(); cron.append(jobType.getCronSchedule().getSeconds()).append(' ') .append(jobType.getCronSchedule().getMinutes()).append(' ') .append(jobType.getCronSchedule().getHours()).append(' ') .append(jobType.getCronSchedule().getDayOfMonth()).append(' ') .append(jobType.getCronSchedule().getMonth()).append(' ') .append(jobType.getCronSchedule().getDayOfWeek()).append(' ') .append(jobType.getCronSchedule().getYear()); Properties configProps = new Properties(); for (ParamType pt : jobType.getParam()) { configProps.setProperty(pt.getName(), pt.getValue()); } Properties jobProps = new Properties(); for (String key : jd.getJobDataMap().getKeys()) { jobProps.setProperty(key, (String) jd.getJobDataMap().getString(key)); } List<Trigger> triggers = (List<Trigger>) scheduler.getTriggersOfJob(jd.getKey()); CronTrigger trigger = (CronTrigger) triggers.get(0); if (!jobType.getClassName().equals(jd.getJobClass().getName())) { logger.info("Reloading job '" + jobType.getName() + "' / '" + jobType.getGroup() + "' - change in class name"); reloadJob(jobType, jd); } else if (!cron.toString().equalsIgnoreCase(trigger.getCronExpression())) { logger.info("Reloading job '" + jobType.getName() + "' / '" + jobType.getGroup() + "' - change in schedule"); reloadJob(jobType, jd); } else if (!configProps.equals(jobProps)) { logger.info("Reloading job '" + jobType.getName() + "' / '" + jobType.getGroup() + "' - change in properties"); reloadJob(jobType, jd); } } } for (String groupName : scheduler.getJobGroupNames()) { for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) { String jobName = jobKey.getName(); String jobGroup = jobKey.getGroup(); //get job's trigger List<Trigger> triggers = (List<Trigger>) scheduler.getTriggersOfJob(jobKey); if (!jobKeys.contains(jobName + "-" + jobGroup)) { logger.info("Removing jab '" + jobName + "' / '" + jobGroup + "'"); scheduler.deleteJob(jobKey); } } } } catch (SchedulerException e) { throw new ProvisioningException("Could not initialize scheduler", e); } catch (ClassNotFoundException e) { throw new ProvisioningException("Could not initialize scheduler", e); } }
From source file:com.athena.meerkat.controller.web.provisioning.AbstractProvisioningService.java
/** * <pre>/*from w ww. ja va2s.com*/ * generate build-ssh.properties & build.properties in job path. * </pre> * * @param tomcatConfig * @param tomcatInstance * @param session * @return */ protected File generateBuildProperties(ProvisionModel pModel, WebSocketSession session) { TomcatInstance tomcatInstance = pModel.getTomcatInstance(); DomainTomcatConfiguration tomcatConfig = pModel.getTomcatConfig(); List<TomcatConfigFile> confFiles = pModel.getConfFiles(); Server targetServer = pModel.getServer(); String serverIp = targetServer.getSshIPAddr(); MDC.put("serverIp", serverIp); List<SshAccount> accounts = (List<SshAccount>) targetServer.getSshAccounts(); String userId = accounts.get(0).getUsername(); String userPass = accounts.get(0).getPassword(); Properties prop = new Properties(); // build-ssh.properties prop.setProperty("server.ip", serverIp); prop.setProperty("server.id", String.valueOf(targetServer.getId())); prop.setProperty("server.port", String.valueOf(targetServer.getSshPort())); prop.setProperty("user.id", userId); prop.setProperty("user.passwd", userPass); prop.setProperty("key.file", commanderDir + "/ssh/svn_key.pem"); String agentDeployDir = "/home/" + userId + "/athena-meerkat-agent"; //String agentName = "athena-meerkat-agent-1.0.0-SNAPSHOT"; Properties targetProps = new Properties(); // build.properties targetProps.setProperty("agent.deploy.dir", agentDeployDir); targetProps.setProperty("agent.name", agentFileName); targetProps.setProperty("server.ant.home", agentDeployDir + "/" + agentFileName + "/apache-ant-1.9.6"); targetProps.setProperty("tomcat.down.url", tomcatDownUrl); targetProps.setProperty("meerkat.controller.host.port", controllerServerPort); if (tomcatInstance != null) { targetProps.setProperty("tomcat.instance.name", tomcatInstance.getName()); } if (tomcatConfig != null) { targetProps.setProperty("catalina.home", tomcatConfig.getCatalinaHome()); targetProps.setProperty("catalina.base", tomcatConfig.getCatalinaBase()); targetProps.setProperty("tomcat.name", getTomcatName(tomcatConfig.getTomcatVersionCd())); targetProps.setProperty("tomcat.major.ver", String.valueOf(tomcatVerProps.getTomcatMajorVersion(tomcatConfig.getTomcatVersionCd()))); targetProps.setProperty("tomcat.full.ver", getTomcatVersion(tomcatConfig.getTomcatVersionCd())); targetProps.setProperty("am.server.port", String.valueOf(tomcatConfig.getServerPort())); targetProps.setProperty("am.http.port", String.valueOf(tomcatConfig.getHttpPort())); targetProps.setProperty("am.ajp.port", String.valueOf(tomcatConfig.getAjpPort())); targetProps.setProperty("am.redirect.port", String.valueOf(tomcatConfig.getRedirectPort())); targetProps.setProperty("am.uri.encoding", tomcatConfig.getEncoding()); targetProps.setProperty("am.rmi.registry.port", String.valueOf(tomcatConfig.getRmiRegistryPort())); targetProps.setProperty("am.rmi.server.port", String.valueOf(tomcatConfig.getRmiServerPort())); targetProps.setProperty("am.ssion.timeout", String.valueOf(tomcatConfig.getSessionTimeout())); } targetProps.setProperty("am.conf.op", pModel.getConfigOP()); if (pModel.getPropsMap() != null) { targetProps.putAll(pModel.getPropsMap());// additional properties. } if (confFiles != null) { /* * used in default.xml (update-config target) */ for (TomcatConfigFile confFile : confFiles) { targetProps.setProperty(codeHandler.getFileTypeName(confFile.getFileTypeCdId()) + ".file", configFileService.getFileFullPath(confFile)); } } OutputStream output = null; File jobDir = null; try { int jobNum = getJobNumber(serverIp); targetProps.setProperty("job.number", String.valueOf(jobNum)); jobDir = makeJobDir(serverIp, jobNum); if (pModel.getTaskHistoryId() > 0) { taskService.updateTaskLogFile(pModel.getTaskHistoryId(), pModel.getTomcatInstance(), jobDir); } MDC.put("jobPath", jobDir.getAbsolutePath()); sendLog(session, jobDir.getAbsolutePath(), pModel.isLastTask()); if (CollectionUtils.isEmpty(accounts)) { throw new RuntimeException("? ssh ."); } LOGGER.debug("SERVER NAME : " + targetServer.getName()); /* * generate agentenv.sh */ if (tomcatConfig != null) { createAgentEnvSHFile(jobDir, tomcatConfig.getJavaHome(), agentDeployDir, agentFileName); generateTomcatEnvFile(jobDir, tomcatConfig, serverIp); } else { createAgentEnvSHFile(jobDir, null, agentDeployDir, agentFileName); } /* * generate build properties */ output = new FileOutputStream(jobDir.getAbsolutePath() + File.separator + "build-ssh.properties"); prop.store(output, PROPS_COMMENTS); LOGGER.debug("generated build-ssh.properties"); IOUtils.closeQuietly(output); output = new FileOutputStream(jobDir.getAbsolutePath() + File.separator + "build.properties"); targetProps.store(output, PROPS_COMMENTS); LOGGER.debug("generated build.properties"); } catch (Exception e) { LOGGER.error(e.toString(), e); throw new RuntimeException(e); } finally { IOUtils.closeQuietly(output); } return jobDir; }
From source file:edu.ucsd.library.dams.api.DAMSAPIServlet.java
public static String toProperties(Map m) { Properties props = new Properties(); Iterator keys = m.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); Object val = m.get(key); if (val instanceof Collection) { Collection col = (Collection) val; int i = 0; for (Iterator it = col.iterator(); it.hasNext(); i++) { Object o = it.next(); if (o instanceof Map) { Map valmap = (Map) o; Iterator fields = valmap.keySet().iterator(); while (fields.hasNext()) { String field = (String) fields.next(); props.put(key + "." + i + "." + field, valmap.get(field).toString()); }/*from w ww. ja va2 s. c om*/ } else { props.put(key + "." + i, o.toString()); } } } else if (val instanceof Map) { Map m2 = (Map) val; for (Iterator it = m2.keySet().iterator(); it.hasNext();) { String k2 = (String) it.next(); props.put(key + "." + k2, (String) m2.get(k2)); } } else if (val instanceof Exception) { Exception ex = (Exception) val; props.put(key + ".summary", ex.toString()); StackTraceElement[] elem = ex.getStackTrace(); for (int i = 0; i < elem.length; i++) { props.put(key + "." + i, elem[i].toString()); } } else { props.put(key, val.toString()); } } // serialize to a string String content = null; try { StringWriter sw = new StringWriter(); props.store(sw, null); content = sw.toString(); } catch (Exception ex) { content = "Error serializing properties: " + ex.toString(); log.error(content, ex); } return content; }
From source file:com.microfocus.application.automation.tools.run.RunFromFileBuilder.java
@Override public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath workspace, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws IOException { // get the mc server settings MCServerSettingsModel mcServerSettingsModel = getMCServerSettingsModel(); EnvVars env = null;/*w w w .ja v a2s . c o m*/ try { env = build.getEnvironment(listener); } catch (IOException | InterruptedException e) { listener.error("Failed loading build environment " + e); } // this is an unproper replacement to the build.getVariableResolver since workflow run won't support the // getBuildEnvironment() as written here: // https://github.com/jenkinsci/pipeline-plugin/blob/893e3484a25289c59567c6724f7ce19e3d23c6ee/DEVGUIDE // .md#variable-substitutions JSONObject jobDetails = null; String mcServerUrl = ""; // now merge them into one list Properties mergedProperties = new Properties(); if (mcServerSettingsModel != null) { mcServerUrl = mcServerSettingsModel.getProperties().getProperty("MobileHostAddress"); if (runFromFileModel.getProxySettings() == null) { jobDetails = runFromFileModel.getJobDetails(mcServerUrl, null, null, null); } else { jobDetails = runFromFileModel.getJobDetails(mcServerUrl, runFromFileModel.getProxySettings().getFsProxyAddress(), runFromFileModel.getProxySettings().getFsProxyUserName(), runFromFileModel.getProxySettings().getFsProxyPassword()); } mergedProperties.setProperty("mobileinfo", jobDetails != null ? jobDetails.toJSONString() : ""); mergedProperties.setProperty("MobileHostAddress", mcServerUrl); } if (runFromFileModel != null && StringUtils.isNotBlank(runFromFileModel.getFsPassword())) { try { String encPassword = EncryptionUtils.Encrypt(runFromFileModel.getFsPassword(), EncryptionUtils.getSecretKey()); mergedProperties.put("MobilePassword", encPassword); } catch (Exception e) { build.setResult(Result.FAILURE); listener.fatalError("problem in mobile center password encryption" + e); } } if (env == null) { listener.fatalError("Enviroment not set"); throw new IOException("Env Null - something went wrong with fetching jenkins build environment"); } if (build instanceof AbstractBuild) { VariableResolver<String> varResolver = ((AbstractBuild) build).getBuildVariableResolver(); mergedProperties.putAll(runFromFileModel.getProperties(env, varResolver)); } else { mergedProperties.putAll(runFromFileModel.getProperties(env)); } int idx = 0; for (Iterator<String> iterator = env.keySet().iterator(); iterator.hasNext();) { String key = iterator.next(); idx++; mergedProperties.put("JenkinsEnv" + idx, key + ";" + env.get(key)); } Date now = new Date(); Format formatter = new SimpleDateFormat("ddMMyyyyHHmmssSSS"); String time = formatter.format(now); // get a unique filename for the params file ParamFileName = "props" + time + ".txt"; ResultFilename = "Results" + time + ".xml"; mergedProperties.put("runType", AlmRunTypes.RunType.FileSystem.toString()); if (summaryDataLogModel != null) { summaryDataLogModel.addToProps(mergedProperties); } if (scriptRTSSetModel != null) { scriptRTSSetModel.addScriptsToProps(mergedProperties); } if (uftSettingsModel != null) { uftSettingsModel.addToProperties(mergedProperties); } mergedProperties.put("resultsFilename", ResultFilename); // parallel runner is enabled if (isParallelRunnerEnabled) { // add the parallel runner properties fileSystemTestSetModel.addTestSetProperties(mergedProperties, env); // we need to replace each mtbx test with mtbx file path for (int index = 1; index < this.fileSystemTestSetModel.getFileSystemTestSet().size(); index++) { String key = "Test" + index; String content = mergedProperties.getProperty(key + index, ""); try { replaceTestWithMtbxFile(workspace, mergedProperties, content, key, time, index); } catch (Exception e) { build.setResult(Result.FAILURE); listener.error("Failed to save MTBX file : " + e.getMessage()); } } } else { // handling mtbx file content : // If we have mtbx content - it is located in Test1 property and there is no other test properties (like // Test2 etc) // We save mtbx content in workspace and replace content of Test1 by reference to saved file // this only applies to the normal file system flow String firstTestKey = "Test1"; String firstTestContent = mergedProperties.getProperty(firstTestKey, ""); try { replaceTestWithMtbxFile(workspace, mergedProperties, firstTestContent, firstTestKey, time); } catch (Exception e) { build.setResult(Result.FAILURE); listener.error("Failed to save MTBX file : " + e.getMessage()); } } // get properties serialized into a stream ByteArrayOutputStream stream = new ByteArrayOutputStream(); try { mergedProperties.store(stream, ""); } catch (IOException e) { listener.error("Storing run variable failed: " + e); build.setResult(Result.FAILURE); } String propsSerialization = stream.toString(); FilePath CmdLineExe; try (InputStream propsStream = IOUtils.toInputStream(propsSerialization)) { // Get the URL to the Script used to run the test, which is bundled // in the plugin @SuppressWarnings("squid:S2259") URL cmdExeUrl = Jenkins.getInstance().pluginManager.uberClassLoader.getResource(HP_TOOLS_LAUNCHER_EXE); if (cmdExeUrl == null) { listener.fatalError(HP_TOOLS_LAUNCHER_EXE + " not found in resources"); return; } @SuppressWarnings("squid:S2259") URL cmdExe2Url = Jenkins.getInstance().pluginManager.uberClassLoader .getResource(LRANALYSIS_LAUNCHER_EXE); if (cmdExe2Url == null) { listener.fatalError(LRANALYSIS_LAUNCHER_EXE + "not found in resources"); return; } FilePath propsFileName = workspace.child(ParamFileName); CmdLineExe = workspace.child(HP_TOOLS_LAUNCHER_EXE); FilePath CmdLineExe2 = workspace.child(LRANALYSIS_LAUNCHER_EXE); try { // create a file for the properties file, and save the properties propsFileName.copyFrom(propsStream); // Copy the script to the project workspace CmdLineExe.copyFrom(cmdExeUrl); CmdLineExe2.copyFrom(cmdExe2Url); } catch (IOException | InterruptedException e) { build.setResult(Result.FAILURE); listener.error("Copying executable files to executing node " + e); } } try { // Run the HpToolsLauncher.exe AlmToolsUtils.runOnBuildEnv(build, launcher, listener, CmdLineExe, ParamFileName); // Has the report been successfully generated? } catch (IOException ioe) { Util.displayIOException(ioe, listener); build.setResult(Result.FAILURE); listener.error("Failed running HpToolsLauncher " + ioe); return; } catch (InterruptedException e) { build.setResult(Result.ABORTED); PrintStream out = listener.getLogger(); listener.error("Failed running HpToolsLauncher - build aborted " + e); try { AlmToolsUtils.runHpToolsAborterOnBuildEnv(build, launcher, listener, ParamFileName, workspace); } catch (IOException e1) { Util.displayIOException(e1, listener); build.setResult(Result.FAILURE); return; } catch (InterruptedException e1) { listener.error("Failed running HpToolsAborter " + e1); } out.println("Operation Was aborted by user."); } }
From source file:it.isislab.dmason.util.SystemManagement.Master.thrower.DMasonMaster.java
private void initComponents() { menuBar1 = new JMenuBar(); jMenuFile = new JMenu(); //menuItemOpen = new JMenuItem(); menuItemExit = new JMenuItem(); jMenuAbout = new JMenu(); menuItemInfo = new JMenuItem(); menuItemHelp = new JMenuItem(); panelMain = new JPanel(); jPanelContainerConnection = new JPanel(); jPanelConnection = new JPanel(); jLabelAddress = new JLabel(); textFieldAddress = new JTextField(); jLabelPort = new JLabel(); textFieldPort = new JTextField(); refreshServerLabel = new JLabel(); buttonRefreshServerLabel = new JButton(); jPanelContainerSettings = new JPanel(); jPanelSetDistribution = new JPanel(); jPanelSettings = new JPanel(); jLabelHorizontal = new JLabel(); jLabelSquare = new JLabel(); jLabelMaxDistance = new JLabel(); jLabelWidth = new JLabel(); jLabelInsertSteps = new JLabel(); textFieldMaxDistance = new JTextField(); textFieldWidth = new JTextField(); jLabelHeight = new JLabel(); textFieldHeight = new JTextField(); jLabelAgents = new JLabel(); textFieldAgents = new JTextField(); textFieldColumns = new JTextField(); textFieldRows = new JTextField(); textFieldSteps = new JTextField(); jLabelChooseSimulation = new JLabel(); jComboBoxChooseSimulation = new JComboBox(); jComboBoxNumRegionXPeer = new JComboBox(); jPanelContainerTabbedPane = new JPanel(); tabbedPane2 = new JTabbedPane(); jPanelDefault = new JPanel(); jPanelSimulation = new ModelPanel(tabbedPane2); labelSimulationConfigSet = new JLabel(); labelRegionsResume = new JLabel(); labelNumOfPeerResume = new JLabel(); labelRegForPeerResume = new JLabel(); labelWriteReg = new JLabel(); labelWriteNumOfPeer = new JLabel(); labelWriteRegForPeer = new JLabel(); labelWidthRegion = new JLabel(); labelheightRegion = new JLabel(); labelDistrMode = new JLabel(); labelWriteRegWidth = new JLabel(); labelWriteRegHeight = new JLabel(); labelWriteDistrMode = new JLabel(); graphicONcheckBox2 = new JCheckBox(); jPanelSetButton = new JPanel(); buttonSetConfigDefault = new JButton(); jPanelAdvanced = new JPanel(); jPanelAdvancedMain = new JPanel(); peerInfoStatus = new JDesktopPane(); internalFrame1 = new JInternalFrame(); architectureLabel = new JTextArea(); architectureLabel.setBackground(Color.BLACK); architectureLabel.setForeground(Color.GREEN); architectureLabel.setEditable(false); advancedConfirmBut = new JLabel(); graphicONcheckBox = new JCheckBox(); jCheckBoxLoadBalancing = new JCheckBox("Load Balancing", false); jCheckBoxLoadBalancing.setEnabled(true); jCheckBoxLoadBalancing.setSelected(false); jCheckBoxMPI = new JCheckBox("Enable MPI", false); jCheckBoxMPI.setEnabled(true);//from w ww. ja v a 2s .co m jCheckBoxMPI.setSelected(false); scrollPaneTree = new JScrollPane(); tree1 = new JTree(); buttonSetConfigAdvanced = new JButton(); jLabelPlayButton = new JLabel(); jLabelPauseButton = new JLabel(); jPanelNumStep = new JPanel(); jLabelStep = new JLabel(); jLabelStep.setHorizontalAlignment(SwingConstants.LEFT); jLabelStopButton = new JLabel(); scrollPane1 = new JScrollPane(); peerInfoStatus1 = new JDesktopPane(); root = new DefaultMutableTreeNode("Simulation"); ButtonGroup b = new ButtonGroup(); ip = textFieldAddress.getText(); port = textFieldPort.getText(); menuBar1 = new JMenuBar(); jMenuFile = new JMenu(); menuItemExit = new JMenuItem(); menuNewSim = new JMenuItem(); jMenuAbout = new JMenu(); menuItemInfo = new JMenuItem(); menuItemHelp = new JMenuItem(); scrollPane3 = new JScrollPane(); scrollPane4 = new JScrollPane(); notifyArea = new JTextArea(); panelConsole = new JPanel(); buttonSetConfigDefault2 = new JButton(); jPanelSetButton2 = new JPanel(); graphicONcheckBox = new JCheckBox(); graphicONcheckBox.setEnabled(false); graphicONcheckBox.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { withGui = graphicONcheckBox.isSelected(); } }); jLabelChooseSimulation = new JLabel(); jComboBoxChooseSimulation = new JComboBox(); loadSimulation(); selectedSimulation = ((SimComboEntry) jComboBoxChooseSimulation.getSelectedItem()).fullSimName; jPanelSimulation.updateHTML(selectedSimulation); jComboBoxChooseSimulation.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { // Prevent executing listener's actions two times if (e.getStateChange() != ItemEvent.SELECTED) return; selectedSimulation = ((SimComboEntry) jComboBoxChooseSimulation.getSelectedItem()).fullSimName; jPanelSimulation.updateHTML(selectedSimulation); isThin = isThinSimulation(selectedSimulation); jCheckBoxLoadBalancing.setSelected(false); jCheckBoxLoadBalancing.setEnabled(!isThin); initializeDefaultLabel(); } }); /*for(int i=2;i<100;i++) jComboRegions.addItem(i);*/ buttonRefreshServerLabel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { connect(); } }); refreshServerLabel.addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent arg0) { if (starter.isConnected()) starter.execute("restart"); else JOptionPane.showMessageDialog(null, "Not connected to the Server!"); } @Override public void mousePressed(MouseEvent arg0) { } @Override public void mouseExited(MouseEvent arg0) { } @Override public void mouseEntered(MouseEvent arg0) { } @Override public void mouseClicked(MouseEvent arg0) { } }); jCheckBoxLoadBalancing.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (!isHorizontal) { if (jCheckBoxLoadBalancing.isSelected()) labelWriteDistrMode.setText("SQUARE BALANCED MODE"); else labelWriteDistrMode.setText("SQUARE MODE"); } if (isHorizontal) { if (jCheckBoxLoadBalancing.isSelected()) labelWriteDistrMode.setText("HORIZONTAL BALANCED MODE"); else labelWriteDistrMode.setText("HORIZONTAL MODE"); } } }); buttonSetConfigDefault2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (initializeDefaultLabel()) submitCustomizeMode(); else JOptionPane.showMessageDialog(null, "To start a simulation must fill in all fields...!"); } }); buttonSetConfigDefault.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (initializeDefaultLabel()) submitDefaultMode(); else JOptionPane.showMessageDialog(null, "To start a simulation must fill in all fields...!"); } }); advancedConfirmBut.addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent arg0) { confirm(); res -= (Integer) jComboBoxNumRegionXPeer.getSelectedItem(); withGui = graphicONcheckBox.isSelected(); jComboBoxNumRegionXPeer.removeAllItems(); graphicONcheckBox.setSelected(false); for (int i = 1; i <= res; i++) jComboBoxNumRegionXPeer.addItem(i); JOptionPane.showMessageDialog(null, "Region assigned !"); } @Override public void mousePressed(MouseEvent arg0) { } @Override public void mouseExited(MouseEvent arg0) { } @Override public void mouseEntered(MouseEvent arg0) { } @Override public void mouseClicked(MouseEvent arg0) { } }); //======== this ======== Container contentPane = getContentPane(); //======== menuBar1 ======== { { jMenuFile.setText(" File "); menuNewSim.setText("New "); menuNewSim.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { me.dispose(); me = null; DMasonMaster p = new DMasonMaster(); p.setVisible(true); } }); jMenuFile.add(menuNewSim); //---- menuItemExit ---- menuItemExit.setText("Exit"); menuItemExit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { me.dispose(); } }); jMenuFile.add(menuItemExit); } menuBar1.add(jMenuFile); menuBar1.add(getJMenuSystem()); //======== jMenuAbout ======== { jMenuAbout.setText(" ? "); //---- menuItemInfo ---- menuItemInfo.setText("Info"); menuItemInfo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, Release.PRODUCT_RELEASE, "Info", 1); } }); jMenuAbout.add(menuItemInfo); //---- menuItenHelp ---- menuItemHelp.setText("Help"); menuItemHelp.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { try { java.net.URI uri = new java.net.URI( "http://isis.dia.unisa.it/projects/it.isislab.dmason/"); try { java.awt.Desktop.getDesktop().browse(uri); } catch (IOException e) { e.printStackTrace(); } } catch (URISyntaxException e) { e.printStackTrace(); } } }); jMenuAbout.add(menuItemHelp); } menuBar1.add(jMenuAbout); } setJMenuBar(menuBar1); //======== panelMain ======== { //======== jPanelContainerConnection ======== { //======== jPanelConnection ======== { jPanelConnection.setBorder(new TitledBorder("Connection")); jPanelConnection.setPreferredSize(new Dimension(215, 125)); //---- jLabelAddress ---- jLabelAddress.setText("IP Address :"); //---- textFieldAddress ---- textFieldAddress.setText("127.0.0.1"); //---- jLabelPort ---- jLabelPort.setText("Port :"); //---- textFieldPort ---- textFieldPort.setText("61616"); //---- refreshServerLabel ---- refreshServerLabel.setIcon(new ImageIcon("resources/image/refresh.png")); //---- buttonRefreshServerLabel ---- buttonRefreshServerLabel.setText("OK"); JLabel lblStatus = new JLabel("Communication Server status :"); lblStatusIcon = new JLabel(""); lblStatusIcon.setIcon(new ImageIcon("resources/image/status-down.png")); buttonActiveMQRestart = new JButton(""); buttonActiveMQRestart.setEnabled(false); buttonActiveMQRestart.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { notifyArea.append("ActiveMQ restarting...\n"); if (csManager.restartActiveMQ()) notifyArea.append("ActiveMQ restarted!\n"); checkCommunicationServerStatus(); } }); buttonActiveMQRestart.setMinimumSize(new Dimension(24, 24)); buttonActiveMQRestart.setMaximumSize(new Dimension(24, 24)); buttonActiveMQRestart.setPreferredSize(new Dimension(24, 24)); buttonActiveMQRestart.setIcon(new ImageIcon("resources/image/LH2 - Restart.png")); buttonActiveMQStart = new JButton(""); buttonActiveMQStart.setEnabled(false); buttonActiveMQStart.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { notifyArea.append("ActiveMQ starting...\n"); if (csManager.startActiveMQ()) notifyArea.append("ActiveMQ started!\n"); checkCommunicationServerStatus(); } }); buttonActiveMQStart.setPreferredSize(new Dimension(24, 24)); buttonActiveMQStart.setMinimumSize(new Dimension(24, 24)); buttonActiveMQStart.setMaximumSize(new Dimension(24, 24)); buttonActiveMQStart.setIcon(new ImageIcon("resources/image/LH2 - Shutdown.png")); buttonActiveMQStop = new JButton(""); buttonActiveMQStop.setEnabled(false); buttonActiveMQStop.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { notifyArea.append("ActiveMQ stopping...\n"); if (csManager.stopActiveMQ()) notifyArea.append("ActiveMQ stopped!\n"); checkCommunicationServerStatus(); } }); buttonActiveMQStop.setPreferredSize(new Dimension(24, 24)); buttonActiveMQStop.setMinimumSize(new Dimension(24, 24)); buttonActiveMQStop.setMaximumSize(new Dimension(24, 24)); buttonActiveMQStop.setIcon(new ImageIcon("resources/image/LH2 - Stop.png")); btnCheckPeers = new JButton("Check Peers"); btnCheckPeers.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { checkPeers(); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); GroupLayout jPanelConnectionLayout = new GroupLayout(jPanelConnection); jPanelConnectionLayout.setHorizontalGroup(jPanelConnectionLayout .createParallelGroup(Alignment.LEADING) .addGroup(jPanelConnectionLayout.createSequentialGroup().addGroup(jPanelConnectionLayout .createParallelGroup(Alignment.LEADING) .addGroup(jPanelConnectionLayout.createSequentialGroup() .addGroup(jPanelConnectionLayout.createParallelGroup(Alignment.TRAILING) .addComponent(refreshServerLabel) .addGroup(jPanelConnectionLayout.createSequentialGroup() .addComponent(buttonActiveMQStart, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(buttonActiveMQRestart, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(buttonActiveMQStop, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addGap(111).addComponent(jLabelAddress).addGap(18) .addComponent(textFieldAddress, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE) .addGap(18).addComponent(jLabelPort).addGap(18) .addComponent(textFieldPort, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE) .addGap(46).addComponent(buttonRefreshServerLabel))) .addGap(51).addComponent(btnCheckPeers)) .addGroup(jPanelConnectionLayout.createSequentialGroup().addComponent(lblStatus) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(lblStatusIcon))) .addContainerGap(71, Short.MAX_VALUE))); jPanelConnectionLayout.setVerticalGroup(jPanelConnectionLayout .createParallelGroup(Alignment.TRAILING) .addGroup(jPanelConnectionLayout.createSequentialGroup().addGroup(jPanelConnectionLayout .createParallelGroup(Alignment.LEADING) .addGroup(jPanelConnectionLayout.createSequentialGroup() .addGroup(jPanelConnectionLayout.createParallelGroup(Alignment.LEADING) .addComponent(lblStatus).addComponent(lblStatusIcon)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(jPanelConnectionLayout.createParallelGroup(Alignment.LEADING) .addComponent(buttonActiveMQRestart, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(buttonActiveMQStart, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(buttonActiveMQStop, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED, 1, Short.MAX_VALUE)) .addGroup(jPanelConnectionLayout.createSequentialGroup() .addContainerGap(18, Short.MAX_VALUE).addComponent(refreshServerLabel) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(jPanelConnectionLayout.createParallelGroup(Alignment.BASELINE) .addComponent(buttonRefreshServerLabel).addComponent(jLabelPort) .addComponent(textFieldPort, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE) .addComponent(jLabelAddress) .addComponent(textFieldAddress, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE) .addComponent(btnCheckPeers)))) .addGap(10))); jPanelConnectionLayout.linkSize(SwingConstants.HORIZONTAL, new Component[] { buttonActiveMQRestart, buttonActiveMQStart, buttonActiveMQStop }); jPanelConnection.setLayout(jPanelConnectionLayout); } GroupLayout jPanelContainerConnectionLayout = new GroupLayout(jPanelContainerConnection); jPanelContainerConnection.setLayout(jPanelContainerConnectionLayout); jPanelContainerConnectionLayout .setHorizontalGroup(jPanelContainerConnectionLayout.createParallelGroup() .addGroup(jPanelContainerConnectionLayout .createSequentialGroup().addContainerGap().addComponent(jPanelConnection, GroupLayout.PREFERRED_SIZE, 829, GroupLayout.PREFERRED_SIZE) .addContainerGap(153, Short.MAX_VALUE))); jPanelContainerConnectionLayout.setVerticalGroup( jPanelContainerConnectionLayout.createParallelGroup().addComponent(jPanelConnection, GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE)); } //======== jPanelContainerSettings ======== { GroupLayout jPanelContainerSettingsLayout = new GroupLayout(jPanelContainerSettings); jPanelContainerSettings.setLayout(jPanelContainerSettingsLayout); jPanelContainerSettingsLayout.setHorizontalGroup( jPanelContainerSettingsLayout.createParallelGroup().addGap(0, 1, Short.MAX_VALUE)); jPanelContainerSettingsLayout.setVerticalGroup( jPanelContainerSettingsLayout.createParallelGroup().addGap(0, 481, Short.MAX_VALUE)); } //======== jPanelSetDistribution ======== { jPanelSetDistribution.setBorder(new TitledBorder("Settings")); //======== jPanelSettings ======== { //jLabelHorizontal.setIcon(new ImageIcon("it.isislab.dmason/resources/image/hori.png"))); //---- jLabelSquare ---- //jLabelSquare.setIcon(new ImageIcon("it.isislab.dmason/resources/image/square.png"))); //---- jLabelMaxDistance ---- jLabelMaxDistance.setText("MAX_DISTANCE :"); //---- jLabelWidth ---- jLabelWidth.setText("WIDTH :"); //---- jLabelInsertSteps ---- jLabelInsertSteps.setText("STEPS :"); //---- textFieldMaxDistance ---- textFieldMaxDistance.setText("1"); //---- textFieldWidth ---- textFieldWidth.setText("200"); //---- jLabelHeight ---- jLabelHeight.setText("HEIGHT :"); //---- textFieldHeight ---- textFieldHeight.setText("200"); //---- jLabelAgents ---- jLabelAgents.setText("AGENTS :"); //---- textFieldAgents ---- textFieldAgents.setText("15"); //---- textFieldSteps textFieldSteps.setText("100"); MouseListener textFieldMouseListener = new MouseListener() { @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent e) { initializeDefaultLabel(); } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub } }; textFieldAgents.addMouseListener(textFieldMouseListener); textFieldAgents.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { char v = e.getKeyChar(); if (!(Character.isDigit(v)) || v == KeyEvent.VK_BACK_SPACE) { e.consume(); } if (textFieldAgents.getText().length() > 0) initializeDefaultLabel(); } @Override public void keyReleased(KeyEvent e) { //initializeDefaultLabel(); } @Override public void keyPressed(KeyEvent e) { } }); textFieldColumns.addMouseListener(textFieldMouseListener); textFieldColumns.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { // TODO Auto-generated method stub char v = e.getKeyChar(); if (!(Character.isDigit(v)) || v == KeyEvent.VK_BACK_SPACE) { e.consume(); } if (textFieldColumns.getText().length() > 0) initializeDefaultLabel(); } @Override public void keyReleased(KeyEvent e) { // TODO Auto-generated method stub } @Override public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub } }); textFieldMaxDistance.addMouseListener(textFieldMouseListener); textFieldMaxDistance.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { char v = e.getKeyChar(); if (!(Character.isDigit(v)) || v == KeyEvent.VK_BACK_SPACE) { e.consume(); } if (textFieldMaxDistance.getText().length() > 0) initializeDefaultLabel(); } @Override public void keyReleased(KeyEvent e) { //initializeDefaultLabel(); } @Override public void keyPressed(KeyEvent e) { } }); textFieldWidth.addMouseListener(textFieldMouseListener); textFieldWidth.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { char v = e.getKeyChar(); if (!(Character.isDigit(v)) || v == KeyEvent.VK_BACK_SPACE) { e.consume(); } if (textFieldWidth.getText().length() > 0) initializeDefaultLabel(); } @Override public void keyReleased(KeyEvent e) { //initializeDefaultLabel(); } @Override public void keyPressed(KeyEvent e) { } }); textFieldRows.addMouseListener(textFieldMouseListener); textFieldRows.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { char v = e.getKeyChar(); if (!(Character.isDigit(v)) || v == KeyEvent.VK_BACK_SPACE) { e.consume(); } if (textFieldRows.getText().length() > 0) initializeDefaultLabel(); } @Override public void keyReleased(KeyEvent e) { } @Override public void keyPressed(KeyEvent e) { } }); textFieldHeight.addMouseListener(textFieldMouseListener); textFieldHeight.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { char v = e.getKeyChar(); if (!(Character.isDigit(v)) || v == KeyEvent.VK_BACK_SPACE) { e.consume(); } if (textFieldHeight.getText().length() > 0) initializeDefaultLabel(); } @Override public void keyReleased(KeyEvent arg0) { //initializeDefaultLabel(); } @Override public void keyPressed(KeyEvent arg0) { } }); textFieldSteps.addMouseListener(textFieldMouseListener); textFieldSteps.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { char v = e.getKeyChar(); if (!(Character.isDigit(v)) || v == KeyEvent.VK_BACK_SPACE) { e.consume(); } if (textFieldSteps.getText().length() > 0) initializeDefaultLabel(); } @Override public void keyReleased(KeyEvent e) { // TODO Auto-generated method stub } @Override public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub } }); //---- jLabelChooseSimulation ---- jLabelChooseSimulation.setText("Choose your simulation:"); //---- jComboBoxChooseSimulation ---- jComboBoxChooseSimulation.setMaximumRowCount(10); JLabel lblRows = new JLabel("ROWS :"); JLabel lblColumns = new JLabel("COLUMNS :"); textFieldRows.setText("1"); textFieldRows.setEnabled(false); textFieldRows.setColumns(10); rows = Integer.parseInt(textFieldRows.getText()); textFieldColumns.setText("2"); textFieldColumns.setEnabled(false); textFieldColumns.setColumns(10); columns = Integer.parseInt(textFieldColumns.getText()); textFieldSteps.setText("100"); textFieldSteps.setEnabled(false); textFieldSteps.setColumns(10); steps = 100; GroupLayout jPanelSettingsLayout = new GroupLayout(jPanelSettings); jPanelSettingsLayout.setHorizontalGroup(jPanelSettingsLayout .createParallelGroup(Alignment.LEADING) .addGroup(jPanelSettingsLayout.createSequentialGroup().addGap(17) .addGroup(jPanelSettingsLayout.createParallelGroup(Alignment.LEADING) .addComponent(jLabelChooseSimulation, GroupLayout.PREFERRED_SIZE, 245, GroupLayout.PREFERRED_SIZE) .addGroup(jPanelSettingsLayout.createSequentialGroup().addGap(119) .addComponent(jLabelHorizontal)) .addComponent(jComboBoxChooseSimulation, GroupLayout.PREFERRED_SIZE, 214, GroupLayout.PREFERRED_SIZE) .addGroup(jPanelSettingsLayout.createSequentialGroup() .addGroup(jPanelSettingsLayout .createParallelGroup(Alignment.TRAILING) .addGroup(Alignment.LEADING, jPanelSettingsLayout .createSequentialGroup() .addGroup(jPanelSettingsLayout .createParallelGroup(Alignment.LEADING) .addComponent(lblRows, GroupLayout.PREFERRED_SIZE, 59, GroupLayout.PREFERRED_SIZE) .addComponent(lblColumns)) .addGap(60) .addGroup(jPanelSettingsLayout .createParallelGroup(Alignment.LEADING) .addComponent(jLabelSquare) .addComponent(textFieldColumns, GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE) .addComponent(textFieldRows, GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE))) .addGroup(Alignment.LEADING, jPanelSettingsLayout .createSequentialGroup() .addGroup(jPanelSettingsLayout .createParallelGroup(Alignment.LEADING) .addComponent(jLabelMaxDistance) .addComponent(jLabelWidth) .addComponent(jLabelHeight) .addComponent(jLabelAgents) .addComponent(jLabelInsertSteps) .addGap(132)) .addGroup(jPanelSettingsLayout .createParallelGroup(Alignment.LEADING) .addComponent(textFieldAgents, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE) .addComponent(textFieldHeight, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE) .addComponent(textFieldWidth, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE) .addComponent(textFieldMaxDistance, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE) .addComponent(textFieldSteps, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE) .addGap(20)))) .addGap(20))))); jPanelSettingsLayout.setVerticalGroup(jPanelSettingsLayout .createParallelGroup(Alignment.LEADING) .addGroup(jPanelSettingsLayout.createSequentialGroup().addContainerGap() .addComponent(jLabelHorizontal).addGap(41) .addGroup(jPanelSettingsLayout.createParallelGroup(Alignment.LEADING) .addComponent(jLabelSquare) .addGroup(jPanelSettingsLayout.createParallelGroup(Alignment.BASELINE) .addComponent(lblRows, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE) .addComponent(textFieldRows, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanelSettingsLayout.createParallelGroup(Alignment.BASELINE) .addComponent(textFieldColumns, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(lblColumns)) .addGap(18) .addGroup(jPanelSettingsLayout.createParallelGroup(Alignment.BASELINE) .addComponent(jLabelMaxDistance).addComponent(textFieldMaxDistance, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(jPanelSettingsLayout.createParallelGroup(Alignment.BASELINE) .addComponent(jLabelWidth, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE) .addComponent(textFieldWidth, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) .addGap(10) .addGroup(jPanelSettingsLayout.createParallelGroup(Alignment.BASELINE) .addComponent(jLabelHeight, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE) .addComponent(textFieldHeight, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(jPanelSettingsLayout.createParallelGroup(Alignment.BASELINE) .addComponent(jLabelAgents).addComponent(textFieldAgents, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) //.addGap(10) .addGroup(jPanelSettingsLayout.createParallelGroup(Alignment.BASELINE) .addComponent(jLabelInsertSteps, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE) .addComponent(textFieldSteps, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) .addGap(35).addComponent(jLabelChooseSimulation) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(jComboBoxChooseSimulation, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addGap(52))); jPanelSettings.setLayout(jPanelSettingsLayout); } //======== jPanelContainerTabbedPane ======== { //======== tabbedPane2 ======== { //======== jPanelDefault ======== { jPanelDefault.setBorder(new EtchedBorder()); jPanelDefault.setPreferredSize(new Dimension(350, 331)); //---- labelSimulationConfigSet ---- labelSimulationConfigSet.setText("Simulation Configuration Settings"); labelSimulationConfigSet.setFont(labelSimulationConfigSet.getFont().deriveFont( labelSimulationConfigSet.getFont().getStyle() | Font.BOLD, labelSimulationConfigSet.getFont().getSize() + 8f)); //---- labelRegionsResume ---- labelRegionsResume.setText("REGIONS :"); //---- labelNumOfPeerResume ---- labelNumOfPeerResume.setText("NUMBER OF PEERS :"); //---- labelRegForPeerResume ---- labelRegForPeerResume.setText("REGIONS FOR PEER :"); //---- labelWriteReg ---- labelWriteReg.setText("text"); //---- labelWriteNumOfPeer ---- labelWriteNumOfPeer.setText("text"); //---- labelWriteRegForPeer ---- labelWriteRegForPeer.setText("text"); //---- labelWidthRegion ---- labelWidthRegion.setText("REGION WIDTH :"); //---- labelheightRegion ---- labelheightRegion.setText("REGION HEIGHT :"); //---- labelDistrMode ---- labelDistrMode.setText("DISTRIBUTION MODE :"); //---- labelWriteRegWidth ---- labelWriteRegWidth.setText("text"); //---- labelWriteRegHeight ---- labelWriteRegHeight.setText("text"); //---- labelWriteDistrMode ---- labelWriteDistrMode.setText("text"); //---- graphicONcheckBox2 ---- graphicONcheckBox2.setText("Graphic ON"); //======== jPanelSetButton ======== { //---- buttonSetConfigDefault ---- buttonSetConfigDefault.setText("Set"); { jCheckBoxLoadBalancing.setText("Load Balancing"); } GroupLayout jPanelSetButtonLayout = new GroupLayout(jPanelSetButton); jPanelSetButton.setLayout(jPanelSetButtonLayout); jPanelSetButtonLayout.setVerticalGroup(jPanelSetButtonLayout.createSequentialGroup() .addGroup(jPanelSetButtonLayout.createParallelGroup().addGroup( GroupLayout.Alignment.TRAILING, jPanelSetButtonLayout.createSequentialGroup().addComponent( jCheckBoxMPI, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE))) .addGroup(jPanelSetButtonLayout.createParallelGroup() .addGroup(GroupLayout.Alignment.LEADING, jPanelSetButtonLayout.createSequentialGroup().addComponent( jCheckBoxLoadBalancing, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)) .addGroup(GroupLayout.Alignment.LEADING, jPanelSetButtonLayout .createSequentialGroup() .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 0, Short.MAX_VALUE) .addComponent(buttonSetConfigDefault, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))) .addContainerGap()); jPanelSetButtonLayout.setHorizontalGroup(jPanelSetButtonLayout .createSequentialGroup() .addComponent(jCheckBoxMPI, GroupLayout.PREFERRED_SIZE, 120, GroupLayout.PREFERRED_SIZE) .addContainerGap(0, 0) .addComponent(jCheckBoxLoadBalancing, GroupLayout.PREFERRED_SIZE, 114, GroupLayout.PREFERRED_SIZE) .addGap(0, 150, Short.MAX_VALUE).addComponent(buttonSetConfigDefault, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE) .addContainerGap(0, 0)); FlowLayout lsetbutt = new FlowLayout(); lsetbutt.addLayoutComponent("", jCheckBoxMPI); lsetbutt.addLayoutComponent("", jCheckBoxLoadBalancing); lsetbutt.addLayoutComponent("", buttonSetConfigDefault); jPanelSetButton.setLayout(lsetbutt); } GroupLayout jPanelDefaultLayout = new GroupLayout(jPanelDefault); jPanelDefaultLayout.setHorizontalGroup(jPanelDefaultLayout .createParallelGroup(Alignment.LEADING) .addGroup(jPanelDefaultLayout.createSequentialGroup().addContainerGap() .addGroup(jPanelDefaultLayout.createParallelGroup(Alignment.LEADING) .addComponent(labelSimulationConfigSet, GroupLayout.DEFAULT_SIZE, 478, Short.MAX_VALUE) .addGroup(jPanelDefaultLayout.createSequentialGroup().addGap(6) .addGroup(jPanelDefaultLayout .createParallelGroup(Alignment.LEADING) .addGroup(jPanelDefaultLayout .createSequentialGroup() .addGroup(jPanelDefaultLayout .createParallelGroup( Alignment.LEADING) .addComponent( labelNumOfPeerResume) .addComponent( labelRegForPeerResume) .addComponent(labelWidthRegion) .addComponent(labelheightRegion) .addComponent(labelDistrMode) .addComponent( labelRegionsResume)) .addPreferredGap( ComponentPlacement.RELATED, 218, Short.MAX_VALUE) .addGroup(jPanelDefaultLayout .createParallelGroup( Alignment.LEADING) .addComponent( labelWriteNumOfPeer, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE) .addComponent(labelWriteReg) .addComponent( labelWriteRegForPeer) .addComponent( labelWriteRegWidth) .addComponent( labelWriteRegHeight) .addComponent( labelWriteDistrMode)) .addGap(118)) .addComponent(graphicONcheckBox2)))) .addGap(211)) .addGroup(jPanelDefaultLayout.createSequentialGroup() .addComponent(jPanelSetButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addContainerGap(23, Short.MAX_VALUE))); jPanelDefaultLayout.setVerticalGroup(jPanelDefaultLayout .createParallelGroup(Alignment.LEADING) .addGroup(jPanelDefaultLayout.createSequentialGroup().addContainerGap() .addComponent(labelSimulationConfigSet, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE) .addGap(28) .addGroup(jPanelDefaultLayout.createParallelGroup(Alignment.TRAILING) .addGroup(jPanelDefaultLayout.createSequentialGroup() .addComponent(labelRegionsResume) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(labelNumOfPeerResume) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(labelRegForPeerResume).addGap(6) .addComponent(labelWidthRegion).addGap(6) .addComponent(labelheightRegion) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(labelDistrMode)) .addGroup(jPanelDefaultLayout.createSequentialGroup() .addComponent(labelWriteReg) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(labelWriteNumOfPeer) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(labelWriteRegForPeer).addGap(6) .addComponent(labelWriteRegWidth).addGap(6) .addComponent(labelWriteRegHeight) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(labelWriteDistrMode, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE) .addGap(8))) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(graphicONcheckBox2) .addPreferredGap(ComponentPlacement.RELATED, 82, Short.MAX_VALUE) .addComponent(jPanelSetButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))); jPanelDefault.setLayout(jPanelDefaultLayout); } tabbedPane2.addTab("Default", jPanelDefault); //======== jPanelSimulation ======== tabbedPane2.addTab("Simulation", jPanelSimulation); //======== End jPanelSimulation ======== //======== jPanelAdvanced ======== { jPanelAdvanced.setBorder(new EtchedBorder()); //======== jPanelAdvancedMain ======== { //======== scrollPaneTree ======== { //---- tree1 ---- tree1.setModel(new DefaultTreeModel(root)); DefaultTreeCellRenderer render = new DefaultTreeCellRenderer(); render.setOpenIcon(new ImageIcon("resources/image/network.png")); render.setLeafIcon(new ImageIcon("esource/image/computer.gif")); render.setClosedIcon(new ImageIcon("resources/image/network.png")); tree1.setCellRenderer(render); tree1.setRowHeight(25); scrollPaneTree.setViewportView(tree1); tree1.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent arg0) { if (arg0.getPath().getLastPathComponent().equals(root)) { jComboBoxNumRegionXPeer.setEnabled(true); advancedConfirmBut.setEnabled(true); graphicONcheckBox.setEnabled(true); total = Integer.parseInt(textFieldRows.getText()) * Integer.parseInt(textFieldColumns.getText()); //(Integer)jComboRegions.getSelectedItem(); res = total; jComboBoxNumRegionXPeer.removeAllItems(); for (int i = 1; i < res; i++) jComboBoxNumRegionXPeer.addItem(i); } else clickTreeListener(); } }); } //======== peerInfoStatus ======== { peerInfoStatus.setBorder(new TitledBorder("Settings")); peerInfoStatus.setBackground(Color.lightGray); //======== peerInfoStatus1 ======== { peerInfoStatus1.setBackground(Color.lightGray); peerInfoStatus1.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); peerInfoStatus1.setBorder(null); //======== internalFrame1 ======== { internalFrame1.setVisible(true); Container internalFrame1ContentPane = internalFrame1.getContentPane(); //======== scrollPane1 ======== { //---- label8 ---- architectureLabel.setText("Architecture Information"); scrollPane1.setViewportView(architectureLabel); } GroupLayout internalFrame1ContentPaneLayout = new GroupLayout( internalFrame1ContentPane); internalFrame1ContentPane.setLayout(internalFrame1ContentPaneLayout); internalFrame1ContentPaneLayout.setHorizontalGroup( internalFrame1ContentPaneLayout.createParallelGroup() .addGroup(internalFrame1ContentPaneLayout .createSequentialGroup().addContainerGap() .addComponent(scrollPane1, GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE) .addContainerGap())); internalFrame1ContentPaneLayout.setVerticalGroup( internalFrame1ContentPaneLayout.createParallelGroup() .addGroup(internalFrame1ContentPaneLayout .createSequentialGroup().addContainerGap() .addComponent(scrollPane1, GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE) .addContainerGap())); } peerInfoStatus1.add(internalFrame1, JLayeredPane.DEFAULT_LAYER); internalFrame1.setBounds(15, 0, 365, 160); } //---- graphicONcheckBox ---- graphicONcheckBox.setText("Graphic ON"); //---- advancedConfirmBut ---- advancedConfirmBut.setIcon(new ImageIcon("resources/image/ok.png")); GroupLayout peerInfoStatusLayout = new GroupLayout(peerInfoStatus); peerInfoStatus.setLayout(peerInfoStatusLayout); peerInfoStatusLayout.setHorizontalGroup(peerInfoStatusLayout .createParallelGroup() .addGroup(peerInfoStatusLayout.createSequentialGroup() .addGroup(peerInfoStatusLayout.createParallelGroup() .addGroup(peerInfoStatusLayout.createSequentialGroup() .addGap(26, 26, 26) .addComponent(graphicONcheckBox) .addGap(73, 73, 73) .addComponent(jComboBoxNumRegionXPeer, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addGap(80, 80, 80) .addComponent(advancedConfirmBut, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE)) .addGroup(peerInfoStatusLayout.createSequentialGroup() .addContainerGap().addComponent(peerInfoStatus1, GroupLayout.DEFAULT_SIZE, 387, Short.MAX_VALUE))) .addContainerGap())); peerInfoStatusLayout.setVerticalGroup(peerInfoStatusLayout.createParallelGroup() .addGroup(peerInfoStatusLayout.createSequentialGroup() .addComponent(peerInfoStatus1, GroupLayout.PREFERRED_SIZE, 175, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(peerInfoStatusLayout .createParallelGroup(GroupLayout.Alignment.TRAILING) .addGroup(GroupLayout.Alignment.LEADING, peerInfoStatusLayout .createParallelGroup( GroupLayout.Alignment.BASELINE) .addComponent(graphicONcheckBox) .addComponent(jComboBoxNumRegionXPeer, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addComponent(advancedConfirmBut, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)) .addContainerGap(16, Short.MAX_VALUE))); } GroupLayout jPanelAdvancedMainLayout = new GroupLayout(jPanelAdvancedMain); jPanelAdvancedMain.setLayout(jPanelAdvancedMainLayout); jPanelAdvancedMainLayout.setHorizontalGroup(jPanelAdvancedMainLayout .createParallelGroup() .addGroup(jPanelAdvancedMainLayout.createSequentialGroup().addContainerGap() .addComponent(scrollPaneTree, GroupLayout.PREFERRED_SIZE, 207, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(peerInfoStatus, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())); jPanelAdvancedMainLayout.setVerticalGroup(jPanelAdvancedMainLayout .createParallelGroup() .addGroup(GroupLayout.Alignment.TRAILING, jPanelAdvancedMainLayout .createSequentialGroup().addContainerGap() .addGroup(jPanelAdvancedMainLayout .createParallelGroup(GroupLayout.Alignment.TRAILING) .addComponent(peerInfoStatus, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(scrollPaneTree, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE)) .addContainerGap())); } //======== jPanelSetButton2 ======== { //---- buttonSetConfigDefault2 ---- buttonSetConfigDefault2.setText("Set"); GroupLayout jPanelSetButton2Layout = new GroupLayout(jPanelSetButton2); jPanelSetButton2.setLayout(jPanelSetButton2Layout); jPanelSetButton2Layout.setHorizontalGroup(jPanelSetButton2Layout .createParallelGroup().addGroup(GroupLayout.Alignment.TRAILING, jPanelSetButton2Layout.createSequentialGroup() .addContainerGap(522, Short.MAX_VALUE) .addComponent(buttonSetConfigDefault2, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE) .addGap(72, 72, 72))); jPanelSetButton2Layout.setVerticalGroup(jPanelSetButton2Layout.createParallelGroup() .addGroup(GroupLayout.Alignment.TRAILING, jPanelSetButton2Layout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonSetConfigDefault2).addContainerGap())); } GroupLayout jPanelAdvancedLayout = new GroupLayout(jPanelAdvanced); jPanelAdvancedLayout.setHorizontalGroup(jPanelAdvancedLayout .createParallelGroup(Alignment.LEADING) .addGroup(jPanelAdvancedLayout.createSequentialGroup() .addGroup(jPanelAdvancedLayout.createParallelGroup(Alignment.LEADING) .addComponent(jPanelAdvancedMain, GroupLayout.DEFAULT_SIZE, 689, Short.MAX_VALUE) .addComponent(jPanelSetButton2, GroupLayout.PREFERRED_SIZE, 681, GroupLayout.PREFERRED_SIZE)) .addContainerGap())); jPanelAdvancedLayout.setVerticalGroup(jPanelAdvancedLayout .createParallelGroup(Alignment.TRAILING) .addGroup(jPanelAdvancedLayout.createSequentialGroup().addContainerGap() .addComponent(jPanelAdvancedMain, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addGap(18).addComponent(jPanelSetButton2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))); jPanelAdvanced.setLayout(jPanelAdvancedLayout); } tabbedPane2.addTab("Advanced", jPanelAdvanced); } //======== panelConsole ======== { //======== scrollPane3 ======== { //---- textField1 ---- notifyArea.setEditable(false); DefaultCaret caret = (DefaultCaret) notifyArea.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); scrollPane3.setViewportView(notifyArea); } GroupLayout panelConsoleLayout = new GroupLayout(panelConsole); panelConsole.setLayout(panelConsoleLayout); panelConsoleLayout.setHorizontalGroup(panelConsoleLayout.createParallelGroup() .addGroup(panelConsoleLayout.createParallelGroup() .addGroup(panelConsoleLayout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent(scrollPane3, GroupLayout.PREFERRED_SIZE, 679, GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addGap(0, 679, Short.MAX_VALUE)); panelConsoleLayout.setVerticalGroup(panelConsoleLayout.createParallelGroup() .addGroup(panelConsoleLayout.createParallelGroup() .addGroup(panelConsoleLayout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent(scrollPane3, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addGap(0, 76, Short.MAX_VALUE)); } GroupLayout jPanelContainerTabbedPaneLayout = new GroupLayout(jPanelContainerTabbedPane); jPanelContainerTabbedPaneLayout.setHorizontalGroup(jPanelContainerTabbedPaneLayout .createParallelGroup(Alignment.LEADING) .addGroup(jPanelContainerTabbedPaneLayout.createSequentialGroup().addContainerGap() .addGroup(jPanelContainerTabbedPaneLayout.createParallelGroup(Alignment.LEADING) .addComponent(tabbedPane2, GroupLayout.PREFERRED_SIZE, 686, GroupLayout.PREFERRED_SIZE) .addComponent(panelConsole, GroupLayout.DEFAULT_SIZE, 708, Short.MAX_VALUE)) .addContainerGap())); jPanelContainerTabbedPaneLayout.setVerticalGroup(jPanelContainerTabbedPaneLayout .createParallelGroup(Alignment.LEADING) .addGroup(jPanelContainerTabbedPaneLayout.createSequentialGroup().addGap(3) .addComponent(tabbedPane2, GroupLayout.PREFERRED_SIZE, 384, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(panelConsole, GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE))); jPanelContainerTabbedPane.setLayout(jPanelContainerTabbedPaneLayout); } { jPanelDeploying = new JPanel(); tabbedPane2.addTab("Simulation Jar", null, jPanelDeploying, null); GroupLayout jPanelDeployingLayout = new GroupLayout(jPanelDeploying); jPanelDeploying.setLayout(jPanelDeployingLayout); { jButtonLoadJar = new JButton(); jButtonLoadJar.setText("Load Jar"); jButtonLoadJar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { if (simulationFile != null) { File dest = new File(FTP_HOME + dirSeparator + SIMULATION_DIR + dirSeparator + simulationFile.getName()); try { FileUtils.copyFile(simulationFile, dest); Digester dg = new Digester(DigestAlgorithm.MD5); InputStream in = new FileInputStream(dest); Properties prop = new Properties(); try { prop.setProperty("MD5", dg.getDigest(in)); String fileName = FilenameUtils .removeExtension(simulationFile.getName()); //save properties to project root folder prop.store(new FileOutputStream(FTP_HOME + dirSeparator + SIMULATION_DIR + dirSeparator + fileName + ".hash"), null); } catch (IOException ex) { ex.printStackTrace(); } System.out.println("MD5: " + dg.getDigest(in)); loadSimulation(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }); } jPanelDeployingLayout.setVerticalGroup(jPanelDeployingLayout.createSequentialGroup() .addGap(22, 22, 22) .addGroup(jPanelDeployingLayout.createParallelGroup().addGroup( GroupLayout.Alignment.LEADING, jPanelDeployingLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(jButtonLoadJar, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(getJTextFieldPathSimJar(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)) .addComponent(getJButtonChoseSimJar(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 286, GroupLayout.PREFERRED_SIZE)); jPanelDeployingLayout .setHorizontalGroup(jPanelDeployingLayout.createSequentialGroup().addGap(22, 22, 22) .addComponent(getJTextFieldPathSimJar(), GroupLayout.PREFERRED_SIZE, 202, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(getJButtonChoseSimJar(), GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE) .addGap(24) .addComponent(jButtonLoadJar, GroupLayout.PREFERRED_SIZE, 146, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 155, Short.MAX_VALUE)); } jPanelRunBatchTests = new JPanel(); tabbedPane2.addTab("Run batch tests", null, jPanelRunBatchTests, null); JLabel lblSelectConfigurationFile = new JLabel("Select configuration file:"); textFieldConfigFilePath = new JTextField(); textFieldConfigFilePath.setColumns(10); JButton buttonChooseConfigFile = new JButton(); buttonChooseConfigFile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { configFile = showFileChooser(); if (configFile != null) textFieldConfigFilePath.setText(configFile.getAbsolutePath()); } }); buttonChooseConfigFile.setIcon(new ImageIcon("it/isislab/dmason/resources/image/openFolder.png")); JButton buttonLoadConfig = new JButton("Start"); buttonLoadConfig.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { if (configFile.getName().contains(".xml")) { ClassLoader.getSystemClassLoader(); //File xsd = new File(xsdFilename); InputStream xsd = new FileInputStream("resources/batch/batchSchema.xsd"); if (xsd != null) { if (validateXML(configFile, xsd)) { Batch batch = loadConfigFromXML(configFile); if (batch != null) { textAreaBatchInfo.append(configFile.getName() + " loaded.\n"); if (batch.getNeededWorkers() > peers.size() || batch.getNeededWorkers() == 0) JOptionPane.showMessageDialog(DMasonMaster.this, "There are not enough workers to start the simulation"); else { textAreaBatchInfo .append("Simulation: " + batch.getSimulationName() + "\n"); textAreaBatchInfo.append( "Needed Worker: " + batch.getNeededWorkers() + "\n"); textAreaBatchInfo.append("Balance: " + batch.isBalanced() + "\n"); Set<List<EntryParam<String, Object>>> testList = generateTestsFrom( batch); textAreaBatchInfo .append("--------------------------------------\n"); textAreaBatchInfo .append("Number of experiments: " + testList.size() + "\n"); ConcurrentLinkedQueue<List<EntryParam<String, Object>>> testQueue = new ConcurrentLinkedQueue<List<EntryParam<String, Object>>>(); for (List<EntryParam<String, Object>> test : testList) testQueue.offer(test); //System.out.println("Test queue: "+testQueue.size()); try { List<List<EntryWorkerScore<Integer, String>>> workersPartition = Util .chopped(scoreList, batch.getNeededWorkers()); //System.out.println(workersPartition.toString()); testCount.set(0); totalTests = testList.size(); progressBarBatchTest.setValue(0); progressBarBatchTest.setString("0 %"); progressBarBatchTest.setStringPainted(true); batchLogger = Logger .getLogger(BatchExecutor.class.getCanonicalName()); batchStartedTime = System.currentTimeMillis(); textAreaBatchInfo.append("Batch started at: " + Util.getCurrentDateTime(batchStartedTime) + "\n"); textAreaBatchInfo .append("--------------------------------------\n"); batchLogger.debug("Started at: " + batchStartedTime); int i = 1; BatchExecutor batchExec; for (List<EntryWorkerScore<Integer, String>> workers : workersPartition) { try { batchExec = new BatchExecutor(batch.getSimulationName(), batch.isBalanced(), testQueue, master, connection, root.getChildCount(), getFPTAddress(), workers, "Batch" + i, 1, textAreaBatchInfo); batchExec.getObservable() .addObserver(DMasonMaster.this); batchExec.start(); //Thread.sleep(2000); //textAreaBatchInfo.append("Batch Executor "+i+" started\n"); i++; //not paraller simulation, I use only one batch executor if (!chckbxParallelBatch.isSelected()) break; } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } catch (Exception e3) { // TODO Auto-generated catch block e3.printStackTrace(); } } } else JOptionPane.showMessageDialog(DMasonMaster.this, "Error when loading config file"); } else JOptionPane.showMessageDialog(DMasonMaster.this, "The configuration file is not a valid file"); } else JOptionPane.showMessageDialog(DMasonMaster.this, xsdFilename + " not exists, can't validate configuration file."); } else JOptionPane.showMessageDialog(DMasonMaster.this, "The file " + configFile.getName() + "is not a configuration file."); } catch (HeadlessException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); JPanel panel = new JPanel(); panel.setBorder( new TitledBorder(null, "Batch Status", TitledBorder.LEADING, TitledBorder.TOP, null, null)); chckbxParallelBatch = new JCheckBox("Parallel Batch"); GroupLayout gl_jPanelRunBatchTests = new GroupLayout(jPanelRunBatchTests); gl_jPanelRunBatchTests.setHorizontalGroup(gl_jPanelRunBatchTests .createParallelGroup(Alignment.LEADING) .addGroup(gl_jPanelRunBatchTests.createSequentialGroup().addContainerGap() .addGroup(gl_jPanelRunBatchTests.createParallelGroup(Alignment.LEADING) .addGroup(gl_jPanelRunBatchTests.createSequentialGroup() .addComponent(lblSelectConfigurationFile, GroupLayout.PREFERRED_SIZE, 139, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(textFieldConfigFilePath, GroupLayout.PREFERRED_SIZE, 250, GroupLayout.PREFERRED_SIZE) .addGap(10).addComponent(buttonChooseConfigFile, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)) .addGroup(gl_jPanelRunBatchTests.createSequentialGroup() .addComponent(chckbxParallelBatch).addGap(18) .addComponent(buttonLoadConfig)) .addComponent(panel, GroupLayout.PREFERRED_SIZE, 666, GroupLayout.PREFERRED_SIZE)) .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); gl_jPanelRunBatchTests.setVerticalGroup(gl_jPanelRunBatchTests .createParallelGroup(Alignment.LEADING) .addGroup(gl_jPanelRunBatchTests.createSequentialGroup().addContainerGap() .addGroup(gl_jPanelRunBatchTests.createParallelGroup(Alignment.TRAILING) .addComponent(buttonChooseConfigFile, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE) .addComponent(textFieldConfigFilePath, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(lblSelectConfigurationFile)) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(gl_jPanelRunBatchTests.createParallelGroup(Alignment.BASELINE) .addComponent(chckbxParallelBatch).addComponent(buttonLoadConfig)) .addPreferredGap(ComponentPlacement.RELATED, 14, Short.MAX_VALUE) .addComponent(panel, GroupLayout.PREFERRED_SIZE, 261, GroupLayout.PREFERRED_SIZE) .addContainerGap())); progressBarBatchTest = new JProgressBar(); JLabel lblProgress = new JLabel("Progress:"); GroupLayout gl_panel = new GroupLayout(panel); gl_panel.setHorizontalGroup(gl_panel.createParallelGroup(Alignment.LEADING).addGroup(gl_panel .createSequentialGroup().addContainerGap() .addGroup(gl_panel.createParallelGroup(Alignment.LEADING) .addComponent(scrollPane4, GroupLayout.DEFAULT_SIZE, 641, Short.MAX_VALUE) .addGroup(gl_panel.createSequentialGroup().addComponent(lblProgress).addGap(18) .addComponent(progressBarBatchTest, GroupLayout.PREFERRED_SIZE, 169, GroupLayout.PREFERRED_SIZE))) .addContainerGap())); gl_panel.setVerticalGroup(gl_panel.createParallelGroup(Alignment.LEADING) .addGroup(gl_panel.createSequentialGroup().addContainerGap() .addGroup(gl_panel.createParallelGroup(Alignment.LEADING).addComponent(lblProgress) .addComponent(progressBarBatchTest, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(scrollPane4, GroupLayout.PREFERRED_SIZE, 202, GroupLayout.PREFERRED_SIZE) .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); panel.setLayout(gl_panel); jPanelRunBatchTests.setLayout(gl_jPanelRunBatchTests); GroupLayout jPanelSetDistributionLayout = new GroupLayout(jPanelSetDistribution); jPanelSetDistributionLayout .setHorizontalGroup( jPanelSetDistributionLayout.createParallelGroup(Alignment.LEADING) .addGroup(jPanelSetDistributionLayout.createSequentialGroup() .addComponent(jPanelSettings, GroupLayout.PREFERRED_SIZE, 254, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(jPanelContainerTabbedPane, GroupLayout.PREFERRED_SIZE, 707, GroupLayout.PREFERRED_SIZE) .addContainerGap(21, Short.MAX_VALUE))); jPanelSetDistributionLayout.setVerticalGroup(jPanelSetDistributionLayout .createParallelGroup(Alignment.LEADING) .addGroup(jPanelSetDistributionLayout.createSequentialGroup() .addGroup(jPanelSetDistributionLayout.createParallelGroup(Alignment.LEADING) .addComponent(jPanelSettings, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(jPanelContainerTabbedPane, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap())); jPanelSetDistribution.setLayout(jPanelSetDistributionLayout); } textAreaBatchInfo = new JTextArea(); textAreaBatchInfo.setEditable(false); DefaultCaret caret = (DefaultCaret) textAreaBatchInfo.getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); scrollPane4.setViewportView(textAreaBatchInfo); //---- jLabelPlayButton ---- jLabelPlayButton.setIcon(new ImageIcon("resources/image/NotStopped.png")); //---- jLabelPauseButton ---- jLabelPauseButton.setIcon(new ImageIcon("resources/image/PauseOff.png")); //---- labelStopButton ---- jLabelPlayButton.setIcon(new ImageIcon("image/NotPlaying.png")); jLabelPlayButton.addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent arg0) { } @Override public void mousePressed(MouseEvent arg0) { } @Override public void mouseExited(MouseEvent arg0) { } @Override public void mouseEntered(MouseEvent arg0) { } @Override public void mouseClicked(MouseEvent arg0) { jLabelPlayButton.setIcon(new ImageIcon("resources/image/Playing.png")); jLabelPauseButton.setIcon(new ImageIcon("resources/image/PauseOff.png")); jLabelStopButton.setIcon(new ImageIcon("resources/image/NotStopped.png")); jLabelResetButton.setIcon(new ImageIcon("resources/image/NotReload.png")); try { master.play(); } catch (Exception e) { e.printStackTrace(); } } }); //---- labelStopButton2 ---- jLabelStopButton.setIcon(new ImageIcon("resources/image/NotStopped.png")); jLabelStopButton.addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseClicked(MouseEvent e) { jLabelStopButton.setIcon(new ImageIcon("resources/image/Stopped.png")); jLabelPlayButton.setIcon(new ImageIcon("resources/image/NotPlaying.png")); jLabelPauseButton.setIcon(new ImageIcon("resources/image/PauseOff.png")); try { Address FTPAddress = getFPTAddress(); if (FTPAddress != null) { UpdateData ud = new UpdateData("", FTPAddress); master.stop(ud); } } catch (Exception e1) { e1.printStackTrace(); } } }); //---- labelPauseButton ---- jLabelPauseButton.setIcon(new ImageIcon("resources/image/PauseOff.png")); jLabelPauseButton.addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseClicked(MouseEvent e) { jLabelPauseButton.setIcon(new ImageIcon("resources/image/PauseOn.png")); jLabelStopButton.setIcon(new ImageIcon("resources/image/NotStopped.png")); jLabelPlayButton.setIcon(new ImageIcon("resources/image/NotPlaying.png")); try { master.pause(); } catch (Exception e1) { e1.printStackTrace(); } } }); //======== jPanelNumStep ======== { GroupLayout jPanelNumStepLayout = new GroupLayout(jPanelNumStep); jPanelNumStepLayout.setHorizontalGroup( jPanelNumStepLayout.createParallelGroup(Alignment.TRAILING).addGap(0, 25, Short.MAX_VALUE)); jPanelNumStepLayout.setVerticalGroup( jPanelNumStepLayout.createParallelGroup(Alignment.LEADING).addGap(0, 28, Short.MAX_VALUE)); jPanelNumStep.setLayout(jPanelNumStepLayout); jPanelNumStep.setPreferredSize(new java.awt.Dimension(89, 23)); } { jLabelResetButton = new JLabel(); jLabelResetButton.setIcon(new ImageIcon("resources/image/NotReload.png")); jLabelResetButton.setPreferredSize(new java.awt.Dimension(20, 20)); jLabelResetButton.setVisible(enableReset); } // for resetting simulation jLabelResetButton.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent arg0) { if (connected) { jLabelStopButton.setIcon(new ImageIcon("resources/image/NotStopped.png")); jLabelPlayButton.setIcon(new ImageIcon("resources/image/NotPlaying.png")); jLabelPauseButton.setIcon(new ImageIcon("resources/image/PauseOff.png")); jLabelResetButton.setIcon(new ImageIcon("resources/image/Reload.png")); //send message to workers for resetting simulation try { master.reset(); } catch (Exception e1) { e1.printStackTrace(); } //clean up topic from AcitveMQ connection.resetTopic(); setSystemSettingsEnabled(true); notifyArea.append("Simulation resetted\n"); } } @Override public void mouseEntered(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent arg0) { // TODO Auto-generated method stub } }); writeStepLabel = new JLabel(); writeStepLabel.setText("0"); lblTotalSteps = new JLabel("Steps:"); GroupLayout panelMainLayout = new GroupLayout(panelMain); panelMainLayout.setHorizontalGroup(panelMainLayout.createParallelGroup(Alignment.LEADING) .addGroup(panelMainLayout.createSequentialGroup() .addComponent(jPanelContainerSettings, GroupLayout.PREFERRED_SIZE, 0, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(panelMainLayout.createParallelGroup(Alignment.LEADING) .addComponent(jPanelSetDistribution, 0, 986, Short.MAX_VALUE) .addGroup(panelMainLayout.createSequentialGroup().addGap(636) .addGroup(panelMainLayout.createParallelGroup(Alignment.TRAILING) .addComponent(jLabelStep, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addGroup(panelMainLayout.createSequentialGroup() .addComponent(lblTotalSteps) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(writeStepLabel))) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(jPanelNumStep, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE) .addGroup(panelMainLayout.createParallelGroup(Alignment.LEADING) .addGroup(panelMainLayout.createSequentialGroup().addGap(24) .addComponent(jLabelPlayButton, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(jLabelPauseButton, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(jLabelStopButton, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)) .addGroup(panelMainLayout.createSequentialGroup().addGap(116) .addComponent(jLabelResetButton, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE))))) .addGap(12)) .addComponent(jPanelContainerConnection, 0, 1004, Short.MAX_VALUE)); panelMainLayout.setVerticalGroup(panelMainLayout.createParallelGroup(Alignment.LEADING) .addGroup(panelMainLayout.createSequentialGroup() .addComponent(jPanelContainerConnection, GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(panelMainLayout.createParallelGroup(Alignment.LEADING) .addComponent(jPanelSetDistribution, GroupLayout.PREFERRED_SIZE, 518, GroupLayout.PREFERRED_SIZE) .addGroup(panelMainLayout.createSequentialGroup().addGap(29).addComponent( jPanelContainerSettings, GroupLayout.PREFERRED_SIZE, 489, GroupLayout.PREFERRED_SIZE))) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(panelMainLayout.createParallelGroup(Alignment.LEADING) .addComponent(jLabelStopButton, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(jLabelPlayButton, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(jLabelPauseButton, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(jLabelResetButton, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE) .addGroup(panelMainLayout.createParallelGroup(Alignment.BASELINE) .addComponent(writeStepLabel, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE) .addComponent(lblTotalSteps)) .addGroup(panelMainLayout.createSequentialGroup() .addComponent(jLabelStep, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED).addComponent(jPanelNumStep, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE))) .addContainerGap(13, Short.MAX_VALUE))); panelMain.setLayout(panelMainLayout); } GroupLayout contentPaneLayout = new GroupLayout(contentPane); contentPaneLayout.setHorizontalGroup( contentPaneLayout.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING, contentPaneLayout .createSequentialGroup().addContainerGap().addComponent(panelMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())); contentPaneLayout.setVerticalGroup( contentPaneLayout.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING, contentPaneLayout.createSequentialGroup().addContainerGap().addComponent(panelMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); contentPane.setLayout(contentPaneLayout); pack(); setLocationRelativeTo(null); refreshServerLabel.setVisible(false); jButtonChoseSimJar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { simulationFile = showFileChooser(); if (simulationFile != null) jTextFieldPathSimJar.setText(simulationFile.getAbsolutePath()); } }); }
From source file:com.ah.ui.actions.home.HmSettingsAction.java
public boolean updateNetworkSettings() { HASettings originalHA = (HASettings) MgrUtil.getSessionAttribute(HASETTINGS_CACHE); boolean originalEnableHA = (originalHA != null) && originalHA.isEnableHA(); boolean isChanged = false; // not support edit some fields on ha enabled if (originalHA.getHaStatus() == HASettings.HASTATUS_ENABLE) { enableFallback = originalHA.isEnableFailBack(); haPort = originalHA.getHaPort() == HASettings.HAPORT_MGT ? HAPORT_MGT : HAPORT_LAN; enableExternalIP = originalHA.isUseExternalIPHostname(); }//from w w w.j a va 2 s . c o m if (enableHA) { // enable ha if (NmsUtil.isHostedHMApplication()) { if (!updateDNSConfiguration4HA()) return false; // update HA Email Notify updateHANotifyEmail(); return true; } // check domain if (!checkDomain(haDomainName)) { return false; } // check gateway should be in the same subnet with port ip if (!(isInSameSubnet(primaryMGTIP, primaryGateway, primaryMGTMask) || isInSameSubnet(primaryLANIP, primaryGateway, primaryLANMask))) { addActionError(MgrUtil.getUserMessage("action.error.primary.node.setting")); return false; } // if (!(isInSameSubnet(secondaryMGTIP, secondaryGateway, secondaryMGTMask) || isInSameSubnet( // secondaryLANIP, secondaryGateway, secondaryLANMask))) { // addActionError(MgrUtil.getUserMessage("action.error.secondary.node.setting")); // return false; // } // check activation key // if (!HmBeActivationUtil.ifActivationKeyValidForHa()) { // addActionError(HmBeResUtil.getString("ha.join.checkActivationKey")); // return false; // } String passive = secondaryMGTIP; if (enableExternalIP) { passive = secondaryExternalIP; } else { passive = haPort.equals(HAPORT_LAN) ? secondaryLANIP : secondaryMGTIP; } // check secondary node ip connect String command = "/HiveManager/script/shell/SSHpassword " + passive; if (null != haSecret && !haSecret.isEmpty()) command += " '" + haSecret + '\''; //TODO escape ' int exitValue = execCommand(command); if (exitValue != 0) { addActionError(MgrUtil.getUserMessage("error.admin.hm.ha.ssh.password.cannot.connect", new String[] { "secondary node", (null != haSecret && !"".equals(haSecret)) ? "invalid" : "required", passive })); return false; } // check primary and secondary database settings final String scp; if (null != haPrimaryDbIp && !haPrimaryDbIp.isEmpty()) { command = "/HiveManager/script/shell/SSHpassword " + haPrimaryDbIp; if (null != haPrimaryDbPwd && !haPrimaryDbPwd.isEmpty()) command += " '" + haPrimaryDbPwd + '\''; //TODO escape ' exitValue = execCommand(command); if (exitValue != 0 || execCommand("ssh " + passive + (scp = " \"" + command + '"')) != 0) { addActionError(MgrUtil.getUserMessage("error.admin.hm.ha.ssh.password.cannot.connect", new String[] { "primary database", (null != haPrimaryDbPwd && !"".equals(haPrimaryDbPwd)) ? "invalid" : "required", haPrimaryDbIp })); return false; } } else scp = null; // check secondary db connect if (null != haSecondaryDbIp && !haSecondaryDbIp.isEmpty()) { command = "/HiveManager/script/shell/SSHpassword " + haSecondaryDbIp; if (null != haSecondaryDbPwd && !haSecondaryDbPwd.isEmpty()) command += " '" + haSecondaryDbPwd + '\''; //TODO escape ' exitValue = execCommand(command); if (exitValue != 0 || execCommand("ssh " + passive + (command = " \"" + command + '"')) != 0 || null != scp && (execCommand("ssh " + haPrimaryDbIp + command) != 0 || execCommand("ssh " + haSecondaryDbIp + scp) != 0)) { addActionError(MgrUtil.getUserMessage("error.admin.hm.ha.ssh.password.cannot.connect", new String[] { "secondary database", (null != haSecondaryDbPwd && !"".equals(haSecondaryDbPwd)) ? "invalid" : "required", haSecondaryDbIp })); return false; } } // check secondary host name String secondaryName = BeAdminCentOSTools.getOutStreamExecCmd("ssh " + passive + " uname -n"); if (null != secondaryName && !secondaryName.isEmpty()) { // secondary domain name // String secDomainName = BeAdminCentOSTools.getOutStreamExecCmd("ssh " + passive + " dnsdomainname"); // if (null == secDomainName || secDomainName.isEmpty() || !secondaryName.endsWith(secDomainName)) { // addActionError(MgrUtil.getUserMessage("error.admin.hm.ha.secondary.node.domainname", passive)); // return false; // } if (!secondaryName.endsWith(haDomainName)) { addActionError(MgrUtil.getUserMessage("error.admin.hm.ha.secondary.node.domainname.different", new String[] { passive, haDomainName })); return false; } String secHostName = secondaryName.substring(0, secondaryName.lastIndexOf(haDomainName) - 1); if (null == secHostName || secHostName.isEmpty()) { addActionError(MgrUtil.getUserMessage("error.admin.hm.ha.secondary.node.hostname", passive)); return false; } secondaryHostName = secHostName; } else { addActionError(MgrUtil.getUserMessage("error.admin.hm.ha.secondary.node.hostname", passive)); return false; } // check 4 nodes, database status if (null != haPrimaryDbIp && !haPrimaryDbIp.isEmpty() && null != haSecondaryDbIp && !haSecondaryDbIp.isEmpty()) { boolean is4Nodes = false; if (!haPrimaryDbIp.equals(primaryMGTIP) && !haPrimaryDbIp.equals(secondaryMGTIP) && !haSecondaryDbIp.equals(primaryMGTIP) && !haSecondaryDbIp.equals(secondaryMGTIP)) { is4Nodes = true; if (null != primaryLANIP && !primaryLANIP.isEmpty()) { is4Nodes = false; if (!haPrimaryDbIp.equals(primaryLANIP) && !haSecondaryDbIp.equals(primaryLANIP)) { is4Nodes = true; } } if (null != secondaryLANIP && !secondaryLANIP.isEmpty()) { is4Nodes = false; if (!haPrimaryDbIp.equals(secondaryLANIP) && !haSecondaryDbIp.equals(secondaryLANIP)) { is4Nodes = true; } } } if (is4Nodes) { String filePath = "/HiveManager/tomcat/.dbOnly"; String resultPriDb = BeAdminCentOSTools .getOutStreamExecCmd("ssh " + haPrimaryDbIp + " file " + filePath); // not db only if (resultPriDb.contains("ERROR")) { addActionError( MgrUtil.getUserMessage("error.admin.hm.ha.primary.not.db.only", haPrimaryDbIp)); return false; } resultPriDb = BeAdminCentOSTools .getOutStreamExecCmd("ssh " + haSecondaryDbIp + " file " + filePath); // not db only if (resultPriDb.contains("ERROR")) { addActionError( MgrUtil.getUserMessage("error.admin.hm.ha.secondary.not.db.only", haSecondaryDbIp)); return false; } } } // check 4 nodes, database status if (null != haPrimaryDbIp && !haPrimaryDbIp.isEmpty() && null != haSecondaryDbIp && !haSecondaryDbIp.isEmpty()) { boolean is4Nodes = false; if (!haPrimaryDbIp.equals(primaryMGTIP) && !haPrimaryDbIp.equals(secondaryMGTIP) && !haSecondaryDbIp.equals(primaryMGTIP) && !haSecondaryDbIp.equals(secondaryMGTIP)) { is4Nodes = true; if (null != primaryLANIP && !primaryLANIP.isEmpty()) { is4Nodes = false; if (!haPrimaryDbIp.equals(primaryLANIP) && !haSecondaryDbIp.equals(primaryLANIP)) { is4Nodes = true; } } if (null != secondaryLANIP && !secondaryLANIP.isEmpty()) { is4Nodes = false; if (!haPrimaryDbIp.equals(secondaryLANIP) && !haSecondaryDbIp.equals(secondaryLANIP)) { is4Nodes = true; } } } if (is4Nodes) { String filePath = "/HiveManager/tomcat/.dbOnly"; String resultPriDb = BeAdminCentOSTools .getOutStreamExecCmd("ssh " + haPrimaryDbIp + " file " + filePath); // not db only if (resultPriDb.contains("ERROR")) { addActionError( MgrUtil.getUserMessage("error.admin.hm.ha.primary.not.db.only", haPrimaryDbIp)); return false; } resultPriDb = BeAdminCentOSTools .getOutStreamExecCmd("ssh " + haSecondaryDbIp + " file " + filePath); // not db only if (resultPriDb.contains("ERROR")) { addActionError( MgrUtil.getUserMessage("error.admin.hm.ha.secondary.not.db.only", haSecondaryDbIp)); return false; } } } // update net configuration if exists changes. if (isChangedHALocalNetConfiguration()) { isChanged = true; boolean isSuccess = updateNetConfiguration4HA(); if (!isSuccess) { return false; } } // update ha settings and execute enable ha if exists changes. if (isChangedHASettings()) { isChanged = true; if (!enableHA()) return false; } File file = new File(CONFIG_FILE_PATH); if (file.exists() && file.isFile()) { file.delete(); } // no changes, give some message if (!isChanged) { // addActionMessage("There are no changes on net configuration or HA // configuration."); } updateProxyConfiguration(true); } else { // disable ha // check domain if (!checkDomain(networkDomain)) { return false; } // check gateway, gateway should in same subnet with mgr or lan if (!(isInSameSubnet(defaultGateway, ip_eth0, mask_eth0) || (enableLan && isInSameSubnet(defaultGateway, ip_eth1, mask_eth1)))) { addActionError(MgrUtil.getUserMessage("action.error.gateway.address.setting")); return false; } // disable ha need update ha settings and execute script if (originalEnableHA) { isChanged = true; boolean isSuccess = disableHA(); if (!isSuccess) { return false; } } // update net configuration // check whether or not modified. if (isChangedStandAloneNetConfiguration()) { isChanged = true; updateStandAloneNetConfiguration(); } updateProxyConfiguration(false); //for db separation if (!NmsUtil.isHostedHMApplication()) { FileOutputStream fos = null; File file = new File(CONFIG_FILE_PATH); if (!enableSeparateExternalDb) { try { List<HASettings> hasettingsList = QueryUtil.executeQuery(HASettings.class, null, null); if (hasettingsList != null && hasettingsList.size() > 0) { HASettings haSetting = hasettingsList.get(0); List<String> hostAndPort = HibernateDbConfigTool.getHostAndPort(); String hibernateDbIp = ""; if (null != hostAndPort && hostAndPort.size() > 0) { hibernateDbIp = hostAndPort.get(0); } String localDbIp = super.getLocalHost(); if (haSetting.getEnableExternalDb() != HASettings.EXTERNALDB_DISABLEHA_INITIAL) { if (!hibernateDbIp.equalsIgnoreCase("localhost") && !hibernateDbIp.equalsIgnoreCase(localDbIp) && haSetting .getEnableExternalDb() == HASettings.EXTERNALDB_ENABLEHA_REMOTE) { haSetting.setEnableExternalDb(HASettings.EXTERNALDB_DISABLEHA_REMOTE); haSetting.setPrimaryDbUrl(hibernateDbIp); if (hibernateDbIp.equals(haSetting.getPrimaryDbUrl())) { haSetting.setPrimaryDbPwd(haSetting.getPrimaryDbPwd()); } else if (hibernateDbIp.equals(haSetting.getSecondaryDbUrl())) { haSetting.setPrimaryDbPwd(haSetting.getSecondaryDbPwd()); } else { haSetting.setPrimaryDbPwd(""); } QueryUtil.updateBo(haSetting); Properties prop = new Properties(); prop.setProperty(EXTERN_DB_IP_KEY, hibernateDbIp); prop.setProperty(EXTERN_DB_PORT_KEY, "5432"); prop.setProperty(LOCAL_USER_KEY, "admin"); if (hibernateDbIp.equals(haSetting.getPrimaryDbUrl())) { prop.setProperty(LOCAL_PASSWORD_KEY, haSetting.getPrimaryDbPwd()); } else if (hibernateDbIp.equals(haSetting.getSecondaryDbUrl())) { prop.setProperty(LOCAL_PASSWORD_KEY, haSetting.getSecondaryDbPwd()); } else { prop.setProperty(LOCAL_PASSWORD_KEY, ""); } fos = new FileOutputStream(file); prop.store(fos, null); } else if (!hibernateDbIp.equalsIgnoreCase("localhost") && !hibernateDbIp.equalsIgnoreCase(localDbIp) && haSetting .getEnableExternalDb() == HASettings.EXTERNALDB_DISABLEHA_REMOTE) { StringBuilder cmds = new StringBuilder( BeAdminCentOSTools.ahShellRoot + "/Connect2HMDB.sh "); cmds.append("local"); int msg = execCommand(cmds.toString()); if (0 == msg) { if (file.exists() && file.isFile()) { file.delete(); } super.generateAuditLog(HmAuditLog.STATUS_SUCCESS, MgrUtil.getUserMessage("admin.separatedb.local.success.log")); addActionMessage( MgrUtil.getUserMessage("message.admin.separatedb.local.success")); Thread thread = new Thread() { public void run() { try { sleep(5000); HmBeAdminUtil.restartSoft(); } catch (Exception e) { e.printStackTrace(); } } }; thread.start(); } else if (107 == msg) { super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.local.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.107")); } else if (109 == msg) { super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.local.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.109")); } else { super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.local.failure.log")); addActionError( MgrUtil.getUserMessage("message.admin.separatedb.local.failure")); } } } else { if (!hibernateDbIp.equalsIgnoreCase("localhost") && !hibernateDbIp.equalsIgnoreCase(localDbIp)) { haSetting.setEnableExternalDb(HASettings.EXTERNALDB_DISABLEHA_REMOTE); haSetting.setPrimaryDbUrl(hibernateDbIp); if (null == haSetting.getHaSecret() || haSetting.getHaSecret().equals("") || "something".equals(haSetting.getHaSecret())) { haSetting.setPrimaryDbPwd(""); } else { haSetting.setPrimaryDbPwd(haSetting.getHaSecret()); } QueryUtil.updateBo(haSetting); Properties prop = new Properties(); prop.setProperty(EXTERN_DB_IP_KEY, hibernateDbIp); prop.setProperty(EXTERN_DB_PORT_KEY, "5432"); prop.setProperty(LOCAL_USER_KEY, "admin"); if (null == haSetting.getHaSecret() || haSetting.getHaSecret().equals("") || "something".equals(haSetting.getHaSecret())) { prop.setProperty(LOCAL_PASSWORD_KEY, ""); } else { prop.setProperty(LOCAL_PASSWORD_KEY, haSetting.getHaSecret()); } fos = new FileOutputStream(file); prop.store(fos, null); } } } } catch (Exception e) { super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.local.failure.log")); addActionError(MgrUtil.getUserMessage("message.admin.separatedb.local.failure")); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { log.error("FileOutputStream close failure"); } } } } else { try { List<HASettings> hasettingsList = QueryUtil.executeQuery(HASettings.class, null, null); if (hasettingsList != null && hasettingsList.size() > 0) { HASettings haSetting = hasettingsList.get(0); if (haSetting.getEnableExternalDb() == HASettings.EXTERNALDB_DISABLEHA_REMOTE) { if (!haSetting.getPrimaryDbUrl().equalsIgnoreCase(remoteDbIp) || !haSetting.getPrimaryDbPwd().equals(remoteDbSshPwd)) { Properties prop = new Properties(); prop.setProperty(EXTERN_DB_IP_KEY, remoteDbIp); prop.setProperty(EXTERN_DB_PORT_KEY, "5432"); prop.setProperty(LOCAL_USER_KEY, "admin"); prop.setProperty(LOCAL_PASSWORD_KEY, remoteDbSshPwd); fos = new FileOutputStream(file); prop.store(fos, null); if (file.exists() && file.isFile()) { int returnMsg = execCommand( BeAdminCentOSTools.ahShellRoot + "/Connect2HMDB.sh"); if (0 == returnMsg) { haSetting.setPrimaryDbUrl(remoteDbIp); haSetting.setPrimaryDbPwd(remoteDbSshPwd); QueryUtil.updateBo(haSetting); super.generateAuditLog(HmAuditLog.STATUS_SUCCESS, MgrUtil.getUserMessage("admin.separatedb.success.log")); addActionMessage( MgrUtil.getUserMessage("message.admin.separatedb.success")); Thread thread = new Thread() { public void run() { try { sleep(5000); HmBeAdminUtil.restartSoft(); } catch (Exception e) { e.printStackTrace(); } } }; thread.start(); } else if (100 == returnMsg) {///'/HiveManager/tomcat/.dbOnly' file has not exist in remote host. prop.setProperty(EXTERN_DB_IP_KEY, haSetting.getPrimaryDbUrl()); prop.setProperty(LOCAL_PASSWORD_KEY, haSetting.getPrimaryDbPwd()); fos = new FileOutputStream(file); prop.store(fos, null); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.100")); } else if (101 == returnMsg) {///extdbsettings.properties file has not exist. prop.setProperty(EXTERN_DB_IP_KEY, haSetting.getPrimaryDbUrl()); prop.setProperty(LOCAL_PASSWORD_KEY, haSetting.getPrimaryDbPwd()); fos = new FileOutputStream(file); prop.store(fos, null); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.101")); } else if (102 == returnMsg) {///public key authentication establish failed. prop.setProperty(EXTERN_DB_IP_KEY, haSetting.getPrimaryDbUrl()); prop.setProperty(LOCAL_PASSWORD_KEY, haSetting.getPrimaryDbPwd()); fos = new FileOutputStream(file); prop.store(fos, null); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.102")); } else if (103 == returnMsg) {///local ip address getting failed. prop.setProperty(EXTERN_DB_IP_KEY, haSetting.getPrimaryDbUrl()); prop.setProperty(LOCAL_PASSWORD_KEY, haSetting.getPrimaryDbPwd()); fos = new FileOutputStream(file); prop.store(fos, null); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.103")); } else if (104 == returnMsg) {///pg_hba.conf file in remote host has not exist. prop.setProperty(EXTERN_DB_IP_KEY, haSetting.getPrimaryDbUrl()); prop.setProperty(LOCAL_PASSWORD_KEY, haSetting.getPrimaryDbPwd()); fos = new FileOutputStream(file); prop.store(fos, null); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.104")); } else if (105 == returnMsg) {///remote database start failure. prop.setProperty(EXTERN_DB_IP_KEY, haSetting.getPrimaryDbUrl()); prop.setProperty(LOCAL_PASSWORD_KEY, haSetting.getPrimaryDbPwd()); fos = new FileOutputStream(file); prop.store(fos, null); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.105")); } else if (106 == returnMsg) {///remote database start failure. prop.setProperty(EXTERN_DB_IP_KEY, haSetting.getPrimaryDbUrl()); prop.setProperty(LOCAL_PASSWORD_KEY, haSetting.getPrimaryDbPwd()); fos = new FileOutputStream(file); prop.store(fos, null); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.106")); } else if (108 == returnMsg) { prop.setProperty(EXTERN_DB_IP_KEY, haSetting.getPrimaryDbUrl()); prop.setProperty(LOCAL_PASSWORD_KEY, haSetting.getPrimaryDbPwd()); fos = new FileOutputStream(file); prop.store(fos, null); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.108")); } else if (110 == returnMsg) { prop.setProperty(EXTERN_DB_IP_KEY, haSetting.getPrimaryDbUrl()); prop.setProperty(LOCAL_PASSWORD_KEY, haSetting.getPrimaryDbPwd()); fos = new FileOutputStream(file); prop.store(fos, null); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.110")); } else { prop.setProperty(EXTERN_DB_IP_KEY, haSetting.getPrimaryDbUrl()); prop.setProperty(LOCAL_PASSWORD_KEY, haSetting.getPrimaryDbPwd()); fos = new FileOutputStream(file); prop.store(fos, null); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb")); } } else { super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); super.addActionError(MgrUtil.getUserMessage("error.admin.separatedb")); } } } else if (haSetting.getEnableExternalDb() == HASettings.EXTERNALDB_DISABLEHA_INITIAL) { Properties prop = new Properties(); prop.setProperty(EXTERN_DB_IP_KEY, remoteDbIp); prop.setProperty(EXTERN_DB_PORT_KEY, "5432"); prop.setProperty(LOCAL_USER_KEY, "admin"); prop.setProperty(LOCAL_PASSWORD_KEY, remoteDbSshPwd); fos = new FileOutputStream(file); prop.store(fos, null); if (file.exists() && file.isFile()) { int returnMsg = execCommand( BeAdminCentOSTools.ahShellRoot + "/Connect2HMDB.sh"); if (0 == returnMsg) { haSetting.setEnableExternalDb(HASettings.EXTERNALDB_DISABLEHA_REMOTE); haSetting.setPrimaryDbUrl(remoteDbIp); haSetting.setPrimaryDbPwd(remoteDbSshPwd); QueryUtil.updateBo(haSetting); super.generateAuditLog(HmAuditLog.STATUS_SUCCESS, MgrUtil.getUserMessage("admin.separatedb.success.log")); addActionMessage( MgrUtil.getUserMessage("message.admin.separatedb.success")); Thread thread = new Thread() { public void run() { try { sleep(5000); HmBeAdminUtil.restartSoft(); } catch (Exception e) { e.printStackTrace(); } } }; thread.start(); } else if (100 == returnMsg) {///'/HiveManager/tomcat/.dbOnly' file has not exist in remote host. file.delete(); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.100")); } else if (101 == returnMsg) {///extdbsettings.properties file has not exist. file.delete(); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.101")); } else if (102 == returnMsg) {///public key authentication establish failed. file.delete(); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.102")); } else if (103 == returnMsg) {///local ip address getting failed. file.delete(); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.103")); } else if (104 == returnMsg) {///pg_hba.conf file in remote host has not exist. file.delete(); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.104")); } else if (105 == returnMsg) {///remote database start failure. file.delete(); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.105")); } else if (106 == returnMsg) {///remote database start failure. file.delete(); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.106")); } else if (108 == returnMsg) { file.delete(); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.108")); } else if (110 == returnMsg) { file.delete(); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb.110")); } else { file.delete(); super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); addActionError(MgrUtil.getUserMessage("error.admin.separatedb")); } } else { super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); super.addActionError(MgrUtil.getUserMessage("error.admin.separatedb")); } } } } catch (Exception e) { super.generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("admin.separatedb.failure.log")); super.addActionError(MgrUtil.getUserMessage("error.admin.separatedb")); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { log.error("FileOutputStream close failure"); } } } } } // no changes, give some message if (!isChanged) { // addActionMessage("There are no changes on net configuration."); return false; } // try { // // for activation key // HmBeActivationUtil.deleteUselessActivationKey(); // // // for license // HmBeLicenseUtil.deleteUselessLicense(); // } catch (Exception e) { // e.printStackTrace(); // } } //fix bug 17196 HmBeOsUtil.setLocalHostName(hostName); return true; }
From source file:com.cloudbees.sdk.Bees.java
private void initialize(boolean force) throws Exception { LocalRepository localRepository = new LocalRepository(); String beesRepoPath = localRepository.getRepositoryPath(); File lastCheckFile = new File(beesRepoPath, CHECK_FILE); boolean checkVersion = true; Properties p = new Properties(); if (!force && Helper.loadProperties(lastCheckFile, p)) { String str = p.getProperty("last"); if (str != null) { long interval = System.currentTimeMillis() - Long.parseLong(str); if (interval < CHECK_INTERVAL) checkVersion = false;//from w ww.jav a 2s. c om } } if (checkVersion) { // Check SDK version File sdkConfig = getURLAsFile(localRepository, app_template_xml_url + app_template_xml_name, app_template_xml_name, app_template_xml_desc); Document doc = XmlHelper.readXMLFromFile(sdkConfig.getCanonicalPath()); Element e = doc.getDocumentElement(); String availVersion = e.getAttribute("version"); String minVersion = e.getAttribute("min-version"); VersionNumber currentVersion = new VersionNumber(BOOTSTRAP_VERSION); VersionNumber availableVersion = new VersionNumber(availVersion); VersionNumber minimumVersion = new VersionNumber(minVersion); if (currentVersion.compareTo(availableVersion) < 0) { System.out.println(); if (currentVersion.compareTo(minimumVersion) < 0) { throw new AbortException("ERROR - This version of the CloudBees SDK is no longer supported," + "" + " please install the latest version (" + availVersion + ")."); } else if (currentVersion.compareTo(availableVersion) < 0) { System.out.println( "WARNING - A new version of the CloudBees SDK is available, please install the latest version (" + availVersion + ")."); } String hRef = e.getAttribute("href"); String homeRef = "www.cloudbees.com"; NodeList nodeList = e.getElementsByTagName("link"); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); NamedNodeMap nodeMap = node.getAttributes(); Node rel = nodeMap.getNamedItem("rel"); Node href = nodeMap.getNamedItem("href"); if (rel != null && rel.getTextContent().trim().equalsIgnoreCase("alternate") && href != null) { homeRef = href.getTextContent(); } } NodeList libsNL = e.getElementsByTagName("libraries"); Node libsNode = null; if (libsNL.getLength() > 0) { libsNode = libsNL.item(0); } if (libsNode != null) { NodeList libNL = e.getElementsByTagName("library"); for (int i = 0; i < libNL.getLength(); i++) { Node node = libNL.item(i); NamedNodeMap nodeMap = node.getAttributes(); Node nameNode = nodeMap.getNamedItem("name"); Node refNode = nodeMap.getNamedItem("href"); if (nameNode != null && refNode != null) { String libName = nameNode.getTextContent(); String libUrlString = refNode.getTextContent().trim(); int idx = libUrlString.lastIndexOf('/'); String libFileName = libUrlString.substring(idx); localRepository.getURLAsFile(libUrlString, "lib1" + libFileName, libName); } } } System.out.println(" SDK home: " + homeRef); System.out.println(" SDK download: " + hRef); System.out.println(); } // Check plugins version NodeList pluginsNL = e.getElementsByTagName("plugins"); Node pluginsNode = null; if (pluginsNL.getLength() > 0) { pluginsNode = pluginsNL.item(0); } if (pluginsNode != null) { NodeList pluginNL = e.getElementsByTagName("plugin"); CommandServiceImpl service = (CommandServiceImpl) commandService; for (int i = 0; i < pluginNL.getLength(); i++) { Node node = pluginNL.item(i); NamedNodeMap nodeMap = node.getAttributes(); Node nameNode = nodeMap.getNamedItem("artifact"); if (nameNode != null) { Node n = nodeMap.getNamedItem("required"); boolean forceInstall = (n != null && Boolean.parseBoolean(n.getTextContent())); String pluginArtifact = nameNode.getTextContent(); GAV gav = new GAV(pluginArtifact); VersionNumber pluginVersion = new VersionNumber(gav.version); Plugin plugin = service.getPlugin(gav.artifactId); if (plugin != null) { forceInstall = false; GAV pgav = new GAV(plugin.getArtifact()); VersionNumber currentPluginVersion = new VersionNumber(pgav.version); if (currentPluginVersion.compareTo(pluginVersion) < 0) { Node nf = nodeMap.getNamedItem("force-upgrade"); boolean forced = (nf != null && Boolean.parseBoolean(nf.getTextContent())); if (forced) { forceInstall = true; } else { System.out.println(); System.out.println("WARNING - A newer version of the [" + gav.artifactId + "] plugin is available, please update with:"); System.out.println(" > bees plugin:update " + gav.artifactId); System.out.println(); } } } if (forceInstall) pluginsToInstallList.put(gav.artifactId, gav); } } } // Update last check p.setProperty("last", "" + System.currentTimeMillis()); lastCheckFile.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(lastCheckFile); p.store(fos, "CloudBees SDK check"); fos.close(); } }