@Override public void cancel() throws IOException { if (!DomainVersions.isClosed(this)) { try { zk.deleteNodeRecursively(path); } catch (Exception e) { throw new IOException(e); } } }
protected DomainVersionData getDomainVersionData(DomainVersion version) throws IOException { DomainVersionData data = new DomainVersionData(); data.versionNumber = version.getVersionNumber(); data.totalNumBytes = DomainVersions.getTotalNumBytes(version); data.totalNumRecords = DomainVersions.getTotalNumRecords(version); data.isClosed = DomainVersions.isClosed(version); data.closedAt = version.getClosedAt(); data.properties = version.getProperties(); data.isDefunct = version.isDefunct(); return data; }
public static long getTotalNumBytes(Domain domain) throws IOException { long total = 0; for (DomainVersion version : domain.getVersions()) { if (version.isDefunct()) { continue; } total += DomainVersions.getTotalNumBytes(version); } return total; }
@Override public String toString() { Boolean isClosed; Boolean isDefunct; try { isClosed = DomainVersions.isClosed(this); } catch (IOException e) { isClosed = null; } try { isDefunct = isDefunct(); } catch (IOException e) { isDefunct = null; } return "AbstractDomainVersion [" + "version=" + getVersionNumber() + ", closed=" + isClosed + ", defunct=" + isDefunct + "]"; } }
if (!DomainVersions.isClosed(parentVersion)) { throw new IOException("Detected a domain version that is still open" + " along the path from current version to version to update to: "
if (DomainVersions.isClosed(version)) { sortedVersions.add(version);
private static boolean allDeltasComplete(DomainVersion version, Domain domain) throws IOException { if(version == null){ return true; } if (isBase(version)) { return true; } if (!DomainVersions.isClosed(version)) { return false; } IncrementalDomainVersionProperties properties = (IncrementalDomainVersionProperties)version.getProperties(); return allDeltasComplete( domain.getVersion(properties.getParentVersionNumber()), domain ); }
private static boolean isCompleteToBase(DomainVersion version, Domain domain) throws IOException { if(version == null){ return true; } if (!DomainVersions.isClosed(version)) { return false; } if (isBase(version)) { return !version.isDefunct(); } // TODO is there ever going to be a different impl of props? IncrementalDomainVersionProperties properties = (IncrementalDomainVersionProperties)version.getProperties(); return isCompleteToBase( domain.getVersion(properties.getParentVersionNumber()), domain ); }
@Test public void testCloseVersion() throws Exception { final DomainVersion dv = ZkDomainVersion.create(getZk(), getRoot(), 1, null, null); assertEquals(1, dv.getVersionNumber()); assertNull(dv.getClosedAt()); assertFalse(DomainVersions.isClosed(dv)); dv.close(); WaitUntil.orDie(() -> { try { return dv.getClosedAt() != null; } catch (IOException e) { throw new RuntimeException(e); } }); assertNotNull(dv.getClosedAt()); assertTrue(DomainVersions.isClosed(dv)); }
@Test public void testCreate() throws Exception { DomainVersion dv = ZkDomainVersion.create(getZk(), getRoot(), 1, null, null); assertEquals(1, dv.getVersionNumber()); assertNull(dv.getClosedAt()); assertFalse(DomainVersions.isClosed(dv)); assertFalse(dv.isDefunct()); }
@Test public void testLoad() throws Exception { ZkDomainVersion.create(getZk(), getRoot(), 1, null, null); DomainVersion dv = new ZkDomainVersion(getZk(), ZkPath.append(getRoot(), "v/" + 1), null); assertEquals(1, dv.getVersionNumber()); assertNull(dv.getClosedAt()); assertFalse(DomainVersions.isClosed(dv)); assertFalse(dv.isDefunct()); }
@Test public void testCancelVersion() throws Exception { DomainVersion dv = ZkDomainVersion.create(getZk(), getRoot(), 1, null, null); assertEquals(1, dv.getVersionNumber()); assertNull(dv.getClosedAt()); assertFalse(DomainVersions.isClosed(dv)); dv.cancel(); assertNull(getZk().exists(ZkPath.append(getRoot(), "v/1"), false)); }