alluxio.master.block.BlockMasterWorkerServiceHandler Maven / Gradle / Ivy
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/
package alluxio.master.block;
import alluxio.Constants;
import alluxio.exception.AlluxioException;
import alluxio.thrift.AlluxioTException;
import alluxio.thrift.BlockMasterWorkerService;
import alluxio.thrift.Command;
import alluxio.thrift.WorkerNetAddress;
import alluxio.wire.ThriftUtils;
import com.google.common.base.Preconditions;
import java.util.List;
import java.util.Map;
import javax.annotation.concurrent.NotThreadSafe;
/**
* This class is a Thrift handler for block master RPCs invoked by an Alluxio worker.
*/
@NotThreadSafe // TODO(jiri): make thread-safe (c.f. ALLUXIO-1664)
public class BlockMasterWorkerServiceHandler implements BlockMasterWorkerService.Iface {
private final BlockMaster mBlockMaster;
/**
* Creates a new instance of {@link BlockMasterWorkerServiceHandler}.
*
* @param blockMaster the {@link BlockMaster} the handler uses internally
*/
public BlockMasterWorkerServiceHandler(BlockMaster blockMaster) {
Preconditions.checkNotNull(blockMaster);
mBlockMaster = blockMaster;
}
@Override
public long getServiceVersion() {
return Constants.BLOCK_MASTER_WORKER_SERVICE_VERSION;
}
@Override
public long getWorkerId(WorkerNetAddress workerNetAddress) {
return mBlockMaster.getWorkerId(ThriftUtils.fromThrift((workerNetAddress)));
}
@Override
public void registerWorker(long workerId, List storageTiers,
Map totalBytesOnTiers, Map usedBytesOnTiers,
Map> currentBlocksOnTiers) throws AlluxioTException {
try {
mBlockMaster.workerRegister(workerId, storageTiers, totalBytesOnTiers,
usedBytesOnTiers, currentBlocksOnTiers);
} catch (AlluxioException e) {
throw e.toThrift();
}
}
@Override
public Command heartbeat(long workerId, Map usedBytesOnTiers,
List removedBlockIds, Map> addedBlocksOnTiers) {
return mBlockMaster.workerHeartbeat(workerId, usedBytesOnTiers, removedBlockIds,
addedBlocksOnTiers);
}
@Override
public void commitBlock(long workerId, long usedBytesOnTier, String tierAlias, long blockId,
long length) throws AlluxioTException {
try {
mBlockMaster.commitBlock(workerId, usedBytesOnTier, tierAlias, blockId, length);
} catch (AlluxioException e) {
throw e.toThrift();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy