-
Notifications
You must be signed in to change notification settings - Fork 440
TEZ-4008: Pluggable AM FrameworkServices and AmExtensions (2/3) #426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+474
−8
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
tez-api/src/main/java/org/apache/tez/client/registry/AMRecord.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| /** | ||
| * 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.tez.client.registry; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| import org.apache.hadoop.classification.InterfaceAudience; | ||
| import org.apache.hadoop.registry.client.types.ServiceRecord; | ||
| import org.apache.hadoop.yarn.api.records.ApplicationId; | ||
|
|
||
|
|
||
| /** | ||
| * Record representing an Application Master (AM) instance within Tez. | ||
| * <p> | ||
| * This class can be serialized to and from a {@link ServiceRecord}, enabling | ||
| * storage and retrieval of AM metadata in external systems. Some constructors | ||
| * and methods are not necessarily used within the Tez codebase itself, but | ||
| * are part of the Tez API and intended for Tez clients that manage or interact | ||
| * with Tez unmanaged sessions. | ||
| */ | ||
| @InterfaceAudience.Public | ||
| public class AMRecord { | ||
| private static final String APP_ID_RECORD_KEY = "appId"; | ||
| private static final String HOST_RECORD_KEY = "host"; | ||
| private static final String PORT_RECORD_KEY = "port"; | ||
| private static final String OPAQUE_ID_KEY = "id"; | ||
|
|
||
| private final ApplicationId appId; | ||
| private final String host; | ||
| private final int port; | ||
| private final String id; | ||
|
|
||
| /** | ||
| * Creates a new {@code AMRecord} with the given application ID, host, port, and identifier. | ||
| * <p> | ||
| * If the provided identifier is {@code null}, it will be converted to an empty string. | ||
| * <p> | ||
| * Although this constructor may not be used directly within Tez internals, | ||
| * it is part of the public API for Tez clients that handle unmanaged sessions. | ||
| * | ||
| * @param appId the {@link ApplicationId} of the Tez application | ||
| * @param host the hostname where the Application Master is running | ||
| * @param port the port number on which the Application Master is listening | ||
| * @param id an opaque identifier for the record; if {@code null}, defaults to an empty string | ||
| */ | ||
| public AMRecord(ApplicationId appId, String host, int port, String id) { | ||
| this.appId = appId; | ||
| this.host = host; | ||
| this.port = port; | ||
| //If id is not provided, convert to empty string | ||
| this.id = (id == null) ? "" : id; | ||
| } | ||
|
|
||
| /** | ||
| * Copy constructor. | ||
| * <p> | ||
| * Creates a new {@code AMRecord} by copying the fields of another instance. | ||
| * <p> | ||
| * This constructor is mainly useful for client-side logic and session handling, | ||
| * and may not be invoked directly within the Tez codebase. | ||
| * | ||
| * @param other the {@code AMRecord} instance to copy | ||
| */ | ||
| public AMRecord(AMRecord other) { | ||
| this.appId = other.getApplicationId(); | ||
| this.host = other.getHost(); | ||
| this.port = other.getPort(); | ||
| this.id = other.getId(); | ||
| } | ||
|
|
||
| /** | ||
| * Constructs a new {@code AMRecord} from a {@link ServiceRecord}. | ||
| * <p> | ||
| * This allows conversion from serialized metadata back into an in-memory {@code AMRecord}. | ||
| * <p> | ||
| * While not always used in Tez internals, it exists in the Tez API so | ||
| * clients can reconstruct AM information when working with unmanaged sessions. | ||
| * | ||
| * @param serviceRecord the {@link ServiceRecord} containing AM metadata | ||
| * @throws IllegalArgumentException if required keys are missing or invalid | ||
| */ | ||
| public AMRecord(ServiceRecord serviceRecord) { | ||
| this.appId = ApplicationId.fromString(serviceRecord.get(APP_ID_RECORD_KEY)); | ||
| this.host = serviceRecord.get(HOST_RECORD_KEY); | ||
| this.port = Integer.parseInt(serviceRecord.get(PORT_RECORD_KEY)); | ||
| this.id = serviceRecord.get(OPAQUE_ID_KEY); | ||
| } | ||
|
|
||
| public ApplicationId getApplicationId() { | ||
| return appId; | ||
| } | ||
|
|
||
| public String getHost() { | ||
| return host; | ||
| } | ||
|
|
||
| public int getPort() { | ||
| return port; | ||
| } | ||
|
|
||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object other) { | ||
| if (this == other) { | ||
| return true; | ||
| } | ||
| if (other instanceof AMRecord otherRecord) { | ||
| return appId.equals(otherRecord.appId) | ||
| && host.equals(otherRecord.host) | ||
| && port == otherRecord.port | ||
| && id.equals(otherRecord.id); | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Converts this {@code AMRecord} into a {@link ServiceRecord}. | ||
| * <p> | ||
| * The returned {@link ServiceRecord} contains the Application Master metadata | ||
| * (application ID, host, port, and opaque identifier) so that it can be stored | ||
| * in an external registry or retrieved later. | ||
| * <p> | ||
| * While this method may not be directly used within Tez internals, | ||
| * it is part of the Tez public API and is intended for Tez clients | ||
| * that interact with unmanaged sessions or otherwise need to | ||
| * persist/reconstruct Application Master information. | ||
| * | ||
| * @return a {@link ServiceRecord} populated with the values of this {@code AMRecord} | ||
| */ | ||
| public ServiceRecord toServiceRecord() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this isn't used either?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above, adding javadoc |
||
| ServiceRecord serviceRecord = new ServiceRecord(); | ||
| serviceRecord.set(APP_ID_RECORD_KEY, appId); | ||
| serviceRecord.set(HOST_RECORD_KEY, host); | ||
| serviceRecord.set(PORT_RECORD_KEY, port); | ||
| serviceRecord.set(OPAQUE_ID_KEY, id); | ||
| return serviceRecord; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(appId, host, port, id); | ||
| } | ||
| } | ||
24 changes: 24 additions & 0 deletions
24
tez-api/src/main/java/org/apache/tez/client/registry/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /** | ||
| * 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. | ||
| */ | ||
|
|
||
| @Public | ||
| @Evolving | ||
| package org.apache.tez.client.registry; | ||
|
|
||
| import org.apache.hadoop.classification.InterfaceAudience.Public; | ||
| import org.apache.hadoop.classification.InterfaceStability.Evolving; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
tez-dag/src/main/java/org/apache/tez/dag/api/client/registry/AMRegistry.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /** | ||
| * 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.tez.dag.api.client.registry; | ||
|
|
||
| import org.apache.hadoop.service.AbstractService; | ||
| import org.apache.tez.client.registry.AMRecord; | ||
|
|
||
| /** | ||
| * Base class for AMRegistry implementations. | ||
| * The specific implementation class is configured by `tez.am.registry.class`. | ||
| * | ||
| * Implementations should handle the relevant service lifecycle operations: | ||
| * `init`, `serviceStart`, `serviceStop`, etc. | ||
| * - `init` and `serviceStart` are invoked during `DAGAppMaster.serviceInit`. | ||
| * - `serviceStop` is invoked on `DAGAppMaster` shutdown. | ||
| */ | ||
| public abstract class AMRegistry extends AbstractService { | ||
|
|
||
| /* Implementations should provide a public no-arg constructor. */ | ||
| protected AMRegistry(String name) { | ||
| super(name); | ||
| } | ||
|
|
||
| /* Under typical usage, add() will be called once automatically with an AMRecord | ||
| for the DAGClientServer that services an AM. */ | ||
| public abstract void add(AMRecord server) throws Exception; | ||
|
|
||
| /* Under typical usage, implementations should remove any stale AMRecords upon serviceStop. */ | ||
| public abstract void remove(AMRecord server) throws Exception; | ||
|
|
||
| } |
24 changes: 24 additions & 0 deletions
24
tez-dag/src/main/java/org/apache/tez/dag/api/client/registry/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /** | ||
| * 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. | ||
| */ | ||
|
|
||
| @Public | ||
| @Evolving | ||
| package org.apache.tez.dag.api.client.registry; | ||
|
|
||
| import org.apache.hadoop.classification.InterfaceAudience.Public; | ||
| import org.apache.hadoop.classification.InterfaceStability.Evolving; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we bail out early if other == this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that branch is part of traditional equals method, let me add