use of alluxio.hub.proto.ApplyMountPointRequest in project alluxio by Alluxio.
the class ManagerProcessContext method startApplyMountPointListener.
/**
* Starts a request stream observer for {@link HostedManagerServiceGrpc} ApplyMountPoint
* RPC calls.
*/
public void startApplyMountPointListener() {
HostedManagerServiceGrpc.HostedManagerServiceStub asyncStub = getHostedAsyncStub();
RequestStreamObserver requestObserver = new RequestStreamObserver<ApplyMountPointRequest, ApplyMountPointResponse>() {
@Override
public ApplyMountPointResponse exec(ApplyMountPointRequest req) {
return ApplyMountPointResponse.newBuilder().setHubMetadata(mHubMetadata).setPayload(applyMount(req)).build();
}
@Override
public void restart() {
startApplyMountPointListener();
}
@Override
public void handleError(String message, Throwable t) {
handleStatusRuntimeException(message, t);
}
};
StreamObserver<ApplyMountPointResponse> responseObserver = asyncStub.applyMountPoint(requestObserver);
requestObserver.start(responseObserver, ApplyMountPointResponse.newBuilder().setHubMetadata(mHubMetadata).build());
LOG.info("Started ApplyMountPoint async listener", asyncStub);
}
use of alluxio.hub.proto.ApplyMountPointRequest in project alluxio by Alluxio.
the class ManagerProcessContextTest method testApplyExistingMount.
@Test
public void testApplyExistingMount() throws Exception {
FileSystem mockFs = mock(FileSystem.class);
Map<String, MountPointInfo> mpi = new HashMap<>();
mpi.put("/", new MountPointInfo().setUfsUri("hdfs://localhost:9000/").setReadOnly(true).setUfsType("hdfs").setUfsCapacityBytes(9001));
doReturn(mockFs).when(mContext).getFileSystem();
doReturn(mpi).when(mockFs).getMountTable();
ApplyMountPointRequest vr = ApplyMountPointRequest.newBuilder().setPayload(ApplyMountPointRequest.Payload.newBuilder().setNew(mContext.getMountPointList().getMountPointList().get(0)).setBefore(mContext.getMountPointList().getMountPointList().get(0))).build();
mContext.applyMount(vr);
}
use of alluxio.hub.proto.ApplyMountPointRequest in project alluxio by Alluxio.
the class ManagerProcessContextTest method testApplyRootMountToOtherPath.
@Test
public void testApplyRootMountToOtherPath() throws Exception {
FileSystem mockFs = mock(FileSystem.class);
Map<String, MountPointInfo> mpi = new HashMap<>();
mpi.put("/", new MountPointInfo().setUfsUri("hdfs://localhost:9000/").setReadOnly(true).setUfsType("hdfs").setUfsCapacityBytes(9001));
doReturn(mockFs).when(mContext).getFileSystem();
doReturn(mpi).when(mockFs).getMountTable();
ApplyMountPointRequest vr = ApplyMountPointRequest.newBuilder().setPayload(ApplyMountPointRequest.Payload.newBuilder().setNew(mContext.getMountPointList().getMountPointList().get(0).toBuilder().setAlluxioPath("/mnt/new")).setBefore(mContext.getMountPointList().getMountPointList().get(0))).build();
ApplyMountPointResponse.Payload resp = mContext.applyMount(vr);
assertFalse(resp.getSuccess());
assertTrue(resp.getErrorCount() > 0);
}
use of alluxio.hub.proto.ApplyMountPointRequest in project alluxio by Alluxio.
the class ManagerProcessContextTest method testApplyNewMount.
@Test
public void testApplyNewMount() throws Exception {
FileSystem mockFs = mock(FileSystem.class);
Map<String, MountPointInfo> mpi = new HashMap<>();
mpi.put("/", new MountPointInfo().setUfsUri("hdfs://localhost:9000/").setReadOnly(true).setUfsType("hdfs").setUfsCapacityBytes(9001));
doReturn(mockFs).when(mContext).getFileSystem();
doReturn(mpi).when(mockFs).getMountTable();
ApplyMountPointRequest vr = ApplyMountPointRequest.newBuilder().setPayload(ApplyMountPointRequest.Payload.newBuilder().setNew(mContext.getMountPointList().getMountPointList().get(0))).build();
mContext.applyMount(vr);
}
use of alluxio.hub.proto.ApplyMountPointRequest in project alluxio by Alluxio.
the class ManagerProcessContext method applyMount.
/**
* Apply mount hdfs command.
*
* @param req validated request
* @return response
*/
public ApplyMountPointResponse.Payload applyMount(ApplyMountPointRequest req) {
ApplyMountPointRequest.Payload p = req.getPayload();
ApplyMountPointResponse.Payload.Builder resultBuilder = ApplyMountPointResponse.Payload.newBuilder();
alluxio.hub.proto.MountPointInfo mountPointInfo = p.getNew();
Map<String, String> properties = constructProp(mountPointInfo, false);
MountPOptions.Builder optionBuilder = MountPOptions.newBuilder().setReadOnly(mountPointInfo.getReadOnly()).setShared(mountPointInfo.getShared()).putAllProperties(properties);
boolean needToRemount = false;
try {
boolean needToMount = true;
if (p.hasBefore()) {
AlluxioURI originalMount = new AlluxioURI(p.getBefore().getAlluxioPath());
if (originalMount.isRoot() && (!(p.getBefore().getAlluxioPath().equals(p.getNew().getAlluxioPath()) && p.getBefore().getUfsUri().equals(p.getNew().getUfsUri())))) {
throw new IOException("Cannot change the mount location or ufs location of a root mount");
}
// if both mount uri and ufs uri has not changed
if (originalMount.isRoot() || (p.getBefore().getAlluxioPath().equals(p.getNew().getAlluxioPath()) && p.getBefore().getUfsUri().equals(p.getNew().getUfsUri()))) {
getFileSystem().updateMount(originalMount, optionBuilder.build());
needToMount = false;
} else {
getFileSystem().unmount(originalMount);
needToRemount = true;
}
}
if (needToMount) {
getFileSystem().mount(new AlluxioURI(mountPointInfo.getAlluxioPath()), new AlluxioURI(mountPointInfo.getUfsUri()), optionBuilder.build());
needToRemount = false;
}
if (mountPointInfo.hasHdfsInfo() && mountPointInfo.getHdfsInfo().getEnableSync()) {
getFileSystem().startSync(new AlluxioURI(mountPointInfo.getAlluxioPath()));
}
resultBuilder.setSuccess(true);
} catch (Exception e) {
if (needToRemount) {
alluxio.hub.proto.MountPointInfo oldMountPoint = p.getBefore();
MountPOptions.Builder oldOptionBuilder = MountPOptions.newBuilder().setReadOnly(oldMountPoint.getReadOnly()).setShared(oldMountPoint.getShared()).putAllProperties(constructProp(oldMountPoint, false));
try {
getFileSystem().mount(new AlluxioURI(oldMountPoint.getAlluxioPath()), new AlluxioURI(oldMountPoint.getUfsUri()), oldOptionBuilder.build());
} catch (Exception ex) {
LOG.warn("Failed to restore the mount point " + oldMountPoint.getAlluxioPath() + " to previous state");
resultBuilder.addError(ValidationUtils.getErrorInfo(ex));
}
}
LOG.warn("Failed applying mount settings due to " + ValidationUtils.getErrorInfo(e));
resultBuilder.setSuccess(false);
resultBuilder.addError(ValidationUtils.getErrorInfo(e));
// =====================
if (e instanceof InvalidPathException) {
if (exceptionMatchesPattern(e, "mount point.*already exists.*")) {
resultBuilder.setAdvice("Another file, directory, or mount point already exists at this" + " path. Check the Alluxio path you are mounting to again to make sure it" + " doesn't conflict with paths that already exist.");
} else if (exceptionMatchesPattern(e, "mount point.*is a prefix of.*")) {
resultBuilder.setAdvice("A mount point with a similar UFS URI is already mounted to" + " Alluxio. Make sure that your UFS URI doesn't have a namespace overlap with" + " another existing mount point");
} else if (exceptionMatchesPattern(e, ".*path.*is invalid.*")) {
resultBuilder.setAdvice("We couldn't parse your Alluxio path. Make sure to provide the" + " absolute path to where the new mount point should exist.");
}
} else if (e instanceof FileDoesNotExistException) {
if (exceptionMatchesPattern(e, "file.*creation failed. component.*does not exist")) {
resultBuilder.setAdvice("One of components in the path you are trying to mount to does" + " not exist. Make sure that all path components in the Alluxio namespace you" + " are trying to mount at exists, except for the last one.");
}
} else if (e instanceof AlluxioException) {
if (exceptionMatchesPattern(e, ".*no underfilesystem factory found for.*")) {
resultBuilder.setAdvice(String.format("Alluxio couldn't find a matching library with the" + " URI (%s) and version (%s) provided. This means that you're trying to mount a" + " URI with an unsupported scheme (<scheme>://) or, that Alluxio doesn't have" + " an available version of the UFS type you're trying to mount.", mountPointInfo.getUfsUri(), p.getNew().hasHdfsInfo() ? p.getNew().getHdfsInfo().getHdfsVersion() : "N/A"));
} else if (exceptionMatchesPattern(e, ".*ufs path.*does not exist.*")) {
resultBuilder.setAdvice("The UFS path you are trying to mount does not exist in the UFS." + " Please make sure the UFS path specified exists.");
} else if (exceptionMatchesPattern(e, ".*java.net.unknownhostexception:.*")) {
resultBuilder.setAdvice(String.format("We weren't able to resolve the hostname in your" + " HDFS uri %s. Please double check that you've typed the hostname correctly and" + " that the system DNS can resolve the hostname.", mountPointInfo.getUfsUri()));
} else if (exceptionMatchesPattern(e, "call from.*to.*failed on connection exception.*")) {
resultBuilder.setAdvice("We were able to resolve the hostname of your URI, but failed to" + " connect. Double check that the hostname and port are correct. Then, if it" + " still fails verify that there is no firewall blocking connections between" + " this machine and the UFS URI specified.");
}
}
// END Advice handling
// ===================
}
return resultBuilder.build();
}
Aggregations