Search in sources :

Example 1 with MantisJobMetadataImpl

use of io.mantisrx.master.jobcluster.job.MantisJobMetadataImpl in project mantis by Netflix.

the class JobClusterActor method initRunningJobs.

/**
 * Iterate through list of jobs in Active jobs table.
 * if a Job is completed move it completed table
 * else bootstrap the job (create actor, send init request)
 * Finally setup sla enforcement
 * @param initReq
 * @param sender
 */
private void initRunningJobs(JobClusterProto.InitializeJobClusterRequest initReq, ActorRef sender) {
    List<CompletedJob> completedJobsList = initReq.completedJobsList;
    List<IMantisJobMetadata> jobList = initReq.jobList;
    logger.info("In _initJobs for cluster {}: {} activeJobs and {} completedJobs", name, jobList.size(), completedJobsList.size());
    if (logger.isDebugEnabled()) {
        logger.debug("In _initJobs for cluster {} activeJobs -> {} and completedJobs -> {}", name, jobList, completedJobsList);
    }
    Observable.from(jobList).flatMap((jobMeta) -> {
        if (JobState.isTerminalState(jobMeta.getState())) {
            jobManager.persistToCompletedJobAndArchiveJobTables(jobMeta);
            return Observable.empty();
        } else {
            if (jobMeta.getSchedulingInfo() == null) {
                logger.error("Scheduling info is null for active job {} in cluster {}." + "Skipping bootstrap ", jobMeta.getJobId(), name);
                return Observable.empty();
            } else {
                return Observable.just(jobMeta);
            }
        }
    }).flatMap((jobMeta) -> jobManager.bootstrapJob((MantisJobMetadataImpl) jobMeta, this.jobClusterMetadata)).subscribe((jobInited) -> {
        logger.info("Job Id {} initialized with code {}", jobInited.jobId, jobInited.responseCode);
    }, (error) -> logger.warn("Exception initializing jobs {}", error.getMessage()), () -> {
        if (initReq.jobList.size() > 0) {
            JobId lastJobId = new JobId(this.name, initReq.lastJobNumber);
            this.jobIdSubmissionSubject.onNext(lastJobId);
        }
        setBookkeepingTimer(BOOKKEEPING_INTERVAL_SECS);
        getContext().become(initializedBehavior);
        logger.info("Job Cluster {} initialized", this.name);
        sender.tell(new JobClusterProto.InitializeJobClusterResponse(initReq.requestId, SUCCESS, String.format("JobCluster %s initialized successfully", initReq.jobClusterDefinition.getName()), initReq.jobClusterDefinition.getName(), initReq.requestor), getSelf());
    });
}
Also used : JobId(io.mantisrx.server.master.domain.JobId) Terminated(akka.actor.Terminated) Optional.of(java.util.Optional.of) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) Action1(rx.functions.Action1) TriggerOperator(com.netflix.fenzo.triggers.TriggerOperator) GetLastSubmittedJobIdStreamResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamResponse) JobActor(io.mantisrx.master.jobcluster.job.JobActor) ListArchivedWorkersRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListArchivedWorkersRequest) ActorRef(akka.actor.ActorRef) UpdateJobClusterLabelsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterLabelsResponse) UpdateJobClusterArtifactResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterArtifactResponse) Duration(java.time.Duration) Map(java.util.Map) CronPolicy(io.mantisrx.server.master.domain.IJobClusterDefinition.CronPolicy) Schedulers(rx.schedulers.Schedulers) Metrics(io.mantisrx.common.metrics.Metrics) Preconditions(com.netflix.spectator.impl.Preconditions) DisableJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterResponse) ListCompletedJobsInClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListCompletedJobsInClusterResponse) JobDefinition(io.mantisrx.server.master.domain.JobDefinition) Set(java.util.Set) ListCompletedJobsInClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListCompletedJobsInClusterRequest) ScaleStageRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ScaleStageRequest) JobStartedEvent(io.mantisrx.master.jobcluster.proto.JobClusterProto.JobStartedEvent) SubmitJobRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.SubmitJobRequest) CompletionStage(java.util.concurrent.CompletionStage) UpdateJobClusterWorkerMigrationStrategyRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterWorkerMigrationStrategyRequest) TriggerNotFoundException(com.netflix.fenzo.triggers.exceptions.TriggerNotFoundException) JobHelper(io.mantisrx.master.jobcluster.job.JobHelper) ListJobIdsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobIdsRequest) BehaviorSubject(rx.subjects.BehaviorSubject) ListWorkersRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListWorkersRequest) GetJobDefinitionUpdatedFromJobActorRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDefinitionUpdatedFromJobActorRequest) Optional.empty(java.util.Optional.empty) SERVER_ERROR(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SERVER_ERROR) CronTrigger(com.netflix.fenzo.triggers.CronTrigger) MetricsRegistry(io.mantisrx.common.metrics.MetricsRegistry) JobConstraints(io.mantisrx.runtime.JobConstraints) LabelUtils(com.mantisrx.common.utils.LabelUtils) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ListJobIdsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobIdsResponse) SupervisorStrategy(akka.actor.SupervisorStrategy) JobClusterDefinitionImpl(io.mantisrx.server.master.domain.JobClusterDefinitionImpl) WorkerEvent(io.mantisrx.server.master.scheduler.WorkerEvent) GetLastSubmittedJobIdStreamRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamRequest) Label(io.mantisrx.common.Label) EnableJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.EnableJobClusterRequest) GetJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterRequest) UpdateJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterRequest) MANTIS_MASTER_USER(io.mantisrx.master.StringConstants.MANTIS_MASTER_USER) CLIENT_ERROR_NOT_FOUND(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.CLIENT_ERROR_NOT_FOUND) UpdateJobClusterWorkerMigrationStrategyResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterWorkerMigrationStrategyResponse) CompletedJob(io.mantisrx.server.master.domain.JobClusterDefinitionImpl.CompletedJob) IMantisJobMetadata(io.mantisrx.master.jobcluster.job.IMantisJobMetadata) KillJobResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.KillJobResponse) SchedulerException(com.netflix.fenzo.triggers.exceptions.SchedulerException) IMantisWorkerMetadata(io.mantisrx.master.jobcluster.job.worker.IMantisWorkerMetadata) ListJobsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsResponse) EnableJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.EnableJobClusterResponse) IJobClusterDefinition(io.mantisrx.server.master.domain.IJobClusterDefinition) JobState(io.mantisrx.master.jobcluster.job.JobState) GetJobSchedInfoRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobSchedInfoRequest) LoggerFactory(org.slf4j.LoggerFactory) GaugeCallback(io.mantisrx.common.metrics.spectator.GaugeCallback) StageSchedulingInfo(io.mantisrx.runtime.descriptor.StageSchedulingInfo) JobCompletedReason(io.mantisrx.server.core.JobCompletedReason) InvalidJobRequest(io.mantisrx.server.master.InvalidJobRequest) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) ListJobsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsRequest) CLIENT_ERROR(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.CLIENT_ERROR) GetJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterResponse) JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) GetLatestJobDiscoveryInfoResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLatestJobDiscoveryInfoResponse) GetJobDetailsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsResponse) BasicTag(com.netflix.spectator.api.BasicTag) JobProto(io.mantisrx.master.jobcluster.proto.JobProto) ResubmitWorkerResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ResubmitWorkerResponse) ConstraintsEvaluators(io.mantisrx.server.master.ConstraintsEvaluators) DisableJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterRequest) ResubmitWorkerRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ResubmitWorkerRequest) GetJobDefinitionUpdatedFromJobActorResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDefinitionUpdatedFromJobActorResponse) UpdateJobClusterLabelsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterLabelsRequest) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SLA(io.mantisrx.server.master.domain.SLA) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) GetJobSchedInfoResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobSchedInfoResponse) Objects(java.util.Objects) List(java.util.List) PatternsCS.ask(akka.pattern.PatternsCS.ask) GetJobDetailsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsRequest) SubmitJobResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.SubmitJobResponse) ConfigurationProvider(io.mantisrx.server.master.config.ConfigurationProvider) Optional(java.util.Optional) Props(akka.actor.Props) UpdateJobClusterSLARequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterSLARequest) MantisJobMetadataView(io.mantisrx.master.jobcluster.job.MantisJobMetadataView) ScaleStageResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ScaleStageResponse) UpdateJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterResponse) JobIdInfo(io.mantisrx.master.api.akka.route.proto.JobClusterProtoAdapter.JobIdInfo) KillJobRequest(io.mantisrx.master.jobcluster.proto.JobClusterProto.KillJobRequest) ListArchivedWorkersResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListArchivedWorkersResponse) MantisJobMetadataImpl(io.mantisrx.master.jobcluster.job.MantisJobMetadataImpl) JobSla(io.mantisrx.runtime.JobSla) HashMap(java.util.HashMap) UpdateJobClusterSLAResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterSLAResponse) MantisActorSupervisorStrategy(io.mantisrx.master.akka.MantisActorSupervisorStrategy) ConcurrentMap(java.util.concurrent.ConcurrentMap) Observable(rx.Observable) HashSet(java.util.HashSet) LifecycleEventsProto(io.mantisrx.master.events.LifecycleEventsProto) DeleteJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DeleteJobClusterResponse) ListWorkersResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListWorkersResponse) AbstractActorWithTimers(akka.actor.AbstractActorWithTimers) JobClusterAlreadyExistsException(io.mantisrx.server.master.persistence.exceptions.JobClusterAlreadyExistsException) Counter(io.mantisrx.common.metrics.Counter) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Optional.ofNullable(java.util.Optional.ofNullable) ListJobCriteria(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobCriteria) GetLatestJobDiscoveryInfoRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLatestJobDiscoveryInfoRequest) JobClusterConfig(io.mantisrx.server.master.domain.JobClusterConfig) SUCCESS(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SUCCESS) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) Lists(io.mantisrx.shaded.com.google.common.collect.Lists) UpdateJobClusterArtifactRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterArtifactRequest) Collections(java.util.Collections) LifecycleEventPublisher(io.mantisrx.master.events.LifecycleEventPublisher) JobClustersManagerInitializeResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.JobClustersManagerInitializeResponse) MetricGroupId(io.mantisrx.common.metrics.spectator.MetricGroupId) JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) CompletedJob(io.mantisrx.server.master.domain.JobClusterDefinitionImpl.CompletedJob) IMantisJobMetadata(io.mantisrx.master.jobcluster.job.IMantisJobMetadata) JobId(io.mantisrx.server.master.domain.JobId)

Example 2 with MantisJobMetadataImpl

use of io.mantisrx.master.jobcluster.job.MantisJobMetadataImpl in project mantis by Netflix.

the class NoOpMantisJobOperations method convertMantisJobWriteableToMantisJobMetadata.

// TODO job specific migration config is not supported, migration config will be at cluster level
public static IMantisJobMetadata convertMantisJobWriteableToMantisJobMetadata(MantisJobMetadata archJob, LifecycleEventPublisher eventPublisher, boolean isArchived) throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("DataFormatAdapter:Converting {}", archJob);
    }
    // convert stages to new format
    List<IMantisStageMetadata> convertedStageList = new ArrayList<>();
    for (MantisStageMetadata stageMeta : ((MantisJobMetadataWritable) archJob).getStageMetadata()) {
        // if this is an archived job then add workerIndex may fail as there maybe multiple workers related to a given index so skip adding workers to stage
        boolean skipAddingWorkers = false;
        if (isArchived) {
            skipAddingWorkers = true;
        }
        convertedStageList.add(convertMantisStageMetadataWriteableToMantisStageMetadata(stageMeta, eventPublisher, skipAddingWorkers));
    }
    // generate SchedulingInfo
    SchedulingInfo schedulingInfo = generateSchedulingInfo(convertedStageList);
    URL jarUrl = archJob.getJarUrl();
    Optional<String> artifactName = extractArtifactName(jarUrl);
    // generate job defn
    JobDefinition jobDefn = new JobDefinition(archJob.getName(), archJob.getUser(), artifactName.orElse(""), null, archJob.getParameters(), archJob.getSla(), archJob.getSubscriptionTimeoutSecs(), schedulingInfo, archJob.getNumStages(), archJob.getLabels(), null);
    Optional<JobId> jIdOp = JobId.fromId(archJob.getJobId());
    if (!jIdOp.isPresent()) {
        throw new IllegalArgumentException("Invalid JobId " + archJob.getJobId());
    }
    // generate job meta
    MantisJobMetadataImpl mantisJobMetadata = new MantisJobMetadataImpl(jIdOp.get(), archJob.getSubmittedAt(), archJob.getStartedAt(), jobDefn, convertMantisJobStateToJobState(archJob.getState()), archJob.getNextWorkerNumberToUse());
    // add the stages
    for (IMantisStageMetadata stageMetadata : convertedStageList) {
        mantisJobMetadata.addJobStageIfAbsent(stageMetadata);
    }
    if (logger.isTraceEnabled()) {
        logger.trace("DataFormatAdapter:Completed conversion to IMantisJobMetadata {}", mantisJobMetadata);
    }
    return mantisJobMetadata;
}
Also used : StageSchedulingInfo(io.mantisrx.runtime.descriptor.StageSchedulingInfo) SchedulingInfo(io.mantisrx.runtime.descriptor.SchedulingInfo) ArrayList(java.util.ArrayList) URL(java.net.URL) FilterableMantisJobMetadataWritable(io.mantisrx.master.jobcluster.job.FilterableMantisJobMetadataWritable) MantisJobMetadataWritable(io.mantisrx.server.master.store.MantisJobMetadataWritable) IMantisStageMetadata(io.mantisrx.master.jobcluster.job.IMantisStageMetadata) MantisStageMetadata(io.mantisrx.server.master.store.MantisStageMetadata) IMantisStageMetadata(io.mantisrx.master.jobcluster.job.IMantisStageMetadata) MantisJobMetadataImpl(io.mantisrx.master.jobcluster.job.MantisJobMetadataImpl) MantisJobDefinition(io.mantisrx.runtime.MantisJobDefinition) NamedJobDefinition(io.mantisrx.runtime.NamedJobDefinition)

Example 3 with MantisJobMetadataImpl

use of io.mantisrx.master.jobcluster.job.MantisJobMetadataImpl in project mantis by Netflix.

the class SimpleCachedFileStorageProviderTest method testCreateJob.

@Test
public void testCreateJob() {
    String clusterName = "testCreateJob";
    SimpleCachedFileStorageProvider sProvider = new SimpleCachedFileStorageProvider();
    IJobClusterDefinition jobClusterDefn = JobTestHelper.generateJobClusterDefinition(clusterName);
    JobDefinition jobDefinition;
    try {
        jobDefinition = JobTestHelper.generateJobDefinition(clusterName);
        JobId jobId = JobId.fromId(clusterName + "-1").get();
        IMantisJobMetadata mantisJobMetaData = new MantisJobMetadataImpl.Builder().withJobId(jobId).withSubmittedAt(Instant.now()).withJobState(JobState.Accepted).withNextWorkerNumToUse(1).withJobDefinition(jobDefinition).build();
        sProvider.storeNewJob(mantisJobMetaData);
        SchedulingInfo schedInfo = jobDefinition.getSchedulingInfo();
        int numStages = schedInfo.getStages().size();
        for (int s = 1; s <= numStages; s++) {
            StageSchedulingInfo stage = schedInfo.getStages().get(s);
            IMantisStageMetadata msmd = new MantisStageMetadataImpl.Builder().withJobId(jobId).withStageNum(s).withNumStages(1).withMachineDefinition(stage.getMachineDefinition()).withNumWorkers(stage.getNumberOfInstances()).withHardConstraints(stage.getHardConstraints()).withSoftConstraints(stage.getSoftConstraints()).withScalingPolicy(stage.getScalingPolicy()).isScalable(stage.getScalable()).build();
            ((MantisJobMetadataImpl) mantisJobMetaData).addJobStageIfAbsent(msmd);
            sProvider.updateMantisStage(msmd);
            for (int w = 0; w < stage.getNumberOfInstances(); w++) {
                JobWorker mwmd = new JobWorker.Builder().withJobId(jobId).withWorkerIndex(w).withWorkerNumber(1).withNumberOfPorts(stage.getMachineDefinition().getNumPorts() + MANTIS_SYSTEM_ALLOCATED_NUM_PORTS).withStageNum(w + 1).withLifecycleEventsPublisher(eventPublisher).build();
                ((MantisJobMetadataImpl) mantisJobMetaData).addWorkerMetadata(1, mwmd);
                sProvider.storeWorker(mwmd.getMetadata());
            }
        }
        Optional<IMantisJobMetadata> loadedJobMetaOp = sProvider.loadActiveJob(jobId.getId());
        assertTrue(loadedJobMetaOp.isPresent());
        IMantisJobMetadata loadedJobMeta = loadedJobMetaOp.get();
        System.out.println("Original Job -> " + mantisJobMetaData);
        System.out.println("Loaded Job ->" + loadedJobMeta);
        isEqual(mantisJobMetaData, loadedJobMeta);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : StageSchedulingInfo(io.mantisrx.runtime.descriptor.StageSchedulingInfo) SchedulingInfo(io.mantisrx.runtime.descriptor.SchedulingInfo) IMantisJobMetadata(io.mantisrx.master.jobcluster.job.IMantisJobMetadata) JobClusterAlreadyExistsException(io.mantisrx.server.master.persistence.exceptions.JobClusterAlreadyExistsException) IOException(java.io.IOException) JobWorker(io.mantisrx.master.jobcluster.job.worker.JobWorker) IJobClusterDefinition(io.mantisrx.server.master.domain.IJobClusterDefinition) StageSchedulingInfo(io.mantisrx.runtime.descriptor.StageSchedulingInfo) IMantisStageMetadata(io.mantisrx.master.jobcluster.job.IMantisStageMetadata) MantisJobMetadataImpl(io.mantisrx.master.jobcluster.job.MantisJobMetadataImpl) JobDefinition(io.mantisrx.server.master.domain.JobDefinition) JobId(io.mantisrx.server.master.domain.JobId) Test(org.junit.Test)

Example 4 with MantisJobMetadataImpl

use of io.mantisrx.master.jobcluster.job.MantisJobMetadataImpl in project mantis by Netflix.

the class DataFormatAdapterTest method convertMantisJobWriteableTest.

@Test
public void convertMantisJobWriteableTest() throws Exception {
    String artifactName = "artifact";
    String version = "1.0.0";
    String clusterName = "myCluster";
    List<Label> labels = new ArrayList<>();
    Label label = new Label("myLable", "myVal");
    labels.add(label);
    List<Parameter> params = new ArrayList<>();
    Parameter param = new Parameter("myparam", "myval");
    params.add(param);
    long subTimeout = 1000;
    JobSla jobSla = new JobSla(100, 10, JobSla.StreamSLAType.Lossy, MantisJobDurationType.Perpetual, "userType");
    JobDefinition jobDefn = new JobDefinition.Builder().withArtifactName(artifactName).withName(clusterName).withLabels(labels).withParameters(params).withSchedulingInfo(DEFAULT_SCHED_INFO).withUser("user").withJobSla(jobSla).withSubscriptionTimeoutSecs(subTimeout).withNumberOfStages(DEFAULT_SCHED_INFO.getStages().size()).build();
    JobId jobId = new JobId(clusterName, 1);
    long currTime = System.currentTimeMillis();
    Instant startedAt = Instant.ofEpochMilli(currTime);
    Instant endedAt = startedAt.plusSeconds(5);
    Instant submittedAt = startedAt.minusSeconds(5);
    IMantisJobMetadata jobmeta = new MantisJobMetadataImpl.Builder().withJobDefinition(jobDefn).withJobId(jobId).withNextWorkerNumToUse(2).withSubmittedAt(submittedAt).withJobState(JobState.Launched).build();
    IMantisWorkerMetadata workerMetadata = new MantisWorkerMetadataImpl(0, 1, jobId.getId(), 1, 3, new WorkerPorts(Lists.newArrayList(8000, 9000, 9010, 9020, 9030)), WorkerState.Started, "slave", "slaveId", startedAt.toEpochMilli(), startedAt.toEpochMilli(), startedAt.toEpochMilli(), startedAt.toEpochMilli(), -1, JobCompletedReason.Normal, 0, 0, of("cluster"));
    ((MantisJobMetadataImpl) jobmeta).addJobStageIfAbsent(new MantisStageMetadataImpl.Builder().withNumStages(1).withStageNum(1).withNumWorkers(1).withJobId(jobId).withHardConstraints(Lists.newArrayList()).withSoftConstraints(Lists.newArrayList()).withMachineDefinition(DEFAULT_MACHINE_DEFINITION).build());
    ((MantisJobMetadataImpl) jobmeta).addWorkerMetadata(1, new JobWorker(workerMetadata, eventPublisher));
    MantisJobMetadata oldFormat = DataFormatAdapter.convertMantisJobMetadataToMantisJobMetadataWriteable(jobmeta);
    System.out.println("oldForamt -> " + oldFormat);
    assertEquals(jobId.getId(), oldFormat.getJobId());
    assertEquals(label, oldFormat.getLabels().get(0));
    assertEquals(param, oldFormat.getParameters().get(0));
    assertEquals(clusterName, oldFormat.getName());
    assertEquals(jobSla, oldFormat.getSla());
    assertEquals(1, oldFormat.getNumStages());
    assertEquals(subTimeout, oldFormat.getSubscriptionTimeoutSecs());
    assertEquals(2, oldFormat.getNextWorkerNumberToUse());
    assertEquals("http://" + artifactName, oldFormat.getJarUrl().toString());
    assertEquals(MantisJobState.Launched, oldFormat.getState());
    assertEquals(submittedAt.toEpochMilli(), oldFormat.getSubmittedAt());
    assertEquals("user", oldFormat.getUser());
    IMantisJobMetadata reconverted = DataFormatAdapter.convertMantisJobWriteableToMantisJobMetadata(oldFormat, eventPublisher);
    System.out.println("newForamt -> " + reconverted);
    // assertEquals(jobmeta, reconverted);
    // assertTrue(jobmeta.equals(reconverted));
    assertEquals(jobmeta.getArtifactName(), reconverted.getArtifactName());
    assertEquals(jobmeta.getClusterName(), reconverted.getClusterName());
    System.out.println("expected Jobdef " + jobmeta.getJobDefinition());
    System.out.println("actual   Jobdef " + reconverted.getJobDefinition());
    assertEquals(jobmeta.getJobDefinition(), reconverted.getJobDefinition());
    assertEquals(jobmeta.getJobId(), reconverted.getJobId());
    assertEquals(jobmeta.getJobJarUrl(), reconverted.getJobJarUrl());
    assertEquals(jobmeta.getLabels().get(0), reconverted.getLabels().get(0));
    assertEquals(jobmeta.getParameters().get(0), reconverted.getParameters().get(0));
    assertEquals(jobmeta.getMinRuntimeSecs(), reconverted.getMinRuntimeSecs());
    assertEquals(jobmeta.getNextWorkerNumberToUse(), reconverted.getNextWorkerNumberToUse());
    assertEquals(jobmeta.getSla().get(), reconverted.getSla().get());
    assertEquals(jobmeta.getSubmittedAtInstant(), reconverted.getSubmittedAtInstant());
    assertEquals(jobmeta.getState(), reconverted.getState());
    assertEquals(jobmeta.getSubscriptionTimeoutSecs(), reconverted.getSubscriptionTimeoutSecs());
    assertEquals(jobmeta.getTotalStages(), reconverted.getTotalStages());
    assertEquals(jobmeta.getUser(), reconverted.getUser());
// assertEquals(jobmeta.getSchedulingInfo(), reconverted.getSchedulingInfo());
}
Also used : MantisStageMetadataImpl(io.mantisrx.master.jobcluster.job.MantisStageMetadataImpl) Instant(java.time.Instant) Label(io.mantisrx.common.Label) ArrayList(java.util.ArrayList) IMantisJobMetadata(io.mantisrx.master.jobcluster.job.IMantisJobMetadata) JobWorker(io.mantisrx.master.jobcluster.job.worker.JobWorker) MantisJobMetadata(io.mantisrx.server.master.store.MantisJobMetadata) IMantisJobMetadata(io.mantisrx.master.jobcluster.job.IMantisJobMetadata) WorkerPorts(io.mantisrx.common.WorkerPorts) Parameter(io.mantisrx.runtime.parameter.Parameter) IMantisWorkerMetadata(io.mantisrx.master.jobcluster.job.worker.IMantisWorkerMetadata) JobSla(io.mantisrx.runtime.JobSla) MantisJobMetadataImpl(io.mantisrx.master.jobcluster.job.MantisJobMetadataImpl) NamedJobDefinition(io.mantisrx.runtime.NamedJobDefinition) MantisWorkerMetadataImpl(io.mantisrx.master.jobcluster.job.worker.MantisWorkerMetadataImpl) Test(org.junit.Test)

Example 5 with MantisJobMetadataImpl

use of io.mantisrx.master.jobcluster.job.MantisJobMetadataImpl in project mantis by Netflix.

the class SimpleCachedFileStorageProvider method loadJob.

private Optional<IMantisJobMetadata> loadJob(String dir, String jobId) throws IOException {
    File jobFile = new File(getJobFileName(dir, jobId));
    IMantisJobMetadata job = null;
    if (jobFile.exists()) {
        try (FileInputStream fis = new FileInputStream(jobFile)) {
            job = mapper.readValue(fis, MantisJobMetadataImpl.class);
        }
        for (IMantisStageMetadata stage : readStagesFor(new File(dir), jobId)) ((MantisJobMetadataImpl) job).addJobStageIfAbsent(stage);
        for (IMantisWorkerMetadata worker : readWorkersFor(new File(dir), jobId)) {
            try {
                JobWorker jobWorker = new JobWorker.Builder().from(worker).withLifecycleEventsPublisher(eventPublisher).build();
                ((MantisJobMetadataImpl) job).addWorkerMetadata(worker.getStageNum(), jobWorker);
            } catch (InvalidJobException e) {
                logger.warn("Unexpected error adding worker index=" + worker.getWorkerIndex() + ", number=" + worker.getWorkerNumber() + " for job " + jobId + ": " + e.getMessage(), e);
            }
        }
    }
    return Optional.ofNullable(job);
}
Also used : IMantisStageMetadata(io.mantisrx.master.jobcluster.job.IMantisStageMetadata) IMantisJobMetadata(io.mantisrx.master.jobcluster.job.IMantisJobMetadata) IMantisWorkerMetadata(io.mantisrx.master.jobcluster.job.worker.IMantisWorkerMetadata) InvalidJobException(io.mantisrx.server.master.persistence.exceptions.InvalidJobException) MantisJobMetadataImpl(io.mantisrx.master.jobcluster.job.MantisJobMetadataImpl) File(java.io.File) FileInputStream(java.io.FileInputStream) JobWorker(io.mantisrx.master.jobcluster.job.worker.JobWorker)

Aggregations

MantisJobMetadataImpl (io.mantisrx.master.jobcluster.job.MantisJobMetadataImpl)6 IMantisJobMetadata (io.mantisrx.master.jobcluster.job.IMantisJobMetadata)4 IMantisStageMetadata (io.mantisrx.master.jobcluster.job.IMantisStageMetadata)3 IMantisWorkerMetadata (io.mantisrx.master.jobcluster.job.worker.IMantisWorkerMetadata)3 JobWorker (io.mantisrx.master.jobcluster.job.worker.JobWorker)3 StageSchedulingInfo (io.mantisrx.runtime.descriptor.StageSchedulingInfo)3 JobId (io.mantisrx.server.master.domain.JobId)3 JobClusterAlreadyExistsException (io.mantisrx.server.master.persistence.exceptions.JobClusterAlreadyExistsException)3 ArrayList (java.util.ArrayList)3 SchedulerException (com.netflix.fenzo.triggers.exceptions.SchedulerException)2 TriggerNotFoundException (com.netflix.fenzo.triggers.exceptions.TriggerNotFoundException)2 Label (io.mantisrx.common.Label)2 JobSla (io.mantisrx.runtime.JobSla)2 NamedJobDefinition (io.mantisrx.runtime.NamedJobDefinition)2 SchedulingInfo (io.mantisrx.runtime.descriptor.SchedulingInfo)2 IJobClusterDefinition (io.mantisrx.server.master.domain.IJobClusterDefinition)2 JobDefinition (io.mantisrx.server.master.domain.JobDefinition)2 Instant (java.time.Instant)2 Test (org.junit.Test)2 AbstractActorWithTimers (akka.actor.AbstractActorWithTimers)1