Example #1
0
    public SoySauceImpl create(
        CompiledTemplates templates,
        ImmutableMap<String, ? extends SoyFunction> soyFunctionMap,
        ImmutableMap<String, ? extends SoyPrintDirective> printDirectives) {
      // SoySauce has no need for SoyFunctions that are not SoyJavaFunctions
      // (it generates Java source code implementing BuiltinFunctions).
      // Filter them out.
      ImmutableMap.Builder<String, SoyJavaFunction> soyJavaFunctions = ImmutableMap.builder();
      for (Map.Entry<String, ? extends SoyFunction> entry : soyFunctionMap.entrySet()) {
        SoyFunction function = entry.getValue();
        if (function instanceof SoyJavaFunction) {
          soyJavaFunctions.put(entry.getKey(), (SoyJavaFunction) function);
        }
      }

      // SoySauce has no need for SoyPrintDirectives that are not SoyJavaPrintDirectives.
      // Filter them out.
      ImmutableMap.Builder<String, SoyJavaPrintDirective> soyJavaPrintDirectives =
          ImmutableMap.builder();
      for (Map.Entry<String, ? extends SoyPrintDirective> entry : printDirectives.entrySet()) {
        SoyPrintDirective printDirective = entry.getValue();
        if (printDirective instanceof SoyJavaPrintDirective) {
          soyJavaPrintDirectives.put(entry.getKey(), (SoyJavaPrintDirective) printDirective);
        }
      }
      return new SoySauceImpl(
          templates,
          apiCallScopeProvider,
          converterProvider.get(),
          soyJavaFunctions.build(),
          soyJavaPrintDirectives.build());
    }
Example #2
0
  /**
   * In a {@link BuckConfig}, an alias can either refer to a fully-qualified build target, or an
   * alias defined earlier in the {@code alias} section. The mapping produced by this method
   * reflects the result of resolving all aliases as values in the {@code alias} section.
   */
  private static ImmutableMap<String, BuildTarget> createAliasToBuildTargetMap(
      ImmutableMap<String, String> rawAliasMap) {
    // We use a LinkedHashMap rather than an ImmutableMap.Builder because we want both (1) order to
    // be preserved, and (2) the ability to inspect the Map while building it up.
    LinkedHashMap<String, BuildTarget> aliasToBuildTarget = Maps.newLinkedHashMap();
    for (Map.Entry<String, String> aliasEntry : rawAliasMap.entrySet()) {
      String alias = aliasEntry.getKey();
      validateAliasName(alias);

      // Determine whether the mapping is to a build target or to an alias.
      String value = aliasEntry.getValue();
      BuildTarget buildTarget;
      if (isValidAliasName(value)) {
        buildTarget = aliasToBuildTarget.get(value);
        if (buildTarget == null) {
          throw new HumanReadableException("No alias for: %s.", value);
        }
      } else {
        // Here we parse the alias values with a BuildTargetParser to be strict. We could be looser
        // and just grab everything between "//" and ":" and assume it's a valid base path.
        buildTarget =
            BuildTargetParser.INSTANCE.parse(value, BuildTargetPatternParser.fullyQualified());
      }
      aliasToBuildTarget.put(alias, buildTarget);
    }
    return ImmutableMap.copyOf(aliasToBuildTarget);
  }
  public ImmutableSet<CxxInferCapture> createInferCaptureBuildRules(
      ImmutableMap<String, CxxSource> sources,
      CxxInferTools inferTools,
      CxxInferSourceFilter sourceFilter) {

    ImmutableSet.Builder<CxxInferCapture> objects = ImmutableSet.builder();

    for (Map.Entry<String, CxxSource> entry : sources.entrySet()) {
      String name = entry.getKey();
      CxxSource source = entry.getValue();

      Preconditions.checkState(
          CxxSourceTypes.isPreprocessableType(source.getType()),
          "Only preprocessable source types are currently supported");

      if (sourceFilter.isBlacklisted(source)) {
        continue;
      }

      CxxInferCapture rule = requireInferCaptureBuildRule(name, source, inferTools);
      objects.add(rule);
    }

    return objects.build();
  }
  Iterable<WhenHttpRequest> findWhensMatchingRequest(
      ImmutableMap<String, RestxSpec> allSpecs, RestxRequest restxRequest) {
    Collection<WhenHttpRequest> matchingRequestsSpecs = Lists.newArrayList();
    for (Map.Entry<String, RestxSpec> spec : allSpecs.entrySet()) {
      for (When when : spec.getValue().getWhens()) {
        if (when instanceof WhenHttpRequest) {
          WhenHttpRequest request = (WhenHttpRequest) when;
          String requestPath = request.getPath();
          if (!requestPath.startsWith("/")) {
            requestPath = "/" + requestPath;
          }
          StdRequest stdRequest =
              StdRequest.builder()
                  .setBaseUri("http://restx.io") // baseUri is required but we won't use it
                  .setHttpMethod(request.getMethod())
                  .setFullPath(requestPath)
                  .build();

          if (restxRequest.getHttpMethod().equals(stdRequest.getHttpMethod())
              && restxRequest.getRestxPath().equals(stdRequest.getRestxPath())) {
            MapDifference<String, ImmutableList<String>> difference =
                Maps.difference(restxRequest.getQueryParams(), stdRequest.getQueryParams());
            if (difference.entriesOnlyOnRight().isEmpty()
                && difference.entriesDiffering().isEmpty()) {
              matchingRequestsSpecs.add(request);
              break;
            }
          }
        }
      }
    }
    return matchingRequestsSpecs;
  }
Example #5
0
  public void updateSettings(Settings settings) {
    Map<String, Settings> groupSettings = settings.getGroups("threadpool");
    if (groupSettings.isEmpty()) {
      return;
    }

    for (Map.Entry<String, Settings> executor : defaultExecutorTypeSettings.entrySet()) {
      Settings updatedSettings = groupSettings.get(executor.getKey());
      if (updatedSettings == null) {
        continue;
      }

      ExecutorHolder oldExecutorHolder = executors.get(executor.getKey());
      ExecutorHolder newExecutorHolder =
          rebuild(executor.getKey(), oldExecutorHolder, updatedSettings, executor.getValue());
      if (!oldExecutorHolder.equals(newExecutorHolder)) {
        executors =
            newMapBuilder(executors).put(executor.getKey(), newExecutorHolder).immutableMap();
        if (!oldExecutorHolder.executor.equals(newExecutorHolder.executor)
            && oldExecutorHolder.executor instanceof EsThreadPoolExecutor) {
          retiredExecutors.add(oldExecutorHolder);
          ((EsThreadPoolExecutor) oldExecutorHolder.executor)
              .shutdown(new ExecutorShutdownListener(oldExecutorHolder));
        }
      }
    }
  }
  @Override
  public int execute(ExecutionContext context) {
    File inputDirectory = inputDirectoryPath.toFile();
    Preconditions.checkState(
        inputDirectory.exists() && inputDirectory.isDirectory(),
        "%s must be a directory.",
        inputDirectoryPath);

    try {
      ImmutableMap.Builder<File, ZipEntry> zipEntriesBuilder = ImmutableMap.builder();
      addDirectoryToZipEntryList(inputDirectory, "", zipEntriesBuilder);
      ImmutableMap<File, ZipEntry> zipEntries = zipEntriesBuilder.build();

      if (!zipEntries.isEmpty()) {
        try (CustomZipOutputStream outputStream =
            ZipOutputStreams.newOutputStream(outputZipPath.toFile())) {
          for (Map.Entry<File, ZipEntry> zipEntry : zipEntries.entrySet()) {
            outputStream.putNextEntry(zipEntry.getValue());
            ByteStreams.copy(Files.newInputStreamSupplier(zipEntry.getKey()), outputStream);
            outputStream.closeEntry();
          }
        }
      }
    } catch (IOException e) {
      e.printStackTrace(context.getStdErr());
      return 1;
    }
    return 0;
  }
Example #7
0
  private ImmutableMap<Path, Path> getExpandedSourcePaths(
      ExecutionContext context, ImmutableMap<Path, Path> paths) throws IOException {
    ProjectFilesystem projectFilesystem = context.getProjectFilesystem();
    ImmutableMap.Builder<Path, Path> sources = ImmutableMap.builder();

    for (ImmutableMap.Entry<Path, Path> ent : paths.entrySet()) {
      if (ent.getValue().toString().endsWith(SRC_ZIP)) {
        Path destinationDirectory = projectFilesystem.resolve(tempDir.resolve(ent.getKey()));
        Files.createDirectories(destinationDirectory);

        ImmutableList<Path> zipPaths =
            Unzip.extractZipFile(
                projectFilesystem.resolve(ent.getValue()),
                destinationDirectory,
                Unzip.ExistingFileMode.OVERWRITE);
        for (Path path : zipPaths) {
          Path modulePath = destinationDirectory.relativize(path);
          sources.put(modulePath, path);
        }
      } else {
        sources.put(ent.getKey(), ent.getValue());
      }
    }

    return sources.build();
  }
 Iterable<String> filterSpecsByOperation(
     ImmutableMap<String, RestxSpec> allSpecs, String httpMethod, String path) {
   StdRestxRequestMatcher matcher = new StdRestxRequestMatcher(httpMethod, path);
   Collection<String> specs = Lists.newArrayList();
   for (Map.Entry<String, RestxSpec> spec : allSpecs.entrySet()) {
     for (When when : spec.getValue().getWhens()) {
       if (when instanceof WhenHttpRequest) {
         WhenHttpRequest request = (WhenHttpRequest) when;
         String requestPath = request.getPath();
         if (!requestPath.startsWith("/")) {
           requestPath = "/" + requestPath;
         }
         if (requestPath.indexOf("?") != -1) {
           requestPath = requestPath.substring(0, requestPath.indexOf("?"));
         }
         Optional<? extends RestxRequestMatch> match =
             matcher.match(request.getMethod(), requestPath);
         if (match.isPresent()) {
           specs.add(spec.getKey());
           break;
         }
       }
     }
   }
   return specs;
 }
 protected void onConfigurationChanged() {
   ProcessManager manager = getProcessManager();
   FabricService fabric = getFabricService();
   if (manager != null && fabric != null) {
     ImmutableMap<String, Installation> map = manager.listInstallationMap();
     ImmutableSet<Map.Entry<String, Installation>> entries = map.entrySet();
     for (Map.Entry<String, Installation> entry : entries) {
       String id = entry.getKey();
       Installation installation = entry.getValue();
       try {
         Container container = null;
         try {
           container = fabric.getContainer(id);
         } catch (Exception e) {
           LOG.debug("No container for id: " + id + ". " + e, e);
         }
         if (container != null && installation != null) {
           ChildContainerController controllerForContainer = getControllerForContainer(container);
           if (controllerForContainer instanceof ProcessManagerController) {
             ProcessManagerController processManagerController =
                 (ProcessManagerController) controllerForContainer;
             processManagerController.updateInstallation(container, installation);
           }
         }
       } catch (Exception e) {
         LOG.warn("Failed to get PID for process " + id + ". " + e, e);
       }
     }
   }
 }
 /**
  * Produces a factory that allows the union of the grants, and intersects policies where they
  * overlap on a particular granted attribute or element name.
  */
 public PolicyFactory and(PolicyFactory f) {
   ImmutableMap.Builder<String, ElementAndAttributePolicies> b = ImmutableMap.builder();
   // Merge this and f into a map of element names to attribute policies.
   for (Map.Entry<String, ElementAndAttributePolicies> e : policies.entrySet()) {
     String elName = e.getKey();
     ElementAndAttributePolicies p = e.getValue();
     ElementAndAttributePolicies q = f.policies.get(elName);
     if (q != null) {
       p = p.and(q);
     } else {
       // Mix in any globals that are not already taken into account in this.
       p = p.andGlobals(f.globalAttrPolicies);
     }
     b.put(elName, p);
   }
   // Handle keys that are in f but not in this.
   for (Map.Entry<String, ElementAndAttributePolicies> e : f.policies.entrySet()) {
     String elName = e.getKey();
     if (!policies.containsKey(elName)) {
       ElementAndAttributePolicies p = e.getValue();
       // Mix in any globals that are not already taken into account in this.
       p = p.andGlobals(f.globalAttrPolicies);
       b.put(elName, p);
     }
   }
   ImmutableSet<String> textContainers;
   if (this.textContainers.containsAll(f.textContainers)) {
     textContainers = this.textContainers;
   } else if (f.textContainers.containsAll(this.textContainers)) {
     textContainers = f.textContainers;
   } else {
     textContainers =
         ImmutableSet.<String>builder()
             .addAll(this.textContainers)
             .addAll(f.textContainers)
             .build();
   }
   ImmutableMap<String, AttributePolicy> allGlobalAttrPolicies;
   if (f.globalAttrPolicies.isEmpty()) {
     allGlobalAttrPolicies = this.globalAttrPolicies;
   } else if (this.globalAttrPolicies.isEmpty()) {
     allGlobalAttrPolicies = f.globalAttrPolicies;
   } else {
     ImmutableMap.Builder<String, AttributePolicy> ab = ImmutableMap.builder();
     for (Map.Entry<String, AttributePolicy> e : this.globalAttrPolicies.entrySet()) {
       String attrName = e.getKey();
       ab.put(
           attrName, AttributePolicy.Util.join(e.getValue(), f.globalAttrPolicies.get(attrName)));
     }
     for (Map.Entry<String, AttributePolicy> e : f.globalAttrPolicies.entrySet()) {
       String attrName = e.getKey();
       if (!this.globalAttrPolicies.containsKey(attrName)) {
         ab.put(attrName, e.getValue());
       }
     }
     allGlobalAttrPolicies = ab.build();
   }
   return new PolicyFactory(b.build(), textContainers, allGlobalAttrPolicies);
 }
 @Override
 public String toString() {
   MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(this);
   helper.add(CLASS, klass.getName());
   for (Map.Entry<String, String> entry : options.entrySet())
     helper.add(entry.getKey(), entry.getValue());
   return helper.toString();
 }
 @Override
 public String toDelimitedString(char delimiter) {
   StringBuilder sb = new StringBuilder();
   for (Map.Entry<String, String> entry : settings.entrySet()) {
     sb.append(entry.getKey()).append("=").append(entry.getValue()).append(delimiter);
   }
   return sb.toString();
 }
Example #13
0
 private ImmutableMap<PathFragment, Path> transformPackageRoots(
     ImmutableMap<PackageIdentifier, Path> packageRoots) {
   ImmutableMap.Builder<PathFragment, Path> builder = ImmutableMap.builder();
   for (Map.Entry<PackageIdentifier, Path> entry : packageRoots.entrySet()) {
     builder.put(entry.getKey().getPathFragment(), entry.getValue());
   }
   return builder.build();
 }
Example #14
0
 public static List<Tuple<ColumnIdent, ReferenceInfo>> forTable(TableIdent tableIdent) {
   List<Tuple<ColumnIdent, ReferenceInfo>> columns = new ArrayList<>(COLUMN_IDENTS.size());
   for (Map.Entry<ColumnIdent, DataType> entry : COLUMN_IDENTS.entrySet()) {
     columns.add(
         new Tuple<>(entry.getKey(), newInfo(tableIdent, entry.getKey(), entry.getValue())));
   }
   return columns;
 }
 private @Nullable HttpService getHttpService(String path) throws Exception {
   for (Entry<Pattern, HttpService> entry : httpServices.entrySet()) {
     Matcher matcher = entry.getKey().matcher(path);
     if (matcher.matches()) {
       return entry.getValue();
     }
   }
   return null;
 }
 SerializedForm(ImmutableMap<?, ?> map) {
   keys = new Object[map.size()];
   values = new Object[map.size()];
   int i = 0;
   for (Entry<?, ?> entry : map.entrySet()) {
     keys[i] = entry.getKey();
     values[i] = entry.getValue();
     i++;
   }
 }
Example #17
0
 /**
  * Try to guess the timezone code, and replace it with a timezone offset. Note: JodaTime can guess
  * a few codes already, they didn't include all codes since they are not standardized. This method
  * should only be used in last resort.
  *
  * @param date Formated date, supposedly ending with a timezone code
  * @return Date with the code replaced by its offset if there is a match
  */
 public static String guessTimezoneOffset(String date) {
   for (Entry<String, String> entry : TIMEZONE_CODE_MAP.entrySet()) {
     String code = entry.getKey();
     String offset = entry.getValue();
     String pattern = " \\(?" + code + "\\)?";
     if (date.matches(".+" + pattern)) {
       return date.replaceAll(pattern, offset);
     }
   }
   return date;
 }
Example #18
0
 /**
  * Returns true if any of the options in {@code options} matches both of the regular expressions
  * provided: its name matches the option's name and its value matches the option's value.
  */
 public boolean optionMatches(String namePattern, String valuePattern) {
   Matcher nameMatcher = Pattern.compile(namePattern).matcher("");
   Matcher valueMatcher = Pattern.compile(valuePattern).matcher("");
   for (Map.Entry<ProtoMember, Object> entry : map.entrySet()) {
     if (nameMatcher.reset(entry.getKey().member()).matches()
         && valueMatcher.reset(String.valueOf(entry.getValue())).matches()) {
       return true;
     }
   }
   return false;
 }
Example #19
0
 static ImmutableMap<String, String> withDefaults(
     ImmutableMap<String, String> map, ImmutableMap<String, String> defaults) {
   ImmutableMap.Builder<String, String> builder =
       ImmutableMap.<String, String>builder().putAll(map);
   for (ImmutableMap.Entry<String, String> entry : defaults.entrySet()) {
     if (!map.containsKey(entry.getKey())) {
       builder = builder.put(entry.getKey(), entry.getValue());
     }
   }
   return builder.build();
 }
 @Override
 public void writeTo(StreamOutput out) throws IOException {
   out.writeUTF(nodeName);
   out.writeUTF(nodeId);
   addressToStream(out, address);
   out.writeVInt(attributes.size());
   for (Map.Entry<String, String> entry : attributes.entrySet()) {
     out.writeUTF(entry.getKey());
     out.writeUTF(entry.getValue());
   }
   Version.writeVersion(version, out);
 }
  public ImmutableSet<DependencyEntry> getDependencies(IjModule module) {
    ImmutableMap<IjProjectElement, IjModuleGraph.DependencyType> deps =
        moduleGraph.getDepsFor(module);
    IjDependencyListBuilder dependencyListBuilder = new IjDependencyListBuilder();

    for (Map.Entry<IjProjectElement, IjModuleGraph.DependencyType> entry : deps.entrySet()) {
      IjProjectElement element = entry.getKey();
      IjModuleGraph.DependencyType dependencyType = entry.getValue();
      element.addAsDependency(dependencyType, dependencyListBuilder);
    }
    return dependencyListBuilder.build();
  }
Example #22
0
 /**
  * Return the manifest as a JSON blob to write to the pex processes stdin.
  *
  * <p>We use stdin rather than passing as an argument to the processes since manifest files can
  * occasionally get extremely large, and surpass exec/shell limits on arguments.
  */
 @Override
 protected Optional<String> getStdin(ExecutionContext context) {
   // Convert the map of paths to a map of strings before converting to JSON.
   ImmutableMap<Path, Path> resolvedModules;
   try {
     resolvedModules = getExpandedSourcePaths(context, modules);
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
   ImmutableMap.Builder<String, String> modulesBuilder = ImmutableMap.builder();
   for (ImmutableMap.Entry<Path, Path> ent : resolvedModules.entrySet()) {
     modulesBuilder.put(ent.getKey().toString(), ent.getValue().toString());
   }
   ImmutableMap.Builder<String, String> resourcesBuilder = ImmutableMap.builder();
   for (ImmutableMap.Entry<Path, Path> ent : resources.entrySet()) {
     resourcesBuilder.put(ent.getKey().toString(), ent.getValue().toString());
   }
   ImmutableMap.Builder<String, String> nativeLibrariesBuilder = ImmutableMap.builder();
   for (ImmutableMap.Entry<Path, Path> ent : nativeLibraries.entrySet()) {
     nativeLibrariesBuilder.put(ent.getKey().toString(), ent.getValue().toString());
   }
   ImmutableList.Builder<String> prebuiltLibrariesBuilder = ImmutableList.builder();
   for (Path req : prebuiltLibraries) {
     prebuiltLibrariesBuilder.add(req.toString());
   }
   try {
     return Optional.of(
         context
             .getObjectMapper()
             .writeValueAsString(
                 ImmutableMap.of(
                     "modules", modulesBuilder.build(),
                     "resources", resourcesBuilder.build(),
                     "nativeLibraries", nativeLibrariesBuilder.build(),
                     "prebuiltLibraries", prebuiltLibrariesBuilder.build())));
   } catch (IOException e) {
     throw Throwables.propagate(e);
   }
 }
  /**
   * Collects and returns all the Java objects reachable in Skylark from (and including)
   * firstClassObject with the corresponding SkylarkSignature annotations.
   *
   * <p>Note that the {@link SkylarkSignature} annotation for firstClassObject - firstAnnotation -
   * is also an input parameter, because some top level Skylark built-in objects and methods are not
   * annotated on the class, but on a field referencing them.
   */
  void collect(
      SkylarkModule firstModule, Class<?> firstClass, Map<String, SkylarkModuleDoc> modules) {
    Set<Class<?>> processedClasses = new HashSet<>();
    LinkedList<Class<?>> classesToProcess = new LinkedList<>();
    Map<Class<?>, SkylarkModule> annotations = new HashMap<>();

    classesToProcess.addLast(firstClass);
    annotations.put(firstClass, firstModule);

    while (!classesToProcess.isEmpty()) {
      Class<?> classObject = classesToProcess.removeFirst();
      SkylarkModule annotation = annotations.get(classObject);
      processedClasses.add(classObject);
      if (!modules.containsKey(annotation.name())) {
        modules.put(annotation.name(), new SkylarkModuleDoc(annotation, classObject));
      }
      SkylarkModuleDoc module = modules.get(annotation.name());

      if (module.javaMethodsNotCollected()) {
        ImmutableMap<Method, SkylarkCallable> methods =
            FuncallExpression.collectSkylarkMethodsWithAnnotation(classObject);
        ArrayList<SkylarkJavaMethod> methodList = new ArrayList<>();
        for (Map.Entry<Method, SkylarkCallable> entry : methods.entrySet()) {
          methodList.add(new SkylarkJavaMethod(entry.getKey(), entry.getValue()));
        }
        module.setJavaMethods(methodList);

        for (Map.Entry<Method, SkylarkCallable> method : methods.entrySet()) {
          Class<?> returnClass = method.getKey().getReturnType();
          if (returnClass.isAnnotationPresent(SkylarkModule.class)
              && !processedClasses.contains(returnClass)) {
            classesToProcess.addLast(returnClass);
            annotations.put(returnClass, returnClass.getAnnotation(SkylarkModule.class));
          }
        }
      }
    }
  }
Example #24
0
  /**
   * Resolve the map of name to {@link SourcePath} to a map of full header name to {@link
   * SourcePath}.
   */
  public static ImmutableMap<Path, SourcePath> resolveHeaderMap(
      Path basePath, ImmutableMap<String, SourcePath> headers) {

    ImmutableMap.Builder<Path, SourcePath> headerMap = ImmutableMap.builder();

    // Resolve the "names" of the headers to actual paths by prepending the base path
    // specified by the build target.
    for (ImmutableMap.Entry<String, SourcePath> ent : headers.entrySet()) {
      Path path = basePath.resolve(ent.getKey());
      headerMap.put(path, ent.getValue());
    }

    return headerMap.build();
  }
Example #25
0
 public Set<String> simpleMatchToIndexNames(String pattern) {
   int dotIndex = pattern.indexOf('.');
   if (dotIndex != -1) {
     String possibleType = pattern.substring(0, dotIndex);
     DocumentMapper possibleDocMapper = mappers.get(possibleType);
     if (possibleDocMapper != null) {
       Set<String> typedFields = Sets.newHashSet();
       for (String indexName : possibleDocMapper.mappers().simpleMatchToIndexNames(pattern)) {
         typedFields.add(possibleType + "." + indexName);
       }
       return typedFields;
     }
   }
   Set<String> fields = Sets.newHashSet();
   for (Map.Entry<String, FieldMappers> entry : fullNameFieldMappers.entrySet()) {
     if (Regex.simpleMatch(pattern, entry.getKey())) {
       for (FieldMapper mapper : entry.getValue()) {
         fields.add(mapper.names().indexName());
       }
     }
   }
   for (Map.Entry<String, FieldMappers> entry : indexNameFieldMappers.entrySet()) {
     if (Regex.simpleMatch(pattern, entry.getKey())) {
       for (FieldMapper mapper : entry.getValue()) {
         fields.add(mapper.names().indexName());
       }
     }
   }
   for (Map.Entry<String, FieldMappers> entry : nameFieldMappers.entrySet()) {
     if (Regex.simpleMatch(pattern, entry.getKey())) {
       for (FieldMapper mapper : entry.getValue()) {
         fields.add(mapper.names().indexName());
       }
     }
   }
   return fields;
 }
    private void installFiles(
        String filesType,
        ImmutableMap<String, Path> filesToInstallByHash,
        String metadataFileContents,
        String filenameFormat,
        Path destinationDirRelativeToDataRoot)
        throws Exception {
      try (TraceEventLogger ignored1 =
          TraceEventLogger.start(eventBus, "multi_install_" + filesType)) {
        device.createForward(agentPort, agentPort);
        try {
          for (Map.Entry<String, Path> entry : filesToInstallByHash.entrySet()) {
            Path destination =
                destinationDirRelativeToDataRoot.resolve(
                    String.format(filenameFormat, entry.getKey()));
            Path source = entry.getValue();

            try (TraceEventLogger ignored2 =
                TraceEventLogger.start(eventBus, "install_" + filesType)) {
              installFile(device, agentPort, destination, source);
            }
          }
          try (TraceEventLogger ignored3 =
              TraceEventLogger.start(eventBus, "install_" + filesType + "_metadata")) {
            try (NamedTemporaryFile temp = new NamedTemporaryFile("metadata", "tmp")) {
              com.google.common.io.Files.write(
                  metadataFileContents.getBytes(Charsets.UTF_8), temp.get().toFile());
              installFile(
                  device,
                  agentPort,
                  destinationDirRelativeToDataRoot.resolve("metadata.txt"),
                  temp.get());
            }
          }
        } finally {
          try {
            device.removeForward(agentPort, agentPort);
          } catch (AdbCommandRejectedException e) {
            LOG.warn(e, "Failed to remove adb forward on port %d for device %s", agentPort, device);
            eventBus.post(
                ConsoleEvent.warning(
                    "Failed to remove adb forward %d. This is not necessarily a problem\n"
                        + "because it will be recreated during the next exopackage installation.\n"
                        + "See the log for the full exception.",
                    agentPort));
          }
        }
      }
    }
 @PostConstruct
 public void init() {
   final ImmutableMap<String, AppManifest> initialTenantMap = tenantConfig.tenantMap();
   log.debug(
       "Registering {} subscribers for {} tenants: {}",
       getClass().getName(),
       initialTenantMap.size(),
       initialTenantMap.keySet());
   for (final Map.Entry<String, AppManifest> tenant : initialTenantMap.entrySet()) {
     createSubscribers(tenant.getKey(), tenant.getValue(), "Init");
   }
   if (tenantRepo != null) {
     tenantRepo.addListener(this);
   }
 }
 public Iterable<String> listStreams() {
   final Set<String> streams = Sets.newHashSet();
   for (Entry<String, Object> e : content.entrySet()) {
     String k = e.getKey();
     String[] streamIds = StringUtils.split(k, "/", 2);
     if (streamIds.length == 2) {
       streams.add(streamIds[1]);
     }
   }
   return new Iterable<String>() {
     public Iterator<String> iterator() {
       return streams.iterator();
     }
   };
 }
Example #29
0
  /**
   * Similar to {@link #createZip(Collection, Path)}, but also takes a list of additional files to
   * write in the zip, including their contents, as a map. It's assumed only paths that should not
   * be ignored are passed to this method.
   */
  public void createZip(
      Collection<Path> pathsToIncludeInZip,
      Path out,
      ImmutableMap<Path, String> additionalFileContents)
      throws IOException {
    try (CustomZipOutputStream zip = ZipOutputStreams.newOutputStream(out)) {
      for (Path path : pathsToIncludeInZip) {
        boolean isDirectory = isDirectory(path);

        String entryName = path.toString();
        if (isDirectory) {
          entryName += "/";
        }
        CustomZipEntry entry = new CustomZipEntry(entryName);

        // We want deterministic ZIPs, so avoid mtimes.
        entry.setTime(0);

        // Support executable files.  If we detect this file is executable, store this
        // information as 0100 in the field typically used in zip implementations for
        // POSIX file permissions.  We'll use this information when unzipping.
        if (isExecutable(path)) {
          entry.setExternalAttributes(
              MorePosixFilePermissions.toMode(EnumSet.of(PosixFilePermission.OWNER_EXECUTE)) << 16);
        }

        zip.putNextEntry(entry);
        if (!isDirectory) {
          try (InputStream input = newFileInputStream(path)) {
            ByteStreams.copy(input, zip);
          }
        }
        zip.closeEntry();
      }

      for (Map.Entry<Path, String> fileContentsEntry : additionalFileContents.entrySet()) {
        CustomZipEntry entry = new CustomZipEntry(fileContentsEntry.getKey().toString());
        // We want deterministic ZIPs, so avoid mtimes.
        entry.setTime(0);
        zip.putNextEntry(entry);
        try (InputStream stream =
            new ByteArrayInputStream(fileContentsEntry.getValue().getBytes(Charsets.UTF_8))) {
          ByteStreams.copy(stream, zip);
        }
        zip.closeEntry();
      }
    }
  }
Example #30
0
  public HBaseStoreManager(org.apache.commons.configuration.Configuration config)
      throws StorageException {
    super(config, PORT_DEFAULT);

    this.tableName = config.getString(TABLE_NAME_KEY, TABLE_NAME_DEFAULT);

    this.hconf = HBaseConfiguration.create();
    for (Map.Entry<String, String> confEntry : HBASE_CONFIGURATION.entrySet()) {
      if (config.containsKey(confEntry.getKey())) {
        hconf.set(confEntry.getValue(), config.getString(confEntry.getKey()));
      }
    }

    // Copy a subset of our commons config into a Hadoop config
    org.apache.commons.configuration.Configuration hbCommons =
        config.subset(HBASE_CONFIGURATION_NAMESPACE);

    @SuppressWarnings("unchecked") // I hope commons-config eventually fixes this
    Iterator<String> keys = hbCommons.getKeys();
    int keysLoaded = 0;

    while (keys.hasNext()) {
      String key = keys.next();
      String value = hbCommons.getString(key);
      logger.debug("HBase configuration: setting {}={}", key, value);
      hconf.set(key, value);
      keysLoaded++;
    }

    logger.debug("HBase configuration: set a total of {} configuration values", keysLoaded);

    connectionPool = new HTablePool(hconf, connectionPoolSize);

    openStores = new ConcurrentHashMap<String, HBaseKeyColumnValueStore>();

    // TODO: allowing publicly mutate fields is bad, should be fixed
    features = new StoreFeatures();
    features.supportsScan = true;
    features.supportsBatchMutation = true;
    features.supportsTransactions = false;
    features.supportsConsistentKeyOperations = true;
    features.supportsLocking = false;
    features.isKeyOrdered = false;
    features.isDistributed = true;
    features.hasLocalKeyPartition = false;
  }