Java 类net.floodlightcontroller.core.RoleInfo 实例源码

项目:fresco_floodlight    文件:RoleManager.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public RoleManager(@Nonnull Controller controller,
        @Nonnull IShutdownService shutdownService,
        @Nonnull HARole role,
        @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(controller, "controller must not be null");
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");
    Preconditions.checkNotNull(shutdownService, "shutdownService must not be null");

    this.currentRoleInfo = new RoleInfo(role,
                                   roleChangeDescription,
                                   new Date());
    this.controller = controller;
    this.shutdownService = shutdownService;
    this.counters = new RoleManagerCounters(controller.getDebugCounter());
}
项目:iTAP-controller    文件:RoleManager.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public RoleManager(@Nonnull Controller controller,
        @Nonnull IShutdownService shutdownService,
        @Nonnull HARole role,
        @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(controller, "controller must not be null");
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");
    Preconditions.checkNotNull(shutdownService, "shutdownService must not be null");

    this.currentRoleInfo = new RoleInfo(role,
                                   roleChangeDescription,
                                   new Date());
    this.controller = controller;
    this.shutdownService = shutdownService;
    this.counters = new RoleManagerCounters(controller.getDebugCounter());
}
项目:SDN-Multicast    文件:RoleManager.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public RoleManager(@Nonnull Controller controller,
        @Nonnull IShutdownService shutdownService,
        @Nonnull HARole role,
        @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(controller, "controller must not be null");
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");
    Preconditions.checkNotNull(shutdownService, "shutdownService must not be null");

    this.currentRoleInfo = new RoleInfo(role,
                                   roleChangeDescription,
                                   new Date());
    this.controller = controller;
    this.shutdownService = shutdownService;
    this.counters = new RoleManagerCounters(controller.getDebugCounter());
}
项目:arscheduler    文件:RoleManager.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public RoleManager(@Nonnull Controller controller,
        @Nonnull IShutdownService shutdownService,
        @Nonnull HARole role,
        @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(controller, "controller must not be null");
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");
    Preconditions.checkNotNull(shutdownService, "shutdownService must not be null");

    this.currentRoleInfo = new RoleInfo(role,
                                   roleChangeDescription,
                                   new Date());
    this.controller = controller;
    this.shutdownService = shutdownService;
    this.counters = new RoleManagerCounters(controller.getDebugCounter());
}
项目:QoS-floodlight    文件:Controller.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 * @throws IllegalArgumentException if role is EQUAL
 */
public RoleManager(Role role, String roleChangeDescription) {
    if (role == null)
        throw new NullPointerException("role must not be null");
    if (role == Role.EQUAL)
        throw new IllegalArgumentException("role must not be EQUAL");
    if (roleChangeDescription == null) {
        throw new NullPointerException("roleChangeDescription must " +
                                       "not be null");
    }

    this.role = role;
    this.roleChangeDescription = roleChangeDescription;
    this.connectedChannelHandlers = new HashSet<OFChannelHandler>();
    this.currentRoleInfo = new RoleInfo(this.role,
                                   this.roleChangeDescription,
                                   new Date());
}
项目:floodlight1.2-delay    文件:RoleManager.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public RoleManager(@Nonnull Controller controller,
        @Nonnull IShutdownService shutdownService,
        @Nonnull HARole role,
        @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(controller, "controller must not be null");
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");
    Preconditions.checkNotNull(shutdownService, "shutdownService must not be null");

    this.currentRoleInfo = new RoleInfo(role,
                                   roleChangeDescription,
                                   new Date());
    this.controller = controller;
    this.shutdownService = shutdownService;
    this.counters = new RoleManagerCounters(controller.getDebugCounter());
}
项目:floodlight-hardware    文件:RoleManager.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public RoleManager(@Nonnull Controller controller,
        @Nonnull IShutdownService shutdownService,
        @Nonnull HARole role,
        @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(controller, "controller must not be null");
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");
    Preconditions.checkNotNull(shutdownService, "shutdownService must not be null");

    this.currentRoleInfo = new RoleInfo(role,
                                   roleChangeDescription,
                                   new Date());
    this.controller = controller;
    this.shutdownService = shutdownService;
    this.counters = new RoleManagerCounters(controller.getDebugCounter());
}
项目:ACAMPController    文件:RoleManager.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public RoleManager(@Nonnull Controller controller,
        @Nonnull IShutdownService shutdownService,
        @Nonnull HARole role,
        @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(controller, "controller must not be null");
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");
    Preconditions.checkNotNull(shutdownService, "shutdownService must not be null");

    this.currentRoleInfo = new RoleInfo(role,
                                   roleChangeDescription,
                                   new Date());
    this.controller = controller;
    this.shutdownService = shutdownService;
    this.counters = new RoleManagerCounters(controller.getDebugCounter());
}
项目:fast-failover-demo    文件:RoleManager.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public RoleManager(@Nonnull Controller controller,
        @Nonnull IShutdownService shutdownService,
        @Nonnull HARole role,
        @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(controller, "controller must not be null");
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");
    Preconditions.checkNotNull(shutdownService, "shutdownService must not be null");

    this.currentRoleInfo = new RoleInfo(role,
                                   roleChangeDescription,
                                   new Date());
    this.controller = controller;
    this.shutdownService = shutdownService;
    this.counters = new RoleManagerCounters(controller.getDebugCounter());
}
项目:floodlightLB    文件:RoleManager.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public RoleManager(@Nonnull Controller controller,
        @Nonnull IShutdownService shutdownService,
        @Nonnull HARole role,
        @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(controller, "controller must not be null");
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");
    Preconditions.checkNotNull(shutdownService, "shutdownService must not be null");

    this.currentRoleInfo = new RoleInfo(role,
                                   roleChangeDescription,
                                   new Date());
    this.controller = controller;
    this.shutdownService = shutdownService;
    this.counters = new RoleManagerCounters(controller.getDebugCounter());
}
项目:floodlight_with_topoguard    文件:Controller.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 * @throws IllegalArgumentException if role is EQUAL
 */
public RoleManager(Role role, String roleChangeDescription) {
    if (role == null)
        throw new NullPointerException("role must not be null");
    if (role == Role.EQUAL)
        throw new IllegalArgumentException("role must not be EQUAL");
    if (roleChangeDescription == null) {
        throw new NullPointerException("roleChangeDescription must " +
                                       "not be null");
    }

    this.role = role;
    this.roleChangeDescription = roleChangeDescription;
    this.connectedChannelHandlers = new HashSet<OFChannelHandler>();
    this.currentRoleInfo = new RoleInfo(this.role,
                                   this.roleChangeDescription,
                                   new Date());
}
项目:floodlight    文件:RoleManager.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public RoleManager(@Nonnull Controller controller,
        @Nonnull IShutdownService shutdownService,
        @Nonnull HARole role,
        @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(controller, "controller must not be null");
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");
    Preconditions.checkNotNull(shutdownService, "shutdownService must not be null");

    this.currentRoleInfo = new RoleInfo(role,
                                   roleChangeDescription,
                                   new Date());
    this.controller = controller;
    this.shutdownService = shutdownService;
    this.counters = new RoleManagerCounters(controller.getDebugCounter());
}
项目:FloodligtModule    文件:Controller.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 * @throws IllegalArgumentException if role is EQUAL
 */
public RoleManager(Role role, String roleChangeDescription) {
    if (role == null)
        throw new NullPointerException("role must not be null");
    if (role == Role.EQUAL)
        throw new IllegalArgumentException("role must not be EQUAL");
    if (roleChangeDescription == null) {
        throw new NullPointerException("roleChangeDescription must " +
                                       "not be null");
    }

    this.role = role;
    this.roleChangeDescription = roleChangeDescription;
    this.connectedChannelHandlers = new HashSet<OFChannelHandler>();
    this.currentRoleInfo = new RoleInfo(this.role,
                                   this.roleChangeDescription,
                                   new Date());
}
项目:multicastSDN    文件:Controller.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 * @throws IllegalArgumentException if role is EQUAL
 */
public RoleManager(Role role, String roleChangeDescription) {
    if (role == null)
        throw new NullPointerException("role must not be null");
    if (role == Role.EQUAL)
        throw new IllegalArgumentException("role must not be EQUAL");
    if (roleChangeDescription == null) {
        throw new NullPointerException("roleChangeDescription must " +
                                       "not be null");
    }

    this.role = role;
    this.roleChangeDescription = roleChangeDescription;
    this.connectedChannelHandlers = new HashSet<OFChannelHandler>();
    this.currentRoleInfo = new RoleInfo(this.role,
                                   this.roleChangeDescription,
                                   new Date());
}
项目:fresco_floodlight    文件:ControllerRoleResource.java   
@Get("json")
public Map<String, String> getRole() {
    IFloodlightProviderService floodlightProvider =
            (IFloodlightProviderService)getContext().getAttributes().
                get(IFloodlightProviderService.class.getCanonicalName());
    Map<String, String> retValue = new HashMap<String, String>();
    RoleInfo ri = floodlightProvider.getRoleInfo();
    retValue.put(STR_ROLE, ri.getRole().toString());
    retValue.put(STR_ROLE_CHANGE_DESC, ri.getRoleChangeDescription());
    retValue.put(STR_ROLE_CHANGE_DATE_TIME, ri.getRoleChangeDateTime().toString());
    return retValue;
}
项目:fresco_floodlight    文件:RoleManager.java   
/**
 * Set the controller's new role and notify switches.
 *
 * This method updates the controllers current role and notifies all
 * connected switches of the new role is different from the current
 * role. We dampen calls to this method. See class description for
 * details.
 *
 * @param role The new role.
 * @param roleChangeDescription A textual description of why the role
 * was changed. For information purposes only.
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public synchronized void setRole(@Nonnull HARole role, @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");

    if (role == getRole()) {
        counters.setSameRole.increment();
        log.debug("Received role request for {} but controller is "
                + "already {}. Ignoring it.", role, this.getRole());
        return;
    }

    if (this.getRole() == HARole.STANDBY && role == HARole.ACTIVE) {
        // At this point we are guaranteed that we will execute the code
        // below exactly once during the lifetime of this process! And
        // it will be a to MASTER transition
        counters.setRoleMaster.increment();
    }

    log.info("Received role request for {} (reason: {})."
            + " Initiating transition", role, roleChangeDescription);

    currentRoleInfo =
            new RoleInfo(role, roleChangeDescription, new Date());

    controller.addUpdateToQueue(new HARoleUpdate(role));
    controller.addUpdateToQueue(new SwitchRoleUpdate(role));

}
项目:fresco_floodlight    文件:ControllerTest.java   
@Test
public void testGetRoleInfoDefault() {
    RoleInfo info = controller.getRoleInfo();
    assertEquals(HARole.ACTIVE, info.getRole());
    assertNotNull(info.getRoleChangeDescription());
    assertEquals(HARole.ACTIVE, controller.getRole());
    // FIXME: RoleInfo's date. but the format is kinda broken
}
项目:fresco_floodlight    文件:ControllerTest.java   
/**
 * Start as SLAVE then set role to MASTER
 * Tests normal role change transition. Check that connected channels
 * receive a setRole request
 */
@Test
public void testSetRole() throws Exception {
    doSetUp(HARole.STANDBY);
    RoleInfo info = controller.getRoleInfo();
    assertEquals(HARole.STANDBY, info.getRole());
    assertEquals(HARole.STANDBY, controller.getRole());


    OFSwitchHandshakeHandler h = createMock(OFSwitchHandshakeHandler.class);

    // Reassert the role.
    reset(h);
    h.sendRoleRequestIfNotPending(OFControllerRole.ROLE_SLAVE);
    replay(h);
    controller.reassertRole(h, HARole.STANDBY);
    verify(h);

    // reassert a different role: no-op
    reset(h);
    replay(h);
    controller.reassertRole(h, HARole.ACTIVE);
    verify(h);

    IHAListener listener = createMock(IHAListener.class);
    expect(listener.getName()).andReturn("foo").anyTimes();
    setupListenerOrdering(listener);
    listener.transitionToActive();
    expectLastCall().once();
    replay(listener);
    controller.addHAListener(listener);
    controller.setRole(HARole.ACTIVE, "FooBar");
    controller.processUpdateQueueForTesting();
    verify(listener);
    info = controller.getRoleInfo();
    assertEquals(HARole.ACTIVE, info.getRole());
    assertEquals("FooBar", info.getRoleChangeDescription());
    assertEquals(HARole.ACTIVE, controller.getRole());
}
项目:iTAP-controller    文件:ControllerRoleResource.java   
@Get("json")
public Map<String, String> getRole() {
    IFloodlightProviderService floodlightProvider =
            (IFloodlightProviderService)getContext().getAttributes().
                get(IFloodlightProviderService.class.getCanonicalName());
    Map<String, String> retValue = new HashMap<String, String>();
    RoleInfo ri = floodlightProvider.getRoleInfo();
    retValue.put(STR_ROLE, ri.getRole().toString());
    retValue.put(STR_ROLE_CHANGE_DESC, ri.getRoleChangeDescription());
    retValue.put(STR_ROLE_CHANGE_DATE_TIME, ri.getRoleChangeDateTime().toString());
    return retValue;
}
项目:iTAP-controller    文件:RoleManager.java   
/**
 * Set the controller's new role and notify switches.
 *
 * This method updates the controllers current role and notifies all
 * connected switches of the new role is different from the current
 * role. We dampen calls to this method. See class description for
 * details.
 *
 * @param role The new role.
 * @param roleChangeDescription A textual description of why the role
 * was changed. For information purposes only.
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public synchronized void setRole(@Nonnull HARole role, @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");

    if (role == getRole()) {
        counters.setSameRole.increment();
        log.debug("Received role request for {} but controller is "
                + "already {}. Ignoring it.", role, this.getRole());
        return;
    }

    if (this.getRole() == HARole.STANDBY && role == HARole.ACTIVE) {
        // At this point we are guaranteed that we will execute the code
        // below exactly once during the lifetime of this process! And
        // it will be a to MASTER transition
        counters.setRoleMaster.increment();
    }

    log.info("Received role request for {} (reason: {})."
            + " Initiating transition", role, roleChangeDescription);

    currentRoleInfo =
            new RoleInfo(role, roleChangeDescription, new Date());

    controller.addUpdateToQueue(new HARoleUpdate(role));
    controller.addUpdateToQueue(new SwitchRoleUpdate(role));

}
项目:iTAP-controller    文件:ControllerTest.java   
@Test
public void testGetRoleInfoDefault() {
    RoleInfo info = controller.getRoleInfo();
    assertEquals(HARole.ACTIVE, info.getRole());
    assertNotNull(info.getRoleChangeDescription());
    assertEquals(HARole.ACTIVE, controller.getRole());
    // FIXME: RoleInfo's date. but the format is kinda broken
}
项目:iTAP-controller    文件:ControllerTest.java   
/**
 * Start as SLAVE then set role to MASTER
 * Tests normal role change transition. Check that connected channels
 * receive a setRole request
 */
@Test
public void testSetRole() throws Exception {
    doSetUp(HARole.STANDBY);
    RoleInfo info = controller.getRoleInfo();
    assertEquals(HARole.STANDBY, info.getRole());
    assertEquals(HARole.STANDBY, controller.getRole());


    OFSwitchHandshakeHandler h = createMock(OFSwitchHandshakeHandler.class);

    // Reassert the role.
    reset(h);
    h.sendRoleRequestIfNotPending(OFControllerRole.ROLE_SLAVE);
    replay(h);
    controller.reassertRole(h, HARole.STANDBY);
    verify(h);

    // reassert a different role: no-op
    reset(h);
    replay(h);
    controller.reassertRole(h, HARole.ACTIVE);
    verify(h);

    IHAListener listener = createMock(IHAListener.class);
    expect(listener.getName()).andReturn("foo").anyTimes();
    setupListenerOrdering(listener);
    listener.transitionToActive();
    expectLastCall().once();
    replay(listener);
    controller.addHAListener(listener);
    controller.setRole(HARole.ACTIVE, "FooBar");
    controller.processUpdateQueueForTesting();
    verify(listener);
    info = controller.getRoleInfo();
    assertEquals(HARole.ACTIVE, info.getRole());
    assertEquals("FooBar", info.getRoleChangeDescription());
    assertEquals(HARole.ACTIVE, controller.getRole());
}
项目:SDN-Multicast    文件:ControllerRoleResource.java   
@Get("json")
public Map<String, String> getRole() {
    IFloodlightProviderService floodlightProvider =
            (IFloodlightProviderService)getContext().getAttributes().
                get(IFloodlightProviderService.class.getCanonicalName());
    Map<String, String> retValue = new HashMap<String, String>();
    RoleInfo ri = floodlightProvider.getRoleInfo();
    retValue.put(STR_ROLE, ri.getRole().toString());
    retValue.put(STR_ROLE_CHANGE_DESC, ri.getRoleChangeDescription());
    retValue.put(STR_ROLE_CHANGE_DATE_TIME, ri.getRoleChangeDateTime().toString());
    return retValue;
}
项目:SDN-Multicast    文件:RoleManager.java   
/**
 * Set the controller's new role and notify switches.
 *
 * This method updates the controllers current role and notifies all
 * connected switches of the new role is different from the current
 * role. We dampen calls to this method. See class description for
 * details.
 *
 * @param role The new role.
 * @param roleChangeDescription A textual description of why the role
 * was changed. For information purposes only.
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public synchronized void setRole(@Nonnull HARole role, @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");

    if (role == getRole()) {
        counters.setSameRole.increment();
        log.debug("Received role request for {} but controller is "
                + "already {}. Ignoring it.", role, this.getRole());
        return;
    }

    if (this.getRole() == HARole.STANDBY && role == HARole.ACTIVE) {
        // At this point we are guaranteed that we will execute the code
        // below exactly once during the lifetime of this process! And
        // it will be a to MASTER transition
        counters.setRoleMaster.increment();
    }

    if (role == HARole.EQUAL) {
        if (this.getRole() == HARole.ACTIVE) {
            counters.setRoleEQUAL.increment();
        } else { // previous role was STANDBY
            //TODO: handle standby to EQUAL 
            log.debug("Received role request for {} but controller is "
                    + "in {}. returning as of now.", role, this.getRole());
            return;
        }
    }

    log.info("Received role request for {} (reason: {})."
            + " Initiating transition", role, roleChangeDescription);

    currentRoleInfo =
            new RoleInfo(role, roleChangeDescription, new Date());

    controller.addUpdateToQueue(new HARoleUpdate(role));
    controller.addUpdateToQueue(new SwitchRoleUpdate(role));

}
项目:SDN-Multicast    文件:ControllerTest.java   
@Test
public void testGetRoleInfoDefault() {
    RoleInfo info = controller.getRoleInfo();
    assertEquals(HARole.ACTIVE, info.getRole());
    assertNotNull(info.getRoleChangeDescription());
    assertEquals(HARole.ACTIVE, controller.getRole());
    // FIXME: RoleInfo's date. but the format is kinda broken
}
项目:SDN-Multicast    文件:ControllerTest.java   
/**
 * Start as SLAVE then set role to MASTER
 * Tests normal role change transition. Check that connected channels
 * receive a setRole request
 */
@Test
public void testSetRole() throws Exception {
    doSetUp(HARole.STANDBY);
    RoleInfo info = controller.getRoleInfo();
    assertEquals(HARole.STANDBY, info.getRole());
    assertEquals(HARole.STANDBY, controller.getRole());


    OFSwitchHandshakeHandler h = createMock(OFSwitchHandshakeHandler.class);

    // Reassert the role.
    reset(h);
    h.sendRoleRequestIfNotPending(OFControllerRole.ROLE_SLAVE);
    replay(h);
    controller.reassertRole(h, HARole.STANDBY);
    verify(h);

    // reassert a different role: no-op
    reset(h);
    replay(h);
    controller.reassertRole(h, HARole.ACTIVE);
    verify(h);

    IHAListener listener = createMock(IHAListener.class);
    expect(listener.getName()).andReturn("foo").anyTimes();
    setupListenerOrdering(listener);
    listener.transitionToActive();
    expectLastCall().once();
    replay(listener);
    controller.addHAListener(listener);
    controller.setRole(HARole.ACTIVE, "FooBar");
    controller.processUpdateQueueForTesting();
    verify(listener);
    info = controller.getRoleInfo();
    assertEquals(HARole.ACTIVE, info.getRole());
    assertEquals("FooBar", info.getRoleChangeDescription());
    assertEquals(HARole.ACTIVE, controller.getRole());
}
项目:arscheduler    文件:ControllerRoleResource.java   
@Get("json")
public Map<String, String> getRole() {
    IFloodlightProviderService floodlightProvider =
            (IFloodlightProviderService)getContext().getAttributes().
                get(IFloodlightProviderService.class.getCanonicalName());
    Map<String, String> retValue = new HashMap<String, String>();
    RoleInfo ri = floodlightProvider.getRoleInfo();
    retValue.put(STR_ROLE, ri.getRole().toString());
    retValue.put(STR_ROLE_CHANGE_DESC, ri.getRoleChangeDescription());
    retValue.put(STR_ROLE_CHANGE_DATE_TIME, ri.getRoleChangeDateTime().toString());
    return retValue;
}
项目:arscheduler    文件:RoleManager.java   
/**
 * Set the controller's new role and notify switches.
 *
 * This method updates the controllers current role and notifies all
 * connected switches of the new role is different from the current
 * role. We dampen calls to this method. See class description for
 * details.
 *
 * @param role The new role.
 * @param roleChangeDescription A textual description of why the role
 * was changed. For information purposes only.
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public synchronized void setRole(@Nonnull HARole role, @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");

    if (role == getRole()) {
        counters.setSameRole.increment();
        log.debug("Received role request for {} but controller is "
                + "already {}. Ignoring it.", role, this.getRole());
        return;
    }

    if (this.getRole() == HARole.STANDBY && role == HARole.ACTIVE) {
        // At this point we are guaranteed that we will execute the code
        // below exactly once during the lifetime of this process! And
        // it will be a to MASTER transition
        counters.setRoleMaster.increment();
    }

    log.info("Received role request for {} (reason: {})."
            + " Initiating transition", role, roleChangeDescription);

    currentRoleInfo =
            new RoleInfo(role, roleChangeDescription, new Date());

    controller.addUpdateToQueue(new HARoleUpdate(role));
    controller.addUpdateToQueue(new SwitchRoleUpdate(role));

}
项目:arscheduler    文件:ControllerTest.java   
@Test
public void testGetRoleInfoDefault() {
    RoleInfo info = controller.getRoleInfo();
    assertEquals(HARole.ACTIVE, info.getRole());
    assertNotNull(info.getRoleChangeDescription());
    assertEquals(HARole.ACTIVE, controller.getRole());
    // FIXME: RoleInfo's date. but the format is kinda broken
}
项目:arscheduler    文件:ControllerTest.java   
/**
 * Start as SLAVE then set role to MASTER
 * Tests normal role change transition. Check that connected channels
 * receive a setRole request
 */
@Test
public void testSetRole() throws Exception {
    doSetUp(HARole.STANDBY);
    RoleInfo info = controller.getRoleInfo();
    assertEquals(HARole.STANDBY, info.getRole());
    assertEquals(HARole.STANDBY, controller.getRole());


    OFSwitchHandshakeHandler h = createMock(OFSwitchHandshakeHandler.class);

    // Reassert the role.
    reset(h);
    h.sendRoleRequestIfNotPending(OFControllerRole.ROLE_SLAVE);
    replay(h);
    controller.reassertRole(h, HARole.STANDBY);
    verify(h);

    // reassert a different role: no-op
    reset(h);
    replay(h);
    controller.reassertRole(h, HARole.ACTIVE);
    verify(h);

    IHAListener listener = createMock(IHAListener.class);
    expect(listener.getName()).andReturn("foo").anyTimes();
    setupListenerOrdering(listener);
    listener.transitionToActive();
    expectLastCall().once();
    replay(listener);
    controller.addHAListener(listener);
    controller.setRole(HARole.ACTIVE, "FooBar");
    controller.processUpdateQueueForTesting();
    verify(listener);
    info = controller.getRoleInfo();
    assertEquals(HARole.ACTIVE, info.getRole());
    assertEquals("FooBar", info.getRoleChangeDescription());
    assertEquals(HARole.ACTIVE, controller.getRole());
}
项目:QoS-floodlight    文件:ControllerRoleResource.java   
@Get("json")
public RoleInfo getRole() {
    IFloodlightProviderService floodlightProvider =
            (IFloodlightProviderService)getContext().getAttributes().
                get(IFloodlightProviderService.class.getCanonicalName());
    return floodlightProvider.getRoleInfo();
}
项目:QoS-floodlight    文件:ControllerRoleResource.java   
@Post("json")
@LogMessageDoc(level="WARN",
               message="Invalid role value specified in REST API to " +
                  "set controller role",
               explanation="An HA role change request was malformed.",
               recommendation=LogMessageDoc.CHECK_CONTROLLER)
public void setRole(RoleInfo roleInfo) {
    //Role role = Role.lookupRole(roleInfo.getRole());
    Role role = null;
    try {
        role = Role.valueOf(roleInfo.getRole().toUpperCase());
    }
    catch (IllegalArgumentException e) {
        // The role value in the REST call didn't match a valid
        // role name, so just leave the role as null and handle
        // the error below.
    }
    if (role == null) {
        log.warn ("Invalid role value specified in REST API to " +
                  "set controller role");
        setStatus(Status.CLIENT_ERROR_BAD_REQUEST, "Invalid role value");
        return;
    }
    String roleChangeDescription = roleInfo.getRoleChangeDescription();
    if (roleChangeDescription == null)
        roleChangeDescription = "<none>";

    IFloodlightProviderService floodlightProvider =
            (IFloodlightProviderService)getContext().getAttributes().
                get(IFloodlightProviderService.class.getCanonicalName());

    floodlightProvider.setRole(role, roleChangeDescription);
}
项目:QoS-floodlight    文件:ControllerTest.java   
@Test
public void testGetRoleInfoDefault() {
    RoleInfo info = controller.getRoleInfo();
    assertEquals(Role.MASTER.toString(), info.getRole());
    assertNotNull(info.getRoleChangeDescription());
    assertEquals(Role.MASTER, controller.getRole());
    // FIXME: RoleInfo's date. but the format is kinda broken
}
项目:floodlight1.2-delay    文件:ControllerRoleResource.java   
@Get("json")
public Map<String, String> getRole() {
    IFloodlightProviderService floodlightProvider =
            (IFloodlightProviderService)getContext().getAttributes().
                get(IFloodlightProviderService.class.getCanonicalName());
    Map<String, String> retValue = new HashMap<String, String>();
    RoleInfo ri = floodlightProvider.getRoleInfo();
    retValue.put(STR_ROLE, ri.getRole().toString());
    retValue.put(STR_ROLE_CHANGE_DESC, ri.getRoleChangeDescription());
    retValue.put(STR_ROLE_CHANGE_DATE_TIME, ri.getRoleChangeDateTime().toString());
    return retValue;
}
项目:floodlight1.2-delay    文件:RoleManager.java   
/**
 * Set the controller's new role and notify switches.
 *
 * This method updates the controllers current role and notifies all
 * connected switches of the new role is different from the current
 * role. We dampen calls to this method. See class description for
 * details.
 *
 * @param role The new role.
 * @param roleChangeDescription A textual description of why the role
 * was changed. For information purposes only.
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public synchronized void setRole(@Nonnull HARole role, @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");

    if (role == getRole()) {
        counters.setSameRole.increment();
        log.debug("Received role request for {} but controller is "
                + "already {}. Ignoring it.", role, this.getRole());
        return;
    }

    if (this.getRole() == HARole.STANDBY && role == HARole.ACTIVE) {
        // At this point we are guaranteed that we will execute the code
        // below exactly once during the lifetime of this process! And
        // it will be a to MASTER transition
        counters.setRoleMaster.increment();
    }

    log.info("Received role request for {} (reason: {})."
            + " Initiating transition", role, roleChangeDescription);

    currentRoleInfo =
            new RoleInfo(role, roleChangeDescription, new Date());

    controller.addUpdateToQueue(new HARoleUpdate(role));
    controller.addUpdateToQueue(new SwitchRoleUpdate(role));

}
项目:floodlight1.2-delay    文件:ControllerTest.java   
@Test
public void testGetRoleInfoDefault() {
    RoleInfo info = controller.getRoleInfo();
    assertEquals(HARole.ACTIVE, info.getRole());
    assertNotNull(info.getRoleChangeDescription());
    assertEquals(HARole.ACTIVE, controller.getRole());
    // FIXME: RoleInfo's date. but the format is kinda broken
}
项目:floodlight1.2-delay    文件:ControllerTest.java   
/**
 * Start as SLAVE then set role to MASTER
 * Tests normal role change transition. Check that connected channels
 * receive a setRole request
 */
@Test
public void testSetRole() throws Exception {
    doSetUp(HARole.STANDBY);
    RoleInfo info = controller.getRoleInfo();
    assertEquals(HARole.STANDBY, info.getRole());
    assertEquals(HARole.STANDBY, controller.getRole());


    OFSwitchHandshakeHandler h = createMock(OFSwitchHandshakeHandler.class);

    // Reassert the role.
    reset(h);
    h.sendRoleRequestIfNotPending(OFControllerRole.ROLE_SLAVE);
    replay(h);
    controller.reassertRole(h, HARole.STANDBY);
    verify(h);

    // reassert a different role: no-op
    reset(h);
    replay(h);
    controller.reassertRole(h, HARole.ACTIVE);
    verify(h);

    IHAListener listener = createMock(IHAListener.class);
    expect(listener.getName()).andReturn("foo").anyTimes();
    setupListenerOrdering(listener);
    listener.transitionToActive();
    expectLastCall().once();
    replay(listener);
    controller.addHAListener(listener);
    controller.setRole(HARole.ACTIVE, "FooBar");
    controller.processUpdateQueueForTesting();
    verify(listener);
    info = controller.getRoleInfo();
    assertEquals(HARole.ACTIVE, info.getRole());
    assertEquals("FooBar", info.getRoleChangeDescription());
    assertEquals(HARole.ACTIVE, controller.getRole());
}
项目:floodlight-hardware    文件:ControllerRoleResource.java   
@Get("json")
public Map<String, String> getRole() {
    IFloodlightProviderService floodlightProvider =
            (IFloodlightProviderService)getContext().getAttributes().
                get(IFloodlightProviderService.class.getCanonicalName());
    Map<String, String> retValue = new HashMap<String, String>();
    RoleInfo ri = floodlightProvider.getRoleInfo();
    retValue.put(STR_ROLE, ri.getRole().toString());
    retValue.put(STR_ROLE_CHANGE_DESC, ri.getRoleChangeDescription());
    retValue.put(STR_ROLE_CHANGE_DATE_TIME, ri.getRoleChangeDateTime().toString());
    return retValue;
}
项目:floodlight-hardware    文件:RoleManager.java   
/**
 * Set the controller's new role and notify switches.
 *
 * This method updates the controllers current role and notifies all
 * connected switches of the new role is different from the current
 * role. We dampen calls to this method. See class description for
 * details.
 *
 * @param role The new role.
 * @param roleChangeDescription A textual description of why the role
 * was changed. For information purposes only.
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public synchronized void setRole(@Nonnull HARole role, @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");

    if (role == getRole()) {
        counters.setSameRole.increment();
        log.debug("Received role request for {} but controller is "
                + "already {}. Ignoring it.", role, this.getRole());
        return;
    }

    if (this.getRole() == HARole.STANDBY && role == HARole.ACTIVE) {
        // At this point we are guaranteed that we will execute the code
        // below exactly once during the lifetime of this process! And
        // it will be a to MASTER transition
        counters.setRoleMaster.increment();
    }

    log.info("Received role request for {} (reason: {})."
            + " Initiating transition", role, roleChangeDescription);

    currentRoleInfo =
            new RoleInfo(role, roleChangeDescription, new Date());

    controller.addUpdateToQueue(new HARoleUpdate(role));
    controller.addUpdateToQueue(new SwitchRoleUpdate(role));

}
项目:floodlight-hardware    文件:ControllerTest.java   
@Test
public void testGetRoleInfoDefault() {
    RoleInfo info = controller.getRoleInfo();
    assertEquals(HARole.ACTIVE, info.getRole());
    assertNotNull(info.getRoleChangeDescription());
    assertEquals(HARole.ACTIVE, controller.getRole());
    // FIXME: RoleInfo's date. but the format is kinda broken
}