List of usage examples for java.util Properties putAll
@Override public synchronized void putAll(Map<?, ?> t)
From source file:com.hpe.application.automation.tools.run.RunFromFileBuilder.java
@Override public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath workspace, @Nonnull Launcher launcher, @Nonnull TaskListener listener)/*from w ww . j ava 2 s .com*/ throws InterruptedException, IOException { // get the mc server settings MCServerSettingsModel mcServerSettingsModel = getMCServerSettingsModel(); EnvVars env = null; try { env = build.getEnvironment(listener); } catch (IOException | InterruptedException e) { listener.error("Failed loading build environment " + e); } // this is an unproper replacment to the build.getVariableResolver since workflow run won't support the // getBuildEnviroment() 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()); mergedProperties.put("resultsFilename", ResultFilename); //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 String firstTestKey = "Test1"; String firstTestContent = mergedProperties.getProperty(firstTestKey, ""); if (RunFromFileSystemModel.isMtbxContent(firstTestContent)) { try { String mtbxFilePath = createMtbxFileInWs(workspace, firstTestContent, time); mergedProperties.setProperty(firstTestKey, mtbxFilePath); } catch (IOException | InterruptedException 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:com.legstar.coxb.gen.CoxbGenModelTest.java
/** * Test the serialization and construction using a properties file. * //from w w w .j a v a 2s .c o m * @throws Exception if test fails */ public void testPropertySerialization() throws Exception { CoxbGenModel model = new CoxbGenModel(); Properties props = model.toProperties(); assertEquals(null, props.get(JaxbGenModel.JAXB_XSD_LOCATION)); assertEquals("true", props.get(JaxbGenModel.JAXB_XJB_ISGENERATEISSETMETHOD)); assertEquals("1", props.get(JaxbGenModel.JAXB_XJB_SERIALIZABLE_ID)); assertEquals(null, props.get(JaxbGenModel.JAXB_XJB_ELEMENTNAME_PREFIX)); assertEquals(null, props.get(JaxbGenModel.JAXB_XJB_ELEMENTNAME_SUFFIX)); assertEquals(null, props.get(JaxbGenModel.JAXB_XJB_TYPENAME_PREFIX)); assertEquals(null, props.get(JaxbGenModel.JAXB_XJB_TYPENAME_SUFFIX)); assertEquals(null, props.get(CoxbGenModel.COXB_PACKAGENAME)); assertEquals(null, props.get(CoxbGenModel.COXB_JAXB_ALTERNATIVEPACKAGENAME)); assertEquals(null, props.get(CoxbGenModel.COXB_JAXB_ALTERNATIVEFACTORYNAME)); assertEquals("true", props.get(CoxbGenModel.COXB_ISXMLTRANSFORMERS)); assertEquals("false", props.get(CoxbGenModel.COXB_ISJSONTRANSFORMERS)); assertEquals(null, props.get(CoxbGenModel.COXB_XSDFILE)); assertEquals(null, props.get(CoxbGenModel.COXB_JAXBROOTCLASSNAMES)); assertEquals(null, props.get(CoxbGenModel.COXB_JAXBSRCDIR)); assertEquals(null, props.get(CoxbGenModel.COXB_JAXBBINDIR)); assertEquals(null, props.get(CoxbGenModel.COXB_COXBSRCDIR)); assertEquals(null, props.get(CoxbGenModel.COXB_COXBBINDIR)); assertEquals(null, props.get(CoxbGenModel.COXB_UNMARSHAL_CHOICE_STRATEGIES)); assertEquals("{isCompileTransformers=false," + " isXmlTransformers=true," + " serializableID=1," + " internalBindings=true," + " eciCompatible=false," + " isJsonTransformers=false," + " noPackageInfo=false," + " generateIsSetMethod=true}", model.toString()); model = new CoxbGenModel(props); assertEquals(null, model.getJaxbPackageName()); JaxbGenModel xjbModel = new JaxbGenModel(); xjbModel.setXsdLocation("xsdLocation"); xjbModel.setSerializableUid(265L); xjbModel.setGenerateIsSetMethod(false); xjbModel.setElementNamePrefix("elementNamePrefix"); xjbModel.setElementNameSuffix("elementNameSuffix"); xjbModel.setTypeNamePrefix("typeNamePrefix"); xjbModel.setTypeNameSuffix("typeNameSuffix"); props.putAll(xjbModel.toProperties()); model = new CoxbGenModel(props); assertEquals("xsdLocation", model.getJaxbGenModel().getXsdLocation()); assertEquals(265L, model.getSerializableUid()); assertEquals(false, model.isGenerateIsSetMethod()); assertEquals("elementNamePrefix", model.getElementNamePrefix()); assertEquals("elementNameSuffix", model.getElementNameSuffix()); assertEquals("typeNamePrefix", model.getTypeNamePrefix()); assertEquals("typeNameSuffix", model.getTypeNameSuffix()); props.put(CoxbGenModel.COXB_PACKAGENAME, "coxb.package.name"); model = new CoxbGenModel(props); assertEquals("coxb.package.name", model.getCoxbPackageName()); props.put(CoxbGenModel.COXB_JAXB_ALTERNATIVEPACKAGENAME, "jaxb.alt.package.name"); props.put(CoxbGenModel.COXB_JAXB_ALTERNATIVEFACTORYNAME, "jaxb.alt.package.name.AltFactory"); model = new CoxbGenModel(props); assertEquals("jaxb.alt.package.name", model.getAlternativePackageName()); assertEquals("jaxb.alt.package.name.AltFactory", model.getAlternativeFactoryName()); props.put(CoxbGenModel.COXB_ISXMLTRANSFORMERS, "true"); props.put(CoxbGenModel.COXB_ISJSONTRANSFORMERS, "true"); model = new CoxbGenModel(props); assertTrue(model.isXmlTransformers()); assertTrue(model.isJsonTransformers()); props.put(CoxbGenModel.COXB_JAXBROOTCLASSNAMES + "_0", "FirstClass"); props.put(CoxbGenModel.COXB_JAXBROOTCLASSNAMES + "_1", "SecondClass"); model = new CoxbGenModel(props); assertEquals("[FirstClass, SecondClass]", model.getJaxbRootClassNames().toString()); props.put(CoxbGenModel.COXB_XSDFILE, "xsdfile"); props.put(CoxbGenModel.COXB_JAXBSRCDIR, "jaxbsrcdir"); props.put(CoxbGenModel.COXB_JAXBBINDIR, "jaxbbindir"); props.put(CoxbGenModel.COXB_COXBSRCDIR, "coxbsrcdir"); props.put(CoxbGenModel.COXB_COXBBINDIR, "coxbbindir"); model = new CoxbGenModel(props); assertEquals("xsdfile", model.getXsdFile().getPath()); assertEquals("jaxbsrcdir", model.getJaxbSrcDir().getPath()); assertEquals("jaxbbindir", model.getJaxbBinDir().getPath()); assertEquals("coxbsrcdir", model.getCoxbSrcDir().getPath()); assertEquals("coxbbindir", model.getCoxbBinDir().getPath()); props.put(CoxbGenModel.COXB_UNMARSHAL_CHOICE_STRATEGIES + "_0", "ITEMA:some.Strategy"); model = new CoxbGenModel(props); assertEquals("ITEMA:some.Strategy", model.getUnmarshalChoiceStrategies().get(0).toString()); props = model.toProperties(); assertEquals("coxb.package.name", props.getProperty(CoxbGenModel.COXB_PACKAGENAME)); assertEquals("jaxb.alt.package.name", props.getProperty(CoxbGenModel.COXB_JAXB_ALTERNATIVEPACKAGENAME)); assertEquals("jaxb.alt.package.name.AltFactory", props.getProperty(CoxbGenModel.COXB_JAXB_ALTERNATIVEFACTORYNAME)); assertEquals("true", props.getProperty(CoxbGenModel.COXB_ISXMLTRANSFORMERS)); assertEquals("true", props.getProperty(CoxbGenModel.COXB_ISJSONTRANSFORMERS)); assertEquals((new File("xsdfile")).getCanonicalPath(), props.getProperty(CoxbGenModel.COXB_XSDFILE)); assertEquals("FirstClass", props.getProperty(CoxbGenModel.COXB_JAXBROOTCLASSNAMES + "_0")); assertEquals("SecondClass", props.getProperty(CoxbGenModel.COXB_JAXBROOTCLASSNAMES + "_1")); assertEquals((new File("jaxbsrcdir")).getCanonicalPath(), props.getProperty(CoxbGenModel.COXB_JAXBSRCDIR)); assertEquals((new File("jaxbbindir")).getCanonicalPath(), props.getProperty(CoxbGenModel.COXB_JAXBBINDIR)); assertEquals((new File("coxbsrcdir")).getCanonicalPath(), props.getProperty(CoxbGenModel.COXB_COXBSRCDIR)); assertEquals((new File("coxbbindir")).getCanonicalPath(), props.getProperty(CoxbGenModel.COXB_COXBBINDIR)); assertEquals("xsdLocation", props.getProperty(JaxbGenModel.JAXB_XSD_LOCATION)); assertEquals("false", props.getProperty(JaxbGenModel.JAXB_XJB_ISGENERATEISSETMETHOD)); assertEquals("265", props.getProperty(JaxbGenModel.JAXB_XJB_SERIALIZABLE_ID)); assertEquals("elementNamePrefix", props.getProperty(JaxbGenModel.JAXB_XJB_ELEMENTNAME_PREFIX)); assertEquals("elementNameSuffix", props.getProperty(JaxbGenModel.JAXB_XJB_ELEMENTNAME_SUFFIX)); assertEquals("typeNamePrefix", props.getProperty(JaxbGenModel.JAXB_XJB_TYPENAME_PREFIX)); assertEquals("typeNameSuffix", props.getProperty(JaxbGenModel.JAXB_XJB_TYPENAME_SUFFIX)); assertEquals("ITEMA:some.Strategy", props.getProperty(CoxbGenModel.COXB_UNMARSHAL_CHOICE_STRATEGIES + "_0")); }
From source file:com.athena.meerkat.controller.web.provisioning.AbstractProvisioningService.java
/** * <pre>// www . java 2 s . co m * 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:me.mast3rplan.phantombot.PhantomBot.java
public void updateGameWispTokens(String[] newTokens) { Properties outputProperties = new Properties() { @Override//w ww .j a v a 2s . co m public synchronized Enumeration<Object> keys() { return Collections.enumeration(new TreeSet<>(super.keySet())); } }; gameWispOAuth = newTokens[0]; gameWispRefresh = newTokens[1]; pbProperties.setProperty("gamewispauth", newTokens[0]); pbProperties.setProperty("gamewisprefresh", newTokens[1]); try { try (FileOutputStream outputStream = new FileOutputStream("botlogin.txt")) { outputProperties.putAll(pbProperties); outputProperties.store(outputStream, "PhantomBot Configuration File"); } print("GameWisp Token has been refreshed."); } catch (IOException ex) { com.gmt2001.Console.err.println( "!!!! CRITICAL !!!! Failed to update GameWisp Refresh Tokens into botlogin.txt! Must manually add!"); com.gmt2001.Console.err.println( "!!!! CRITICAL !!!! gamewispauth = " + newTokens[0] + " gamewisprefresh = " + newTokens[1]); } SingularityAPI.instance().setAccessToken(gameWispOAuth); }
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;//from w w w.ja v a 2s . co 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:org.apache.oozie.cli.OozieCLI.java
private Properties getConfiguration(OozieClient wc, CommandLine commandLine) throws IOException { if (!isConfigurationSpecified(wc, commandLine)) { throw new IOException("configuration is not specified"); }// w w w. j a va2 s .co m Properties conf = wc.createConfiguration(); String configFile = commandLine.getOptionValue(CONFIG_OPTION); if (configFile != null) { File file = new File(configFile); if (!file.exists()) { throw new IOException("configuration file [" + configFile + "] not found"); } if (configFile.endsWith(".properties")) { conf.load(new FileReader(file)); } else if (configFile.endsWith(".xml")) { parse(new FileInputStream(configFile), conf); } else { throw new IllegalArgumentException("configuration must be a '.properties' or a '.xml' file"); } } if (commandLine.hasOption("D")) { Properties commandLineProperties = commandLine.getOptionProperties("D"); conf.putAll(commandLineProperties); } return conf; }
From source file:me.mast3rplan.phantombot.PhantomBot.java
@Subscribe public void consoleInput(ConsoleInputEvent event) { String message = event.getMsg(); Boolean changed = false;/*from w ww. j av a 2 s .c om*/ Boolean reset = false; String arguments; String[] argument = null; /* Check to see if the message is null or has nothing in it */ if (message == null || message.isEmpty()) { return; } /* Check for arguments */ if (message.contains(" ")) { String messageString = message; message = messageString.substring(0, messageString.indexOf(" ")); arguments = messageString.substring(messageString.indexOf(" ") + 1); argument = arguments.split(" "); } if (message.equalsIgnoreCase("ankhtophantombot")) { print("Not all of AnkhBot's data will be compatible with PhantomBot."); print("This process will take a long time."); print("Are you sure you want to convert AnkhBot's data to PhantomBot? [y/n]"); String check = System.console().readLine().trim(); if (check.equals("y")) { AnkhConverter.instance(); } else { print("No changes were made."); return; } } if (message.equalsIgnoreCase("backupdb")) { SimpleDateFormat datefmt = new SimpleDateFormat("ddMMyyyy.hhmmss"); datefmt.setTimeZone(TimeZone.getTimeZone(timeZone)); String timestamp = datefmt.format(new Date()); dataStore.backupSQLite3("phantombot.manual.backup." + timestamp + ".db"); return; } /* Update the followed (followers) table. */ if (message.equalsIgnoreCase("fixfollowedtable")) { TwitchAPIv3.instance().FixFollowedTable(channelName, dataStore, false); return; } /* Update the followed (followers) table - forced. */ if (message.equalsIgnoreCase("fixfollowedtable-force")) { TwitchAPIv3.instance().FixFollowedTable(channelName, dataStore, true); return; } if (message.equalsIgnoreCase("jointest")) { for (int i = 0; i < 30; i++) { EventBus.instance() .postAsync(new IrcChannelJoinEvent(this.session, this.channel, generateRandomString(8))); } } /* tests a follow event */ if (message.equalsIgnoreCase("followertest")) { String randomUser = generateRandomString(10); print("[CONSOLE] Executing followertest (User: " + randomUser + ")"); EventBus.instance() .postAsync(new TwitchFollowEvent(randomUser, PhantomBot.getChannel(this.channelName))); return; } /* tests multiple follows */ if (message.equalsIgnoreCase("followerstest")) { String randomUser = generateRandomString(10); int followCount = 5; if (argument != null) { followCount = Integer.parseInt(argument[0]); } print("[CONSOLE] Executing followerstest (Count: " + followCount + ", User: " + randomUser + ")"); for (int i = 0; i < followCount; i++) { EventBus.instance().postAsync( new TwitchFollowEvent(randomUser + "_" + i, PhantomBot.getChannel(this.channelName))); } return; } /* Test a subscriber event */ if (message.equalsIgnoreCase("subscribertest")) { String randomUser = generateRandomString(10); print("[CONSOLE] Executing subscribertest (User: " + randomUser + ")"); EventBus.instance().postAsync(new NewSubscriberEvent(PhantomBot.getSession(this.channelName), PhantomBot.getChannel(this.channelName), randomUser)); return; } /* Test a prime subscriber event */ if (message.equalsIgnoreCase("primesubscribertest")) { String randomUser = generateRandomString(10); print("[CONSOLE] Executing primesubscribertest (User: " + randomUser + ")"); EventBus.instance().postAsync(new NewPrimeSubscriberEvent(PhantomBot.getSession(this.channelName), PhantomBot.getChannel(this.channelName), randomUser)); return; } /* Test a resubscriber event */ if (message.equalsIgnoreCase("resubscribertest")) { String randomUser = generateRandomString(10); print("[CONSOLE] Executing resubscribertest (User: " + randomUser + ")"); EventBus.instance().postAsync(new NewReSubscriberEvent(PhantomBot.getSession(this.channelName), PhantomBot.getChannel(this.channelName), randomUser, "10")); return; } /* Test the online event */ if (message.equalsIgnoreCase("onlinetest")) { print("[CONSOLE] Executing onlinetest"); EventBus.instance().postAsync(new TwitchOnlineEvent(PhantomBot.getChannel(this.channelName))); return; } /* Test the offline event */ if (message.equalsIgnoreCase("offlinetest")) { print("[CONSOLE] Executing offlinetest"); EventBus.instance().postAsync(new TwitchOfflineEvent(PhantomBot.getChannel(this.channelName))); return; } /* Test the host event */ if (message.equalsIgnoreCase("hosttest")) { print("[CONSOLE] Executing hosttest"); EventBus.instance() .postAsync(new TwitchHostedEvent(this.botName, PhantomBot.getChannel(this.channelName))); return; } /* test the gamewisp subscriber event */ if (message.equalsIgnoreCase("gamewispsubscribertest")) { print("[CONSOLE] Executing gamewispsubscribertest"); EventBus.instance().postAsync(new GameWispSubscribeEvent(this.botName, 1)); return; } /* test the gamewisp resubscriber event */ if (message.equalsIgnoreCase("gamewispresubscribertest")) { print("[CONSOLE] Executing gamewispresubscribertest"); EventBus.instance().postAsync(new GameWispAnniversaryEvent(this.botName, 2)); return; } /* test the bits event */ if (message.equalsIgnoreCase("bitstest")) { print("[CONSOLE] Executing bitstest"); EventBus.instance().postAsync(new BitsEvent(PhantomBot.getSession(this.channelName), PhantomBot.getChannel(this.channelName), this.botName, "100")); return; } /* enables debug mode */ if (message.equalsIgnoreCase("debugon")) { print("[CONSOLE] Executing debugon: Enable Debug Mode"); PhantomBot.setDebugging(true); return; } /* disables debug mode - note that setDebuggingLogOnly() completely disables all debugging */ if (message.equalsIgnoreCase("debugoff")) { print("[CONSOLE] Executing debugoff: Disable Debug Mode"); PhantomBot.setDebuggingLogOnly(false); return; } /* enables debug mode - log only */ if (message.equalsIgnoreCase("debuglog")) { print("[CONSOLE] Executing debuglog: Enable Debug Mode - Log Only"); PhantomBot.setDebuggingLogOnly(true); return; } /* Reset the bot login */ if (message.equalsIgnoreCase("reset")) { print("Are you sure you want to reset the bot login? [y/n]"); String check = System.console().readLine().trim(); if (check.equals("y")) { reset = true; changed = true; } else { print("No changes were made."); return; } } /* Change the apiOAuth token */ if (message.equalsIgnoreCase("apioauth")) { System.out.print( "Please enter you're oauth token that you generated from https://phantombot.tv/oauth while logged as the caster: "); apiOAuth = System.console().readLine().trim(); pbProperties.setProperty("apioauth", apiOAuth); changed = true; } /* Setup for MySql */ if (message.equalsIgnoreCase("mysqlsetup")) { try { print(""); print("PhantomBot MySQL setup."); print(""); com.gmt2001.Console.out.print("Please enter your MySQL host name: "); mySqlHost = System.console().readLine().trim(); pbProperties.setProperty("mysqlhost", mySqlHost); com.gmt2001.Console.out.print("Please enter your MySQL port: "); mySqlPort = System.console().readLine().trim(); pbProperties.setProperty("mysqlport", mySqlPort); com.gmt2001.Console.out.print("Please enter your MySQL db name: "); mySqlName = System.console().readLine().trim(); pbProperties.setProperty("mysqlname", mySqlName); com.gmt2001.Console.out.print("Please enter a username for MySQL: "); mySqlUser = System.console().readLine().trim(); pbProperties.setProperty("mysqluser", mySqlUser); com.gmt2001.Console.out.print("Please enter a password for MySQL: "); mySqlPass = System.console().readLine().trim(); pbProperties.setProperty("mysqlpass", mySqlPass); dataStoreType = "MySQLStore"; pbProperties.setProperty("datastore", dataStoreType); print("PhantomBot MySQL setup done, PhantomBot will exit."); changed = true; } catch (NullPointerException ex) { com.gmt2001.Console.err.printStackTrace(ex); } } /* Setup for GameWisp */ if (message.equalsIgnoreCase("gamewispsetup")) { try { print(""); print("PhantomBot GameWisp setup."); print(""); com.gmt2001.Console.out.print("Please enter your GameWisp OAuth key: "); gameWispOAuth = System.console().readLine().trim(); pbProperties.setProperty("gamewispauth", gameWispOAuth); com.gmt2001.Console.out.print("Please enter your GameWisp refresh key: "); gameWispRefresh = System.console().readLine().trim(); pbProperties.setProperty("gamewisprefresh", gameWispRefresh); print("PhantomBot GameWisp setup done, PhantomBot will exit."); changed = true; } catch (NullPointerException ex) { com.gmt2001.Console.err.printStackTrace(ex); } } /* Setup for StreamLabs (TwitchAlerts) */ if (message.equalsIgnoreCase("streamlabssetup")) { try { print(""); print("PhantomBot StreamLabs setup."); print(""); com.gmt2001.Console.out.print("Please enter your StreamLabs OAuth key: "); twitchAlertsKey = System.console().readLine().trim(); pbProperties.setProperty("twitchalertskey", twitchAlertsKey); print("PhantomBot StreamLabs setup done, PhantomBot will exit."); changed = true; } catch (NullPointerException ex) { com.gmt2001.Console.err.printStackTrace(ex); } } /* Setup for StreamTip */ if (message.equalsIgnoreCase("streamtipsetup")) { try { print(""); print("PhantomBot StreamTip setup."); print(""); com.gmt2001.Console.out.print("Please enter your StreamTip Api OAuth: "); streamTipOAuth = System.console().readLine().trim(); pbProperties.setProperty("streamtipkey", streamTipOAuth); com.gmt2001.Console.out.print("Please enter your StreamTip Client Id: "); streamTipClientId = System.console().readLine().trim(); pbProperties.setProperty("streamtipid", streamTipClientId); print("PhantomBot StreamTip setup done, PhantomBot will exit."); changed = true; } catch (NullPointerException ex) { com.gmt2001.Console.err.printStackTrace(ex); } } /* Setup for TipeeeStream */ if (message.equalsIgnoreCase("tipeeestreamsetup")) { try { print(""); print("PhantomBot TipeeeStream setup."); print(""); com.gmt2001.Console.out.print("Please enter your TipeeeStream Api OAuth: "); tipeeeStreamOAuth = System.console().readLine().trim(); pbProperties.setProperty("tipeeestreamkey", tipeeeStreamOAuth); print("PhantomBot TipeeeStream setup done, PhantomBot will exit."); changed = true; } catch (NullPointerException ex) { com.gmt2001.Console.err.printStackTrace(ex); } } /* Setup the web panel login info */ if (message.equalsIgnoreCase("panelsetup")) { try { print(""); print("PhantomBot Web Panel setup."); print("Note: Do not use any ascii characters in your username of password."); print(""); com.gmt2001.Console.out.print("Please enter a username of your choice: "); panelUsername = System.console().readLine().trim(); pbProperties.setProperty("paneluser", panelUsername); com.gmt2001.Console.out.print("Please enter a password of your choice: "); panelPassword = System.console().readLine().trim(); pbProperties.setProperty("panelpassword", panelPassword); print("PhantomBot Web Panel setup done, PhantomBot will exit."); changed = true; } catch (NullPointerException ex) { com.gmt2001.Console.err.printStackTrace(ex); } } /* Setup for Twitter */ if (message.equalsIgnoreCase("twittersetup")) { try { print(""); print("PhantomBot Twitter setup."); print(""); com.gmt2001.Console.out.print("Please enter your Twitter username: "); twitterUsername = System.console().readLine().trim(); pbProperties.setProperty("twitterUser", twitterUsername); com.gmt2001.Console.out.print("Please enter your consumer key: "); twitterConsumerToken = System.console().readLine().trim(); pbProperties.setProperty("twitter_consumer_key", twitterConsumerToken); com.gmt2001.Console.out.print("Please enter your consumer secret: "); twitterConsumerSecret = System.console().readLine().trim(); pbProperties.setProperty("twitter_consumer_secret", twitterConsumerSecret); com.gmt2001.Console.out.print("Please enter your access token: "); twitterAccessToken = System.console().readLine().trim(); pbProperties.setProperty("twitter_access_token", twitterAccessToken); com.gmt2001.Console.out.print("Please enter your access token secret: "); twitterSecretToken = System.console().readLine().trim(); pbProperties.setProperty("twitter_secret_token", twitterSecretToken); /* Delete the old Twitter file if it exists */ try { File f = new File("./twitter.txt"); f.delete(); } catch (NullPointerException ex) { com.gmt2001.Console.debug.println(ex); } print("PhantomBot Twitter setup done, PhantomBot will exit."); changed = true; } catch (NullPointerException ex) { com.gmt2001.Console.err.printStackTrace(ex); } } /* Check to see if any settings have been changed */ if (changed && !reset) { Properties outputProperties = new Properties() { @Override public synchronized Enumeration<Object> keys() { return Collections.enumeration(new TreeSet<>(super.keySet())); } }; try { try (FileOutputStream outputStream = new FileOutputStream("botlogin.txt")) { outputProperties.putAll(pbProperties); outputProperties.store(outputStream, "PhantomBot Configuration File"); } dataStore.SaveAll(true); print(""); print("Changes have been saved, now exiting PhantomBot."); print(""); System.exit(0); } catch (IOException ex) { com.gmt2001.Console.err.printStackTrace(ex); } return; } /* Save everything */ if (message.equalsIgnoreCase("save")) { print("[CONSOLE] Executing save"); dataStore.SaveAll(true); return; } /* Exit phantombot */ if (message.equalsIgnoreCase("exit")) { print("[CONSOLE] Executing exit"); System.exit(0); return; } /* handle any other commands */ handleCommand(botName, event.getMsg(), PhantomBot.getChannel(this.channelName)); // Need to support channel here. command (channel) argument[1] /* Handle dev commands */ if (event.getMsg().startsWith("!debug !dev")) { devDebugCommands(event.getMsg(), "no_id", botName, true); } }
From source file:cn.quickj.AbstractApplication.java
public void hibernateInit() { Properties properties = new Properties(); Configuration cfg = new Configuration(); // add model class to configuration. ArrayList<Class<?>> models = QuickUtils.getPackageClasses(Setting.packageRoot + ".model", null, Entity.class); models.addAll(QuickUtils.getPackageClassInJar(Setting.webRoot + "WEB-INF/lib/quick.jar", Setting.packageRoot + ".model", null, Entity.class)); for (Plugin plugin : Setting.plugins) { if (plugin.getModels() != null) models.addAll(plugin.getModels()); }//from w ww . j a va 2 s . c om for (Class<?> model : models) { cfg.addAnnotatedClass(model); } models = getModels(); if (models != null) { for (Class<?> model : models) { cfg.addAnnotatedClass(model); } } // dialectjdbcjdbc?mysqlinnodb for // mysql5dialect??? if (Setting.dialect != null && Setting.dialect.length() > 0) properties.put("hibernate.dialect", Setting.dialect); else properties.put("hibernate.dialect", QuickUtils.getDialectByDriver(Setting.jdbcDriver)); properties.put("hibernate.connection.driver_class", Setting.jdbcDriver); properties.put("hibernate.connection.url", Setting.jdbcUrl); properties.put("hibernate.connection.username", Setting.jdbcUser); properties.put("hibernate.connection.password", Setting.jdbcPassword); properties.put("hibernate.connection.provider_class", "org.hibernate.connection.C3P0ConnectionProvider"); properties.put("hibernate.c3p0.min_size", Setting.initActive + ""); properties.put("hibernate.c3p0.max_size", Setting.maxActive + ""); properties.put("hibernate.c3p0.timeout", Setting.maxIdle + ""); properties.put("hibernate.c3p0.idle_test_period", "600");//10 properties.put("hibernate.c3p0.preferredTestQuery", "SELECT 1"); if (Setting.runMode == Setting.DEV_MODE) { properties.put("hibernate.show_sql", "true"); } properties.put("hibernate.order_updates", "true"); properties.put("hibernate.cache.use_second_level_cache", "true"); properties.put("hibernate.cache.provider_class", "org.hibernate.cache.EhCacheProvider"); Properties extraProp = new Properties(); try { InputStream extra = ClassLoader.getSystemResourceAsStream("hibernate.properties"); if (extra != null) { extraProp.load(extra); properties.putAll(extraProp); } } catch (IOException e) { e.printStackTrace(); } onHibernateConfig(properties); cfg.mergeProperties(properties); ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()) .buildServiceRegistry(); Setting.sessionFactory = cfg.buildSessionFactory(serviceRegistry); }
From source file:org.apache.flink.streaming.connectors.kafka.KafkaConsumerTestBase.java
/** * Test that ensures the KafkaConsumer is properly failing if the topic doesnt exist * and a wrong broker was specified/* w ww . j av a 2 s . c o m*/ * * @throws Exception */ public void runFailOnNoBrokerTest() throws Exception { try { Properties properties = new Properties(); StreamExecutionEnvironment see = StreamExecutionEnvironment.createRemoteEnvironment("localhost", flinkPort); see.getConfig().disableSysoutLogging(); see.setRestartStrategy(RestartStrategies.noRestart()); see.setParallelism(1); // use wrong ports for the consumers properties.setProperty("bootstrap.servers", "localhost:80"); properties.setProperty("zookeeper.connect", "localhost:80"); properties.setProperty("group.id", "test"); properties.setProperty("request.timeout.ms", "3000"); // let the test fail fast properties.setProperty("socket.timeout.ms", "3000"); properties.setProperty("session.timeout.ms", "2000"); properties.setProperty("fetch.max.wait.ms", "2000"); properties.setProperty("heartbeat.interval.ms", "1000"); properties.putAll(secureProps); FlinkKafkaConsumerBase<String> source = kafkaServer.getConsumer("doesntexist", new SimpleStringSchema(), properties); DataStream<String> stream = see.addSource(source); stream.print(); see.execute("No broker test"); } catch (ProgramInvocationException pie) { if (kafkaServer.getVersion().equals("0.9") || kafkaServer.getVersion().equals("0.10")) { assertTrue(pie.getCause() instanceof JobExecutionException); JobExecutionException jee = (JobExecutionException) pie.getCause(); assertTrue(jee.getCause() instanceof TimeoutException); TimeoutException te = (TimeoutException) jee.getCause(); assertEquals("Timeout expired while fetching topic metadata", te.getMessage()); } else { assertTrue(pie.getCause() instanceof JobExecutionException); JobExecutionException jee = (JobExecutionException) pie.getCause(); assertTrue(jee.getCause() instanceof RuntimeException); RuntimeException re = (RuntimeException) jee.getCause(); assertTrue(re.getMessage() .contains("Unable to retrieve any partitions for the requested topics [doesntexist]")); } } }
From source file:org.apache.flink.streaming.connectors.kafka.KafkaConsumerTestBase.java
/** * Runs a job using the provided environment to read a sequence of records from a single Kafka topic. * The method allows to individually specify the expected starting offset and total read value count of each partition. * The job will be considered successful only if all partition read results match the start offset and value count criteria. *//*from w ww .j av a 2 s.com*/ protected void readSequence(final StreamExecutionEnvironment env, final StartupMode startupMode, final Map<KafkaTopicPartition, Long> specificStartupOffsets, final Properties cc, final String topicName, final Map<Integer, Tuple2<Integer, Integer>> partitionsToValuesCountAndStartOffset) throws Exception { final int sourceParallelism = partitionsToValuesCountAndStartOffset.keySet().size(); int finalCountTmp = 0; for (Map.Entry<Integer, Tuple2<Integer, Integer>> valuesCountAndStartOffset : partitionsToValuesCountAndStartOffset .entrySet()) { finalCountTmp += valuesCountAndStartOffset.getValue().f0; } final int finalCount = finalCountTmp; final TypeInformation<Tuple2<Integer, Integer>> intIntTupleType = TypeInfoParser .parse("Tuple2<Integer, Integer>"); final TypeInformationSerializationSchema<Tuple2<Integer, Integer>> deser = new TypeInformationSerializationSchema<>( intIntTupleType, env.getConfig()); // create the consumer cc.putAll(secureProps); FlinkKafkaConsumerBase<Tuple2<Integer, Integer>> consumer = kafkaServer.getConsumer(topicName, deser, cc); switch (startupMode) { case EARLIEST: consumer.setStartFromEarliest(); break; case LATEST: consumer.setStartFromLatest(); break; case SPECIFIC_OFFSETS: consumer.setStartFromSpecificOffsets(specificStartupOffsets); break; case GROUP_OFFSETS: consumer.setStartFromGroupOffsets(); break; } DataStream<Tuple2<Integer, Integer>> source = env.addSource(consumer).setParallelism(sourceParallelism) .map(new ThrottledMapper<Tuple2<Integer, Integer>>(20)).setParallelism(sourceParallelism); // verify data source.flatMap(new RichFlatMapFunction<Tuple2<Integer, Integer>, Integer>() { private HashMap<Integer, BitSet> partitionsToValueCheck; private int count = 0; @Override public void open(Configuration parameters) throws Exception { partitionsToValueCheck = new HashMap<>(); for (Integer partition : partitionsToValuesCountAndStartOffset.keySet()) { partitionsToValueCheck.put(partition, new BitSet()); } } @Override public void flatMap(Tuple2<Integer, Integer> value, Collector<Integer> out) throws Exception { int partition = value.f0; int val = value.f1; BitSet bitSet = partitionsToValueCheck.get(partition); if (bitSet == null) { throw new RuntimeException("Got a record from an unknown partition"); } else { bitSet.set(val - partitionsToValuesCountAndStartOffset.get(partition).f1); } count++; LOG.info("Received message {}, total {} messages", value, count); // verify if we've seen everything if (count == finalCount) { for (Map.Entry<Integer, BitSet> partitionsToValueCheck : this.partitionsToValueCheck .entrySet()) { BitSet check = partitionsToValueCheck.getValue(); int expectedValueCount = partitionsToValuesCountAndStartOffset .get(partitionsToValueCheck.getKey()).f0; if (check.cardinality() != expectedValueCount) { throw new RuntimeException("Expected cardinality to be " + expectedValueCount + ", but was " + check.cardinality()); } else if (check.nextClearBit(0) != expectedValueCount) { throw new RuntimeException("Expected next clear bit to be " + expectedValueCount + ", but was " + check.cardinality()); } } // test has passed throw new SuccessException(); } } }).setParallelism(1); tryExecute(env, "Read data from Kafka"); LOG.info("Successfully read sequence for verification"); }