public static ResourceSpec extractResourceSpec(SlotSharingGroup slotSharingGroup) {
        if (!slotSharingGroup.getCpuCores().isPresent()) {
            return ResourceSpec.UNKNOWN;
        }

        Preconditions.checkState(slotSharingGroup.getCpuCores().isPresent());
        Preconditions.checkState(slotSharingGroup.getTaskHeapMemory().isPresent());
        Preconditions.checkState(slotSharingGroup.getTaskOffHeapMemory().isPresent());
        Preconditions.checkState(slotSharingGroup.getManagedMemory().isPresent());

        return ResourceSpec.newBuilder(
                        slotSharingGroup.getCpuCores().get(),
                        slotSharingGroup.getTaskHeapMemory().get())
                .setTaskOffHeapMemory(slotSharingGroup.getTaskOffHeapMemory().get())
                .setManagedMemory(slotSharingGroup.getManagedMemory().get())
                .setExtendedResources(
                        slotSharingGroup.getExternalResources().entrySet().stream()
                                .map(
                                        entry ->
                                                new ExternalResource(
                                                        entry.getKey(), entry.getValue()))
                                .collect(Collectors.toList()))
                .build();
    }
@Test
    void testCovertToResourceSpec() {
        final ExternalResource gpu = new ExternalResource("gpu", 1);
        final ResourceSpec resourceSpec =
                ResourceSpec.newBuilder(1.0, 100)
                        .setManagedMemoryMB(200)
                        .setTaskOffHeapMemoryMB(300)
                        .setExtendedResource(gpu)
                        .build();
        final SlotSharingGroup slotSharingGroup1 =
                SlotSharingGroup.newBuilder("ssg")
                        .setCpuCores(resourceSpec.getCpuCores().getValue().doubleValue())
                        .setTaskHeapMemory(resourceSpec.getTaskHeapMemory())
                        .setTaskOffHeapMemory(resourceSpec.getTaskOffHeapMemory())
                        .setManagedMemory(resourceSpec.getManagedMemory())
                        .setExternalResource(gpu.getName(), gpu.getValue().doubleValue())
                        .build();
        final SlotSharingGroup slotSharingGroup2 = SlotSharingGroup.newBuilder("ssg").build();

        assertThat(SlotSharingGroupUtils.extractResourceSpec(slotSharingGroup1))
                .isEqualTo(resourceSpec);
        assertThat(SlotSharingGroupUtils.extractResourceSpec(slotSharingGroup2))
                .isEqualTo(ResourceSpec.UNKNOWN);
    }