Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: CAMEL-7477

...

Maven users will need to add the following dependency to their pom.xml for this component:

Code Block
xml
xml

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-jclouds</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

...

The camel jclouds component will make use of multiple jclouds blobstores and compute services as long as they are passed to the component during initialization. The component accepts a list blobstores and compute services. Here is how it can be configured.

Code Block
xml
xml

    <bean id="jclouds" class="org.apache.camel.component.jclouds.JcloudsComponent">
        <property name="computeServices">
            <list>
                <ref bean="computeService"/>
            </list>
        </property>
        <property name="blobStores">
            <list>
                <ref bean="blobStore"/>
            </list>
        </property>
    </bean>

    <!-- Creating a blobstore from spring / blueprint xml -->
    <bean id="blobStoreContextFactory" class="org.jclouds.blobstore.BlobStoreContextFactory"/>

    <bean id="blobStoreContext" factory-bean="blobStoreContextFactory" factory-method="createContext">
        <constructor-arg name="provider" value="PROVIDER_NAME"/>
        <constructor-arg name="identity"  value="IDENTITY"/>
        <constructor-arg name="credential" value="CREDENTIAL"/>
    </bean>

    <bean id="blobStore" factory-bean="blobStoreContext" factory-method="getBlobStore"/>

    <!-- Creating a compute service from spring / blueprint xml -->
    <bean id="computeServiceContextFactory" class="org.jclouds.compute.ComputeServiceContextFactory"/>

    <bean id="computeServiceContext" factory-bean="computeServiceContextFactory" factory-method="createContext">
        <constructor-arg name="provider" value="PROVIDER_NAME"/>
        <constructor-arg name="identity"  value="IDENTITY"/>
        <constructor-arg name="credential" value="CREDENTIAL"/>
    </bean>

    <bean id="computeService" factory-bean="computeServiceContext" factory-method="getComputeService"/>

As you can see the component is capable of handling multiple blobstores and compute services. The actual implementation that will be used by each endpoint is specified by passing the provider inside the URI.

URI format

Code Block

jclouds:blobstore:[provider id][?options]
jclouds:compute:[provider id][?options]

...

You can have as many of these options as you like.

Code Block

jclouds:blobstore:aws-s3?operation=CamelJcloudsGet&container=mycontainer&blobName=someblob

...

This example will show you how you can store any message inside a blob using the jclouds component.

Code Block

from("direct:start")
    .to("jclouds:blobstore:aws-s3" +
        "?operation=PUT" +
        "&container=mycontainer" +
        "&blobName=myblob");

In the above example you can override any of the URI parameters with headers on the message.
Here is how the above example would look like using xml to define our route.

Code Block
xml
xml

<route>
    <from uri="direct:start"/>
    <to uri="jclouds:blobstore:aws-s3?operation=PUT&container=mycontainer&blobName=myblob"/>
</route>

...

This example will show you how you can read the contnet of a blob using the jclouds component.

Code Block

from("direct:start")
    .to("jclouds:blobstore:aws-s3" +
        "?operation=GET" +
        "&container=mycontainer" +
        "&blobName=myblob");

In the above example you can override any of the URI parameters with headers on the message.
Here is how the above example would look like using xml to define our route.

Code Block
xml
xml

<route>
    <from uri="direct:start"/>
    <to uri="jclouds:blobstore:aws-s3?operation=PUT&container=mycontainer&blobName=myblob"/>
</route>

...

This example will consume all blob that are under the specified container. The generated exchange will contain the payload of the blob as body.

Code Block

    from("jclouds:blobstore:aws-s3" +
        "?container=mycontainer")
        .to("direct:next");

You can achieve the same goal by using xml, as you can see below.

Code Block
xml
xml

<route>
    <from uri="jclouds:blobstore:aws-s3?operation=GET&container=mycontainer&blobName=myblob"/>
    <to uri="direct:next"/>
</route>

...

Wiki Markup
{div:class=confluenceTableSmall}
|| Name || Default Value || Description ||
| {{operation}} | PUTCamelJcloudsPut | Specifies the type of operation that will be performed to the compute service. Allowed values are CREATE_NODE CamelJcloudsCreateNode, 
CamelJcloudsRunScript, RUNS_CRIPTCamelJcloudsDestroyNode, DESTROY_NODECamelJCloudsDestroyNode, LIST_NODESCamelJCloudsListNodes, LIST_IMAGESCamelJCloudsListImages, LIST_HARDWARECamelJCloudsListHardware. |
| {{imageId}} | null | *CREATE_NODECamelJcloudsCreateNode operation only* The imageId that will be used for creating a node. Values depend on the actual cloud provider. |
| {{locationId}} | null | *CREATE_NODECamelJcloudsCreateNode operation only* The location that will be used for creating a node. Values depend on the actual cloud provider. |
| {{hardwareId}} | null | *CREATE_NODECamelJcloudsCreateNode operation only* The hardware that will be used for creating a node. Values depend on the actual cloud provider. |
| {{group}} | null | *CREATE_NODECamelJcloudsCreateNode operation only* The group that will be assigned to the newly created node. Values depend on the actual cloud provider. |
| {{nodeId}} | null | *RUN_SCRIPTCamelJcloudsRunScript & DESTROY_NODECamelJcloudsDestroyNode operation only* The id of the node that will run the script or destroyed. |
| {{user}} | null | *RUN_SCRIPTCamelJcloudsRunScript operation only* The user on the target node that will run the script. |
{div}

The combination of parameters for use with the compute service depend on the operation.

Code Block

jclouds:compute:aws-ec2?operation=CREATE_NODECamelJcloudsCreateNode&imageId=AMI_XXXXX&locationId=eu-west-1&group=mygroup

...

Example 1: Listing the available images.

Code Block

    from("jclouds:compute:aws-ec2" +
        "&operation=LIST_IMAGESCamelJCloudsListImages")
        .to("direct:next");

This will create a message that will contain the list of images inside its body. You can also do the same using xml.

Code Block
xml
xml

<route>
    <from uri="jclouds:compute:aws-ec2?operation=LIST_IMAGESCamelJCloudsListImages"/>
    <to uri="direct:next"/>
</route>

Example 2: Create a new node.

Code Block

    from("direct:start").
    to("jclouds:compute:aws-ec2" +
        "?operation=CREATE_NODECamelJcloudsCreateNode" +
        "&imageId=AMI_XXXXX" +
        "&locationId=XXXXX" +
        "&group=myGroup");

This will create a new node on the cloud provider. The out message in this case will be a set of metadata that contains information about the newly created node (e.g. the ip, hostname etc). Here is the same using spring xml.

Code Block
xml
xml

<route>
    <from uri="direct:start"/>
    <to uri="jclouds:compute:aws-ec2?operation=CREATE_NODECamelJcloudsCreateNode&imageId=AMI_XXXXX&locationId=XXXXX&group=myGroup"/>
</route>

Example 3: Run a shell script on running node.

Code Block

    from("direct:start").
    to("jclouds:compute:aws-ec2" +
        "?operation=RUN_SCRIPTCamelJcloudsRunScript" +
        "?nodeId=10" +
        "&user=ubuntu");

...

Here is the same using spring xml.

Code Block
xml
xml

<route>
    <from uri="direct:start"/>
    <to uri="jclouds:compute:aws-ec2?operation=RUN_SCRIPTCamelJcloudsListNodes&?nodeId=10&user=ubuntu"/>
</route>

...