package com.metamx.druid.indexing.worker;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import com.metamx.druid.indexing.common.TaskStatus;
import com.metamx.druid.indexing.common.task.Task;
import com.metamx.druid.indexing.common.task.TaskResource;

/**
 * Used by workers to announce the status of tasks they are currently running. This class is immutable.
 */
public class TaskAnnouncement
{
  private final TaskStatus taskStatus;
  private final TaskResource taskResource;

  public static TaskAnnouncement create(Task task, TaskStatus status)
  {
    Preconditions.checkArgument(status.getId().equals(task.getId()), "task id == status id");
    return new TaskAnnouncement(null, null, status, task.getTaskResource());
  }

  @JsonCreator
  private TaskAnnouncement(
      @JsonProperty("id") String taskId,
      @JsonProperty("status") TaskStatus.Status status,
      @JsonProperty("taskStatus") TaskStatus taskStatus,
      @JsonProperty("taskResource") TaskResource taskResource
  )
  {
    if (taskStatus != null) {
      this.taskStatus = taskStatus;
    } else {
      // Can be removed when backwards compat is no longer needed
      this.taskStatus = TaskStatus.fromCode(taskId, status);
    }
    this.taskResource = taskResource == null ? new TaskResource(this.taskStatus.getId(), 1) : taskResource;
  }

  // Can be removed when backwards compat is no longer needed
  @JsonProperty("id")
  @Deprecated
  public String getTaskId()
  {
    return taskStatus.getId();
  }

  // Can be removed when backwards compat is no longer needed
  @JsonProperty("status")
  @Deprecated
  public TaskStatus.Status getStatus()
  {
    return taskStatus.getStatusCode();
  }

  @JsonProperty("taskStatus")
  public TaskStatus getTaskStatus()
  {
    return taskStatus;
  }

  @JsonProperty("taskResource")
  public TaskResource getTaskResource()
  {
    return taskResource;
  }
}

@@ -1,8 +1,823 @@
+/*%0A * Druid - a distributed column store.%0A * Copyright (C) 2012  Metamarkets Group Inc.%0A *%0A * This program is free software; you can redistribute it and/or%0A * modify it under the terms of the GNU General Public License%0A * as published by the Free Software Foundation; either version 2%0A * of the License, or (at your option) any later version.%0A *%0A * This program is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A * GNU General Public License for more details.%0A *%0A * You should have received a copy of the GNU General Public License%0A * along with this program; if not, write to the Free Software%0A * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.%0A */%0A%0A
 package 

Add missing license headers