예제 #1
0
  public void doGet(Request req, Response resp) throws RestletException {

    String taskIds = null;
    try {
      taskIds = URLDecoder.decode((String) req.getAttributes().get("taskids"), "UTF-8");
    } catch (UnsupportedEncodingException uee) {
      log.error("Exception type = " + uee.getClass().getName() + " msg = " + uee.getMessage());
      throw new RestletException(uee.getMessage(), Status.SERVER_ERROR_INTERNAL);
    }

    ArrayList<GWCTaskStatus> taskList = new ArrayList<GWCTaskStatus>();
    seeder.getStorageBroker().getTasks(taskIds, taskList);

    List<String> segments = req.getResourceRef().getSegments();
    String reqAction = segments.get(segments.size() - 2);
    if (reqAction.equalsIgnoreCase("seedprogress")) {
      handleProgress(req, resp, taskList);
    } else if (reqAction.equalsIgnoreCase("seedcancel")) {
      handleCancel(req, resp, taskList);
    } else {
      String msg = "Unsupported action: " + reqAction;
      log.error(msg);
      throw new RestletException(msg, Status.CLIENT_ERROR_NOT_FOUND);
    }
  }
예제 #2
0
  private void handleCancel(Request req, Response resp, ArrayList<GWCTaskStatus> taskList)
      throws RestletException {

    StringBuilder strBld = new StringBuilder();
    strBld.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    strBld.append("<CancelResults>");

    Object[] tasks = taskList.toArray();
    for (int i = 0; i < tasks.length; i++) {
      GWCTaskStatus taskStatus = (GWCTaskStatus) tasks[i];
      strBld.append("<Task>");
      strBld.append("<dbId>" + taskStatus.getDbId() + "</dbId>");
      strBld.append("<CancelResult>");
      Iterator<Entry<Long, GWCTask>> iter = seeder.getRunningTasksIterator();
      while (iter.hasNext()) {
        Entry<Long, GWCTask> entry = iter.next();
        GWCTask task = entry.getValue();
        if (task.getDbId() == taskStatus.getDbId()) {
          taskStatus.setThreadRunning(true);
          taskStatus.setTaskId(task.getTaskId());
        }
      }
      if (!taskStatus.getThreadRunning()) {
        strBld.append("not running");
      } else {
        log.debug("terminating task with id = " + taskStatus.getTaskId());
        if (seeder.terminateGWCTask(taskStatus.getTaskId())) {
          strBld.append("true");
        } else {
          strBld.append("false");
        }
      }
      strBld.append("</CancelResult>");
      strBld.append("</Task>");
    }

    strBld.append("</CancelResults>");
    resp.setEntity(strBld.toString(), MediaType.TEXT_XML);
  }
예제 #3
0
  @Test
  public void testMinMaxCacheSeedTile() throws Exception {
    WMSLayer tl = createWMSLayer("image/png", 5, 6);

    MockTileSupport mock = new MockTileSupport(tl);

    SeedRequest req = createRequest(tl, GWCTask.TYPE.SEED, 4, 7);
    TileRange tr = TileBreeder.createTileRange(req, tl);

    seedTiles(mock.storageBroker, tr, tl);

    // zero transient cache attempts
    assertEquals(0, mock.cacheHits.get());
    assertEquals(0, mock.cacheMisses.get());
    // empirical numbers
    assertEquals(42, mock.wmsMetaRequestCounter.get());
    assertEquals(218, mock.storagePutCounter.get());
  }
예제 #4
0
  /** Returns a StringRepresentation with the status of the running threads in the thread pool. */
  private void handleProgress(Request req, Response resp, ArrayList<GWCTaskStatus> taskList)
      throws RestletException {

    Object[] tasks = taskList.toArray();

    StringBuilder strBld = new StringBuilder();
    strBld.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    strBld.append("<Tasks>");

    XStream xs = new XStream();
    xs.omitField(GWCTask.class, "parsedType");
    xs.omitField(GWCTask.class, "state");
    xs.omitField(GWCTask.class, "sharedThreadCount");
    xs.omitField(GWCTask.class, "groupStartTime");
    xs.omitField(GWCTask.class, "storageBroker");

    xs.alias("GWCTaskStatus", GWCTaskStatus.class);

    for (int i = 0; i < tasks.length; i++) {
      GWCTaskStatus taskStatus = (GWCTaskStatus) tasks[i];
      Iterator<Entry<Long, GWCTask>> iter = seeder.getRunningTasksIterator();

      while (iter.hasNext()) {
        Entry<Long, GWCTask> entry = iter.next();
        GWCTask task = entry.getValue();
        if (task.getDbId() == taskStatus.getDbId()) {
          taskStatus.setTaskId(task.getTaskId());
          taskStatus.setThreadRunning(true);
          taskStatus.setTilesDone(task.getTilesDone());
          taskStatus.setTilesTotal(task.getTilesTotal());
          taskStatus.setTimeSpent(task.getTimeSpent());
          taskStatus.setTimeRemaing(task.getTimeRemaining());
        }
      }
      String task_xml = xs.toXML(taskStatus);
      strBld.append(task_xml);
    }

    strBld.append("</Tasks>");
    resp.setEntity(strBld.toString(), MediaType.TEXT_XML);
  }
예제 #5
0
  // ignore to fix the build until the failing assertion is worked out
  @Test
  @Ignore
  public void testMinMaxCacheGetTile() throws Exception {
    WMSLayer tl = createWMSLayer("image/png", 5, 6);

    MockTileSupport mock = new MockTileSupport(tl);

    // we're not really seeding, just using the range
    SeedRequest req = createRequest(tl, GWCTask.TYPE.SEED, 4, 7);
    TileRange tr = TileBreeder.createTileRange(req, tl);

    List<ConveyorTile> tiles = getTiles(mock.storageBroker, tr, tl);

    // this number is determined by our tileRange minus those out of bounds
    assertEquals(880, tiles.size());
    // tiles at zoom 4 and 7 will have non png data
    for (int i = 0; i < tiles.size(); i++) {
      ConveyorTile tile = tiles.get(i);
      assertNotNull(tile.getBlob());
      // System.out.println(tile.getTileIndex()[2] + " " + tile.getBlob().getSize());
    }

    // empirical numbers
    // this number is determined by the number of metarequests at level 5+6
    assertEquals(218, mock.storagePutCounter.get());
    // and the number of successful hits at level 5+6
    assertEquals(176, mock.storageGetCounter.get());
    // these last will vary - on a dual core machine, they appeared predictable
    // but on a 8 core machine, the threads compete for cache and we can only
    // assertain by range
    // @todo
    // assertTrue(Math.abs(532 - mock.cacheHits.get()) < 10);
    // assertTrue(Math.abs(494 - mock.cacheMisses.get()) < 10);
    // assertTrue(Math.abs(172 - mock.wmsMetaRequestCounter.get()) < 10);
    // stats
    System.out.println("transientCacheSize " + mock.transientCache.size());
    System.out.println("transientCacheStorage " + mock.transientCache.storageSize());
  }
예제 #6
0
  /**
   * Method responsible for handling incoming POSTs. It will parse the XML document and deserialize
   * it into a SeedRequest, then create a SeedTask and forward it to the thread pool executor.
   */
  public void doPost(Request req, Response resp) throws RestletException, IOException {
    String formatExtension = (String) req.getAttributes().get("extension");

    SeedRequest sr = null;

    XStream xs = xmlConfig.getConfiguredXStream(new XStream(new DomDriver()));
    try {
      if (formatExtension.equalsIgnoreCase("xml")) {
        String xml_body = req.getEntity().getText();
        log.debug("doPost, xml = " + xml_body);
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        ByteArrayInputStream xml_bs = new ByteArrayInputStream(xml_body.getBytes());
        Document doc = db.parse(xml_bs);
        Node rootNode = doc.getFirstChild();
        xs.alias("seedRequest", SeedRequest.class);
        sr = (SeedRequest) xs.unmarshal(new DomReader((Element) rootNode));
        log.debug("doPost, sr = " + sr.getLayerName());
      } else if (formatExtension.equalsIgnoreCase("json")) {
        sr = (SeedRequest) xs.fromXML(convertJson(req.getEntity().getText()));
      } else {
        throw new RestletException(
            "Format extension unknown or not specified: " + formatExtension,
            Status.CLIENT_ERROR_BAD_REQUEST);
      }
    } catch (Exception e) {
      log.error("Exception type = " + e.getClass().getName() + " msg = " + e.getMessage());
      e.printStackTrace();
      if (e.getCause() != null) {
        log.error("cause = " + e.getCause().getMessage());
      }
    }

    StringBuilder strBld = new StringBuilder();
    strBld.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    String layerName = null;
    try {
      layerName = URLDecoder.decode((String) req.getAttributes().get("layer"), "UTF-8");
    } catch (UnsupportedEncodingException uee) {
      log.error("Exception type = " + uee.getClass().getName() + " msg = " + uee.getMessage());
      throw new RestletException(uee.getMessage(), Status.SERVER_ERROR_INTERNAL);
    }

    log.debug(
        "layerName = "
            + layerName
            + " sr.GridSetId = "
            + sr.getGridSetId()
            + " type = "
            + sr.getType());
    GWCTask[] tasks = null;
    try {
      TileLayer tl = null;
      try {
        tl = seeder.findTileLayer(layerName);
      } catch (GeoWebCacheException e) {
        strBld.append("<GeoWebCacheException>");
        strBld.append(e.getMessage());
        strBld.append("</GeoWebCacheException>");
        resp.setEntity(strBld.toString(), MediaType.TEXT_XML);
        throw new RestletException(e.getMessage(), Status.SERVER_ERROR_INTERNAL);
      }

      TileRange tr = TileBreeder.createTileRange(sr, tl);

      tasks = seeder.createTasks(tr, tl, sr.getType(), sr.getThreadCount(), sr.getFilterUpdate());

      seeder.dispatchTasks(tasks);
      // Give the thread executor a chance to run
      try {
        Thread.sleep(500);
      } catch (InterruptedException e) {
        // Ok, no worries
      }

    } catch (IllegalArgumentException e) {
      log.error("IllegalArgumentException occured: " + e.getMessage());
      throw new RestletException(e.getMessage(), Status.CLIENT_ERROR_BAD_REQUEST);
    } catch (GeoWebCacheException e) {
      log.error("GeoWebCacheException occured: " + e.getMessage());
      throw new RestletException(e.getMessage(), Status.SERVER_ERROR_INTERNAL);
    }

    strBld.append("<Tasks>");
    if (tasks.length == 0) {
      log.debug("No running tasks");
    }
    for (int i = 0; i < tasks.length; i++) {
      if (i > 0) {
        strBld.append(",");
      }
      strBld.append(tasks[i].getDbId());
    }
    strBld.append("</Tasks>\n");
    log.debug("post response = " + strBld.toString());
    resp.setEntity(strBld.toString(), MediaType.TEXT_XML);
  }