Example usage for org.apache.cassandra.streaming SessionInfo SessionInfo

List of usage examples for org.apache.cassandra.streaming SessionInfo SessionInfo

Introduction

In this page you can find the example usage for org.apache.cassandra.streaming SessionInfo SessionInfo.

Prototype

public SessionInfo(InetAddressAndPort peer, int sessionIndex, InetAddressAndPort connecting,
            Collection<StreamSummary> receivingSummaries, Collection<StreamSummary> sendingSummaries,
            StreamSession.State state) 

Source Link

Usage

From source file:io.cassandrareaper.service.StreamFactoryTest.java

License:Apache License

@Test
public void testCountProgressPerTableWithTable() throws UnknownHostException {
    UUID cfid = UUID.randomUUID();
    int files = 3;
    int totalSize = 2048;
    StreamSummary streamSummary = new StreamSummary(cfid, files, totalSize);

    InetAddress peer = InetAddress.getByName("127.0.0.1");
    int index = 0;
    InetAddress connecting = InetAddress.getByName("127.0.0.2");
    ImmutableSet<StreamSummary> receivingSummaries = ImmutableSet.of(streamSummary);
    ImmutableSet<StreamSummary> sendingSummaries = ImmutableSet.of();
    SessionInfo sessionInfo = new SessionInfo(peer, index, connecting, receivingSummaries, sendingSummaries,
            StreamSession.State.STREAMING);

    String file1 = "/cass/data/keyspace1/standard1-af5311f0633a11e89d71710c22f847e7/lb-4-big-Data.db";
    String file2 = "/cass/data/keyspace1/standard1-af5311f0633a11e89d71710c22f847e7/lb-5-big-Data.db";
    sessionInfo.updateProgress(new ProgressInfo(peer, index, file1, ProgressInfo.Direction.OUT, 512, 1024));
    sessionInfo.updateProgress(new ProgressInfo(peer, index, file2, ProgressInfo.Direction.OUT, 512, 1024));

    UUID planId = UUID.randomUUID();
    ImmutableSet<SessionInfo> sessionInfos = ImmutableSet.of(sessionInfo);
    StreamState streamState = new StreamState(planId, "descr", sessionInfos);

    io.cassandrareaper.core.StreamSession streamSession = StreamSessionFactory.fromStreamState(peer.toString(),
            streamState);//from w w w . j  a v a2s . c  o  m
    assertEquals(1, streamSession.getStreams().size());

    List<Stream.TableProgress> progressSent = streamSession.getStreams().values().asList().get(0)
            .getProgressSent();
    assertEquals(1, progressSent.size());

    Stream.TableProgress tableProgress = progressSent.get(0);
    assertEquals("keyspace1.standard1", tableProgress.getTable());
    assertEquals(Long.valueOf(1024), tableProgress.getCurrent());
    assertEquals(Long.valueOf(2048), tableProgress.getTotal());
}

From source file:io.cassandrareaper.service.StreamFactoryTest.java

License:Apache License

@Test
public void testCountProgressPerTableWithMultipleTables() throws UnknownHostException {
    UUID cfid = UUID.randomUUID();
    int files = 3;
    int totalSize = 2048;
    StreamSummary streamSummary = new StreamSummary(cfid, files, totalSize);

    InetAddress peer = InetAddress.getByName("127.0.0.1");
    int index = 0;
    InetAddress connecting = InetAddress.getByName("127.0.0.2");
    ImmutableSet<StreamSummary> receivingSummaries = ImmutableSet.of(streamSummary);
    ImmutableSet<StreamSummary> sendingSummaries = ImmutableSet.of();
    SessionInfo sessionInfo = new SessionInfo(peer, index, connecting, receivingSummaries, sendingSummaries,
            StreamSession.State.STREAMING);

    String file1 = "/cass/data/keyspace1/standard1-af5311f0633a11e89d71710c22f847e7/lb-4-big-Data.db";
    sessionInfo.updateProgress(new ProgressInfo(peer, index, file1, ProgressInfo.Direction.OUT, 32, 1024));
    String file2 = "/cass/data/keyspace1/standard1-af5311f0633a11e89d71710c22f847e7/lb-5-big-Data.db";
    sessionInfo.updateProgress(new ProgressInfo(peer, index, file2, ProgressInfo.Direction.OUT, 64, 1024));
    String file3 = "/cass/data/keyspace1/counter1-af5311f0633a11e89d71710c22f847e7/lb-4-big-Data.db";
    sessionInfo.updateProgress(new ProgressInfo(peer, index, file3, ProgressInfo.Direction.OUT, 512, 512));
    String file4 = "/cass/data/keyspace1/counter1-af5311f0633a11e89d71710c22f847e7/lb-5-big-Data.db";
    sessionInfo.updateProgress(new ProgressInfo(peer, index, file4, ProgressInfo.Direction.OUT, 128, 512));

    UUID planId = UUID.randomUUID();
    ImmutableSet<SessionInfo> sessionInfos = ImmutableSet.of(sessionInfo);
    StreamState streamState = new StreamState(planId, "descr", sessionInfos);

    io.cassandrareaper.core.StreamSession streamSession = StreamSessionFactory.fromStreamState(peer.toString(),
            streamState);/*from w  ww.  ja va 2 s . c  o  m*/
    assertEquals(1, streamSession.getStreams().size());

    List<Stream.TableProgress> progressSent = streamSession.getStreams().values().asList().get(0)
            .getProgressSent();
    assertEquals(2, progressSent.size());

    Stream.TableProgress standardTableProgess = progressSent.stream()
            .filter(ps -> ps.getTable().equals("keyspace1.standard1")).findFirst().get();
    assertEquals(Long.valueOf(96), standardTableProgess.getCurrent());
    assertEquals(Long.valueOf(2048), standardTableProgess.getTotal());

    Stream.TableProgress counterTableProgress = progressSent.stream()
            .filter(ps -> ps.getTable().equals("keyspace1.counter1")).findFirst().get();
    assertEquals(Long.valueOf(640), counterTableProgress.getCurrent());
    assertEquals(Long.valueOf(1024), counterTableProgress.getTotal());
}

From source file:io.cassandrareaper.service.StreamManager.java

License:Apache License

private SessionInfo parseSessionInfoPre2_1(CompositeData compositeData) {
    try {//from w  ww . j a v a2  s  . c o  m
        // these fields can be directly parsed
        InetAddress peer = InetAddress.getByName((String) compositeData.get("peer"));
        InetAddress connecting = InetAddress.getByName((String) compositeData.get("connecting"));
        org.apache.cassandra.streaming.StreamSession.State state = org.apache.cassandra.streaming.StreamSession.State
                .valueOf((String) compositeData.get("state"));

        // sending and receiving summaries parsing can be delegated to their composite data classes
        CompositeData[] receivingSummariesData = (CompositeData[]) compositeData.get("receivingSummaries");
        Set<StreamSummary> receivingSummaries = Arrays.stream(receivingSummariesData)
                .map(StreamSummaryCompositeData::fromCompositeData).collect(Collectors.toSet());
        CompositeData[] sendingSummariesData = (CompositeData[]) compositeData.get("sendingSummaries");
        Set<StreamSummary> sendingSummaries = Arrays.stream(sendingSummariesData)
                .map(StreamSummaryCompositeData::fromCompositeData).collect(Collectors.toSet());

        // Prior to 2.1, Session does not have session Index in the SessionInfo class
        int sessionIndex = Integer.MIN_VALUE;

        SessionInfo sessionInfo = new SessionInfo(peer, sessionIndex, connecting, receivingSummaries,
                sendingSummaries, state);

        // when pulling streams, C* also bundles in the progress of files. it's not possible to add them to SessionInfo
        // through the constructor, but it's possible via .updateProgress() calls

        CompositeData[] receivingFilesData = (CompositeData[]) compositeData.get("receivingFiles");
        Arrays.stream(receivingFilesData).map(this::parseProgressInfoPre2_1)
                .forEach(sessionInfo::updateProgress);

        CompositeData[] sendingFilesData = (CompositeData[]) compositeData.get("sendingFiles");
        Arrays.stream(sendingFilesData).map(this::parseProgressInfoPre2_1).forEach(sessionInfo::updateProgress);

        return sessionInfo;
    } catch (UnknownHostException e) {
        throw new IllegalStateException(e);
    }
}