Java Code Examples for org.apache.ignite.Ignite#fileSystem()

The following examples show how to use org.apache.ignite.Ignite#fileSystem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgfsEventsTestSuite.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Start a grid with the secondary file system.
 *
 * @return Secondary file system handle.
 * @throws Exception If failed.
 */
@Nullable private IgniteFileSystem startSecondary() throws Exception {
    IgniteConfiguration cfg = getConfiguration("grid-secondary", getSecondaryIgfsConfiguration());

    cfg.setLocalHost("127.0.0.1");
    cfg.setPeerClassLoadingEnabled(false);

    Ignite secG = G.start(cfg);

    return secG.fileSystem("igfs-secondary");
}
 
Example 2
Source File: IgniteHadoopFileSystemHandshakeSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Perform startup.
 *
 * @param dfltIgniteInstanceName Default Ignite instance name.
 * @param dfltIgfsName Default IGFS name.
 * @throws Exception If failed.
 */
private void startUp(boolean dfltIgniteInstanceName, boolean dfltIgfsName) throws Exception {
    Ignite ignite = G.start(gridConfiguration(dfltIgniteInstanceName));

    IgniteFileSystem igfs = ignite.fileSystem(dfltIgfsName ? "" : IGFS_NAME);

    igfs.mkdirs(PATH);
}
 
Example 3
Source File: IgfsTaskSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
    for (int i = 0; i < NODE_CNT; i++) {
        Ignite g = G.start(config(i));

        if (i + 1 == NODE_CNT)
            igfs = g.fileSystem("igfs");
    }
}
 
Example 4
Source File: IgfsMetricsSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Start a grid with the primary file system.
 *
 * @throws Exception If failed.
 */
private void startPrimary() throws Exception {
    igfsPrimary = new IgniteFileSystem[NODES_CNT];

    for (int i = 0; i < NODES_CNT; i++) {
        Ignite g = G.start(primaryConfiguration(i));

        igfsPrimary[i] = g.fileSystem(IGFS_PRIMARY);
    }
}
 
Example 5
Source File: IgfsAbstractBaseSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
    igfsSecondaryFileSystem = createSecondaryFileSystemStack();

    nodes = new Ignite[nodeCount()];

    for (int i = 0; i < nodes.length; i++) {
        String nodeName = i == 0 ? "ignite" : "ignite" + i;

        nodes[i] = startGridWithIgfs(nodeName, "igfs", mode, igfsSecondaryFileSystem, PRIMARY_REST_CFG,
            primaryIpFinder);
    }

    igfs = (IgfsImpl) nodes[0].fileSystem("igfs");

    if (client()) {
        // Start client.
        Ignition.setClientMode(true);

        try {
            Ignite ignite = startGridWithIgfs("ignite-client", "igfs", mode, igfsSecondaryFileSystem,
                PRIMARY_REST_CFG, primaryIpFinder);

            igfs = (IgfsImpl) ignite.fileSystem("igfs");
        }
        finally {
            Ignition.setClientMode(false);
        }
    }
}
 
Example 6
Source File: IgfsAbstractBaseSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates secondary file system stack.
 *
 * @return The secondary file system.
 * @throws Exception On error.
 */
protected IgfsSecondaryFileSystem createSecondaryFileSystemStack() throws Exception {
    Ignite igniteSecondary = startGridWithIgfs("ignite-secondary", "igfs-secondary", PRIMARY, null,
        SECONDARY_REST_CFG, secondaryIpFinder);

    IgfsEx secondaryIgfsImpl = (IgfsEx) igniteSecondary.fileSystem("igfs-secondary");

    igfsSecondary = new DefaultIgfsSecondaryFileSystemTestAdapter(secondaryIgfsImpl);

    return secondaryIgfsImpl.asSecondary();
}
 
Example 7
Source File: IgfsAbstractRecordResolverSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
    FileSystemConfiguration igfsCfg = new FileSystemConfiguration();

    igfsCfg.setName("igfs");
    igfsCfg.setBlockSize(512);
    igfsCfg.setDefaultMode(PRIMARY);

    CacheConfiguration dataCacheCfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    dataCacheCfg.setCacheMode(PARTITIONED);
    dataCacheCfg.setAtomicityMode(TRANSACTIONAL);
    dataCacheCfg.setNearConfiguration(new NearCacheConfiguration());
    dataCacheCfg.setWriteSynchronizationMode(FULL_SYNC);
    dataCacheCfg.setAffinityMapper(new IgfsGroupDataBlocksKeyMapper(128));
    dataCacheCfg.setBackups(0);

    CacheConfiguration metaCacheCfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    metaCacheCfg.setCacheMode(REPLICATED);
    metaCacheCfg.setAtomicityMode(TRANSACTIONAL);
    metaCacheCfg.setWriteSynchronizationMode(FULL_SYNC);

    igfsCfg.setMetaCacheConfiguration(metaCacheCfg);
    igfsCfg.setDataCacheConfiguration(dataCacheCfg);

    IgniteConfiguration cfg = new IgniteConfiguration();

    cfg.setIgniteInstanceName("grid");

    cfg.setFileSystemConfiguration(igfsCfg);

    Ignite g = G.start(cfg);

    igfs = g.fileSystem("igfs");
}
 
Example 8
Source File: HadoopIgfsDualAbstractSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
    chunk = new byte[128];

    for (int i = 0; i < chunk.length; i++)
        chunk[i] = (byte)i;

    Ignite igniteSecondary = startGridWithIgfs("grid-secondary", "igfs-secondary", PRIMARY, null, SECONDARY_REST_CFG);

    IgfsSecondaryFileSystem hadoopFs = new IgniteHadoopIgfsSecondaryFileSystem(SECONDARY_URI, SECONDARY_CFG);

    Ignite ignite = startGridWithIgfs("grid", "igfs", mode, hadoopFs, PRIMARY_REST_CFG);

    igfsSecondary = (IgfsImpl) igniteSecondary.fileSystem("igfs-secondary");
    igfs = (IgfsImpl) ignite.fileSystem("igfs");
}
 
Example 9
Source File: IgfsMetricsSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Start a grid with the secondary file system.
 *
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
private void startSecondary() throws Exception {
    FileSystemConfiguration igfsCfg = new FileSystemConfiguration();

    igfsCfg.setName(IGFS_SECONDARY);
    igfsCfg.setBlockSize(SECONDARY_BLOCK_SIZE);
    igfsCfg.setDefaultMode(PRIMARY);
    igfsCfg.setIpcEndpointConfiguration(SECONDARY_REST_CFG);

    CacheConfiguration dataCacheCfg = defaultCacheConfiguration();

    dataCacheCfg.setCacheMode(PARTITIONED);
    dataCacheCfg.setNearConfiguration(null);
    dataCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    dataCacheCfg.setAffinityMapper(new IgfsGroupDataBlocksKeyMapper(128));
    dataCacheCfg.setBackups(0);
    dataCacheCfg.setAtomicityMode(TRANSACTIONAL);

    CacheConfiguration metaCacheCfg = defaultCacheConfiguration();

    metaCacheCfg.setCacheMode(REPLICATED);
    metaCacheCfg.setNearConfiguration(null);
    metaCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    metaCacheCfg.setAtomicityMode(TRANSACTIONAL);

    igfsCfg.setMetaCacheConfiguration(metaCacheCfg);
    igfsCfg.setDataCacheConfiguration(dataCacheCfg);

    IgniteConfiguration cfg = new IgniteConfiguration();

    cfg.setIgniteInstanceName("grid-secondary");

    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();

    discoSpi.setIpFinder(new TcpDiscoveryVmIpFinder(true));

    cfg.setDiscoverySpi(discoSpi);
    cfg.setFileSystemConfiguration(igfsCfg);

    cfg.setLocalHost("127.0.0.1");

    Ignite g = G.start(cfg);

    igfsSecondary = (IgfsImpl)g.fileSystem(IGFS_SECONDARY);
}
 
Example 10
Source File: IgfsCachePerBlockLruEvictionPolicySelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Start a grid with the primary file system.
 *
 * @throws Exception If failed.
 */
private void startPrimary() throws Exception {
    FileSystemConfiguration igfsCfg = new FileSystemConfiguration();

    igfsCfg.setName(IGFS_PRIMARY);
    igfsCfg.setBlockSize(512);
    igfsCfg.setDefaultMode(DUAL_SYNC);
    igfsCfg.setPrefetchBlocks(1);
    igfsCfg.setSequentialReadsBeforePrefetch(Integer.MAX_VALUE);
    igfsCfg.setSecondaryFileSystem(secondaryFs.asSecondary());

    Map<String, IgfsMode> pathModes = new HashMap<>();

    pathModes.put(FILE.toString(), PRIMARY);

    igfsCfg.setPathModes(pathModes);

    CacheConfiguration dataCacheCfg = defaultCacheConfiguration();

    dataCacheCfg.setCacheMode(PARTITIONED);
    dataCacheCfg.setNearConfiguration(null);
    dataCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    dataCacheCfg.setAtomicityMode(TRANSACTIONAL);

    evictPlc = new IgfsPerBlockLruEvictionPolicy();

    dataCacheCfg.setEvictionPolicy(evictPlc);
    dataCacheCfg.setOnheapCacheEnabled(true);
    dataCacheCfg.setAffinityMapper(new IgfsGroupDataBlocksKeyMapper(128));
    dataCacheCfg.setBackups(0);

    CacheConfiguration metaCacheCfg = defaultCacheConfiguration();

    metaCacheCfg.setCacheMode(REPLICATED);
    metaCacheCfg.setNearConfiguration(null);
    metaCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    metaCacheCfg.setAtomicityMode(TRANSACTIONAL);

    igfsCfg.setMetaCacheConfiguration(metaCacheCfg);
    igfsCfg.setDataCacheConfiguration(dataCacheCfg);

    IgniteConfiguration cfg = new IgniteConfiguration();

    cfg.setIgniteInstanceName("grid-primary");

    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();

    discoSpi.setIpFinder(new TcpDiscoveryVmIpFinder(true));

    cfg.setDiscoverySpi(discoSpi);
    cfg.setFileSystemConfiguration(igfsCfg);

    cfg.setLocalHost("127.0.0.1");
    cfg.setConnectorConfiguration(null);

    Ignite g = G.start(cfg);

    igfsPrimary = (IgfsImpl)g.fileSystem(IGFS_PRIMARY);

    dataCache = igfsPrimary.context().kernalContext().cache().internalCache(
        igfsPrimary.context().configuration().getDataCacheConfiguration().getName());
}
 
Example 11
Source File: IgfsCachePerBlockLruEvictionPolicySelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Start a grid with the secondary file system.
 *
 * @throws Exception If failed.
 */
private void startSecondary() throws Exception {
    FileSystemConfiguration igfsCfg = new FileSystemConfiguration();

    igfsCfg.setName(IGFS_SECONDARY);
    igfsCfg.setBlockSize(512);
    igfsCfg.setDefaultMode(PRIMARY);
    igfsCfg.setIpcEndpointConfiguration(SECONDARY_REST_CFG);

    CacheConfiguration dataCacheCfg = defaultCacheConfiguration();

    dataCacheCfg.setCacheMode(PARTITIONED);
    dataCacheCfg.setNearConfiguration(null);
    dataCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    dataCacheCfg.setAffinityMapper(new IgfsGroupDataBlocksKeyMapper(128));
    dataCacheCfg.setBackups(0);
    dataCacheCfg.setAtomicityMode(TRANSACTIONAL);

    CacheConfiguration metaCacheCfg = defaultCacheConfiguration();

    metaCacheCfg.setCacheMode(REPLICATED);
    metaCacheCfg.setNearConfiguration(null);
    metaCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    metaCacheCfg.setAtomicityMode(TRANSACTIONAL);

    igfsCfg.setMetaCacheConfiguration(metaCacheCfg);
    igfsCfg.setDataCacheConfiguration(dataCacheCfg);

    IgniteConfiguration cfg = new IgniteConfiguration();

    cfg.setIgniteInstanceName("grid-secondary");

    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();

    discoSpi.setIpFinder(new TcpDiscoveryVmIpFinder(true));

    cfg.setDiscoverySpi(discoSpi);
    cfg.setFileSystemConfiguration(igfsCfg);

    cfg.setLocalHost("127.0.0.1");
    cfg.setConnectorConfiguration(null);

    Ignite g = G.start(cfg);

    secondaryFs = (IgfsImpl)g.fileSystem(IGFS_SECONDARY);
}
 
Example 12
Source File: IgfsStartCacheTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testCacheStart() throws Exception {
    Ignite g0 = G.start(config(true, 0));

    String dataCacheName = ((IgniteEx)g0).igfsx("igfs").configuration().getDataCacheConfiguration().getName();
    String metaCacheName = ((IgniteEx)g0).igfsx("igfs").configuration().getMetaCacheConfiguration().getName();

    checkIgfsCaches(g0, dataCacheName, metaCacheName);

    Ignite g1 = G.start(config(false, 1));

    checkIgfsCaches(g1, dataCacheName, metaCacheName);

    IgniteFileSystem igfs = g0.fileSystem("igfs");

    igfs.mkdirs(new IgfsPath("/test"));

    try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(igfs.create(
        new IgfsPath("/test/test.file"), true)))) {

        for (int i = 0; i < 1000; i++)
            bw.write("test-" + i);
    }
}
 
Example 13
Source File: IgfsExample.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Executes example.
 *
 * @param args Command line arguments, none required.
 * @throws Exception If example execution failed.
 */
public static void main(String[] args) throws Exception {
    Ignite ignite = Ignition.start("examples/config/filesystem/example-igfs.xml");

    System.out.println();
    System.out.println(">>> IGFS example started.");

    try {
        // Get an instance of Ignite File System.
        IgniteFileSystem fs = ignite.fileSystem("igfs");

        // Working directory path.
        IgfsPath workDir = new IgfsPath("/examples/fs");

        // Cleanup working directory.
        delete(fs, workDir);

        // Create empty working directory.
        mkdirs(fs, workDir);

        // Print information for working directory.
        printInfo(fs, workDir);

        // File path.
        IgfsPath filePath = new IgfsPath(workDir, "file.txt");

        // Create file.
        create(fs, filePath, new byte[] {1, 2, 3});

        // Print information for file.
        printInfo(fs, filePath);

        // Append more data to previously created file.
        append(fs, filePath, new byte[] {4, 5});

        // Print information for file.
        printInfo(fs, filePath);

        // Read data from file.
        read(fs, filePath);

        // Delete file.
        delete(fs, filePath);

        // Print information for file.
        printInfo(fs, filePath);

        // Create several files.
        for (int i = 0; i < 5; i++)
            create(fs, new IgfsPath(workDir, "file-" + i + ".txt"), null);

        list(fs, workDir);
    }
    finally {
        Ignition.stop(false);
    }
}
 
Example 14
Source File: IgniteHadoopFileSystemLoggerStateSelfTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Startup the grid and instantiate the file system.
 *
 * @throws Exception If failed.
 */
private void startUp() throws Exception {
    FileSystemConfiguration igfsCfg = new FileSystemConfiguration();

    igfsCfg.setName("igfs");
    igfsCfg.setBlockSize(512 * 1024);
    igfsCfg.setDefaultMode(PRIMARY);

    IgfsIpcEndpointConfiguration endpointCfg = new IgfsIpcEndpointConfiguration();

    endpointCfg.setType(IgfsIpcEndpointType.TCP);
    endpointCfg.setPort(10500);

    igfsCfg.setIpcEndpointConfiguration(endpointCfg);

    CacheConfiguration dataCacheCfg = defaultCacheConfiguration();

    dataCacheCfg.setName("partitioned");
    dataCacheCfg.setCacheMode(PARTITIONED);
    dataCacheCfg.setNearConfiguration(null);
    dataCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    dataCacheCfg.setAffinityMapper(new IgfsGroupDataBlocksKeyMapper(128));
    dataCacheCfg.setBackups(0);
    dataCacheCfg.setAtomicityMode(TRANSACTIONAL);

    CacheConfiguration metaCacheCfg = defaultCacheConfiguration();

    metaCacheCfg.setName("replicated");
    metaCacheCfg.setCacheMode(REPLICATED);
    metaCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    metaCacheCfg.setAtomicityMode(TRANSACTIONAL);

    igfsCfg.setDataCacheConfiguration(dataCacheCfg);
    igfsCfg.setMetaCacheConfiguration(metaCacheCfg);

    IgniteConfiguration cfg = new IgniteConfiguration();

    cfg.setIgniteInstanceName("igfs-grid");

    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();

    discoSpi.setIpFinder(new TcpDiscoveryVmIpFinder(true));

    cfg.setDiscoverySpi(discoSpi);
    cfg.setFileSystemConfiguration(igfsCfg);

    cfg.setLocalHost("127.0.0.1");
    cfg.setConnectorConfiguration(null);

    Ignite g = G.start(cfg);

    igfs = (IgfsEx)g.fileSystem("igfs");

    igfs.globalSampling(sampling);

    fs = fileSystem();
}