Search in sources :

Example 1 with AtmosResult

use of org.apache.camel.component.atmos.dto.AtmosResult in project camel by apache.

the class AtmosAPIFacade method del.

/**
     * Delete every files and subdirectories inside the remote directory. In
     * case the remotePath is a file, delete the file.
     *
     * @param remotePath the remote location to delete
     * @return a AtmosResult object with the result of the delete operation.
     * @throws AtmosException
     */
public AtmosResult del(String remotePath) throws AtmosException {
    AtmosResult result = null;
    ObjectPath op = new ObjectPath(remotePath);
    AtmosAPIFacade.client.delete(op);
    result = new AtmosDelResult();
    result.setResultEntries(remotePath);
    return result;
}
Also used : ObjectPath(com.emc.atmos.api.ObjectPath) AtmosResult(org.apache.camel.component.atmos.dto.AtmosResult) AtmosDelResult(org.apache.camel.component.atmos.dto.AtmosDelResult)

Example 2 with AtmosResult

use of org.apache.camel.component.atmos.dto.AtmosResult in project camel by apache.

the class AtmosMoveProducer method process.

@Override
public void process(Exchange exchange) throws Exception {
    AtmosResult result = AtmosAPIFacade.getInstance(configuration.getClient()).move(configuration.getRemotePath(), configuration.getNewRemotePath());
    result.populateExchange(exchange);
}
Also used : AtmosResult(org.apache.camel.component.atmos.dto.AtmosResult)

Example 3 with AtmosResult

use of org.apache.camel.component.atmos.dto.AtmosResult in project camel by apache.

the class AtmosAPIFacade method put.

/**
     * Put or upload a new file or an entire directory to atmos
     *
     * @param localPath the file path or the dir path on the local filesystem
     * @param remotePath the remote path destination on atmos
     * the file already existing with the same name
     * will be overridden.
     * @return a AtmosResult object reporting for each remote path the result of
     * the operation.
     * @throws AtmosException
     */
public AtmosResult put(String localPath, String remotePath) throws AtmosException {
    AtmosResult result = new AtmosFileUploadResult();
    //a map representing for each path the result of the put operation
    Map<String, AtmosResultCode> resultEntries = null;
    //in case the remote path is not specified, the remotePath = localPath
    String atmosPath = remotePath == null ? localPath : remotePath;
    if (!atmosPath.endsWith(ATMOS_FILE_SEPARATOR)) {
        atmosPath += ATMOS_FILE_SEPARATOR;
    }
    ObjectPath atmosEntry = new ObjectPath(atmosPath);
    if (!atmosPath.equals(ATMOS_FILE_SEPARATOR)) {
        if (AtmosAPIFacade.client.getSystemMetadata(atmosEntry) == null) {
            throw new AtmosException(atmosPath + " does not exist or cannot obtain metadata");
        }
    }
    File fileLocalPath = new File(localPath);
    //verify uploading of a single file
    if (fileLocalPath.isFile()) {
        //check if atmos file exists
        if (atmosEntry != null && !atmosEntry.isDirectory()) {
            throw new AtmosException(atmosPath + " exists on atmos and is not a folder!");
        }
        atmosPath = atmosPath + fileLocalPath.getName();
        resultEntries = new HashMap<String, AtmosResultCode>(1);
        try {
            ObjectId uploadedFile = putSingleFile(fileLocalPath, atmosPath);
            if (uploadedFile == null) {
                resultEntries.put(atmosPath, AtmosResultCode.KO);
            } else {
                resultEntries.put(atmosPath, AtmosResultCode.OK);
            }
        } catch (Exception ex) {
            resultEntries.put(atmosPath, AtmosResultCode.KO);
        } finally {
            result.setResultEntries(resultEntries);
        }
        return result;
    } else {
        //verify uploading of a list of files inside a dir
        LOG.info("uploading a dir...");
        //check if atmos folder exists
        if (atmosEntry != null && !atmosEntry.isDirectory()) {
            throw new AtmosException(atmosPath + " exists on atmos and is not a folder!");
        }
        //revert to old path
        String oldAtmosPath = atmosPath;
        //list all files in a dir
        Collection<File> listFiles = FileUtils.listFiles(fileLocalPath, null, true);
        if (listFiles == null || listFiles.isEmpty()) {
            throw new AtmosException(localPath + " does not contain any files");
        }
        resultEntries = new HashMap<String, AtmosResultCode>(listFiles.size());
        for (File file : listFiles) {
            String absPath = file.getAbsolutePath();
            int indexRemainingPath = localPath.length();
            if (!localPath.endsWith("/")) {
                indexRemainingPath += 1;
            }
            String remainingPath = absPath.substring(indexRemainingPath);
            atmosPath = atmosPath + remainingPath;
            try {
                LOG.debug("uploading: {} to {}", fileLocalPath, atmosPath);
                ObjectId uploadedFile = putSingleFile(file, atmosPath);
                if (uploadedFile == null) {
                    resultEntries.put(atmosPath, AtmosResultCode.KO);
                } else {
                    resultEntries.put(atmosPath, AtmosResultCode.OK);
                }
            } catch (Exception ex) {
                resultEntries.put(atmosPath, AtmosResultCode.KO);
            }
            atmosPath = oldAtmosPath;
        }
        result.setResultEntries(resultEntries);
        return result;
    }
}
Also used : ObjectPath(com.emc.atmos.api.ObjectPath) ObjectId(com.emc.atmos.api.ObjectId) AtmosResult(org.apache.camel.component.atmos.dto.AtmosResult) AtmosFileUploadResult(org.apache.camel.component.atmos.dto.AtmosFileUploadResult) AtmosException(org.apache.camel.component.atmos.util.AtmosException) IOException(java.io.IOException) AtmosException(org.apache.camel.component.atmos.util.AtmosException) File(java.io.File) AtmosResultCode(org.apache.camel.component.atmos.util.AtmosResultCode)

Example 4 with AtmosResult

use of org.apache.camel.component.atmos.dto.AtmosResult in project camel by apache.

the class AtmosAPIFacade method move.

/**
     * Rename a remote path with the new path location.
     *
     * @param remotePath the existing remote path to be renamed
     * @param newRemotePath the new remote path substituting the old one
     * @return a AtmosResult object with the result of the move operation.
     * @throws AtmosException
     */
public AtmosResult move(String remotePath, String newRemotePath) throws AtmosException {
    AtmosResult result = null;
    AtmosAPIFacade.client.move(new ObjectPath(remotePath), new ObjectPath(newRemotePath), true);
    result = new AtmosMoveResult();
    result.setResultEntries(remotePath + "-" + newRemotePath);
    return result;
}
Also used : ObjectPath(com.emc.atmos.api.ObjectPath) AtmosMoveResult(org.apache.camel.component.atmos.dto.AtmosMoveResult) AtmosResult(org.apache.camel.component.atmos.dto.AtmosResult)

Example 5 with AtmosResult

use of org.apache.camel.component.atmos.dto.AtmosResult in project camel by apache.

the class AtmosAPIFacade method get.

/**
     * Get the content of every file inside the remote path.
     *
     * @param remotePath the remote path where to download from
     * @return a AtmosResult object with the content (ByteArrayOutputStream) of
     * every files inside the remote path.
     * @throws AtmosException
     */
public AtmosResult get(String remotePath) throws AtmosException {
    AtmosResult result = new AtmosFileDownloadResult();
    //a map representing for each path the result of the baos
    Map<String, ByteArrayOutputStream> resultEntries = new HashMap<String, ByteArrayOutputStream>();
    //iterate from the remotePath
    downloadFilesInFolder(remotePath, resultEntries);
    //put the map of baos as result
    result.setResultEntries(resultEntries);
    return result;
}
Also used : AtmosFileDownloadResult(org.apache.camel.component.atmos.dto.AtmosFileDownloadResult) HashMap(java.util.HashMap) AtmosResult(org.apache.camel.component.atmos.dto.AtmosResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

AtmosResult (org.apache.camel.component.atmos.dto.AtmosResult)9 ObjectPath (com.emc.atmos.api.ObjectPath)3 ObjectId (com.emc.atmos.api.ObjectId)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Exchange (org.apache.camel.Exchange)1 AtmosDelResult (org.apache.camel.component.atmos.dto.AtmosDelResult)1 AtmosFileDownloadResult (org.apache.camel.component.atmos.dto.AtmosFileDownloadResult)1 AtmosFileUploadResult (org.apache.camel.component.atmos.dto.AtmosFileUploadResult)1 AtmosMoveResult (org.apache.camel.component.atmos.dto.AtmosMoveResult)1 AtmosException (org.apache.camel.component.atmos.util.AtmosException)1 AtmosResultCode (org.apache.camel.component.atmos.util.AtmosResultCode)1