コード例 #1
0
  private List<UpdateWorkerTask> getScheduledTasks(final ApiKey apiKey) {
    final int[] objectTypeValues = apiKey.getConnector().objectTypeValues();
    List<UpdateWorkerTask> scheduledTasks = new ArrayList<UpdateWorkerTask>();
    if (apiKey.getConnector().isAutonomous()) {
      final List<UpdateWorkerTask> updateWorkerTasks =
          connectorUpdateService.getUpdateWorkerTasks(apiKey, 0, 10);
      scheduledTasks.addAll(updateWorkerTasks);
    } else {
      for (int objectTypeValue : objectTypeValues) {
        final List<UpdateWorkerTask> updateWorkerTasks =
            connectorUpdateService.getUpdateWorkerTasks(apiKey, objectTypeValue, 10);
        scheduledTasks.addAll(updateWorkerTasks);
      }
    }
    Collections.sort(
        scheduledTasks,
        new Comparator<UpdateWorkerTask>() {

          @Override
          public int compare(final UpdateWorkerTask o1, final UpdateWorkerTask o2) {
            return (int) (o2.timeScheduled - o1.timeScheduled);
          }
        });
    return scheduledTasks;
  }
コード例 #2
0
 private ValueHolder getSynchingUpdateWorkerTasks() {
   ValueHolder synching = new ValueHolder();
   final List<UpdateWorkerTask> tasks = connectorUpdateService.getAllSynchingUpdateWorkerTasks();
   for (UpdateWorkerTask task : tasks) {
     if (synching.get(task.apiKeyId) != null)
       synching.put(task.apiKeyId, synching.get(task.apiKeyId) + 1);
     else synching.put(task.apiKeyId, 1);
   }
   return synching;
 }
コード例 #3
0
 @Secured({"ROLE_ADMIN"})
 @RequestMapping("/admin/{guestId}/{apiKeyId}/{objectTypes}/refresh")
 public ModelAndView refreshConnectorInstance(
     @PathVariable("guestId") long guestId,
     @PathVariable("apiKeyId") long apiKeyId,
     @PathVariable("objectTypes") int objectTypes) {
   final ApiKey apiKey = guestService.getApiKey(apiKeyId);
   connectorUpdateService.updateConnectorObjectType(apiKey, objectTypes, true, false);
   return new ModelAndView(String.format("redirect:/admin/%s/%s", guestId, apiKeyId));
 }
コード例 #4
0
 @Secured({"ROLE_ADMIN"})
 @RequestMapping("/admin/{guestId}/{apiKeyId}")
 public ModelAndView showConnectorInstanceDetails(
     @PathVariable("guestId") long guestId, @PathVariable("apiKeyId") long apiKeyId) {
   ModelAndView mav = getAdminModel();
   mav.addObject("subview", "connectorDetails");
   final ApiKey apiKey = guestService.getApiKey(apiKeyId);
   final Map<String, Object> connectorInstanceModel =
       connectorInstanceModelFactory.createConnectorInstanceModel(apiKey);
   final Guest guest = guestService.getGuestById(guestId);
   final List<ApiUpdate> lastUpdates = connectorUpdateService.getUpdates(apiKey, 100, 0);
   mav.addObject("guest", guest);
   mav.addObject("guestId", guest.getId());
   mav.addObject("apiKeyId", apiKeyId);
   mav.addObject("apiKey", apiKey);
   mav.addObject("attributes", guestService.getApiKeyAttributes(apiKeyId));
   mav.addObject("connectorInstanceModel", connectorInstanceModel);
   mav.addObject("lastUpdates", lastUpdates);
   mav.addObject("liveServerUUIDs", connectorUpdateService.getLiveServerUUIDs());
   List<UpdateWorkerTask> scheduledTasks = getScheduledTasks(apiKey);
   mav.addObject("scheduledTasks", scheduledTasks);
   return mav;
 }
コード例 #5
0
  @Secured({"ROLE_ADMIN"})
  @RequestMapping(value = {"/admin"})
  public ModelAndView admin(
      HttpServletResponse response,
      @RequestParam(value = "page", required = false, defaultValue = "1") int page,
      @RequestParam(value = "pageSize", required = false, defaultValue = "20") int pageSize)
      throws Exception {
    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
    response.setDateHeader("Expires", 0);
    ModelAndView mav = new ModelAndView("admin/index");

    long totalGuests = jpaDaoService.executeNativeQuery("SELECT count(*) from Guest");

    // If pageSize is too small, set to default of 20
    if (pageSize <= 0) pageSize = 20;

    // Limit range of page to be >=1 and <= lastPage)
    int lastPage =
        ((int) totalGuests) % pageSize == 0
            ? ((int) totalGuests) / pageSize
            : ((int) totalGuests) / pageSize + 1;
    if (page < 1) page = 1;
    else if (page > lastPage) page = lastPage;

    final int offset = (page - 1) * pageSize;
    final List<Guest> allGuests =
        jpaDaoService.executeQueryWithLimitAndOffset(
            "SELECT guest FROM Guest guest", pageSize, offset, Guest.class);
    // get scheduled updateWorkerTasks for the current subset of users
    final List<UpdateWorkerTask> tasks = connectorUpdateService.getAllScheduledUpdateWorkerTasks();

    mav.addObject("allGuests", allGuests);
    mav.addObject("release", env.get("release"));
    final List<ConnectorInfo> connectors = systemService.getConnectors();
    mav.addObject("subview", "connectorHealthDashboard");
    mav.addObject("connectors", connectors);
    List<Map.Entry<Guest, List<List<ApiKey>>>> rows =
        new ArrayList<Map.Entry<Guest, List<List<ApiKey>>>>();
    ValueHolder synching = getSynchingUpdateWorkerTasks();

    long consumerTriggerRepeatInterval = Long.valueOf(env.get("consumer.trigger.repeatInterval"));
    ValueHolder due = getDueUpdateWorkerWorkerTasks(tasks, consumerTriggerRepeatInterval);
    ValueHolder overdue = getOverdueUpdateWorkerWorkerTasks(tasks, consumerTriggerRepeatInterval);

    for (Guest guest : allGuests) {
      List<List<ApiKey>> guestApiKeys = new ArrayList<List<ApiKey>>();
      for (ConnectorInfo connector : connectors) {
        final List<ApiKey> apiKeys =
            guestService.getApiKeys(guest.getId(), Connector.fromValue(connector.api));
        guestApiKeys.add(apiKeys);
      }
      final Map.Entry<Guest, List<List<ApiKey>>> guestListEntry =
          new AbstractMap.SimpleEntry<Guest, List<List<ApiKey>>>(guest, guestApiKeys);
      rows.add(guestListEntry);
    }
    mav.addObject("totalGuests", totalGuests);
    mav.addObject("fromGuest", offset);
    mav.addObject("toGuest", offset + allGuests.size());
    mav.addObject("page", page);
    mav.addObject("pageSize", pageSize);
    mav.addObject("synching", synching);
    mav.addObject("tasksDue", due);
    mav.addObject("tasksOverdue", overdue);
    mav.addObject("rows", rows);
    mav.addObject("serverUUID", connectorUpdateService.getLiveServerUUIDs().toString());
    return mav;
  }