Search in sources :

Example 1 with AtmosException

use of org.apache.camel.component.atmos.util.AtmosException in project camel by apache.

the class AtmosEndpoint method createProducer.

/**
     * Create one of the camel producer available based on the configuration
     *
     * @return the camel producer
     * @throws Exception
     */
public Producer createProducer() throws Exception {
    LOG.debug("resolve producer atmos endpoint {" + configuration.getOperation().toString() + "}");
    LOG.debug("resolve producer atmos attached client: " + configuration.getClient());
    if (configuration.getOperation() == AtmosOperation.put) {
        return new AtmosPutProducer(this, configuration);
    } else if (this.configuration.getOperation() == AtmosOperation.del) {
        return new AtmosDelProducer(this, configuration);
    } else if (this.configuration.getOperation() == AtmosOperation.get) {
        return new AtmosGetProducer(this, configuration);
    } else if (this.configuration.getOperation() == AtmosOperation.move) {
        return new AtmosMoveProducer(this, configuration);
    } else {
        throw new AtmosException("operation specified is not valid for producer!");
    }
}
Also used : AtmosDelProducer(org.apache.camel.component.atmos.integration.producer.AtmosDelProducer) AtmosPutProducer(org.apache.camel.component.atmos.integration.producer.AtmosPutProducer) AtmosMoveProducer(org.apache.camel.component.atmos.integration.producer.AtmosMoveProducer) AtmosException(org.apache.camel.component.atmos.util.AtmosException) AtmosGetProducer(org.apache.camel.component.atmos.integration.producer.AtmosGetProducer)

Example 2 with AtmosException

use of org.apache.camel.component.atmos.util.AtmosException in project camel by apache.

the class AtmosAPIFacade method downloadSingleFile.

private void downloadSingleFile(String path, Map<String, ByteArrayOutputStream> resultEntries) throws AtmosException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] content = null;
    try {
        content = AtmosAPIFacade.client.readObject(new ObjectPath(path), byte[].class);
        baos.write(content);
    } catch (IOException e) {
        throw new AtmosException(path + " cannot obtain a stream", e);
    }
    if (content != null) {
        resultEntries.put(path, baos);
        LOG.debug("Downloaded path: {} size:", path, baos.size());
    }
}
Also used : ObjectPath(com.emc.atmos.api.ObjectPath) AtmosException(org.apache.camel.component.atmos.util.AtmosException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 3 with AtmosException

use of org.apache.camel.component.atmos.util.AtmosException in project camel by apache.

the class AtmosConfiguration method createClient.

/**
     * Obtain a new instance of AtmosApi client and store it in configuration.
     *
     * @throws AtmosException
     */
public void createClient() throws AtmosException {
    AtmosConfig config = null;
    try {
        config = new AtmosConfig(fullTokenId, secretKey, new URI(uri));
    } catch (URISyntaxException use) {
        throw new AtmosException("wrong syntax for Atmos URI!", use);
    }
    if (!enableSslValidation) {
        config.setDisableSslValidation(true);
    }
    AtmosApi atmosclient = new AtmosApiClient(config);
    this.client = atmosclient;
}
Also used : AtmosApiClient(com.emc.atmos.api.jersey.AtmosApiClient) AtmosException(org.apache.camel.component.atmos.util.AtmosException) URISyntaxException(java.net.URISyntaxException) AtmosApi(com.emc.atmos.api.AtmosApi) URI(java.net.URI) AtmosConfig(com.emc.atmos.api.AtmosConfig)

Example 4 with AtmosException

use of org.apache.camel.component.atmos.util.AtmosException in project camel by apache.

the class AtmosEndpoint method createConsumer.

/**
     * Create one of the camel consumer available based on the configuration
     *
     * @param processor the given processor
     * @return the camel consumer
     * @throws Exception
     */
public Consumer createConsumer(Processor processor) throws Exception {
    LOG.debug("resolve consumer atmos endpoint {" + configuration.getOperation().toString() + "}");
    LOG.debug("resolve consumer atmos attached client:" + configuration.getClient());
    AtmosScheduledPollConsumer consumer;
    if (this.configuration.getOperation() == AtmosOperation.get) {
        consumer = new AtmosScheduledPollGetConsumer(this, processor, configuration);
        consumer.setDelay(POLL_CONSUMER_DELAY);
        return consumer;
    } else {
        throw new AtmosException("operation specified is not valid for consumer!");
    }
}
Also used : AtmosScheduledPollGetConsumer(org.apache.camel.component.atmos.integration.consumer.AtmosScheduledPollGetConsumer) AtmosScheduledPollConsumer(org.apache.camel.component.atmos.integration.consumer.AtmosScheduledPollConsumer) AtmosException(org.apache.camel.component.atmos.util.AtmosException)

Example 5 with AtmosException

use of org.apache.camel.component.atmos.util.AtmosException in project camel by apache.

the class AtmosAPIFacade method downloadFilesInFolder.

private void downloadFilesInFolder(String atmosPath, Map<String, ByteArrayOutputStream> resultEntries) throws AtmosException {
    ObjectPath atmosEntry = new ObjectPath(atmosPath);
    if (AtmosAPIFacade.client.getSystemMetadata(atmosEntry) == null) {
        throw new AtmosException(atmosPath + " does not exist or cannot obtain metadata");
    }
    if (!atmosEntry.isDirectory()) {
        LOG.debug("downloading a single file...");
        downloadSingleFile(atmosPath, resultEntries);
        return;
    }
    ListDirectoryRequest listRequest = new ListDirectoryRequest().path(atmosEntry);
    AtmosAPIFacade.client.listDirectory(listRequest);
    for (DirectoryEntry entry : AtmosAPIFacade.client.listDirectory(listRequest).getEntries()) {
        if (!entry.isDirectory()) {
            try {
                //get the baos of the file
                downloadSingleFile(atmosEntry.getPath().concat(entry.getFilename()), resultEntries);
            } catch (AtmosException e) {
                LOG.warn("Cannot download from " + entry.getFilename());
            }
        } else {
            //iterate on folder
            downloadFilesInFolder(atmosEntry.getPath().concat(entry.getFilename()), resultEntries);
        }
    }
}
Also used : ObjectPath(com.emc.atmos.api.ObjectPath) AtmosException(org.apache.camel.component.atmos.util.AtmosException) ListDirectoryRequest(com.emc.atmos.api.request.ListDirectoryRequest) DirectoryEntry(com.emc.atmos.api.bean.DirectoryEntry)

Aggregations

AtmosException (org.apache.camel.component.atmos.util.AtmosException)6 ObjectPath (com.emc.atmos.api.ObjectPath)3 IOException (java.io.IOException)2 AtmosApi (com.emc.atmos.api.AtmosApi)1 AtmosConfig (com.emc.atmos.api.AtmosConfig)1 ObjectId (com.emc.atmos.api.ObjectId)1 DirectoryEntry (com.emc.atmos.api.bean.DirectoryEntry)1 AtmosApiClient (com.emc.atmos.api.jersey.AtmosApiClient)1 ListDirectoryRequest (com.emc.atmos.api.request.ListDirectoryRequest)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 AtmosFileUploadResult (org.apache.camel.component.atmos.dto.AtmosFileUploadResult)1 AtmosResult (org.apache.camel.component.atmos.dto.AtmosResult)1 AtmosScheduledPollConsumer (org.apache.camel.component.atmos.integration.consumer.AtmosScheduledPollConsumer)1 AtmosScheduledPollGetConsumer (org.apache.camel.component.atmos.integration.consumer.AtmosScheduledPollGetConsumer)1 AtmosDelProducer (org.apache.camel.component.atmos.integration.producer.AtmosDelProducer)1 AtmosGetProducer (org.apache.camel.component.atmos.integration.producer.AtmosGetProducer)1 AtmosMoveProducer (org.apache.camel.component.atmos.integration.producer.AtmosMoveProducer)1