use of org.onosproject.cluster.Member in project onos by opennetworkinglab.
the class UpgradeManagerTest method createUpgradeManager.
/**
* Creates a new upgrade manager to test.
*
* @param version the local node version
* @param state the initial upgrade state
* @param versions a list of controller node versions
* @return the activated upgrade manager
*/
@SuppressWarnings("unchecked")
private UpgradeManager createUpgradeManager(Version version, Upgrade state, List<Version> versions) {
UpgradeManager upgradeManager = new UpgradeManager();
injectEventDispatcher(upgradeManager, new TestEventDispatcher());
upgradeManager.membershipService = new MembershipServiceAdapter() {
@Override
public MembershipGroup getLocalGroup() {
return getGroups().stream().filter(group -> group.version().equals(version)).findFirst().get();
}
@Override
public Collection<MembershipGroup> getGroups() {
AtomicInteger nodeCounter = new AtomicInteger();
Map<Version, Set<Member>> groups = Maps.newHashMap();
versions.stream().forEach(version -> {
groups.computeIfAbsent(version, k -> Sets.newHashSet()).add(new Member(NodeId.nodeId(String.valueOf(nodeCounter.getAndIncrement())), version));
});
return Maps.transformEntries(groups, MembershipGroup::new).values();
}
};
upgradeManager.clusterService = new ClusterServiceAdapter() {
@Override
public Set<ControllerNode> getNodes() {
AtomicInteger nodeCounter = new AtomicInteger();
return versions.stream().map(v -> {
int nodeId = nodeCounter.getAndIncrement();
return new DefaultControllerNode(NodeId.nodeId(String.valueOf(nodeId)), IpAddress.valueOf("127.0.0.1"), nodeId);
}).collect(Collectors.toSet());
}
@Override
public ControllerNode getNode(NodeId nodeId) {
return getNodes().stream().filter(node -> node.id().equals(nodeId)).findFirst().orElse(null);
}
@Override
public Version getVersion(NodeId nodeId) {
return versions.get(Integer.parseInt(nodeId.id()));
}
};
upgradeManager.versionService = new VersionServiceAdapter() {
@Override
public Version version() {
return version;
}
};
upgradeManager.coordinationService = new CoordinationServiceAdapter() {
@Override
public <V> AtomicValueBuilder<V> atomicValueBuilder() {
return new AtomicValueBuilder<V>() {
@Override
public AsyncAtomicValue<V> build() {
return new AsyncAtomicValueAdapter() {
@Override
public AtomicValue asAtomicValue() {
return new AtomicValueAdapter() {
private Object value = state;
@Override
public void set(Object value) {
this.value = value;
}
@Override
public Object get() {
return value;
}
@Override
public boolean compareAndSet(Object expect, Object update) {
if ((value == null && expect == null) || (value != null && value.equals(expect))) {
value = update;
return true;
}
return false;
}
};
}
};
}
};
}
};
upgradeManager.activate();
return upgradeManager;
}
use of org.onosproject.cluster.Member in project onos by opennetworkinglab.
the class MembershipsListCommand method doExecute.
@Override
protected void doExecute() {
MembershipService service = get(MembershipService.class);
ClusterAdminService clusterService = get(ClusterAdminService.class);
if (outputJson()) {
print("%s", json(service));
} else {
service.getGroups().forEach(group -> {
List<Member> members = newArrayList(group.members());
print("-------------------------------------------------------------------");
print("Version: %s, Members: %d", group.version(), members.size());
members.sort(MEMBERSHIP_COMPARATOR);
members.forEach(member -> {
Optional<ControllerNode> controllerNode = Optional.ofNullable(clusterService.getNode(member.nodeId()));
if (!controllerNode.isPresent()) {
print(" id=%s, version=%s, self=%s", member.nodeId(), member.version(), member.equals(service.getLocalMember()) ? "*" : "");
} else {
ControllerNode node = controllerNode.get();
print(" id=%s, ip=%s, tcpPort=%s, state=%s, self=%s", member.nodeId(), node.ip(), node.tcpPort(), clusterService.getState(node.id()), member.equals(service.getLocalMember()) ? "*" : "");
}
});
print("-------------------------------------------------------------------");
});
}
}
use of org.onosproject.cluster.Member in project onos by opennetworkinglab.
the class StorageManager method eventuallyConsistentMapBuilder.
@Override
public <K, V> EventuallyConsistentMapBuilder<K, V> eventuallyConsistentMapBuilder() {
checkPermission(STORAGE_WRITE);
// Note: NPE in the usage of ClusterService/MembershipService prevents rebooting the Karaf container.
// We need to reference these services outside the following peer suppliers.
final MembershipService membershipService = this.membershipService;
final ClusterService clusterService = this.clusterService;
final NodeId localNodeId = clusterService.getLocalNode().id();
// Use the MembershipService to provide peers for the map that are isolated within the current version.
Supplier<List<NodeId>> peersSupplier = () -> membershipService.getMembers().stream().map(Member::nodeId).filter(nodeId -> !nodeId.equals(localNodeId)).filter(id -> clusterService.getState(id).isActive()).collect(Collectors.toList());
// If this is the first node in its version, bootstrap from the previous version. Otherwise, bootstrap the
// map from members isolated within the current version.
Supplier<List<NodeId>> bootstrapPeersSupplier = () -> {
if (membershipService.getMembers().size() == 1) {
return clusterService.getNodes().stream().map(ControllerNode::id).filter(id -> !localNodeId.equals(id)).filter(id -> clusterService.getState(id).isActive()).collect(Collectors.toList());
} else {
return membershipService.getMembers().stream().map(Member::nodeId).filter(id -> !localNodeId.equals(id)).filter(id -> clusterService.getState(id).isActive()).collect(Collectors.toList());
}
};
return new EventuallyConsistentMapBuilderImpl<>(localNodeId, clusterCommunicator, persistenceService, peersSupplier, bootstrapPeersSupplier);
}
use of org.onosproject.cluster.Member in project onos by opennetworkinglab.
the class MembershipManager method activate.
@Activate
public void activate() {
NodeId localId = clusterService.getLocalNode().id();
localMember = new Member(localId, clusterService.getVersion(localId));
log.info("Started");
}
Aggregations