52 lines
2 KiB
Java
52 lines
2 KiB
Java
package com.databuild.examples.basic_graph;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
|
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
|
|
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator;
|
|
|
|
import java.io.File;
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
|
|
/**
|
|
* Configure class for generating a random number.
|
|
* This class creates a job configuration for generating a random number based on the partition ref.
|
|
*/
|
|
public class SumConfigure {
|
|
public static void main(String[] args) {
|
|
if (args.length != 1) {
|
|
System.err.println("Error: Must provide exactly one partition ref as an argument");
|
|
System.exit(1);
|
|
}
|
|
|
|
String partitionRef = args[0];
|
|
String[] upstreams = partitionRef.split("_");
|
|
|
|
// Create and populate JobConfig object
|
|
JobConfig config = new JobConfig();
|
|
config.outputs = Collections.singletonList(partitionRef);
|
|
config.args = Arrays.asList(upstreams);
|
|
// inputs and env are already initialized as empty collections in the constructor
|
|
|
|
try {
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
// Load the schema
|
|
JsonNode schemaNode = mapper.readTree(new File("../databuild+/databuild.schema.json"));
|
|
|
|
// Create JSON Schema validator
|
|
JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper);
|
|
JsonSchema schema = schemaGen.generateSchema(JobConfig.class);
|
|
|
|
// Convert config to JsonNode and serialize
|
|
JsonNode configNode = mapper.valueToTree(config);
|
|
String jsonConfig = mapper.writeValueAsString(configNode);
|
|
System.out.println(jsonConfig);
|
|
} catch (Exception e) {
|
|
System.err.println("Error: Failed to validate or serialize config: " + e.getMessage());
|
|
System.exit(1);
|
|
}
|
|
}
|
|
}
|