Search in sources :

Example 1 with ClientIdentifier

use of org.opendaylight.controller.cluster.access.concepts.ClientIdentifier in project controller by opendaylight.

the class FrontendClientMetadata method readFrom.

public static FrontendClientMetadata readFrom(final DataInput in) throws IOException, ClassNotFoundException {
    final ClientIdentifier id = ClientIdentifier.readFrom(in);
    final int purgedSize = in.readInt();
    final Builder<UnsignedLong> b = ImmutableRangeSet.builder();
    for (int i = 0; i < purgedSize; ++i) {
        final byte header = WritableObjects.readLongHeader(in);
        final UnsignedLong lower = UnsignedLong.fromLongBits(WritableObjects.readFirstLong(in, header));
        final UnsignedLong upper = UnsignedLong.fromLongBits(WritableObjects.readSecondLong(in, header));
        b.add(Range.closed(lower, upper));
    }
    final int currentSize = in.readInt();
    final Collection<FrontendHistoryMetadata> currentHistories = new ArrayList<>(currentSize);
    for (int i = 0; i < currentSize; ++i) {
        currentHistories.add(FrontendHistoryMetadata.readFrom(in));
    }
    return new FrontendClientMetadata(id, b.build(), currentHistories);
}
Also used : ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) UnsignedLong(com.google.common.primitives.UnsignedLong) ArrayList(java.util.ArrayList)

Example 2 with ClientIdentifier

use of org.opendaylight.controller.cluster.access.concepts.ClientIdentifier in project controller by opendaylight.

the class FrontendShardDataTreeSnapshotMetadataTest method createFrontedClientMetadata.

private static FrontendClientMetadata createFrontedClientMetadata(final long num) {
    final String index = String.valueOf(num);
    final String indexName = "test_" + index;
    final FrontendIdentifier frontendIdentifier = FrontendIdentifier.create(MemberName.forName(indexName), FrontendType.forName(index));
    final ClientIdentifier clientIdentifier = ClientIdentifier.create(frontendIdentifier, num);
    final RangeSet<UnsignedLong> purgedHistories = TreeRangeSet.create();
    purgedHistories.add(Range.closed(UnsignedLong.ZERO, UnsignedLong.ONE));
    final Collection<FrontendHistoryMetadata> currentHistories = Collections.singleton(new FrontendHistoryMetadata(num, num, true, ImmutableMap.of(UnsignedLong.ZERO, Boolean.TRUE), purgedHistories));
    return new FrontendClientMetadata(clientIdentifier, purgedHistories, currentHistories);
}
Also used : ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) UnsignedLong(com.google.common.primitives.UnsignedLong) FrontendIdentifier(org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier)

Example 3 with ClientIdentifier

use of org.opendaylight.controller.cluster.access.concepts.ClientIdentifier in project controller by opendaylight.

the class Shard method handleConnectClient.

@SuppressWarnings("checkstyle:IllegalCatch")
private void handleConnectClient(final ConnectClientRequest message) {
    try {
        final ClientIdentifier clientId = message.getTarget();
        final LeaderFrontendState existing = findFrontend(clientId);
        if (existing != null) {
            existing.touch();
        }
        if (!isLeader() || !isLeaderActive()) {
            LOG.info("{}: not currently leader, rejecting request {}. isLeader: {}, isLeaderActive: {}," + "isLeadershipTransferInProgress: {}.", persistenceId(), message, isLeader(), isLeaderActive(), isLeadershipTransferInProgress());
            throw new NotLeaderException(getSelf());
        }
        final ABIVersion selectedVersion = selectVersion(message);
        final LeaderFrontendState frontend;
        if (existing == null) {
            frontend = new LeaderFrontendState(persistenceId(), clientId, store);
            knownFrontends.put(clientId.getFrontendId(), frontend);
            LOG.debug("{}: created state {} for client {}", persistenceId(), frontend, clientId);
        } else {
            frontend = existing;
        }
        frontend.reconnect();
        message.getReplyTo().tell(new ConnectClientSuccess(message.getTarget(), message.getSequence(), getSelf(), ImmutableList.of(), store.getDataTree(), CLIENT_MAX_MESSAGES).toVersion(selectedVersion), ActorRef.noSender());
    } catch (RequestException | RuntimeException e) {
        message.getReplyTo().tell(new Failure(e), ActorRef.noSender());
    }
}
Also used : ConnectClientSuccess(org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess) NotLeaderException(org.opendaylight.controller.cluster.access.commands.NotLeaderException) ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) ABIVersion(org.opendaylight.controller.cluster.access.ABIVersion) RequestException(org.opendaylight.controller.cluster.access.concepts.RequestException) UnsupportedRequestException(org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException) RuntimeRequestException(org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException) Failure(akka.actor.Status.Failure)

Example 4 with ClientIdentifier

use of org.opendaylight.controller.cluster.access.concepts.ClientIdentifier in project controller by opendaylight.

the class ShardTransactionActorFactory method actorNameFor.

private String actorNameFor(final TransactionIdentifier txId) {
    final LocalHistoryIdentifier historyId = txId.getHistoryId();
    final ClientIdentifier clientId = historyId.getClientId();
    final FrontendIdentifier frontendId = clientId.getFrontendId();
    final StringBuilder sb = new StringBuilder("shard-");
    sb.append(shardName).append('-').append(frontendId.getMemberName().getName()).append(':').append(frontendId.getClientType().getName()).append('@').append(clientId.getGeneration()).append(':');
    if (historyId.getHistoryId() != 0) {
        sb.append(historyId.getHistoryId()).append('-');
    }
    return sb.append(txId.getTransactionId()).append('_').append(ACTOR_NAME_COUNTER.incrementAndGet()).toString();
}
Also used : ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier) FrontendIdentifier(org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier)

Example 5 with ClientIdentifier

use of org.opendaylight.controller.cluster.access.concepts.ClientIdentifier in project controller by opendaylight.

the class AbstractClientActorTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    final FrontendType frontendType = FrontendType.forName(getClass().getSimpleName());
    final FrontendIdentifier frontendId = FrontendIdentifier.create(MEMBER_NAME, frontendType);
    final ClientIdentifier clientId = ClientIdentifier.create(frontendId, 0);
    doReturn(ticker).when(mockActorContext).ticker();
    doReturn(clientId).when(mockActorContext).getIdentifier();
    doReturn(getClass().getSimpleName()).when(mockActorContext).persistenceId();
    doReturn(mockSelf).when(mockActorContext).self();
}
Also used : ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) FrontendType(org.opendaylight.controller.cluster.access.concepts.FrontendType) FrontendIdentifier(org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier) Before(org.junit.Before)

Aggregations

ClientIdentifier (org.opendaylight.controller.cluster.access.concepts.ClientIdentifier)10 FrontendIdentifier (org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier)5 Before (org.junit.Before)3 UnsignedLong (com.google.common.primitives.UnsignedLong)2 NotLeaderException (org.opendaylight.controller.cluster.access.commands.NotLeaderException)2 LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)2 UnsupportedRequestException (org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException)2 Failure (akka.actor.Status.Failure)1 RecoveryCompleted (akka.persistence.RecoveryCompleted)1 SelectedSnapshot (akka.persistence.SelectedSnapshot)1 SnapshotMetadata (akka.persistence.SnapshotMetadata)1 SnapshotOffer (akka.persistence.SnapshotOffer)1 Timeout (akka.util.Timeout)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Timer (com.codahale.metrics.Timer)1 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 Test (org.junit.Test)1 ABIVersion (org.opendaylight.controller.cluster.access.ABIVersion)1 ConnectClientSuccess (org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess)1