Search in sources :

Example 21 with JobConfig

use of alluxio.job.JobConfig in project alluxio by Alluxio.

the class TransformPlan method computeJobConfigs.

private ArrayList<JobConfig> computeJobConfigs(TransformDefinition definition) {
    ArrayList<JobConfig> actions = new ArrayList<>();
    Layout baseLayout = mBaseLayout;
    boolean deleteSrc = false;
    for (TransformAction action : definition.getActions()) {
        actions.add(action.generateJobConfig(baseLayout, mTransformedLayout, deleteSrc));
        baseLayout = mTransformedLayout;
        deleteSrc = true;
    }
    if (actions.isEmpty()) {
        throw new IllegalArgumentException("At least one action should be defined for the transformation");
    }
    return actions;
}
Also used : Layout(alluxio.table.common.Layout) ArrayList(java.util.ArrayList) TransformAction(alluxio.table.common.transform.action.TransformAction) JobConfig(alluxio.job.JobConfig)

Example 22 with JobConfig

use of alluxio.job.JobConfig in project alluxio by Alluxio.

the class TransformManager method execute.

/**
 * Executes the plans for the table transformation.
 *
 * This method executes a transformation job with type{@link CompositeConfig},
 * the transformation job concurrently executes the plans,
 * each plan has a list of jobs to be executed sequentially.
 *
 * This method triggers the execution of the transformation job asynchronously without waiting
 * for it to finish. The returned job ID can be used to poll the job service for the status of
 * this transformation.
 *
 * @param dbName the database name
 * @param tableName the table name
 * @param definition the parsed transformation definition
 * @return the job ID for the transformation job
 * @throws IOException when there is an ongoing transformation on the table, or the transformation
 *    job fails to be started, or all partitions of the table have been transformed with the same
 *    definition
 */
public long execute(String dbName, String tableName, TransformDefinition definition) throws IOException {
    List<TransformPlan> plans = mCatalog.getTransformPlan(dbName, tableName, definition);
    if (plans.isEmpty()) {
        throw new IOException(ExceptionMessage.TABLE_ALREADY_TRANSFORMED.getMessage(dbName, tableName, definition.getDefinition()));
    }
    Pair<String, String> dbTable = new Pair<>(dbName, tableName);
    // Atomically try to acquire the permit to execute the transformation job.
    // This PUT does not need to be journaled, because if this PUT succeeds and master crashes,
    // when master restarts, this temporary placeholder entry will not exist, which is correct
    // behavior.
    Long existingJobId = mState.acquireJobPermit(dbTable);
    if (existingJobId != null) {
        if (existingJobId == INVALID_JOB_ID) {
            throw new IOException("A concurrent transformation request is going to be executed");
        } else {
            throw new IOException(ExceptionMessage.TABLE_BEING_TRANSFORMED.getMessage(existingJobId.toString(), tableName, dbName));
        }
    }
    ArrayList<JobConfig> concurrentJobs = new ArrayList<>(plans.size());
    for (TransformPlan plan : plans) {
        concurrentJobs.add(new CompositeConfig(plan.getJobConfigs(), true));
    }
    CompositeConfig transformJob = new CompositeConfig(concurrentJobs, false);
    long jobId;
    try {
        jobId = mJobMasterClient.run(transformJob);
    } catch (IOException e) {
        // The job fails to start, clear the acquired permit for execution.
        // No need to journal this REMOVE, if master crashes, when it restarts, the permit placeholder
        // entry will not exist any more, which is correct behavior.
        mState.releaseJobPermit(dbTable);
        String error = String.format("Fails to start job to transform table %s in database %s", tableName, dbName);
        LOG.error(error, e);
        throw new IOException(error, e);
    }
    Map<String, Layout> transformedLayouts = new HashMap<>(plans.size());
    for (TransformPlan plan : plans) {
        transformedLayouts.put(plan.getBaseLayout().getSpec(), plan.getTransformedLayout());
    }
    AddTransformJobInfoEntry journalEntry = AddTransformJobInfoEntry.newBuilder().setDbName(dbName).setTableName(tableName).setDefinition(definition.getDefinition()).setJobId(jobId).putAllTransformedLayouts(Maps.transformValues(transformedLayouts, Layout::toProto)).build();
    try (JournalContext journalContext = mCreateJournalContext.apply()) {
        applyAndJournal(journalContext, Journal.JournalEntry.newBuilder().setAddTransformJobInfo(journalEntry).build());
    }
    return jobId;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JournalContext(alluxio.master.journal.JournalContext) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JobConfig(alluxio.job.JobConfig) Layout(alluxio.table.common.Layout) AddTransformJobInfoEntry(alluxio.proto.journal.Table.AddTransformJobInfoEntry) TransformPlan(alluxio.table.common.transform.TransformPlan) CompositeConfig(alluxio.job.workflow.composite.CompositeConfig) Pair(alluxio.collections.Pair)

Example 23 with JobConfig

use of alluxio.job.JobConfig in project alluxio by Alluxio.

the class WorkflowTracker method next.

private synchronized void next(long jobId) {
    WorkflowExecution workflowExecution = mWorkflows.get(jobId);
    mChildren.putIfAbsent(jobId, new ConcurrentHashSet<>());
    Set<JobConfig> childJobConfigs = workflowExecution.next();
    if (childJobConfigs.isEmpty()) {
        done(jobId);
        return;
    }
    ConcurrentHashSet<Long> childJobIds = new ConcurrentHashSet<>();
    for (int i = 0; i < childJobConfigs.size(); i++) {
        childJobIds.add(mJobMaster.getNewJobId());
    }
    mWaitingOn.put(jobId, childJobIds);
    mChildren.get(jobId).addAll(childJobIds);
    for (Long childJobId : childJobIds) {
        mParentWorkflow.put(childJobId, jobId);
    }
    Iterator<Long> childJobIdsIter = childJobIds.iterator();
    Iterator<JobConfig> childJobConfigsIter = childJobConfigs.iterator();
    while (childJobIdsIter.hasNext() && childJobConfigsIter.hasNext()) {
        Long childJobId = childJobIdsIter.next();
        JobConfig childJobConfig = childJobConfigsIter.next();
        try {
            mJobMaster.run(childJobConfig, childJobId);
        } catch (JobDoesNotExistException | ResourceExhaustedException e) {
            LOG.warn(e.getMessage());
            final String errorType = ErrorUtils.getErrorType(e);
            workflowExecution.stop(Status.FAILED, errorType, e.getMessage());
            stop(jobId, Status.FAILED, errorType, e.getMessage());
        }
    }
}
Also used : JobDoesNotExistException(alluxio.exception.JobDoesNotExistException) JobConfig(alluxio.job.JobConfig) ResourceExhaustedException(alluxio.exception.status.ResourceExhaustedException) ConcurrentHashSet(alluxio.collections.ConcurrentHashSet) WorkflowExecution(alluxio.job.workflow.WorkflowExecution)

Example 24 with JobConfig

use of alluxio.job.JobConfig in project alluxio by Alluxio.

the class CommandHandlingExecutorTest method heartbeat.

@Test
public void heartbeat() throws Exception {
    JobCommand.Builder command = JobCommand.newBuilder();
    RunTaskCommand.Builder runTaskCommand = RunTaskCommand.newBuilder();
    long jobId = 1;
    runTaskCommand.setJobId(jobId);
    long taskId = 2;
    runTaskCommand.setTaskId(taskId);
    JobConfig jobConfig = new TestPlanConfig("/test");
    runTaskCommand.setJobConfig(ByteString.copyFrom(SerializationUtils.serialize(jobConfig)));
    Serializable taskArgs = Lists.newArrayList(1);
    runTaskCommand.setTaskArgs(ByteString.copyFrom(SerializationUtils.serialize(taskArgs)));
    command.setRunTaskCommand(runTaskCommand);
    Mockito.when(mJobMasterClient.heartbeat(any(JobWorkerHealth.class), eq(Lists.newArrayList()))).thenReturn(Lists.newArrayList(command.build()));
    mCommandHandlingExecutor.heartbeat();
    ExecutorService executorService = Whitebox.getInternalState(mCommandHandlingExecutor, "mCommandHandlingService");
    executorService.shutdown();
    Assert.assertTrue(executorService.awaitTermination(5000, TimeUnit.MILLISECONDS));
    Mockito.verify(mTaskExecutorManager).getAndClearTaskUpdates();
    Mockito.verify(mTaskExecutorManager).executeTask(Mockito.eq(jobId), Mockito.eq(taskId), Mockito.eq(runTaskCommand.build()), Mockito.any(RunTaskContext.class));
}
Also used : RunTaskCommand(alluxio.grpc.RunTaskCommand) TestPlanConfig(alluxio.job.TestPlanConfig) Serializable(java.io.Serializable) RunTaskContext(alluxio.job.RunTaskContext) JobCommand(alluxio.grpc.JobCommand) ExecutorService(java.util.concurrent.ExecutorService) JobWorkerHealth(alluxio.job.wire.JobWorkerHealth) JobConfig(alluxio.job.JobConfig) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 25 with JobConfig

use of alluxio.job.JobConfig in project alluxio by Alluxio.

the class PlanCoordinator method updateStatus.

/**
 * Updates the status of the job. When all the tasks are completed, run the join method in the
 * definition.
 */
private synchronized void updateStatus() {
    int completed = 0;
    List<TaskInfo> taskInfoList = mPlanInfo.getTaskInfoList();
    JobConfig config = mPlanInfo.getJobConfig();
    Preconditions.checkNotNull(config);
    FileSystem fileSystem = mJobServerContext.getFileSystem();
    for (TaskInfo info : taskInfoList) {
        Status status = info.getStatus();
        switch(status) {
            case FAILED:
                setJobAsFailed(info.getErrorType(), "Task execution failed: " + info.getErrorMessage());
                return;
            case CANCELED:
                if (mPlanInfo.getStatus() != Status.FAILED) {
                    mPlanInfo.setStatus(Status.CANCELED);
                    DistributedCmdMetrics.incrementForAllConfigsCancelStatus(config);
                }
                return;
            case RUNNING:
                if (mPlanInfo.getStatus() != Status.FAILED && mPlanInfo.getStatus() != Status.CANCELED) {
                    mPlanInfo.setStatus(Status.RUNNING);
                }
                break;
            case COMPLETED:
                completed++;
                break;
            case CREATED:
                // do nothing
                break;
            default:
                throw new IllegalArgumentException("Unsupported status " + info.getStatus());
        }
    }
    if (completed == taskInfoList.size()) {
        if (mPlanInfo.getStatus() == Status.COMPLETED) {
            return;
        }
        // all the tasks completed, run join
        try {
            // Try to join first, so that in case of failure we don't move to a completed state yet
            mPlanInfo.setResult(join(taskInfoList));
            mPlanInfo.setStatus(Status.COMPLETED);
            // Increment the counter for Complete status when all the tasks in a job are completed.
            DistributedCmdMetrics.incrementForAllConfigsCompleteStatus(config, fileSystem, new CountingRetry(5));
        } catch (Exception e) {
            LOG.warn("Job error when joining tasks Job Id={} Config={}", mPlanInfo.getId(), mPlanInfo.getJobConfig(), e);
            setJobAsFailed(ErrorUtils.getErrorType(e), e.getMessage());
        }
    }
}
Also used : TaskInfo(alluxio.job.wire.TaskInfo) Status(alluxio.job.wire.Status) CountingRetry(alluxio.retry.CountingRetry) FileSystem(alluxio.client.file.FileSystem) BatchedJobConfig(alluxio.job.plan.BatchedJobConfig) JobConfig(alluxio.job.JobConfig) JobDoesNotExistException(alluxio.exception.JobDoesNotExistException)

Aggregations

JobConfig (alluxio.job.JobConfig)26 Test (org.junit.Test)17 SleepJobConfig (alluxio.job.SleepJobConfig)10 TestPlanConfig (alluxio.job.TestPlanConfig)9 Serializable (java.io.Serializable)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 JobServerContext (alluxio.job.JobServerContext)5 CompositeConfig (alluxio.job.workflow.composite.CompositeConfig)5 CommandManager (alluxio.master.job.command.CommandManager)5 WorkerInfo (alluxio.wire.WorkerInfo)5 ArrayList (java.util.ArrayList)5 JobDoesNotExistException (alluxio.exception.JobDoesNotExistException)4 BatchedJobConfig (alluxio.job.plan.BatchedJobConfig)4 PlanInfo (alluxio.job.plan.meta.PlanInfo)4 ResourceExhaustedException (alluxio.exception.status.ResourceExhaustedException)3 RunTaskCommand (alluxio.grpc.RunTaskCommand)3 RunTaskContext (alluxio.job.RunTaskContext)3 CompactConfig (alluxio.job.plan.transform.CompactConfig)3 WorkflowInfo (alluxio.job.wire.WorkflowInfo)3 PlanCoordinator (alluxio.master.job.plan.PlanCoordinator)3