@Override public boolean apply(String input) { String firstWord = Strings.getFirstWord(input); return id.startsWith(firstWord); } });
@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()); } };
/** returns the first word after the given phrase, or null if no such phrase; * if the character immediately after the phrase is not whitespace, the non-whitespace * sequence starting with that character will be returned */ public static String getFirstWordAfter(String context, String phrase) { if (context==null || phrase==null) return null; int index = context.indexOf(phrase); if (index<0) return null; return getFirstWord(context.substring(index + phrase.length())); }
@Override public Duration apply(SshPollValue input) { return Duration.seconds(Double.valueOf(Strings.getFirstWord(input.getStdout()))); } }))
@Test public void testFirstWord() { Assert.assertEquals(Strings.getFirstWord("hello world"), "hello"); Assert.assertEquals(Strings.getFirstWord(" hello world"), "hello"); Assert.assertEquals(Strings.getFirstWord(" hello "), "hello"); Assert.assertEquals(Strings.getFirstWord("hello"), "hello"); Assert.assertEquals(Strings.getFirstWord(" "), null); Assert.assertEquals(Strings.getFirstWord(""), null); Assert.assertEquals(Strings.getFirstWord(null), null); }
/** {@inheritDoc} */ @Override public String runDockerCommandTimeout(String command, Duration timeout) { // FIXME Set DOCKER_OPTS values in command-line for when running on localhost String stdout = execCommandTimeout(BashCommands.sudo(String.format("docker %s", command)), timeout); LOG.debug("Successfully executed Docker {}: {}", Strings.getFirstWord(command), Strings.getFirstLine(stdout)); return Strings.trim(stdout); }
Optional<String> node = Iterables.tryFind(found, Predicates.containsPattern(nodeName)); if (Iterables.size(found) > 1 && node.isPresent()) { String nodeId = Strings.getFirstWord(node.get()).replace(":", ""); log.debug("{}: Removing etcd node {} with id {} from {}", new Object[] { entity, nodeName, nodeId, getClientUrl() });
for (int i = 1; i < ps.size(); i++) { String line = ps.get(i); String id = Strings.getFirstWord(line); Optional<Entity> container = Iterables.tryFind(getDockerContainerCluster().getMembers(), Predicates.compose(StringPredicates.startsWith(id), EntityFunctions.attribute(DockerContainer.DOCKER_CONTAINER_ID))); String containerId = Strings.getFirstWord(runDockerCommand("inspect --format {{.Id}} " + id)); String imageId = Strings.getFirstWord(runDockerCommand("inspect --format {{.Image}} " + id)); String imageName = Strings.getFirstWord(runDockerCommand("inspect --format {{.Config.Image}} " + id)); EntitySpec<DockerContainer> containerSpec = EntitySpec.create(config().get(DOCKER_CONTAINER_SPEC)); containerSpec.configure(SoftwareProcess.ENTITY_STARTED, Boolean.TRUE)
.noExtraOutput(); uname.execute(); String kernelVersion = Strings.getFirstWord(uname.getResultStdout());