Search in sources :

Example 11 with FileSystemException

use of org.apache.commons.vfs2.FileSystemException in project scheduling by ow2-proactive.

the class SmartProxyImpl method createFolder.

@Override
protected void createFolder(String fUri) throws NotConnectedException, PermissionException {
    FileObject fo = null;
    try {
        fo = jobTracker.resolveFile(fUri);
        fo.createFolder();
    } catch (FileSystemException e) {
        log.error("Error while creating folder: " + fo, e);
    }
    log.debug("Created remote folder: " + fUri);
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) FileObject(org.apache.commons.vfs2.FileObject)

Example 12 with FileSystemException

use of org.apache.commons.vfs2.FileSystemException in project scheduling by ow2-proactive.

the class SmartProxyImpl method downloadTaskOutputFiles.

@Override
protected void downloadTaskOutputFiles(AwaitedJob awaitedjob, String jobId, String t_name, String localFolder) throws Exception {
    AwaitedTask atask = awaitedjob.getAwaitedTask(t_name);
    if (atask == null) {
        throw new IllegalArgumentException("The task " + t_name + " does not belong to job " + jobId + " or has already been removed");
    }
    if (atask.isTransferring()) {
        log.warn("The task " + t_name + " of job " + jobId + " is already transferring its output");
        return;
    }
    String pull_URL = awaitedjob.getPullURL();
    if (awaitedjob.isIsolateTaskOutputs()) {
        pull_URL = pull_URL.replace(SchedulerConstants.TASKID_DIR_DEFAULT_NAME, SchedulerConstants.TASKID_DIR_DEFAULT_NAME + "/" + atask.getTaskId());
    }
    FileObject remotePullFolderFO;
    FileObject localfolderFO;
    try {
        remotePullFolderFO = jobTracker.resolveFile(pull_URL);
        localfolderFO = jobTracker.resolveFile(localFolder);
    } catch (FileSystemException e) {
        log.error("Could not retrieve data for job " + jobId, e);
        throw new IllegalStateException("Could not retrieve data for job " + jobId, e);
    }
    String sourceUrl = remotePullFolderFO.getURL().toString();
    String destUrl = localfolderFO.getURL().toString();
    org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector fileSelector = new org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector();
    List<OutputSelector> ouputFileSelectors = atask.getOutputSelectors();
    for (OutputSelector os : ouputFileSelectors) {
        org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector fs = os.getOutputFiles();
        if (!fs.getIncludes().isEmpty()) {
            fileSelector.addIncludes(fs.getIncludes());
        }
        if (!fs.getExcludes().isEmpty()) {
            fileSelector.addExcludes(fs.getExcludes());
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Looking at files in " + sourceUrl + " with " + fileSelector.getIncludes() + "-" + fileSelector.getExcludes());
        boolean goon = true;
        int cpt = 0;
        FileObject[] fos = null;
        while (goon) {
            fos = remotePullFolderFO.findFiles(fileSelector);
            goon = cpt < 50 && (fos == null || fos.length == 0);
            cpt++;
            if (goon) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            }
        }
        if (fos != null && fos.length > 0) {
            for (FileObject fo : fos) {
                log.debug("Found " + fo.getName());
            }
        } else {
            log.warn("Couldn't find " + fileSelector.getIncludes() + "-" + fileSelector.getExcludes() + " in " + sourceUrl);
        }
    }
    if (awaitedjob.isAutomaticTransfer()) {
        DataTransferProcessor dtp = new DataTransferProcessor(remotePullFolderFO, localfolderFO, jobId, t_name, fileSelector);
        jobTracker.setTaskTransferring(jobId, t_name, true);
        threadPool.submit((Runnable) dtp);
    } else {
        log.debug("Copying files from " + sourceUrl + " to " + destUrl);
        try {
            localfolderFO.copyFrom(remotePullFolderFO, fileSelector);
        } catch (FileSystemException e) {
            log.error(e);
            throw e;
        } finally {
            jobTracker.setTaskTransferring(jobId, t_name, false);
        }
        // task is removed from the job tracker only if the transfer is successful
        jobTracker.removeAwaitedTask(jobId, t_name);
        log.debug("Finished copying files from " + sourceUrl + " to " + destUrl);
    // ok we can remove the task
    }
}
Also used : FileSelector(org.apache.commons.vfs2.FileSelector) AwaitedTask(org.ow2.proactive.scheduler.smartproxy.common.AwaitedTask) FileSystemException(org.apache.commons.vfs2.FileSystemException) OutputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.OutputSelector) FileObject(org.apache.commons.vfs2.FileObject)

Example 13 with FileSystemException

use of org.apache.commons.vfs2.FileSystemException in project zeppelin by apache.

the class NotebookServer method createNote.

private void createNote(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message message) throws IOException {
    AuthenticationInfo subject = new AuthenticationInfo(message.principal);
    try {
        Note note = null;
        String defaultInterpreterId = (String) message.get("defaultInterpreterId");
        if (!StringUtils.isEmpty(defaultInterpreterId)) {
            List<String> interpreterSettingIds = new LinkedList<>();
            interpreterSettingIds.add(defaultInterpreterId);
            for (String interpreterSettingId : notebook.getInterpreterSettingManager().getDefaultInterpreterSettingList()) {
                if (!interpreterSettingId.equals(defaultInterpreterId)) {
                    interpreterSettingIds.add(interpreterSettingId);
                }
            }
            note = notebook.createNote(interpreterSettingIds, subject);
        } else {
            note = notebook.createNote(subject);
        }
        // it's an empty note. so add one paragraph
        note.addParagraph(subject);
        if (message != null) {
            String noteName = (String) message.get("name");
            if (StringUtils.isEmpty(noteName)) {
                noteName = "Note " + note.getId();
            }
            note.setName(noteName);
        }
        note.persist(subject);
        addConnectionToNote(note.getId(), (NotebookSocket) conn);
        conn.send(serializeMessage(new Message(OP.NEW_NOTE).put("note", note)));
    } catch (FileSystemException e) {
        LOG.error("Exception from createNote", e);
        conn.send(serializeMessage(new Message(OP.ERROR_INFO).put("info", "Oops! There is something wrong with the notebook file system. " + "Please check the logs for more details.")));
        return;
    }
    broadcastNoteList(subject, userAndRoles);
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) LinkedList(java.util.LinkedList)

Example 14 with FileSystemException

use of org.apache.commons.vfs2.FileSystemException in project jackrabbit by apache.

the class VFSBackend method getTouchFileObject.

/**
     * Returns the touch file for the fileObject.
     * If there's no corresponding touch file existing, then returns null when {@code create} is false.
     * When {@code create} is true, it creates a new touch file if no corresponding touch file exists.
     *
     * @param fileObject file object
     * @param create create a touch file if not existing
     * @return touch file object
     * @throws DataStoreException if any file system exception occurs
     */
protected FileObject getTouchFileObject(FileObject fileObject, boolean create) throws DataStoreException {
    try {
        FileObject folderObject = fileObject.getParent();
        String touchFileName = fileObject.getName().getBaseName() + TOUCH_FILE_NAME_SUFFIX;
        FileObject touchFileObject = folderObject.getChild(touchFileName);
        if (touchFileObject == null && create) {
            touchFileObject = folderObject.resolveFile(touchFileName);
            touchFileObject.createFile();
            touchFileObject = folderObject.getChild(touchFileName);
        }
        return touchFileObject;
    } catch (FileSystemException e) {
        throw new DataStoreException("Touch file object not resolved: " + fileObject.getName().getFriendlyURI(), e);
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) FileObject(org.apache.commons.vfs2.FileObject)

Example 15 with FileSystemException

use of org.apache.commons.vfs2.FileSystemException in project jackrabbit by apache.

the class VFSBackend method deleteOlderRecursive.

/**
     * Deletes any descendant record files under {@code folderObject} if the record files are older than {@code timestamp},
     * and push all the deleted record identifiers into {@code deleteIdSet}.
     * @param deleteIdSet set to store all the deleted record identifiers
     * @param folderObject folder object to start with
     * @param timestamp timestamp
     * @throws FileSystemException if any file system exception occurs
     * @throws DataStoreException if any file system exception occurs
     */
private void deleteOlderRecursive(Set<DataIdentifier> deleteIdSet, FileObject folderObject, long timestamp) throws FileSystemException, DataStoreException {
    FileType type;
    DataIdentifier identifier;
    for (FileObject fileObject : VFSUtils.getChildFileOrFolders(folderObject)) {
        type = fileObject.getType();
        if (type == FileType.FOLDER) {
            deleteOlderRecursive(deleteIdSet, fileObject, timestamp);
            synchronized (this) {
                if (!VFSUtils.hasAnyChildFileOrFolder(fileObject)) {
                    fileObject.delete();
                }
            }
        } else if (type == FileType.FILE) {
            long lastModified = getLastModifiedTime(fileObject);
            if (lastModified < timestamp) {
                identifier = new DataIdentifier(fileObject.getName().getBaseName());
                if (getDataStore().confirmDelete(identifier)) {
                    getDataStore().deleteFromCache(identifier);
                    if (LOG.isInfoEnabled()) {
                        LOG.info("Deleting old file " + fileObject.getName().getFriendlyURI() + " modified: " + new Timestamp(lastModified).toString() + " length: " + fileObject.getContent().getSize());
                    }
                    if (deleteRecordFileObject(fileObject)) {
                        deleteIdSet.add(identifier);
                    } else {
                        LOG.warn("Failed to delete old file " + fileObject.getName().getFriendlyURI());
                    }
                }
            }
        }
    }
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) FileType(org.apache.commons.vfs2.FileType) FileObject(org.apache.commons.vfs2.FileObject) Timestamp(java.sql.Timestamp)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)16 FileSystemException (org.apache.commons.vfs2.FileSystemException)16 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)8 RepositoryException (javax.jcr.RepositoryException)3 FileType (org.apache.commons.vfs2.FileType)3 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 FileSystemManager (org.apache.commons.vfs2.FileSystemManager)2 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)2 VFSClassLoader (org.apache.commons.vfs2.impl.VFSClassLoader)2 DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)2 File (java.io.File)1 IOException (java.io.IOException)1 Timestamp (java.sql.Timestamp)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 UniqueFileReplicator (org.apache.accumulo.start.classloader.vfs.UniqueFileReplicator)1 FileName (org.apache.commons.vfs2.FileName)1 FileSelector (org.apache.commons.vfs2.FileSelector)1