本文整理汇总了Java中org.onosproject.cluster.DefaultPartition类的典型用法代码示例。如果您正苦于以下问题:Java DefaultPartition类的具体用法?Java DefaultPartition怎么用?Java DefaultPartition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultPartition类属于org.onosproject.cluster包,在下文中一共展示了DefaultPartition类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildDefaultPartitions
import org.onosproject.cluster.DefaultPartition; //导入依赖的package包/类
private static Set<Partition> buildDefaultPartitions(Collection<ControllerNode> nodes) {
List<ControllerNode> sorted = new ArrayList<>(nodes);
Collections.sort(sorted, (o1, o2) -> o1.id().toString().compareTo(o2.id().toString()));
Set<Partition> partitions = Sets.newHashSet();
// add partitions
int length = nodes.size();
int count = Math.min(3, length);
for (int i = 0; i < length; i++) {
int index = i;
Set<NodeId> set = new HashSet<>(count);
for (int j = 0; j < count; j++) {
set.add(sorted.get((i + j) % length).id());
}
partitions.add(new DefaultPartition(PartitionId.from((index + 1)), set));
}
return partitions;
}
示例2: activate
import org.onosproject.cluster.DefaultPartition; //导入依赖的package包/类
@Activate
public void activate() {
String localIp = getSiteLocalAddress();
ControllerNode localNode =
new DefaultControllerNode(new NodeId(localIp), IpAddress.valueOf(localIp), DEFAULT_ONOS_PORT);
// partition 1
Partition partition = new DefaultPartition(PartitionId.from(1), ImmutableSet.of(localNode.id()));
ClusterMetadata metadata = new ClusterMetadata(PROVIDER_ID,
"default",
ImmutableSet.of(localNode),
ImmutableSet.of(partition));
long version = System.currentTimeMillis();
cachedMetadata.set(new Versioned<>(metadata, version));
providerRegistry.register(this);
log.info("Started");
}
示例3: buildDefaultPartitions
import org.onosproject.cluster.DefaultPartition; //导入依赖的package包/类
private Set<Partition> buildDefaultPartitions(Collection<ControllerNode> nodes, int partitionSize) {
List<ControllerNode> sorted = new ArrayList<>(nodes);
Collections.sort(sorted, (o1, o2) -> o1.id().toString().compareTo(o2.id().toString()));
Set<Partition> partitions = Sets.newHashSet();
// add partitions
int length = nodes.size();
int count = Math.min(partitionSize, length);
for (int i = 0; i < length; i++) {
int index = i;
Set<NodeId> set = new HashSet<>(count);
for (int j = 0; j < count; j++) {
set.add(sorted.get((i + j) % length).id());
}
partitions.add(new DefaultPartition(PartitionId.from((index + 1)), versionService.version(), set));
}
return partitions;
}
示例4: activate
import org.onosproject.cluster.DefaultPartition; //导入依赖的package包/类
@Activate
public void activate() {
partition = new ActiveStoragePartition(
new DefaultPartition(
PartitionId.SHARED,
null,
clusterService.getNodes()
.stream()
.map(ControllerNode::id)
.collect(Collectors.toSet())),
clusterCommunicator,
clusterService);
partition.open().join();
primitiveCreator = partition.client();
log.info("Started");
}
示例5: testComputeInitialIncompletePartition
import org.onosproject.cluster.DefaultPartition; //导入依赖的package包/类
@Test
public void testComputeInitialIncompletePartition() throws Exception {
Partition sourcePartition = new DefaultPartition(
PartitionId.from(1),
Version.version("1.0.0"),
Arrays.asList(
NodeId.nodeId("1"),
NodeId.nodeId("2"),
NodeId.nodeId("3")));
Version targetVersion = Version.version("1.0.1");
List<NodeId> members = Arrays.asList(
NodeId.nodeId("1"),
NodeId.nodeId("2"));
Partition forkedPartition = PartitionManager.computeInitialPartition(sourcePartition, targetVersion, members);
assertTrue(forkedPartition.getMembers().size() == 2);
assertTrue(forkedPartition.getMembers().contains(NodeId.nodeId("1")));
assertTrue(forkedPartition.getMembers().contains(NodeId.nodeId("2")));
}
示例6: testComputeInitialCompletePartition
import org.onosproject.cluster.DefaultPartition; //导入依赖的package包/类
@Test
public void testComputeInitialCompletePartition() throws Exception {
Partition sourcePartition = new DefaultPartition(
PartitionId.from(1),
Version.version("1.0.0"),
Arrays.asList(
NodeId.nodeId("3"),
NodeId.nodeId("4"),
NodeId.nodeId("5")));
Version targetVersion = Version.version("1.0.1");
List<NodeId> members = Arrays.asList(
NodeId.nodeId("1"),
NodeId.nodeId("2"),
NodeId.nodeId("3"),
NodeId.nodeId("4"),
NodeId.nodeId("5"));
Partition forkedPartition = PartitionManager.computeInitialPartition(sourcePartition, targetVersion, members);
assertTrue(forkedPartition.getMembers().size() == 4);
assertTrue(forkedPartition.getMembers().contains(NodeId.nodeId("1")));
assertTrue(forkedPartition.getMembers().contains(NodeId.nodeId("3")));
assertTrue(forkedPartition.getMembers().contains(NodeId.nodeId("4")));
assertTrue(forkedPartition.getMembers().contains(NodeId.nodeId("5")));
}
示例7: testComputeFinalIncompletePartition
import org.onosproject.cluster.DefaultPartition; //导入依赖的package包/类
@Test
public void testComputeFinalIncompletePartition() throws Exception {
Partition sourcePartition = new DefaultPartition(
PartitionId.from(1),
Version.version("1.0.0"),
Arrays.asList(
NodeId.nodeId("1"),
NodeId.nodeId("2"),
NodeId.nodeId("3")));
Version targetVersion = Version.version("1.0.1");
List<NodeId> members = Arrays.asList(
NodeId.nodeId("1"),
NodeId.nodeId("2"));
Partition forkedPartition = PartitionManager.computeFinalPartition(sourcePartition, targetVersion, members);
assertTrue(forkedPartition.getMembers().size() == 2);
assertTrue(forkedPartition.getMembers().contains(NodeId.nodeId("1")));
assertTrue(forkedPartition.getMembers().contains(NodeId.nodeId("2")));
}
示例8: testComputeFinalCompletePartition
import org.onosproject.cluster.DefaultPartition; //导入依赖的package包/类
@Test
public void testComputeFinalCompletePartition() throws Exception {
Partition sourcePartition = new DefaultPartition(
PartitionId.from(1),
Version.version("1.0.0"),
Arrays.asList(
NodeId.nodeId("3"),
NodeId.nodeId("4"),
NodeId.nodeId("5")));
Version targetVersion = Version.version("1.0.1");
List<NodeId> members = Arrays.asList(
NodeId.nodeId("1"),
NodeId.nodeId("2"),
NodeId.nodeId("3"),
NodeId.nodeId("4"),
NodeId.nodeId("5"));
Partition forkedPartition = PartitionManager.computeFinalPartition(sourcePartition, targetVersion, members);
assertTrue(forkedPartition.getMembers().size() == 3);
assertTrue(forkedPartition.getMembers().contains(NodeId.nodeId("3")));
assertTrue(forkedPartition.getMembers().contains(NodeId.nodeId("4")));
assertTrue(forkedPartition.getMembers().contains(NodeId.nodeId("5")));
}
示例9: computePartition
import org.onosproject.cluster.DefaultPartition; //导入依赖的package包/类
/**
* Computes a forked partition from the given source partition.
*
* @param sourcePartition the source partition from which to compute the partition
* @param targetVersion the target partition version
* @param members the set of members available to the partition
* @param delta the number of additional members to preserve outside the partition
* @return the computed forked partition
*/
private static Partition computePartition(
Partition sourcePartition,
Version targetVersion,
List<NodeId> members,
int delta) {
// Create a collection of members of the forked/isolated partition. Initial membership
// will include up to n upgraded nodes until all n nodes in the partition have been upgraded.
List<NodeId> sortedMembers = members.stream()
.sorted()
.collect(Collectors.toList());
// Create a list of members of the partition that have been upgraded according to the
// version isolated cluster membership.
List<NodeId> partitionMembers = sortedMembers.stream()
.filter(nodeId -> sourcePartition.getMembers().contains(nodeId))
.collect(Collectors.toList());
// If additional members need to be added to the partition to make up a full member list,
// add members in sorted order to create deterministic rebalancing of nodes.
int totalMembers = sourcePartition.getMembers().size() + delta;
if (partitionMembers.size() < totalMembers) {
for (int i = partitionMembers.size(); i < totalMembers; i++) {
Optional<NodeId> nextMember = sortedMembers.stream()
.filter(nodeId -> !partitionMembers.contains(nodeId))
.findFirst();
if (nextMember.isPresent()) {
partitionMembers.add(nextMember.get());
} else {
break;
}
}
}
return new DefaultPartition(
sourcePartition.getId(),
targetVersion,
partitionMembers);
}
示例10: deserialize
import org.onosproject.cluster.DefaultPartition; //导入依赖的package包/类
@Override
public Partition deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
return jp.readValueAs(DefaultPartition.class);
}