YARN-1447: Forgot to add new files
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1548320 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a5fce4fa71
commit
1cdeb83167
@ -0,0 +1,78 @@
|
||||
/**
|
||||
* 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.yarn.util.Records;
|
||||
|
||||
/**
|
||||
* Used by Application Master to ask Node Manager reduce size of a specified
|
||||
* container
|
||||
*/
|
||||
public abstract class ContainerResourceDecrease {
|
||||
@Public
|
||||
public static ContainerResourceDecrease newInstance(
|
||||
ContainerId existingContainerId, Resource targetCapability) {
|
||||
ContainerResourceDecrease context = Records
|
||||
.newRecord(ContainerResourceDecrease.class);
|
||||
context.setContainerId(existingContainerId);
|
||||
context.setCapability(targetCapability);
|
||||
return context;
|
||||
}
|
||||
|
||||
@Public
|
||||
public abstract ContainerId getContainerId();
|
||||
|
||||
@Public
|
||||
public abstract void setContainerId(ContainerId containerId);
|
||||
|
||||
@Public
|
||||
public abstract Resource getCapability();
|
||||
|
||||
@Public
|
||||
public abstract void setCapability(Resource capability);
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getCapability().hashCode() + getContainerId().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other instanceof ContainerResourceDecrease) {
|
||||
ContainerResourceDecrease ctx = (ContainerResourceDecrease)other;
|
||||
|
||||
if (getContainerId() == null && ctx.getContainerId() != null) {
|
||||
return false;
|
||||
} else if (!getContainerId().equals(ctx.getContainerId())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getCapability() == null && ctx.getCapability() != null) {
|
||||
return false;
|
||||
} else if (!getCapability().equals(ctx.getCapability())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
/**
|
||||
* 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.yarn.util.Records;
|
||||
|
||||
/**
|
||||
* Represent a new increased container accepted by Resource Manager
|
||||
*/
|
||||
public abstract class ContainerResourceIncrease {
|
||||
@Public
|
||||
public static ContainerResourceIncrease newInstance(
|
||||
ContainerId existingContainerId, Resource targetCapability, Token token) {
|
||||
ContainerResourceIncrease context = Records
|
||||
.newRecord(ContainerResourceIncrease.class);
|
||||
context.setContainerId(existingContainerId);
|
||||
context.setCapability(targetCapability);
|
||||
context.setContainerToken(token);
|
||||
return context;
|
||||
}
|
||||
|
||||
@Public
|
||||
public abstract ContainerId getContainerId();
|
||||
|
||||
@Public
|
||||
public abstract void setContainerId(ContainerId containerId);
|
||||
|
||||
@Public
|
||||
public abstract Resource getCapability();
|
||||
|
||||
@Public
|
||||
public abstract void setCapability(Resource capability);
|
||||
|
||||
@Public
|
||||
public abstract Token getContainerToken();
|
||||
|
||||
@Public
|
||||
public abstract void setContainerToken(Token token);
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getCapability().hashCode() + getContainerId().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other instanceof ContainerResourceIncrease) {
|
||||
ContainerResourceIncrease ctx = (ContainerResourceIncrease)other;
|
||||
|
||||
if (getContainerId() == null && ctx.getContainerId() != null) {
|
||||
return false;
|
||||
} else if (!getContainerId().equals(ctx.getContainerId())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getCapability() == null && ctx.getCapability() != null) {
|
||||
return false;
|
||||
} else if (!getCapability().equals(ctx.getCapability())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/**
|
||||
* 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.yarn.util.Records;
|
||||
|
||||
/**
|
||||
* Used by Application Master, send a container resource increase request to
|
||||
* Resource Manager
|
||||
*/
|
||||
@Public
|
||||
public abstract class ContainerResourceIncreaseRequest {
|
||||
@Public
|
||||
public static ContainerResourceIncreaseRequest newInstance(
|
||||
ContainerId existingContainerId, Resource targetCapability) {
|
||||
ContainerResourceIncreaseRequest context = Records
|
||||
.newRecord(ContainerResourceIncreaseRequest.class);
|
||||
context.setContainerId(existingContainerId);
|
||||
context.setCapability(targetCapability);
|
||||
return context;
|
||||
}
|
||||
|
||||
@Public
|
||||
public abstract ContainerId getContainerId();
|
||||
|
||||
@Public
|
||||
public abstract void setContainerId(ContainerId containerId);
|
||||
|
||||
@Public
|
||||
public abstract Resource getCapability();
|
||||
|
||||
@Public
|
||||
public abstract void setCapability(Resource capability);
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getCapability().hashCode() + getContainerId().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other instanceof ContainerResourceIncreaseRequest) {
|
||||
ContainerResourceIncreaseRequest ctx =
|
||||
(ContainerResourceIncreaseRequest) other;
|
||||
|
||||
if (getContainerId() == null && ctx.getContainerId() != null) {
|
||||
return false;
|
||||
} else if (!getContainerId().equals(ctx.getContainerId())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getCapability() == null && ctx.getCapability() != null) {
|
||||
return false;
|
||||
} else if (!getCapability().equals(ctx.getCapability())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,136 @@
|
||||
/**
|
||||
* 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.impl.pb;
|
||||
|
||||
import org.apache.hadoop.yarn.api.records.ContainerId;
|
||||
import org.apache.hadoop.yarn.api.records.ContainerResourceDecrease;
|
||||
import org.apache.hadoop.yarn.api.records.Resource;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ContainerIdProto;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceDecreaseProto;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceDecreaseProtoOrBuilder;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ResourceProto;
|
||||
|
||||
public class ContainerResourceDecreasePBImpl extends ContainerResourceDecrease {
|
||||
ContainerResourceDecreaseProto proto = ContainerResourceDecreaseProto
|
||||
.getDefaultInstance();
|
||||
ContainerResourceDecreaseProto.Builder builder = null;
|
||||
boolean viaProto = false;
|
||||
|
||||
private ContainerId existingContainerId = null;
|
||||
private Resource targetCapability = null;
|
||||
|
||||
public ContainerResourceDecreasePBImpl() {
|
||||
builder = ContainerResourceDecreaseProto.newBuilder();
|
||||
}
|
||||
|
||||
public ContainerResourceDecreasePBImpl(ContainerResourceDecreaseProto proto) {
|
||||
this.proto = proto;
|
||||
viaProto = true;
|
||||
}
|
||||
|
||||
public ContainerResourceDecreaseProto getProto() {
|
||||
mergeLocalToProto();
|
||||
proto = viaProto ? proto : builder.build();
|
||||
viaProto = true;
|
||||
return proto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerId getContainerId() {
|
||||
ContainerResourceDecreaseProtoOrBuilder p = viaProto ? proto : builder;
|
||||
if (this.existingContainerId != null) {
|
||||
return this.existingContainerId;
|
||||
}
|
||||
if (p.hasContainerId()) {
|
||||
this.existingContainerId = convertFromProtoFormat(p.getContainerId());
|
||||
}
|
||||
return this.existingContainerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContainerId(ContainerId existingContainerId) {
|
||||
maybeInitBuilder();
|
||||
if (existingContainerId == null) {
|
||||
builder.clearContainerId();
|
||||
}
|
||||
this.existingContainerId = existingContainerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource getCapability() {
|
||||
ContainerResourceDecreaseProtoOrBuilder p = viaProto ? proto : builder;
|
||||
if (this.targetCapability != null) {
|
||||
return this.targetCapability;
|
||||
}
|
||||
if (p.hasCapability()) {
|
||||
this.targetCapability = convertFromProtoFormat(p.getCapability());
|
||||
}
|
||||
return this.targetCapability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCapability(Resource targetCapability) {
|
||||
maybeInitBuilder();
|
||||
if (targetCapability == null) {
|
||||
builder.clearCapability();
|
||||
}
|
||||
this.targetCapability = targetCapability;
|
||||
}
|
||||
|
||||
private ContainerIdPBImpl convertFromProtoFormat(ContainerIdProto p) {
|
||||
return new ContainerIdPBImpl(p);
|
||||
}
|
||||
|
||||
private ContainerIdProto convertToProtoFormat(ContainerId t) {
|
||||
return ((ContainerIdPBImpl) t).getProto();
|
||||
}
|
||||
|
||||
private Resource convertFromProtoFormat(ResourceProto p) {
|
||||
return new ResourcePBImpl(p);
|
||||
}
|
||||
|
||||
private ResourceProto convertToProtoFormat(Resource t) {
|
||||
return ((ResourcePBImpl) t).getProto();
|
||||
}
|
||||
|
||||
private void mergeLocalToProto() {
|
||||
if (viaProto) {
|
||||
maybeInitBuilder();
|
||||
}
|
||||
mergeLocalToBuilder();
|
||||
proto = builder.build();
|
||||
viaProto = true;
|
||||
}
|
||||
|
||||
private void maybeInitBuilder() {
|
||||
if (viaProto || builder == null) {
|
||||
builder = ContainerResourceDecreaseProto.newBuilder(proto);
|
||||
}
|
||||
viaProto = false;
|
||||
}
|
||||
|
||||
private void mergeLocalToBuilder() {
|
||||
if (this.existingContainerId != null) {
|
||||
builder.setContainerId(convertToProtoFormat(this.existingContainerId));
|
||||
}
|
||||
if (this.targetCapability != null) {
|
||||
builder.setCapability(convertToProtoFormat(this.targetCapability));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,171 @@
|
||||
/**
|
||||
* 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.impl.pb;
|
||||
|
||||
import org.apache.hadoop.security.proto.SecurityProtos.TokenProto;
|
||||
import org.apache.hadoop.yarn.api.records.ContainerId;
|
||||
import org.apache.hadoop.yarn.api.records.ContainerResourceIncrease;
|
||||
import org.apache.hadoop.yarn.api.records.Resource;
|
||||
import org.apache.hadoop.yarn.api.records.Token;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ContainerIdProto;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceIncreaseProto;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceIncreaseProtoOrBuilder;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ResourceProto;
|
||||
|
||||
public class ContainerResourceIncreasePBImpl extends ContainerResourceIncrease {
|
||||
ContainerResourceIncreaseProto proto = ContainerResourceIncreaseProto
|
||||
.getDefaultInstance();
|
||||
ContainerResourceIncreaseProto.Builder builder = null;
|
||||
boolean viaProto = false;
|
||||
|
||||
private ContainerId existingContainerId = null;
|
||||
private Resource targetCapability = null;
|
||||
private Token token = null;
|
||||
|
||||
public ContainerResourceIncreasePBImpl() {
|
||||
builder = ContainerResourceIncreaseProto.newBuilder();
|
||||
}
|
||||
|
||||
public ContainerResourceIncreasePBImpl(ContainerResourceIncreaseProto proto) {
|
||||
this.proto = proto;
|
||||
viaProto = true;
|
||||
}
|
||||
|
||||
public ContainerResourceIncreaseProto getProto() {
|
||||
mergeLocalToProto();
|
||||
proto = viaProto ? proto : builder.build();
|
||||
viaProto = true;
|
||||
return proto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerId getContainerId() {
|
||||
ContainerResourceIncreaseProtoOrBuilder p = viaProto ? proto : builder;
|
||||
if (this.existingContainerId != null) {
|
||||
return this.existingContainerId;
|
||||
}
|
||||
if (p.hasContainerId()) {
|
||||
this.existingContainerId = convertFromProtoFormat(p.getContainerId());
|
||||
}
|
||||
return this.existingContainerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContainerId(ContainerId existingContainerId) {
|
||||
maybeInitBuilder();
|
||||
if (existingContainerId == null) {
|
||||
builder.clearContainerId();
|
||||
}
|
||||
this.existingContainerId = existingContainerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource getCapability() {
|
||||
ContainerResourceIncreaseProtoOrBuilder p = viaProto ? proto : builder;
|
||||
if (this.targetCapability != null) {
|
||||
return this.targetCapability;
|
||||
}
|
||||
if (p.hasCapability()) {
|
||||
this.targetCapability = convertFromProtoFormat(p.getCapability());
|
||||
}
|
||||
return this.targetCapability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCapability(Resource targetCapability) {
|
||||
maybeInitBuilder();
|
||||
if (targetCapability == null) {
|
||||
builder.clearCapability();
|
||||
}
|
||||
this.targetCapability = targetCapability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token getContainerToken() {
|
||||
ContainerResourceIncreaseProtoOrBuilder p = viaProto ? proto : builder;
|
||||
if (this.token != null) {
|
||||
return this.token;
|
||||
}
|
||||
if (p.hasContainerToken()) {
|
||||
this.token = convertFromProtoFormat(p.getContainerToken());
|
||||
}
|
||||
return this.token;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContainerToken(Token token) {
|
||||
maybeInitBuilder();
|
||||
if (token == null) {
|
||||
builder.clearContainerToken();
|
||||
}
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
private ContainerIdPBImpl convertFromProtoFormat(ContainerIdProto p) {
|
||||
return new ContainerIdPBImpl(p);
|
||||
}
|
||||
|
||||
private ContainerIdProto convertToProtoFormat(ContainerId t) {
|
||||
return ((ContainerIdPBImpl) t).getProto();
|
||||
}
|
||||
|
||||
private Resource convertFromProtoFormat(ResourceProto p) {
|
||||
return new ResourcePBImpl(p);
|
||||
}
|
||||
|
||||
private ResourceProto convertToProtoFormat(Resource t) {
|
||||
return ((ResourcePBImpl) t).getProto();
|
||||
}
|
||||
|
||||
private Token convertFromProtoFormat(TokenProto p) {
|
||||
return new TokenPBImpl(p);
|
||||
}
|
||||
|
||||
private TokenProto convertToProtoFormat(Token t) {
|
||||
return ((TokenPBImpl) t).getProto();
|
||||
}
|
||||
|
||||
private void mergeLocalToProto() {
|
||||
if (viaProto) {
|
||||
maybeInitBuilder();
|
||||
}
|
||||
mergeLocalToBuilder();
|
||||
proto = builder.build();
|
||||
viaProto = true;
|
||||
}
|
||||
|
||||
private void maybeInitBuilder() {
|
||||
if (viaProto || builder == null) {
|
||||
builder = ContainerResourceIncreaseProto.newBuilder(proto);
|
||||
}
|
||||
viaProto = false;
|
||||
}
|
||||
|
||||
private void mergeLocalToBuilder() {
|
||||
if (this.existingContainerId != null) {
|
||||
builder.setContainerId(convertToProtoFormat(this.existingContainerId));
|
||||
}
|
||||
if (this.targetCapability != null) {
|
||||
builder.setCapability(convertToProtoFormat(this.targetCapability));
|
||||
}
|
||||
if (this.token != null) {
|
||||
builder.setContainerToken(convertToProtoFormat(this.token));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,141 @@
|
||||
/**
|
||||
* 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.impl.pb;
|
||||
|
||||
import org.apache.hadoop.yarn.api.records.ContainerId;
|
||||
import org.apache.hadoop.yarn.api.records.ContainerResourceIncreaseRequest;
|
||||
import org.apache.hadoop.yarn.api.records.Resource;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ContainerIdProto;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceIncreaseRequestProto;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceIncreaseRequestProtoOrBuilder;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ResourceProto;
|
||||
|
||||
|
||||
public class ContainerResourceIncreaseRequestPBImpl extends
|
||||
ContainerResourceIncreaseRequest {
|
||||
ContainerResourceIncreaseRequestProto proto =
|
||||
ContainerResourceIncreaseRequestProto.getDefaultInstance();
|
||||
ContainerResourceIncreaseRequestProto.Builder builder = null;
|
||||
boolean viaProto = false;
|
||||
|
||||
private ContainerId existingContainerId = null;
|
||||
private Resource targetCapability = null;
|
||||
|
||||
public ContainerResourceIncreaseRequestPBImpl() {
|
||||
builder = ContainerResourceIncreaseRequestProto.newBuilder();
|
||||
}
|
||||
|
||||
public ContainerResourceIncreaseRequestPBImpl(
|
||||
ContainerResourceIncreaseRequestProto proto) {
|
||||
this.proto = proto;
|
||||
viaProto = true;
|
||||
}
|
||||
|
||||
public ContainerResourceIncreaseRequestProto getProto() {
|
||||
mergeLocalToProto();
|
||||
proto = viaProto ? proto : builder.build();
|
||||
viaProto = true;
|
||||
return proto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerId getContainerId() {
|
||||
ContainerResourceIncreaseRequestProtoOrBuilder p = viaProto ? proto
|
||||
: builder;
|
||||
if (this.existingContainerId != null) {
|
||||
return this.existingContainerId;
|
||||
}
|
||||
if (p.hasContainerId()) {
|
||||
this.existingContainerId = convertFromProtoFormat(p.getContainerId());
|
||||
}
|
||||
return this.existingContainerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContainerId(ContainerId existingContainerId) {
|
||||
maybeInitBuilder();
|
||||
if (existingContainerId == null) {
|
||||
builder.clearContainerId();
|
||||
}
|
||||
this.existingContainerId = existingContainerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource getCapability() {
|
||||
ContainerResourceIncreaseRequestProtoOrBuilder p = viaProto ? proto
|
||||
: builder;
|
||||
if (this.targetCapability != null) {
|
||||
return this.targetCapability;
|
||||
}
|
||||
if (p.hasCapability()) {
|
||||
this.targetCapability = convertFromProtoFormat(p.getCapability());
|
||||
}
|
||||
return this.targetCapability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCapability(Resource targetCapability) {
|
||||
maybeInitBuilder();
|
||||
if (targetCapability == null) {
|
||||
builder.clearCapability();
|
||||
}
|
||||
this.targetCapability = targetCapability;
|
||||
}
|
||||
|
||||
private ContainerIdPBImpl convertFromProtoFormat(ContainerIdProto p) {
|
||||
return new ContainerIdPBImpl(p);
|
||||
}
|
||||
|
||||
private ContainerIdProto convertToProtoFormat(ContainerId t) {
|
||||
return ((ContainerIdPBImpl) t).getProto();
|
||||
}
|
||||
|
||||
private Resource convertFromProtoFormat(ResourceProto p) {
|
||||
return new ResourcePBImpl(p);
|
||||
}
|
||||
|
||||
private ResourceProto convertToProtoFormat(Resource t) {
|
||||
return ((ResourcePBImpl) t).getProto();
|
||||
}
|
||||
|
||||
private void mergeLocalToProto() {
|
||||
if (viaProto) {
|
||||
maybeInitBuilder();
|
||||
}
|
||||
mergeLocalToBuilder();
|
||||
proto = builder.build();
|
||||
viaProto = true;
|
||||
}
|
||||
|
||||
private void maybeInitBuilder() {
|
||||
if (viaProto || builder == null) {
|
||||
builder = ContainerResourceIncreaseRequestProto.newBuilder(proto);
|
||||
}
|
||||
viaProto = false;
|
||||
}
|
||||
|
||||
private void mergeLocalToBuilder() {
|
||||
if (this.existingContainerId != null) {
|
||||
builder.setContainerId(convertToProtoFormat(this.existingContainerId));
|
||||
}
|
||||
if (this.targetCapability != null) {
|
||||
builder.setCapability(convertToProtoFormat(this.targetCapability));
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
||||
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
||||
import org.apache.hadoop.yarn.api.records.ContainerId;
|
||||
import org.apache.hadoop.yarn.api.records.ContainerResourceDecrease;
|
||||
import org.apache.hadoop.yarn.api.records.Resource;
|
||||
import org.apache.hadoop.yarn.api.records.impl.pb.ContainerResourceDecreasePBImpl;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceDecreaseProto;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestContainerResourceDecrease {
|
||||
@Test
|
||||
public void testResourceDecreaseContext() {
|
||||
ContainerId containerId = ContainerId
|
||||
.newInstance(ApplicationAttemptId.newInstance(
|
||||
ApplicationId.newInstance(1234, 3), 3), 7);
|
||||
Resource resource = Resource.newInstance(1023, 3);
|
||||
ContainerResourceDecrease ctx = ContainerResourceDecrease.newInstance(
|
||||
containerId, resource);
|
||||
|
||||
// get proto and recover to ctx
|
||||
ContainerResourceDecreaseProto proto =
|
||||
((ContainerResourceDecreasePBImpl) ctx).getProto();
|
||||
ctx = new ContainerResourceDecreasePBImpl(proto);
|
||||
|
||||
// check values
|
||||
Assert.assertEquals(ctx.getCapability(), resource);
|
||||
Assert.assertEquals(ctx.getContainerId(), containerId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResourceDecreaseContextWithNull() {
|
||||
ContainerResourceDecrease ctx = ContainerResourceDecrease.newInstance(null,
|
||||
null);
|
||||
|
||||
// get proto and recover to ctx;
|
||||
ContainerResourceDecreaseProto proto =
|
||||
((ContainerResourceDecreasePBImpl) ctx).getProto();
|
||||
ctx = new ContainerResourceDecreasePBImpl(proto);
|
||||
|
||||
// check values
|
||||
Assert.assertNull(ctx.getCapability());
|
||||
Assert.assertNull(ctx.getContainerId());
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
||||
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
||||
import org.apache.hadoop.yarn.api.records.ContainerId;
|
||||
import org.apache.hadoop.yarn.api.records.ContainerResourceIncrease;
|
||||
import org.apache.hadoop.yarn.api.records.Resource;
|
||||
import org.apache.hadoop.yarn.api.records.Token;
|
||||
import org.apache.hadoop.yarn.api.records.impl.pb.ContainerResourceIncreasePBImpl;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceIncreaseProto;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestContainerResourceIncrease {
|
||||
@Test
|
||||
public void testResourceIncreaseContext() {
|
||||
byte[] identifier = new byte[] { 1, 2, 3, 4 };
|
||||
Token token = Token.newInstance(identifier, "", "".getBytes(), "");
|
||||
ContainerId containerId = ContainerId
|
||||
.newInstance(ApplicationAttemptId.newInstance(
|
||||
ApplicationId.newInstance(1234, 3), 3), 7);
|
||||
Resource resource = Resource.newInstance(1023, 3);
|
||||
ContainerResourceIncrease ctx = ContainerResourceIncrease.newInstance(
|
||||
containerId, resource, token);
|
||||
|
||||
// get proto and recover to ctx
|
||||
ContainerResourceIncreaseProto proto =
|
||||
((ContainerResourceIncreasePBImpl) ctx).getProto();
|
||||
ctx = new ContainerResourceIncreasePBImpl(proto);
|
||||
|
||||
// check values
|
||||
Assert.assertEquals(ctx.getCapability(), resource);
|
||||
Assert.assertEquals(ctx.getContainerId(), containerId);
|
||||
Assert.assertTrue(Arrays.equals(ctx.getContainerToken().getIdentifier()
|
||||
.array(), identifier));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResourceIncreaseContextWithNull() {
|
||||
ContainerResourceIncrease ctx = ContainerResourceIncrease.newInstance(null,
|
||||
null, null);
|
||||
|
||||
// get proto and recover to ctx;
|
||||
ContainerResourceIncreaseProto proto =
|
||||
((ContainerResourceIncreasePBImpl) ctx).getProto();
|
||||
ctx = new ContainerResourceIncreasePBImpl(proto);
|
||||
|
||||
// check values
|
||||
Assert.assertNull(ctx.getContainerToken());
|
||||
Assert.assertNull(ctx.getCapability());
|
||||
Assert.assertNull(ctx.getContainerId());
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
||||
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
||||
import org.apache.hadoop.yarn.api.records.ContainerId;
|
||||
import org.apache.hadoop.yarn.api.records.ContainerResourceIncreaseRequest;
|
||||
import org.apache.hadoop.yarn.api.records.Resource;
|
||||
import org.apache.hadoop.yarn.api.records.impl.pb.ContainerResourceIncreaseRequestPBImpl;
|
||||
import org.apache.hadoop.yarn.proto.YarnProtos.ContainerResourceIncreaseRequestProto;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestContainerResourceIncreaseRequest {
|
||||
@Test
|
||||
public void ContainerResourceIncreaseRequest() {
|
||||
ContainerId containerId = ContainerId
|
||||
.newInstance(ApplicationAttemptId.newInstance(
|
||||
ApplicationId.newInstance(1234, 3), 3), 7);
|
||||
Resource resource = Resource.newInstance(1023, 3);
|
||||
ContainerResourceIncreaseRequest context = ContainerResourceIncreaseRequest
|
||||
.newInstance(containerId, resource);
|
||||
|
||||
// to proto and get it back
|
||||
ContainerResourceIncreaseRequestProto proto =
|
||||
((ContainerResourceIncreaseRequestPBImpl) context).getProto();
|
||||
ContainerResourceIncreaseRequest contextRecover =
|
||||
new ContainerResourceIncreaseRequestPBImpl(proto);
|
||||
|
||||
// check value
|
||||
Assert.assertEquals(contextRecover.getContainerId(), containerId);
|
||||
Assert.assertEquals(contextRecover.getCapability(), resource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResourceChangeContextWithNullField() {
|
||||
ContainerResourceIncreaseRequest context = ContainerResourceIncreaseRequest
|
||||
.newInstance(null, null);
|
||||
|
||||
// to proto and get it back
|
||||
ContainerResourceIncreaseRequestProto proto =
|
||||
((ContainerResourceIncreaseRequestPBImpl) context).getProto();
|
||||
ContainerResourceIncreaseRequest contextRecover =
|
||||
new ContainerResourceIncreaseRequestPBImpl(proto);
|
||||
|
||||
// check value
|
||||
Assert.assertNull(contextRecover.getContainerId());
|
||||
Assert.assertNull(contextRecover.getCapability());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user