@Override public Double apply(SshPollValue input) { String q = Strings.getFirstWordAfter(input.getStdout(), "Queries per second avg:"); return (q == null) ? null : Double.parseDouble(q); }}) .setOnFailureOrException(null) )
@Override public Double apply(SshPollValue input) { String loadAverage = Strings.getFirstWordAfter(input.getStdout(), "load average:").replace(",", ""); return Double.valueOf(loadAverage); } }))
@Override public Double apply(SshPollValue input) { String q = Strings.getFirstWordAfter(input.getStdout(), "Queries per second avg:"); if (q==null) return null; return Double.parseDouble(q); }}) .setOnFailureOrException(null)
@Override public Optional<String> getImageNamed(String name, String tag) { String imageList = runDockerCommand("images --no-trunc " + name); return Optional.fromNullable(Strings.getFirstWordAfter(imageList, tag)); }
@Test public void testFirstWordAfter() { Assert.assertEquals(Strings.getFirstWordAfter("hello world", "hello"), "world"); Assert.assertEquals(Strings.getFirstWordAfter(" hello world", "hello"), "world"); Assert.assertEquals(Strings.getFirstWordAfter(" hello world: is not enough", "world:"), "is"); Assert.assertEquals(Strings.getFirstWordAfter(" hello world: is not enough", "world"), ":"); Assert.assertEquals(Strings.getFirstWordAfter(" hello ", "hello"), null); Assert.assertEquals(Strings.getFirstWordAfter("hello", "hello"), null); Assert.assertEquals(Strings.getFirstWordAfter(" ", "x"), null); Assert.assertEquals(Strings.getFirstWordAfter("", "x"), null); Assert.assertEquals(Strings.getFirstWordAfter(null, "x"), null); }
private String buildDockerfile(String dockerfile, String name) { String build = format("build --rm -t %s - < %s", name, Os.mergePaths(getRunDir(), name, dockerfile)); String stdout = ((DockerHost) getEntity()).runDockerCommandTimeout(build, Duration.minutes(20)); String prefix = Strings.getFirstWordAfter(stdout, "Successfully built"); return getImageId(prefix, name); }
private String buildDockerfileDirectory(String name) { String build = format("build --rm -t %s %s", name, Os.mergePaths(getRunDir(), name)); String stdout = ((DockerHost) getEntity()).runDockerCommandTimeout(build, Duration.minutes(20)); String prefix = Strings.getFirstWordAfter(stdout, "Successfully built"); return getImageId(prefix, name); }
String dockerIp = Strings.getFirstWordAfter(dockerIpOutput.replace('/', ' '), "inet"); String inspect = Strings.trimEnd(slave.execCommand(sudo("docker inspect -f '{{.State.Pid}}' " + containerId))); String dockerPid = Iterables.find(Splitter.on(CharMatcher.anyOf("\r\n")).omitEmptyStrings().split(inspect), Cidr subnetCidr = getSubnetCidr(subnetId); String slaveAddressOutput = slave.execCommand(sudo("ip addr show dev eth0 scope global label eth0")); String slaveAddress = Strings.getFirstWordAfter(slaveAddressOutput.replace('/', ' '), "inet");
private Long getRunTimeUtc(VanillaSoftwareProcess p) { Assert.assertNotNull(p.getAttribute(SoftwareProcess.RUN_DIR)); return Long.parseLong( Strings.getFirstWordAfter(new ResourceUtils(this).getResourceAsString(Os.mergePaths(p.getAttribute(SoftwareProcess.RUN_DIR), "DATE")), "utc") ); }
@Override public boolean apply(Application app) { VanillaWindowsProcess entity = Iterables.getOnlyElement(Entities.descendantsAndSelf(app, VanillaWindowsProcess.class)); String winRMAddress = entity.getAttribute(AdvertiseWinrmLoginPolicy.VM_USER_CREDENTIALS); String ipPort = Strings.getFirstWordAfter(winRMAddress, "@"); String user = Strings.getFirstWord(winRMAddress); String password = Strings.getFirstWordAfter(winRMAddress, ":"); WinRmTool winRmTool = WinRmTool.Builder.builder(ipPort, user, password).build(); WinRmToolResponse winRmResponse = winRmTool.executePs(ImmutableList.of("(Get-Item \"C:\\\\Program Files\\\\7-Zip\\\\7z.exe\").name")); LOG.info("winRmResponse: code="+winRmResponse.getStatusCode()+"; out="+winRmResponse.getStdOut()+"; err="+winRmResponse.getStdErr()); return "7z.exe\r\n".equals(winRmResponse.getStdOut()); } };
/** yaml variant of VanillaSoftwareProcessAndChildrenIntegrationTest */ @Test(groups="Integration") public void testVanillaSoftwareYamlWithChildStartedAfter() { SimpleYamlLauncher l = new SimpleYamlLauncherForTests(); try { Application app = l.launchAppYaml("vanilla-software-with-child-blueprint.yaml"); log.info("started "+app); Entity p1 = Iterables.getOnlyElement( app.getChildren() ); Long d1 = Long.parseLong( Strings.getFirstWordAfter(new ResourceUtils(this).getResourceAsString(Os.mergePaths(p1.getAttribute(SoftwareProcess.RUN_DIR), "DATE")), "utc") ); Entity p2 = Iterables.getOnlyElement( p1.getChildren() ); Long d2 = Long.parseLong( Strings.getFirstWordAfter(new ResourceUtils(this).getResourceAsString(Os.mergePaths(p2.getAttribute(SoftwareProcess.RUN_DIR), "DATE")), "utc") ); Assert.assertTrue( d2-d1 > 2 && d2-d1 < 10, "p2 should have started 3s after parent, but it did not ("+(d2-d1)+"s difference" ); } finally { l.destroyAll(); } log.info("DONE"); }
Long d1 = Long.parseLong( Strings.getFirstWordAfter(fileContents, "utc") ); Assert.assertTrue( Math.abs(d1*1000-System.currentTimeMillis())<15000, "Time UTC does not match system; "+d1+" v "+System.currentTimeMillis() );