use of alluxio.exception.status.AlluxioStatusException in project alluxio by Alluxio.
the class AbstractClient method connect.
/**
* Connects with the remote.
*/
@Override
public synchronized void connect() throws AlluxioStatusException {
if (mConnected) {
return;
}
disconnect();
Preconditions.checkState(!mClosed, "Client is closed, will not try to connect.");
IOException lastConnectFailure = null;
RetryPolicy retryPolicy = mRetryPolicySupplier.get();
while (retryPolicy.attempt()) {
if (mClosed) {
throw new FailedPreconditionException("Failed to connect: client has been closed");
}
// failover).
try {
mAddress = getAddress();
} catch (UnavailableException e) {
LOG.debug("Failed to determine {} rpc address ({}): {}", getServiceName(), retryPolicy.getAttemptCount(), e.toString());
continue;
}
try {
beforeConnect();
LOG.debug("Alluxio client (version {}) is trying to connect with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress);
mChannel = GrpcChannelBuilder.newBuilder(GrpcServerAddress.create(mAddress), mContext.getClusterConf()).setSubject(mContext.getSubject()).setClientType(getServiceName()).build();
// Create stub for version service on host
mVersionService = ServiceVersionClientServiceGrpc.newBlockingStub(mChannel);
mConnected = true;
afterConnect();
checkVersion(getServiceVersion());
LOG.debug("Alluxio client (version {}) is connected with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress);
return;
} catch (IOException e) {
LOG.debug("Failed to connect ({}) with {} @ {}", retryPolicy.getAttemptCount(), getServiceName(), mAddress, e);
lastConnectFailure = e;
if (e instanceof UnauthenticatedException) {
// If there has been a failure in opening GrpcChannel, it's possible because
// the authentication credential has expired. Relogin.
mContext.getUserState().relogin();
}
if (e instanceof NotFoundException) {
// service is not found in the server, skip retry
break;
}
}
}
if (mChannel != null) {
mChannel.shutdown();
}
if (mAddress == null) {
throw new UnavailableException(String.format("Failed to determine address for %s after %s attempts", getServiceName(), retryPolicy.getAttemptCount()));
}
/*
* Throw as-is if {@link UnauthenticatedException} occurred.
*/
if (lastConnectFailure instanceof UnauthenticatedException) {
throw (AlluxioStatusException) lastConnectFailure;
}
if (lastConnectFailure instanceof NotFoundException) {
throw new NotFoundException(lastConnectFailure.getMessage(), new ServiceNotFoundException(lastConnectFailure.getMessage(), lastConnectFailure));
}
throw new UnavailableException(String.format("Failed to connect to master (%s) after %s attempts." + "Please check if Alluxio master is currently running on \"%s\". Service=\"%s\"", mAddress, retryPolicy.getAttemptCount(), mAddress, getServiceName()), lastConnectFailure);
}
use of alluxio.exception.status.AlluxioStatusException in project alluxio by Alluxio.
the class GetPinnedFileIdsBench method cleanup.
@Override
public void cleanup() throws Exception {
// skip cleanup in job worker as the test files are to be cleaned up by the client
if (mBaseParameters.mDistributed) {
LOG.info("Skipping cleanup in distributed execution");
} else {
AlluxioURI baseUri = new AlluxioURI(mParameters.mBasePath);
try (CloseableResource<FileSystemMasterClient> client = mFileSystemContext.acquireMasterClientResource()) {
LOG.info("Deleting test directory {}", baseUri);
client.get().delete(baseUri, DeletePOptions.newBuilder().setRecursive(true).build());
} catch (AlluxioStatusException e) {
LOG.warn("Failed to delete test directory {}, manual cleanup needed", baseUri, e);
}
}
super.cleanup();
}
use of alluxio.exception.status.AlluxioStatusException in project alluxio by Alluxio.
the class RestUtilsTest method errorResponse.
@Test
public void errorResponse() throws Exception {
final Status status = Status.ALREADY_EXISTS;
final String message = "error message";
Response response = RestUtils.call(new RestUtils.RestCallable<Void>() {
@Override
public Void call() throws Exception {
throw new AlluxioStatusException(status.withDescription(message));
}
}, ServerConfiguration.global());
Assert.assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus());
RestUtils.ErrorResponse errorResponse = (RestUtils.ErrorResponse) response.getEntity();
Assert.assertEquals(status.getCode(), errorResponse.getStatusCode());
Assert.assertEquals(message, errorResponse.getMessage());
}
use of alluxio.exception.status.AlluxioStatusException in project alluxio by Alluxio.
the class ManagerProcessContext method getHostedAsyncStub.
private HostedManagerServiceGrpc.HostedManagerServiceStub getHostedAsyncStub() {
AlluxioConfiguration modifiedConfig = getConfWithHubTlsEnabled();
LOG.debug("Connecting to hosted hub with TLS enabled={}", modifiedConfig.getBoolean(PropertyKey.NETWORK_TLS_ENABLED));
if (mHostedAsyncSub == null) {
InetSocketAddress addr = NetworkAddressUtils.getConnectAddress(NetworkAddressUtils.ServiceType.HUB_HOSTED_RPC, modifiedConfig);
try {
GrpcChannel channel = RpcClient.createChannel(addr, modifiedConfig);
channel.intercept(new HubAuthenticationInterceptor(HubAuthentication.newBuilder().setApiKey(modifiedConfig.getString(PropertyKey.HUB_AUTHENTICATION_API_KEY)).setSecretKey(modifiedConfig.getString(PropertyKey.HUB_AUTHENTICATION_SECRET_KEY)).build()));
mHostedAsyncSub = HostedManagerServiceGrpc.newStub(channel);
} catch (AlluxioStatusException e) {
LOG.error("Error connecting to hosted hub {}", e);
}
}
return mHostedAsyncSub;
}
use of alluxio.exception.status.AlluxioStatusException in project alluxio by Alluxio.
the class PollingMasterInquireClient method getAddress.
@Nullable
private InetSocketAddress getAddress() {
// Iterate over the masters and try to connect to each of their RPC ports.
List<InetSocketAddress> addresses;
if (mConfiguration.getBoolean(PropertyKey.USER_RPC_SHUFFLE_MASTERS_ENABLED)) {
addresses = Lists.newArrayList(mConnectDetails.getAddresses());
Collections.shuffle(addresses);
} else {
addresses = mConnectDetails.getAddresses();
}
for (InetSocketAddress address : addresses) {
try {
LOG.debug("Checking whether {} is listening for RPCs", address);
pingMetaService(address);
LOG.debug("Successfully connected to {}", address);
return address;
} catch (UnavailableException e) {
LOG.debug("Failed to connect to {}", address);
continue;
} catch (DeadlineExceededException e) {
LOG.debug("Timeout while connecting to {}", address);
continue;
} catch (CancelledException e) {
LOG.debug("Cancelled while connecting to {}", address);
continue;
} catch (AlluxioStatusException e) {
LOG.error("Error while connecting to {}. {}", address, e);
// Breaking the loop on non filtered error.
break;
}
}
return null;
}
Aggregations