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);
}
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);
}
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());
}
}
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();
}
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();
}
Aggregations