Example #1
0
  private static Task createTask() {
    LibraryCacheManager libCache = mock(LibraryCacheManager.class);
    when(libCache.getClassLoader(any(JobID.class))).thenReturn(ClassLoader.getSystemClassLoader());

    ResultPartitionManager partitionManager = mock(ResultPartitionManager.class);
    ResultPartitionConsumableNotifier consumableNotifier =
        mock(ResultPartitionConsumableNotifier.class);
    NetworkEnvironment networkEnvironment = mock(NetworkEnvironment.class);
    when(networkEnvironment.getPartitionManager()).thenReturn(partitionManager);
    when(networkEnvironment.getPartitionConsumableNotifier()).thenReturn(consumableNotifier);
    when(networkEnvironment.getDefaultIOMode()).thenReturn(IOManager.IOMode.SYNC);

    TaskDeploymentDescriptor tdd =
        new TaskDeploymentDescriptor(
            new JobID(),
            new JobVertexID(),
            new ExecutionAttemptID(),
            "Test Task",
            0,
            1,
            new Configuration(),
            new Configuration(),
            CheckpointsInOrderInvokable.class.getName(),
            Collections.<ResultPartitionDeploymentDescriptor>emptyList(),
            Collections.<InputGateDeploymentDescriptor>emptyList(),
            Collections.<BlobKey>emptyList(),
            0);

    ActorGateway taskManagerGateway = DummyActorGateway.INSTANCE;
    return new Task(
        tdd,
        mock(MemoryManager.class),
        mock(IOManager.class),
        networkEnvironment,
        mock(BroadcastVariableManager.class),
        taskManagerGateway,
        DummyActorGateway.INSTANCE,
        new FiniteDuration(60, TimeUnit.SECONDS),
        libCache,
        mock(FileCache.class),
        new TaskManagerRuntimeInfo("localhost", new Configuration()));
  }
  private static Task createTask(TaskDeploymentDescriptor tdd) throws IOException {
    NetworkEnvironment networkEnvironment = mock(NetworkEnvironment.class);
    when(networkEnvironment.createKvStateTaskRegistry(any(JobID.class), any(JobVertexID.class)))
        .thenReturn(mock(TaskKvStateRegistry.class));

    return new Task(
        tdd,
        mock(MemoryManager.class),
        mock(IOManager.class),
        networkEnvironment,
        mock(JobManagerCommunicationFactory.class),
        mock(BroadcastVariableManager.class),
        mock(TaskManagerConnection.class),
        mock(InputSplitProvider.class),
        mock(CheckpointResponder.class),
        new FallbackLibraryCacheManager(),
        new FileCache(new Configuration()),
        new TaskManagerRuntimeInfo(
            "localhost", new Configuration(), EnvironmentInformation.getTemporaryFileDirectory()),
        new UnregisteredTaskMetricsGroup());
  }
  /** Creates an input gate and all of its input channels. */
  public static SingleInputGate create(
      String owningTaskName,
      JobID jobId,
      ExecutionAttemptID executionId,
      InputGateDeploymentDescriptor igdd,
      NetworkEnvironment networkEnvironment) {

    final IntermediateDataSetID consumedResultId = checkNotNull(igdd.getConsumedResultId());

    final int consumedSubpartitionIndex = igdd.getConsumedSubpartitionIndex();
    checkArgument(consumedSubpartitionIndex >= 0);

    final InputChannelDeploymentDescriptor[] icdd =
        checkNotNull(igdd.getInputChannelDeploymentDescriptors());

    final SingleInputGate inputGate =
        new SingleInputGate(
            owningTaskName,
            jobId,
            executionId,
            consumedResultId,
            consumedSubpartitionIndex,
            icdd.length,
            networkEnvironment.getPartitionStateChecker());

    // Create the input channels. There is one input channel for each consumed partition.
    final InputChannel[] inputChannels = new InputChannel[icdd.length];

    for (int i = 0; i < inputChannels.length; i++) {

      final ResultPartitionID partitionId = icdd[i].getConsumedPartitionId();
      final ResultPartitionLocation partitionLocation = icdd[i].getConsumedPartitionLocation();

      if (partitionLocation.isLocal()) {
        inputChannels[i] =
            new LocalInputChannel(
                inputGate,
                i,
                partitionId,
                networkEnvironment.getPartitionManager(),
                networkEnvironment.getTaskEventDispatcher(),
                networkEnvironment.getPartitionRequestInitialAndMaxBackoff());
      } else if (partitionLocation.isRemote()) {
        inputChannels[i] =
            new RemoteInputChannel(
                inputGate,
                i,
                partitionId,
                partitionLocation.getConnectionId(),
                networkEnvironment.getConnectionManager(),
                networkEnvironment.getPartitionRequestInitialAndMaxBackoff());
      } else if (partitionLocation.isUnknown()) {
        inputChannels[i] =
            new UnknownInputChannel(
                inputGate,
                i,
                partitionId,
                networkEnvironment.getPartitionManager(),
                networkEnvironment.getTaskEventDispatcher(),
                networkEnvironment.getConnectionManager(),
                networkEnvironment.getPartitionRequestInitialAndMaxBackoff());
      } else {
        throw new IllegalStateException("Unexpected partition location.");
      }

      inputGate.setInputChannel(partitionId.getPartitionId(), inputChannels[i]);
    }

    LOG.debug("Created input channels {} from {}.", Arrays.toString(inputChannels), igdd);

    return inputGate;
  }