blob: b2d48a65ecf3652f3e7f476d222f8ed0d78fbd20 [file] [log] [blame]
pierventre37dcf4c2021-09-16 18:43:06 +02001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.segmentrouting;
18
19import org.onosproject.cluster.LeadershipService;
20import org.onosproject.cluster.NodeId;
21import org.onosproject.cluster.PartitionId;
22import org.onosproject.net.intent.WorkPartitionServiceAdapter;
23
24import java.util.function.Function;
25
26public class MockWorkPartitionService extends WorkPartitionServiceAdapter {
27
28 LeadershipService leadershipService;
29 static final int NUM_PARTITIONS = 14;
30
31 @Override
32 public <K> NodeId getLeader(K id, Function<K, Long> hasher) {
33 int partition = Math.abs(hasher.apply(id).intValue()) % NUM_PARTITIONS;
34 PartitionId partitionId = new PartitionId(partition);
35 return leadershipService.getLeadership(partitionId.toString()).leaderNodeId();
36 }
37
38}