List of usage examples for com.google.common.collect ImmutableMap keySet
public ImmutableSet<K> keySet()
From source file:org.glowroot.agent.weaving.AnalyzedWorld.java
static List<Advice> mergeInstrumentationAnnotations(List<Advice> advisors, byte[] classBytes, @Nullable ClassLoader loader, String className) { byte[] marker = "Lorg/glowroot/agent/api/Instrumentation$".getBytes(UTF_8); if (Bytes.indexOf(classBytes, marker) == -1) { return advisors; }//from w ww.ja v a 2s. c o m InstrumentationSeekerClassVisitor cv = new InstrumentationSeekerClassVisitor(); ClassReader cr = new ClassReader(classBytes); cr.accept(cv, ClassReader.SKIP_CODE); List<InstrumentationConfig> instrumentationConfigs = cv.getInstrumentationConfigs(); if (instrumentationConfigs.isEmpty()) { return advisors; } if (loader == null) { logger.warn("@Instrumentation annotations not currently supported in bootstrap class" + " loader: {}", className); return advisors; } for (InstrumentationConfig instrumentationConfig : instrumentationConfigs) { instrumentationConfig.logValidationErrorsIfAny(); } ImmutableMap<Advice, LazyDefinedClass> newAdvisors = AdviceGenerator.createAdvisors(instrumentationConfigs, null, false, false); try { ClassLoaders.defineClasses(newAdvisors.values(), loader); } catch (Exception e) { logger.error(e.getMessage(), e); } List<Advice> mergedAdvisors = Lists.newArrayList(advisors); mergedAdvisors.addAll(newAdvisors.keySet()); return mergedAdvisors; }
From source file:fr.xebia.cloud.amazon.aws.tools.AmazonAwsUtils.java
public static void deleteCnameIfExist(Iterable<String> cnames, HostedZone hostedZone, AmazonRoute53 route53) { // List all/*from w ww.j ava 2 s . c o m*/ ListResourceRecordSetsRequest listResourceRecordSetsRequest = new ListResourceRecordSetsRequest() // .withStartRecordType(RRType.CNAME) .withHostedZoneId(hostedZone.getId()); ListResourceRecordSetsResult listResourceRecordSetsResult = route53 .listResourceRecordSets(listResourceRecordSetsRequest); if (listResourceRecordSetsResult.isTruncated()) { logger.warn("truncated result"); } Function<ResourceRecordSet, String> cnameExtractor = new Function<ResourceRecordSet, String>() { @Override public String apply(@Nullable ResourceRecordSet resourceRecordSet) { if (resourceRecordSet == null) { return null; } if (!RRType.CNAME.equals(RRType.fromValue(resourceRecordSet.getType()))) { return null; } return resourceRecordSet.getName(); } }; Iterable<ResourceRecordSet> existingCnamesAsResourceRecordSet = Iterables .filter(listResourceRecordSetsResult.getResourceRecordSets(), new Predicate<ResourceRecordSet>() { @Override public boolean apply(@Nullable ResourceRecordSet resourceRecordSet) { return RRType.CNAME.equals(RRType.fromValue(resourceRecordSet.getType())); } }); final ImmutableMap<String, ResourceRecordSet> existingCnames = Maps .uniqueIndex(existingCnamesAsResourceRecordSet, cnameExtractor); Sets.SetView<String> cnamesToDelete = Sets.intersection(Sets.newHashSet(cnames), existingCnames.keySet()); Function<String, Change> cnameToDeleteCnameChange = new Function<String, Change>() { @Override public Change apply(@Nullable String cname) { ResourceRecordSet existingResourceRecordSet = existingCnames.get(cname); return new Change().withAction(ChangeAction.DELETE) .withResourceRecordSet(new ResourceRecordSet().withType(RRType.CNAME).withName(cname) .withTTL(existingResourceRecordSet.getTTL()) .withResourceRecords(existingResourceRecordSet.getResourceRecords())); } }; List<Change> changes = Lists.newArrayList(Iterables.transform(cnamesToDelete, cnameToDeleteCnameChange)); if (changes.isEmpty()) { logger.debug("No CNAME to delete"); return; } logger.info("Delete CNAME changes {}", changes); ChangeResourceRecordSetsRequest changeResourceRecordSetsRequest = new ChangeResourceRecordSetsRequest() .withHostedZoneId(hostedZone.getId()).withChangeBatch(new ChangeBatch().withChanges(changes)); route53.changeResourceRecordSets(changeResourceRecordSetsRequest); }
From source file:com.facebook.buck.cxx.Omnibus.java
protected static OmnibusSpec buildSpec(final CxxPlatform cxxPlatform, final Iterable<? extends NativeLinkTarget> includedRoots, final Iterable<? extends NativeLinkable> excludedRoots) { // A map of targets to native linkable objects. We maintain this, so that we index our // bookkeeping around `BuildTarget` and avoid having to guarantee that all other types are // hashable.// ww w . j ava 2 s . c om final Map<BuildTarget, NativeLinkable> nativeLinkables = new LinkedHashMap<>(); // The nodes which should *not* be included in the omnibus link. final Set<BuildTarget> excluded = new LinkedHashSet<>(); // Process all the roots included in the omnibus link. final Map<BuildTarget, NativeLinkTarget> roots = new LinkedHashMap<>(); Map<BuildTarget, NativeLinkable> rootDeps = new LinkedHashMap<>(); for (NativeLinkTarget root : includedRoots) { roots.put(root.getBuildTarget(), root); for (NativeLinkable dep : NativeLinkables.getNativeLinkables(cxxPlatform, root.getNativeLinkTargetDeps(cxxPlatform), Linker.LinkableDepType.SHARED).values()) { Linker.LinkableDepType linkStyle = NativeLinkables .getLinkStyle(dep.getPreferredLinkage(cxxPlatform), Linker.LinkableDepType.SHARED); Preconditions.checkState(linkStyle != Linker.LinkableDepType.STATIC); // We only consider deps which aren't *only* statically linked. if (linkStyle == Linker.LinkableDepType.SHARED) { rootDeps.put(dep.getBuildTarget(), dep); nativeLinkables.put(dep.getBuildTarget(), dep); } } } // Process all roots excluded from the omnibus link, and add them to our running list of // excluded nodes. for (NativeLinkable root : excludedRoots) { nativeLinkables.put(root.getBuildTarget(), root); excluded.add(root.getBuildTarget()); } // Perform the first walk starting from the native linkable nodes immediately reachable via the // included roots. We'll accomplish two things here: // 1. Build up the map of node names to their native linkable objects. // 2. Perform an initial discovery of dependency nodes to exclude from the omnibus link. new AbstractBreadthFirstTraversal<BuildTarget>(rootDeps.keySet()) { @Override public ImmutableSet<BuildTarget> visit(BuildTarget target) { NativeLinkable nativeLinkable = Preconditions.checkNotNull(nativeLinkables.get(target)); ImmutableMap<BuildTarget, NativeLinkable> deps = Maps .uniqueIndex(getDeps(nativeLinkable, cxxPlatform), HasBuildTarget::getBuildTarget); nativeLinkables.putAll(deps); if (nativeLinkable.getPreferredLinkage(cxxPlatform) == NativeLinkable.Linkage.SHARED) { excluded.add(target); } return deps.keySet(); } }.start(); // Do another walk to flesh out the transitively excluded nodes. new AbstractBreadthFirstTraversal<BuildTarget>(excluded) { @Override public Iterable<BuildTarget> visit(BuildTarget target) { NativeLinkable nativeLinkable = Preconditions.checkNotNull(nativeLinkables.get(target)); ImmutableMap<BuildTarget, NativeLinkable> deps = Maps .uniqueIndex(getDeps(nativeLinkable, cxxPlatform), HasBuildTarget::getBuildTarget); nativeLinkables.putAll(deps); excluded.add(target); return deps.keySet(); } }.start(); // And then we can do one last walk to create the actual graph which contain only root and body // nodes to include in the omnibus link. final MutableDirectedGraph<BuildTarget> graphBuilder = new MutableDirectedGraph<>(); final Set<BuildTarget> deps = new LinkedHashSet<>(); new AbstractBreadthFirstTraversal<BuildTarget>(Sets.difference(rootDeps.keySet(), excluded)) { @Override public Iterable<BuildTarget> visit(BuildTarget target) { graphBuilder.addNode(target); Set<BuildTarget> keep = new LinkedHashSet<>(); for (BuildTarget dep : Iterables.transform(getDeps(target, roots, nativeLinkables, cxxPlatform), HasBuildTarget::getBuildTarget)) { if (excluded.contains(dep)) { deps.add(dep); } else { keep.add(dep); graphBuilder.addEdge(target, dep); } } return keep; } }.start(); DirectedAcyclicGraph<BuildTarget> graph = new DirectedAcyclicGraph<>(graphBuilder); // Since we add all undefined root symbols into the omnibus library, we also need to include // any excluded root deps as deps of omnibus, as they may fulfill these undefined symbols. // Also add any excluded nodes that are also root dependencies. deps.addAll(Sets.intersection(rootDeps.keySet(), excluded)); return ImmutableOmnibusSpec.builder().graph(graph).roots(roots) .body(FluentIterable.from(graph.getNodes()).filter(Predicates.not(roots.keySet()::contains)) .toMap(Functions.forMap(nativeLinkables))) .deps(Maps.asMap(deps, Functions.forMap(nativeLinkables))) .excluded(Maps.asMap(excluded, Functions.forMap(nativeLinkables))).build(); }
From source file:com.google.api.codegen.config.DiscoGapicInterfaceConfig.java
static DiscoGapicInterfaceConfig createInterfaceConfig(DiscoApiModel model, TargetLanguage language, InterfaceConfigProto interfaceConfigProto, String interfaceNameOverride, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs) { ImmutableMap<String, ImmutableSet<String>> retryCodesDefinition = RetryDefinitionsTransformer .createRetryCodesDefinition(model.getDiagCollector(), interfaceConfigProto); ImmutableMap<String, RetryParamsDefinitionProto> retrySettingsDefinition = RetryDefinitionsTransformer .createRetrySettingsDefinition(interfaceConfigProto); List<DiscoGapicMethodConfig> methodConfigs = null; ImmutableMap<String, DiscoGapicMethodConfig> methodConfigMap = null; if (retryCodesDefinition != null && retrySettingsDefinition != null) { methodConfigMap = createMethodConfigMap(model, language, interfaceConfigProto, messageConfigs, resourceNameConfigs, retryCodesDefinition.keySet(), retrySettingsDefinition.keySet()); methodConfigs = GapicInterfaceConfig.createMethodConfigs(methodConfigMap, interfaceConfigProto); }/*from w w w.ja v a2 s . co m*/ // TODO(andrealin) Make non-null smokeTestConfig. SmokeTestConfig smokeTestConfig = null; // TODO(andrealin) IAM permissions configs. ImmutableList<String> requiredConstructorParams = ImmutableList .copyOf(interfaceConfigProto.getRequiredConstructorParamsList()); for (String param : interfaceConfigProto.getRequiredConstructorParamsList()) { if (!CONSTRUCTOR_PARAMS.contains(param)) { model.getDiagCollector() .addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Unsupported constructor param: %s", param)); } } ImmutableList.Builder<SingleResourceNameConfig> resourcesBuilder = ImmutableList.builder(); for (CollectionConfigProto collectionConfigProto : interfaceConfigProto.getCollectionsList()) { String entityName = collectionConfigProto.getEntityName(); ResourceNameConfig resourceName = resourceNameConfigs.get(entityName); if (resourceName == null || !(resourceName instanceof SingleResourceNameConfig)) { model.getDiagCollector() .addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Inconsistent configuration - single resource name %s specified for interface, " + " but was not found in GapicProductConfig configuration.", entityName)); return null; } resourcesBuilder.add((SingleResourceNameConfig) resourceName); } ImmutableList<SingleResourceNameConfig> singleResourceNames = resourcesBuilder.build(); ImmutableMap.Builder<MethodConfig, SingleResourceNameConfig> methodToSingleResourceNameMap = ImmutableMap .builder(); if (methodConfigs != null) { for (MethodConfig methodConfig : methodConfigs) { Method method = ((DiscoveryMethodModel) methodConfig.getMethodModel()).getDiscoMethod(); String canonicalMethodPath = DiscoGapicParser.getCanonicalPath(method.flatPath()); for (SingleResourceNameConfig nameConfig : singleResourceNames) { if (nameConfig.getNamePattern().equals(canonicalMethodPath)) { methodToSingleResourceNameMap.put(methodConfig, nameConfig); } } } } String manualDoc = Strings .nullToEmpty(interfaceConfigProto.getLangDoc().get(language.toString().toLowerCase())).trim(); String interfaceName = interfaceNameOverride != null ? interfaceNameOverride : DiscoGapicParser.getInterfaceName(interfaceConfigProto.getName()).toUpperCamel(); if (model.getDiagCollector().hasErrors()) { return null; } else { return new AutoValue_DiscoGapicInterfaceConfig(methodConfigs, retryCodesDefinition, retrySettingsDefinition, requiredConstructorParams, manualDoc, interfaceNameOverride, new DiscoInterfaceModel(interfaceName, model), smokeTestConfig, methodToSingleResourceNameMap.build(), methodConfigMap, singleResourceNames); } }
From source file:com.facebook.buck.cxx.toolchain.CxxBuckConfig.java
/** * If the config specifies a value for "toolchain_target", returns a {@link UnresolvedCxxPlatform} * backed by the specified target./*from w w w . j av a 2 s . c om*/ */ public static Optional<UnresolvedCxxPlatform> getProviderBasedPlatform(BuckConfig config, Flavor flavor) { String cxxSection = new CxxBuckConfig(config, flavor).cxxSection; Optional<BuildTarget> toolchainTarget = config.getBuildTarget(cxxSection, TOOLCHAIN_TARGET, EmptyTargetConfiguration.INSTANCE); if (!toolchainTarget.isPresent()) { return Optional.empty(); } if (!cxxSection.equals(UNFLAVORED_CXX_SECTION)) { // In a flavored cxx section, we don't allow any configuration except for configuration of the // platform. ImmutableMap<String, String> allEntries = config.getEntriesForSection(cxxSection); if (allEntries.size() != 1) { throw new HumanReadableException( "When configuring a cxx %s, no other configuration is allowed in that section. Got unexpected keys [%s]", TOOLCHAIN_TARGET, Joiner.on(", ") .join(Sets.difference(allEntries.keySet(), ImmutableSet.of(TOOLCHAIN_TARGET)))); } } return Optional.of(new ProviderBasedUnresolvedCxxPlatform(toolchainTarget.get(), flavor)); }
From source file:net.lldp.checksims.ChecksimsCommandLine.java
/** * Parse CLI arguments and run Checksims from them. * * TODO add unit tests/* ww w . j a v a2 s. c om*/ * * @param args CLI arguments to parse * @throws ParseException Thrown on error parsing CLI arguments * @throws ChecksimsException Thrown on invalid CLI arguments or error running Checksims * @throws IOException Thrown on error building a submission from files or writing output to file */ public static void runCLI(String[] args) throws ParseException, ChecksimsException, IOException { checkNotNull(args); // Parse options, first round: nothing required, so we can check for --help and --version CommandLine cli = parseOpts(args, false); // Print CLI Help if (cli.hasOption("h")) { printHelp(); } // Print version if (cli.hasOption("version")) { System.err.println("Checksims version " + ChecksimsRunner.getChecksimsVersion()); System.exit(0); } // Parse options, second round: required arguments are required cli = parseOpts(args, true); // Parse verbose setting if (cli.hasOption("vv")) { logs = startLogger(2); } else if (cli.hasOption("v")) { logs = startLogger(1); } else { logs = startLogger(0); } // First, parse basic flags ChecksimsConfig config = parseBaseFlags(cli); // Parse file flags ChecksimsConfig finalConfig = parseFileFlags(cli, config); // Run Checksims with this config ImmutableMap<String, String> output = ChecksimsRunner.runChecksims(finalConfig); // Check if file output specified if (cli.hasOption("f")) { // Writing to a file // Get the filename String outfileBaseName = cli.getOptionValue("f"); // Output for all specified strategies for (String strategy : output.keySet()) { // Final filename is the basename specified through CLI, with the strategy name as its extension. File outfile = new File(outfileBaseName + "." + strategy); logs.info("Writing " + strategy + " output to " + outfile.getName()); FileUtils.writeStringToFile(outfile, output.get(strategy), StandardCharsets.UTF_8); } } else { // Just outputting to STDOUT for (String strategy : output.keySet()) { System.out.println("\n\n"); System.out.println("Output from " + strategy + "\n"); System.out.println(output.get(strategy)); } } logs.trace("CLI parsing complete!"); }
From source file:com.google.api.codegen.config.GapicInterfaceConfig.java
/** * Creates an instance of GapicInterfaceConfig based on ConfigProto, linking up method * configurations with specified methods in methodConfigMap. On errors, null will be returned, and * diagnostics are reported to the model. *//*from w w w . java 2s . c om*/ @Nullable static GapicInterfaceConfig createInterfaceConfig(DiagCollector diagCollector, TargetLanguage language, InterfaceConfigProto interfaceConfigProto, Interface apiInterface, String interfaceNameOverride, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs) { ImmutableMap<String, ImmutableSet<String>> retryCodesDefinition = RetryDefinitionsTransformer .createRetryCodesDefinition(diagCollector, interfaceConfigProto); ImmutableMap<String, RetryParamsDefinitionProto> retrySettingsDefinition = RetryDefinitionsTransformer .createRetrySettingsDefinition(interfaceConfigProto); List<GapicMethodConfig> methodConfigs = null; ImmutableMap<String, GapicMethodConfig> methodConfigMap = null; if (retryCodesDefinition != null && retrySettingsDefinition != null) { methodConfigMap = createMethodConfigMap(diagCollector, language, interfaceConfigProto, apiInterface, messageConfigs, resourceNameConfigs, retryCodesDefinition.keySet(), retrySettingsDefinition.keySet()); methodConfigs = createMethodConfigs(methodConfigMap, interfaceConfigProto); } SmokeTestConfig smokeTestConfig = createSmokeTestConfig(diagCollector, apiInterface, interfaceConfigProto); ImmutableList<FieldModel> iamResources = createIamResources(apiInterface.getModel(), interfaceConfigProto.getExperimentalFeatures().getIamResourcesList()); ImmutableList<String> requiredConstructorParams = ImmutableList .<String>copyOf(interfaceConfigProto.getRequiredConstructorParamsList()); for (String param : interfaceConfigProto.getRequiredConstructorParamsList()) { if (!CONSTRUCTOR_PARAMS.contains(param)) { diagCollector .addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Unsupported constructor param: %s", param)); } } ImmutableList.Builder<SingleResourceNameConfig> resourcesBuilder = ImmutableList.builder(); for (CollectionConfigProto collectionConfigProto : interfaceConfigProto.getCollectionsList()) { String entityName = collectionConfigProto.getEntityName(); ResourceNameConfig resourceName = resourceNameConfigs.get(entityName); if (resourceName == null || !(resourceName instanceof SingleResourceNameConfig)) { diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Inconsistent configuration - single resource name %s specified for interface, " + " but was not found in GapicProductConfig configuration.", entityName)); return null; } resourcesBuilder.add((SingleResourceNameConfig) resourceName); } ImmutableList<SingleResourceNameConfig> singleResourceNames = resourcesBuilder.build(); String manualDoc = Strings .nullToEmpty(interfaceConfigProto.getLangDoc().get(language.toString().toLowerCase())).trim(); if (diagCollector.hasErrors()) { return null; } else { return new AutoValue_GapicInterfaceConfig(interfaceNameOverride, new ProtoInterfaceModel(apiInterface), methodConfigs, smokeTestConfig, methodConfigMap, retryCodesDefinition, retrySettingsDefinition, iamResources, requiredConstructorParams, singleResourceNames, manualDoc); } }
From source file:com.intel.hibench.stormbench.trident.functions.Parser.java
@Override public void execute(TridentTuple tuple, TridentCollector collector) { ImmutableMap<String, String> kv = (ImmutableMap<String, String>) tuple.getValue(0); String key = kv.keySet().iterator().next(); Long startTime = Long.parseLong(key); UserVisit uv = UserVisitParser.parse(kv.get(key)); collector.emit(new Values(uv.getIp(), startTime)); }
From source file:google.registry.tools.params.TransitionListParameter.java
@Override protected final ImmutableSortedMap<DateTime, V> processMap(ImmutableMap<DateTime, V> map) { checkArgument(Ordering.natural().isOrdered(map.keySet()), "Transition times out of order."); return ImmutableSortedMap.copyOf(map); }
From source file:com.facebook.buck.features.project.intellij.IjModuleGraph.java
public ImmutableMap<IjModule, DependencyType> getDependentModulesFor(IjModule source) { ImmutableMap<IjProjectElement, DependencyType> deps = getDepsFor(source); return deps.keySet().stream().filter(dep -> dep instanceof IjModule).map(module -> (IjModule) module) .collect(ImmutableMap.toImmutableMap(k -> k, input -> Objects.requireNonNull(deps.get(input)))); }