/** {@inheritDoc} */ @Override public IgfsHandshakeResponse handshake(final String logDir) { return IgfsUserContext.doAs(user, new IgniteOutClosure<IgfsHandshakeResponse>() { @Override public IgfsHandshakeResponse apply() { igfs.clientLogDirectory(logDir); return new IgfsHandshakeResponse(igfs.name(), igfs.groupBlockSize(), igfs.globalSampling()); } }); }
/** * Get info for the given path. * * @param path Path. * @return Info. * @throws IgniteCheckedException If failed. */ @Nullable public IgfsEntryInfo infoForPath(IgfsPath path) throws IgniteCheckedException { return client ? runClientTask(new IgfsClientMetaInfoForPathCallable(cfg.getName(), IgfsUserContext.currentUser(), path)) : info(fileId(path)); }
/** * Gets owner of a secondary Fs path. * @param secFs The sec Fs. * @param p The path. * @return The owner. */ private static String getOwnerSecondary(final IgfsSecondaryFileSystem secFs, final IgfsPath p) { return IgfsUserContext.doAs(USER, new IgniteOutClosure<String>() { @Override public String apply() { return secFs.info(p).property(IgfsUtils.PROP_USER_NAME); } }); }
/** * Get IDs for the given path. * * @param path Path. * @return IDs. * @throws IgniteCheckedException If failed. */ public List<IgniteUuid> idsForPath(IgfsPath path) throws IgniteCheckedException { return client ? runClientTask(new IgfsClientMetaIdsForPathCallable(cfg.getName(), IgfsUserContext.currentUser(), path)) : fileIds(path); }
/** {@inheritDoc} */ @Override public IgfsModeResolver modeResolver() throws IgniteCheckedException { try { return IgfsUserContext.doAs(user, new IgniteOutClosure<IgfsModeResolver>() { @Override public IgfsModeResolver apply() { return ((IgfsImpl)igfs).modeResolver(); } }); } catch (IllegalStateException ignored) { throw new HadoopIgfsCommunicationException("Failed to get mode resolver because Grid is stopping"); } } }
/** {@inheritDoc} */ @Override @Nullable public IgfsFile info(final IgfsPath path) { A.notNull(path, "path"); if (meta.isClient()) return meta.runClientTask(new IgfsClientInfoCallable(cfg.getName(), IgfsUserContext.currentUser(), path)); return safeOp(new Callable<IgfsFile>() { @Override public IgfsFile call() throws Exception { if (log.isDebugEnabled()) log.debug("Get file info: " + path); IgfsMode mode = resolveMode(path); return resolveFileInfo(path, mode); } }); }
/** * Gets owner of a IgfsEx path. * @param p The path. * @return The owner. */ private static String getOwner(final IgfsEx i, final IgfsPath p) { return IgfsUserContext.doAs(USER, new IgniteOutClosure<String>() { @Override public String apply() { IgfsFile f = i.info(p); assert f != null; return f.property(IgfsUtils.PROP_USER_NAME); } }); }
/** {@inheritDoc} */ @Override public long size(final IgfsPath path) { A.notNull(path, "path"); if (meta.isClient()) return meta.runClientTask(new IgfsClientSizeCallable(cfg.getName(), IgfsUserContext.currentUser(), path)); return safeOp(new Callable<Long>() { @Override public Long call() throws Exception { return summary0(path).totalLength(); } }); }
/** {@inheritDoc} */ @Override public IgfsStatus fsStatus() throws IgniteCheckedException { try { return IgfsUserContext.doAs(user, new Callable<IgfsStatus>() { @Override public IgfsStatus call() throws IgniteCheckedException { return igfs.globalSpace(); } }); } catch (IllegalStateException ignored) { throw new HadoopIgfsCommunicationException("Failed to get file system status because Grid is stopping."); } catch (IgniteCheckedException | RuntimeException | Error e) { throw e; } catch (Exception ignored) { throw new AssertionError("Must never go there."); } }
runClientTask(new IgfsClientMetaUnlockCallable(cfg.getName(), IgfsUserContext.currentUser(), fileId, lockId, modificationTime, updateSpace, space, affRange));
/** {@inheritDoc} */ @Override public HadoopIgfsStreamDelegate append(final IgfsPath path, final boolean create, @Nullable final Map<String, String> props) throws IgniteCheckedException { try { return IgfsUserContext.doAs(user, new IgniteOutClosure<HadoopIgfsStreamDelegate>() { @Override public HadoopIgfsStreamDelegate apply() { IgfsOutputStream stream = igfs.append(path, bufSize, create, props); return new HadoopIgfsStreamDelegate(HadoopIgfsInProc.this, stream); } }); } catch (IgniteException e) { throw new IgniteCheckedException(e); } catch (IllegalStateException ignored) { throw new HadoopIgfsCommunicationException("Failed to append file because Grid is stopping: " + path); } }
/** * Gets the FileSystem for the current context user. * @return the FileSystem instance, never null. */ private FileSystem fileSystemForUser() { String user = IgfsUserContext.currentUser(); if (F.isEmpty(user)) user = IgfsUtils.fixUserName(dfltUsrName); assert !F.isEmpty(user); try { return (FileSystem)factory.get(user); } catch (IOException ioe) { throw new IgniteException(ioe); } }
/** {@inheritDoc} */ @Override public IgfsFile info(final IgfsPath path) throws IgniteCheckedException { try { return IgfsUserContext.doAs(user, new IgniteOutClosure<IgfsFile>() { @Override public IgfsFile apply() { return igfs.info(path); } }); } catch (IgniteException e) { throw new IgniteCheckedException(e); } catch (IllegalStateException ignored) { throw new HadoopIgfsCommunicationException("Failed to get file info because Grid is stopping: " + path); } }
/** {@inheritDoc} */ @Override public void mkdirs(final IgfsPath path, @Nullable final Map<String, String> props) { A.notNull(path, "path"); if (meta.isClient()) { meta.runClientTask(new IgfsClientMkdirsCallable(cfg.getName(), IgfsUserContext.currentUser(), path, props)); return ; } safeOp(new Callable<Void>() { @Override public Void call() throws Exception { if (log.isDebugEnabled()) log.debug("Make directories: " + path); IgfsMode mode = resolveMode(path); switch (mode) { case PRIMARY: meta.mkdirs(path, props == null ? DFLT_DIR_META : new HashMap<>(props)); break; case DUAL_ASYNC: case DUAL_SYNC: await(path); meta.mkdirsDual(secondaryFs, path, props); break; case PROXY: secondaryFs.mkdirs(path, props); break; } return null; } }); }
/** {@inheritDoc} */ @Override public HadoopIgfsStreamDelegate create(final IgfsPath path, final boolean overwrite, final boolean colocate, final int replication, final long blockSize, @Nullable final Map<String, String> props) throws IgniteCheckedException { try { return IgfsUserContext.doAs(user, new IgniteOutClosure<HadoopIgfsStreamDelegate>() { @Override public HadoopIgfsStreamDelegate apply() { IgfsOutputStream stream = igfs.create(path, bufSize, overwrite, colocate ? igfs.nextAffinityKey() : null, replication, blockSize, props); return new HadoopIgfsStreamDelegate(HadoopIgfsInProc.this, stream); } }); } catch (IgniteException e) { throw new IgniteCheckedException(e); } catch (IllegalStateException ignored) { throw new HadoopIgfsCommunicationException("Failed to findIgfsAndCreate file because Grid is stopping: " + path); } }
/** {@inheritDoc} */ @Override public IgfsPathSummary summary(final IgfsPath path) { A.notNull(path, "path"); if (meta.isClient()) return meta.runClientTask(new IgfsClientSummaryCallable(cfg.getName(), IgfsUserContext.currentUser(), path)); return safeOp(new Callable<IgfsPathSummary>() { @Override public IgfsPathSummary call() throws Exception { if (log.isDebugEnabled()) log.debug("Calculating path summary: " + path); return summary0(path); } }); }
/** {@inheritDoc} */ @Override public Collection<IgfsPath> listPaths(final IgfsPath path) throws IgniteCheckedException { try { return IgfsUserContext.doAs(user, new IgniteOutClosure<Collection<IgfsPath>>() { @Override public Collection<IgfsPath> apply() { return igfs.listPaths(path); } }); } catch (IgniteException e) { throw new IgniteCheckedException(e); } catch (IllegalStateException ignored) { throw new HadoopIgfsCommunicationException("Failed to list paths because Grid is stopping: " + path); } }
IgfsUserContext.currentUser(), path));
/** {@inheritDoc} */ @Override public Collection<IgfsFile> listFiles(final IgfsPath path) throws IgniteCheckedException { try { return IgfsUserContext.doAs(user, new IgniteOutClosure<Collection<IgfsFile>>() { @Override public Collection<IgfsFile> apply() { return igfs.listFiles(path); } }); } catch (IgniteException e) { throw new IgniteCheckedException(e); } catch (IllegalStateException ignored) { throw new HadoopIgfsCommunicationException("Failed to list files because Grid is stopping: " + path); } }
/** {@inheritDoc} */ @Override public void setTimes(final IgfsPath path, final long modificationTime, final long accessTime) { A.notNull(path, "path"); if (accessTime == -1 && modificationTime == -1) return; if (meta.isClient()) { meta.runClientTask(new IgfsClientSetTimesCallable(cfg.getName(), IgfsUserContext.currentUser(), path, accessTime, modificationTime)); return; } safeOp(new Callable<Void>() { @Override public Void call() throws Exception { IgfsMode mode = resolveMode(path); if (mode == PROXY) secondaryFs.setTimes(path, modificationTime, accessTime); else { meta.updateTimes(path, modificationTime, accessTime, IgfsUtils.isDualMode(mode) ? secondaryFs : null); } return null; } }); }