Search in sources :

Example 1 with Primitive

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();
}
Also used : Primitive(org.flyte.api.v1.Primitive) Instant(java.time.Instant) Duration(java.time.Duration) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with Primitive

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))));
}
Also used : LaunchPlanIdentifier(org.flyte.api.v1.LaunchPlanIdentifier) Primitive(org.flyte.api.v1.Primitive) LaunchPlan(org.flyte.api.v1.LaunchPlan) Test(org.junit.jupiter.api.Test)

Example 3 with Primitive

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());
    }
}
Also used : BindingData(org.flyte.api.v1.BindingData)

Example 4 with 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()));
}
Also used : PartialWorkflowIdentifier(org.flyte.api.v1.PartialWorkflowIdentifier) Primitive(org.flyte.api.v1.Primitive) LaunchPlan(org.flyte.api.v1.LaunchPlan) Test(org.junit.Test)

Example 5 with Primitive

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);
}
Also used : LiteralType(org.flyte.api.v1.LiteralType) BindingData(org.flyte.api.v1.BindingData)

Aggregations

Primitive (org.flyte.api.v1.Primitive)3 BindingData (org.flyte.api.v1.BindingData)2 LaunchPlan (org.flyte.api.v1.LaunchPlan)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 LaunchPlanIdentifier (org.flyte.api.v1.LaunchPlanIdentifier)1 LiteralType (org.flyte.api.v1.LiteralType)1 PartialWorkflowIdentifier (org.flyte.api.v1.PartialWorkflowIdentifier)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1