Search in sources :

Example 1 with SUCCESS

use of io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SUCCESS in project mantis by Netflix.

the class JobClusterActor method onJobList.

@Override
public void onJobList(final ListJobsRequest request) {
    if (logger.isDebugEnabled()) {
        logger.info("Entering JCA:onJobList");
    }
    final ActorRef sender = getSender();
    final ActorRef self = getSelf();
    Set<JobId> jobIdsFilteredByLabelsSet = new HashSet<>();
    // If labels criterion is given prefilter by labels
    if (!request.getCriteria().getMatchingLabels().isEmpty()) {
        jobIdsFilteredByLabelsSet = jobManager.getJobsMatchingLabels(request.getCriteria().getMatchingLabels(), request.getCriteria().getLabelsOperand());
        // Found no jobs matching labels exit
        if (jobIdsFilteredByLabelsSet.isEmpty()) {
            if (logger.isTraceEnabled()) {
                logger.trace("Exit JCA:onJobList {}", jobIdsFilteredByLabelsSet.size());
            }
            sender.tell(new ListJobsResponse(request.requestId, SUCCESS, "", new ArrayList<>()), self);
            return;
        }
    }
    // Found jobs matching labels or no labels criterion given.
    // Apply additional criterion to both active and completed jobs
    getFilteredNonTerminalJobList(request.getCriteria(), jobIdsFilteredByLabelsSet).mergeWith(getFilteredTerminalJobList(request.getCriteria(), jobIdsFilteredByLabelsSet)).collect(() -> Lists.<MantisJobMetadataView>newArrayList(), List::add).doOnNext(resultList -> {
        if (logger.isTraceEnabled()) {
            logger.trace("Exit JCA:onJobList {}", resultList.size());
        }
        sender.tell(new ListJobsResponse(request.requestId, SUCCESS, "", resultList), self);
    }).subscribe();
}
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) ActorRef(akka.actor.ActorRef) ArrayList(java.util.ArrayList) ListJobsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsResponse) ArrayList(java.util.ArrayList) List(java.util.List) JobId(io.mantisrx.server.master.domain.JobId) HashSet(java.util.HashSet)

Example 2 with SUCCESS

use of io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SUCCESS 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 3 with SUCCESS

use of io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SUCCESS in project mantis by Netflix.

the class JobClustersManagerActor method initialize.

private void initialize(JobClustersManagerInitialize initMsg) {
    ActorRef sender = getSender();
    try {
        logger.info("In JobClustersManagerActor:initialize");
        this.jobListHelperActor = getContext().actorOf(JobListHelperActor.props(), "JobListHelperActor");
        getContext().watch(jobListHelperActor);
        mantisScheduler = initMsg.getScheduler();
        Map<String, IJobClusterMetadata> jobClusterMap = new HashMap<>();
        this.jobClusterInfoManager = new JobClusterInfoManager(jobStore, mantisScheduler, eventPublisher);
        if (!initMsg.isLoadJobsFromStore()) {
            getContext().become(initializedBehavior);
            sender.tell(new JobClustersManagerInitializeResponse(initMsg.requestId, SUCCESS, "JobClustersManager successfully inited"), getSelf());
        } else {
            List<IJobClusterMetadata> jobClusters = jobStore.loadAllJobClusters();
            logger.info("Read {} job clusters from storage", jobClusters.size());
            List<IMantisJobMetadata> activeJobs = jobStore.loadAllActiveJobs();
            logger.info("Read {} jobs from storage", activeJobs.size());
            List<CompletedJob> completedJobs = jobStore.loadAllCompletedJobs();
            logger.info("Read {} completed jobs from storage", completedJobs.size());
            for (IJobClusterMetadata jobClusterMeta : jobClusters) {
                String clusterName = jobClusterMeta.getJobClusterDefinition().getName();
                jobClusterMap.put(clusterName, jobClusterMeta);
            }
            Map<String, List<IMantisJobMetadata>> clusterToJobMap = new HashMap<>();
            Map<String, List<CompletedJob>> clusterToCompletedJobMap = new HashMap<>();
            // group jobs by cluster
            for (IMantisJobMetadata jobMeta : activeJobs) {
                String clusterName = jobMeta.getClusterName();
                clusterToJobMap.computeIfAbsent(clusterName, k -> new ArrayList<>()).add(jobMeta);
            }
            for (CompletedJob jobMeta : completedJobs) {
                String clusterName = jobMeta.getName();
                clusterToCompletedJobMap.computeIfAbsent(clusterName, k -> new ArrayList<>()).add(jobMeta);
            }
            long masterInitTimeoutSecs = ConfigurationProvider.getConfig().getMasterInitTimeoutSecs();
            long timeout = ((masterInitTimeoutSecs - 60)) > 0 ? (masterInitTimeoutSecs - 60) : masterInitTimeoutSecs;
            Observable.from(jobClusterMap.values()).filter((jobClusterMeta) -> jobClusterMeta != null && jobClusterMeta.getJobClusterDefinition() != null).flatMap((jobClusterMeta) -> {
                Duration t = Duration.ofSeconds(timeout);
                Optional<JobClusterInfo> jobClusterInfoO = jobClusterInfoManager.createClusterActorAndRegister(jobClusterMeta.getJobClusterDefinition());
                if (!jobClusterInfoO.isPresent()) {
                    logger.info("skipping job cluster {} on bootstrap as actor creating failed", jobClusterMeta.getJobClusterDefinition().getName());
                    return Observable.empty();
                }
                JobClusterInfo jobClusterInfo = jobClusterInfoO.get();
                List<IMantisJobMetadata> jobList = Lists.newArrayList();
                List<IMantisJobMetadata> jList = clusterToJobMap.get(jobClusterMeta.getJobClusterDefinition().getName());
                if (jList != null) {
                    jobList.addAll(jList);
                }
                List<CompletedJob> completedJobsList = Lists.newArrayList();
                List<CompletedJob> cList = clusterToCompletedJobMap.get(jobClusterMeta.getJobClusterDefinition().getName());
                if (cList != null) {
                    completedJobsList.addAll(cList);
                }
                JobClusterProto.InitializeJobClusterRequest req = new JobClusterProto.InitializeJobClusterRequest((JobClusterDefinitionImpl) jobClusterMeta.getJobClusterDefinition(), jobClusterMeta.isDisabled(), jobClusterMeta.getLastJobCount(), jobList, completedJobsList, "system", getSelf(), false);
                return jobClusterInfoManager.initializeCluster(jobClusterInfo, req, t);
            }).filter(Objects::nonNull).toBlocking().subscribe((clusterInit) -> {
                logger.info("JobCluster {} inited with code {}", clusterInit.jobClusterName, clusterInit.responseCode);
                numJobClusterInitSuccesses.increment();
            }, (error) -> {
                logger.warn("Exception initializing clusters {}", error.getMessage(), error);
                logger.error("JobClusterManagerActor had errors during initialization NOT transitioning to initialized behavior");
                // getContext().become(initializedBehavior);
                sender.tell(new JobClustersManagerInitializeResponse(initMsg.requestId, SERVER_ERROR, "JobClustersManager  inited with errors"), getSelf());
            }, () -> {
                logger.info("JobClusterManagerActor transitioning to initialized behavior");
                getContext().become(initializedBehavior);
                sender.tell(new JobClustersManagerInitializeResponse(initMsg.requestId, SUCCESS, "JobClustersManager successfully inited"), getSelf());
            });
            getTimers().startPeriodicTimer(CHECK_CLUSTERS_TIMER_KEY, new ReconcileJobCluster(), Duration.ofSeconds(checkAgainInSecs));
            // kick off loading of archived jobs
            logger.info("Kicking off archived job load asynchronously");
            jobStore.loadAllArchivedJobsAsync();
        }
    } catch (Exception e) {
        logger.error("caught exception", e);
        sender.tell(new JobClustersManagerInitializeResponse(initMsg.requestId, SERVER_ERROR, e.getMessage()), getSelf());
    }
    logger.info("JobClustersManagerActor:initialize ends");
}
Also used : JobId(io.mantisrx.server.master.domain.JobId) Terminated(akka.actor.Terminated) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) GetLastSubmittedJobIdStreamResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamResponse) ListArchivedWorkersRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListArchivedWorkersRequest) CreateJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.CreateJobClusterRequest) UpdateJobClusterLabelsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterLabelsResponse) ActorRef(akka.actor.ActorRef) UpdateJobClusterArtifactResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterArtifactResponse) DeleteJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DeleteJobClusterRequest) Duration(java.time.Duration) Map(java.util.Map) Schedulers(rx.schedulers.Schedulers) Metrics(io.mantisrx.common.metrics.Metrics) DisableJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterResponse) ListCompletedJobsInClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListCompletedJobsInClusterResponse) Set(java.util.Set) ListCompletedJobsInClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListCompletedJobsInClusterRequest) ScaleStageRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ScaleStageRequest) BaseResponse(io.mantisrx.master.jobcluster.proto.BaseResponse) SUCCESS_CREATED(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SUCCESS_CREATED) SubmitJobRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.SubmitJobRequest) CompletionStage(java.util.concurrent.CompletionStage) UpdateJobClusterWorkerMigrationStrategyRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterWorkerMigrationStrategyRequest) ListJobIdsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobIdsRequest) JobHelper(io.mantisrx.master.jobcluster.job.JobHelper) CLIENT_ERROR_CONFLICT(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.CLIENT_ERROR_CONFLICT) ListWorkersRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListWorkersRequest) IJobClusterMetadata(io.mantisrx.master.jobcluster.IJobClusterMetadata) Optional.empty(java.util.Optional.empty) SERVER_ERROR(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SERVER_ERROR) ListJobClustersRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobClustersRequest) MetricsRegistry(io.mantisrx.common.metrics.MetricsRegistry) 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) KillJobRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.KillJobRequest) EnableJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.EnableJobClusterRequest) CreateJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.CreateJobClusterResponse) GetJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterRequest) UpdateJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterRequest) 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) ListJobsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsResponse) ListJobClustersResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobClustersResponse) EnableJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.EnableJobClusterResponse) IJobClusterDefinition(io.mantisrx.server.master.domain.IJobClusterDefinition) GetJobSchedInfoRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobSchedInfoRequest) JobState(io.mantisrx.master.jobcluster.job.JobState) LoggerFactory(org.slf4j.LoggerFactory) GaugeCallback(io.mantisrx.common.metrics.spectator.GaugeCallback) JobCompletedReason(io.mantisrx.server.core.JobCompletedReason) 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) JobClustersManagerInitialize(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.JobClustersManagerInitialize) ReconcileJobCluster(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ReconcileJobCluster) GetJobDetailsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsResponse) JobClusterActor(io.mantisrx.master.jobcluster.JobClusterActor) ResubmitWorkerResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ResubmitWorkerResponse) DisableJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterRequest) ResubmitWorkerRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ResubmitWorkerRequest) UpdateJobClusterLabelsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterLabelsRequest) Collectors(java.util.stream.Collectors) GetJobSchedInfoResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobSchedInfoResponse) Objects(java.util.Objects) List(java.util.List) ActorPaths(akka.actor.ActorPaths) PatternsCS.ask(akka.pattern.PatternsCS.ask) SubmitJobResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.SubmitJobResponse) GetJobDetailsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsRequest) ConfigurationProvider(io.mantisrx.server.master.config.ConfigurationProvider) Optional(java.util.Optional) Props(akka.actor.Props) UpdateJobClusterSLARequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterSLARequest) ScaleStageResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ScaleStageResponse) UpdateJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterResponse) ListArchivedWorkersResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListArchivedWorkersResponse) HashMap(java.util.HashMap) UpdateJobClusterSLAResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterSLAResponse) MantisActorSupervisorStrategy(io.mantisrx.master.akka.MantisActorSupervisorStrategy) Observable(rx.Observable) DeleteJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DeleteJobClusterResponse) ListWorkersResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListWorkersResponse) AbstractActorWithTimers(akka.actor.AbstractActorWithTimers) Counter(io.mantisrx.common.metrics.Counter) Logger(org.slf4j.Logger) Optional.ofNullable(java.util.Optional.ofNullable) GetLatestJobDiscoveryInfoRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLatestJobDiscoveryInfoRequest) SUCCESS(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SUCCESS) Lists(io.mantisrx.shaded.com.google.common.collect.Lists) UpdateJobClusterArtifactRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterArtifactRequest) Collections(java.util.Collections) JobClustersManagerInitializeResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.JobClustersManagerInitializeResponse) LifecycleEventPublisher(io.mantisrx.master.events.LifecycleEventPublisher) MetricGroupId(io.mantisrx.common.metrics.spectator.MetricGroupId) JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) HashMap(java.util.HashMap) ActorRef(akka.actor.ActorRef) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ReconcileJobCluster(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ReconcileJobCluster) JobClustersManagerInitializeResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.JobClustersManagerInitializeResponse) Optional(java.util.Optional) JobClusterDefinitionImpl(io.mantisrx.server.master.domain.JobClusterDefinitionImpl) IMantisJobMetadata(io.mantisrx.master.jobcluster.job.IMantisJobMetadata) Duration(java.time.Duration) CompletedJob(io.mantisrx.server.master.domain.JobClusterDefinitionImpl.CompletedJob) Objects(java.util.Objects) IJobClusterMetadata(io.mantisrx.master.jobcluster.IJobClusterMetadata)

Example 4 with SUCCESS

use of io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SUCCESS in project mantis by Netflix.

the class JobListHelperActor method onJobClustersList.

private void onJobClustersList(ListJobClusterRequestWrapper request) {
    if (logger.isTraceEnabled()) {
        logger.trace("In onJobClustersListRequest {}", request);
    }
    ActorRef callerActor = getSender();
    Timeout timeout = new Timeout(Duration.create(500, TimeUnit.MILLISECONDS));
    List<MantisJobClusterMetadataView> clusterList = Lists.newArrayList();
    Observable.from(request.jobClusterInfoMap.values()).flatMap((jInfo) -> {
        CompletionStage<JobClusterManagerProto.GetJobClusterResponse> respCS = ask(jInfo.jobClusterActor, new JobClusterManagerProto.GetJobClusterRequest(jInfo.clusterName), timeout).thenApply(JobClusterManagerProto.GetJobClusterResponse.class::cast);
        return Observable.from(respCS.toCompletableFuture(), Schedulers.io()).onErrorResumeNext(ex -> {
            logger.warn("caught exception {}", ex.getMessage(), ex);
            return Observable.empty();
        });
    }).filter((resp) -> resp != null && resp.getJobCluster().isPresent()).map((resp) -> resp.getJobCluster().get()).doOnError(this::logError).subscribeOn(Schedulers.computation()).subscribe(clusterList::add, (err) -> {
        logger.warn("Exception in onJobClusterList ", err);
        if (logger.isTraceEnabled()) {
            logger.trace("Exit onJobClustersListRequest {}", err);
        }
        request.sender.tell(new JobClusterManagerProto.ListJobClustersResponse(request.listJobClustersRequest.requestId, SERVER_ERROR, err.getMessage(), clusterList), callerActor);
    }, () -> {
        if (logger.isTraceEnabled()) {
            logger.trace("Exit onJobClustersListRequest {}", clusterList);
        }
        request.sender.tell(new JobClusterManagerProto.ListJobClustersResponse(request.listJobClustersRequest.requestId, SUCCESS, "", clusterList), callerActor);
    });
}
Also used : SERVER_ERROR(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SERVER_ERROR) Logger(org.slf4j.Logger) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) SUCCESS(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SUCCESS) Timeout(akka.util.Timeout) Observable(rx.Observable) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) List(java.util.List) Duration(scala.concurrent.duration.Duration) Lists(io.mantisrx.shaded.com.google.common.collect.Lists) CompletionStage(java.util.concurrent.CompletionStage) ActorRef(akka.actor.ActorRef) PatternsCS.ask(akka.pattern.PatternsCS.ask) Map(java.util.Map) AbstractActor(akka.actor.AbstractActor) JobClusterProtoAdapter(io.mantisrx.master.api.akka.route.proto.JobClusterProtoAdapter) Schedulers(rx.schedulers.Schedulers) MantisJobClusterMetadataView(io.mantisrx.master.jobcluster.MantisJobClusterMetadataView) Pattern(java.util.regex.Pattern) Props(akka.actor.Props) MantisJobMetadataView(io.mantisrx.master.jobcluster.job.MantisJobMetadataView) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) MantisJobClusterMetadataView(io.mantisrx.master.jobcluster.MantisJobClusterMetadataView) CompletionStage(java.util.concurrent.CompletionStage) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto)

Example 5 with SUCCESS

use of io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SUCCESS in project mantis by Netflix.

the class JobClusterTest method testJobClusterDisable.

@Test
public void testJobClusterDisable() throws InterruptedException {
    TestKit probe = new TestKit(system);
    CountDownLatch storeCompletedCalled = new CountDownLatch(1);
    String clusterName = "testJobClusterDisable";
    MantisScheduler schedulerMock = mock(MantisScheduler.class);
    MantisJobStore jobStoreMock = mock(MantisJobStore.class);
    final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName);
    ActorRef jobClusterActor = system.actorOf(props(clusterName, jobStoreMock, schedulerMock, eventPublisher));
    jobClusterActor.tell(new JobClusterProto.InitializeJobClusterRequest(fakeJobCluster, user, probe.getRef()), probe.getRef());
    JobClusterProto.InitializeJobClusterResponse createResp = probe.expectMsgClass(JobClusterProto.InitializeJobClusterResponse.class);
    assertEquals(SUCCESS, createResp.responseCode);
    try {
        final JobDefinition jobDefn = createJob(clusterName, 1, MantisJobDurationType.Transient);
        String jobId = clusterName + "-1";
        IMantisJobMetadata completedJobMock = new MantisJobMetadataImpl.Builder().withJobId(new JobId(clusterName, 1)).withJobDefinition(jobDefn).withJobState(JobState.Completed).build();
        when(jobStoreMock.getArchivedJob(any())).thenReturn(of(completedJobMock));
        doAnswer((Answer) invocation -> {
            storeCompletedCalled.countDown();
            return null;
        }).when(jobStoreMock).storeCompletedJobForCluster(any(), any());
        JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn, jobId);
        JobTestHelper.getJobDetailsAndVerify(probe, jobClusterActor, jobId, SUCCESS, JobState.Accepted);
        jobClusterActor.tell(new DisableJobClusterRequest(clusterName, "user"), probe.getRef());
        DisableJobClusterResponse disableResp = probe.expectMsgClass(DisableJobClusterResponse.class);
        assertEquals(SUCCESS, disableResp.responseCode);
        jobClusterActor.tell(new GetJobClusterRequest(clusterName), probe.getRef());
        GetJobClusterResponse getJobClusterResp = probe.expectMsgClass(GetJobClusterResponse.class);
        assertTrue(getJobClusterResp.getJobCluster().get().isDisabled());
        jobClusterActor.tell(new GetJobDetailsRequest(clusterName, JobId.fromId(jobId).get()), probe.getRef());
        GetJobDetailsResponse jobDetailsResp = probe.expectMsgClass(GetJobDetailsResponse.class);
        assertEquals(SUCCESS, jobDetailsResp.responseCode);
        assertEquals(jobId, jobDetailsResp.getJobMetadata().get().getJobId().getId());
        assertEquals(JobState.Completed, jobDetailsResp.getJobMetadata().get().getState());
        verify(jobStoreMock, times(1)).createJobCluster(any());
        verify(jobStoreMock, times(2)).updateJobCluster(any());
        verify(jobStoreMock, times(1)).storeNewJob(any());
        verify(jobStoreMock, times(1)).updateStage(any());
        verify(jobStoreMock, times(2)).updateJob(any());
        verify(jobStoreMock, times(1)).storeNewWorkers(any(), any());
        storeCompletedCalled.await(1, TimeUnit.SECONDS);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : TestHelpers(com.netflix.mantis.master.scheduler.TestHelpers) MantisJobDurationType(io.mantisrx.runtime.MantisJobDurationType) MantisJobState(io.mantisrx.runtime.MantisJobState) Optional.of(java.util.Optional.of) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) GetLastSubmittedJobIdStreamResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamResponse) Mockito.doThrow(org.mockito.Mockito.doThrow) ListArchivedWorkersRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListArchivedWorkersRequest) UpdateJobClusterLabelsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterLabelsResponse) ActorRef(akka.actor.ActorRef) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) UpdateJobClusterArtifactResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterArtifactResponse) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Duration(java.time.Duration) Map(java.util.Map) JobClusterProtoAdapter(io.mantisrx.master.api.akka.route.proto.JobClusterProtoAdapter) Schedulers(rx.schedulers.Schedulers) MigrationStrategyEnum(io.mantisrx.runtime.WorkerMigrationConfig.MigrationStrategyEnum) AfterClass(org.junit.AfterClass) DisableJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterResponse) ScaleStageRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ScaleStageRequest) BaseResponse(io.mantisrx.master.jobcluster.proto.BaseResponse) Matchers.any(org.mockito.Matchers.any) CountDownLatch(java.util.concurrent.CountDownLatch) SubmitJobRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.SubmitJobRequest) WorkerState(io.mantisrx.master.jobcluster.job.worker.WorkerState) UpdateJobClusterWorkerMigrationStrategyRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterWorkerMigrationStrategyRequest) ListJobIdsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobIdsRequest) Assert.assertFalse(org.junit.Assert.assertFalse) NamedJob(io.mantisrx.server.master.store.NamedJob) BehaviorSubject(rx.subjects.BehaviorSubject) Mockito.mock(org.mockito.Mockito.mock) Optional.empty(java.util.Optional.empty) IMantisStorageProvider(io.mantisrx.server.master.persistence.IMantisStorageProvider) SERVER_ERROR(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SERVER_ERROR) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) ListJobIdsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobIdsResponse) Mockito.timeout(org.mockito.Mockito.timeout) Answer(org.mockito.stubbing.Answer) LifecycleEventPublisherImpl(io.mantisrx.master.events.LifecycleEventPublisherImpl) JobTestHelper(io.mantisrx.master.jobcluster.job.JobTestHelper) WorkerEvent(io.mantisrx.server.master.scheduler.WorkerEvent) GetLastSubmittedJobIdStreamRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamRequest) Label(io.mantisrx.common.Label) Config(com.typesafe.config.Config) EnableJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.EnableJobClusterRequest) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) GetJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterRequest) TYPE(io.mantisrx.server.core.Status.TYPE) File(java.io.File) UpdateJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterRequest) UpdateJobClusterWorkerMigrationStrategyResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterWorkerMigrationStrategyResponse) IMantisJobMetadata(io.mantisrx.master.jobcluster.job.IMantisJobMetadata) MantisStorageProviderAdapter(io.mantisrx.server.master.persistence.MantisStorageProviderAdapter) Assert.assertEquals(org.junit.Assert.assertEquals) ListJobsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsResponse) IMantisWorkerMetadata(io.mantisrx.master.jobcluster.job.worker.IMantisWorkerMetadata) EnableJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.EnableJobClusterResponse) JobState(io.mantisrx.master.jobcluster.job.JobState) JobCompletedReason(io.mantisrx.server.core.JobCompletedReason) StageDeploymentStrategy(io.mantisrx.runtime.descriptor.StageDeploymentStrategy) 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) JobOwner(io.mantisrx.runtime.JobOwner) GetJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterResponse) JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) JobWorker(io.mantisrx.master.jobcluster.job.worker.JobWorker) GetJobDetailsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsResponse) Assert.fail(org.junit.Assert.fail) ResubmitWorkerResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ResubmitWorkerResponse) StatusEventSubscriberLoggingImpl(io.mantisrx.master.events.StatusEventSubscriberLoggingImpl) Status(io.mantisrx.server.core.Status) DisableJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterRequest) ResubmitWorkerRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ResubmitWorkerRequest) WorkerEventSubscriberLoggingImpl(io.mantisrx.master.events.WorkerEventSubscriberLoggingImpl) UpdateJobClusterLabelsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterLabelsRequest) WorkerId(io.mantisrx.server.core.domain.WorkerId) List(java.util.List) ActorSystem(akka.actor.ActorSystem) GetJobDetailsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsRequest) SubmitJobResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.SubmitJobResponse) StageScalingPolicy(io.mantisrx.runtime.descriptor.StageScalingPolicy) Optional(java.util.Optional) UpdateJobClusterSLARequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterSLARequest) ScaleStageResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ScaleStageResponse) MantisJobMetadataView(io.mantisrx.master.jobcluster.job.MantisJobMetadataView) UpdateJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterResponse) BeforeClass(org.junit.BeforeClass) WorkerTerminate(io.mantisrx.master.jobcluster.job.worker.WorkerTerminate) WorkerMigrationConfig(io.mantisrx.runtime.WorkerMigrationConfig) ListArchivedWorkersResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListArchivedWorkersResponse) MantisJobMetadataImpl(io.mantisrx.master.jobcluster.job.MantisJobMetadataImpl) JobSla(io.mantisrx.runtime.JobSla) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) io.mantisrx.server.master.domain(io.mantisrx.server.master.domain) HashMap(java.util.HashMap) UpdateJobClusterSLAResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterSLAResponse) AuditEventSubscriberLoggingImpl(io.mantisrx.master.events.AuditEventSubscriberLoggingImpl) JobInfo(io.mantisrx.master.jobcluster.JobClusterActor.JobInfo) SchedulingInfo(io.mantisrx.runtime.descriptor.SchedulingInfo) ConfigFactory(com.typesafe.config.ConfigFactory) MachineDefinition(io.mantisrx.runtime.MachineDefinition) ListJobCriteria(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobCriteria) Mockito.when(org.mockito.Mockito.when) TestKit(akka.testkit.javadsl.TestKit) SUCCESS(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SUCCESS) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) Mockito(org.mockito.Mockito) Lists(io.mantisrx.shaded.com.google.common.collect.Lists) UpdateJobClusterArtifactRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterArtifactRequest) JobClusterActor.props(io.mantisrx.master.jobcluster.JobClusterActor.props) IMantisStageMetadata(io.mantisrx.master.jobcluster.job.IMantisStageMetadata) DeploymentStrategy(io.mantisrx.runtime.descriptor.DeploymentStrategy) LifecycleEventPublisher(io.mantisrx.master.events.LifecycleEventPublisher) WorkerHeartbeat(io.mantisrx.master.jobcluster.job.worker.WorkerHeartbeat) JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) GetJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterResponse) ActorRef(akka.actor.ActorRef) GetJobDetailsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsRequest) IMantisJobMetadata(io.mantisrx.master.jobcluster.job.IMantisJobMetadata) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) TestKit(akka.testkit.javadsl.TestKit) Matchers.anyString(org.mockito.Matchers.anyString) CountDownLatch(java.util.concurrent.CountDownLatch) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) GetJobDetailsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsResponse) DisableJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterResponse) DisableJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterRequest) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) GetJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterRequest) Test(org.junit.Test)

Aggregations

ActorRef (akka.actor.ActorRef)7 SUCCESS (io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SUCCESS)7 Lists (io.mantisrx.shaded.com.google.common.collect.Lists)7 List (java.util.List)7 Map (java.util.Map)7 Schedulers (rx.schedulers.Schedulers)7 SERVER_ERROR (io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SERVER_ERROR)6 JobClusterManagerProto (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto)6 Props (akka.actor.Props)5 PatternsCS.ask (akka.pattern.PatternsCS.ask)5 LifecycleEventPublisher (io.mantisrx.master.events.LifecycleEventPublisher)5 MantisJobMetadataView (io.mantisrx.master.jobcluster.job.MantisJobMetadataView)5 CLIENT_ERROR (io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.CLIENT_ERROR)5 IMantisJobMetadata (io.mantisrx.master.jobcluster.job.IMantisJobMetadata)4 JobState (io.mantisrx.master.jobcluster.job.JobState)4 DisableJobClusterRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterRequest)4 DisableJobClusterResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterResponse)4 EnableJobClusterRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.EnableJobClusterRequest)4 EnableJobClusterResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.EnableJobClusterResponse)4 GetJobClusterRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterRequest)4