Example #1
0
  /**
   * @param part Partition.
   * @param topVer Topology version.
   * @return Primary node for given key.
   */
  @Nullable
  public GridNode primary(int part, long topVer) {
    Collection<GridNode> nodes = nodes(part, topVer);

    if (nodes.isEmpty()) return null;

    return nodes.iterator().next();
  }
Example #2
0
  /**
   * @param part Partition.
   * @param topVer Topology version.
   * @return Backup nodes.
   */
  public Collection<GridNode> backups(int part, long topVer) {
    Collection<GridNode> nodes = nodes(part, topVer);

    assert !F.isEmpty(nodes);

    if (nodes.size() <= 1) return Collections.emptyList();

    return F.view(nodes, F.notEqualTo(nodes.iterator().next()));
  }
    /** {@inheritDoc} */
    @Override
    public Class<?> deployClass() {
      if (cls == null) {
        Class<?> cls0 = null;

        if (depCls != null) cls0 = depCls;
        else {
          for (Iterator<Object> it = objs.iterator();
              (cls0 == null || U.isJdk(cls0)) && it.hasNext(); ) {
            Object o = it.next();

            if (o != null) cls0 = U.detectClass(o);
          }

          if (cls0 == null || U.isJdk(cls0)) cls0 = GridDataLoaderImpl.class;
        }

        assert cls0 != null : "Failed to detect deploy class [objs=" + objs + ']';

        cls = cls0;
      }

      return cls;
    }
  /** {@inheritDoc} */
  @SuppressWarnings("all")
  @Override
  public boolean writeTo(ByteBuffer buf) {
    commState.setBuffer(buf);

    if (!super.writeTo(buf)) return false;

    if (!commState.typeWritten) {
      if (!commState.putByte(directType())) return false;

      commState.typeWritten = true;
    }

    switch (commState.idx) {
      case 2:
        if (dataBytes != null) {
          if (commState.it == null) {
            if (!commState.putInt(dataBytes.size())) return false;

            commState.it = dataBytes.iterator();
          }

          while (commState.it.hasNext() || commState.cur != NULL) {
            if (commState.cur == NULL) commState.cur = commState.it.next();

            if (!commState.putByteArray((byte[]) commState.cur)) return false;

            commState.cur = NULL;
          }

          commState.it = null;
        } else {
          if (!commState.putInt(-1)) return false;
        }

        commState.idx++;

      case 3:
        if (!commState.putByteArray(errBytes)) return false;

        commState.idx++;

      case 4:
        if (!commState.putBoolean(fields)) return false;

        commState.idx++;

      case 5:
        if (!commState.putBoolean(finished)) return false;

        commState.idx++;

      case 6:
        if (metaDataBytes != null) {
          if (commState.it == null) {
            if (!commState.putInt(metaDataBytes.size())) return false;

            commState.it = metaDataBytes.iterator();
          }

          while (commState.it.hasNext() || commState.cur != NULL) {
            if (commState.cur == NULL) commState.cur = commState.it.next();

            if (!commState.putByteArray((byte[]) commState.cur)) return false;

            commState.cur = NULL;
          }

          commState.it = null;
        } else {
          if (!commState.putInt(-1)) return false;
        }

        commState.idx++;

      case 7:
        commState.idx++;

      case 8:
        if (!commState.putLong(reqId)) return false;

        commState.idx++;
    }

    return true;
  }
  /** @throws Exception If failed. */
  public void testEmptyProjections() throws Exception {
    final GridClientCompute dflt = client.compute();

    Collection<? extends GridClientNode> nodes = dflt.nodes();

    assertEquals(NODES_CNT, nodes.size());

    Iterator<? extends GridClientNode> iter = nodes.iterator();

    final GridClientCompute singleNodePrj = dflt.projection(Collections.singletonList(iter.next()));

    final GridClientNode second = iter.next();

    final GridClientPredicate<GridClientNode> noneFilter =
        new GridClientPredicate<GridClientNode>() {
          @Override
          public boolean apply(GridClientNode node) {
            return false;
          }
        };

    final GridClientPredicate<GridClientNode> targetFilter =
        new GridClientPredicate<GridClientNode>() {
          @Override
          public boolean apply(GridClientNode node) {
            return node.nodeId().equals(second.nodeId());
          }
        };

    GridTestUtils.assertThrows(
        log(),
        new Callable<Object>() {
          @Override
          public Object call() throws Exception {
            return dflt.projection(noneFilter).log(-1, -1);
          }
        },
        GridServerUnreachableException.class,
        null);

    GridTestUtils.assertThrows(
        log(),
        new Callable<Object>() {
          @Override
          public Object call() throws Exception {
            return singleNodePrj.projection(second);
          }
        },
        GridClientException.class,
        null);

    GridTestUtils.assertThrows(
        log(),
        new Callable<Object>() {
          @Override
          public Object call() throws Exception {
            return singleNodePrj.projection(targetFilter);
          }
        },
        GridClientException.class,
        null);
  }