public void testUpdateInvalidLimits() {
    // CPU soft remains to 0 => conflict because hard is smaller
    limits.setCpuCountHardLimit(2);

    try {
      limits.update();
    } catch (AbiquoException ex) {
      assertHasError(ex, Status.BAD_REQUEST, "CONSTR-LIMITRANGE");
    }
  }
  public void testUpdateLimits() {
    limits.setCpuCountLimits(4, 5);
    limits.update();

    DatacentersLimitsDto limitsDto =
        env.enterpriseApi.getLimits(enterprise.unwrap(), env.datacenter.unwrap());
    assertNotNull(limitsDto);
    assertEquals(limitsDto.getCollection().size(), 1);
    assertEquals(limitsDto.getCollection().get(0).getCpuCountHardLimit(), 5);
    assertEquals(limitsDto.getCollection().get(0).getCpuCountSoftLimit(), 4);
  }
Exemple #3
0
 public String IPv6Lists(String country, String clientIP) {
   IPListDAO dao = new IPListDAOHibernate();
   if (dao.clientRequestCount(clientIP) < Limits.getRequestLimit()) {
     StringBuffer sb = new StringBuffer();
     String[] countries = country.toUpperCase().split(",");
     for (int i = 0; i < countries.length; i++) {
       sb.append(dao.IPv6List(countries[i]));
     }
     return sb.toString();
   } else {
     return "# update limit exceed, please don't attack server.";
   }
 }
 public static Building[] placeBigFires(int num, Building[] b, Limits radius) {
   List remaining = new ArrayList();
   for (int i = 0; i < b.length; ++i) remaining.add(b[i]);
   Collections.shuffle(remaining);
   Collection fires = new HashSet();
   System.out.print("Placing " + num + " big fires");
   Iterator it = remaining.iterator();
   for (int i = 0; i < num; ++i) {
     Building center = (Building) it.next();
     fires.add(center);
     long r = radius.getNumber();
     long distanceSquared = r * r;
     // Check for close buildings
     for (int j = 0; j < b.length; ++j) {
       long dx = center.getX() - b[j].getX();
       long dy = center.getY() - b[j].getY();
       long distance = (dx * dx) + (dy * dy);
       if (distance <= distanceSquared) fires.add(b[j]);
     }
   }
   return (Building[]) fires.toArray(new Building[0]);
 }
 public int getPossibleAverageY() {
   return verticalL.middle();
 }
 public int getPossibleAverageX() {
   return horizontalL.middle();
 }
 public void setBackAngle(int backAngle) {
   this.backAngle = angleL.fullCheck(backAngle);
 }
 public void setBottomY(int bottomY) {
   this.bottomY = verticalL.fullCheck(bottomY);
 }
 public void setBottomX(int bottomX) {
   this.bottomX = horizontalL.fullCheck(bottomX);
 }
  RandomConfig(String[] args) {
    Limits fireBrigades = new Limits(10, 15, "fireBrigades", "fire brigades");
    Limits policeForces = new Limits(10, 15, "policeForces", "police forces");
    Limits ambulanceTeams = new Limits(5, 8, "ambulanceTeams", "ambulance teams");
    Limits fireStations = new Limits(1, 1, "fireStations", "fire stations");
    Limits policeStations = new Limits(1, 1, "policeStations", "police stations");
    Limits ambulanceCenters = new Limits(1, 1, "ambulanceCenters", "ambulance centers");
    Limits civilians = new Limits(70, 90, "civilians", "civilians");
    Limits refuges = new Limits(1, 5, "refuges", "refuges");
    Limits fires = new Limits(2, 8, "fires", "fires");
    Limits fireRadius = new Limits(0, 20000, "fireradius", "fire radius");
    Limits[] allLimits =
        new Limits[] {
          fireBrigades,
          policeForces,
          ambulanceTeams,
          fireStations,
          policeStations,
          ambulanceCenters,
          civilians,
          refuges,
          fires,
          fireRadius
        };
    boolean allowTrappedAgents = false;
    boolean bigFires = false;
    boolean trappedCivilians = true;

    String dir = "";

    for (int i = 0; i < args.length; ++i) {
      if (args[i].startsWith("-min-")) {
        for (int j = 0; j < allLimits.length; ++j) {
          if (args[i].equalsIgnoreCase("-min-" + allLimits[j].prefix))
            allLimits[j].min = Integer.parseInt(args[++i]);
        }
      } else if (args[i].startsWith("-max-")) {
        for (int j = 0; j < allLimits.length; ++j) {
          if (args[i].equalsIgnoreCase("-max-" + allLimits[j].prefix))
            allLimits[j].max = Integer.parseInt(args[++i]);
        }
      } else if (args[i].startsWith("-no-")) {
        for (int j = 0; j < allLimits.length; ++j) {
          if (args[i].equalsIgnoreCase("-no-" + allLimits[j].prefix)) {
            allLimits[j].min = 0;
            allLimits[j].max = 0;
          }
        }
      } else if (args[i].startsWith("-set-")) {
        int num = Integer.parseInt(args[i + 1]);
        for (int j = 0; j < allLimits.length; ++j) {
          if (args[i].equalsIgnoreCase("-set-" + allLimits[j].prefix)) {
            allLimits[j].min = num;
            allLimits[j].max = num;
          }
        }
        ++i;
      } else if (args[i].equalsIgnoreCase("-t")
          || args[i].equalsIgnoreCase("--allow-trapped-agents")) {
        allowTrappedAgents = true;
      } else if (args[i].equalsIgnoreCase("-c")
          || args[i].equalsIgnoreCase("--allow-untrapped-civilians")) {
        trappedCivilians = false;
      } else if (args[i].equalsIgnoreCase("-b") || args[i].equalsIgnoreCase("--big-fires")) {
        bigFires = true;
      } else if (args[i].equalsIgnoreCase("-d") || args[i].equalsIgnoreCase("--dir")) {
        dir = args[i + 1];
      } else if (args[i].equalsIgnoreCase("-h") || args[i].equalsIgnoreCase("--help")) {
        System.out.println("Usage: RandomConfig [options]");
        System.out.println(
            "This program will read from \"road.bin\", \"node.bin\" and \"building.bin\" and produce a randomised \"gisini.txt\"");
        System.out.println("Options");
        System.out.println("=======");
        for (int j = 0; j < allLimits.length; ++j) {
          System.out.println(
              "-min-"
                  + allLimits[j].prefix
                  + "\tSet the minimum number of "
                  + allLimits[j].name
                  + " (currently "
                  + allLimits[j].min
                  + ")");
          System.out.println(
              "-max-"
                  + allLimits[j].prefix
                  + "\tSet the maximum number of "
                  + allLimits[j].name
                  + " (currently "
                  + allLimits[j].max
                  + ")");
          System.out.println(
              "-no-"
                  + allLimits[j].prefix
                  + "\tSet the minimum and maximum of "
                  + allLimits[j].name
                  + " to zero");
        }
        System.out.println(
            "-t\t--allow-trapped-agents\tAllow rescue agents (fire brigades, police forces and ambulance teams) to be placed inside buildings (default OFF)");
        System.out.println(
            "-c\t--allow-untrapped-civilians\tAllow civilians to be placed outside buildings (default OFF)");
        System.out.println("-b\t--big-fires\tAllow big fires");
        System.out.println("-d\t--dir\tSet output directory (use full path)");
        System.out.println("-h\t--help\tPrint this message");
        return;
      }
    }
    try {

      File parentDir = new File(dir);
      File gisini = new File(parentDir, "gisini.txt");

      // Open the output

      PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(gisini)));

      // Build the city data
      allNodes = MapFiles.loadNodes(parentDir);
      allRoads = MapFiles.loadRoads(parentDir);
      allBuildings = MapFiles.loadBuildings(parentDir);

      Memory memory = new HashMemory();
      for (int i = 0; i < allNodes.length; ++i) memory.add(allNodes[i], 0);
      for (int i = 0; i < allRoads.length; ++i) memory.add(allRoads[i], 0);
      for (int i = 0; i < allBuildings.length; ++i) memory.add(allBuildings[i], 0);
      // Place items
      int numFireBrigades = fireBrigades.getNumber();
      int numPoliceForces = policeForces.getNumber();
      int numAmbulanceTeams = ambulanceTeams.getNumber();
      int numFireStations = fireStations.getNumber();
      int numPoliceStations = policeStations.getNumber();
      int numAmbulanceCenters = ambulanceCenters.getNumber();
      int numRefuges = refuges.getNumber();
      int numCivilians = civilians.getNumber();
      int numFires = fires.getNumber();

      FireStation[] fireStationBuildings = new FireStation[numFireStations];
      PoliceOffice[] policeOfficeBuildings = new PoliceOffice[numPoliceStations];
      AmbulanceCenter[] ambulanceCenterBuildings = new AmbulanceCenter[numAmbulanceCenters];
      Refuge[] refugeBuildings = new Refuge[numRefuges];
      Building[] normalBuildings =
          placeMotionlessObjects(
              fireStationBuildings,
              policeOfficeBuildings,
              ambulanceCenterBuildings,
              refugeBuildings,
              allBuildings);
      MapFiles.writeGISMotionlessObjects(
          out,
          fireStationBuildings,
          policeOfficeBuildings,
          ambulanceCenterBuildings,
          refugeBuildings);

      FireBrigade[] fireBrigadeObjects = new FireBrigade[numFireBrigades];
      PoliceForce[] policeForceObjects = new PoliceForce[numPoliceForces];
      AmbulanceTeam[] ambulanceTeamObjects = new AmbulanceTeam[numAmbulanceTeams];
      Civilian[] civilianObjects = new Civilian[numCivilians];
      //
      //	placeMovingObjects(fireBrigadeObjects,policeForceObjects,ambulanceTeamObjects,civilianObjects,allBuildings,allRoads,allNodes,allowTrappedAgents,trappedCivilians);
      placeMovingObjects(
          fireBrigadeObjects,
          policeForceObjects,
          ambulanceTeamObjects,
          civilianObjects,
          allBuildings,
          new Road[0],
          allNodes,
          allowTrappedAgents,
          trappedCivilians);
      MapFiles.writeGISMovingObjects(
          out,
          fireBrigadeObjects,
          policeForceObjects,
          ambulanceTeamObjects,
          civilianObjects,
          memory);

      Building[] fireBuildings;
      if (bigFires) fireBuildings = placeBigFires(numFires, normalBuildings, fireRadius);
      else fireBuildings = placeNormalFires(numFires, normalBuildings);
      MapFiles.writeGISFires(out, fireBuildings);

      out.flush();
      out.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }