Skip to content

Commit

Permalink
YARN-7892. Revisit NodeAttribute class structure. Contributed by Naga…
Browse files Browse the repository at this point in the history
…narasimha G R.
  • Loading branch information
bibinchundatt authored and sunilgovind committed Sep 12, 2018
1 parent 5dc7d6e commit 8cf6a9a
Show file tree
Hide file tree
Showing 36 changed files with 1,119 additions and 357 deletions.
Expand Up @@ -59,10 +59,13 @@
import org.apache.hadoop.yarn.api.records.ContainerId;
import org.apache.hadoop.yarn.api.records.ContainerReport;
import org.apache.hadoop.yarn.api.records.NodeAttribute;
import org.apache.hadoop.yarn.api.records.NodeAttributeKey;
import org.apache.hadoop.yarn.api.records.NodeAttributeInfo;
import org.apache.hadoop.yarn.api.records.NodeId;
import org.apache.hadoop.yarn.api.records.NodeLabel;
import org.apache.hadoop.yarn.api.records.NodeReport;
import org.apache.hadoop.yarn.api.records.NodeState;
import org.apache.hadoop.yarn.api.records.NodeToAttributeValue;
import org.apache.hadoop.yarn.api.records.Priority;
import org.apache.hadoop.yarn.api.records.QueueUserACLInfo;
import org.apache.hadoop.yarn.api.records.Resource;
Expand Down Expand Up @@ -541,14 +544,14 @@ public List<ResourceTypeInfo> getResourceTypeInfo()
}

@Override
public Set<NodeAttribute> getClusterAttributes()
public Set<NodeAttributeInfo> getClusterAttributes()
throws YarnException, IOException {
return client.getClusterAttributes();
}

@Override
public Map<NodeAttribute, Set<String>> getAttributesToNodes(
Set<NodeAttribute> attributes) throws YarnException, IOException {
public Map<NodeAttributeKey, List<NodeToAttributeValue>> getAttributesToNodes(
Set<NodeAttributeKey> attributes) throws YarnException, IOException {
return client.getAttributesToNodes(attributes);
}

Expand Down
Expand Up @@ -17,22 +17,24 @@
*/
package org.apache.hadoop.yarn.api.protocolrecords;

import static org.apache.hadoop.classification.InterfaceAudience.*;
import static org.apache.hadoop.classification.InterfaceStability.*;
import java.util.Set;

import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Evolving;
import org.apache.hadoop.classification.InterfaceStability.Unstable;
import org.apache.hadoop.yarn.api.ApplicationClientProtocol;
import org.apache.hadoop.yarn.api.records.NodeAttribute;
import org.apache.hadoop.yarn.api.records.NodeAttributeKey;
import org.apache.hadoop.yarn.util.Records;

import java.util.Set;

/**
* <p>
* The request from clients to get attribtues to nodes mapping
* in the cluster from the <code>ResourceManager</code>.
* The request from clients to get node to attribute value mapping for all or
* given set of Node AttributeKey's in the cluster from the
* <code>ResourceManager</code>.
* </p>
*
* @see ApplicationClientProtocol#getAttributesToNodes
* (GetAttributesToNodesRequest)
* (GetAttributesToNodesRequest)
*/
@Public
@Evolving
Expand All @@ -43,28 +45,30 @@ public static GetAttributesToNodesRequest newInstance() {
}

public static GetAttributesToNodesRequest newInstance(
Set<NodeAttribute> attributes) {
Set<NodeAttributeKey> attributes) {
GetAttributesToNodesRequest request =
Records.newRecord(GetAttributesToNodesRequest.class);
request.setNodeAttributes(attributes);
return request;
}

/**
* Set node attributes for which the mapping is required.
* Set node attributeKeys for which the mapping of hostname to attribute value
* is required.
*
* @param attributes Set<NodeAttribute> provided.
* @param attributes Set<NodeAttributeKey> provided.
*/
@Public
@Unstable
public abstract void setNodeAttributes(Set<NodeAttribute> attributes);
public abstract void setNodeAttributes(Set<NodeAttributeKey> attributes);

/**
* Get node attributes for which mapping mapping is required.
* Get node attributeKeys for which mapping of hostname to attribute value is
* required.
*
* @return Set<NodeAttribute>
* @return Set<NodeAttributeKey>
*/
@Public
@Unstable
public abstract Set<NodeAttribute> getNodeAttributes();
public abstract Set<NodeAttributeKey> getNodeAttributes();
}
Expand Up @@ -17,29 +17,30 @@
*/
package org.apache.hadoop.yarn.api.protocolrecords;

import static org.apache.hadoop.classification.InterfaceAudience.Public;
import static org.apache.hadoop.classification.InterfaceStability.Evolving;
import java.util.List;
import java.util.Map;

import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Evolving;
import org.apache.hadoop.yarn.api.ApplicationClientProtocol;
import org.apache.hadoop.yarn.api.records.NodeAttribute;
import org.apache.hadoop.yarn.api.records.NodeAttributeKey;
import org.apache.hadoop.yarn.api.records.NodeToAttributeValue;
import org.apache.hadoop.yarn.util.Records;

import java.util.Map;
import java.util.Set;

/**
* <p>
* The response sent by the <code>ResourceManager</code> to a client requesting
* attributes to hostname mapping.
* node to attribute value mapping for all or given set of Node AttributeKey's.
* </p>
*
* @see ApplicationClientProtocol#getAttributesToNodes
* (GetAttributesToNodesRequest)
* (GetAttributesToNodesRequest)
*/
@Public
@Evolving
public abstract class GetAttributesToNodesResponse {
public static GetAttributesToNodesResponse newInstance(
Map<NodeAttribute, Set<String>> map) {
Map<NodeAttributeKey, List<NodeToAttributeValue>> map) {
GetAttributesToNodesResponse response =
Records.newRecord(GetAttributesToNodesResponse.class);
response.setAttributeToNodes(map);
Expand All @@ -48,15 +49,17 @@ public static GetAttributesToNodesResponse newInstance(

@Public
@Evolving
public abstract void setAttributeToNodes(Map<NodeAttribute, Set<String>> map);
public abstract void setAttributeToNodes(
Map<NodeAttributeKey, List<NodeToAttributeValue>> map);

/*
* Get attributes to node hostname mapping.
/**
* Get mapping of NodeAttributeKey to its associated mapping of list of
* NodeToAttributeValuenode to attribute value.
*
* @return Map<NodeAttribute, Set<String>> node attributes to hostname
* mapping.
* @return Map<NodeAttributeKey, List<NodeToAttributeValue>> node attributes
* to list of NodeToAttributeValuenode.
*/
@Public
@Evolving
public abstract Map<NodeAttribute, Set<String>> getAttributesToNodes();
public abstract Map<NodeAttributeKey, List<NodeToAttributeValue>> getAttributesToNodes();
}
Expand Up @@ -17,14 +17,15 @@
*/
package org.apache.hadoop.yarn.api.protocolrecords;

import static org.apache.hadoop.classification.InterfaceAudience.*;
import static org.apache.hadoop.classification.InterfaceStability.*;
import java.util.Set;

import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Evolving;
import org.apache.hadoop.classification.InterfaceStability.Unstable;
import org.apache.hadoop.yarn.api.ApplicationClientProtocol;
import org.apache.hadoop.yarn.api.records.NodeAttribute;
import org.apache.hadoop.yarn.api.records.NodeAttributeInfo;
import org.apache.hadoop.yarn.util.Records;

import java.util.Set;

/**
* <p>
* The response sent by the <code>ResourceManager</code> to a client requesting
Expand All @@ -45,7 +46,7 @@ public abstract class GetClusterNodeAttributesResponse {
* @return GetClusterNodeAttributesResponse.
*/
public static GetClusterNodeAttributesResponse newInstance(
Set<NodeAttribute> attributes) {
Set<NodeAttributeInfo> attributes) {
GetClusterNodeAttributesResponse response =
Records.newRecord(GetClusterNodeAttributesResponse.class);
response.setNodeAttributes(attributes);
Expand All @@ -55,18 +56,18 @@ public static GetClusterNodeAttributesResponse newInstance(
/**
* Set node attributes to the response.
*
* @param attributes Node attributes
* @param attributes Map of Node attributeKey to Type.
*/
@Public
@Unstable
public abstract void setNodeAttributes(Set<NodeAttribute> attributes);
public abstract void setNodeAttributes(Set<NodeAttributeInfo> attributes);

/**
* Get node attributes of the response.
* Get node attributes from the response.
*
* @return Node attributes
* @return Node attributes.
*/
@Public
@Unstable
public abstract Set<NodeAttribute> getNodeAttributes();
public abstract Set<NodeAttributeInfo> getNodeAttributes();
}
Expand Up @@ -58,28 +58,21 @@ public static NodeAttribute newInstance(String attributePrefix,
String attributeName, NodeAttributeType attributeType,
String attributeValue) {
NodeAttribute nodeAttribute = Records.newRecord(NodeAttribute.class);
nodeAttribute.setAttributePrefix(attributePrefix);
nodeAttribute.setAttributeName(attributeName);
NodeAttributeKey nodeAttributeKey =
NodeAttributeKey.newInstance(attributePrefix, attributeName);
nodeAttribute.setAttributeKey(nodeAttributeKey);
nodeAttribute.setAttributeType(attributeType);
nodeAttribute.setAttributeValue(attributeValue);
return nodeAttribute;
}

@Public
@Unstable
public abstract String getAttributePrefix();
public abstract NodeAttributeKey getAttributeKey();

@Public
@Unstable
public abstract void setAttributePrefix(String attributePrefix);

@Public
@Unstable
public abstract String getAttributeName();

@Public
@Unstable
public abstract void setAttributeName(String attributeName);
public abstract void setAttributeKey(NodeAttributeKey attributeKey);

@Public
@Unstable
Expand Down
@@ -0,0 +1,62 @@
/**
* 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.hadoop.yarn.api.records;

import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Unstable;
import org.apache.hadoop.yarn.util.Records;

/**
* <p>
* Node Attribute Info describes a NodeAttribute.
* </p>
*/
@Public
@Unstable
public abstract class NodeAttributeInfo {

public static NodeAttributeInfo newInstance(NodeAttribute nodeAttribute) {
return newInstance(nodeAttribute.getAttributeKey(),
nodeAttribute.getAttributeType());
}

public static NodeAttributeInfo newInstance(NodeAttributeKey nodeAttributeKey,
NodeAttributeType attributeType) {
NodeAttributeInfo nodeAttribute =
Records.newRecord(NodeAttributeInfo.class);
nodeAttribute.setAttributeKey(nodeAttributeKey);
nodeAttribute.setAttributeType(attributeType);
return nodeAttribute;
}

@Public
@Unstable
public abstract NodeAttributeKey getAttributeKey();

@Public
@Unstable
public abstract void setAttributeKey(NodeAttributeKey attributeKey);

@Public
@Unstable
public abstract NodeAttributeType getAttributeType();

@Public
@Unstable
public abstract void setAttributeType(NodeAttributeType attributeType);
}
@@ -0,0 +1,66 @@
/**
* 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.hadoop.yarn.api.records;

import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Unstable;
import org.apache.hadoop.yarn.util.Records;

/**
* <p>
* Node AttributeKey uniquely identifies a given Node Attribute. Node Attribute
* is identified based on attribute prefix and name.
* </p>
* <p>
* Node Attribute Prefix is used as namespace to segregate the attributes.
* </p>
*/
@Public
@Unstable
public abstract class NodeAttributeKey {

public static NodeAttributeKey newInstance(String attributeName) {
return newInstance(NodeAttribute.PREFIX_CENTRALIZED, attributeName);
}

public static NodeAttributeKey newInstance(String attributePrefix,
String attributeName) {
NodeAttributeKey nodeAttributeKey =
Records.newRecord(NodeAttributeKey.class);
nodeAttributeKey.setAttributePrefix(attributePrefix);
nodeAttributeKey.setAttributeName(attributeName);
return nodeAttributeKey;
}

@Public
@Unstable
public abstract String getAttributePrefix();

@Public
@Unstable
public abstract void setAttributePrefix(String attributePrefix);

@Public
@Unstable
public abstract String getAttributeName();

@Public
@Unstable
public abstract void setAttributeName(String attributeName);
}

0 comments on commit 8cf6a9a

Please sign in to comment.