Search in sources :

Example 1 with Metadata

use of io.mantisrx.runtime.Metadata in project mantis by Netflix.

the class CreateJobDescriptorFile method execute.

@SuppressWarnings("unchecked")
@Override
public void execute() throws CommandException {
    Metadata jobMetadata = job.getMetadata();
    // create stage info
    Map<Integer, StageInfo> stagesInfo = new HashMap<>();
    List<StageConfig<?, ?>> stages = job.getStages();
    int numStages = 0;
    for (StageConfig<?, ?> stage : stages) {
        stagesInfo.put(numStages, new StageInfo(numStages, stage.getDescription()));
        numStages++;
    }
    // create parameter info
    final Map<String, ParameterInfo> parameterInfo = createParameterInfo(job.getParameterDefinitions());
    final Map<String, ParameterInfo> systemParameterInfo = createParameterInfo(ParameterUtils.getSystemParameters());
    final int totalNumStages = numStages;
    final Map<String, ParameterInfo> sysParams = systemParameterInfo.entrySet().stream().filter(sysParam -> {
        for (int stageNum = totalNumStages + 1; stageNum <= ParameterUtils.MAX_NUM_STAGES_FOR_JVM_OPTS_OVERRIDE; stageNum++) {
            if (sysParam.getKey().equals(String.format(ParameterUtils.PER_STAGE_JVM_OPTS_FORMAT, stageNum))) {
                return false;
            }
        }
        return true;
    }).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
    parameterInfo.putAll(sysParams);
    // create source/sink info
    Metadata sourceMetadata = job.getSource().getMetadata();
    MetadataInfo sourceMetadataInfo = toMetaDataInfo(sourceMetadata);
    Metadata sinkMetadata = job.getSink().getMetadata();
    MetadataInfo sinkMetadataInfo = toMetaDataInfo(sinkMetadata);
    JobInfo jobInfo = new JobInfo(jobMetadata.getName(), jobMetadata.getDescription(), numStages, parameterInfo, sourceMetadataInfo, sinkMetadataInfo, stagesInfo);
    JobDescriptor jobDescriptor = new JobDescriptor(jobInfo, project, version, System.currentTimeMillis(), readyForJobMaster);
    try {
        mapper.writeValue(descriptorFile, jobDescriptor);
    } catch (IOException e) {
        throw new DescriptorException(e);
    }
}
Also used : StageInfo(io.mantisrx.runtime.descriptor.StageInfo) StageConfig(io.mantisrx.runtime.StageConfig) ObjectMapper(io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper) Metadata(io.mantisrx.runtime.Metadata) IOException(java.io.IOException) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) File(java.io.File) ParameterDefinition(io.mantisrx.runtime.parameter.ParameterDefinition) Job(io.mantisrx.runtime.Job) DeserializationFeature(io.mantisrx.shaded.com.fasterxml.jackson.databind.DeserializationFeature) List(java.util.List) MetadataInfo(io.mantisrx.runtime.descriptor.MetadataInfo) ParameterUtils(io.mantisrx.runtime.parameter.ParameterUtils) Map(java.util.Map) Entry(java.util.Map.Entry) JobInfo(io.mantisrx.runtime.descriptor.JobInfo) JobDescriptor(io.mantisrx.runtime.descriptor.JobDescriptor) ParameterInfo(io.mantisrx.runtime.descriptor.ParameterInfo) MetadataInfo(io.mantisrx.runtime.descriptor.MetadataInfo) HashMap(java.util.HashMap) JobDescriptor(io.mantisrx.runtime.descriptor.JobDescriptor) StageInfo(io.mantisrx.runtime.descriptor.StageInfo) Metadata(io.mantisrx.runtime.Metadata) ParameterInfo(io.mantisrx.runtime.descriptor.ParameterInfo) IOException(java.io.IOException) StageConfig(io.mantisrx.runtime.StageConfig) JobInfo(io.mantisrx.runtime.descriptor.JobInfo)

Example 2 with Metadata

use of io.mantisrx.runtime.Metadata in project mantis by Netflix.

the class PushRequestEventSourceJob method getJobInstance.

@Override
public Job<String> getJobInstance() {
    String jobId = Utils.getEnvVariable("JOB_ID", "PushRequestEventSourceJobLocal-1");
    String mantisClientId = MANTIS_CLIENT_ID + "_" + jobId;
    QueryRegistry queryRegistry = new QueryRegistry.Builder().withClientIdPrefix(mantisClientId).build();
    String customPortName = "MANTIS_WORKER_CUSTOM_PORT";
    String consolePort = Utils.getEnvVariable(customPortName, "9090");
    int port = 9090;
    if (consolePort != null && !consolePort.isEmpty()) {
        port = Integer.parseInt(consolePort);
    }
    return MantisJob.source(new PushHttpSource(queryRegistry, port)).stage(new EchoStage(), EchoStage.config()).sink(new SourceSink(new RequestPreProcessor(queryRegistry), new RequestPostProcessor(queryRegistry), mantisClientId)).parameterDefinition(new IntParameter().name(MantisSourceJobConstants.ECHO_STAGE_BUFFER_MILLIS).description("millis to buffer events before processing").validator(Validators.range(100, 1000)).defaultValue(250).build()).metadata(new Metadata.Builder().name("PushRequestEventSourceJob").description("Fetches request events from any source in a distributed manner. " + "The output is served via HTTP server using SSE protocol.").build()).create();
}
Also used : RequestPreProcessor(io.mantisrx.sourcejobs.publish.core.RequestPreProcessor) RequestPostProcessor(io.mantisrx.sourcejobs.publish.core.RequestPostProcessor) PushHttpSource(io.mantisrx.connector.publish.source.http.PushHttpSource) QueryRegistry(io.mantisrx.connector.publish.core.QueryRegistry) Metadata(io.mantisrx.runtime.Metadata) EchoStage(io.mantisrx.sourcejobs.publish.stages.EchoStage) SourceSink(io.mantisrx.connector.publish.source.http.SourceSink) IntParameter(io.mantisrx.runtime.parameter.type.IntParameter)

Example 3 with Metadata

use of io.mantisrx.runtime.Metadata in project mantis by Netflix.

the class TestJobParameterized method getJobInstance.

@Override
public Job<Integer> getJobInstance() {
    return MantisJob.<Integer>source(new Source<Integer>() {

        @Override
        public Observable<Observable<Integer>> call(Context context, Index index) {
            Integer start = (Integer) context.getParameters().get("start-range");
            Integer end = (Integer) context.getParameters().get("end-range");
            return Observable.just(Observable.range(start, end));
        }
    }).stage(new ScalarComputation<Integer, Integer>() {

        @Override
        public Observable<Integer> call(Context context, Observable<Integer> t1) {
            final Integer scale = (Integer) context.getParameters().get("scale-by");
            return t1.map(new Func1<Integer, Integer>() {

                @Override
                public Integer call(Integer t1) {
                    return t1 * scale;
                }
            });
        }
    }, new ScalarToScalar.Config<Integer, Integer>().codec(Codecs.integer())).sink(new Sink<Integer>() {

        @Override
        public void init(Context context) {
            System.out.println("sink init called");
        }

        @Override
        public void call(Context context, PortRequest p, Observable<Integer> o) {
            final String message = (String) context.getParameters().get("sink-message");
            o.toBlocking().forEach(new Action1<Integer>() {

                @Override
                public void call(Integer t1) {
                    System.out.println(message + t1);
                    itemsWritten.add(t1);
                }
            });
        }
    }).metadata(new Metadata.Builder().name("test job").description("showcase parameters").build()).parameterDefinition(new IntParameter().name("start-range").validator(Validators.range(0, 100)).build()).parameterDefinition(new IntParameter().name("end-range").validator(Validators.range(100, 1000)).build()).parameterDefinition(new IntParameter().name("scale-by").description("scale each value from the range").validator(Validators.range(1, 10)).build()).parameterDefinition(new StringParameter().name("sink-message").defaultValue("hello: ").description("concat with results").validator(Validators.notNullOrEmpty()).build()).create();
}
Also used : Context(io.mantisrx.runtime.Context) StringParameter(io.mantisrx.runtime.parameter.type.StringParameter) Action1(rx.functions.Action1) Metadata(io.mantisrx.runtime.Metadata) Index(io.mantisrx.runtime.source.Index) Observable(rx.Observable) ScalarToScalar(io.mantisrx.runtime.ScalarToScalar) PortRequest(io.mantisrx.runtime.PortRequest) ScalarComputation(io.mantisrx.runtime.computation.ScalarComputation) IntParameter(io.mantisrx.runtime.parameter.type.IntParameter)

Aggregations

Metadata (io.mantisrx.runtime.Metadata)3 IntParameter (io.mantisrx.runtime.parameter.type.IntParameter)2 QueryRegistry (io.mantisrx.connector.publish.core.QueryRegistry)1 PushHttpSource (io.mantisrx.connector.publish.source.http.PushHttpSource)1 SourceSink (io.mantisrx.connector.publish.source.http.SourceSink)1 Context (io.mantisrx.runtime.Context)1 Job (io.mantisrx.runtime.Job)1 PortRequest (io.mantisrx.runtime.PortRequest)1 ScalarToScalar (io.mantisrx.runtime.ScalarToScalar)1 StageConfig (io.mantisrx.runtime.StageConfig)1 ScalarComputation (io.mantisrx.runtime.computation.ScalarComputation)1 JobDescriptor (io.mantisrx.runtime.descriptor.JobDescriptor)1 JobInfo (io.mantisrx.runtime.descriptor.JobInfo)1 MetadataInfo (io.mantisrx.runtime.descriptor.MetadataInfo)1 ParameterInfo (io.mantisrx.runtime.descriptor.ParameterInfo)1 StageInfo (io.mantisrx.runtime.descriptor.StageInfo)1 ParameterDefinition (io.mantisrx.runtime.parameter.ParameterDefinition)1 ParameterUtils (io.mantisrx.runtime.parameter.ParameterUtils)1 StringParameter (io.mantisrx.runtime.parameter.type.StringParameter)1 Index (io.mantisrx.runtime.source.Index)1