@Override public void run(Coordinator coordinator) throws IOException { DomainVersion domainVersion = getDomainVersion(coordinator, domainName, domainVersionNumber); LOG.info("Closing new version #" + domainVersion.getVersionNumber() + " of domain: " + domainName); domainVersion.close(); } }
@Override protected void action(HttpServletRequest req, HttpServletResponse resp) throws IOException { Domain domain = DomainController.this.coordinator.getDomain(req.getParameter("n")); final DomainVersion domainVersion = domain.getVersion(Integer.parseInt(req.getParameter("ver"))); domainVersion.setDefunct(false); redirect("/domain.jsp?n=" + req.getParameter("n"), resp); } });
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; }
@Override public void run(Coordinator coordinator) throws IOException { DomainVersion domainVersion = getDomainVersion(coordinator, domainName, domainVersionNumber); LOG.info("Cancelling new version #" + domainVersion.getVersionNumber() + " of domain: " + domainName); domainVersion.cancel(); } }
protected DomainVersion findVersion(Collection<DomainVersion> versions, int versionNumber) throws IOException { for (DomainVersion v : versions) { if (v != null && v.getVersionNumber() == versionNumber) { return v; } } return null; }
@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()); }
LOG.info("Keeping Version " + version.getVersionNumber() + " of Domain " + domain.getName()); if (!version.isDefunct()) { LOG.info("Deleting Version " + version.getVersionNumber() + " of Domain " + domain.getName()); version.setDefunct(true); remoteDomainVersionDeleter.deleteVersion(version.getVersionNumber()); domain.deleteVersion(version.getVersionNumber());
@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 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)); }
@Override protected void action(HttpServletRequest req, HttpServletResponse resp) throws IOException { Domain domain = DomainController.this.coordinator.getDomain(req.getParameter("n")); for (DomainVersion domainVersion : domain.getVersions()) { if (domainVersion.isDefunct()) { domain.deleteVersion(domainVersion.getVersionNumber()); } } redirect("/domain.jsp?n=" + req.getParameter("n"), resp); } });
@Test public void testDefunct() throws Exception { final DomainVersion dv = ZkDomainVersion.create(getZk(), getRoot(), 1, null, null); final DomainVersion otherDv = new ZkDomainVersion(getZk(), ZkPath.append(getRoot(), "v/1"), null); assertFalse(dv.isDefunct()); assertFalse(otherDv.isDefunct()); dv.setDefunct(true); WaitUntil.orDie(() -> { try { return dv.isDefunct() && otherDv.isDefunct(); } catch (IOException e) { throw new RuntimeException(e); } }); assertTrue(dv.isDefunct()); assertTrue(otherDv.isDefunct()); dv.setDefunct(false); WaitUntil.orDie(() -> { try { return !dv.isDefunct() && !otherDv.isDefunct(); } catch (IOException e) { throw new RuntimeException(e); } }); assertFalse(dv.isDefunct()); assertFalse(otherDv.isDefunct()); }
public static DomainVersion getParentDomainVersion(Domain domain, DomainVersion version) throws IOException { IncrementalDomainVersionProperties properties = (IncrementalDomainVersionProperties)version.getProperties(); if (properties == null) { throw new IOException("Failed to get parent of Domain Version since corresponding properties are empty: " + version); } else { Integer parentVersionNumber = properties.getParentVersionNumber(); if (parentVersionNumber == null) { return null; } else { DomainVersion result = domain.getVersion(parentVersionNumber); if (result == null) { throw new IOException("Failed to get parent Domain Version since specified parent version number (" + parentVersionNumber + ") of version " + version.getVersionNumber() + " of Domain " + domain.getName() + " does not correspond to any version."); } return result; } } }
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 ); }
@Override protected void action(HttpServletRequest req, HttpServletResponse resp) throws IOException { Domain domain = DomainController.this.coordinator.getDomain(req.getParameter("n")); final DomainVersion domainVersion = domain.getVersion(Integer.parseInt(req.getParameter("ver"))); domainVersion.close(); redirect("/domain.jsp?n=" + req.getParameter("n"), resp); } });
private IncrementalDomainVersionProperties getDomainVersionProperties(DomainVersion domainVersion) throws IOException { IncrementalDomainVersionProperties result; try { result = (IncrementalDomainVersionProperties)domainVersion.getProperties(); } catch (ClassCastException e) { throw new IOException("Failed to load properties of version " + domainVersion); } if (result == null) { throw new IOException("Null properties for version " + domainVersion); } return result; }
@Test public void testPartitionMetadata() throws Exception { final DomainVersion dv = ZkDomainVersion.create(getZk(), getRoot(), 1, null, null); final DomainVersion dv2 = new ZkDomainVersion(getZk(), ZkPath.append(getRoot(), "v/1"), null); assertTrue(dv.getPartitionsMetadata().isEmpty()); assertTrue(dv2.getPartitionsMetadata().isEmpty()); dv.addPartitionProperties(1, 2, 3); WaitUntil.orDie(() -> { try { return dv.getPartitionsMetadata().size() == 1 && dv2.getPartitionsMetadata().size() == 1; } catch (IOException e) { throw new RuntimeException(e); } }); assertEquals(1, dv.getPartitionsMetadata().size()); assertEquals(1, dv2.getPartitionsMetadata().size()); PartitionMetadata metadata = dv.getPartitionsMetadata().iterator().next(); assertEquals(2, metadata.get_num_bytes()); assertEquals(3, metadata.get_num_records()); }
public static boolean isClosed(DomainVersion domainVersion) throws IOException { return domainVersion.getClosedAt() != null; }
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; }
public static long getTotalNumBytes(DomainVersion domainVersion) throws IOException { long total = 0; for (PartitionMetadata pm : domainVersion.getPartitionsMetadata()) { total += pm.get_num_bytes(); } return total; }
@Override public void run(Coordinator coordinator) throws IOException { DomainVersion domainVersion = DomainBuilderProperties.getDomainVersion(coordinator, domainName, domainVersionNumber); domainVersion.addPartitionProperties(writerPartition, writer.getNumBytesWritten(), writer.getNumRecordsWritten()); } });