mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-16 01:41:26 +02:00
MastershipManager: make "useRegionForBalanceRoles" a property
useRegionForBalance roles has been available for a while but seems to only be accessed directly (it's a public field). It'd be useful to be able to change that using the CLI. Change-Id: If8c6dfbb300513e4d8dc0ba3d0d8f6ce9eac036a
This commit is contained in:
parent
a0b0a1395a
commit
f2b9d03102
@ -23,10 +23,14 @@ import com.google.common.util.concurrent.Futures;
|
||||
import org.apache.felix.scr.annotations.Activate;
|
||||
import org.apache.felix.scr.annotations.Component;
|
||||
import org.apache.felix.scr.annotations.Deactivate;
|
||||
import org.apache.felix.scr.annotations.Modified;
|
||||
import org.apache.felix.scr.annotations.Property;
|
||||
import org.apache.felix.scr.annotations.Reference;
|
||||
import org.apache.felix.scr.annotations.ReferenceCardinality;
|
||||
import org.apache.felix.scr.annotations.Service;
|
||||
import org.onlab.metrics.MetricsService;
|
||||
import org.onosproject.cfg.ComponentConfigService;
|
||||
import org.onosproject.cfg.ConfigProperty;
|
||||
import org.onosproject.cluster.ClusterService;
|
||||
import org.onosproject.cluster.ControllerNode;
|
||||
import org.onosproject.cluster.NodeId;
|
||||
@ -97,12 +101,22 @@ public class MastershipManager
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||
protected RegionService regionService;
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||
protected ComponentConfigService cfgService;
|
||||
|
||||
private NodeId localNodeId;
|
||||
private Timer requestRoleTimer;
|
||||
|
||||
static final boolean DEFAULT_USE_REGION_FOR_BALANCE_ROLES = false;
|
||||
@Property(name = "useRegionForBalanceRoles", boolValue = DEFAULT_USE_REGION_FOR_BALANCE_ROLES,
|
||||
label = "Use Regions for balancing roles")
|
||||
public boolean useRegionForBalanceRoles;
|
||||
|
||||
@Activate
|
||||
public void activate() {
|
||||
cfgService.registerProperties(getClass());
|
||||
modified();
|
||||
|
||||
requestRoleTimer = createTimer("Mastership", "requestRole", "responseTime");
|
||||
localNodeId = clusterService.getLocalNode().id();
|
||||
eventDispatcher.addSink(MastershipEvent.class, listenerRegistry);
|
||||
@ -110,11 +124,22 @@ public class MastershipManager
|
||||
log.info("Started");
|
||||
}
|
||||
|
||||
@Modified
|
||||
public void modified() {
|
||||
Set<ConfigProperty> configProperties = cfgService.getProperties(getClass().getCanonicalName());
|
||||
for (ConfigProperty property : configProperties) {
|
||||
if (property.name().equals("useRegionForBalanceRoles")) {
|
||||
useRegionForBalanceRoles = property.asBoolean();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Deactivate
|
||||
public void deactivate() {
|
||||
eventDispatcher.removeSink(MastershipEvent.class);
|
||||
store.unsetDelegate(delegate);
|
||||
log.info("Stopped");
|
||||
cfgService.unregisterProperties(getClass(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,11 +21,13 @@ import java.util.function.Consumer;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.onlab.junit.TestUtils;
|
||||
import org.onlab.packet.IpAddress;
|
||||
import org.onosproject.cfg.ComponentConfigService;
|
||||
import org.onosproject.cluster.ClusterService;
|
||||
import org.onosproject.cluster.ControllerNode;
|
||||
import org.onosproject.cluster.DefaultControllerNode;
|
||||
@ -47,6 +49,10 @@ import org.onosproject.store.trivial.SimpleMastershipStore;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
|
||||
import static org.easymock.EasyMock.anyObject;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.expectLastCall;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.onosproject.net.MastershipRole.MASTER;
|
||||
import static org.onosproject.net.MastershipRole.NONE;
|
||||
@ -106,6 +112,18 @@ public class MastershipManagerTest {
|
||||
TestUtils.setField(regionManager, "store", regionStore);
|
||||
regionManager.activate();
|
||||
mgr.regionService = regionManager;
|
||||
|
||||
ComponentConfigService mockConfigService =
|
||||
EasyMock.createMock(ComponentConfigService.class);
|
||||
expect(mockConfigService.getProperties(anyObject())).andReturn(ImmutableSet.of());
|
||||
mockConfigService.registerProperties(mgr.getClass());
|
||||
expectLastCall();
|
||||
mockConfigService.unregisterProperties(mgr.getClass(), false);
|
||||
expectLastCall();
|
||||
expect(mockConfigService.getProperties(anyObject())).andReturn(ImmutableSet.of());
|
||||
mgr.cfgService = mockConfigService;
|
||||
replay(mockConfigService);
|
||||
|
||||
mgr.activate();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user