List of usage examples for com.google.common.base Predicates containsPattern
@GwtIncompatible(value = "java.util.regex.Pattern") public static Predicate<CharSequence> containsPattern(String pattern)
From source file:com.groupon.mesos.zookeeper.ZookeeperMasterDetector.java
private void processChildList(final List<String> children) { final Set<String> masterNodes = ImmutableSet .copyOf(Iterables.filter(children, Predicates.containsPattern("^info_"))); eventBus.post(new MasterUpdateMessage(masterNodes)); }
From source file:brooklyn.location.basic.LocationPropertiesFromBrooklynProperties.java
/** * Gets all properties that start with the given {@code fullPrefix}, stripping off * the prefix in the returned map.//from ww w . jav a 2 s. c om * * Returns only those properties whose key suffix is a single word (i.e. contains no dots). * We do this special (sub-optimal!) filtering because we want sub-scoped things * (e.g. could want brooklyn.location.privateKeyFile, but not brooklyn.location.named.*). */ protected Map<String, Object> getMatchingSingleWordProperties(String fullPrefix, Map<String, ?> properties) { BrooklynProperties filteredProperties = ConfigUtils.filterForPrefixAndStrip(properties, fullPrefix); return ConfigUtils.filterFor(filteredProperties, Predicates.not(Predicates.containsPattern("\\."))) .asMapWithStringKeys(); }
From source file:org.killbill.billing.plugin.adyen.api.mapping.PaymentInfoMappingService.java
private static void set3DSecureFields(final PaymentInfo paymentInfo, final Iterable<PluginProperty> properties) { final String ccUserAgent = PluginProperties.findPluginPropertyValue(PROPERTY_USER_AGENT, properties); paymentInfo.setUserAgent(ccUserAgent); final String ccAcceptHeader = PluginProperties.findPluginPropertyValue(PROPERTY_ACCEPT_HEADER, properties); paymentInfo.setAcceptHeader(ccAcceptHeader); final String md = PluginProperties.findPluginPropertyValue(PROPERTY_MD, properties); if (md != null) { paymentInfo.setMd(decode(md));//w w w . j a v a 2 s .c o m } final String paRes = PluginProperties.findPluginPropertyValue(PROPERTY_PA_RES, properties); if (paRes != null) { paymentInfo.setPaRes(decode(paRes)); } final String threeDThreshold = PluginProperties.findPluginPropertyValue(PROPERTY_THREE_D_THRESHOLD, properties); if (!Strings.isNullOrEmpty(threeDThreshold)) { // Expected in minor units paymentInfo.setThreeDThreshold(Long.valueOf(threeDThreshold)); } final String mpiDataDirectoryResponse = PluginProperties .findPluginPropertyValue(PROPERTY_MPI_DATA_DIRECTORY_RESPONSE, properties); paymentInfo.setMpiDataDirectoryResponse(mpiDataDirectoryResponse); final String mpiDataAuthenticationResponse = PluginProperties .findPluginPropertyValue(PROPERTY_MPI_DATA_AUTHENTICATION_RESPONSE, properties); paymentInfo.setMpiDataAuthenticationResponse(mpiDataAuthenticationResponse); final String mpiDataCavv = PluginProperties.findPluginPropertyValue(PROPERTY_MPI_DATA_CAVV, properties); paymentInfo.setMpiDataCavv(mpiDataCavv); final String mpiDataCavvAlgorithm = PluginProperties .findPluginPropertyValue(PROPERTY_MPI_DATA_CAVV_ALGORITHM, properties); paymentInfo.setMpiDataCavvAlgorithm(mpiDataCavvAlgorithm); final String mpiDataXid = PluginProperties.findPluginPropertyValue(PROPERTY_MPI_DATA_XID, properties); paymentInfo.setMpiDataXid(mpiDataXid); final String mpiDataEci = PluginProperties.findPluginPropertyValue(PROPERTY_MPI_DATA_ECI, properties); paymentInfo.setMpiDataEci(mpiDataEci); final String mpiImplementationType = PluginProperties .findPluginPropertyValue(PROPERTY_MPI_IMPLEMENTATION_TYPE, properties); paymentInfo.setMpiImplementationType(mpiImplementationType); if (mpiImplementationType != null) { paymentInfo.setMpiImplementationTypeValues(Maps.filterKeys(PluginProperties.toStringMap(properties), Predicates.containsPattern(mpiImplementationType + "."))); } final String termUrl = PluginProperties.findPluginPropertyValue(PROPERTY_TERM_URL, properties); paymentInfo.setTermUrl(termUrl); }
From source file:brooklyn.entity.nosql.etcd.EtcdNodeSshDriver.java
@Override public void leaveCluster(String nodeName) { List<String> listMembersCommands = Lists.newLinkedList(); listMembersCommands.add("cd " + getRunDir()); listMembersCommands.add(String.format("%s --peers %s member list", getEtcdCtlCommand(), getClientUrl())); ScriptHelper listMembersScript = newScript("listMembers").body.append(listMembersCommands).gatherOutput(); int result = listMembersScript.execute(); if (result != 0) { log.warn("{}: The 'member list' command on etcd '{}' failed: {}", new Object[] { entity, getClientUrl(), result }); ;/*from w ww . j av a 2 s .c o m*/ log.debug("{}: STDOUT: {}", entity, listMembersScript.getResultStdout()); log.debug("{}: STDERR: {}", entity, listMembersScript.getResultStderr()); return; // Do not throw exception as may not be possible during shutdown } String output = listMembersScript.getResultStdout(); Optional<String> found = Iterables.tryFind(Splitter.on(CharMatcher.anyOf("\r\n")).split(output), Predicates.containsPattern("name=" + nodeName)); if (found.isPresent()) { String nodeId = Strings.getFirstWord(found.get()).replace(":", ""); log.debug("{}: Removing etcd node {} with id {} from {}", new Object[] { entity, nodeName, nodeId, getClientUrl() }); List<String> removeMemberCommands = Lists.newLinkedList(); removeMemberCommands.add("cd " + getRunDir()); removeMemberCommands.add( String.format("%s --peers %s member remove %s", getEtcdCtlCommand(), getClientUrl(), nodeId)); newScript("removeMember").body.append(removeMemberCommands).failOnNonZeroResultCode().execute(); } else { log.warn("{}: Did not find {} in list of etcd members", entity, nodeName); } }
From source file:org.apache.brooklyn.entity.nosql.etcd.EtcdNodeSshDriver.java
@Override public void leaveCluster(String nodeName) { synchronized (getEntity().getClusterMutex()) { List<String> listMembersCommands = Lists.newLinkedList(); listMembersCommands.add("cd " + getRunDir()); listMembersCommands/*from w ww . j a va2 s .co m*/ .add(String.format("%s --peers %s member list", getEtcdCtlCommand(), getClientUrl())); ScriptHelper listMembersScript = newScript("listMembers").body.append(listMembersCommands) .gatherOutput(); int result = listMembersScript.execute(); if (result != 0) { log.warn("{}: The 'member list' command on etcd '{}' failed: {}", new Object[] { entity, getClientUrl(), result }); ; log.debug("{}: STDOUT: {}", entity, listMembersScript.getResultStdout()); log.debug("{}: STDERR: {}", entity, listMembersScript.getResultStderr()); return; // Do not throw exception as may not be possible during shutdown } String output = listMembersScript.getResultStdout(); Iterable<String> found = Iterables.filter(Splitter.on(CharMatcher.anyOf("\r\n")).split(output), Predicates.containsPattern("name=")); 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() }); List<String> removeMemberCommands = Lists.newLinkedList(); removeMemberCommands.add("cd " + getRunDir()); removeMemberCommands.add(String.format("%s --peers %s member remove %s", getEtcdCtlCommand(), getClientUrl(), nodeId)); newScript("removeMember").body.append(removeMemberCommands).failOnNonZeroResultCode().execute(); } else { log.warn("{}: {} is not part of an etcd cluster", entity, nodeName); } } }
From source file:clocker.docker.location.DockerContainerLocation.java
@Override public int execScript(Map<String, ?> props, String summaryForLogging, List<String> commands, Map<String, ?> env) { Iterable<String> filtered = Iterables.filter(commands, DockerCallbacks.FILTER); for (String commandString : filtered) { parseDockerCallback(commandString); }// w ww . j a v a 2 s. c o m boolean entitySsh = Boolean.TRUE.equals(entity.config().get(DockerContainer.DOCKER_USE_SSH)); boolean dockerSsh = Boolean.TRUE.equals(getOwner().config().get(DockerContainer.DOCKER_USE_SSH)); if (entitySsh && dockerSsh) { return super.execScript(props, summaryForLogging, commands, env); } else { Map<String, ?> nonPortProps = Maps.filterKeys(props, Predicates.not(Predicates.containsPattern("port"))); return hostMachine.execCommands(nonPortProps, summaryForLogging, getDockerExecCommand(commands, env)); } }
From source file:com.davidbracewell.string.StringPredicates.java
/** * Creates a predicate that matches a given regular expression * * @param pattern the pattern to match//from w w w. j a va 2 s. c om * @return the predicate */ public static Predicate<CharSequence> REGEX_MATCH(String pattern) { return Predicates.containsPattern(pattern); }
From source file:org.apache.brooklyn.location.jclouds.JCloudsPropertiesBuilder.java
public JCloudsPropertiesBuilder setCustomJcloudsProperties() { Map<String, Object> extra = Maps.filterKeys(conf.getAllConfig(), Predicates.containsPattern("^jclouds\\.")); if (extra.size() > 0) { String provider = getProviderFromConfig(conf); LOG.debug("Configuring custom jclouds property overrides for {}: {}", provider, Sanitizer.sanitize(extra)); }//w w w.j av a 2 s . c om properties.putAll(Maps.filterValues(extra, Predicates.notNull())); return this; }
From source file:clocker.docker.location.DockerContainerLocation.java
@Override public int execCommands(Map<String, ?> props, String summaryForLogging, List<String> commands, Map<String, ?> env) { Iterable<String> filtered = Iterables.filter(commands, DockerCallbacks.FILTER); for (String commandString : filtered) { parseDockerCallback(commandString); }/*from w w w. j av a 2 s.c o m*/ boolean entitySsh = Boolean.TRUE.equals(entity.config().get(DockerContainer.DOCKER_USE_SSH)); boolean dockerSsh = Boolean.TRUE.equals(getOwner().config().get(DockerContainer.DOCKER_USE_SSH)); if (entitySsh && dockerSsh) { return super.execCommands(props, summaryForLogging, commands, env); } else { Map<String, ?> nonPortProps = Maps.filterKeys(props, Predicates.not(Predicates.containsPattern("port"))); return hostMachine.execCommands(nonPortProps, summaryForLogging, getDockerExecCommand(commands, env)); } }
From source file:grkvlt.Ec2CleanUp.java
private Iterable<String> getVolumesMatchingName(TagApi tagApi, final String name) { FluentIterable<Tag> volumeTags = tagApi.filter(new TagFilterBuilder().volume().key("Name").build()); LOG.info("Found {} named Volumes", Iterables.size(volumeTags)); FluentIterable<String> filtered = volumeTags.filter(new Predicate<Tag>() { @Override//from ww w . j av a 2 s.c om public boolean apply(Tag input) { return Predicates.containsPattern("^" + name + "$").apply(input.getValue().orNull()); } }).transform(new Function<Tag, String>() { @Override public String apply(Tag input) { return input.getResourceId(); } }); LOG.info("Found {} matching Volumes", Iterables.size(filtered)); return filtered; }