@Before
    public void standUp() throws EntityNotFoundException, UnprocessableEntityException {
      lb = new LoadBalancer();
      lbRepository = mock(LoadBalancerRepository.class);
      lbService = new LoadBalancerServiceImpl();
      lbService.setLoadBalancerRepository(lbRepository);

      SslTermination sslTermination = new SslTermination();
      sslTermination.setIntermediateCertificate("iCert");
      sslTermination.setCertificate("cert");
      sslTermination.setPrivatekey("aKey");
      sslTermination.setEnabled(true);
      sslTermination.setSecurePort(445);
      sslTermination.setSecureTrafficOnly(false);

      lb.setSslTermination(sslTermination);
      lb.setStatus(LoadBalancerStatus.ACTIVE);

      defaultProtocol =
          new LoadBalancerProtocolObject(LoadBalancerProtocol.HTTP, "HTTP Protocol", 80, true);
      when(lbRepository.getByIdAndAccountId(Matchers.<Integer>any(), Matchers.<Integer>any()))
          .thenReturn(lb);
      //            when(lbRepository.testAndSetStatus(Matchers.<Integer>any(),
      // Matchers.<Integer>any(),Matchers.<LoadBalancerStatus>any(),
      // Matchers.<Boolean>any())).thenReturn(true);

    }
 /**
  * Configure and reload the load balancer
  *
  * @throws LoadBalancerExtensionException if the configuration or reload process fails
  */
 private void configureAndReload() throws LoadBalancerExtensionException {
   // Configure load balancer
   if (loadBalancer.configure(topologyProvider.getTopology())) {
     // Reload the load balancer
     loadBalancer.reload();
   }
 }
    @Test
    public void shouldSetStatusToBuildWhenStatusIsModified() {
      lb.setStatus(LoadBalancerStatus.ERROR);

      lbService.addDefaultValues(lb);

      Assert.assertEquals(LoadBalancerStatus.BUILD, lb.getStatus());
    }
    @Test(expected = BadRequestException.class)
    public void shouldRejectUpdateProtocolIfUsingSslTermination() throws Exception {
      LoadBalancer loadBalancer = new LoadBalancer();
      loadBalancer.setProtocol(LoadBalancerProtocol.HTTPS);
      loadBalancer.setStatus(LoadBalancerStatus.ACTIVE);

      lbService.prepareForUpdate(loadBalancer);
    }
    @Test(expected = BadRequestException.class)
    public void shouldFailWhenUpdatingPortToSSLPort() throws Exception {

      LoadBalancer loadBalancer = new LoadBalancer();
      loadBalancer.setStatus(LoadBalancerStatus.ACTIVE);
      loadBalancer.setPort(445);

      lbService.prepareForUpdate(loadBalancer);
    }
    @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());
    }
  /**
   * Configure and start the load balancer
   *
   * @throws LoadBalancerExtensionException if configuration or start process fails
   */
  private void configureAndStart() throws LoadBalancerExtensionException {
    // Initialize topology
    if (!topologyEventReceiver.isInitialized()) {
      topologyEventReceiver.initializeTopology();
    }

    // Configure load balancer
    Topology topology = topologyProvider.getTopology();
    if (topologyPopulated(topology) && loadBalancer.configure(topology)) {
      // Start load balancer
      loadBalancer.start();
      loadBalancerStarted = true;
    }
  }
  private void testNodes() throws IOException {
    System.out.println("Start testing.");
    long startTime = System.currentTimeMillis();

    StringReader stringReader = new StringReader(readTestData());
    Instances instances = new Instances(stringReader);
    instances.setClassIndex(instances.numAttributes() - 1);

    System.out.println("Starting testing of " + instances.numInstances() + " instances in total.");
    LoadBalancer loadBalancer = new LoadBalancer(daoList, instances);
    loadBalancer.start();

    long testTime = System.currentTimeMillis() - startTime;
    System.out.println("Finished testing in " + testTime + " ms");
  }
    @Test
    public void shouldNotAddDefaultValuesWhenValuesAreSet() {
      lb.setAlgorithm(LoadBalancerAlgorithm.LEAST_CONNECTIONS);
      lb.setProtocol(LoadBalancerProtocol.IMAPv3);
      lb.setConnectionLogging(true);
      lb.setPort(1234);
      lb.setSessionPersistence(SessionPersistence.HTTP_COOKIE);

      lbService.addDefaultValues(lb);

      Assert.assertEquals(LoadBalancerAlgorithm.LEAST_CONNECTIONS, lb.getAlgorithm());
      Assert.assertEquals(LoadBalancerProtocol.IMAPv3, lb.getProtocol());
      Assert.assertTrue(lb.isConnectionLogging());
      Assert.assertEquals(1234, lb.getPort().intValue());
      Assert.assertEquals(SessionPersistence.HTTP_COOKIE, lb.getSessionPersistence());
    }
    @Test
    public void shouldUpdateNodesStatusAndWeightsAppropriately() {
      Set<Node> nodes = new HashSet<Node>();
      Node node1 = new Node();
      Node node2 = new Node();
      Node node3 = new Node();

      node1.setCondition(NodeCondition.ENABLED);
      node2.setCondition(NodeCondition.DRAINING);
      node3.setCondition(NodeCondition.DISABLED);
      node1.setWeight(null);
      node2.setWeight(0);
      node3.setWeight(10);
      nodes.add(node1);
      nodes.add(node2);
      nodes.add(node3);
      lb.setNodes(nodes);

      lbService.addDefaultValues(lb);

      Assert.assertEquals(NodeStatus.ONLINE, node1.getStatus());
      Assert.assertEquals(NodeStatus.ONLINE, node2.getStatus());
      Assert.assertEquals(NodeStatus.ONLINE, node3.getStatus());

      Assert.assertEquals(1, node1.getWeight().intValue());
      Assert.assertEquals(0, node2.getWeight().intValue());
      Assert.assertEquals(10, node3.getWeight().intValue());
    }
    @Test(expected = BadRequestException.class)
    public void shouldFailIfLbisSticky() throws Exception {
      when(lbRepository.getById(Matchers.<Integer>any())).thenReturn(lb);

      List<LoadBalancer> lbs = new ArrayList<LoadBalancer>();
      LoadBalancer loadBalancer = new LoadBalancer();
      loadBalancer.setId(3333);
      lb.setSticky(true);
      lbs.add(loadBalancer);

      List<LoadBalancer> newLbs;
      newLbs = lbService.reassignLoadBalancerHost(lbs);

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

      Assert.assertEquals((Object) 555555, newLb.getAccountId());
    }
Beispiel #12
0
  protected static void setupIvars() {
    Set<LoadBalancerJoinVip> vipList = new HashSet<LoadBalancerJoinVip>();
    vip1 = new VirtualIp();
    vip1.setId(TEST_VIP_ID);
    vip1.setIpAddress("10.69.0.59");
    vip2 = new VirtualIp();
    vip2.setId(TEST_VIP_ID + 1);
    vip2.setIpAddress("10.69.0.60");
    LoadBalancerJoinVip loadBalancerJoinVip = new LoadBalancerJoinVip();
    loadBalancerJoinVip.setVirtualIp(vip1);
    vipList.add(loadBalancerJoinVip);
    loadBalancerJoinVip = new LoadBalancerJoinVip();
    loadBalancerJoinVip.setVirtualIp(vip2);
    vipList.add(loadBalancerJoinVip);

    Set<Node> nodeList = new HashSet<Node>();
    node1 = new Node();
    node2 = new Node();
    node1.setIpAddress("127.0.0.1");
    node2.setIpAddress("127.0.0.2");
    node1.setPort(80);
    node2.setPort(80);
    node1.setCondition(ENABLED);
    node2.setCondition(DISABLED);
    node1.setWeight(1);
    node2.setWeight(1);
    nodeList.add(node1);
    nodeList.add(node2);

    LoadBalancer lb = new LoadBalancer();
    lb.setId(TEST_LOADBALANCER_ID);
    lb.setAccountId(TEST_ACCOUNT_ID);
    lb.setPort(80);
    lb.setAlgorithm(ROUND_ROBIN);
    lb.setName("STM-TESTER");
    lb.setProtocol(HTTP);
    lb.setNodes(nodeList);
    lb.setLoadBalancerJoinVipSet(vipList);

    lb.setUserPages(new UserPages());

    STMTestBase.lb = lb;
  }
    @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());
    }
    @Before
    public void setUp() throws Exception {
      loadBalancer = new LoadBalancer();
      loadBalancer.setAccountId(1000);
      loadBalancer.setName("integration testing");
      loadBalancer.setPort(80);
      loadBalancer.setProtocol(LoadBalancerProtocol.POP3);

      Set<Node> nodes = new HashSet<Node>();
      Node node = new Node();
      node.setIpAddress("2.2.2.2");
      node.setPort(80);
      node.setCondition(NodeCondition.ENABLED);
      nodes.add(node);
      loadBalancer.setNodes(nodes);

      UserPages userPages = new UserPages();
      userPages.setErrorpage("aError");
      userPages.setLoadbalancer(loadBalancer);
      loadBalancer.setUserPages(userPages);

      loadBalancer = createLoadBalancerInActiveStatus(loadBalancer);

      accessList = new AccessList();
      accessList.setIpAddress("new ip");
      accessList.setType(AccessListType.ALLOW);
    }
    @Test
    public void shouldAddDefaultValuesWhenNoValuesAreSet() {
      lbService.addDefaultValues(lb);

      Assert.assertEquals(LoadBalancerAlgorithm.RANDOM, lb.getAlgorithm());
      Assert.assertEquals(LoadBalancerProtocol.HTTP, lb.getProtocol());
      Assert.assertFalse(lb.isConnectionLogging());
      Assert.assertEquals(defaultProtocol.getPort(), lb.getPort());
      Assert.assertEquals(SessionPersistence.NONE, lb.getSessionPersistence());
      Assert.assertEquals(LoadBalancerStatus.BUILD, lb.getStatus());
      Assert.assertEquals(false, lb.isHalfClosed());
    }
 private void start() {
   lifecycleService.setStarted();
   connectionManager.start();
   try {
     clusterService.start();
   } catch (IllegalStateException e) {
     // there was an authentication failure (todo: perhaps use an AuthenticationException
     // ??)
     lifecycleService.shutdown();
     throw e;
   }
   loadBalancer.init(getCluster(), config);
   partitionService.start();
 }
    @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);
    }
    @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);
    }
  /** Stop load balancer instance. */
  public void stop() {
    try {
      if (topologyEventReceiver != null) {
        topologyEventReceiver.terminate();
      }
    } catch (Exception ignore) {
    }

    try {
      if (statisticsNotifier != null) {
        statisticsNotifier.terminate();
      }
    } catch (Exception ignore) {
    }

    try {
      loadBalancer.stop();
    } catch (Exception ignore) {
    }
  }
    @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);
    }
Beispiel #21
0
 public Queue(LoadBalancer loadBalancer) {
   this.loadBalancer = loadBalancer.sanitize();
   // if all the executors are busy doing something, then the queue won't be maintained in
   // timely fashion, so use another thread to make sure it happens.
   new MaintainTask(this);
 }
    @Before
    public void standUp()
        throws EntityNotFoundException, UnprocessableEntityException, ClusterStatusException,
            NoAvailableClusterException {
      lb = new LoadBalancer();
      lbRepository = mock(LoadBalancerRepository.class);
      lbService = new LoadBalancerServiceImpl();
      lbService.setLoadBalancerRepository(lbRepository);

      hostService = new HostServiceImpl();
      hostService.setLoadBalancerRepository(lbRepository);
      hostRepository = mock(HostRepository.class);
      hostService.setHostRepository(hostRepository);

      clusterService = new ClusterServiceImpl();
      clusterService.setLoadBalancerRepository(lbRepository);
      clusterRepository = mock(ClusterRepository.class);
      clusterService.setClusterRepository(clusterRepository);

      virtualIpRepository = mock(VirtualIpRepository.class);

      loadBalancerStatusHistoryRepository = mock(LoadBalancerStatusHistoryRepository.class);
      loadBalancerStatusHistoryService = new LoadBalancerStatusHistoryServiceImpl();
      loadBalancerStatusHistoryService.setLoadBalancerStatusHistoryRepository(
          loadBalancerStatusHistoryRepository);

      hostService.setClusterRepository(clusterRepository);
      //            lbService.setHostService(hostService);
      //            lbService.setLoadBalancerStatusHistoryService(loadBalancerStatusHistoryService);
      lbService.setVirtualIpRepository(virtualIpRepository);

      lb.setStatus(LoadBalancerStatus.ACTIVE);

      lb.setAccountId(555555);
      lb.setId(3333);
      lb.setPort(33);
      lb.setProtocol(LoadBalancerProtocol.HTTP);

      Host host = new Host();
      host.setId(2);
      host.setHostStatus(HostStatus.ACTIVE);

      Cluster cluster = new Cluster();
      cluster.setId(3);

      lb.setHost(host);

      when(hostRepository.getById(Matchers.<Integer>any())).thenReturn(host);
      when(hostRepository.getDefaultActiveHost(Matchers.<Integer>any())).thenReturn(host);
      when(clusterRepository.getActiveCluster(null, false)).thenReturn(cluster);
      when(hostService.getById(Matchers.<Integer>any())).thenReturn(host);
      when(loadBalancerStatusHistoryRepository.save(
              Matchers.<LoadBalancerStatusHistory>anyObject()))
          .thenReturn(new LoadBalancerStatusHistory());

      //            when(loadBalancerStatusHistoryService.save(lb.getAccountId(), lb.getId(),
      // status);)
      //            when(lbRepository.testAndSetStatus(Matchers.<Integer>any(),
      // Matchers.<Integer>any(),Matchers.<LoadBalancerStatus>any(),
      // Matchers.<Boolean>any())).thenReturn(true);

    }
Beispiel #23
0
  public static void run(
      SIRStream str,
      JInterfaceDeclaration[] interfaces,
      SIRInterfaceTable[] interfaceTables,
      SIRStructure[] structs,
      SIRHelper[] helpers,
      SIRGlobal global) {
    System.out.println("Entry to SMP Backend...");

    checkArguments();
    setScheduler();

    if (KjcOptions.smp > 16) {
      setupLargeConfig();
    }

    // create cores in desired amount and order
    int[] cores = new int[KjcOptions.smp];
    for (int x = 0; x < KjcOptions.smp; x++) cores[x] = coreOrder[x];
    chip = new SMPMachine(cores);

    // create a new structs.h file for typedefs etc.
    structs_h = new Structs_h(structs);

    // The usual optimizations and transformation to slice graph
    CommonPasses commonPasses = new CommonPasses();
    // perform standard optimizations, use the number of cores the user wants to target
    commonPasses.run(str, interfaces, interfaceTables, structs, helpers, global, chip.size());
    // perform some standard cleanup on the slice graph.
    commonPasses.simplifySlices();
    // dump slice graph to dot file
    commonPasses.getSlicer().dumpGraph("traces.dot", null);

    // partition the slice graph based on the scheduling policy
    SpaceTimeScheduleAndSlicer graphSchedule =
        new SpaceTimeScheduleAndSlicer(commonPasses.getSlicer());
    scheduler.setGraphSchedule(graphSchedule);
    scheduler.run(chip.size());
    FilterInfo.reset();

    // generate schedules for initialization, primepump and steady-state
    scheduleSlices(graphSchedule);

    // generate layout for filters
    scheduler.runLayout();

    // dump final slice graph to dot file
    graphSchedule.getSlicer().dumpGraph("after_slice_partition.dot", scheduler);
    graphSchedule.getSlicer().dumpGraph("slice_graph.dot", scheduler, false);

    // if load balancing, find candidiate fission groups to load balance
    if (KjcOptions.loadbalance) {
      LoadBalancer.findCandidates();
      LoadBalancer.instrumentMainMethods();
    }

    // create all buffers and set the rotation lengths
    RotatingBuffer.createBuffers(graphSchedule);

    // now convert to Kopi code plus communication commands
    backEndBits = new SMPBackEndFactory(chip, scheduler);
    backEndBits.getBackEndMain().run(graphSchedule, backEndBits);

    // generate code for file writer
    CoreCodeStore.generatePrintOutputCode();

    if (KjcOptions.numbers > 0) chip.getNthComputeNode(0).getComputeCode().generateNumbersCode();

    // emit c code for all cores
    EmitSMPCode.doit(backEndBits);

    // dump structs.h file
    structs_h.writeToFile();

    // display final assignment of filters to cores
    System.out.println("Final filter assignments:");
    System.out.println("========================================");
    for (int x = 0; x < KjcOptions.smp; x++) {
      Core core = chip.getNthComputeNode(x);
      Set<FilterSliceNode> filters = core.getComputeCode().getFilters();
      long totalWork = 0;

      System.out.println("Core " + core.getCoreID() + ": ");
      for (FilterSliceNode filter : filters) {
        long work = SliceWorkEstimate.getWork(filter.getParent());
        System.out.format("%16d | " + filter + "\n", work);
        totalWork += work;
      }
      System.out.format("%16d | Total\n", totalWork);
    }

    // calculate computation to communication ratio
    if (KjcOptions.sharedbufs) {
      LinkedList<Slice> slices =
          DataFlowOrder.getTraversal(graphSchedule.getSlicer().getTopSlices());
      HashSet<Slice> compProcessed = new HashSet<Slice>();
      HashSet<Slice> commProcessed = new HashSet<Slice>();

      long comp = 0;
      long comm = 0;

      for (Slice slice : slices) {
        if (compProcessed.contains(slice)) continue;

        comp += SliceWorkEstimate.getWork(slice);
        compProcessed.add(slice);
      }

      /*
                  for(Slice slice : slices) {
                      if(commProcessed.contains(slice))
                          continue;

                      FilterInfo info = FilterInfo.getFilterInfo(slice.getFirstFilter());
                      int totalItemsReceived = info.totalItemsReceived(SchedulingPhase.STEADY);

                      if(totalItemsReceived == 0)
                          continue;

                      InputSliceNode input = slice.getHead();
                      Set<InterSliceEdge> sources = input.getSourceSet(SchedulingPhase.STEADY);
                      int numInputRots = totalItemsReceived / input.totalWeights(SchedulingPhase.STEADY);

                      if(!FissionGroupStore.isFizzed(slice)) {
                          for(InterSliceEdge source : sources) {
                              Slice srcSlice = source.getSrc().getParent();

      //                         if(srcSlice.getFirstFilter().isFileInput())
      //                             continue;

                              if(FissionGroupStore.isFizzed(srcSlice)) {
                                  // Filter is not fizzed, source is fizzed
                                  // Filter must receive (N-1)/N of inputs from different cores
                                  comm += numInputRots *
                                      input.getWeight(source, SchedulingPhase.STEADY) /
                                      KjcOptions.smp * (KjcOptions.smp - 1);
                              }
                              else {
                                  // Filter is not fizzed, source is not fizzed
                                  // Check to see if on same core
                                  // If not, must communicate all elements
                                  if(!scheduler.getComputeNode(slice.getFirstFilter()).equals(
                                         scheduler.getComputeNode(srcSlice.getFirstFilter()))) {
                                      comm += numInputRots *
                                          input.getWeight(source, SchedulingPhase.STEADY);
                                  }
                              }
                          }
                      }
                      else {
                          for(InterSliceEdge source : sources) {
                              Slice srcSlice = source.getSrc().getParent();

      //                         if(srcSlice.getFirstFilter().isFileInput())
      //                             continue;

                              if(FissionGroupStore.isFizzed(srcSlice)) {
                                  // Filter is fizzed, source is also fizzed
                                  int totalItemsReceivedPerFizzed = totalItemsReceived /
                                      FissionGroupStore.getFissionGroup(slice).fizzedSlices.length;
                                  int numInputRotsPerFizzed = numInputRots /
                                      FissionGroupStore.getFissionGroup(slice).fizzedSlices.length;

                                  System.out.println("totalItemsReceivedPerFizzed: " + totalItemsReceivedPerFizzed);
                                  System.out.println("numInputRotsPerFizzed: " + numInputRotsPerFizzed);

                                  int inputWeightBeforeSrc =
                                      input.weightBefore(source, SchedulingPhase.STEADY);
                                  int inputWeightSrc = input.getWeight(source, SchedulingPhase.STEADY);
                                  int inputTotalWeight = input.totalWeights(SchedulingPhase.STEADY);

                                  System.out.println("inputWeightBeforeSrc: " + inputWeightBeforeSrc);
                                  System.out.println("inputWeightSrc: " + inputWeightSrc);
                                  System.out.println("copyDown: " + info.copyDown);

                                  int numXmit = 0;

                                  for(int rot = 0 ; rot < numInputRotsPerFizzed ; rot++) {
                                      numXmit += Math.min(inputWeightSrc,
                                                          Math.max(0,
                                                                   info.copyDown +
                                                                   rot * inputTotalWeight +
                                                                   inputWeightBeforeSrc + inputWeightSrc -
                                                                   totalItemsReceivedPerFizzed));
                                  }

                                  System.out.println("numXmit: " + numXmit);

                                  comm += KjcOptions.smp * numXmit;
                              }
                              else {
                                  // Filter is fizzed, source is not fizzed
                                  // Source must send (N-1)/N of outputs to different cores
                                  comm += numInputRots *
                                      input.getWeight(source, SchedulingPhase.STEADY) /
                                      KjcOptions.smp * (KjcOptions.smp - 1);
                              }
                          }
                      }

                      commProcessed.add(slice);
                  }
                  */

      // Simple communication estimation
      for (Slice slice : slices) {
        if (commProcessed.contains(slice)) continue;

        FilterInfo info = FilterInfo.getFilterInfo(slice.getFirstFilter());
        int totalItemsReceived = info.totalItemsReceived(SchedulingPhase.STEADY);

        if (totalItemsReceived == 0) continue;

        comm += totalItemsReceived;

        if (FissionGroupStore.isFizzed(slice)) {
          assert info.peek >= info.pop;
          comm += (info.peek - info.pop) * KjcOptions.smp;
        }

        commProcessed.add(slice);
      }

      // Simple communication estimation 2
      /*
      for(Slice slice : slices) {
          if(commProcessed.contains(slice))
              continue;

          FilterInfo info = FilterInfo.getFilterInfo(slice.getFirstFilter());
          int totalItemsReceived = info.totalItemsReceived(SchedulingPhase.STEADY);
          int totalItemsSent = info.totalItemsSent(SchedulingPhase.STEADY);

          comm += totalItemsReceived;
          comm += totalItemsSent;

          if(totalItemsReceived == 0)
              continue;

          if(FissionGroupStore.isFizzed(slice)) {
              assert info.peek >= info.pop;
              comm += (info.peek - info.pop) * KjcOptions.smp;
          }

          commProcessed.add(slice);
      }
      */

      System.out.println("Final Computation: " + comp);
      System.out.println("Final Communication: " + comm);
      System.out.println("Final Comp/Comm Ratio: " + (float) comp / (float) comm);
    }

    System.exit(0);
  }
 public static LoadBalancer generateLoadBalancer() {
   LoadBalancer loadBalancer = new LoadBalancer();
   loadBalancer.setPort(port);
   Set<AccessList> accessLists = new HashSet<AccessList>();
   AccessList item = new AccessList();
   item.setUserName(username);
   item.setId(id);
   item.setIpAddress(ipv42);
   item.setType(AccessListType.DENY);
   item.setLoadbalancer(loadBalancer);
   accessLists.add(item);
   loadBalancer.setAccessLists(accessLists);
   loadBalancer.setAccountId(accountId);
   loadBalancer.setAlgorithm(LoadBalancerAlgorithm.ROUND_ROBIN);
   ConnectionLimit limit = new ConnectionLimit();
   limit.setId(id);
   limit.setUserName(username);
   limit.setLoadBalancer(loadBalancer);
   limit.setMaxConnectionRate(maxConnectRate);
   limit.setMaxConnections(maxConnections);
   limit.setMinConnections(minConnections);
   limit.setRateInterval(rateInterval);
   loadBalancer.setConnectionLimit(limit);
   loadBalancer.setConnectionLogging(active);
   loadBalancer.setContentCaching(active);
   loadBalancer.setCreated(Calendar.getInstance());
   loadBalancer.setUpdated(Calendar.getInstance());
   loadBalancer.setHalfClosed(active);
   HealthMonitor monitor = new HealthMonitor();
   monitor.setUserName(username);
   monitor.setId(id);
   monitor.setAttemptsBeforeDeactivation(numAttempts);
   monitor.setBodyRegex(regex);
   monitor.setDelay(delay);
   monitor.setHostHeader(header);
   monitor.setLoadbalancer(loadBalancer);
   monitor.setStatusRegex(regex);
   monitor.setPath(path);
   monitor.setTimeout(timeout);
   monitor.setType(HealthMonitorType.CONNECT);
   loadBalancer.setHealthMonitor(monitor);
   loadBalancer.setHost(new Host());
   loadBalancer.setName(name);
   Set<Node> nodes = new HashSet<Node>();
   Node node = new Node();
   node.setId(id);
   node.setPort(port);
   node.setLoadbalancer(loadBalancer);
   node.setCondition(NodeCondition.ENABLED);
   node.setIpAddress(ipv43);
   List<NodeMeta> nodeMetadata = new ArrayList<NodeMeta>();
   NodeMeta nodeMeta = new NodeMeta();
   nodeMeta.setKey(metaKey);
   nodeMeta.setNode(node);
   nodeMeta.setValue(metaValue);
   nodeMeta.setId(id);
   nodeMeta.setUserName(username);
   nodeMetadata.add(nodeMeta);
   node.setNodeMetadata(nodeMetadata);
   node.setStatus(NodeStatus.ONLINE);
   node.setType(NodeType.PRIMARY);
   node.setWeight(weight);
   nodes.add(node);
   node = new Node();
   node.setId(id + 1);
   node.setPort(port);
   node.setLoadbalancer(loadBalancer);
   node.setCondition(NodeCondition.ENABLED);
   node.setIpAddress(ipv44);
   nodeMetadata = new ArrayList<NodeMeta>();
   nodeMeta = new NodeMeta();
   nodeMeta.setKey(metaKey);
   nodeMeta.setNode(node);
   nodeMeta.setValue(metaValue);
   nodeMeta.setId(id + 1);
   nodeMeta.setUserName(username);
   nodeMetadata.add(nodeMeta);
   node.setNodeMetadata(nodeMetadata);
   node.setStatus(NodeStatus.ONLINE);
   node.setType(NodeType.PRIMARY);
   node.setWeight(weight);
   nodes.add(node);
   loadBalancer.setNodes(nodes);
   Set<LoadbalancerMeta> lbMetadata = new HashSet<LoadbalancerMeta>();
   LoadbalancerMeta lbMeta = new LoadbalancerMeta();
   lbMeta.setUserName(username);
   lbMeta.setId(id);
   lbMeta.setKey(metaKey);
   lbMeta.setValue(metaValue);
   lbMeta.setLoadbalancer(loadBalancer);
   lbMetadata.add(lbMeta);
   loadBalancer.setLoadbalancerMetadata(lbMetadata);
   loadBalancer.setProtocol(LoadBalancerProtocol.HTTP);
   RateLimit limits = new RateLimit();
   limits.setLoadbalancer(loadBalancer);
   limits.setId(id);
   limits.setUserName(username);
   limits.setExpirationTime(Calendar.getInstance());
   limits.setMaxRequestsPerSecond(maxRequests);
   Ticket ticket = new Ticket();
   ticket.setUserName(username);
   ticket.setId(id);
   ticket.setLoadbalancer(loadBalancer);
   ticket.setComment(comment);
   ticket.setTicketId(ticketId);
   limits.setTicket(ticket);
   loadBalancer.setRateLimit(limits);
   loadBalancer.setSessionPersistence(SessionPersistence.HTTP_COOKIE);
   SslTermination termination = new SslTermination();
   termination.setId(id);
   termination.setEnabled(active);
   termination.setUserName(username);
   termination.setSecurePort(securePort);
   termination.setCertificate(cert);
   termination.setPrivatekey(key);
   termination.setSecureTrafficOnly(inactive);
   termination.setLoadbalancer(loadBalancer);
   loadBalancer.setSslTermination(termination);
   loadBalancer.setStatus(LoadBalancerStatus.ACTIVE);
   loadBalancer.setSticky(inactive);
   Suspension suspension = new Suspension();
   suspension.setUserName(username);
   suspension.setId(id);
   suspension.setLoadbalancer(loadBalancer);
   suspension.setUser(user);
   suspension.setReason(reason);
   suspension.setTicket(ticket);
   loadBalancer.setSuspension(suspension);
   Set<Ticket> tickets = new HashSet<Ticket>();
   tickets.add(ticket);
   loadBalancer.setTickets(tickets);
   loadBalancer.setTimeout(timeout);
   UserPages pages = new UserPages();
   pages.setLoadbalancer(loadBalancer);
   pages.setId(id);
   pages.setUserName(username);
   pages.setErrorpage(errorPage);
   loadBalancer.setUserPages(pages);
   loadBalancer.setId(id);
   loadBalancer.setUserName(username);
   Set<LoadBalancerJoinVip> vipList = spy(new HashSet<LoadBalancerJoinVip>());
   VirtualIp vip = new VirtualIp();
   vip.setId(1234);
   vip.setIpAddress("10.69.0.60");
   LoadBalancerJoinVip loadBalancerJoinVip = new LoadBalancerJoinVip();
   loadBalancerJoinVip.setVirtualIp(vip);
   vipList.add(loadBalancerJoinVip);
   loadBalancer.setLoadBalancerJoinVipSet(vipList);
   return loadBalancer;
 }
Beispiel #25
0
 protected static String errorFileName() throws InsufficientRequestException {
   return ZxtmNameBuilder.generateErrorPageName(lb.getId(), lb.getAccountId());
 }
Beispiel #26
0
  /**
   * Called by the executor to fetch something to build next.
   *
   * <p>This method blocks until a next project becomes buildable.
   */
  public Queue.Item pop() throws InterruptedException {
    final Executor exec = Executor.currentExecutor();

    try {
      while (true) {
        final JobOffer offer = new JobOffer(exec);
        long sleep = -1;

        synchronized (this) {
          // consider myself parked
          assert !parked.containsKey(exec);
          parked.put(exec, offer);

          // reuse executor thread to do a queue maintenance.
          // at the end of this we get all the buildable jobs
          // in the buildables field.
          maintain();

          // allocate buildable jobs to executors
          Iterator<BuildableItem> itr = buildables.iterator();
          while (itr.hasNext()) {
            BuildableItem p = itr.next();

            // one last check to make sure this build is not blocked.
            if (isBuildBlocked(p.task)) {
              itr.remove();
              blockedProjects.put(p.task, new BlockedItem(p));
              continue;
            }

            JobOffer runner = loadBalancer.choose(p.task, new ApplicableJobOfferList(p.task));
            if (runner == null)
              // if we couldn't find the executor that fits,
              // just leave it in the buildables list and
              // check if we can execute other projects
              continue;

            assert runner.canTake(p.task);

            // found a matching executor. use it.
            runner.set(p);
            itr.remove();
          }

          // we went over all the buildable projects and awaken
          // all the executors that got work to do. now, go to sleep
          // until this thread is awakened. If this executor assigned a job to
          // itself above, the block method will return immediately.

          if (!waitingList.isEmpty()) {
            // wait until the first item in the queue is due
            sleep = peek().timestamp.getTimeInMillis() - new GregorianCalendar().getTimeInMillis();
            if (sleep < 100) sleep = 100; // avoid wait(0)
          }
        }

        // this needs to be done outside synchronized block,
        // so that executors can maintain a queue while others are sleeping
        if (sleep == -1) offer.event.block();
        else offer.event.block(sleep);

        synchronized (this) {
          // retract the offer object
          assert parked.get(exec) == offer;
          parked.remove(exec);

          // am I woken up because I have a project to build?
          if (offer.item != null) {
            // if so, just build it
            LOGGER.fine("Pop returning " + offer.item + " for " + exec.getName());
            offer.item.future.startExecuting(exec);
            return offer.item;
          }
          // otherwise run a queue maintenance
        }
      }
    } finally {
      synchronized (this) {
        // remove myself from the parked list
        JobOffer offer = parked.remove(exec);
        if (offer != null && offer.item != null) {
          // we are already assigned a project,
          // ask for someone else to build it.
          // note that while this thread is waiting for CPU
          // someone else can schedule this build again,
          // so check the contains method first.
          if (!contains(offer.item.task)) buildables.put(offer.item.task, offer.item);
        }

        // since this executor might have been chosen for
        // maintenance, schedule another one. Worst case
        // we'll just run a pointless maintenance, and that's
        // fine.
        scheduleMaintenance();
      }
    }
  }