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.asoem.greyfish.core.actions.ResourceConsumptionAction.java
@Override protected ImmutableACLMessage.Builder<A> createCFP(final AgentContext<A> context) { final A receiver = Iterables.get(sensedMates, RandomGenerators.rng().nextInt(Iterables.size(sensedMates))); sensedMates = ImmutableList.of();/*from w w w . j av a 2 s . c o m*/ return ImmutableACLMessage.<A>builder().sender(context.agent()).performative(ACLPerformative.CFP) .ontology(getOntology()) // Choose only one receiver. Adding evaluates possible candidates as receivers will decrease the performance in high density populations! .addReceiver(receiver) .content(new ResourceRequestMessage(call(requestAmount, this), call(classification, this))); }
From source file:clocker.docker.location.strategy.basic.LabelPlacementStrategy.java
@Override public boolean apply(DockerHostLocation input) { Set<String> labels = MutableSet.copyOf(config().get(LABELS)); if (labels.isEmpty()) return true; SshMachineLocation ssh = input.getMachine(); if (ssh instanceof JcloudsSshMachineLocation) { JcloudsSshMachineLocation jclouds = (JcloudsSshMachineLocation) ssh; NodeMetadata metadata = jclouds.getOptionalNode().get(); Set<String> tags = MutableSet .copyOf(Iterables.transform(metadata.getTags(), new Function<String, String>() { @Override/*from w w w. j av a 2s . c o m*/ public String apply(String input) { return Iterables.get(Splitter.on("=").split(input), 0); } })); tags.addAll(metadata.getUserMetadata().keySet()); labels.removeAll(tags); LOG.debug("Host {} : Tags {} : Remaining {}", new Object[] { input, Iterables.toString(tags), labels.isEmpty() ? "none" : Iterables.toString(labels) }); return labels.isEmpty(); } else { return false; } }
From source file:fr.duminy.objectviewer.ui.BeanTableModel.java
@SuppressWarnings("unchecked") BeanTableModel(Class<T> baseClass, List<T> beans) { SortedSet<Method> getters = new TreeSet<Method>(METHOD_COMPARATOR); getters.addAll(getAllMethods(baseClass, withModifier(PUBLIC), withPrefix("get"), withParametersCount(0))); rowCount = beans.size();// w w w.j a v a 2 s .c o m columnCount = getters.size(); columnClasses = new Class<?>[columnCount]; columnNames = new String[columnCount]; values = new Object[columnCount][]; for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) { Method method = Iterables.get(getters, columnIndex); columnClasses[columnIndex] = method.getReturnType(); columnNames[columnIndex] = method.getName().substring(3); Object[] columnValues = new Object[rowCount]; values[columnIndex] = columnValues; for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { try { columnValues[rowIndex] = method.invoke(beans.get(rowIndex)); } catch (IllegalAccessException e) { LOGGER.error(e.getMessage(), e); } catch (InvocationTargetException e) { LOGGER.error(e.getMessage(), e); } } } }
From source file:org.jclouds.gogrid.handlers.GoGridErrorHandler.java
@Override public void handleError(HttpCommand command, HttpResponse response) { try {/*from ww w . j a v a2 s. c om*/ // it is important to always read fully and close streams byte[] data = closeClientButKeepContentStream(response); String message = data != null ? new String(data) : null; Exception exception = message != null ? new HttpResponseException(command, response, message) : new HttpResponseException(command, response); Set<ErrorResponse> errors = parseErrorsFromContentOrNull(data); if (errors != null) exception = new GoGridResponseException(command, response, errors); switch (response.getStatusCode()) { case 400: if (Iterables.get(errors, 0).getMessage().indexOf("No object found") != -1) { exception = new ResourceNotFoundException(Iterables.get(errors, 0).getMessage(), exception); break; } break; case 403: exception = new AuthorizationException(exception.getMessage(), exception); break; } command.setException(exception); } finally { releasePayload(response); } }
From source file:org.jclouds.vcloud.compute.functions.HardwareForVAppTemplate.java
@Override public Hardware apply(VAppTemplate from) { checkNotNull(from, "VAppTemplate"); Envelope ovf = templateToEnvelope.apply(from); if (ovf.getVirtualSystem().getVirtualHardwareSections().size() > 1) { logger.warn("multiple hardware choices found. using first", ovf); }/*w w w . jav a2 s. co m*/ VirtualHardwareSection hardware = Iterables.get(ovf.getVirtualSystem().getVirtualHardwareSections(), 0); HardwareBuilder builder = rasdToHardwareBuilder.apply(hardware.getItems()); if (from.getVDC() != null) { builder.location(findLocationForResource.apply(from.getVDC())); } else { // otherwise, it could be in a public catalog, which is not assigned to a VDC } builder.ids(from.getHref().toASCIIString()).name(from.getName()) .supportsImage(ImagePredicates.idEquals(from.getHref().toASCIIString())); builder.hypervisor("VMware"); return builder.build(); }
From source file:org.jclouds.ibm.smartcloud.compute.suppliers.IBMSmartCloudImageSupplier.java
@Override public Set<? extends Image> get() { final Set<Image> images = Sets.newHashSet(); logger.debug(">> providing images"); for (org.jclouds.ibm.smartcloud.domain.Image image : sync.listImages()) { OperatingSystem.Builder osBuilder = OperatingSystem.builder(); Iterable<String> osVersion = Splitter.on('/').split(checkNotNull(image.getPlatform(), "platform")); osBuilder.version(Iterables.get(osVersion, 1)); osBuilder.name(image.getPlatform()); osBuilder.description(image.getPlatform()); if ("Red Hat Enterprise Linux".equals(Iterables.get(osVersion, 0))) osBuilder.family(OsFamily.RHEL); else if ("SUSE Linux Enterprise Server".equals(Iterables.get(osVersion, 0))) osBuilder.family(OsFamily.SUSE); else if ("Windows".equals(Iterables.get(osVersion, 0))) osBuilder.family(OsFamily.WINDOWS); else/*from w ww . j a va2s. co m*/ osBuilder.family(OsFamily.UNRECOGNIZED); osBuilder.arch(image.getArchitecture().toString()); osBuilder.is64Bit(image.getArchitecture() == Architecture.X86_64); // TODO manifest fails to parse due to encoding issues in the path // TODO get correct default credentials // http://www-180.ibm.com/cloud/enterprise/beta/ram/community/_rlvid.jsp.faces?_rap=pc_DiscussionForum.doDiscussionTopic&_rvip=/community/discussionForum.jsp&guid={DA689AEE-783C-6FE7-6F9F-DFEE9763F806}&v=1&submission=false&fid=1068&tid=1527 images.add(new ImageBuilder().ids(image.getId()).name(image.getName()) .location(locations.get().get(image.getLocation())).operatingSystem(osBuilder.build()) .description(image.getName()).version(image.getCreatedTime().getTime() + "") .defaultCredentials(new Credentials("idcuser", null)).build()); } logger.debug("<< images(%d)", images.size()); return images; }
From source file:org.jclouds.atmos.blobstore.functions.ObjectToBlobMetadata.java
public MutableBlobMetadata apply(AtmosObject from) { if (from == null) return null; MutableBlobMetadata to = new MutableBlobMetadataImpl(); to.setId(from.getSystemMetadata().getObjectID()); to.setLastModified(from.getSystemMetadata().getLastUserDataModification()); HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata()); to.setName(objectName.apply(from));//from ww w. ja v a2s .c o m to.setUri(from.getContentMetadata().getUri()); to.setContainer(Iterables.get(Splitter.on('/').split(from.getContentMetadata().getPath()), 0)); if (from.getAllHeaders().containsEntry("x-emc-groupacl", "other=READ")) to.setPublicUri(shareUrl.apply(from.getContentMetadata().getPath())); if (from.getSystemMetadata().getType() == FileType.DIRECTORY) { to.setType(StorageType.FOLDER); } else { to.setType(StorageType.BLOB); } Map<String, String> lowerKeyMetadata = Maps.newHashMap(); for (Entry<String, String> entry : from.getUserMetadata().getMetadata().entrySet()) { String key = entry.getKey().toLowerCase(); if (!systemMetadata.contains(key)) lowerKeyMetadata.put(key, entry.getValue()); } to.setUserMetadata(lowerKeyMetadata); return to; }
From source file:com.replaymod.replaystudio.pathing.change.AddKeyframe.java
@Override public void undo(Timeline timeline) { Preconditions.checkState(applied, "Not yet applied!"); Path path = timeline.getPaths().get(this.path); path.remove(Iterables.get(path.getKeyframes(), index), true); applied = false;// w ww. ja v a2 s . co m }
From source file:org.apache.whirr.service.jclouds.FirewallSettings.java
public static void authorizeIngress(ComputeServiceContext computeServiceContext, Set<Instance> instances, ClusterSpec clusterSpec, List<String> cidrs, int... ports) { if (computeServiceContext.getProviderSpecificContext().getApi() instanceof EC2Client) { // This code (or something like it) may be added to jclouds (see // http://code.google.com/p/jclouds/issues/detail?id=336). // Until then we need this temporary workaround. String region = AWSUtils.parseHandle(Iterables.get(instances, 0).getId())[0]; EC2Client ec2Client = EC2Client.class.cast(computeServiceContext.getProviderSpecificContext().getApi()); String groupName = "jclouds#" + clusterSpec.getClusterName() + "#" + region; for (String cidr : cidrs) { for (int port : ports) { try { ec2Client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(region, groupName, IpProtocol.TCP, port, port, cidr); } catch (IllegalStateException e) { LOG.warn(e.getMessage()); /* ignore, it means that this permission was already granted */ }//from ww w . j a v a 2s.c om } } } }
From source file:org.jclouds.vcloud.compute.util.VCloudComputeUtils.java
public static Set<String> getIpsFromVApp(VApp vApp) { // TODO make this work with composite vApps if (vApp.getChildren().size() == 0) return ImmutableSet.of(); Builder<String> ips = ImmutableSet.builder(); Vm vm = Iterables.get(vApp.getChildren(), 0); // TODO: figure out how to differentiate public from private ip addresses // assumption is that we'll do this from the network object, which may // have/*from www .j av a2 s .c o m*/ // enough data to tell whether or not it is a public network without // string // parsing. At worst, we could have properties set per cloud provider to // declare the networks which are public, then check against these in // networkconnection.getNetwork if (vm.getNetworkConnectionSection() != null) { for (NetworkConnection connection : vm.getNetworkConnectionSection().getConnections()) { if (connection.getIpAddress() != null) ips.add(connection.getIpAddress()); if (connection.getExternalIpAddress() != null) ips.add(connection.getExternalIpAddress()); } } else { for (ResourceAllocationSettingData net : filter(vm.getVirtualHardwareSection().getItems(), CIMPredicates.resourceTypeIn(ResourceType.ETHERNET_ADAPTER))) { if (net instanceof VCloudNetworkAdapter) { VCloudNetworkAdapter vNet = VCloudNetworkAdapter.class.cast(net); if (vNet.getIpAddress() != null) ips.add(vNet.getIpAddress()); } } } return ips.build(); }