List of usage examples for com.google.common.collect Iterables get
public static <T> T get(Iterable<T> iterable, int position)
From source file:org.jclouds.cloudloadbalancers.loadbalancer.strategy.CloudLoadBalancersLoadBalanceNodesStrategy.java
@Override public LoadBalancerMetadata createLoadBalancerInLocation(Location location, String name, String protocol, int loadBalancerPort, final int instancePort, Iterable<? extends NodeMetadata> nodes) { String region = checkNotNull(location, "location").getId(); // TODO need to query and update the LB per current design. LoadBalancer lb = client.getLoadBalancerClient(region) .createLoadBalancer(LoadBalancerRequest.builder().name(name).protocol(protocol.toUpperCase()) .port(loadBalancerPort).virtualIPType(Type.PUBLIC) .nodes(Iterables.transform(nodes, new Function<NodeMetadata, NodeRequest>() { @Override public NodeRequest apply(NodeMetadata arg0) { return NodeRequest.builder().address(Iterables.get(arg0.getPrivateAddresses(), 0)) .port(instancePort).build(); }/*from w w w. ja v a 2 s . c om*/ })).build()); return getLB.getLoadBalancer(region + "/" + lb.getId()); }
From source file:org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule.java
@Provides @Singleton//from w w w .j av a 2s .c o m protected Supplier<Location> getLocation(@Memoized Supplier<Set<? extends Location>> locations) { return Suppliers.<Location>ofInstance(Iterables.get(locations.get(), 0)); }
From source file:net.freifunk.autodeploy.selenium.HeadlessDriver.java
@Override protected void get(final URL url) { final String userInfo = url.getUserInfo(); if (userInfo != null) { final Iterable<String> parts = Splitter.on(':').split(userInfo); Preconditions.checkState(Iterables.size(parts) == 2, "Expecting format user:password for userinfo."); final String username = Iterables.get(parts, 0); final String password = Iterables.getLast(parts); _headlessDriverCredentialsProvider.set(username, password); } else {//from w w w. j a va 2 s . c o m _headlessDriverCredentialsProvider.reset(); } super.get(url); }
From source file:nz.co.testamation.testcommon.fixture.SomeFixture.java
public static <T> T someValue(Collection<T> values) { return Iterables.get(values, someIntLessThan(values.size())); }
From source file:org.apache.pulsar.broker.loadbalance.impl.WRRPlacementStrategy.java
/** * <code>/* ww w . j a va 2s .co m*/ * Function : getByWeightedRoundRobin * returns ResourceUnit selected by WRR algorithm based on available resource on RU * ^ * | * | * | * | | | | | * | | | | | * | Broker 2 | Broker 3 | Broker 1 | B4 | * | | | | | * +----------------+------------------------+--------------------------------+---------> * 0 20 50 90 100 * * This is weighted Round robin, we calculate weight based on availability of resources; * total availability is taken as a full range then each broker is given range based on * its resource availability, if the number generated within total range happens to be in * broker's range, that broker is selected * </code> */ public ResourceUnit findBrokerForPlacement(Multimap<Long, ResourceUnit> finalCandidates) { if (finalCandidates.isEmpty()) { return null; } log.debug("Total Final Candidates selected - [{}]", finalCandidates.size()); int totalAvailability = 0; for (Map.Entry<Long, ResourceUnit> candidateOwner : finalCandidates.entries()) { totalAvailability += candidateOwner.getKey().intValue(); } ResourceUnit selectedRU = null; if (totalAvailability <= 0) { // todo: this means all the brokers are overloaded and we can't assign this namespace to any broker // for now, pick anyone and return that one, because when we don't have ranking we put O for each broker return Iterables.get(finalCandidates.get(0L), rand.nextInt(finalCandidates.size())); } int weightedSelector = rand.nextInt(totalAvailability); log.debug("Generated Weighted Selector Number - [{}] ", weightedSelector); int weightRangeSoFar = 0; for (Map.Entry<Long, ResourceUnit> candidateOwner : finalCandidates.entries()) { weightRangeSoFar += candidateOwner.getKey(); if (weightedSelector < weightRangeSoFar) { selectedRU = candidateOwner.getValue(); log.debug(" Weighted Round Robin Selected RU - [{}]", candidateOwner.getValue().getResourceId()); break; } } return selectedRU; }
From source file:org.jclouds.ec2.compute.functions.CreateSecurityGroupIfNeeded.java
private void authorizeGroupToItself(String region, String name) { logger.debug(">> authorizing securityGroup region(%s) name(%s) permission to itself", region, name); String myOwnerId = Iterables .get(ec2Client.getSecurityGroupServices().describeSecurityGroupsInRegion(region), 0).getOwnerId(); ec2Client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(region, name, new UserIdGroupPair(myOwnerId, name)); logger.debug("<< authorized securityGroup(%s)", name); }
From source file:com.google.template.soy.passes.CheckCallsVisitor.java
@Override protected void visitCallNode(CallNode node) { // Recurse.// w w w . ja va 2 s . c om visitChildren(node); // If all the data keys being passed are listed using 'param' commands, then check that all // required params of the callee are included. if (!node.dataAttribute().isPassingData()) { // Get the callee node (basic or delegate). TemplateNode callee = null; if (node instanceof CallBasicNode) { callee = templateRegistry.getBasicTemplate(((CallBasicNode) node).getCalleeName()); } else { String delTemplateName = ((CallDelegateNode) node).getDelCalleeName(); ImmutableSet<DelegateTemplateDivision> divisions = templateRegistry .getDelTemplateDivisionsForAllVariants(delTemplateName); if (!divisions.isEmpty()) { callee = Iterables .get(Iterables.getFirst(divisions, null).delPackageNameToDelTemplateMap.values(), 0); } } // Do the check if the callee node has declared params. if (callee != null && callee.getParams() != null) { // Get param keys passed by caller. Set<String> callerParamKeys = Sets.newHashSet(); for (CallParamNode callerParam : node.getChildren()) { callerParamKeys.add(callerParam.getKey()); } // Check param keys required by callee. List<String> missingParamKeys = Lists.newArrayListWithCapacity(2); for (TemplateParam calleeParam : callee.getParams()) { if (calleeParam.isRequired() && !callerParamKeys.contains(calleeParam.name())) { missingParamKeys.add(calleeParam.name()); } } // Report errors. if (!missingParamKeys.isEmpty()) { String errorMsgEnd = (missingParamKeys.size() == 1) ? "param '" + missingParamKeys.get(0) + "'" : "params " + missingParamKeys; errorReporter.report(node.getSourceLocation(), MISSING_PARAM, errorMsgEnd); } } } }
From source file:org.jclouds.rackspace.cloudloadbalancers.loadbalancer.strategy.CloudLoadBalancersLoadBalanceNodesStrategy.java
@Override public LoadBalancerMetadata createLoadBalancerInLocation(Location location, String name, String protocol, int loadBalancerPort, final int instancePort, Iterable<? extends NodeMetadata> nodes) { String region = checkNotNull(location, "location").getId(); // TODO need to query and update the LB per current design. LoadBalancer lb = client.getLoadBalancerApiForZone(region) .create(LoadBalancerRequest.builder().name(name).protocol(protocol.toUpperCase()) .port(loadBalancerPort).virtualIPType(Type.PUBLIC) .nodes(Iterables.transform(nodes, new Function<NodeMetadata, NodeRequest>() { @Override public NodeRequest apply(NodeMetadata arg0) { return NodeRequest.builder().address(Iterables.get(arg0.getPrivateAddresses(), 0)) .port(instancePort).build(); }//from w w w. ja va 2 s .c o m })).build()); return getLB.getLoadBalancer(region + "/" + lb.getId()); }
From source file:org.jclouds.rackspace.cloudloadbalancers.v1.loadbalancer.strategy.CloudLoadBalancersLoadBalanceNodesStrategy.java
@Override public LoadBalancerMetadata createLoadBalancerInLocation(Location location, String name, String protocol, int loadBalancerPort, final int instancePort, Iterable<? extends NodeMetadata> nodes) { String region = checkNotNull(location, "location").getId(); // TODO need to query and update the LB per current design. LoadBalancer lb = client.getLoadBalancerApiForZone(region) .create(CreateLoadBalancer.builder().name(name).protocol(protocol.toUpperCase()) .port(loadBalancerPort).virtualIPType(Type.PUBLIC) .nodes(Iterables.transform(nodes, new Function<NodeMetadata, AddNode>() { @Override public AddNode apply(NodeMetadata arg0) { return AddNode.builder().address(Iterables.get(arg0.getPrivateAddresses(), 0)) .port(instancePort).build(); }//from w w w . j a v a2 s.c o m })).build()); return getLB.getLoadBalancer(region + "/" + lb.getId()); }
From source file:net.holmes.core.business.streaming.airplay.controlpoint.CommandResponse.java
/** * Decode content parameters./*from w w w .j a v a2 s . co m*/ * * @param content content */ public void decodeContentParameters(String content) { for (String line : Splitter.on(EOL).split(content)) { Iterable<String> it = Splitter.on(PARAMETER_SEPARATOR).trimResults().split(line); if (Iterables.size(it) > 1) { contentParameters.put(Iterables.get(it, 0), Iterables.getLast(it)); } } }