Search in sources :

Example 1 with CheckpointInfo

use of org.apache.heron.spi.statefulstorage.CheckpointInfo in project heron by twitter.

the class CheckpointManagerServer method handleSaveInstanceStateRequest.

protected void handleSaveInstanceStateRequest(REQID rid, SocketChannel channel, CheckpointManager.SaveInstanceStateRequest request) {
    CheckpointInfo info = new CheckpointInfo(request.getCheckpoint().getCheckpointId(), request.getInstance());
    Checkpoint checkpoint;
    if (request.getCheckpoint().hasStateLocation()) {
        checkpoint = loadCheckpoint(request.getInstance(), request.getCheckpoint().getCheckpointId(), request.getCheckpoint().getStateLocation());
    } else {
        checkpoint = new Checkpoint(request.getCheckpoint());
    }
    LOG.info(String.format("Got a save checkpoint request for checkpointId %s " + " component %s instanceId %s on connection %s", info.getCheckpointId(), info.getComponent(), info.getInstanceId(), channel.socket().getRemoteSocketAddress()));
    Common.StatusCode statusCode = Common.StatusCode.OK;
    String errorMessage = "";
    try {
        statefulStorage.storeCheckpoint(info, checkpoint);
        LOG.info(String.format("Saved checkpoint for checkpointId %s compnent %s instanceId %s", info.getCheckpointId(), info.getComponent(), info.getInstanceId()));
    } catch (StatefulStorageException e) {
        errorMessage = String.format("Save checkpoint not successful for checkpointId " + "%s component %s instanceId %s", info.getCheckpointId(), info.getComponent(), info.getInstanceId());
        statusCode = Common.StatusCode.NOTOK;
        LOG.log(Level.WARNING, errorMessage, e);
    }
    CheckpointManager.SaveInstanceStateResponse.Builder responseBuilder = CheckpointManager.SaveInstanceStateResponse.newBuilder();
    responseBuilder.setStatus(Common.Status.newBuilder().setStatus(statusCode).setMessage(errorMessage));
    responseBuilder.setCheckpointId(request.getCheckpoint().getCheckpointId());
    responseBuilder.setInstance(request.getInstance());
    sendResponse(rid, channel, responseBuilder.build());
}
Also used : StatefulStorageException(org.apache.heron.spi.statefulstorage.StatefulStorageException) Checkpoint(org.apache.heron.spi.statefulstorage.Checkpoint) ByteString(com.google.protobuf.ByteString) CheckpointInfo(org.apache.heron.spi.statefulstorage.CheckpointInfo) Common(org.apache.heron.proto.system.Common)

Example 2 with CheckpointInfo

use of org.apache.heron.spi.statefulstorage.CheckpointInfo in project heron by twitter.

the class CheckpointManagerServerTest method testGetInstanceState.

@Test
public void testGetInstanceState() throws Exception {
    final CheckpointInfo info = new CheckpointInfo(CHECKPOINT_ID, instance);
    final Checkpoint checkpoint = new Checkpoint(checkpointPartition);
    when(statefulStorage.restoreCheckpoint(any(CheckpointInfo.class))).thenReturn(checkpoint);
    runTest(TestRequestHandler.RequestType.GET_INSTANCE_STATE, new HeronServerTester.SuccessResponseHandler(CheckpointManager.GetInstanceStateResponse.class, new HeronServerTester.TestResponseHandler() {

        @Override
        public void handleResponse(HeronClient client, StatusCode status, Object ctx, Message response) throws Exception {
            verify(statefulStorage).restoreCheckpoint(info);
            assertEquals(checkpoint.getCheckpoint(), ((CheckpointManager.GetInstanceStateResponse) response).getCheckpoint());
        }
    }));
}
Also used : Checkpoint(org.apache.heron.spi.statefulstorage.Checkpoint) HeronClient(org.apache.heron.common.network.HeronClient) Message(com.google.protobuf.Message) CheckpointManager(org.apache.heron.proto.ckptmgr.CheckpointManager) CheckpointInfo(org.apache.heron.spi.statefulstorage.CheckpointInfo) HeronServerTester(org.apache.heron.common.testhelpers.HeronServerTester) StatusCode(org.apache.heron.common.network.StatusCode) Test(org.junit.Test)

Example 3 with CheckpointInfo

use of org.apache.heron.spi.statefulstorage.CheckpointInfo in project heron by twitter.

the class HDFSStorageTest method testRestore.

@Test
public void testRestore() throws Exception {
    FSDataInputStream mockFSDataInputStream = mock(FSDataInputStream.class);
    when(mockFileSystem.open(any(Path.class))).thenReturn(mockFSDataInputStream);
    PowerMockito.spy(CheckpointManager.InstanceStateCheckpoint.class);
    PowerMockito.doReturn(instanceCheckpointState).when(CheckpointManager.InstanceStateCheckpoint.class, "parseFrom", mockFSDataInputStream);
    final CheckpointInfo info = new CheckpointInfo(StatefulStorageTestContext.CHECKPOINT_ID, instance);
    Checkpoint restoreCheckpoint = hdfsStorage.restoreCheckpoint(info);
    assertEquals(restoreCheckpoint.getCheckpoint(), instanceCheckpointState);
}
Also used : Path(org.apache.hadoop.fs.Path) Checkpoint(org.apache.heron.spi.statefulstorage.Checkpoint) CheckpointManager(org.apache.heron.proto.ckptmgr.CheckpointManager) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) CheckpointInfo(org.apache.heron.spi.statefulstorage.CheckpointInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with CheckpointInfo

use of org.apache.heron.spi.statefulstorage.CheckpointInfo in project heron by twitter.

the class HDFSStorageTest method testStore.

@Test
public void testStore() throws Exception {
    PowerMockito.mockStatic(CheckpointManager.InstanceStateCheckpoint.class);
    CheckpointManager.InstanceStateCheckpoint mockCheckpointState = mock(CheckpointManager.InstanceStateCheckpoint.class);
    Checkpoint checkpoint = new Checkpoint(mockCheckpointState);
    FSDataOutputStream mockFSDateOutputStream = mock(FSDataOutputStream.class);
    when(mockFileSystem.create(any(Path.class))).thenReturn(mockFSDateOutputStream);
    doNothing().when(hdfsStorage).createDir(anyString());
    final CheckpointInfo info = new CheckpointInfo(StatefulStorageTestContext.CHECKPOINT_ID, instance);
    hdfsStorage.storeCheckpoint(info, checkpoint);
    verify(mockCheckpointState).writeTo(mockFSDateOutputStream);
}
Also used : Path(org.apache.hadoop.fs.Path) Checkpoint(org.apache.heron.spi.statefulstorage.Checkpoint) CheckpointManager(org.apache.heron.proto.ckptmgr.CheckpointManager) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) CheckpointInfo(org.apache.heron.spi.statefulstorage.CheckpointInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with CheckpointInfo

use of org.apache.heron.spi.statefulstorage.CheckpointInfo in project heron by twitter.

the class DlogStorageTest method testStore.

@Test
public void testStore() throws Exception {
    PowerMockito.mockStatic(CheckpointManager.InstanceStateCheckpoint.class);
    CheckpointManager.InstanceStateCheckpoint mockCheckpointState = mock(CheckpointManager.InstanceStateCheckpoint.class);
    final CheckpointInfo info = new CheckpointInfo(StatefulStorageTestContext.CHECKPOINT_ID, instance);
    Checkpoint checkpoint = new Checkpoint(mockCheckpointState);
    DistributedLogManager mockDLM = mock(DistributedLogManager.class);
    when(mockNamespace.openLog(anyString())).thenReturn(mockDLM);
    AppendOnlyStreamWriter mockWriter = mock(AppendOnlyStreamWriter.class);
    when(mockDLM.getAppendOnlyStreamWriter()).thenReturn(mockWriter);
    dlogStorage.storeCheckpoint(info, checkpoint);
    verify(mockWriter).markEndOfStream();
    verify(mockWriter).close();
}
Also used : Checkpoint(org.apache.heron.spi.statefulstorage.Checkpoint) CheckpointManager(org.apache.heron.proto.ckptmgr.CheckpointManager) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) AppendOnlyStreamWriter(org.apache.distributedlog.AppendOnlyStreamWriter) CheckpointInfo(org.apache.heron.spi.statefulstorage.CheckpointInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Checkpoint (org.apache.heron.spi.statefulstorage.Checkpoint)9 CheckpointInfo (org.apache.heron.spi.statefulstorage.CheckpointInfo)9 Test (org.junit.Test)7 CheckpointManager (org.apache.heron.proto.ckptmgr.CheckpointManager)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 ByteString (com.google.protobuf.ByteString)2 Path (org.apache.hadoop.fs.Path)2 InstanceStateCheckpoint (org.apache.heron.proto.ckptmgr.CheckpointManager.InstanceStateCheckpoint)2 Common (org.apache.heron.proto.system.Common)2 StatefulStorageException (org.apache.heron.spi.statefulstorage.StatefulStorageException)2 Message (com.google.protobuf.Message)1 AppendOnlyStreamWriter (org.apache.distributedlog.AppendOnlyStreamWriter)1 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 HeronClient (org.apache.heron.common.network.HeronClient)1 StatusCode (org.apache.heron.common.network.StatusCode)1 HeronServerTester (org.apache.heron.common.testhelpers.HeronServerTester)1 DLInputStream (org.apache.heron.dlog.DLInputStream)1