och5351 commented on code in PR #27695: URL: https://github.com/apache/flink/pull/27695#discussion_r3050203714
########## flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/job/rescales/JobRescaleDetails.java: ########## @@ -0,0 +1,508 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.runtime.rest.messages.job.rescales; + +import org.apache.flink.runtime.clusterframework.types.ResourceProfile; +import org.apache.flink.runtime.instance.SlotSharingGroupId; +import org.apache.flink.runtime.jobgraph.JobVertexID; +import org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup; +import org.apache.flink.runtime.rest.messages.ResourceProfileInfo; +import org.apache.flink.runtime.rest.messages.ResponseBody; +import org.apache.flink.runtime.rest.messages.json.JobVertexIDDeserializer; +import org.apache.flink.runtime.rest.messages.json.JobVertexIDKeyDeserializer; +import org.apache.flink.runtime.rest.messages.json.JobVertexIDKeySerializer; +import org.apache.flink.runtime.rest.messages.json.JobVertexIDSerializer; +import org.apache.flink.runtime.rest.messages.json.SlotSharingGroupIDDeserializer; +import org.apache.flink.runtime.rest.messages.json.SlotSharingGroupIDKeyDeserializer; +import org.apache.flink.runtime.rest.messages.json.SlotSharingGroupIDKeySerializer; +import org.apache.flink.runtime.rest.messages.json.SlotSharingGroupIDSerializer; +import org.apache.flink.runtime.scheduler.VertexParallelismInformation; +import org.apache.flink.runtime.scheduler.adaptive.timeline.Rescale; +import org.apache.flink.runtime.scheduler.adaptive.timeline.SlotSharingGroupRescale; +import org.apache.flink.runtime.scheduler.adaptive.timeline.TerminalState; +import org.apache.flink.runtime.scheduler.adaptive.timeline.TerminatedReason; +import org.apache.flink.runtime.scheduler.adaptive.timeline.TriggerCause; +import org.apache.flink.util.Preconditions; + +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator; +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonIgnore; +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.annotation.JsonSerialize; + +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.annotation.Nullable; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** Job rescales details class. */ +@Schema(name = "JobRescaleDetails") +public class JobRescaleDetails implements ResponseBody, Serializable { + private static final long serialVersionUID = 1L; + + public static final String FIELD_NAME_RESCALE_UUID = "rescaleUuid"; + public static final String FIELD_NAME_RESOURCE_REQUIREMENTS_UUID = "resourceRequirementsUuid"; + public static final String FIELD_NAME_RESCALE_ATTEMPT_ID = "rescaleAttemptId"; + public static final String FIELD_NAME_VERTICES = "vertices"; + public static final String FIELD_NAME_SLOTS = "slots"; + public static final String FIELD_NAME_SCHEDULER_STATES = "schedulerStates"; + public static final String FIELD_NAME_START_TIMESTAMP = "startTimestampInMillis"; + public static final String FIELD_NAME_END_TIMESTAMP = "endTimestampInMillis"; + public static final String FIELD_NAME_TERMINAL_STATE = "terminalState"; + public static final String FIELD_NAME_TRIGGER_CAUSE = "triggerCause"; + public static final String FIELD_NAME_TERMINATED_REASON = "terminatedReason"; + + @JsonProperty(FIELD_NAME_RESCALE_UUID) + private final String rescaleUuid; + + @JsonProperty(FIELD_NAME_RESOURCE_REQUIREMENTS_UUID) + private final String resourceRequirementsUuid; + + @JsonProperty(FIELD_NAME_RESCALE_ATTEMPT_ID) + private final long rescaleAttemptId; + + @JsonProperty(FIELD_NAME_VERTICES) + @JsonSerialize(keyUsing = JobVertexIDKeySerializer.class) + @JsonDeserialize(keyUsing = JobVertexIDKeyDeserializer.class) + private final Map<JobVertexID, VertexParallelismRescaleInfo> vertices; + + @JsonProperty(FIELD_NAME_SLOTS) + @JsonSerialize(keyUsing = SlotSharingGroupIDKeySerializer.class) + @JsonDeserialize(keyUsing = SlotSharingGroupIDKeyDeserializer.class) + private final Map<SlotSharingGroupId, SlotSharingGroupRescaleInfo> slots; + + @JsonProperty(FIELD_NAME_SCHEDULER_STATES) + private final List<SchedulerStateSpan> schedulerStates; + + @JsonProperty(FIELD_NAME_START_TIMESTAMP) + private final Long startTimestamp; + + @Nullable + @JsonProperty(FIELD_NAME_END_TIMESTAMP) + private final Long endTimestamp; + + @JsonProperty(FIELD_NAME_TERMINAL_STATE) + private final TerminalState terminalState; + + @JsonProperty(FIELD_NAME_TRIGGER_CAUSE) + private final TriggerCause triggerCause; + + @JsonProperty(FIELD_NAME_TERMINATED_REASON) + private final TerminatedReason terminatedReason; + + @JsonCreator + public JobRescaleDetails( + @JsonProperty(FIELD_NAME_RESCALE_UUID) String rescaleUuid, + @JsonProperty(FIELD_NAME_RESOURCE_REQUIREMENTS_UUID) String resourceRequirementsUuid, + @JsonProperty(FIELD_NAME_RESCALE_ATTEMPT_ID) long rescaleAttemptId, + @JsonSerialize(keyUsing = JobVertexIDKeySerializer.class) + @JsonDeserialize(keyUsing = JobVertexIDKeyDeserializer.class) + @JsonProperty(FIELD_NAME_VERTICES) + Map<JobVertexID, VertexParallelismRescaleInfo> vertices, + @JsonSerialize(keyUsing = SlotSharingGroupIDKeySerializer.class) + @JsonDeserialize(keyUsing = SlotSharingGroupIDKeyDeserializer.class) + @JsonProperty(FIELD_NAME_SLOTS) + Map<SlotSharingGroupId, SlotSharingGroupRescaleInfo> slots, + @JsonProperty(FIELD_NAME_SCHEDULER_STATES) List<SchedulerStateSpan> schedulerStates, + @JsonProperty(FIELD_NAME_START_TIMESTAMP) Long startTimestamp, + @Nullable @JsonProperty(FIELD_NAME_END_TIMESTAMP) Long endTimestamp, + @JsonProperty(FIELD_NAME_TERMINAL_STATE) TerminalState terminalState, + @JsonProperty(FIELD_NAME_TRIGGER_CAUSE) TriggerCause triggerCause, + @JsonProperty(FIELD_NAME_TERMINATED_REASON) TerminatedReason terminatedReason) { + this.rescaleUuid = rescaleUuid; + this.resourceRequirementsUuid = resourceRequirementsUuid; + this.rescaleAttemptId = rescaleAttemptId; + this.vertices = vertices; + this.slots = slots; + this.schedulerStates = schedulerStates; + this.startTimestamp = startTimestamp; + this.endTimestamp = endTimestamp; + this.terminalState = terminalState; + this.triggerCause = triggerCause; + this.terminatedReason = terminatedReason; + } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) { + return false; + } + + JobRescaleDetails that = (JobRescaleDetails) o; + return rescaleAttemptId == that.rescaleAttemptId + && Objects.equals(rescaleUuid, that.rescaleUuid) + && Objects.equals(resourceRequirementsUuid, that.resourceRequirementsUuid) + && Objects.equals(vertices, that.vertices) + && Objects.equals(slots, that.slots) + && Objects.equals(schedulerStates, that.schedulerStates) + && Objects.equals(startTimestamp, that.startTimestamp) + && Objects.equals(endTimestamp, that.endTimestamp) + && terminalState == that.terminalState + && triggerCause == that.triggerCause + && terminatedReason == that.terminatedReason; + } + + @Override + public int hashCode() { + return Objects.hash( + rescaleUuid, + resourceRequirementsUuid, + rescaleAttemptId, + vertices, + slots, + schedulerStates, + startTimestamp, + endTimestamp, + terminalState, + triggerCause, + terminatedReason); + } + + public static JobRescaleDetails fromRescale(Rescale rescale, boolean includeSchedulerStates) { + return new JobRescaleDetails( + rescale.getRescaleIdInfo().getRescaleUuid().toString(), + rescale.getRescaleIdInfo().getResourceRequirementsId().toString(), + rescale.getRescaleIdInfo().getRescaleAttemptId(), + rescale.getVertices(), + convertMapValues( + rescale.getSlots(), + SlotSharingGroupRescaleInfo::fromSlotSharingGroupRescale), + includeSchedulerStates ? rescale.getSchedulerStates() : null, + rescale.getStartTimestamp(), + rescale.getEndTimestamp(), + rescale.getTerminalState(), + rescale.getTriggerCause(), + rescale.getTerminatedReason()); + } + + private static <K, NV, OV> Map<K, NV> convertMapValues( + Map<K, OV> rawMap, Function<OV, NV> valueMapper) { + return rawMap == null + ? new HashMap<>() + : rawMap.entrySet().stream() + .collect( + Collectors.toMap( + Map.Entry::getKey, + kovEntry -> valueMapper.apply(kovEntry.getValue()))); + } + + /** The rescale information of a {@link org.apache.flink.runtime.jobgraph.JobVertex}. */ + public static final class VertexParallelismRescaleInfo implements Serializable { + private static final long serialVersionUID = 1L; + + public static final String FIELD_NAME_JOB_VERTEX_ID = "jobVertexId"; + public static final String FIELD_NAME_VERTEX_NAME = "jobVertexName"; + public static final String FIELD_NAME_SLOT_SHARING_GROUP_ID = "slotSharingGroupId"; + public static final String FIELD_NAME_SLOT_SHARING_GROUP_NAME = "slotSharingGroupName"; + public static final String FIELD_NAME_DESIRED_PARALLELISM = "desiredParallelism"; + public static final String FIELD_NAME_SUFFICIENT_PARALLELISM = "sufficientParallelism"; + public static final String FIELD_NAME_PRE_RESCALE_PARALLELISM = "preRescaleParallelism"; + public static final String FIELD_NAME_POST_RESCALE_PARALLELISM = "postRescaleParallelism"; Review Comment: Thank you for letting me know. I understand now ~ LGTM + 1 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
