All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hubspot.singularity.data.history.DeployTaskHistoryHelper Maven / Gradle / Ivy

package com.hubspot.singularity.data.history;

import java.util.List;

import com.google.common.base.Optional;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.hubspot.singularity.ExtendedTaskState;
import com.hubspot.singularity.OrderDirection;
import com.hubspot.singularity.SingularityDeployKey;
import com.hubspot.singularity.SingularityTaskId;
import com.hubspot.singularity.SingularityTaskIdHistory;
import com.hubspot.singularity.data.TaskManager;

@Singleton
public class DeployTaskHistoryHelper extends BlendedHistoryHelper {

  private final TaskManager taskManager;
  private final HistoryManager historyManager;

  @Inject
  public DeployTaskHistoryHelper(TaskManager taskManager, HistoryManager historyManager) {
    this.taskManager = taskManager;
    this.historyManager = historyManager;
  }

  @Override
  protected List getFromZk(final SingularityDeployKey deployKey) {
    List deployTaskIds = taskManager.getInactiveTaskIdsForDeploy(deployKey.getRequestId(), deployKey.getDeployId());
    return getTaskHistoriesFor(taskManager, deployTaskIds);
  }

  @Override
  protected List getFromHistory(final SingularityDeployKey deployKey, int historyStart, int numFromHistory) {
    return historyManager.getTaskIdHistory(Optional.of(deployKey.getRequestId()), Optional.of(deployKey.getDeployId()), Optional.absent(), Optional. absent(), Optional. absent(),
        Optional. absent(), Optional. absent(), Optional. absent(), Optional. absent(), Optional. absent(), Optional.of(historyStart), numFromHistory);
  }

  @Override
  protected Optional getTotalCount(SingularityDeployKey deployKey) {
    final int numFromZk = taskManager.getInactiveTaskIdsForDeploy(deployKey.getRequestId(), deployKey.getDeployId()).size();
    final int numFromHistory = historyManager.getTaskIdHistoryCount(Optional.of(deployKey.getRequestId()), Optional.of(deployKey.getDeployId()), Optional.absent(), Optional. absent(), Optional. absent(),
      Optional. absent(), Optional. absent(), Optional. absent(), Optional. absent());
    return Optional.of(numFromZk + numFromHistory);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy