Search in sources :

Example 36 with IgfsOutputStream

use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.

the class IgfsAbstractSelfTest method testCreate.

/**
 * Test regular create.
 *
 * @throws Exception If failed.
 */
@SuppressWarnings({ "ConstantConditions", "EmptyTryBlock", "UnusedDeclaration" })
public void testCreate() throws Exception {
    create(igfs, paths(DIR, SUBDIR), null);
    createFile(igfs, FILE, true, chunk);
    checkFile(igfs, igfsSecondary, FILE, chunk);
    try (IgfsOutputStream os = igfs.create(new IgfsPath("/r"), false)) {
        checkExist(igfs, igfsSecondary, new IgfsPath("/r"));
        assert igfs.info(new IgfsPath("/r")).isFile();
    }
    try (IgfsOutputStream os = igfs.create(new IgfsPath("/k/l"), false)) {
        checkExist(igfs, igfsSecondary, new IgfsPath("/k/l"));
        assert igfs.info(new IgfsPath("/k/l")).isFile();
    }
    try {
        try (IgfsOutputStream os = igfs.create(new IgfsPath("/k/l"), false)) {
        }
        fail("Exception expected");
    } catch (IgniteException ignored) {
    // No-op.
    }
    checkExist(igfs, igfsSecondary, new IgfsPath("/k/l"));
    assert igfs.info(new IgfsPath("/k/l")).isFile();
    try {
        try (IgfsOutputStream os = igfs.create(new IgfsPath("/k/l/m"), true)) {
        }
        fail("Exception expected");
    } catch (IgniteException ignored) {
    // okay
    }
    checkNotExist(igfs, igfsSecondary, new IgfsPath("/k/l/m"));
    checkExist(igfs, igfsSecondary, new IgfsPath("/k/l"));
    assert igfs.info(new IgfsPath("/k/l")).isFile();
    try {
        try (IgfsOutputStream os = igfs.create(new IgfsPath("/k/l/m/n/o/p"), true)) {
        }
        fail("Exception expected");
    } catch (IgniteException ignored) {
    // okay
    }
    checkNotExist(igfs, igfsSecondary, new IgfsPath("/k/l/m"));
    checkExist(igfs, igfsSecondary, new IgfsPath("/k/l"));
    assert igfs.info(new IgfsPath("/k/l")).isFile();
    igfs.mkdirs(new IgfsPath("/x/y"), null);
    try {
        try (IgfsOutputStream os = igfs.create(new IgfsPath("/x/y"), true)) {
        }
        fail("Exception expected");
    } catch (IgniteException ignored) {
    // okay
    }
    checkExist(igfs, igfsSecondary, new IgfsPath("/x/y"));
    assert igfs.info(new IgfsPath("/x/y")).isDirectory();
    try (IgfsOutputStream os = igfs.create(new IgfsPath("/x/y/f"), false)) {
        assert igfs.info(new IgfsPath("/x/y/f")).isFile();
    }
    try (IgfsOutputStream os = igfs.create(new IgfsPath("/x/y/z/f"), false)) {
        assert igfs.info(new IgfsPath("/x/y/z/f")).isFile();
    }
    try (IgfsOutputStream os = igfs.create(new IgfsPath("/x/y/z/t/f"), false)) {
        assert igfs.info(new IgfsPath("/x/y/z/t/f")).isFile();
    }
    try (IgfsOutputStream os = igfs.create(new IgfsPath("/x/y/z/t/t2/t3/t4/t5/f"), false)) {
        assert igfs.info(new IgfsPath("/x/y/z/t/t2/t3/t4/t5/f")).isFile();
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgniteException(org.apache.ignite.IgniteException) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Example 37 with IgfsOutputStream

use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.

the class IgfsAbstractSelfTest method testCreateUpdateNoClose.

/**
 * Test update on the file when it was opened for write(create) and is not closed yet.
 *
 * @throws Exception If failed.
 */
public void testCreateUpdateNoClose() throws Exception {
    if (dual)
        return;
    if (!propertiesSupported())
        return;
    Map<String, String> props = properties("owner", "group", "0555");
    create(igfs, paths(DIR, SUBDIR), null);
    IgfsOutputStream os = null;
    try {
        os = igfs.create(FILE, true);
        igfs.update(FILE, props);
        os.close();
    } finally {
        U.closeQuiet(os);
    }
}
Also used : IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Example 38 with IgfsOutputStream

use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.

the class IgfsAbstractSelfTest method testAppendRenameParentNoClose.

/**
 * Test rename on the file parent when it was opened for write(append) and is not closed yet.
 *
 * @throws Exception If failed.
 */
public void testAppendRenameParentNoClose() throws Exception {
    if (dual)
        return;
    if (appendSupported()) {
        create(igfs, paths(DIR, SUBDIR), null);
        createFile(igfs, FILE, false);
        IgfsOutputStream os = null;
        try {
            os = igfs.append(FILE, false);
            igfs.rename(SUBDIR, SUBDIR2);
            os.close();
        } finally {
            U.closeQuiet(os);
        }
    }
}
Also used : IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Example 39 with IgfsOutputStream

use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.

the class HadoopExternalTaskExecutionSelfTest method prepareTestFile.

/**
 * @param filePath File path to prepare.
 * @throws Exception If failed.
 */
private void prepareTestFile(String filePath) throws Exception {
    IgniteFileSystem igfs = grid(0).fileSystem(igfsName);
    try (IgfsOutputStream out = igfs.create(new IgfsPath(filePath), true)) {
        PrintWriter wr = new PrintWriter(new OutputStreamWriter(out));
        for (int i = 0; i < 1000; i++) wr.println("Hello, world: " + i);
        wr.flush();
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgniteFileSystem(org.apache.ignite.IgniteFileSystem) OutputStreamWriter(java.io.OutputStreamWriter) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream) PrintWriter(java.io.PrintWriter)

Example 40 with IgfsOutputStream

use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.

the class HadoopIgfsInProc method writeData.

/**
 * {@inheritDoc}
 */
@Override
public void writeData(HadoopIgfsStreamDelegate delegate, byte[] data, int off, int len) throws IOException {
    try {
        IgfsOutputStream stream = delegate.target();
        stream.write(data, off, len);
    } catch (IllegalStateException | IOException e) {
        HadoopIgfsStreamEventListener lsnr = lsnrs.get(delegate);
        if (lsnr != null)
            lsnr.onError(e.getMessage());
        if (e instanceof IllegalStateException)
            throw new IOException("Failed to write data to IGFS stream because Grid is stopping.", e);
        else
            throw e;
    }
}
Also used : IOException(java.io.IOException) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Aggregations

IgfsOutputStream (org.apache.ignite.igfs.IgfsOutputStream)47 IgfsPath (org.apache.ignite.igfs.IgfsPath)25 IOException (java.io.IOException)14 IgniteException (org.apache.ignite.IgniteException)13 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 IgfsInputStream (org.apache.ignite.igfs.IgfsInputStream)8 IgniteUuid (org.apache.ignite.lang.IgniteUuid)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 IgniteFileSystem (org.apache.ignite.IgniteFileSystem)4 IgfsDirectoryNotEmptyException (org.apache.ignite.igfs.IgfsDirectoryNotEmptyException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 IgfsException (org.apache.ignite.igfs.IgfsException)3 IgfsMetrics (org.apache.ignite.igfs.IgfsMetrics)3 IgfsParentNotDirectoryException (org.apache.ignite.igfs.IgfsParentNotDirectoryException)3 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)3 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2