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"));
}
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));
}
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());
}
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()));
}
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();
}
Aggregations