Package com.google.appengine.tools.mapreduce.impl.shardedjob

Examples of com.google.appengine.tools.mapreduce.impl.shardedjob.ShardedJobState


    ShardedJobController<TestTask> controller = new DummyWorkerController();
    TestTask s1 = new TestTask(0, 2, 2, 2);
    TestTask s2 = new TestTask(1, 2, 2, 1);
    jobService.startJob("testGetJobDetail_populated", ImmutableList.of(s1, s2), controller,
        settings);
    ShardedJobState state = jobService.getJobState("testGetJobDetail_populated");
    assertEquals(2, state.getActiveTaskCount());
    assertEquals(2, state.getTotalTaskCount());
    assertEquals(new Status(Status.StatusCode.RUNNING), state.getStatus());
    JSONObject jobDetail = StatusHandler.handleGetJobDetail("testGetJobDetail_populated");
    assertNotNull(jobDetail);
    assertEquals("testGetJobDetail_populated", jobDetail.getString("mapreduce_id"));
    assertEquals("testGetJobDetail_populated", jobDetail.getString("name"));
    assertTrue(jobDetail.getBoolean("active"));
View Full Code Here


   * Handle the get_job_detail AJAX command.
   */
  @VisibleForTesting
  static JSONObject handleGetJobDetail(String jobId) {
    ShardedJobService shardedJobService = ShardedJobServiceFactory.getShardedJobService();
    ShardedJobState state = shardedJobService.getJobState(jobId);
    if (state == null) {
      return null;
    }
    JSONObject jobObject = new JSONObject();
    try {
      jobObject.put("name", jobId); // For display
      jobObject.put("mapreduce_id", jobId); // This is the sharedJobId but it needs be be called
                                            // mapreduce_id for python compatibility.
      jobObject.put("start_timestamp_ms", state.getStartTimeMillis());

      if (state.getStatus().isActive()) {
        jobObject.put("active", true);
        jobObject.put("updated_timestamp_ms", System.currentTimeMillis());
      } else {
        jobObject.put("active", false);
        jobObject.put("result_status", String.valueOf(state.getStatus().getStatusCode()));
        jobObject.put("updated_timestamp_ms", state.getMostRecentUpdateTimeMillis());
      }
      jobObject.put("shards", state.getTotalTaskCount());
      jobObject.put("active_shards", state.getActiveTaskCount());

      JSONObject mapperParams = new JSONObject();
      mapperParams.put("Shards completed",
          state.getTotalTaskCount() - state.getActiveTaskCount());
      mapperParams.put("Shards active", state.getActiveTaskCount());
      mapperParams.put("Shards total", state.getTotalTaskCount());
      JSONObject mapperSpec = new JSONObject();
      mapperSpec.put("mapper_params", mapperParams);
      jobObject.put("mapper_spec", mapperSpec);

      JSONArray shardArray = new JSONArray();
      Counters totalCounters = new CountersImpl();
      int i = 0;
      long[] workerCallCounts = new long[state.getTotalTaskCount()];
      Iterator<IncrementalTaskState<IncrementalTask>> tasks = shardedJobService.lookupTasks(state);
      while (tasks.hasNext()) {
        IncrementalTaskState<?> taskState = tasks.next();
        JSONObject shardObject = new JSONObject();
        shardObject.put("shard_number", i);
        shardObject.put("shard_description", taskState.getTaskId());
        shardObject.put("updated_timestamp_ms", taskState.getMostRecentUpdateMillis());
        if (taskState.getStatus().isActive()) {
          shardObject.put("active", true);
        } else {
          shardObject.put("active", false);
          shardObject.put("result_status", taskState.getStatus().getStatusCode());
        }
        IncrementalTask task = taskState.getTask();
        if (task instanceof IncrementalTaskWithContext) {
          IncrementalTaskContext context = ((IncrementalTaskWithContext) task).getContext();
          totalCounters.addAll(context.getCounters());
          workerCallCounts[i] = context.getWorkerCallCount();
          shardObject.put("last_work_item", context.getLastWorkItemString());
        }
        shardArray.put(shardObject);
        i++;
      }
      jobObject.put("counters", toJson(totalCounters));
      jobObject.put("shards", shardArray);
      jobObject.put("chart_width", getChartWidth(state.getTotalTaskCount()));
      jobObject.put("chart_url", getChartUrl(workerCallCounts));
      jobObject.put("chart_data", workerCallCounts);
    } catch (JSONException e) {
      throw new RuntimeException("Hard coded string is null", e);
    }
View Full Code Here

TOP

Related Classes of com.google.appengine.tools.mapreduce.impl.shardedjob.ShardedJobState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.