Search in sources :

Example 1 with JobletData

use of io.datarouter.joblet.storage.jobletdata.JobletData in project datarouter by hotpads.

the class TableSamplerTestTool method executeJobletsAndCollectSamples.

public static List<TableSample> executeJobletsAndCollectSamples(DatarouterInjector injector, List<JobletPackage> jobletPackages) {
    List<TableSample> results = new ArrayList<>();
    for (JobletData jobletData : JobletPackage.getJobletDatas(jobletPackages)) {
        TableSpanSamplerJoblet joblet = injector.getInstance(TableSpanSamplerJoblet.class);
        JobletRequest jobletRequest = new JobletRequest();
        // this field referenced by the joblet
        jobletRequest.getKey().setCreated(System.currentTimeMillis());
        joblet.setJobletRequest(jobletRequest);
        TableSpanSamplerJobletParams params = new TableSpanSamplerJobletCodec().unmarshallData(jobletData.getData());
        joblet.setJobletParams(params);
        joblet.process();
        results.addAll(joblet.getSamples());
    }
    return results;
}
Also used : TableSpanSamplerJobletCodec(io.datarouter.nodewatch.joblet.TableSpanSamplerJoblet.TableSpanSamplerJobletCodec) ArrayList(java.util.ArrayList) TableSpanSamplerJoblet(io.datarouter.nodewatch.joblet.TableSpanSamplerJoblet) TableSample(io.datarouter.nodewatch.storage.tablesample.TableSample) TableSpanSamplerJobletParams(io.datarouter.nodewatch.joblet.TableSpanSamplerJoblet.TableSpanSamplerJobletParams) JobletData(io.datarouter.joblet.storage.jobletdata.JobletData) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest)

Example 2 with JobletData

use of io.datarouter.joblet.storage.jobletdata.JobletData in project datarouter by hotpads.

the class JobletService method getJobletPackagesForJobletRequests.

private List<JobletPackage> getJobletPackagesForJobletRequests(Collection<JobletRequest> jobletRequests) {
    List<JobletDataKey> keys = Scanner.of(jobletRequests).map(JobletRequest::getJobletDataKey).list();
    Map<Long, JobletData> dataKeyToJobletData = jobletDataDao.getMulti(keys).stream().collect(Collectors.toMap(jobletData -> jobletData.getKey().getId(), Function.identity()));
    return jobletRequests.stream().map(jobletRequest -> {
        Long dataKey = jobletRequest.getJobletDataId();
        JobletData jobletData = dataKeyToJobletData.get(dataKey);
        return new JobletPackage(jobletRequest, jobletData);
    }).collect(Collectors.toList());
}
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) JobletDataKey(io.datarouter.joblet.storage.jobletdata.JobletDataKey) AtomicLong(java.util.concurrent.atomic.AtomicLong) JobletPackage(io.datarouter.joblet.model.JobletPackage) JobletData(io.datarouter.joblet.storage.jobletdata.JobletData)

Example 3 with JobletData

use of io.datarouter.joblet.storage.jobletdata.JobletData in project datarouter by hotpads.

the class JobletPackage method createDetailed.

public static <P> JobletPackage createDetailed(JobletType<P> jobletType, JobletPriority priority, Instant dateCreated, int batchSequence, boolean restartable, String queueId, String groupId, P params) {
    JobletCodec<P> codec = jobletType.getCodecSupplier().get();
    // build JobletData
    String encodedParams = codec.marshallData(params);
    JobletData data = new JobletData(encodedParams);
    // build JobletRequest
    JobletRequest request = new JobletRequest(jobletType, priority, dateCreated, batchSequence, restartable, getDataSignature(encodedParams));
    request.setQueueId(queueId);
    request.setGroupId(groupId);
    request.setNumItems(codec.calculateNumItems(params));
    return new JobletPackage(request, data);
}
Also used : JobletData(io.datarouter.joblet.storage.jobletdata.JobletData) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest)

Aggregations

JobletData (io.datarouter.joblet.storage.jobletdata.JobletData)3 JobletRequest (io.datarouter.joblet.storage.jobletrequest.JobletRequest)3 DatarouterJobletCounters (io.datarouter.joblet.DatarouterJobletCounters)1 JobletExceptionCategory (io.datarouter.joblet.JobletExceptionCategory)1 JobletQueueMechanism (io.datarouter.joblet.enums.JobletQueueMechanism)1 JobletStatus (io.datarouter.joblet.enums.JobletStatus)1 JobletPackage (io.datarouter.joblet.model.JobletPackage)1 JobletRequestQueueManager (io.datarouter.joblet.queue.JobletRequestQueueManager)1 JobletRequestSelector (io.datarouter.joblet.queue.JobletRequestSelector)1 JobletRequestSelectorFactory (io.datarouter.joblet.queue.JobletRequestSelectorFactory)1 DatarouterJobletSettingRoot (io.datarouter.joblet.setting.DatarouterJobletSettingRoot)1 DatarouterJobletDataDao (io.datarouter.joblet.storage.jobletdata.DatarouterJobletDataDao)1 JobletDataKey (io.datarouter.joblet.storage.jobletdata.JobletDataKey)1 DatarouterJobletRequestDao (io.datarouter.joblet.storage.jobletrequest.DatarouterJobletRequestDao)1 JobletRequestKey (io.datarouter.joblet.storage.jobletrequest.JobletRequestKey)1 DatarouterJobletQueueDao (io.datarouter.joblet.storage.jobletrequestqueue.DatarouterJobletQueueDao)1 JobletRequestQueueKey (io.datarouter.joblet.storage.jobletrequestqueue.JobletRequestQueueKey)1 JobletType (io.datarouter.joblet.type.JobletType)1 JobletTypeFactory (io.datarouter.joblet.type.JobletTypeFactory)1 Databean (io.datarouter.model.databean.Databean)1