@Override public void publish(HollowProducer.Blob blob) { Path destination = null; switch(blob.getType()) { case SNAPSHOT: destination = blobStorePath.resolve(String.format("%s-%d", blob.getType().prefix, blob.getToVersion())); break; case DELTA: case REVERSE_DELTA: destination = blobStorePath.resolve(String.format("%s-%d-%d", blob.getType().prefix, blob.getFromVersion(), blob.getToVersion())); break; } try( InputStream is = blob.newInputStream(); OutputStream os = Files.newOutputStream(destination) ) { byte buf[] = new byte[4096]; int n; while (-1 != (n = is.read(buf))) os.write(buf, 0, n); } catch(IOException e) { throw new RuntimeException("Unable to publish file!", e); } } }
@Override public void publish(Blob blob) { File blobFile = blob.getFile(); if (!blobFile.exists()) throw new RuntimeException("File does not existis: " + blobFile); if (!blob.getType().equals(Type.SNAPSHOT)) { return; // Only snapshot is needed for smoke Test } // Copy file File copiedFile = new File(tmpFolder, "copied_" + blobFile.getName()); try { Files.copy(blobFile.toPath(), copiedFile.toPath()); } catch (IOException e) { throw new RuntimeException("Failed to publish:" + copiedFile, e); } blobMap.put(blob.getToVersion(), blob); blobFileMap.put(blob.getToVersion(), copiedFile); System.out.println("Published:" + copiedFile); } }
public void updateBlobTypeMetrics(Status status, HollowProducer.Blob blob) { HollowProducer.Blob.Type blobType = blob.getType(); switch (blobType) { case SNAPSHOT: if(status.getType() == Status.StatusType.SUCCESS) snapshotsCompleted++; else snapshotsFailed++; break; case DELTA: if(status.getType() == Status.StatusType.SUCCESS) deltasCompleted++; else deltasFailed++; break; case REVERSE_DELTA: if(status.getType() == Status.StatusType.SUCCESS) reverseDeltasCompleted++; else reverseDeltasFailed++; break; } }
private void stageBlob(long toVersion, Artifacts artifacts, Blob.Type blobType) throws IOException { HollowBlobWriter writer = new HollowBlobWriter(getWriteEngine()); switch (blobType) { case SNAPSHOT: artifacts.snapshot = blobStager.openSnapshot(toVersion); artifacts.snapshot.write(writer); break; case DELTA: artifacts.delta = blobStager.openDelta(readStates.current().getVersion(), toVersion); artifacts.delta.write(writer); break; case REVERSE_DELTA: artifacts.reverseDelta = blobStager.openReverseDelta(toVersion, readStates.current().getVersion()); artifacts.reverseDelta.write(writer); break; default: throw new IllegalStateException("unknown type, type=" + blobType); } }
@Override public void publish(final HollowProducer.Blob blob) { Blob consumerBlob = new Blob(blob.getFromVersion(), blob.getToVersion()) { @Override public InputStream getInputStream() throws IOException { return blob.newInputStream(); } }; switch(blob.getType()) { case SNAPSHOT: snapshots.put(blob.getToVersion(), consumerBlob); break; case DELTA: deltas.put(blob.getFromVersion(), consumerBlob); break; case REVERSE_DELTA: reverseDeltas.put(blob.getFromVersion(), consumerBlob); break; } }
private void readSnapshot(Blob blob, HollowReadStateEngine stateEngine) throws IOException { try (InputStream is = blob.newInputStream()) { new HollowBlobReader(stateEngine, new HollowBlobHeaderReader()).readSnapshot(is); } }
private void cleanupSnapshot() { if (cleanupCalled && snapshotPublishComplete && snapshot != null) { snapshot.cleanup(); snapshot = null; } }
@Override public InputStream getInputStream() throws IOException { return blob.newInputStream(); } };
private void applyDelta(Blob blob, HollowReadStateEngine stateEngine) throws IOException { try (InputStream is = blob.newInputStream()) { new HollowBlobReader(stateEngine, new HollowBlobHeaderReader()).applyDelta(is); } }