use of org.flyte.api.v1.Primitive in project flytekit-java by flyteorg.
the class ProtoUtil method serialize.
@VisibleForTesting
static Literals.Primitive serialize(Primitive primitive) {
Literals.Primitive.Builder builder = Literals.Primitive.newBuilder();
switch(primitive.kind()) {
case INTEGER_VALUE:
builder.setInteger(primitive.integerValue());
break;
case FLOAT_VALUE:
builder.setFloatValue(primitive.floatValue());
break;
case STRING_VALUE:
builder.setStringValue(primitive.stringValue());
break;
case BOOLEAN_VALUE:
builder.setBoolean(primitive.booleanValue());
break;
case DATETIME:
Instant datetime = primitive.datetime();
builder.setDatetime(serialize(datetime));
break;
case DURATION:
Duration duration = primitive.duration();
builder.setDuration(serialize(duration));
break;
}
return builder.build();
}
use of org.flyte.api.v1.Primitive in project flytekit-java by flyteorg.
the class SdkLaunchPlanRegistrarTest method shouldLoadLaunchPlansFromDiscoveredRegistries.
@Test
void shouldLoadLaunchPlansFromDiscoveredRegistries() {
Map<LaunchPlanIdentifier, LaunchPlan> launchPlans = registrar.load(ENV);
Primitive defaultPrimitive = Primitive.ofStringValue("default-bar");
LaunchPlanIdentifier expectedTestPlan = LaunchPlanIdentifier.builder().project("project").domain("domain").name("TestPlan").version("version").build();
LaunchPlan expectedPlan = LaunchPlan.builder().name("TestPlan").workflowId(PartialWorkflowIdentifier.builder().name("org.flyte.flytekit.SdkLaunchPlanRegistrarTest$TestWorkflow").build()).fixedInputs(singletonMap("foo", Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofStringValue("bar"))))).defaultInputs(singletonMap("default-foo", Parameter.create(Variable.builder().description("").literalType(LiteralType.ofSimpleType(SimpleType.STRING)).build(), Literal.ofScalar(Scalar.ofPrimitive(defaultPrimitive))))).build();
LaunchPlanIdentifier expectedOtherTestPlan = LaunchPlanIdentifier.builder().project("project").domain("domain").name("OtherTestPlan").version("version").build();
LaunchPlan expectedOtherPlan = LaunchPlan.builder().name("OtherTestPlan").workflowId(PartialWorkflowIdentifier.builder().name("org.flyte.flytekit.SdkLaunchPlanRegistrarTest$TestWorkflow").build()).fixedInputs(singletonMap("foo", Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofStringValue("baz"))))).defaultInputs(singletonMap("default-foo", Parameter.create(Variable.builder().description("").literalType(LiteralType.ofSimpleType(SimpleType.STRING)).build(), Literal.ofScalar(Scalar.ofPrimitive(defaultPrimitive))))).build();
assertAll(() -> assertThat(launchPlans, hasEntry(is(expectedTestPlan), is(expectedPlan))), () -> assertThat(launchPlans, hasEntry(is(expectedOtherTestPlan), is(expectedOtherPlan))));
}
use of org.flyte.api.v1.Primitive in project flytekit-java by flyteorg.
the class IfBlockIdl method toOperand.
private static Operand toOperand(Map<String, Binding> extraInputs, SdkBindingData bindingData) {
BindingData idl = bindingData.idl();
if (idl.kind() == BindingData.Kind.PROMISE) {
String nextVarName = "$" + extraInputs.size();
extraInputs.put(nextVarName, Binding.builder().binding(idl).var_(nextVarName).build());
return Operand.ofVar(nextVarName);
} else {
return Operand.ofPrimitive(bindingData.idl().scalar().primitive());
}
}
use of org.flyte.api.v1.Primitive in project flytekit-java by flyteorg.
the class FlyteAdminClientTest method shouldPropagateLaunchPlanToStub.
@Test
public void shouldPropagateLaunchPlanToStub() {
PartialWorkflowIdentifier wfIdentifier = PartialWorkflowIdentifier.builder().project(PROJECT).domain(DOMAIN).name(WF_NAME).version(WF_VERSION).build();
Primitive defaultPrimitive = Primitive.ofStringValue("default-bar");
LaunchPlan launchPlan = LaunchPlan.builder().workflowId(wfIdentifier).name(LP_NAME).fixedInputs(Collections.singletonMap("foo", Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofStringValue("bar"))))).defaultInputs(Collections.singletonMap("default-foo", Parameter.create(Variable.builder().description("").literalType(LiteralType.ofSimpleType(SimpleType.STRING)).build(), Literal.ofScalar(Scalar.ofPrimitive(defaultPrimitive))))).cronSchedule(CronSchedule.builder().schedule("daily").offset(Duration.ofHours(1).toString()).build()).build();
client.createLaunchPlan(LP_IDENTIFIER, launchPlan);
assertThat(stubService.createLaunchPlanRequest, equalTo(LaunchPlanOuterClass.LaunchPlanCreateRequest.newBuilder().setId(newIdentifier(ResourceType.LAUNCH_PLAN, LP_NAME, LP_VERSION)).setSpec(LaunchPlanOuterClass.LaunchPlanSpec.newBuilder().setWorkflowId(newIdentifier(ResourceType.WORKFLOW, WF_NAME, WF_VERSION)).setFixedInputs(Literals.LiteralMap.newBuilder().putLiterals("foo", Literals.Literal.newBuilder().setScalar(Literals.Scalar.newBuilder().setPrimitive(Literals.Primitive.newBuilder().setStringValue("bar").build()).build()).build()).build()).setDefaultInputs(Interface.ParameterMap.newBuilder().putParameters("default-foo", Interface.Parameter.newBuilder().setVar(Interface.Variable.newBuilder().setDescription("").setType(Types.LiteralType.newBuilder().setSimple(Types.SimpleType.STRING).build())).setDefault(Literals.Literal.newBuilder().setScalar(Literals.Scalar.newBuilder().setPrimitive(Literals.Primitive.newBuilder().setStringValue("default-bar").build()).build()).build()).build()).build()).setEntityMetadata(LaunchPlanOuterClass.LaunchPlanMetadata.newBuilder().setSchedule(ScheduleOuterClass.Schedule.newBuilder().setCronSchedule(ScheduleOuterClass.CronSchedule.newBuilder().setSchedule("daily").setOffset("PT1H").build()).build()).build()).build()).build()));
}
use of org.flyte.api.v1.Primitive in project flytekit-java by flyteorg.
the class SdkBindingData method ofPrimitive.
public static SdkBindingData ofPrimitive(Primitive primitive) {
BindingData bindingData = BindingData.ofScalar(Scalar.ofPrimitive(primitive));
LiteralType literalType = LiteralType.ofSimpleType(getSimpleType(primitive.kind()));
return create(bindingData, literalType);
}
Aggregations