@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);
  }
Пример #2
0
 @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
 }
Пример #3
0
  /**
   * 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());
  }