Search in sources :

Example 6 with UnavailableException

use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.

the class PollingMasterInquireClientTest method pollRejectingDoesntHang.

@Test(timeout = 10000)
public void pollRejectingDoesntHang() throws Exception {
    int port = mPort.getPort();
    InetSocketAddress serverAddress = new InetSocketAddress("127.0.0.1", port);
    RejectingServer s = new RejectingServer(serverAddress);
    s.start();
    List<InetSocketAddress> addrs = Arrays.asList(InetSocketAddress.createUnresolved(NetworkAddressUtils.getLocalHostName(Constants.SECOND_MS), port));
    PollingMasterInquireClient client = new PollingMasterInquireClient(addrs, () -> new CountingRetry(0), new ConfigurationBuilder().build());
    try {
        client.getPrimaryRpcAddress();
        fail("Expected polling to fail");
    } catch (UnavailableException e) {
    // Expected
    }
}
Also used : ConfigurationBuilder(alluxio.conf.ConfigurationBuilder) CountingRetry(alluxio.retry.CountingRetry) RejectingServer(alluxio.network.RejectingServer) InetSocketAddress(java.net.InetSocketAddress) UnavailableException(alluxio.exception.status.UnavailableException) Test(org.junit.Test)

Example 7 with UnavailableException

use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.

the class ZkMasterInquireClientTest method testNoParticipant.

@Test
public void testNoParticipant() throws Exception {
    // Create zk inquire client.
    MasterInquireClient zkInquirer = ZkMasterInquireClient.getClient(mZkServer.getConnectString(), ELECTION_PATH, LEADER_PATH, INQUIRE_RETRY_COUNT, ZOOKEEPER_AUTH_ENABLED);
    // Create curator client for manipulating the leader path.
    CuratorFramework client = CuratorFrameworkFactory.newClient(mZkServer.getConnectString(), new ExponentialBackoffRetry(Constants.SECOND_MS, INQUIRE_RETRY_COUNT));
    // Create the leader path with no participants.
    client.start();
    client.create().forPath(LEADER_PATH);
    client.close();
    // Query should fail with no leader under path.
    boolean queryFailed = false;
    try {
        zkInquirer.getPrimaryRpcAddress();
    } catch (UnavailableException e) {
        // Expected.
        queryFailed = true;
    }
    Assert.assertTrue("Master query should have been failed.", queryFailed);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) UnavailableException(alluxio.exception.status.UnavailableException) Test(org.junit.Test)

Example 8 with UnavailableException

use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.

the class AbstractClient method retryRPCInternal.

private synchronized <V> V retryRPCInternal(RetryPolicy retryPolicy, RpcCallable<V> rpc, Supplier<Void> onRetry) throws AlluxioStatusException {
    Exception ex = null;
    while (retryPolicy.attempt()) {
        if (mClosed) {
            throw new FailedPreconditionException("Client is closed");
        }
        connect();
        try {
            return rpc.call();
        } catch (StatusRuntimeException e) {
            AlluxioStatusException se = AlluxioStatusException.fromStatusRuntimeException(e);
            if (se.getStatusCode() == Status.Code.UNAVAILABLE || se.getStatusCode() == Status.Code.CANCELLED || se.getStatusCode() == Status.Code.UNAUTHENTICATED || e.getCause() instanceof UnresolvedAddressException) {
                ex = se;
            } else {
                throw se;
            }
        }
        LOG.debug("Rpc failed ({}): ", retryPolicy.getAttemptCount(), ex);
        onRetry.get();
        disconnect();
    }
    throw new UnavailableException("Failed after " + retryPolicy.getAttemptCount() + " attempts: " + ex.toString(), ex);
}
Also used : FailedPreconditionException(alluxio.exception.status.FailedPreconditionException) StatusRuntimeException(io.grpc.StatusRuntimeException) UnavailableException(alluxio.exception.status.UnavailableException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) FailedPreconditionException(alluxio.exception.status.FailedPreconditionException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) UnauthenticatedException(alluxio.exception.status.UnauthenticatedException) IOException(java.io.IOException) NotFoundException(alluxio.exception.status.NotFoundException) StatusRuntimeException(io.grpc.StatusRuntimeException) ServiceNotFoundException(alluxio.exception.ServiceNotFoundException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) UnavailableException(alluxio.exception.status.UnavailableException)

Example 9 with UnavailableException

use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.

the class ConfigurationUtils method loadConfiguration.

/**
 * Loads configuration from meta master in one RPC.
 *
 * @param address the meta master address
 * @param conf the existing configuration
 * @param ignoreClusterConf do not load cluster configuration related information
 * @param ignorePathConf do not load path configuration related information
 * @return the RPC response
 */
public static GetConfigurationPResponse loadConfiguration(InetSocketAddress address, AlluxioConfiguration conf, boolean ignoreClusterConf, boolean ignorePathConf) throws AlluxioStatusException {
    GrpcChannel channel = null;
    try {
        LOG.debug("Alluxio client (version {}) is trying to load configuration from meta master {}", RuntimeConstants.VERSION, address);
        channel = GrpcChannelBuilder.newBuilder(GrpcServerAddress.create(address), conf).setClientType("ConfigurationUtils").disableAuthentication().build();
        MetaMasterConfigurationServiceGrpc.MetaMasterConfigurationServiceBlockingStub client = MetaMasterConfigurationServiceGrpc.newBlockingStub(channel);
        GetConfigurationPResponse response = client.getConfiguration(GetConfigurationPOptions.newBuilder().setRawValue(true).setIgnoreClusterConf(ignoreClusterConf).setIgnorePathConf(ignorePathConf).build());
        LOG.debug("Alluxio client has loaded configuration from meta master {}", address);
        return response;
    } catch (io.grpc.StatusRuntimeException e) {
        throw new UnavailableException(String.format("Failed to handshake with master %s to load cluster default configuration values: %s", address, e.getMessage()), e);
    } catch (UnauthenticatedException e) {
        throw new RuntimeException(String.format("Received authentication exception during boot-strap connect with host:%s", address), e);
    } finally {
        if (channel != null) {
            channel.shutdown();
        }
    }
}
Also used : MetaMasterConfigurationServiceGrpc(alluxio.grpc.MetaMasterConfigurationServiceGrpc) UnauthenticatedException(alluxio.exception.status.UnauthenticatedException) UnavailableException(alluxio.exception.status.UnavailableException) GetConfigurationPResponse(alluxio.grpc.GetConfigurationPResponse) GrpcChannel(alluxio.grpc.GrpcChannel)

Example 10 with UnavailableException

use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.

the class AlluxioMasterRestServiceHandler method getWebUIBrowse.

/**
 * Gets Web UI browse page data.
 *
 * @param requestPath the request path
 * @param requestOffset the request offset
 * @param requestEnd the request end
 * @param requestLimit the request limit
 * @return the response object
 */
@GET
@Path(WEBUI_BROWSE)
public Response getWebUIBrowse(@DefaultValue("/") @QueryParam("path") String requestPath, @DefaultValue("0") @QueryParam("offset") String requestOffset, @DefaultValue("") @QueryParam("end") String requestEnd, @DefaultValue("20") @QueryParam("limit") String requestLimit) {
    return RestUtils.call(() -> {
        MasterWebUIBrowse response = new MasterWebUIBrowse();
        if (!ServerConfiguration.getBoolean(PropertyKey.WEB_FILE_INFO_ENABLED)) {
            return response;
        }
        if (SecurityUtils.isSecurityEnabled(ServerConfiguration.global()) && AuthenticatedClientUser.get(ServerConfiguration.global()) == null) {
            AuthenticatedClientUser.set(ServerUserState.global().getUser().getName());
        }
        response.setDebug(ServerConfiguration.getBoolean(PropertyKey.DEBUG)).setShowPermissions(ServerConfiguration.getBoolean(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_ENABLED)).setMasterNodeAddress(mMasterProcess.getRpcAddress().toString()).setInvalidPathError("");
        List<FileInfo> filesInfo;
        String path = URLDecoder.decode(requestPath, "UTF-8");
        if (path.isEmpty()) {
            path = AlluxioURI.SEPARATOR;
        }
        AlluxioURI currentPath = new AlluxioURI(path);
        response.setCurrentPath(currentPath.toString()).setViewingOffset(0);
        try {
            long fileId = mFileSystemMaster.getFileId(currentPath);
            FileInfo fileInfo = mFileSystemMaster.getFileInfo(fileId);
            UIFileInfo currentFileInfo = new UIFileInfo(fileInfo, ServerConfiguration.global(), new MasterStorageTierAssoc().getOrderedStorageAliases());
            if (currentFileInfo.getAbsolutePath() == null) {
                throw new FileDoesNotExistException(currentPath.toString());
            }
            response.setCurrentDirectory(currentFileInfo).setBlockSizeBytes(currentFileInfo.getBlockSizeBytes());
            if (!currentFileInfo.getIsDirectory()) {
                long relativeOffset = 0;
                long offset;
                try {
                    if (requestOffset != null) {
                        relativeOffset = Long.parseLong(requestOffset);
                    }
                } catch (NumberFormatException e) {
                // ignore the exception
                }
                // relative to the end of the file.
                if (requestEnd.equals("")) {
                    offset = relativeOffset;
                } else {
                    offset = fileInfo.getLength() - relativeOffset;
                }
                if (offset < 0) {
                    offset = 0;
                } else if (offset > fileInfo.getLength()) {
                    offset = fileInfo.getLength();
                }
                try {
                    AlluxioURI absolutePath = new AlluxioURI(currentFileInfo.getAbsolutePath());
                    FileSystem fs = mFsClient;
                    String fileData;
                    URIStatus status = fs.getStatus(absolutePath);
                    if (status.isCompleted()) {
                        OpenFilePOptions options = OpenFilePOptions.newBuilder().setReadType(ReadPType.NO_CACHE).build();
                        try (FileInStream is = fs.openFile(absolutePath, options)) {
                            int len = (int) Math.min(5L * Constants.KB, status.getLength() - offset);
                            byte[] data = new byte[len];
                            long skipped = is.skip(offset);
                            if (skipped < 0) {
                                // nothing was skipped
                                fileData = "Unable to traverse to offset; is file empty?";
                            } else if (skipped < offset) {
                                // couldn't skip all the way to offset
                                fileData = "Unable to traverse to offset; is offset larger than the file?";
                            } else {
                                // read may not read up to len, so only convert what was read
                                int read = is.read(data, 0, len);
                                if (read < 0) {
                                    // stream couldn't read anything, skip went to EOF?
                                    fileData = "Unable to read file";
                                } else {
                                    fileData = WebUtils.convertByteArrayToStringWithoutEscape(data, 0, read);
                                }
                            }
                        }
                    } else {
                        fileData = "The requested file is not complete yet.";
                    }
                    List<UIFileBlockInfo> uiBlockInfo = new ArrayList<>();
                    for (FileBlockInfo fileBlockInfo : mFileSystemMaster.getFileBlockInfoList(absolutePath)) {
                        uiBlockInfo.add(new UIFileBlockInfo(fileBlockInfo, ServerConfiguration.global()));
                    }
                    response.setFileBlocks(uiBlockInfo).setFileData(fileData).setHighestTierAlias(mBlockMaster.getGlobalStorageTierAssoc().getAlias(0));
                } catch (AlluxioException e) {
                    throw new IOException(e);
                }
                response.setViewingOffset(offset);
                return response;
            }
            if (currentPath.isRoot()) {
                response.setPathInfos(new UIFileInfo[0]);
            } else {
                String[] splitPath = PathUtils.getPathComponents(currentPath.toString());
                UIFileInfo[] pathInfos = new UIFileInfo[splitPath.length - 1];
                fileId = mFileSystemMaster.getFileId(currentPath);
                pathInfos[0] = new UIFileInfo(mFileSystemMaster.getFileInfo(fileId), ServerConfiguration.global(), new MasterStorageTierAssoc().getOrderedStorageAliases());
                AlluxioURI breadcrumb = new AlluxioURI(AlluxioURI.SEPARATOR);
                for (int i = 1; i < splitPath.length - 1; i++) {
                    breadcrumb = breadcrumb.join(splitPath[i]);
                    fileId = mFileSystemMaster.getFileId(breadcrumb);
                    pathInfos[i] = new UIFileInfo(mFileSystemMaster.getFileInfo(fileId), ServerConfiguration.global(), new MasterStorageTierAssoc().getOrderedStorageAliases());
                }
                response.setPathInfos(pathInfos);
            }
            filesInfo = mFileSystemMaster.listStatus(currentPath, ListStatusContext.defaults());
        } catch (FileDoesNotExistException e) {
            response.setInvalidPathError("Error: Invalid Path " + e.getMessage());
            return response;
        } catch (InvalidPathException e) {
            response.setInvalidPathError("Error: Invalid Path " + e.getLocalizedMessage());
            return response;
        } catch (UnavailableException e) {
            response.setInvalidPathError("The service is temporarily unavailable. " + e.getMessage());
            return response;
        } catch (IOException e) {
            response.setInvalidPathError("Error: File " + currentPath + " is not available " + e.getMessage());
            return response;
        } catch (AccessControlException e) {
            response.setInvalidPathError("Error: File " + currentPath + " cannot be accessed " + e.getMessage());
            return response;
        }
        List<UIFileInfo> fileInfos = new ArrayList<>(filesInfo.size());
        for (FileInfo fileInfo : filesInfo) {
            UIFileInfo toAdd = new UIFileInfo(fileInfo, ServerConfiguration.global(), new MasterStorageTierAssoc().getOrderedStorageAliases());
            try {
                if (!toAdd.getIsDirectory() && fileInfo.getLength() > 0) {
                    FileBlockInfo blockInfo = mFileSystemMaster.getFileBlockInfoList(new AlluxioURI(toAdd.getAbsolutePath())).get(0);
                    List<String> locations = new ArrayList<>();
                    // add the in-Alluxio block locations
                    for (BlockLocation location : blockInfo.getBlockInfo().getLocations()) {
                        WorkerNetAddress address = location.getWorkerAddress();
                        locations.add(address.getHost() + ":" + address.getDataPort());
                    }
                    // add underFS locations
                    locations.addAll(blockInfo.getUfsLocations());
                    toAdd.setFileLocations(locations);
                }
            } catch (FileDoesNotExistException e) {
                response.setFileDoesNotExistException("Error: non-existing file " + e.getMessage());
                return response;
            } catch (InvalidPathException e) {
                response.setInvalidPathException("Error: invalid path " + e.getMessage());
                return response;
            } catch (AccessControlException e) {
                response.setAccessControlException("Error: File " + currentPath + " cannot be accessed " + e.getMessage());
                return response;
            }
            fileInfos.add(toAdd);
        }
        fileInfos.sort(UIFileInfo.PATH_STRING_COMPARE);
        response.setNTotalFile(fileInfos.size());
        try {
            int offset = Integer.parseInt(requestOffset);
            int limit = Integer.parseInt(requestLimit);
            limit = offset == 0 && limit > fileInfos.size() ? fileInfos.size() : limit;
            limit = offset + limit > fileInfos.size() ? fileInfos.size() - offset : limit;
            int sum = Math.addExact(offset, limit);
            fileInfos = fileInfos.subList(offset, sum);
            response.setFileInfos(fileInfos);
        } catch (NumberFormatException e) {
            response.setFatalError("Error: offset or limit parse error, " + e.getLocalizedMessage());
            return response;
        } catch (ArithmeticException e) {
            response.setFatalError("Error: offset or offset + limit is out of bound, " + e.getLocalizedMessage());
            return response;
        } catch (IllegalArgumentException e) {
            response.setFatalError(e.getLocalizedMessage());
            return response;
        }
        return response;
    }, ServerConfiguration.global());
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) ArrayList(java.util.ArrayList) UnavailableException(alluxio.exception.status.UnavailableException) UIFileBlockInfo(alluxio.util.webui.UIFileBlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockLocation(alluxio.wire.BlockLocation) InvalidPathException(alluxio.exception.InvalidPathException) MasterWebUIBrowse(alluxio.wire.MasterWebUIBrowse) UIFileInfo(alluxio.util.webui.UIFileInfo) FileInfo(alluxio.wire.FileInfo) FileSystem(alluxio.client.file.FileSystem) UIFileInfo(alluxio.util.webui.UIFileInfo) AlluxioException(alluxio.exception.AlluxioException) UIFileBlockInfo(alluxio.util.webui.UIFileBlockInfo) AccessControlException(alluxio.exception.AccessControlException) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) MasterStorageTierAssoc(alluxio.MasterStorageTierAssoc) WorkerNetAddress(alluxio.wire.WorkerNetAddress) FileInStream(alluxio.client.file.FileInStream) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) AlluxioURI(alluxio.AlluxioURI) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

UnavailableException (alluxio.exception.status.UnavailableException)58 IOException (java.io.IOException)25 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)10 AlluxioURI (alluxio.AlluxioURI)9 AlluxioStatusException (alluxio.exception.status.AlluxioStatusException)9 NotFoundException (alluxio.exception.status.NotFoundException)9 InetSocketAddress (java.net.InetSocketAddress)9 BlockInfo (alluxio.wire.BlockInfo)8 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)7 WorkerNetAddress (alluxio.wire.WorkerNetAddress)7 WorkerInfo (alluxio.wire.WorkerInfo)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Set (java.util.Set)6 RetryPolicy (alluxio.retry.RetryPolicy)5 TimeoutException (java.util.concurrent.TimeoutException)5 BlockInfoException (alluxio.exception.BlockInfoException)4 ExceptionMessage (alluxio.exception.ExceptionMessage)4 InodeFile (alluxio.master.file.meta.InodeFile)4