use of org.apache.distributedlog.api.namespace.Namespace in project incubator-heron by apache.
the class DlogUploaderTest method testUploadPackageLocalFileNotExist.
@Test
public void testUploadPackageLocalFileNotExist() throws Exception {
uploader = Mockito.spy(uploader);
Namespace ns = mock(Namespace.class);
when(nsBuilder.build()).thenReturn(ns);
Mockito.doReturn(false).when(uploader).isLocalFileExists(Mockito.anyString());
uploader.initialize(config);
try {
uploader.uploadPackage();
fail("Should fail on uploading package");
} catch (UploaderException ue) {
// expected
}
verify(ns, never()).logExists(anyString());
}
use of org.apache.distributedlog.api.namespace.Namespace in project incubator-heron by apache.
the class DlogUploaderTest method testUndoSuccess.
@Test
public void testUndoSuccess() throws Exception {
Namespace ns = mock(Namespace.class);
when(nsBuilder.build()).thenReturn(ns);
uploader.initialize(config);
assertTrue(uploader.undo());
verify(ns, times(1)).deleteLog(eq(uploader.getPackageName()));
}
use of org.apache.distributedlog.api.namespace.Namespace in project incubator-heron by apache.
the class DlogStorage method deleteCheckpoint.
private void deleteCheckpoint(URI checkpointUri) throws IOException {
Namespace checkpointNs = initializeNamespace(checkpointUri);
try {
Iterator<String> checkpoints = checkpointNs.getLogs();
while (checkpoints.hasNext()) {
String checkpoint = checkpoints.next();
checkpointNs.deleteLog(checkpoint);
}
} finally {
checkpointNs.close();
}
}
use of org.apache.distributedlog.api.namespace.Namespace in project incubator-heron by apache.
the class DlogStorage method dispose.
@Override
public void dispose(String topologyName, String oldestCheckpointId, boolean deleteAll) throws StatefulStorageException {
// Currently dlog doesn't support recursive deletion. so we have to fetch all the checkpoints
// and delete individual checkpoints.
// TODO (sijie): replace the logic here once distributedlog supports recursive deletion.
String topologyCheckpointRoot = getTopologyCheckpointRoot(topologyName);
URI topologyUri = URI.create(checkpointNamespaceUriStr + topologyCheckpointRoot);
// get checkpoints
Namespace topologyNs = null;
Iterator<String> checkpoints;
try {
topologyNs = initializeNamespace(topologyUri);
checkpoints = topologyNs.getLogs();
} catch (IOException ioe) {
throw new StatefulStorageException("Failed to open topology namespace", ioe);
} finally {
if (null != topologyNs) {
topologyNs.close();
}
}
while (checkpoints.hasNext()) {
String checkpointId = checkpoints.next();
if (deleteAll || checkpointId.compareTo(oldestCheckpointId) < 0) {
URI checkpointUri = URI.create(checkpointNamespaceUriStr + topologyCheckpointRoot + "/" + checkpointId);
try {
deleteCheckpoint(checkpointUri);
} catch (IOException e) {
throw new StatefulStorageException("Failed to remove checkpoint " + checkpointId + " for topology " + topologyName, e);
}
}
}
}
use of org.apache.distributedlog.api.namespace.Namespace in project incubator-heron by apache.
the class DlogStorageTest method testDiposeNone.
@Test
public void testDiposeNone() throws Exception {
Namespace mockTopoloyNs = mock(Namespace.class);
Namespace mockCheckpoint1 = mock(Namespace.class);
Namespace mockCheckpoint2 = mock(Namespace.class);
String checkpoint1 = "checkpoint1";
String checkpoint2 = "checkpoint2";
List<String> checkpoints = Lists.newArrayList(checkpoint1, checkpoint2);
List<String> chkp1Tasks = Lists.newArrayList("component1_task1", "component1_task2");
List<String> chkp2Tasks = Lists.newArrayList("component2_task1", "component2_task2");
doReturn(mockTopoloyNs).when(dlogStorage).initializeNamespace(eq(URI.create(ROOT_URI + "/" + StatefulStorageTestContext.TOPOLOGY_NAME)));
doReturn(mockCheckpoint1).when(dlogStorage).initializeNamespace(eq(URI.create(ROOT_URI + "/" + StatefulStorageTestContext.TOPOLOGY_NAME + "/checkpoint1")));
doReturn(mockCheckpoint2).when(dlogStorage).initializeNamespace(eq(URI.create(ROOT_URI + "/" + StatefulStorageTestContext.TOPOLOGY_NAME + "/checkpoint2")));
when(mockTopoloyNs.getLogs()).thenReturn(checkpoints.iterator());
when(mockCheckpoint1.getLogs()).thenReturn(chkp1Tasks.iterator());
when(mockCheckpoint2.getLogs()).thenReturn(chkp2Tasks.iterator());
dlogStorage.dispose(StatefulStorageTestContext.TOPOLOGY_NAME, "checkpoint0", false);
verify(mockCheckpoint1, times(0)).deleteLog(eq("component1_task1"));
verify(mockCheckpoint1, times(0)).deleteLog(eq("component1_task2"));
verify(mockCheckpoint2, times(0)).deleteLog(eq("component2_task1"));
verify(mockCheckpoint2, times(0)).deleteLog(eq("component2_task2"));
}
Aggregations