/** Normalizes all shard routings to the same version. */
 public IndexShardRoutingTable normalizeVersions() {
   if (shards.isEmpty()) {
     return this;
   }
   if (shards.size() == 1) {
     return this;
   }
   long highestVersion = shards.get(0).version();
   boolean requiresNormalization = false;
   for (int i = 1; i < shards.size(); i++) {
     if (shards.get(i).version() != highestVersion) {
       requiresNormalization = true;
     }
     if (shards.get(i).version() > highestVersion) {
       highestVersion = shards.get(i).version();
     }
   }
   if (!requiresNormalization) {
     return this;
   }
   List<ShardRouting> shardRoutings = new ArrayList<>(shards.size());
   for (int i = 0; i < shards.size(); i++) {
     if (shards.get(i).version() == highestVersion) {
       shardRoutings.add(shards.get(i));
     } else {
       shardRoutings.add(new ShardRouting(shards.get(i), highestVersion));
     }
   }
   return new IndexShardRoutingTable(
       shardId, ImmutableList.copyOf(shardRoutings), primaryAllocatedPostApi);
 }
Beispiel #2
0
  public ServiceManager(Iterable<? extends Service> services) {
    ImmutableList<Service> copy = ImmutableList.copyOf(services);
    if (copy.isEmpty()) {
      logger.log(
          Level.WARNING,
          "ServiceManager configured with no services.  Is your application configured properly?",
          new EmptyServiceManagerWarning(null));

      copy = ImmutableList.of(new NoOpService(null));
    }
    this.state = new ServiceManagerState(copy);
    this.services = copy;
    WeakReference<ServiceManagerState> stateReference = new WeakReference(this.state);

    Executor sameThreadExecutor = MoreExecutors.sameThreadExecutor();
    for (Service service : copy) {
      service.addListener(new ServiceListener(service, stateReference), sameThreadExecutor);

      Preconditions.checkArgument(
          service.state() == Service.State.NEW,
          "Can only manage NEW services, %s",
          new Object[] {service});
    }
    this.state.markReady();
  }
  public Result createBuildableForAndroidResources(
      BuildRuleResolver ruleResolver, boolean createBuildableIfEmptyDeps) {
    ImmutableSortedSet<BuildRule> originalDeps = originalBuildRuleParams.getDeps();
    ImmutableList<HasAndroidResourceDeps> androidResourceDeps =
        UberRDotJavaUtil.getAndroidResourceDeps(originalDeps);

    if (androidResourceDeps.isEmpty() && !createBuildableIfEmptyDeps) {
      return new Result(originalBuildRuleParams, Optional.<DummyRDotJava>absent());
    }

    BuildRule dummyRDotJavaBuildRule =
        ruleResolver.buildAndAddToIndex(
            DummyRDotJava.newDummyRDotJavaBuildableBuilder(buildRuleBuilderParams)
                .setBuildTarget(dummyRDotJavaBuildTarget)
                .setAndroidResourceDeps(androidResourceDeps));
    final DummyRDotJava dummyRDotJava = (DummyRDotJava) dummyRDotJavaBuildRule.getBuildable();

    ImmutableSortedSet<BuildRule> totalDeps =
        ImmutableSortedSet.<BuildRule>naturalOrder()
            .addAll(originalDeps)
            .add(dummyRDotJavaBuildRule)
            .build();

    BuildRuleParams newBuildRuleParams = originalBuildRuleParams.copyWithChangedDeps(totalDeps);

    return new Result(newBuildRuleParams, Optional.of(dummyRDotJava));
  }
 public ArtifactCache createArtifactCache(
     Optional<String> currentWifiSsid, BuckEventBus buckEventBus) {
   ImmutableList<String> modes = getArtifactCacheModes();
   if (modes.isEmpty()) {
     return new NoopArtifactCache();
   }
   ImmutableList.Builder<ArtifactCache> builder = ImmutableList.builder();
   boolean useDistributedCache = isWifiUsableForDistributedCache(currentWifiSsid);
   try {
     for (String mode : modes) {
       switch (ArtifactCacheNames.valueOf(mode)) {
         case dir:
           ArtifactCache dirArtifactCache = createDirArtifactCache();
           buckEventBus.register(dirArtifactCache);
           builder.add(dirArtifactCache);
           break;
         case http:
           if (useDistributedCache) {
             ArtifactCache httpArtifactCache = createHttpArtifactCache(buckEventBus);
             builder.add(httpArtifactCache);
           }
           break;
       }
     }
   } catch (IllegalArgumentException e) {
     throw new HumanReadableException("Unusable cache.mode: '%s'", modes.toString());
   }
   ImmutableList<ArtifactCache> artifactCaches = builder.build();
   if (artifactCaches.size() == 1) {
     // Don't bother wrapping a single artifact cache in MultiArtifactCache.
     return artifactCaches.get(0);
   } else {
     return new MultiArtifactCache(artifactCaches);
   }
 }
  @Override
  public Object readFrom(
      Class<Object> type,
      Type genericType,
      Annotation[] annotations,
      MediaType mediaType,
      MultivaluedMap<String, String> httpHeaders,
      InputStream entityStream)
      throws IOException, WebApplicationException {
    boolean validating = false;
    for (Annotation annotation : annotations) {
      validating = validating || (annotation.annotationType() == Valid.class);
    }

    final Object value = json.readValue(entityStream, genericType);
    if (validating) {
      final ImmutableList<String> errors = VALIDATOR.validate(value);
      if (!errors.isEmpty()) {
        final StringBuilder msg =
            new StringBuilder("The request entity had the following errors:\n");
        for (String error : errors) {
          msg.append("  * ").append(error).append('\n');
        }
        throw new WebApplicationException(
            Response.status(UNPROCESSABLE_ENTITY)
                .entity(msg.toString())
                .type(MediaType.TEXT_PLAIN_TYPE)
                .build());
      }
    }
    return value;
  }
 private void ensureNodesAreAvailable(ImmutableList<DiscoveryNode> nodes) {
   if (nodes.isEmpty()) {
     String message =
         String.format(Locale.ROOT, "None of the configured nodes are available: %s", nodes);
     throw new NoNodeAvailableException(message);
   }
 }
Beispiel #7
0
  /** Returns an object of the same type as {@code o}, or null if it is not retained. */
  private Object retainAll(Schema schema, MarkSet markSet, ProtoType type, Object o) {
    if (!markSet.contains(type)) {
      return null; // Prune this type.

    } else if (o instanceof Map) {
      ImmutableMap.Builder<ProtoMember, Object> builder = ImmutableMap.builder();
      for (Map.Entry<?, ?> entry : ((Map<?, ?>) o).entrySet()) {
        ProtoMember protoMember = (ProtoMember) entry.getKey();
        if (!markSet.contains(protoMember)) continue; // Prune this field.
        Field field = schema.getField(protoMember);
        Object retainedValue = retainAll(schema, markSet, field.type(), entry.getValue());
        if (retainedValue != null) {
          builder.put(protoMember, retainedValue); // This retained field is non-empty.
        }
      }
      ImmutableMap<ProtoMember, Object> map = builder.build();
      return !map.isEmpty() ? map : null;

    } else if (o instanceof List) {
      ImmutableList.Builder<Object> builder = ImmutableList.builder();
      for (Object value : ((List) o)) {
        Object retainedValue = retainAll(schema, markSet, type, value);
        if (retainedValue != null) {
          builder.add(retainedValue); // This retained value is non-empty.
        }
      }
      ImmutableList<Object> list = builder.build();
      return !list.isEmpty() ? list : null;

    } else {
      return o;
    }
  }
  /**
   * Scans {@code action_listeners} associated with this build to see if any {@code extra_actions}
   * should be added to this configured target. If any action_listeners are present, a partial visit
   * of the artifact/action graph is performed (for as long as actions found are owned by this
   * {@link ConfiguredTarget}). Any actions that match the {@code action_listener} get an {@code
   * extra_action} associated. The output artifacts of the extra_action are reported to the {@link
   * AnalysisEnvironment} for bookkeeping.
   */
  private ExtraActionArtifactsProvider initializeExtraActions() {
    BuildConfiguration configuration = ruleContext.getConfiguration();
    if (configuration.isHostConfiguration()) {
      return ExtraActionArtifactsProvider.EMPTY;
    }

    ImmutableList<Artifact> extraActionArtifacts = ImmutableList.of();
    NestedSetBuilder<ExtraArtifactSet> builder = NestedSetBuilder.stableOrder();

    List<Label> actionListenerLabels = configuration.getActionListeners();
    if (!actionListenerLabels.isEmpty()
        && ruleContext.getRule().getAttributeDefinition(":action_listener") != null) {
      ExtraActionsVisitor visitor =
          new ExtraActionsVisitor(ruleContext, computeMnemonicsToExtraActionMap());

      // The action list is modified within the body of the loop by the addExtraAction() call,
      // thus the copy
      for (Action action :
          ImmutableList.copyOf(ruleContext.getAnalysisEnvironment().getRegisteredActions())) {
        if (!actionsWithoutExtraAction.contains(action)) {
          visitor.addExtraAction(action);
        }
      }

      extraActionArtifacts = visitor.getAndResetExtraArtifacts();
      if (!extraActionArtifacts.isEmpty()) {
        builder.add(ExtraArtifactSet.of(ruleContext.getLabel(), extraActionArtifacts));
      }
    }

    // Add extra action artifacts from dependencies
    for (TransitiveInfoCollection dep : ruleContext.getConfiguredTargetMap().values()) {
      ExtraActionArtifactsProvider provider = dep.getProvider(ExtraActionArtifactsProvider.class);
      if (provider != null) {
        builder.addTransitive(provider.getTransitiveExtraActionArtifacts());
      }
    }

    if (mandatoryStampFiles != null && !mandatoryStampFiles.isEmpty()) {
      builder.add(ExtraArtifactSet.of(ruleContext.getLabel(), mandatoryStampFiles));
    }

    if (extraActionArtifacts.isEmpty() && builder.isEmpty()) {
      return ExtraActionArtifactsProvider.EMPTY;
    }
    return new ExtraActionArtifactsProvider(extraActionArtifacts, builder.build());
  }
 void isNotValidGlobal() {
   FormattingErrorReporter errorReporter = new FormattingErrorReporter();
   ExprNode expr = expressionParser(errorReporter).parseExpression();
   ImmutableList<String> errorMessages = errorReporter.getErrorMessages();
   if (expr instanceof GlobalNode && errorMessages.isEmpty()) {
     fail("is an invalid global");
   }
 }
 @Override
 public int hashCode() {
   int baseHash = super.hashCode();
   if (templateTypes.isEmpty()) {
     return baseHash;
   }
   return Objects.hash(templateTypes, baseHash);
 }
Beispiel #11
0
  /**
   * Return a manifest of what finalized edit logs are available. All available edit logs are
   * returned starting from the transaction id passed.
   *
   * @param fromTxId Starting transaction id to read the logs.
   * @return RemoteEditLogManifest object.
   */
  public synchronized RemoteEditLogManifest getEditLogManifest(long fromTxId) {
    // Collect RemoteEditLogs available from each FileJournalManager
    List<RemoteEditLog> allLogs = Lists.newArrayList();
    for (JournalAndStream j : journals) {
      if (j.getManager() instanceof FileJournalManager) {
        FileJournalManager fjm = (FileJournalManager) j.getManager();
        try {
          allLogs.addAll(fjm.getRemoteEditLogs(fromTxId));
        } catch (Throwable t) {
          LOG.warn("Cannot list edit logs in " + fjm, t);
        }
      }
    }

    // Group logs by their starting txid
    ImmutableListMultimap<Long, RemoteEditLog> logsByStartTxId =
        Multimaps.index(allLogs, RemoteEditLog.GET_START_TXID);
    long curStartTxId = fromTxId;

    List<RemoteEditLog> logs = Lists.newArrayList();
    while (true) {
      ImmutableList<RemoteEditLog> logGroup = logsByStartTxId.get(curStartTxId);
      if (logGroup.isEmpty()) {
        // we have a gap in logs - for example because we recovered some old
        // storage directory with ancient logs. Clear out any logs we've
        // accumulated so far, and then skip to the next segment of logs
        // after the gap.
        SortedSet<Long> startTxIds = Sets.newTreeSet(logsByStartTxId.keySet());
        startTxIds = startTxIds.tailSet(curStartTxId);
        if (startTxIds.isEmpty()) {
          break;
        } else {
          if (LOG.isDebugEnabled()) {
            LOG.debug(
                "Found gap in logs at "
                    + curStartTxId
                    + ": "
                    + "not returning previous logs in manifest.");
          }
          logs.clear();
          curStartTxId = startTxIds.first();
          continue;
        }
      }

      // Find the one that extends the farthest forward
      RemoteEditLog bestLog = Collections.max(logGroup);
      logs.add(bestLog);
      // And then start looking from after that point
      curStartTxId = bestLog.getEndTxId() + 1;
    }
    RemoteEditLogManifest ret = new RemoteEditLogManifest(logs);

    if (LOG.isDebugEnabled()) {
      LOG.debug("Generated manifest for logs since " + fromTxId + ":" + ret);
    }
    return ret;
  }
Beispiel #12
0
 /**
  * Returns the list of proto files that were added directly into the deps attributes. This way
  * of specifying the protos is deprecated, and displays a warning when the target does so.
  */
 private ImmutableList<Artifact> getProtoDepsFiles() {
   PrerequisiteArtifacts prerequisiteArtifacts =
       ruleContext.getPrerequisiteArtifacts("deps", Mode.TARGET);
   ImmutableList<Artifact> protos = prerequisiteArtifacts.filter(FileType.of(".proto")).list();
   if (!protos.isEmpty()) {
     ruleContext.attributeWarning("deps", FILES_DEPRECATED_WARNING);
   }
   return protos;
 }
 public ShardIterator primaryActiveInitializingShardIt() {
   if (!primaryAsList.isEmpty()
       && !primaryAsList.get(0).active()
       && !primaryAsList.get(0).initializing()) {
     List<ShardRouting> primaryList = ImmutableList.of();
     return new PlainShardIterator(shardId, primaryList);
   }
   return primaryShardIt();
 }
  @Override
  protected void masterOperation(
      final SnapshotsStatusRequest request,
      final ClusterState state,
      final ActionListener<SnapshotsStatusResponse> listener)
      throws Exception {
    ImmutableList<SnapshotMetaData.Entry> currentSnapshots =
        snapshotsService.currentSnapshots(request.repository(), request.snapshots());

    if (currentSnapshots.isEmpty()) {
      listener.onResponse(buildResponse(request, currentSnapshots, null));
      return;
    }

    Set<String> nodesIds = newHashSet();
    for (SnapshotMetaData.Entry entry : currentSnapshots) {
      for (SnapshotMetaData.ShardSnapshotStatus status : entry.shards().values()) {
        if (status.nodeId() != null) {
          nodesIds.add(status.nodeId());
        }
      }
    }

    if (!nodesIds.isEmpty()) {
      // There are still some snapshots running - check their progress
      SnapshotId[] snapshotIds = new SnapshotId[currentSnapshots.size()];
      for (int i = 0; i < currentSnapshots.size(); i++) {
        snapshotIds[i] = currentSnapshots.get(i).snapshotId();
      }

      transportNodesSnapshotsStatus.status(
          nodesIds.toArray(new String[nodesIds.size()]),
          snapshotIds,
          request.masterNodeTimeout(),
          new ActionListener<TransportNodesSnapshotsStatus.NodesSnapshotStatus>() {
            @Override
            public void onResponse(
                TransportNodesSnapshotsStatus.NodesSnapshotStatus nodeSnapshotStatuses) {
              try {
                ImmutableList<SnapshotMetaData.Entry> currentSnapshots =
                    snapshotsService.currentSnapshots(request.repository(), request.snapshots());
                listener.onResponse(buildResponse(request, currentSnapshots, nodeSnapshotStatuses));
              } catch (Throwable e) {
                listener.onFailure(e);
              }
            }

            @Override
            public void onFailure(Throwable e) {
              listener.onFailure(e);
            }
          });
    } else {
      // We don't have any in-progress shards, just return current stats
      listener.onResponse(buildResponse(request, currentSnapshots, null));
    }
  }
  private void incrementalBuild(IProgressMonitor monitor) throws CoreException {
    IProject project = this.getProject();
    IResourceDelta delta = this.getDelta(project);
    ImmutableList<FileDelta> fileDeltas = ResourceDeltaVisitor.getFileDeltas(delta, project);

    if (!fileDeltas.isEmpty()) {
      this.clean(fileDeltas, monitor);
      this.build(fileDeltas, monitor);
    }
  }
 /**
  * Returns an iterator over active and initializing shards. Making sure though that its random
  * within the active shards, and initializing shards are the last to iterate through.
  */
 public ShardIterator activeInitializingShardsIt(int seed) {
   if (allInitializingShards.isEmpty()) {
     return new PlainShardIterator(shardId, shuffler.shuffle(activeShards, seed));
   }
   ArrayList<ShardRouting> ordered =
       new ArrayList<>(activeShards.size() + allInitializingShards.size());
   ordered.addAll(shuffler.shuffle(activeShards, seed));
   ordered.addAll(allInitializingShards);
   return new PlainShardIterator(shardId, ordered);
 }
 public boolean hasImplementedInterfaces() {
   if (!implementedInterfaces.isEmpty()) {
     return true;
   }
   FunctionType superCtor = isConstructor() ? getSuperClassConstructor() : null;
   if (superCtor != null) {
     return superCtor.hasImplementedInterfaces();
   }
   return false;
 }
Beispiel #18
0
  /**
   * Skontroluj deserializaciu a stiahnutie eventov v ramci obdobia
   *
   * @throws Exception
   */
  public void testGetEvents() throws Exception {
    Configuration.getInstance();
    EventsRequest request = new EventsRequest();
    Date start = DateUtils.fromString("2014-01-01T00:00:00.000Z");
    Date end = DateUtils.fromString("2014-03-01T00:00:00.000Z");
    request.setTime(start, end);

    ImmutableList<EventDto> response = ActivityService.getInstance().getEvents(request);
    Assert.assertNotNull(response);
    Assert.assertFalse(response.isEmpty());
  }
Beispiel #19
0
  protected boolean hasSelfArgument() {
    Class<?> clazz = getObjectType();
    if (clazz == null) {
      return false;
    }
    List<SkylarkType> types = signature.getTypes();
    ImmutableList<String> names = signature.getSignature().getNames();

    return (!types.isEmpty() && types.get(0).canBeCastTo(clazz))
        || (!names.isEmpty() && names.get(0).equals("self"));
  }
 private static ImmutableSortedSet copyOfInternal(Comparator comparator1, Iterable iterable) {
   if (SortedIterables.hasSameComparator(comparator1, iterable)
       && (iterable instanceof ImmutableSortedSet)) {
     ImmutableSortedSet immutablesortedset = (ImmutableSortedSet) iterable;
     if (!immutablesortedset.isPartialView()) return immutablesortedset;
   }
   ImmutableList immutablelist =
       ImmutableList.copyOf(SortedIterables.sortedUnique(comparator1, iterable));
   Object obj;
   if (immutablelist.isEmpty()) obj = emptySet(comparator1);
   else obj = new RegularImmutableSortedSet(immutablelist, comparator1);
   return ((ImmutableSortedSet) (obj));
 }
Beispiel #21
0
 public String getExplainString(TExplainLevel explainLevel) {
   StringBuilder str = new StringBuilder();
   str.append(type.toString());
   if (!partitionExprs.isEmpty()) {
     List<String> strings = Lists.newArrayList();
     for (Expr expr : partitionExprs) {
       strings.add(expr.toSql());
     }
     str.append(": " + Joiner.on(", ").join(strings));
   }
   str.append("\n");
   return str.toString();
 }
Beispiel #22
0
  public Schema load() throws IOException {
    ImmutableList<Path> directories = this.directories.build();
    if (directories.isEmpty()) {
      throw new IllegalStateException("No directories added.");
    }

    Deque<Path> protos = new ArrayDeque<>(this.protos.build());
    if (protos.isEmpty()) {
      // TODO traverse all files in every directory.
    }

    Map<Path, ProtoFile> loaded = new LinkedHashMap<>();
    while (!protos.isEmpty()) {
      Path proto = protos.removeFirst();
      if (loaded.containsKey(proto)) {
        continue;
      }

      ProtoFileElement element = null;
      for (Path directory : directories) {
        if (proto.isAbsolute() && !proto.startsWith(directory)) {
          continue;
        }
        Path resolvedPath = directory.resolve(proto);
        if (Files.exists(resolvedPath)) {
          Location location = Location.get(directory.toString(), proto.toString());
          try (Source source = Okio.source(resolvedPath)) {
            String data = Okio.buffer(source).readUtf8();
            element = ProtoParser.parse(location, data);
          } catch (IOException e) {
            throw new IOException("Failed to load " + proto, e);
          }
          break;
        }
      }
      if (element == null) {
        throw new FileNotFoundException("Failed to locate " + proto + " in " + directories);
      }

      ProtoFile protoFile = ProtoFile.get(element);
      loaded.put(proto, protoFile);

      // Queue dependencies to be loaded.
      FileSystem fs = proto.getFileSystem();
      for (String importPath : element.imports()) {
        protos.addLast(fs.getPath(importPath));
      }
    }

    return new Linker(loaded.values()).link();
  }
Beispiel #23
0
 private void printMatchingTestRules(Console console, Iterable<TestRule> testRules) {
   PrintStream out = console.getStdOut();
   ImmutableList<TestRule> list = ImmutableList.copyOf(testRules);
   out.println(String.format("MATCHING TEST RULES (%d):", list.size()));
   out.println("");
   if (list.isEmpty()) {
     out.println("  (none)");
   } else {
     for (TestRule testRule : testRules) {
       out.println("  " + testRule.getBuildTarget());
     }
   }
   out.println("");
 }
 public final ImmutableList<ModelEntryT> getModelsByIds(
     final ImmutableList<ModelIdT> ids,
     final Logger logger,
     final Marker logMarker,
     final ModelFactory<ModelEntryT> modelFactory)
     throws IoExceptionT {
   if (ids.isEmpty()) {
     logger.info(logMarker, "no model ids requested from index {}", indexName);
     return ImmutableList.of();
   }
   logger.debug(logMarker, "getting models {} from index {}", ids, indexName);
   try {
     final MultiGetRequestBuilder requestBuilder = client.prepareMultiGet();
     for (final ModelId id : ids) {
       requestBuilder.add(indexName, documentType, id.toString());
     }
     final MultiGetResponse responses = requestBuilder.execute().actionGet();
     final ImmutableList.Builder<ModelEntryT> modelsBuilder = ImmutableList.builder();
     for (final MultiGetItemResponse response : responses.getResponses()) {
       if (response.isFailed()) {
         continue;
       }
       BytesReference sourceAsBytesRef;
       try {
         sourceAsBytesRef = response.getResponse().getSourceAsBytesRef();
       } catch (final NullPointerException e) {
         logger.debug(
             logMarker,
             "model {} actually missing, but hipsters don't know that",
             response.getId());
         continue;
       }
       try {
         modelsBuilder.add(modelFactory.createModelEntry(response.getId(), sourceAsBytesRef));
       } catch (final InvalidModelException e) {
         logger.error(logMarker, "invalid model {} from index, ignoring: ", response.getId(), e);
         continue;
       }
     }
     return modelsBuilder.build();
   } catch (final IndexNotFoundException e) {
     logger.warn(logMarker, "tried to get models {} from missing index {}", ids, indexName);
     return ImmutableList.of();
   } catch (final ElasticsearchException e) {
     throw exceptionFactory.newIoException(
         e, String.format("error getting models %s from index %s", ids, indexName));
   }
 }
Beispiel #25
0
  /**
   * Returns a {@link CommandLine} that is constructed by prepending the {@code executableArgs} to
   * {@code commandLine}.
   */
  static CommandLine ofMixed(
      final ImmutableList<String> executableArgs,
      final CommandLine commandLine,
      final boolean isShellCommand) {
    Preconditions.checkState(!executableArgs.isEmpty());
    return new CommandLine() {
      @Override
      public Iterable<String> arguments() {
        return Iterables.concat(executableArgs, commandLine.arguments());
      }

      @Override
      public boolean isShellCommand() {
        return isShellCommand;
      }
    };
  }
 private Bitmap getElementAt(final int position) {
   ImmutableList<File> collection =
       ImmutableList.copyOf(
           Collections2.filter(
               pictures,
               new Predicate<File>() {
                 @Override
                 public boolean apply(File input) {
                   return input.getName().endsWith(position + 1 + ".jpeg");
                 }
               }));
   if (!collection.isEmpty()) {
     return BitmapFactory.decodeFile(collection.get(0).getAbsolutePath());
   }
   throw new IllegalArgumentException(
       String.format("Cant find %d th element in the map", position));
 }
 public final void putModels(
     final Logger logger, final Marker logMarker, final ImmutableList<ModelEntryT> models)
     throws IoExceptionT {
   if (models.isEmpty()) {
     return;
   }
   logger.debug(logMarker, "putting {} models to index {}", models.size(), indexName);
   final BulkRequestBuilder bulkRequest = client.prepareBulk();
   for (final ModelEntryT modelEntry : models) {
     bulkRequest.add(__prepareIndex(modelEntry));
   }
   try {
     bulkRequest.execute().actionGet();
   } catch (final ElasticsearchException e) {
     throw exceptionFactory.newIoException(e, "error executing bulk request");
   }
 }
 public ShardIterator preferNodeActiveInitializingShardsIt(String nodeId) {
   ArrayList<ShardRouting> ordered =
       new ArrayList<>(activeShards.size() + allInitializingShards.size());
   // fill it in a randomized fashion
   for (ShardRouting shardRouting : shuffler.shuffle(activeShards)) {
     ordered.add(shardRouting);
     if (nodeId.equals(shardRouting.currentNodeId())) {
       // switch, its the matching node id
       ordered.set(ordered.size() - 1, ordered.get(0));
       ordered.set(0, shardRouting);
     }
   }
   if (!allInitializingShards.isEmpty()) {
     ordered.addAll(allInitializingShards);
   }
   return new PlainShardIterator(shardId, ordered);
 }
 /**
  * Adds a submenu containing a given list of actions. The menu is only added if there is at least
  * one visible action in the list.
  *
  * @param imageDescriptor
  */
 private void addSubmenu(
     IMenuManager parent,
     String label,
     ImageDescriptor imageDescriptor,
     ImmutableList<IAction> actions) {
   if (actions != null && !actions.isEmpty()) {
     boolean notEmpty = false;
     MenuManager submenu = new MenuManager(label);
     for (IAction a : actions) {
       notEmpty |= addVisible(submenu, a);
     }
     if (notEmpty) {
       submenu.setImageDescriptor(imageDescriptor);
       parent.add(submenu);
     }
   }
 }
 private StageSpec(
     int stageNum,
     StageFormat format,
     ImmutableList<RoundSpec> rounds,
     int playerLimit,
     ImmutableSet<TPlayer> excludedPlayers) {
   Preconditions.checkArgument(stageNum >= 0);
   Preconditions.checkNotNull(format);
   Preconditions.checkArgument(!rounds.isEmpty());
   Preconditions.checkArgument(playerLimit > 0, "Player cutoff must be positive if present");
   format.validateRounds(rounds);
   this.stageNum = stageNum;
   this.format = format;
   this.rounds = rounds;
   this.playerLimit = playerLimit;
   this.excludedPlayers = excludedPlayers;
 }