GrpcJobManagementModelConverters { public static Task toCoreTask(com.netflix.titus.grpc.protogen.Task grpcTask) { Map<String, String> taskContext = grpcTask.getTaskContextMap(); String originalId = Preconditions.checkNotNull( taskContext.get(TASK_ATTRIBUTES_TASK_ORIGINAL_ID), TASK_ATTRIBUTES_TASK_ORIGINAL_ID + " missing in Task entity" ); String resubmitOf = taskContext.get(TASK_ATTRIBUTES_TASK_RESUBMIT_OF); int taskResubmitNumber = Integer.parseInt(taskContext.get(TASK_ATTRIBUTES_RESUBMIT_NUMBER)); int systemResubmitNumber = Integer.parseInt(grpcTask.getTaskContextMap().getOrDefault(TASK_ATTRIBUTES_SYSTEM_RESUBMIT_NUMBER, "0")); int evictionResubmitNumber = Integer.parseInt(grpcTask.getTaskContextMap().getOrDefault(TASK_ATTRIBUTES_EVICTION_RESUBMIT_NUMBER, "0")); String taskIndexStr = taskContext.get(TASK_ATTRIBUTES_TASK_INDEX); boolean isBatchTask = taskIndexStr != null; Task.TaskBuilder<?, ?> builder = isBatchTask ? JobModel.newBatchJobTask() : JobModel.newServiceJobTask(); builder.withId(grpcTask.getId()) .withJobId(grpcTask.getJobId()) .withStatus(toCoreTaskStatus(grpcTask.getStatus())) .withStatusHistory(grpcTask.getStatusHistoryList().stream().map(GrpcJobManagementModelConverters::toCoreTaskStatus).collect(Collectors.toList())) .withResubmitNumber(taskResubmitNumber) .withOriginalId(originalId) .withResubmitOf(resubmitOf) .withSystemResubmitNumber(systemResubmitNumber) .withEvictionResubmitNumber(evictionResubmitNumber) .withTaskContext(taskContext) .withAttributes(buildAttributesMapForCoreTask(grpcTask)); if (isBatchTask) { ((BatchJobTask.Builder) builder).withIndex(Integer.parseInt(taskIndexStr)); } else { ((ServiceJobTask.Builder) builder).withMigrationDetails(toCoreMigrationDetails(grpcTask.getMigrationDetails())); } return builder.build(); } private  GrpcJobManagementModelConverters(); static Job toCoreJob(com.netflix.titus.grpc.protogen.Job grpcJob); static JobStatus toCoreJobStatus(com.netflix.titus.grpc.protogen.JobStatus grpcJobStatus); static JobState toCoreJobState(com.netflix.titus.grpc.protogen.JobStatus.JobState grpcState); static JobDescriptor toCoreJobDescriptor(com.netflix.titus.grpc.protogen.JobDescriptor grpcJobDescriptor); static Owner toCoreOwner(com.netflix.titus.grpc.protogen.Owner grpcOwner); static JobGroupInfo toCoreJobGroupInfo(com.netflix.titus.grpc.protogen.JobGroupInfo grpcJobGroupInfo); static Image toCoreImage(com.netflix.titus.grpc.protogen.Image grpcImage); static EfsMount toCoreEfsMount(com.netflix.titus.grpc.protogen.ContainerResources.EfsMount grpcEfsMount); static SignedIpAddressAllocation toCoreSignedIpAddressAllocation(SignedAddressAllocation grpcSignedIpAddressAllocation); static ContainerResources toCoreScalarResources(com.netflix.titus.grpc.protogen.ContainerResources grpcResources); static com.netflix.titus.api.jobmanager.model.job.SecurityProfile toCoreSecurityProfile(SecurityProfile grpcSecurityProfile); static Map<String, String> toCoreConstraints(Constraints grpcConstraints); static ServiceJobProcesses toCoreServiceJobProcesses(ServiceJobSpec.ServiceJobProcesses serviceJobProcesses); static ServiceJobSpec.ServiceJobProcesses toGrpcServiceJobProcesses(ServiceJobProcesses serviceJobProcesses); static Container toCoreContainer(com.netflix.titus.grpc.protogen.Container grpcContainer); static DisruptionBudget toCoreDisruptionBudget(com.netflix.titus.grpc.protogen.JobDisruptionBudget grpcDisruptionBudget); static DisruptionBudgetPolicy toCoreDisruptionBudgetPolicy(JobDisruptionBudget grpcDisruptionBudget); static DisruptionBudgetRate toCoreDisruptionBudgetRate(JobDisruptionBudget grpcDisruptionBudget); static List<TimeWindow> toCoreTimeWindows(List<com.netflix.titus.grpc.protogen.TimeWindow> grpcTimeWindows); static TimeWindow toCoreTimeWindow(com.netflix.titus.grpc.protogen.TimeWindow grpcTimeWindow); static List<Day> toCoreDays(List<com.netflix.titus.grpc.protogen.Day> grpcDays); static Day toCoreDay(com.netflix.titus.grpc.protogen.Day grpcDay); static List<HourlyTimeWindow> toCoreHourlyTimeWindows(List<com.netflix.titus.grpc.protogen.TimeWindow.HourlyTimeWindow> grpcHourlyTimeWindows); static HourlyTimeWindow toCoreHourlyTimeWindow(com.netflix.titus.grpc.protogen.TimeWindow.HourlyTimeWindow grpcHourlyTimeWindow); static List<ContainerHealthProvider> toCoreContainerHealthProviders(List<com.netflix.titus.grpc.protogen.ContainerHealthProvider> grpcContainerHealthProviders); static ContainerHealthProvider toCoreHourlyTimeWindow(com.netflix.titus.grpc.protogen.ContainerHealthProvider grpcContainerHealthProvider); static JobDescriptor.JobDescriptorExt toCoreJobExtensions(com.netflix.titus.grpc.protogen.JobDescriptor grpcJobDescriptor); static com.netflix.titus.api.jobmanager.model.job.Capacity toCoreCapacity(Capacity capacity); static com.netflix.titus.api.jobmanager.model.job.CapacityAttributes toCoreCapacityAttributes(JobCapacityWithOptionalAttributes capacity); static com.netflix.titus.api.jobmanager.model.job.CapacityAttributes toCoreCapacityAttributes(Capacity capacity); static Task toCoreTask(com.netflix.titus.grpc.protogen.Task grpcTask); static Task toCoreTask(Job<?> job, com.netflix.titus.grpc.protogen.Task grpcTask); static TaskStatus toCoreTaskStatus(com.netflix.titus.grpc.protogen.TaskStatus grpcStatus); static TaskState toCoreTaskState(com.netflix.titus.grpc.protogen.TaskStatus.TaskState grpcState); static com.netflix.titus.grpc.protogen.Owner toGrpcOwner(Owner owner); static com.netflix.titus.grpc.protogen.JobGroupInfo toGrpcJobGroupInfo(JobGroupInfo jobGroupInfo); static com.netflix.titus.grpc.protogen.ContainerResources.EfsMount toGrpcEfsMount(EfsMount coreEfsMount); static AddressLocation toGrpcAddressLocation(IpAddressLocation coreIpAddressLocation); static AddressAllocation toGrpcAddressAllocation(IpAddressAllocation coreIpAddressAllocation); static SignedAddressAllocation toGrpcSignedAddressAllocation(SignedIpAddressAllocation coreSignedIpAddressAllocation); static com.netflix.titus.grpc.protogen.ContainerResources toGrpcResources(ContainerResources containerResources); static SecurityProfile toGrpcSecurityProfile(com.netflix.titus.api.jobmanager.model.job.SecurityProfile coreSecurityProfile); static Constraints toGrpcConstraints(Map<String, String> constraints); static com.netflix.titus.grpc.protogen.Container toGrpcContainer(Container container); static BatchJobSpec toGrpcBatchSpec(BatchJobExt batchJobExt); static ServiceJobSpec toGrpcServiceSpec(ServiceJobExt serviceJobExt); static Capacity toGrpcCapacity(com.netflix.titus.api.jobmanager.model.job.Capacity capacity); static com.netflix.titus.grpc.protogen.JobDisruptionBudget toGrpcDisruptionBudget(DisruptionBudget coreDisruptionBudget); static List<com.netflix.titus.grpc.protogen.TimeWindow> toGrpcTimeWindows(List<TimeWindow> grpcTimeWindows); static com.netflix.titus.grpc.protogen.TimeWindow toGrpcTimeWindow(TimeWindow coreTimeWindow); static List<com.netflix.titus.grpc.protogen.Day> toGrpcDays(List<Day> coreDays); static com.netflix.titus.grpc.protogen.Day toGrpcDay(Day coreDay); static List<com.netflix.titus.grpc.protogen.TimeWindow.HourlyTimeWindow> toGrpcHourlyTimeWindows(List<HourlyTimeWindow> coreHourlyTimeWindows); static com.netflix.titus.grpc.protogen.TimeWindow.HourlyTimeWindow toGrpcHourlyTimeWindow(HourlyTimeWindow coreHourlyTimeWindow); static List<com.netflix.titus.grpc.protogen.ContainerHealthProvider> toGrpcContainerHealthProviders(List<ContainerHealthProvider> grpcContainerHealthProviders); static com.netflix.titus.grpc.protogen.ContainerHealthProvider toGrpcHourlyTimeWindow(ContainerHealthProvider coreContainerHealthProvider); static com.netflix.titus.grpc.protogen.JobDescriptor toGrpcJobDescriptor(JobDescriptor<?> jobDescriptor); static com.netflix.titus.grpc.protogen.JobStatus toGrpcJobStatus(JobStatus status); static List<com.netflix.titus.grpc.protogen.JobStatus> toGrpcJobStatusHistory(List<JobStatus> statusHistory); static com.netflix.titus.grpc.protogen.TaskStatus toGrpcTaskStatus(TaskStatus status); static List<com.netflix.titus.grpc.protogen.TaskStatus> toGrpcTaskStatusHistory(List<TaskStatus> statusHistory); static com.netflix.titus.grpc.protogen.Job toGrpcJob(Job<?> coreJob); static com.netflix.titus.grpc.protogen.Task toGrpcTask(Task coreTask, LogStorageInfo<Task> logStorageInfo); static LogLocation toGrpcLogLocation(TASK task, LogStorageInfo<TASK> logStorageInfo); static com.netflix.titus.grpc.protogen.MigrationDetails toGrpcMigrationDetails(MigrationDetails migrationDetails); static MigrationDetails toCoreMigrationDetails(com.netflix.titus.grpc.protogen.MigrationDetails grpcMigrationDetails); static JobChangeNotification toGrpcJobChangeNotification(JobManagerEvent<?> event, LogStorageInfo<Task> logStorageInfo);  }
@Test public void coreTaskLogAttributes() { String taskId = "tid-1"; String uiLocation = "http: String s3Bucket = "bucket-1"; String s3Key = "key-1"; String s3AccountId = "acc-1"; String s3AccountName = "acc-name-1"; String s3Region = "us-east-1"; Map<String, String> taskContext = new HashMap<>(); taskContext.put(TASK_ATTRIBUTES_TASK_ORIGINAL_ID, taskId); taskContext.put(TASK_ATTRIBUTES_RESUBMIT_NUMBER, "1"); Task grpcTask = Task.newBuilder() .setId(taskId) .putAllTaskContext(taskContext) .setLogLocation(LogLocation.newBuilder() .setUi(LogLocation.UI.newBuilder().setUrl(uiLocation)) .setS3(LogLocation.S3.newBuilder() .setRegion(s3Region) .setBucket(s3Bucket) .setKey(s3Key) .setAccountId(s3AccountId) .setAccountName(s3AccountName)) .build()) .build(); com.netflix.titus.api.jobmanager.model.job.Task coreTask = GrpcJobManagementModelConverters.toCoreTask(grpcTask); assertThat(coreTask).isNotNull(); assertThat(coreTask.getAttributes()).hasSizeGreaterThan(0); assertThat(coreTask.getAttributes().containsKey(TASK_ATTRIBUTE_LOG_S3_KEY)).isTrue(); assertThat(coreTask.getAttributes().get(TASK_ATTRIBUTE_LOG_S3_KEY)).isEqualTo(s3Key); assertThat(coreTask.getAttributes().containsKey(TASK_ATTRIBUTE_LOG_S3_BUCKET_NAME)).isTrue(); assertThat(coreTask.getAttributes().get(TASK_ATTRIBUTE_LOG_S3_BUCKET_NAME)).isEqualTo(s3Bucket); assertThat(coreTask.getAttributes().containsKey(TASK_ATTRIBUTE_LOG_S3_ACCOUNT_ID)).isTrue(); assertThat(coreTask.getAttributes().get(TASK_ATTRIBUTE_LOG_S3_ACCOUNT_ID)).isEqualTo(s3AccountId); assertThat(coreTask.getAttributes().containsKey(TASK_ATTRIBUTE_LOG_S3_ACCOUNT_NAME)).isTrue(); assertThat(coreTask.getAttributes().get(TASK_ATTRIBUTE_LOG_S3_ACCOUNT_NAME)).isEqualTo(s3AccountName); assertThat(coreTask.getAttributes().containsKey(TASK_ATTRIBUTE_LOG_S3_REGION)).isTrue(); assertThat(coreTask.getAttributes().get(TASK_ATTRIBUTE_LOG_S3_REGION)).isEqualTo(s3Region); assertThat(coreTask.getAttributes().containsKey(TASK_ATTRIBUTE_LOG_UI_LOCATION)).isTrue(); assertThat(coreTask.getAttributes().get(TASK_ATTRIBUTE_LOG_UI_LOCATION)).isEqualTo(uiLocation); }