use of com.twitter.heron.spi.statefulstorage.Checkpoint in project incubator-heron by apache.
the class CheckpointManagerServer method handleGetInstanceStateRequest.
protected void handleGetInstanceStateRequest(REQID rid, SocketChannel channel, CheckpointManager.GetInstanceStateRequest request) {
LOG.info(String.format("Got a get checkpoint request for checkpointId %s " + " component %s taskId %d on connection %s", request.getCheckpointId(), request.getInstance().getInfo().getComponentName(), request.getInstance().getInfo().getTaskId(), channel.socket().getRemoteSocketAddress()));
CheckpointManager.GetInstanceStateResponse.Builder responseBuilder = CheckpointManager.GetInstanceStateResponse.newBuilder();
responseBuilder.setInstance(request.getInstance());
responseBuilder.setCheckpointId(request.getCheckpointId());
String errorMessage = "";
Common.StatusCode statusCode = Common.StatusCode.OK;
if (!request.hasCheckpointId() || request.getCheckpointId().isEmpty()) {
LOG.info("The checkpoint id was empty, this sending empty state");
CheckpointManager.InstanceStateCheckpoint dummyState = CheckpointManager.InstanceStateCheckpoint.newBuilder().setCheckpointId(request.getCheckpointId()).setState(ByteString.EMPTY).build();
responseBuilder.setCheckpoint(dummyState);
} else {
try {
Checkpoint checkpoint = statefulStorage.restore(topologyName, request.getCheckpointId(), request.getInstance());
LOG.info(String.format("Get checkpoint successful for checkpointId %s " + "component %s taskId %d", checkpoint.getCheckpointId(), checkpoint.getComponent(), checkpoint.getTaskId()));
// Set the checkpoint-state in response
responseBuilder.setCheckpoint(checkpoint.getCheckpoint());
} catch (StatefulStorageException e) {
errorMessage = String.format("Get checkpoint not successful for checkpointId %s " + "component %s taskId %d", request.getCheckpointId(), request.getInstance().getInfo().getComponentName(), request.getInstance().getInfo().getTaskId());
LOG.log(Level.WARNING, errorMessage, e);
statusCode = Common.StatusCode.NOTOK;
}
}
responseBuilder.setStatus(Common.Status.newBuilder().setStatus(statusCode).setMessage(errorMessage));
sendResponse(rid, channel, responseBuilder.build());
}
use of com.twitter.heron.spi.statefulstorage.Checkpoint in project incubator-heron by apache.
the class DlogStorage method restore.
@Override
public Checkpoint restore(String topologyName, String checkpointId, PhysicalPlans.Instance instanceInfo) throws StatefulStorageException {
String checkpointPath = getCheckpointPath(topologyName, checkpointId, instanceInfo.getInfo().getComponentName(), instanceInfo.getInfo().getTaskId());
InputStream in = null;
CheckpointManager.InstanceStateCheckpoint state;
try {
in = openInputStream(checkpointPath);
state = CheckpointManager.InstanceStateCheckpoint.parseFrom(in);
} catch (IOException ioe) {
throw new StatefulStorageException("Failed to read checkpoint from " + checkpointPath, ioe);
} finally {
SysUtils.closeIgnoringExceptions(in);
}
return new Checkpoint(topologyName, instanceInfo, state);
}
use of com.twitter.heron.spi.statefulstorage.Checkpoint in project incubator-heron by apache.
the class DlogStorageTest method testRestore.
@Test
public void testRestore() throws Exception {
Checkpoint restoreCheckpoint = new Checkpoint(StatefulStorageTestContext.TOPOLOGY_NAME, instance, instanceStateCheckpoint);
InputStream mockInputStream = mock(InputStream.class);
doReturn(mockInputStream).when(dlogStorage).openInputStream(anyString());
PowerMockito.spy(CheckpointManager.InstanceStateCheckpoint.class);
PowerMockito.doReturn(instanceStateCheckpoint).when(CheckpointManager.InstanceStateCheckpoint.class, "parseFrom", mockInputStream);
dlogStorage.restore(StatefulStorageTestContext.TOPOLOGY_NAME, StatefulStorageTestContext.CHECKPOINT_ID, instance);
assertEquals(restoreCheckpoint.getCheckpoint(), instanceStateCheckpoint);
}
use of com.twitter.heron.spi.statefulstorage.Checkpoint in project incubator-heron by apache.
the class DlogStorageTest method testStore.
@Test
public void testStore() throws Exception {
PowerMockito.mockStatic(CheckpointManager.InstanceStateCheckpoint.class);
CheckpointManager.InstanceStateCheckpoint mockCheckpointState = mock(CheckpointManager.InstanceStateCheckpoint.class);
Checkpoint checkpoint = new Checkpoint(StatefulStorageTestContext.TOPOLOGY_NAME, instance, mockCheckpointState);
DistributedLogManager mockDLM = mock(DistributedLogManager.class);
when(mockNamespace.openLog(anyString())).thenReturn(mockDLM);
AppendOnlyStreamWriter mockWriter = mock(AppendOnlyStreamWriter.class);
when(mockDLM.getAppendOnlyStreamWriter()).thenReturn(mockWriter);
dlogStorage.store(checkpoint);
verify(mockWriter).markEndOfStream();
verify(mockWriter).close();
}
use of com.twitter.heron.spi.statefulstorage.Checkpoint in project incubator-heron by apache.
the class LocalFileSystemStorageTest method testRestore.
@Test
public void testRestore() throws Exception {
PowerMockito.spy(FileUtils.class);
PowerMockito.doReturn(checkpoint.toByteArray()).when(FileUtils.class, "readFromFile", anyString());
Checkpoint ckpt = new Checkpoint(StatefulStorageTestContext.TOPOLOGY_NAME, instance, checkpoint);
localFileSystemStorage.restore(StatefulStorageTestContext.TOPOLOGY_NAME, StatefulStorageTestContext.CHECKPOINT_ID, instance);
assertEquals(checkpoint, ckpt.getCheckpoint());
}
Aggregations