/** {@inheritDoc} */ @Override public Collection<R> reduce(List<GridComputeJobResult> results) throws GridException { Collection<R> res = new ArrayList<>(results.size()); for (GridComputeJobResult jobRes : results) res.add(jobRes.<R>getData()); return res; }
/** {@inheritDoc} */ @Nullable @Override protected Boolean reduce0(List<GridComputeJobResult> results) throws GridException { Collection<Boolean> toggles = new HashSet<>(); for (GridComputeJobResult res: results) toggles.add(res.<Boolean>getData()); // If all nodes return same result. return toggles.size() == 1; }
/** {@inheritDoc} */ @Override public Boolean reduce(List<GridComputeJobResult> results) throws GridException { return F.first(results).getData(); } }
/** {@inheritDoc} */ @Override protected Iterable<? extends VisorGridEvent> reduce0(List<GridComputeJobResult> results) throws GridException { Collection<VisorGridEvent> allEvents = new ArrayList<>(); for (GridComputeJobResult r : results) { if (r.getException() == null) allEvents.addAll((Collection<VisorGridEvent>) r.getData()); } return allEvents.isEmpty() ? Collections.<VisorGridEvent>emptyList() : allEvents; }
/** {@inheritDoc} */ @Override public byte[] reduce(List<GridComputeJobResult> results) throws GridException { return F.first(results).getData(); }
/** {@inheritDoc} */ @Override public final Collection<?> reduce(List<GridComputeJobResult> results) throws GridException { assert results.size() >= 1; Collection<Object> data = new ArrayList<>(results.size()); for (GridComputeJobResult res : results) { if (res.getException() != null) throw res.getException(); data.add(res.getData()); } return data; }
/** {@inheritDoc} */ @Nullable @Override protected Map<UUID, GridBiTuple<Long, Long>> reduce0(List<GridComputeJobResult> results) throws GridException { Map<UUID, GridBiTuple<Long, Long>> total = new HashMap<>(); for (GridComputeJobResult res: results) { GridBiTuple<Long, Long> jobRes = res.getData(); total.put(res.getNode().id(), jobRes); } return total; }
/** {@inheritDoc} */ @Override public final Object reduce(List<GridComputeJobResult> results) throws GridException { assert results.size() == 1; GridComputeJobResult res = results.get(0); if (res.getException() != null) throw res.getException(); return res.getData(); } }
/** {@inheritDoc} */ @Override public R reduce(List<GridComputeJobResult> res) throws GridException { for (GridComputeJobResult r : res) { if (r.getException() == null) return r.getData(); } throw new GridException("Failed to find successful job result: " + res); } }
/** {@inheritDoc} */ @Override public R reduce(List<GridComputeJobResult> res) throws GridException { for (GridComputeJobResult r : res) if (r.getException() == null) return r.getData(); throw new GridException("Failed to find successful job result: " + res); } }
/** {@inheritDoc} */ @Nullable @Override protected Iterable<GridBiTuple<UUID, VisorLicense>> reduce0(List<GridComputeJobResult> results) throws GridException { Collection<GridBiTuple<UUID, VisorLicense>> licenses = new ArrayList<>(results.size()); for (GridComputeJobResult r : results) { VisorLicense license = r.getException() != null ? null : (VisorLicense) r.getData(); licenses.add(new GridBiTuple<>(r.getNode().id(), license)); } return licenses; }
/** {@inheritDoc} */ @Override public R reduce(List<GridComputeJobResult> res) throws GridException { for (GridComputeJobResult r : res) if (r.getException() == null) return r.getData(); throw new GridException("Failed to find successful job result: " + res); } }
/** {@inheritDoc} */ @Nullable @Override protected R reduce0(List<GridComputeJobResult> results) throws GridException { assert results.size() == 1; GridComputeJobResult res = F.first(results); if (res.getException() == null) return res.getData(); throw res.getException(); } }
/** {@inheritDoc} */ @Nullable @Override protected GridBiTuple<Iterable<GridBiTuple<Exception, UUID>>, Iterable<VisorLogSearchResult>> reduce0(List<GridComputeJobResult> results) throws GridException { Collection<VisorLogSearchResult> searchRes = new ArrayList<>(); Collection<GridBiTuple<Exception, UUID>> exRes = new ArrayList<>(); // Separate successfully executed results and exceptions. for (GridComputeJobResult result : results) { if (result.getException() != null) exRes.add(new GridBiTuple<Exception, UUID>(result.getException(), result.getNode().id())); else if(result.getData() != null) { Collection<VisorLogSearchResult> data = result.getData(); searchRes.addAll(data); } } return new GridBiTuple<Iterable<GridBiTuple<Exception, UUID>>, Iterable<VisorLogSearchResult>> (exRes.isEmpty() ? null : exRes, searchRes.isEmpty() ? null : searchRes); } /**
/** {@inheritDoc} */ @Nullable @Override public GridBiTuple<Long, Long> reduce(List<GridComputeJobResult> results) throws GridException { long used = 0; long max = 0; for (GridComputeJobResult res : results) { GridBiTuple<Long, Long> data = res.getData(); if (data != null) { used += data.get1(); max += data.get2(); } } return F.t(used, max); }
/** {@inheritDoc} */ @Nullable @Override public GridBiTuple<Long, Long> reduce(List<GridComputeJobResult> results) throws GridException { long used = 0; long max = 0; for (GridComputeJobResult res : results) { GridBiTuple<Long, Long> data = res.getData(); if (data != null) { used += data.get1(); max += data.get2(); } } return F.t(used, max); }
/** {@inheritDoc} */ @Override public GridComputeJobResultPolicy result(GridComputeJobResult res, List<GridComputeJobResult> rcvd) throws GridException { GridComputeJobResultPolicy resPlc = super.result(res, rcvd); if (res.getException() == null && resPlc != FAILOVER && !rdc.collect((R1) res.getData())) resPlc = REDUCE; // If reducer returned false - reduce right away. return resPlc; }
/** {@inheritDoc} */ @Override public GridComputeJobResultPolicy result(GridComputeJobResult res, List<GridComputeJobResult> rcvd) throws GridException { // No failover for this task. if (res.getException() != null) throw res.getException(); rdc.collect(res.<R1>getData()); return GridComputeJobResultPolicy.WAIT; }
/** {@inheritDoc} */ @Override public GridComputeJobResultPolicy result(GridComputeJobResult res, List<GridComputeJobResult> rcvd) throws GridException { GridComputeJobResultPolicy resPlc = super.result(res, rcvd); if (res.getException() == null && resPlc != FAILOVER && !t.get3().collect((R1)res.getData())) resPlc = REDUCE; // If reducer returned false - reduce right away. return resPlc; }
/** {@inheritDoc} */ @Override public byte[] reduce(List<GridComputeJobResult> results) throws GridException { byte status; byte[] bytes; GridComputeJobResult res = F.first(results); if (res.getException() == null) { status = 0; bytes = MARSHALLER.marshal(res.getData()); } else { status = 1; bytes = MARSHALLER.marshal(new SQLException(res.getException().getMessage())); } byte[] packet = new byte[bytes.length + 1]; packet[0] = status; U.arrayCopy(bytes, 0, packet, 1, bytes.length); return packet; }