protected Builder<Location> buildJustProviderOrVDCs() { Builder<Location> locations = ImmutableSet.builder(); Location provider = Iterables.getOnlyElement(super.get()); if (orgNameToResource.get().size() == 0) return locations.add(provider); else for (ReferenceType org : orgNameToResource.get().values()) { LocationBuilder builder = new LocationBuilder() .scope(LocationScope.REGION) .id(org.getHref().toASCIIString()) .description((org.getName())) .parent(provider); if (isoCodesById.containsKey(org.getHref().toASCIIString())) builder.iso3166Codes(isoCodesById.get(org.getHref().toASCIIString())); Location orgL = builder.build(); for (ReferenceType vdc : orgNameToVDCResource.get().get(org.getName()).getVDCs().values()) { builder = new LocationBuilder() .scope(LocationScope.ZONE) .id(vdc.getHref().toASCIIString()) .description((vdc.getName())) .parent(orgL); if (isoCodesById.containsKey(vdc.getHref().toASCIIString())) builder.iso3166Codes(isoCodesById.get(vdc.getHref().toASCIIString())); locations.add(builder.build()); } } return locations; }
@Override public Set<? extends Location> get() { Set<? extends Location> regionsOrJustProvider = regionToProviderOrJustProvider.get(); Set<String> zoneIds = zoneIdsSupplier.get(); if (zoneIds.size() == 0) return regionsOrJustProvider; Map<String, Location> zoneIdToParent = setParentOfZoneToRegionOrProvider(zoneIds, regionsOrJustProvider); Map<String, Supplier<Set<String>>> isoCodesById = isoCodesByIdSupplier.get(); Builder<Location> locations = ImmutableSet.builder(); if (!Iterables.all(regionsOrJustProvider, LocationPredicates.isProvider())) locations.addAll(regionsOrJustProvider); for (Map.Entry<String, Location> entry : zoneIdToParent.entrySet()) { String zoneId = entry.getKey(); Location parent = entry.getValue(); LocationBuilder builder = new LocationBuilder() .scope(LocationScope.ZONE) .id(zoneId) .description(zoneId) .parent(parent); if (isoCodesById.containsKey(zoneId)) builder.iso3166Codes(isoCodesById.get(zoneId).get()); // be cautious.. only inherit iso codes if the parent is a region // regions may be added dynamically, and we prefer to inherit an // empty set of codes from a region, then a provider, whose code // are likely hard-coded. else if (parent.getScope() == LocationScope.REGION) builder.iso3166Codes(parent.getIso3166Codes()); locations.add(builder.build()); } return locations.build(); }
@Override public Iterable<Hardware> listHardwareProfiles() { Builder<Hardware> hardware = ImmutableSet.builder(); for (double cpu : new double[] {1000, 5000, 10000, 20000}) for (int ram : new int[] {512, 1024, 4 * 1024, 16 * 1024, 32 * 1024}) { final float size = (float) cpu / 100; String id = String.format("cpu=%f,ram=%s,disk=%f", cpu, ram, size); hardware.add( new HardwareBuilder() .supportsImage( new Predicate<Image>() { @Override public boolean apply(Image input) { String toParse = input.getUserMetadata().get("size"); return (toParse != null && new Float(toParse) <= size); } @Override public String toString() { return "sizeLessThanOrEqual(" + size + ")"; } }) .ids(id) .ram(ram) .processors(ImmutableList.of(new Processor(1, cpu))) .hypervisor("kvm") .volumes(ImmutableList.<Volume>of(new VolumeImpl(size, true, true))) .build()); } return hardware.build(); }
@VisibleForTesting public Set<String> getSecurityGroupsForTagAndOptions( String region, @Nullable String group, TemplateOptions options) { Builder<String> groups = ImmutableSet.builder(); if (group != null) { String markerGroup = namingConvention.create().sharedNameForGroup(group); groups.add(markerGroup); RegionNameAndIngressRules regionNameAndIngressRulesForMarkerGroup; if (userSpecifiedTheirOwnGroups(options)) { regionNameAndIngressRulesForMarkerGroup = new RegionNameAndIngressRules(region, markerGroup, new int[] {}, false); groups.addAll(EC2TemplateOptions.class.cast(options).getGroups()); } else { regionNameAndIngressRulesForMarkerGroup = new RegionNameAndIngressRules(region, markerGroup, options.getInboundPorts(), true); } // this will create if not yet exists. securityGroupMap.getUnchecked(regionNameAndIngressRulesForMarkerGroup); } return groups.build(); }
public Set<String> apply(HttpResponse response) { checkNotNull(response, "response"); Set<EventType> toParse = parser.apply(response); checkNotNull(toParse, "parsed result from %s", response); Builder<String> builder = ImmutableSet.builder(); for (EventType entry : toParse) builder.add(entry.name); return builder.build(); }
public Set<ComplexEntityPart> getParts() { Builder<ComplexEntityPart> builder = ImmutableSet.builder(); for (EntityComplexPart part : getHandle().children) { builder.add((ComplexEntityPart) part.getBukkitEntity()); } return builder.build(); }
public AggregatedNetconfOperation( final Set<NetconfOperationServiceFactory> factories, final String netconfSessionIdForReporting) { final Builder<NetconfOperationService> b = ImmutableSet.builder(); for (final NetconfOperationServiceFactory factory : factories) { b.add(factory.createService(netconfSessionIdForReporting)); } this.services = b.build(); }
public Set<ComplexEntityPart> getParts() { Builder<ComplexEntityPart> builder = ImmutableSet.builder(); for (net.minecraft.entity.Entity p : getHandle().getParts()) { EntityDragonPart part = (EntityDragonPart) p; builder.add((ComplexEntityPart) CraftEnderDragon.getEntity(this.server, part)); } return builder.build(); }
private void addRecursiveParents( AccountGroup.UUID g, Builder<AccountGroup.UUID> builder, GroupIncludeCache groupIncludeCache) { for (AccountGroup.UUID p : groupIncludeCache.parentGroupsOf(g)) { if (builder.build().contains(p)) { continue; } builder.add(p); addRecursiveParents(p, builder, groupIncludeCache); } }
/** * Filters SchemaContext for yang modules * * @param delegate original SchemaContext * @param rootModules modules (yang schemas) to be available and all their dependencies (modules * importing rootModule and whole chain of their imports) * @param additionalModuleIds (additional) modules (yang schemas) to be available and whole chain * of their imports */ public FilteringSchemaContextProxy( final SchemaContext delegate, final Collection<ModuleId> rootModules, final Set<ModuleId> additionalModuleIds) { Preconditions.checkArgument(rootModules != null, "Base modules cannot be null."); Preconditions.checkArgument(additionalModuleIds != null, "Additional modules cannot be null."); final Builder<Module> filteredModulesBuilder = new Builder<>(); final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(new TreeMap<URI, Collection<Module>>(), MODULE_SET_SUPPLIER); final SetMultimap<String, Module> nameMap = Multimaps.newSetMultimap(new TreeMap<String, Collection<Module>>(), MODULE_SET_SUPPLIER); ImmutableMap.Builder<ModuleIdentifier, String> identifiersToSourcesBuilder = ImmutableMap.builder(); // preparing map to get all modules with one name but difference in revision final TreeMultimap<String, Module> nameToModulesAll = getStringModuleTreeMultimap(); nameToModulesAll.putAll(getStringModuleMap(delegate)); // in case there is a particular dependancy to view filteredModules/yang models // dependancy is checked for module name and imports processForRootModules(delegate, rootModules, filteredModulesBuilder); // adding additional modules processForAdditionalModules(delegate, additionalModuleIds, filteredModulesBuilder); filteredModulesBuilder.addAll( getImportedModules( Maps.uniqueIndex(delegate.getModules(), ModuleId.MODULE_TO_MODULE_ID), filteredModulesBuilder.build(), nameToModulesAll)); /** * Instead of doing this on each invocation of getModules(), pre-compute it once and keep it * around -- better than the set we got in. */ this.filteredModules = filteredModulesBuilder.build(); for (final Module module : filteredModules) { nameMap.put(module.getName(), module); nsMap.put(module.getNamespace(), module); identifiersToSourcesBuilder.put(module, module.getSource()); } namespaceToModules = ImmutableSetMultimap.copyOf(nsMap); nameToModules = ImmutableSetMultimap.copyOf(nameMap); identifiersToSources = identifiersToSourcesBuilder.build(); }
protected Set<DirectoryEntry> values() { Builder<DirectoryEntry> expected = ImmutableSet.<DirectoryEntry>builder(); expected.add( new DirectoryEntry( "4980cdb2a411106a04a4538c92a1b204ad92077de6e3", FileType.DIRECTORY, "adriancole-blobstore-2096685753")); expected.add( new DirectoryEntry( "4980cdb2a410105404980d99e53a0504ad93939e7dc3", FileType.DIRECTORY, "adriancole-blobstore247496608")); return expected.build(); }
/** * Returns a list of datastreams for the object * * @param pid persistent identifier of the digital object * @return the list of datastreams * @throws RepositoryException * @throws IOException * @throws TemplateException */ @GET @Path("/") @Produces({TEXT_XML, APPLICATION_JSON}) public ObjectDatastreams getDatastreams(@PathParam("pid") final String pid) throws RepositoryException, IOException { final ObjectDatastreams objectDatastreams = new ObjectDatastreams(); final Builder<DatastreamElement> datastreams = builder(); NodeIterator i = getObjectNode(pid).getNodes(); while (i.hasNext()) { final Node ds = i.nextNode(); datastreams.add(new DatastreamElement(ds.getName(), ds.getName(), getDSMimeType(ds))); } objectDatastreams.datastreams = datastreams.build(); return objectDatastreams; }
protected NodeMetadataBuilder buildInstance( final RunningInstance instance, NodeMetadataBuilder builder) { builder.providerId(instance.getId()); builder.id(instance.getRegion() + "/" + instance.getId()); String group = getGroupForInstance(instance); builder.group(group); // standard convention from aws-ec2, which might not be re-used outside. if (instance.getPrivateDnsName() != null) builder.hostname(instance.getPrivateDnsName().replaceAll("\\..*", "")); addCredentialsForInstance(builder, instance); builder.status(instanceToNodeStatus.get(instance.getInstanceState())); builder.backendStatus(instance.getRawState()); // collect all ip addresses into one bundle in case the api mistakenly put a private address // into the public address field Builder<String> addressesBuilder = ImmutableSet.builder(); if (Strings.emptyToNull(instance.getIpAddress()) != null) addressesBuilder.add(instance.getIpAddress()); // Add dnsName (if available) to addresses, when the IPAddress is null // happens on Eucalyptus sometimes. else if (Strings.emptyToNull(instance.getDnsName()) != null) addressesBuilder.add(instance.getDnsName()); if (Strings.emptyToNull(instance.getPrivateIpAddress()) != null) addressesBuilder.add(instance.getPrivateIpAddress()); Set<String> addresses = addressesBuilder.build(); builder.publicAddresses(filter(addresses, not(IsPrivateIPAddress.INSTANCE))); builder.privateAddresses(filter(addresses, IsPrivateIPAddress.INSTANCE)); builder.hardware(parseHardware(instance)); Location location = getLocationForAvailabilityZoneOrRegion(instance); builder.location(location); builder.imageId(instance.getRegion() + "/" + instance.getImageId()); // extract the operating system from the image RegionAndName regionAndName = new RegionAndName(instance.getRegion(), instance.getImageId()); try { Image image = imageMap.get().getUnchecked(regionAndName); if (image != null) builder.operatingSystem(image.getOperatingSystem()); } catch (CacheLoader.InvalidCacheLoadException e) { logger.debug("image not found for %s: %s", regionAndName, e); } catch (UncheckedExecutionException e) { logger.debug("error getting image for %s: %s", regionAndName, e); } return builder; }
private Cluster newCluster(int numberOfWorkers) { NodeMetadata node = mock(NodeMetadata.class); List<Processor> processors = ImmutableList.of(new Processor(4, 1.0)); Hardware hardware = new HardwareImpl( null, null, "id", null, null, ImmutableMap.<String, String>of(), ImmutableSet.<String>of(), processors, 1024, ImmutableList.<Volume>of(), null); when(node.getHardware()).thenReturn(hardware); Builder<Instance> instances = ImmutableSet.<Instance>builder(); Instance master = new Instance( new Credentials("", ""), ImmutableSet.of( HadoopNameNodeClusterActionHandler.ROLE, HadoopJobTrackerClusterActionHandler.ROLE), "10.0.0.1", "10.0.0.1", "1", node); instances.add(master); for (int i = 0; i < numberOfWorkers; i++) { int id = i + 2; instances.add( new Instance( new Credentials("", ""), ImmutableSet.of( HadoopDataNodeClusterActionHandler.ROLE, HadoopTaskTrackerClusterActionHandler.ROLE), "10.0.0." + id, "10.0.0." + id, id + "", node)); } return new Cluster(instances.build()); }
@Override public void buildTransitiveClosure(QueryExpression caller, Set<Target> targets, int maxDepth) throws QueryException { // Everything has already been loaded, so here we just check for errors so that we can // pre-emptively throw/report if needed. Iterable<SkyKey> transitiveTraversalKeys = makeTransitiveTraversalKeys(targets); ImmutableList.Builder<String> errorMessagesBuilder = ImmutableList.builder(); // First, look for errors in the successfully evaluated TransitiveTraversalValues. They may // have encountered errors that they were able to recover from. Set<Entry<SkyKey, SkyValue>> successfulEntries = graph.getSuccessfulValues(transitiveTraversalKeys).entrySet(); Builder<SkyKey> successfulKeysBuilder = ImmutableSet.builder(); for (Entry<SkyKey, SkyValue> successfulEntry : successfulEntries) { successfulKeysBuilder.add(successfulEntry.getKey()); TransitiveTraversalValue value = (TransitiveTraversalValue) successfulEntry.getValue(); String firstErrorMessage = value.getFirstErrorMessage(); if (firstErrorMessage != null) { errorMessagesBuilder.add(firstErrorMessage); } } ImmutableSet<SkyKey> successfulKeys = successfulKeysBuilder.build(); // Next, look for errors from the unsuccessfully evaluated TransitiveTraversal skyfunctions. Iterable<SkyKey> unsuccessfulKeys = Iterables.filter(transitiveTraversalKeys, Predicates.not(Predicates.in(successfulKeys))); Set<Entry<SkyKey, Exception>> errorEntries = graph.getMissingAndExceptions(unsuccessfulKeys).entrySet(); for (Map.Entry<SkyKey, Exception> entry : errorEntries) { if (entry.getValue() == null) { // Targets may be in the graph because they are not in the universe or depend on cycles. eventHandler.handle(Event.warn(entry.getKey().argument() + " does not exist in graph")); } else { errorMessagesBuilder.add(entry.getValue().getMessage()); } } // Lastly, report all found errors. ImmutableList<String> errorMessages = errorMessagesBuilder.build(); for (String errorMessage : errorMessages) { reportBuildFileError(caller, errorMessage); } }
private void processForRootModules( SchemaContext delegate, final Collection<ModuleId> rootModules, Builder<Module> filteredModulesBuilder) { filteredModulesBuilder.addAll( Collections2.filter( delegate.getModules(), new Predicate<Module>() { @Override public boolean apply(@Nullable Module module) { return checkModuleDependency(module, rootModules); } })); }
private void processForAdditionalModules( SchemaContext delegate, final Set<ModuleId> additionalModuleIds, Builder<Module> filteredModulesBuilder) { filteredModulesBuilder.addAll( Collections2.filter( delegate.getModules(), new Predicate<Module>() { @Override public boolean apply(@Nullable Module module) { return selectAdditionalModules(module, additionalModuleIds); } })); }
@Override public Set<E> read(JsonReader in) throws IOException { if (in.peek() == JsonToken.BEGIN_OBJECT) { Builder<E> builder = ImmutableSet.<E>builder(); boolean foundValues = false; in.beginObject(); while (in.hasNext()) { String name = in.nextName(); if (Objects.equal("values", name)) { foundValues = true; builder.addAll(delegate.read(in)); } else { in.skipValue(); } } checkState( foundValues, "Expected BEGIN_ARRAY or the object to contain an array called 'values'"); in.endObject(); return builder.build(); } else { return delegate.read(in); } }
@Override public Set<? extends Hardware> get() { Builder<Hardware> sizes = ImmutableSet.builder(); sizes.add(cc1_4xlarge().supportsImageIds(ccAmis).build()); sizes.add(cg1_4xlarge().supportsImageIds(ccAmis).build()); sizes.add(cc2_8xlarge().supportsImageIds(ccAmis).build()); sizes.add(hi1_4xlarge().supportsImageIds(ccAmis).build()); sizes.add(hs1_8xlarge().supportsImageIds(ccAmis).build()); sizes.addAll( ImmutableSet.<Hardware>of( t1_micro().build(), c1_medium().build(), c1_xlarge().build(), m1_large().build(), m1_small().build(), m1_medium().build(), m1_xlarge().build(), m2_xlarge().build(), m2_2xlarge().build(), m2_4xlarge().build(), m3_xlarge().build(), m3_2xlarge().build())); return sizes.build(); }
/** {@inheritDoc} */ @Override public Set<PolicyType> getResult() { return policyTypes.build(); }
protected void endMember(String uri, String name, String qName) throws SAXException { if (inPolicyTypeTypes) { if (memberDepth == 1) policyTypes.add(policyTypeHandler.getResult()); else policyTypeHandler.endElement(uri, name, qName); } }
@Test public void testListDatacentersContent() { Builder<Datacenter> builder = ImmutableSet.builder(); builder.add(Datacenter.builder().id(265592).name("ams01").longName("Amsterdam 1").build()); builder.add(Datacenter.builder().id(3).name("dal01").longName("Dallas").build()); builder.add(Datacenter.builder().id(18171).name("sea01").longName("Seattle").build()); builder.add(Datacenter.builder().id(168642).name("sjc01").longName("San Jose 1").build()); builder.add(Datacenter.builder().id(2).name("dal00").longName("Corporate HQ").build()); builder.add(Datacenter.builder().id(37473).name("wdc01").longName("Washington, DC").build()); builder.add(Datacenter.builder().id(154770).name("dal02").longName("Dallas 2").build()); builder.add(Datacenter.builder().id(138124).name("dal05").longName("Dallas 5").build()); builder.add(Datacenter.builder().id(167093).name("hou01").longName("Houston 1").build()); builder.add(Datacenter.builder().id(167094).name("lon01").longName("London 1").build()); builder.add(Datacenter.builder().id(167092).name("dal04").longName("Dallas 4").build()); builder.add(Datacenter.builder().id(224092).name("sng01").longName("Singapore 1").build()); builder.add(Datacenter.builder().id(142775).name("hou02").longName("Houston 2").build()); builder.add(Datacenter.builder().id(142776).name("dal07").longName("Dallas 7").build()); builder.add(Datacenter.builder().id(154820).name("dal06").longName("Dallas 6").build()); Set<Datacenter> response = client.listDatacenters(); Set<Datacenter> expected = builder.build(); assertEquals(response.size(), expected.size()); assertTrue(response.containsAll(expected)); for (Datacenter datacenter : response) { Address address = datacenter.getLocationAddress(); if (address != null) checkAddress(address); } }