@Test(expected = BadRequestException.class)
    public void shouldVerifySharedVipLbs() throws Exception {

      List<LoadBalancer> lbs = new ArrayList<LoadBalancer>();
      LoadBalancer loadBalancer = new LoadBalancer();
      loadBalancer.setId(3333);
      loadBalancer.setAccountId(55555);

      Set<LoadBalancerJoinVip> jvips = new HashSet<LoadBalancerJoinVip>();
      LoadBalancerJoinVip jvip = new LoadBalancerJoinVip();

      jvip.setVirtualIp(new VirtualIp());
      jvip.setId(new LoadBalancerJoinVip.Id(loadBalancer.getId(), 676));
      jvip.setLoadBalancer(lb);
      jvips.add(jvip);
      loadBalancer.setLoadBalancerJoinVipSet(jvips);

      List<LoadBalancer> sharedlbs = new ArrayList<LoadBalancer>();
      LoadBalancer sharedlb = new LoadBalancer();
      sharedlb.setId(9844);
      sharedlbs.add(sharedlb);
      when(virtualIpRepository.getLoadBalancersByVipId(Matchers.anyInt())).thenReturn(sharedlbs);

      lbs.add(loadBalancer);

      when(lbRepository.getById(Matchers.anyInt())).thenReturn(loadBalancer);
      List<LoadBalancer> newLbs;
      newLbs = lbService.reassignLoadBalancerHost(lbs);

      LoadBalancer newLb;
      newLb = newLbs.get(0);

      Assert.assertEquals((Object) 55555, newLb.getAccountId());
    }
    @Test
    public void shouldAddNewAccessListLoadBalancerWhenOperationSucceeds() throws Exception {
      List<AccessList> accessListsBefore =
          accessListService.getAccessListByAccountIdLoadBalancerId(
              loadBalancer.getAccountId(), loadBalancer.getId());

      LoadBalancer newLoadBalancer = new LoadBalancer();
      newLoadBalancer.setId(loadBalancer.getId());
      newLoadBalancer.setAccountId(loadBalancer.getAccountId());

      accessList.setLoadbalancer(loadBalancer);
      newLoadBalancer.addAccessList(accessList);

      accessListService.updateAccessList(newLoadBalancer);

      List<AccessList> accessListsAfter =
          accessListService.getAccessListByAccountIdLoadBalancerId(
              loadBalancer.getAccountId(), loadBalancer.getId());
      Assert.assertEquals(accessListsBefore.size() + 1, accessListsAfter.size());
    }
    @Test(expected = ImmutableEntityException.class)
    public void shouldThrowExceptionWhenLoaBalancerNotActive() throws Exception {
      loadBalancerService.setStatus(loadBalancer, LoadBalancerStatus.ERROR);

      LoadBalancer newLoadBalancer = new LoadBalancer();
      newLoadBalancer.setId(loadBalancer.getId());
      newLoadBalancer.setAccountId(loadBalancer.getAccountId());

      newLoadBalancer.addAccessList(accessList);

      accessListService.updateAccessList(newLoadBalancer);
    }
 private void sendErrorToEventResource(LoadBalancer lb) {
   String title = "Error Updating Session Persistence";
   String desc = "Could not update the session persistence settings at this time.";
   notificationService.saveSessionPersistenceEvent(
       lb.getUserName(),
       lb.getAccountId(),
       lb.getId(),
       title,
       desc,
       UPDATE_SESSION_PERSISTENCE,
       UPDATE,
       CRITICAL);
 }
    @Test(expected = BadRequestException.class)
    public void shouldThrowExceptionWhenAccessListLimitExceeded() throws Exception {
      LoadBalancer newLoadBalancer = new LoadBalancer();
      newLoadBalancer.setId(loadBalancer.getId());
      newLoadBalancer.setAccountId(loadBalancer.getAccountId());

      accessList.setLoadbalancer(loadBalancer);
      for (int i = 0; i < 101; i++) {
        accessList = new AccessList();
        accessList.setIpAddress("new ip " + i);
        accessList.setType(AccessListType.ALLOW);
        newLoadBalancer.addAccessList(accessList);
      }

      accessListService.updateAccessList(newLoadBalancer);
    }
    @Test(expected = BadRequestException.class)
    public void shouldThrowExceptionWhenDuplicateAccessLists() throws Exception {
      LoadBalancer newLoadBalancer = new LoadBalancer();
      newLoadBalancer.setId(loadBalancer.getId());
      newLoadBalancer.setAccountId(loadBalancer.getAccountId());

      accessList.setLoadbalancer(loadBalancer);
      newLoadBalancer.addAccessList(accessList);

      accessListService.updateAccessList(newLoadBalancer);

      loadBalancerService.setStatus(loadBalancer, LoadBalancerStatus.ACTIVE);

      newLoadBalancer.addAccessList(accessList);
      accessListService.updateAccessList(newLoadBalancer);
    }
  @Override
  public void doOnMessage(final Message message) throws Exception {
    LOG.debug("Entering " + getClass());
    LOG.debug(message);
    LoadBalancer queueLb = getLoadbalancerFromMessage(message);
    LoadBalancer dbLoadBalancer;

    try {
      dbLoadBalancer = loadBalancerService.get(queueLb.getId(), queueLb.getAccountId());
    } catch (EntityNotFoundException enfe) {
      String alertDescription =
          String.format("Load balancer '%d' not found in database.", queueLb.getId());
      LOG.error(alertDescription, enfe);
      notificationService.saveAlert(
          queueLb.getAccountId(), queueLb.getId(), enfe, DATABASE_FAILURE.name(), alertDescription);
      sendErrorToEventResource(queueLb);
      return;
    }

    try {
      if (isRestAdapter()) {
        LOG.debug(
            String.format(
                "Updating session persistence for load balancer '%d' in STM...",
                dbLoadBalancer.getId()));
        reverseProxyLoadBalancerStmService.updateLoadBalancer(
            dbLoadBalancer,
            queueLb,
            loadBalancerService.getUserPages(queueLb.getId(), queueLb.getAccountId()));
        LOG.debug(
            String.format(
                "Successfully updated session persistence for load balancer '%d' in Zeus...",
                dbLoadBalancer.getId()));
      } else {
        if (dbLoadBalancer.getSessionPersistence() != SessionPersistence.NONE) {
          LOG.debug(
              String.format(
                  "Updating session persistence for load balancer '%d' in ZXTM...",
                  dbLoadBalancer.getId()));
          reverseProxyLoadBalancerService.updateSessionPersistence(
              dbLoadBalancer.getId(),
              dbLoadBalancer.getAccountId(),
              dbLoadBalancer.getSessionPersistence());
          LOG.debug(
              String.format(
                  "Successfully updated session persistence for load balancer '%d' in Zeus...",
                  dbLoadBalancer.getId()));
        }
      }
    } catch (Exception e) {
      loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR);
      String alertDescription =
          String.format(
              "Error updating session persistence in Zeus for loadbalancer '%d'.",
              dbLoadBalancer.getId());
      LOG.error(alertDescription, e);
      notificationService.saveAlert(
          dbLoadBalancer.getAccountId(),
          dbLoadBalancer.getId(),
          e,
          ZEUS_FAILURE.name(),
          alertDescription);
      sendErrorToEventResource(queueLb);

      return;
    }

    // Update load balancer status in DB
    loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE);

    if (dbLoadBalancer.getSessionPersistence() != SessionPersistence.NONE) {
      // Add atom entry
      String atomSummary =
          String.format(
              "Session persistence successfully updated to '%s'",
              dbLoadBalancer.getSessionPersistence().name());
      notificationService.saveSessionPersistenceEvent(
          queueLb.getUserName(),
          dbLoadBalancer.getAccountId(),
          dbLoadBalancer.getId(),
          UPDATE_PERSISTENCE_TITLE,
          atomSummary,
          UPDATE_SESSION_PERSISTENCE,
          UPDATE,
          INFO);
    }

    LOG.info(
        String.format(
            "Update session persistence operation complete for load balancer '%d'.",
            dbLoadBalancer.getId()));
  }
Пример #8
0
 protected static String errorFileName() throws InsufficientRequestException {
   return ZxtmNameBuilder.generateErrorPageName(lb.getId(), lb.getAccountId());
 }