Search in sources :

Example 1 with JobletType

use of io.datarouter.joblet.type.JobletType in project datarouter by hotpads.

the class JobletUpdateHandler method copyJobletRequestsToQueues.

@Handler
private Mav copyJobletRequestsToQueues(@Param(PARAM_jobletType) OptionalString jobletType) {
    List<JobletType<?>> jobletTypes = jobletType.isPresent() ? List.of(jobletTypeFactory.fromPersistentString(jobletType.get())) : jobletTypeFactory.getAllTypes();
    long numCopied = 0;
    for (JobletType<?> type : jobletTypes) {
        Scanner<JobletRequest> requestsOfType = jobletRequestDao.scanType(type, false).include(jobletRequest -> JobletStatus.CREATED == jobletRequest.getStatus());
        for (List<JobletRequest> requestBatch : requestsOfType.batch(100).iterable()) {
            Map<JobletRequestQueueKey, List<JobletRequest>> requestsByQueueKey = Scanner.of(requestBatch).groupBy(jobletRequestQueueManager::getQueueKey);
            for (JobletRequestQueueKey queueKey : requestsByQueueKey.keySet()) {
                List<JobletRequest> jobletsForQueue = requestsByQueueKey.get(queueKey);
                jobletQueueDao.getQueue(queueKey).putMulti(jobletsForQueue);
                numCopied += jobletsForQueue.size();
            }
            logger.warn("copied {}", numCopied);
        }
    }
    var dto = new DatarouterChangelogDtoBuilder("Joblet", jobletType.orElse("all"), "requeue", getSessionInfo().getRequiredSession().getUsername()).build();
    changelogRecorder.record(dto);
    return pageFactory.message(request, "copied " + numCopied);
}
Also used : JobletType(io.datarouter.joblet.type.JobletType) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest) ArrayList(java.util.ArrayList) List(java.util.List) DatarouterChangelogDtoBuilder(io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder) JobletRequestQueueKey(io.datarouter.joblet.storage.jobletrequestqueue.JobletRequestQueueKey) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 2 with JobletType

use of io.datarouter.joblet.type.JobletType in project datarouter by hotpads.

the class JobletUpdateHandler method timeoutStuckRunning.

// is this used?
@Handler
private Mav timeoutStuckRunning(String type) {
    JobletType<?> jobletType = jobletTypeFactory.fromPersistentString(type);
    Scanner<JobletRequest> requests = jobletRequestDao.scanType(jobletType, false).include(request -> request.getStatus() == JobletStatus.RUNNING).include(request -> request.getReservedAgoMs().isPresent()).include(request -> request.getReservedAgoMs().get() > Duration.ofDays(2).toMillis());
    long numTimedOut = 0;
    for (List<JobletRequest> requestBatch : requests.batch(100).iterable()) {
        List<JobletRequest> toSave = new ArrayList<>();
        for (JobletRequest request : requestBatch) {
            request.setStatus(JobletStatus.CREATED);
            request.setNumFailures(0);
            ++numTimedOut;
        }
        jobletRequestDao.putMulti(toSave);
        logger.warn("copied {}", numTimedOut);
    }
    changelogRecorder.record(new DatarouterChangelogDtoBuilder("Joblet", type, "timeoutStuckRunning", getSessionInfo().getRequiredSession().getUsername()).build());
    return pageFactory.message(request, "timedOut " + numTimedOut);
}
Also used : JobletService(io.datarouter.joblet.service.JobletService) Scanner(io.datarouter.scanner.Scanner) JobletTypeFactory(io.datarouter.joblet.type.JobletTypeFactory) LoggerFactory(org.slf4j.LoggerFactory) JobletRequestQueueManager(io.datarouter.joblet.queue.JobletRequestQueueManager) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) JobletStatus(io.datarouter.joblet.enums.JobletStatus) ArrayList(java.util.ArrayList) ChangelogRecorder(io.datarouter.instrumentation.changelog.ChangelogRecorder) Inject(javax.inject.Inject) JobletType(io.datarouter.joblet.type.JobletType) JobletRequestKey(io.datarouter.joblet.storage.jobletrequest.JobletRequestKey) Duration(java.time.Duration) Map(java.util.Map) DatarouterJobletRequestDao(io.datarouter.joblet.storage.jobletrequest.DatarouterJobletRequestDao) Param(io.datarouter.web.handler.types.Param) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest) JobletPageFactory(io.datarouter.joblet.JobletPageFactory) JobletRequestQueueKey(io.datarouter.joblet.storage.jobletrequestqueue.JobletRequestQueueKey) Logger(org.slf4j.Logger) DatarouterChangelogDtoBuilder(io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder) Mav(io.datarouter.web.handler.mav.Mav) DatarouterJobletQueueDao(io.datarouter.joblet.storage.jobletrequestqueue.DatarouterJobletQueueDao) Objects(java.util.Objects) List(java.util.List) Databean(io.datarouter.model.databean.Databean) BaseHandler(io.datarouter.web.handler.BaseHandler) ArrayList(java.util.ArrayList) DatarouterChangelogDtoBuilder(io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 3 with JobletType

use of io.datarouter.joblet.type.JobletType in project datarouter by hotpads.

the class JobletUpdateHandler method deleteGroup.

@Handler
private Mav deleteGroup(@Param(PARAM_jobletType) String typeString, @Param(PARAM_executionOrder) Integer executionOrder, @Param(PARAM_status) String status) {
    JobletType<?> jobletType = jobletTypeFactory.fromPersistentString(typeString);
    Objects.requireNonNull(jobletType, "No joblet type found with name=" + typeString);
    JobletStatus statusString = JobletStatus.fromPersistentStringStatic(status);
    JobletRequestKey prefix = JobletRequestKey.create(jobletType, executionOrder, null, null);
    jobletRequestDao.scanWithPrefix(prefix).include(jobletRequest -> statusString == jobletRequest.getStatus()).map(Databean::getKey).batch(100).forEach(jobletRequestDao::deleteMulti);
    String message = String.format("Deleted joblets with type %s, status %s, executionOrder %s", typeString, status, executionOrder);
    var dto = new DatarouterChangelogDtoBuilder("Joblet", typeString + " " + status + " " + executionOrder, "deleteGroup", getSessionInfo().getRequiredSession().getUsername()).build();
    changelogRecorder.record(dto);
    return pageFactory.message(request, message);
}
Also used : JobletService(io.datarouter.joblet.service.JobletService) Scanner(io.datarouter.scanner.Scanner) JobletTypeFactory(io.datarouter.joblet.type.JobletTypeFactory) LoggerFactory(org.slf4j.LoggerFactory) JobletRequestQueueManager(io.datarouter.joblet.queue.JobletRequestQueueManager) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) JobletStatus(io.datarouter.joblet.enums.JobletStatus) ArrayList(java.util.ArrayList) ChangelogRecorder(io.datarouter.instrumentation.changelog.ChangelogRecorder) Inject(javax.inject.Inject) JobletType(io.datarouter.joblet.type.JobletType) JobletRequestKey(io.datarouter.joblet.storage.jobletrequest.JobletRequestKey) Duration(java.time.Duration) Map(java.util.Map) DatarouterJobletRequestDao(io.datarouter.joblet.storage.jobletrequest.DatarouterJobletRequestDao) Param(io.datarouter.web.handler.types.Param) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest) JobletPageFactory(io.datarouter.joblet.JobletPageFactory) JobletRequestQueueKey(io.datarouter.joblet.storage.jobletrequestqueue.JobletRequestQueueKey) Logger(org.slf4j.Logger) DatarouterChangelogDtoBuilder(io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder) Mav(io.datarouter.web.handler.mav.Mav) DatarouterJobletQueueDao(io.datarouter.joblet.storage.jobletrequestqueue.DatarouterJobletQueueDao) Objects(java.util.Objects) List(java.util.List) Databean(io.datarouter.model.databean.Databean) BaseHandler(io.datarouter.web.handler.BaseHandler) JobletRequestKey(io.datarouter.joblet.storage.jobletrequest.JobletRequestKey) Databean(io.datarouter.model.databean.Databean) JobletStatus(io.datarouter.joblet.enums.JobletStatus) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) DatarouterChangelogDtoBuilder(io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 4 with JobletType

use of io.datarouter.joblet.type.JobletType in project datarouter by hotpads.

the class JobletService method restartJoblets.

public long restartJoblets(JobletType<?> jobletType, JobletStatus jobletStatus) {
    var numRestarted = new AtomicLong();
    jobletRequestDao.scanType(jobletType, false).include(request -> request.getStatus() == jobletStatus).forEach(request -> {
        request.setStatus(JobletStatus.CREATED);
        request.setNumFailures(0);
        jobletRequestDao.put(request);
        if (Objects.equals(jobletSettings.queueMechanism.get(), JobletQueueMechanism.QUEUE.getPersistentString())) {
            JobletRequestQueueKey queueKey = jobletRequestQueueManager.getQueueKey(request);
            jobletQueueDao.getQueue(queueKey).put(request);
        }
        numRestarted.incrementAndGet();
        logger.warn("restarted {}", numRestarted.get());
    });
    return numRestarted.get();
}
Also used : IntStream(java.util.stream.IntStream) Scanner(io.datarouter.scanner.Scanner) DatarouterJobletSettingRoot(io.datarouter.joblet.setting.DatarouterJobletSettingRoot) JobletTypeFactory(io.datarouter.joblet.type.JobletTypeFactory) JobletPackage(io.datarouter.joblet.model.JobletPackage) JobletRequestSelector(io.datarouter.joblet.queue.JobletRequestSelector) ExceptionRecorder(io.datarouter.web.exception.ExceptionRecorder) LoggerFactory(org.slf4j.LoggerFactory) JobletRequestQueueManager(io.datarouter.joblet.queue.JobletRequestQueueManager) Singleton(javax.inject.Singleton) ServerName(io.datarouter.storage.config.properties.ServerName) Function(java.util.function.Function) JobletStatus(io.datarouter.joblet.enums.JobletStatus) Inject(javax.inject.Inject) JobletType(io.datarouter.joblet.type.JobletType) JobletRequestKey(io.datarouter.joblet.storage.jobletrequest.JobletRequestKey) JobletRequestSelectorFactory(io.datarouter.joblet.queue.JobletRequestSelectorFactory) Map(java.util.Map) Config(io.datarouter.storage.config.Config) HashMethods(io.datarouter.util.HashMethods) DatarouterJobletRequestDao(io.datarouter.joblet.storage.jobletrequest.DatarouterJobletRequestDao) JobletDataKey(io.datarouter.joblet.storage.jobletdata.JobletDataKey) PhaseTimer(io.datarouter.util.timer.PhaseTimer) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest) JobletExceptionCategory(io.datarouter.joblet.JobletExceptionCategory) JobletRequestQueueKey(io.datarouter.joblet.storage.jobletrequestqueue.JobletRequestQueueKey) Logger(org.slf4j.Logger) DatarouterJobletCounters(io.datarouter.joblet.DatarouterJobletCounters) DatarouterJobletDataDao(io.datarouter.joblet.storage.jobletdata.DatarouterJobletDataDao) Collection(java.util.Collection) DatarouterJobletQueueDao(io.datarouter.joblet.storage.jobletrequestqueue.DatarouterJobletQueueDao) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Range(io.datarouter.util.tuple.Range) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Databean(io.datarouter.model.databean.Databean) CachedWebappInstancesOfThisServerType(io.datarouter.webappinstance.service.CachedWebappInstancesOfThisServerType) Entry(java.util.Map.Entry) Optional(java.util.Optional) JobletData(io.datarouter.joblet.storage.jobletdata.JobletData) PutMethod(io.datarouter.storage.config.PutMethod) JobletQueueMechanism(io.datarouter.joblet.enums.JobletQueueMechanism) AtomicLong(java.util.concurrent.atomic.AtomicLong) JobletRequestQueueKey(io.datarouter.joblet.storage.jobletrequestqueue.JobletRequestQueueKey)

Aggregations

JobletRequest (io.datarouter.joblet.storage.jobletrequest.JobletRequest)4 JobletRequestQueueKey (io.datarouter.joblet.storage.jobletrequestqueue.JobletRequestQueueKey)4 JobletType (io.datarouter.joblet.type.JobletType)4 List (java.util.List)4 DatarouterChangelogDtoBuilder (io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder)3 JobletStatus (io.datarouter.joblet.enums.JobletStatus)3 JobletRequestQueueManager (io.datarouter.joblet.queue.JobletRequestQueueManager)3 DatarouterJobletRequestDao (io.datarouter.joblet.storage.jobletrequest.DatarouterJobletRequestDao)3 JobletRequestKey (io.datarouter.joblet.storage.jobletrequest.JobletRequestKey)3 DatarouterJobletQueueDao (io.datarouter.joblet.storage.jobletrequestqueue.DatarouterJobletQueueDao)3 JobletTypeFactory (io.datarouter.joblet.type.JobletTypeFactory)3 Databean (io.datarouter.model.databean.Databean)3 Scanner (io.datarouter.scanner.Scanner)3 BaseHandler (io.datarouter.web.handler.BaseHandler)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Objects (java.util.Objects)3 Inject (javax.inject.Inject)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3