Search in sources :

Example 26 with Container

use of net.minecraft.server.v1_15_R1.Container in project flytekit-java by flyteorg.

the class ProjectClosureTest method testCreateTaskTemplateForRunnableTaskWithResources.

@Test
public void testCreateTaskTemplateForRunnableTaskWithResources() {
    // given
    Map<Resources.ResourceName, String> resourceValues = new HashMap<>();
    resourceValues.put(Resources.ResourceName.MEMORY, "0.5Gi");
    Resources expectedResources = Resources.builder().limits(resourceValues).requests(resourceValues).build();
    RunnableTask task = createRunnableTask(expectedResources);
    String image = "my-image";
    // when
    TaskTemplate result = ProjectClosure.createTaskTemplateForRunnableTask(task, image);
    // then
    Container container = result.container();
    assertNotNull(container);
    assertThat(container.image(), equalTo(image));
    assertThat(container.resources(), equalTo(expectedResources));
    assertThat(result.interface_(), equalTo(TypedInterface.builder().inputs(SdkTypes.nulls().getVariableMap()).outputs(SdkTypes.nulls().getVariableMap()).build()));
    assertThat(result.custom(), equalTo(Struct.of(emptyMap())));
    assertThat(result.retries(), equalTo(RetryStrategy.builder().retries(0).build()));
    assertThat(result.type(), equalTo("java-task"));
}
Also used : TaskTemplate(org.flyte.api.v1.TaskTemplate) Container(org.flyte.api.v1.Container) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) Resources(org.flyte.api.v1.Resources) RunnableTask(org.flyte.api.v1.RunnableTask) Test(org.junit.jupiter.api.Test)

Example 27 with Container

use of net.minecraft.server.v1_15_R1.Container in project flytekit-java by flyteorg.

the class ProtoUtilTest method shouldSerDeTaskTemplate.

@Test
void shouldSerDeTaskTemplate() {
    Container container = Container.builder().command(ImmutableList.of("echo")).args(ImmutableList.of("hello world")).env(ImmutableList.of(KeyValuePair.of("key", "value"))).image("alpine:3.7").build();
    Variable stringVar = ApiUtils.createVar(SimpleType.STRING);
    Variable integerVar = ApiUtils.createVar(SimpleType.INTEGER);
    TypedInterface interface_ = TypedInterface.builder().inputs(ImmutableMap.of("x", stringVar)).outputs(ImmutableMap.of("y", integerVar)).build();
    RetryStrategy retries = RetryStrategy.builder().retries(4).build();
    TaskTemplate template = TaskTemplate.builder().container(container).type("custom-task").interface_(interface_).retries(retries).custom(Struct.of(ImmutableMap.of("custom-prop", Struct.Value.ofStringValue("custom-value")))).build();
    Tasks.TaskTemplate templateProto = Tasks.TaskTemplate.newBuilder().setContainer(Tasks.Container.newBuilder().setImage("alpine:3.7").addCommand("echo").addArgs("hello world").addEnv(Literals.KeyValuePair.newBuilder().setKey("key").setValue("value").build()).build()).setMetadata(Tasks.TaskMetadata.newBuilder().setRuntime(Tasks.RuntimeMetadata.newBuilder().setType(Tasks.RuntimeMetadata.RuntimeType.FLYTE_SDK).setFlavor(ProtoUtil.RUNTIME_FLAVOR).setVersion(ProtoUtil.RUNTIME_VERSION).build()).setRetries(Literals.RetryStrategy.newBuilder().setRetries(4).build()).build()).setInterface(Interface.TypedInterface.newBuilder().setInputs(Interface.VariableMap.newBuilder().putVariables("x", Interface.Variable.newBuilder().setType(Types.LiteralType.newBuilder().setSimple(Types.SimpleType.STRING).build()).build()).build()).setOutputs(Interface.VariableMap.newBuilder().putVariables("y", Interface.Variable.newBuilder().setType(Types.LiteralType.newBuilder().setSimple(Types.SimpleType.INTEGER).build()).build()).build()).build()).setType("custom-task").setCustom(com.google.protobuf.Struct.newBuilder().putFields("custom-prop", Value.newBuilder().setStringValue("custom-value").build()).build()).build();
    Tasks.TaskTemplate serializedTemplate = ProtoUtil.serialize(template);
    TaskTemplate deserializedTemplate = ProtoUtil.deserialize(templateProto);
    assertThat(serializedTemplate, equalTo(templateProto));
    assertThat(deserializedTemplate, equalTo(template));
}
Also used : TaskTemplate(org.flyte.api.v1.TaskTemplate) TypedInterface(org.flyte.api.v1.TypedInterface) Container(org.flyte.api.v1.Container) Variable(org.flyte.api.v1.Variable) Tasks(flyteidl.core.Tasks) RetryStrategy(org.flyte.api.v1.RetryStrategy) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with Container

use of net.minecraft.server.v1_15_R1.Container in project flytekit-java by flyteorg.

the class ProtoUtilTest method shouldRejectResourcesWithInvalidQuantities.

@ParameterizedTest
@ValueSource(strings = { "", "1.1.", "+-1", "2+2", "Ki", "1Qi", "-1", "-5G" })
void shouldRejectResourcesWithInvalidQuantities(String quantity) {
    Container container = createContainer(Resources.builder().requests(ImmutableMap.of(Resources.ResourceName.CPU, quantity)).build());
    IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> ProtoUtil.serialize(container));
    assertEquals("Resource requests [CPU] has invalid quantity: " + quantity, exception.getMessage());
}
Also used : Container(org.flyte.api.v1.Container) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with Container

use of net.minecraft.server.v1_15_R1.Container in project flytekit-java by flyteorg.

the class ProtoUtilTest method shouldAcceptResourcesWithValidQuantities.

@ParameterizedTest
@ValueSource(strings = { "4", "2.3", "+1", "2Ki", "4m", "5e-3", "3E6" })
void shouldAcceptResourcesWithValidQuantities(String quantity) {
    Container container = createContainer(Resources.builder().limits(ImmutableMap.of(Resources.ResourceName.CPU, quantity)).build());
    Tasks.Container actual = ProtoUtil.serialize(container);
    assertThat(actual, equalTo(Tasks.Container.newBuilder().setImage("busybox").addCommand("bash").addAllArgs(asList("-c", "echo", "hello")).setResources(Tasks.Resources.newBuilder().addLimits(Tasks.Resources.ResourceEntry.newBuilder().setName(Tasks.Resources.ResourceName.CPU).setValue(quantity).build()).build()).build()));
}
Also used : Container(org.flyte.api.v1.Container) Tasks(flyteidl.core.Tasks) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with Container

use of net.minecraft.server.v1_15_R1.Container in project flytekit-java by flyteorg.

the class ProtoUtil method serialize.

@VisibleForTesting
static Tasks.Container serialize(Container container) {
    Tasks.Container.Builder builder = Tasks.Container.newBuilder().setImage(container.image()).addAllCommand(container.command()).addAllArgs(container.args());
    container.env().forEach(pair -> builder.addEnv(serialize(pair)));
    Resources resources = container.resources();
    if (resources != null) {
        builder.setResources(serialize(resources));
    }
    return builder.build();
}
Also used : Container(org.flyte.api.v1.Container) Resources(org.flyte.api.v1.Resources) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Container (org.flyte.api.v1.Container)9 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 Tasks (flyteidl.core.Tasks)4 SelfContainer (io.github.bananapuncher714.crafters.implementation.v1_11_R1.ContainerManager_v1_11_R1.SelfContainer)4 ArrayList (java.util.ArrayList)4 App (mesosphere.marathon.client.model.v2.App)4 Container (mesosphere.marathon.client.model.v2.Container)4 Docker (mesosphere.marathon.client.model.v2.Docker)4 HealthCheck (mesosphere.marathon.client.model.v2.HealthCheck)4 Container (net.minecraft.server.v1_11_R1.Container)4 Container (net.minecraft.server.v1_12_R1.Container)4 Container (net.minecraft.server.v1_16_R3.Container)4 Container (net.minecraft.server.v1_8_R3.Container)4 TaskTemplate (org.flyte.api.v1.TaskTemplate)4 Test (org.junit.jupiter.api.Test)4 Container (org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.Container)4 ContainerBuilder (org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.ContainerBuilder)4 TileEntityContainer (com.bgsoftware.wildchests.objects.containers.TileEntityContainer)3 SelfContainer (io.github.bananapuncher714.crafters.implementation.v1_10_R1.ContainerManager_v1_10_R1.SelfContainer)3