Search in sources :

Example 26 with AlluxioConfiguration

use of alluxio.conf.AlluxioConfiguration in project alluxio by Alluxio.

the class AgentProcessMonitor method main.

/**
 * Starts the Hub Agent monitor.
 *
 * @param args command line arguments, should be empty
 */
public static void main(String[] args) {
    AlluxioConfiguration conf = ServerConfiguration.global();
    RetryPolicy policy = new ExponentialBackoffRetry(50, 1000, // Max time ~2 min
    130);
    InetSocketAddress addr = AgentRpcServer.getConfiguredAddress(conf);
    try {
        pingService(addr, policy, 5000);
    } catch (Exception e) {
        LOG.error("Failed to connect to Hub Agent RPC server @" + addr);
        System.exit(1);
    }
    System.exit(0);
}
Also used : ExponentialBackoffRetry(alluxio.retry.ExponentialBackoffRetry) InetSocketAddress(java.net.InetSocketAddress) RetryPolicy(alluxio.retry.RetryPolicy) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration)

Example 27 with AlluxioConfiguration

use of alluxio.conf.AlluxioConfiguration in project alluxio by Alluxio.

the class AgentRpcServerTest method testSimpleStartup.

@Test
public void testSimpleStartup() throws Exception {
    AlluxioConfiguration conf = getTestSpecificTestConfig();
    AgentRpcServer server = new AgentRpcServer(conf, TestAgentProcessContextFactory.simpleContext(conf));
    // Server is running if assigned port is != 0
    assertTrue(server.isServing());
    assertTrue(server.getPort() != 0);
}
Also used : AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) Test(org.junit.Test) BaseHubTest(alluxio.hub.test.BaseHubTest)

Example 28 with AlluxioConfiguration

use of alluxio.conf.AlluxioConfiguration in project alluxio by Alluxio.

the class JobUtils method loadThroughRead.

private static void loadThroughRead(URIStatus status, FileSystemContext context, long blockId, AlluxioConfiguration conf) throws IOException {
    // This does not work for remote worker unless we have passive cache on.
    AlluxioProperties prop = context.getClusterConf().copyProperties();
    prop.set(PropertyKey.USER_FILE_PASSIVE_CACHE_ENABLED, true);
    AlluxioConfiguration config = new InstancedConfiguration(prop);
    FileSystemContext loadContext = FileSystemContext.create(config);
    AlluxioBlockStore blockStore = AlluxioBlockStore.create(loadContext);
    OpenFilePOptions openOptions = OpenFilePOptions.newBuilder().setReadType(ReadPType.CACHE).build();
    InStreamOptions inOptions = new InStreamOptions(status, openOptions, conf);
    inOptions.setUfsReadLocationPolicy(BlockLocationPolicy.Factory.create(LocalFirstPolicy.class.getCanonicalName(), conf));
    BlockInfo info = Preconditions.checkNotNull(status.getBlockInfo(blockId));
    try (InputStream inputStream = blockStore.getInStream(info, inOptions, ImmutableMap.of())) {
        while (inputStream.read(sIgnoredReadBuf) != -1) {
        }
    }
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) AlluxioProperties(alluxio.conf.AlluxioProperties) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) InputStream(java.io.InputStream) FileSystemContext(alluxio.client.file.FileSystemContext) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) InStreamOptions(alluxio.client.file.options.InStreamOptions)

Example 29 with AlluxioConfiguration

use of alluxio.conf.AlluxioConfiguration in project alluxio by Alluxio.

the class JobUtils method loadBlock.

/**
 * Loads a block into the local worker. If the block doesn't exist in Alluxio, it will be read
 * from the UFS.
 * @param status the uriStatus
 * @param context filesystem context
 * @param blockId the id of the block to load
 * @param address specify a worker to load into
 * @param directCache Use passive-cache or direct cache request
 */
public static void loadBlock(URIStatus status, FileSystemContext context, long blockId, WorkerNetAddress address, boolean directCache) throws AlluxioException, IOException {
    AlluxioConfiguration conf = ServerConfiguration.global();
    // Explicitly specified a worker to load
    WorkerNetAddress localNetAddress = address;
    String localHostName = NetworkAddressUtils.getConnectHost(ServiceType.WORKER_RPC, conf);
    List<WorkerNetAddress> netAddress = context.getCachedWorkers().stream().map(BlockWorkerInfo::getNetAddress).filter(x -> Objects.equals(x.getHost(), localHostName)).collect(Collectors.toList());
    if (localNetAddress == null && !netAddress.isEmpty()) {
        localNetAddress = netAddress.get(0);
    }
    if (localNetAddress == null) {
        throw new NotFoundException(ExceptionMessage.NO_LOCAL_BLOCK_WORKER_LOAD_TASK.getMessage(blockId));
    }
    Set<String> pinnedLocation = status.getPinnedMediumTypes();
    if (pinnedLocation.size() > 1) {
        throw new AlluxioException(ExceptionMessage.PINNED_TO_MULTIPLE_MEDIUMTYPES.getMessage(status.getPath()));
    }
    // Only use this read local first method to load if nearest worker is clear
    if (netAddress.size() <= 1 && pinnedLocation.isEmpty() && status.isPersisted()) {
        if (directCache) {
            loadThroughCacheRequest(status, context, blockId, conf, localNetAddress);
        } else {
            loadThroughRead(status, context, blockId, conf);
        }
        return;
    }
    // TODO(bin): remove the following case when we consolidate tier and medium
    // since there is only one element in the set, we take the first element in the set
    String medium = pinnedLocation.isEmpty() ? "" : pinnedLocation.iterator().next();
    OpenFilePOptions openOptions = OpenFilePOptions.newBuilder().setReadType(ReadPType.NO_CACHE).build();
    InStreamOptions inOptions = new InStreamOptions(status, openOptions, conf);
    // Set read location policy always to local first for loading blocks for job tasks
    inOptions.setUfsReadLocationPolicy(BlockLocationPolicy.Factory.create(LocalFirstPolicy.class.getCanonicalName(), conf));
    OutStreamOptions outOptions = OutStreamOptions.defaults(context.getClientContext());
    outOptions.setMediumType(medium);
    // Set write location policy always to local first for loading blocks for job tasks
    outOptions.setLocationPolicy(BlockLocationPolicy.Factory.create(LocalFirstPolicy.class.getCanonicalName(), conf));
    BlockInfo blockInfo = status.getBlockInfo(blockId);
    Preconditions.checkNotNull(blockInfo, "Can not find block %s in status %s", blockId, status);
    long blockSize = blockInfo.getLength();
    AlluxioBlockStore blockStore = AlluxioBlockStore.create(context);
    try (OutputStream outputStream = blockStore.getOutStream(blockId, blockSize, localNetAddress, outOptions)) {
        try (InputStream inputStream = blockStore.getInStream(blockId, inOptions)) {
            ByteStreams.copy(inputStream, outputStream);
        } catch (Throwable t) {
            try {
                ((Cancelable) outputStream).cancel();
            } catch (Throwable t2) {
                t.addSuppressed(t2);
            }
            throw t;
        }
    }
}
Also used : Cancelable(alluxio.client.Cancelable) BlockLocationPolicy(alluxio.client.block.policy.BlockLocationPolicy) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) NetworkAddressUtils(alluxio.util.network.NetworkAddressUtils) FileBlockInfo(alluxio.wire.FileBlockInfo) PropertyKey(alluxio.conf.PropertyKey) ConcurrentMap(java.util.concurrent.ConcurrentMap) LocalFirstPolicy(alluxio.client.block.policy.LocalFirstPolicy) Constants(alluxio.Constants) CloseableResource(alluxio.resource.CloseableResource) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) ReadPType(alluxio.grpc.ReadPType) IndexDefinition(alluxio.collections.IndexDefinition) ServiceType(alluxio.util.network.NetworkAddressUtils.ServiceType) BlockWorkerClient(alluxio.client.block.stream.BlockWorkerClient) OutputStream(java.io.OutputStream) Protocol(alluxio.proto.dataserver.Protocol) IndexedSet(alluxio.collections.IndexedSet) ServerConfiguration(alluxio.conf.ServerConfiguration) ImmutableMap(com.google.common.collect.ImmutableMap) CacheRequest(alluxio.grpc.CacheRequest) BlockInStream(alluxio.client.block.stream.BlockInStream) InStreamOptions(alluxio.client.file.options.InStreamOptions) ExceptionMessage(alluxio.exception.ExceptionMessage) OutStreamOptions(alluxio.client.file.options.OutStreamOptions) Set(java.util.Set) AlluxioException(alluxio.exception.AlluxioException) IOException(java.io.IOException) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) Pair(alluxio.collections.Pair) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) NotFoundException(alluxio.exception.status.NotFoundException) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) AlluxioProperties(alluxio.conf.AlluxioProperties) Objects(java.util.Objects) BlockLocation(alluxio.wire.BlockLocation) URIStatus(alluxio.client.file.URIStatus) List(java.util.List) FileSystemContext(alluxio.client.file.FileSystemContext) ByteStreams(com.google.common.io.ByteStreams) Preconditions(com.google.common.base.Preconditions) InstancedConfiguration(alluxio.conf.InstancedConfiguration) InputStream(java.io.InputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) NotFoundException(alluxio.exception.status.NotFoundException) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) InStreamOptions(alluxio.client.file.options.InStreamOptions) OutStreamOptions(alluxio.client.file.options.OutStreamOptions) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) AlluxioException(alluxio.exception.AlluxioException)

Example 30 with AlluxioConfiguration

use of alluxio.conf.AlluxioConfiguration in project alluxio by Alluxio.

the class DistributedLoadCommand method run.

@Override
public int run(CommandLine cl) throws AlluxioException, IOException {
    mActiveJobs = FileSystemShellUtils.getIntArg(cl, ACTIVE_JOB_COUNT_OPTION, AbstractDistributedJobCommand.DEFAULT_ACTIVE_JOBS);
    System.out.format("Allow up to %s active jobs%n", mActiveJobs);
    String[] args = cl.getArgs();
    AlluxioConfiguration conf = mFsContext.getClusterConf();
    int defaultBatchSize = conf.getInt(PropertyKey.JOB_REQUEST_BATCH_SIZE);
    int replication = FileSystemShellUtils.getIntArg(cl, REPLICATION_OPTION, DEFAULT_REPLICATION);
    int batchSize = FileSystemShellUtils.getIntArg(cl, BATCH_SIZE_OPTION, defaultBatchSize);
    boolean directCache = !cl.hasOption(PASSIVE_CACHE_OPTION.getLongOpt());
    Set<String> workerSet = new HashSet<>();
    Set<String> excludedWorkerSet = new HashSet<>();
    Set<String> localityIds = new HashSet<>();
    Set<String> excludedLocalityIds = new HashSet<>();
    if (cl.hasOption(HOST_FILE_OPTION.getLongOpt())) {
        String hostFile = cl.getOptionValue(HOST_FILE_OPTION.getLongOpt()).trim();
        readLinesToSet(workerSet, hostFile);
    } else if (cl.hasOption(HOSTS_OPTION.getLongOpt())) {
        String argOption = cl.getOptionValue(HOSTS_OPTION.getLongOpt()).trim();
        readItemsFromOptionString(workerSet, argOption);
    }
    if (cl.hasOption(EXCLUDED_HOST_FILE_OPTION.getLongOpt())) {
        String hostFile = cl.getOptionValue(EXCLUDED_HOST_FILE_OPTION.getLongOpt()).trim();
        readLinesToSet(excludedWorkerSet, hostFile);
    } else if (cl.hasOption(EXCLUDED_HOSTS_OPTION.getLongOpt())) {
        String argOption = cl.getOptionValue(EXCLUDED_HOSTS_OPTION.getLongOpt()).trim();
        readItemsFromOptionString(excludedWorkerSet, argOption);
    }
    if (cl.hasOption(LOCALITY_FILE_OPTION.getLongOpt())) {
        String localityFile = cl.getOptionValue(LOCALITY_FILE_OPTION.getLongOpt()).trim();
        readLinesToSet(localityIds, localityFile);
    } else if (cl.hasOption(LOCALITY_OPTION.getLongOpt())) {
        String argOption = cl.getOptionValue(LOCALITY_OPTION.getLongOpt()).trim();
        readItemsFromOptionString(localityIds, argOption);
    }
    if (cl.hasOption(EXCLUDED_LOCALITY_FILE_OPTION.getLongOpt())) {
        String localityFile = cl.getOptionValue(EXCLUDED_LOCALITY_FILE_OPTION.getLongOpt()).trim();
        readLinesToSet(excludedLocalityIds, localityFile);
    } else if (cl.hasOption(EXCLUDED_LOCALITY_OPTION.getLongOpt())) {
        String argOption = cl.getOptionValue(EXCLUDED_LOCALITY_OPTION.getLongOpt()).trim();
        readItemsFromOptionString(excludedLocalityIds, argOption);
    }
    List<URIStatus> filePool = new ArrayList<>(batchSize);
    if (!cl.hasOption(INDEX_FILE.getLongOpt())) {
        AlluxioURI path = new AlluxioURI(args[0]);
        DistributedLoadUtils.distributedLoad(this, filePool, batchSize, path, replication, workerSet, excludedWorkerSet, localityIds, excludedLocalityIds, directCache, true);
    } else {
        try (BufferedReader reader = new BufferedReader(new FileReader(args[0]))) {
            for (String filename; (filename = reader.readLine()) != null; ) {
                AlluxioURI path = new AlluxioURI(filename);
                DistributedLoadUtils.distributedLoad(this, filePool, batchSize, path, replication, workerSet, excludedWorkerSet, localityIds, excludedLocalityIds, directCache, true);
            }
        }
    }
    System.out.println(String.format("Completed count is %d,Failed count is %d.", getCompletedCount(), getFailedCount()));
    return 0;
}
Also used : ArrayList(java.util.ArrayList) URIStatus(alluxio.client.file.URIStatus) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) HashSet(java.util.HashSet) AlluxioURI(alluxio.AlluxioURI)

Aggregations

AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)62 Test (org.junit.Test)20 InstancedConfiguration (alluxio.conf.InstancedConfiguration)17 IOException (java.io.IOException)11 AlluxioURI (alluxio.AlluxioURI)7 UnderFileSystemFactory (alluxio.underfs.UnderFileSystemFactory)7 ArrayList (java.util.ArrayList)7 AlluxioProperties (alluxio.conf.AlluxioProperties)5 PropertyKey (alluxio.conf.PropertyKey)5 OpenFilePOptions (alluxio.grpc.OpenFilePOptions)5 HealthCheckClient (alluxio.HealthCheckClient)4 FileSystemContext (alluxio.client.file.FileSystemContext)4 InStreamOptions (alluxio.client.file.options.InStreamOptions)4 InetSocketAddress (java.net.InetSocketAddress)4 Constants (alluxio.Constants)3 AlluxioBlockStore (alluxio.client.block.AlluxioBlockStore)3 FileSystem (alluxio.client.file.FileSystem)3 URIStatus (alluxio.client.file.URIStatus)3 ReadRequest (alluxio.grpc.ReadRequest)3 InputStream (java.io.InputStream)3